Unroll a level of prefs for fieldname templates.

It was playing havoc with the saving of project and global templates
without one overwriting the other.

Fixes https://gitlab.com/kicad/code/kicad/issues/5415
This commit is contained in:
Jeff Young 2020-08-30 18:57:10 +01:00
parent 7652637553
commit 20211eed49
18 changed files with 88 additions and 171 deletions

View File

@ -41,7 +41,6 @@ PROJECT_FILE::PROJECT_FILE( const wxString& aFullPath ) :
m_project( nullptr ), m_project( nullptr ),
m_ErcSettings( nullptr ), m_ErcSettings( nullptr ),
m_SchematicSettings( nullptr ), m_SchematicSettings( nullptr ),
m_TemplateFieldNames( nullptr ),
m_BoardSettings() m_BoardSettings()
{ {
// Keep old files around // Keep old files around

View File

@ -798,7 +798,7 @@ bool SETTINGS_MANAGER::SaveProject( const wxString& aFullPath )
return false; return false;
PROJECT_FILE* project = m_project_files.at( path ); PROJECT_FILE* project = m_project_files.at( path );
wxString projectPath = GetPathForSettingsFile( project ); wxString projectPath = GetPathForSettingsFile( project );
project->SaveToFile( projectPath ); project->SaveToFile( projectPath );
Prj().GetLocalSettings().SaveToFile( projectPath ); Prj().GetLocalSettings().SaveToFile( projectPath );

View File

@ -23,7 +23,6 @@
*/ */
#include <template_fieldnames.h> #include <template_fieldnames.h>
#include <dsnlexer.h>
#include <fctsys.h> #include <fctsys.h>
#include <macros.h> #include <macros.h>
#include <pgm_base.h> #include <pgm_base.h>

View File

@ -64,13 +64,13 @@ PAGED_DIALOG::PAGED_DIALOG( wxWindow* aParent, const wxString& aTitle, bool aUse
if( aUseReset ) if( aUseReset )
{ {
m_resetButton = new wxButton( this, wxID_ANY, _( "Reset to Defaults" ) ); m_resetButton = new wxButton( this, wxID_ANY, _( "Reset to Defaults" ) );
buttonsSizer->Add( m_resetButton, 0, wxRIGHT | wxLEFT, 5 ); buttonsSizer->Add( m_resetButton, 0, wxALL, 5 );
} }
if( !aAuxiliaryAction.IsEmpty() ) if( !aAuxiliaryAction.IsEmpty() )
{ {
m_auxiliaryButton = new wxButton( this, wxID_ANY, aAuxiliaryAction ); m_auxiliaryButton = new wxButton( this, wxID_ANY, aAuxiliaryAction );
buttonsSizer->Add( m_auxiliaryButton, 0, wxEXPAND|wxRIGHT|wxLEFT, 10 ); buttonsSizer->Add( m_auxiliaryButton, 0, wxALL, 5 );
} }
buttonsSizer->AddStretchSpacer(); buttonsSizer->AddStretchSpacer();

View File

@ -149,7 +149,8 @@ bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::TransferDataToWindow()
} }
// Add in any template fieldnames not yet defined: // Add in any template fieldnames not yet defined:
for( const TEMPLATE_FIELDNAME& templateFieldname : GetParent()->GetTemplateFieldNames() ) for( const TEMPLATE_FIELDNAME& templateFieldname :
GetParent()->Schematic().Settings().m_TemplateFieldNames.GetTemplateFieldNames() )
{ {
if( defined.count( templateFieldname.m_Name ) <= 0 ) if( defined.count( templateFieldname.m_Name ) <= 0 )
{ {
@ -400,6 +401,7 @@ bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::TransferDataFromWindow()
return false; return false;
SCH_SCREEN* currentScreen = GetParent()->GetScreen(); SCH_SCREEN* currentScreen = GetParent()->GetScreen();
SCHEMATIC& schematic = GetParent()->Schematic();
wxCHECK( currentScreen, false ); wxCHECK( currentScreen, false );
@ -483,8 +485,7 @@ bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::TransferDataFromWindow()
// Push all fields to the component -except- for those which are TEMPLATE_FIELDNAMES // Push all fields to the component -except- for those which are TEMPLATE_FIELDNAMES
// with empty values. // with empty values.
TEMPLATE_FIELDNAMES templateFieldnames = GetParent()->GetTemplateFieldNames(); SCH_FIELDS& fields = m_cmp->GetFields();
SCH_FIELDS& fields = m_cmp->GetFields();
fields.clear(); fields.clear();
@ -495,7 +496,8 @@ bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::TransferDataFromWindow()
if( i >= MANDATORY_FIELDS ) if( i >= MANDATORY_FIELDS )
{ {
for( const auto& fieldname : templateFieldnames ) for( const TEMPLATE_FIELDNAME& fieldname :
schematic.Settings().m_TemplateFieldNames.GetTemplateFieldNames() )
{ {
if( field.GetName() == fieldname.m_Name && field.GetText().IsEmpty() ) if( field.GetName() == fieldname.m_Name && field.GetText().IsEmpty() )
{ {
@ -746,7 +748,8 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::UpdateFieldsFromLibrary( wxCommandEvent
} }
// Add in any template fieldnames not yet defined: // Add in any template fieldnames not yet defined:
for( const TEMPLATE_FIELDNAME& templateFieldname : GetParent()->GetTemplateFieldNames() ) for( const TEMPLATE_FIELDNAME& templateFieldname :
GetParent()->Schematic().Settings().m_TemplateFieldNames.GetTemplateFieldNames() )
{ {
if( defined.count( templateFieldname.m_Name ) <= 0 ) if( defined.count( templateFieldname.m_Name ) <= 0 )
{ {

View File

@ -957,10 +957,11 @@ void DIALOG_FIELDS_EDITOR_GLOBAL::LoadFieldNames()
AddField( fieldName, true, false ); AddField( fieldName, true, false );
// Add any templateFieldNames which aren't already present in the userFieldNames // Add any templateFieldNames which aren't already present in the userFieldNames
for( const TEMPLATE_FIELDNAME& templateFieldName : m_parent->GetTemplateFieldNames() ) for( const TEMPLATE_FIELDNAME& templateFieldname :
m_parent->Schematic().Settings().m_TemplateFieldNames.GetTemplateFieldNames() )
{ {
if( userFieldNames.count( templateFieldName.m_Name ) == 0 ) if( userFieldNames.count( templateFieldname.m_Name ) == 0 )
AddField( templateFieldName.m_Name, false, false ); AddField( templateFieldname.m_Name, false, false );
} }
} }

View File

@ -153,23 +153,20 @@ void DIALOG_SCHEMATIC_SETUP::OnAuxiliaryAction( wxCommandEvent& event )
return; return;
} }
PROJECT* otherPrj = m_frame->GetSettingsManager()->GetProject( projectFn.GetFullPath() ); PROJECT* otherPrj = m_frame->GetSettingsManager()->GetProject( projectFn.GetFullPath() );
SCHEMATIC otherSch( otherPrj );
SCHEMATIC otherSch( otherPrj ); TEMPLATES templateMgr;
TEMPLATES templateMgr;
PROJECT_FILE& file = otherPrj->GetProjectFile(); PROJECT_FILE& file = otherPrj->GetProjectFile();
wxASSERT( file.m_SchematicSettings ); wxASSERT( file.m_SchematicSettings );
file.m_SchematicSettings->m_TemplateFieldNames = &templateMgr;
file.m_SchematicSettings->LoadFromFile(); file.m_SchematicSettings->LoadFromFile();
if( importDlg.m_FormattingOpt->GetValue() ) if( importDlg.m_FormattingOpt->GetValue() )
m_formatting->ImportSettingsFrom( *file.m_SchematicSettings ); m_formatting->ImportSettingsFrom( *file.m_SchematicSettings );
if( importDlg.m_FieldNameTemplatesOpt->GetValue() ) if( importDlg.m_FieldNameTemplatesOpt->GetValue() )
m_fieldNameTemplates->ImportSettingsFrom( file.m_SchematicSettings->m_TemplateFieldNames ); m_fieldNameTemplates->ImportSettingsFrom( &otherSch.Settings().m_TemplateFieldNames );
if( importDlg.m_PinMapOpt->GetValue() ) if( importDlg.m_PinMapOpt->GetValue() )
m_pinMap->ImportSettingsFrom( file.m_ErcSettings->m_PinMap ); m_pinMap->ImportSettingsFrom( file.m_ErcSettings->m_PinMap );

View File

@ -28,7 +28,7 @@
#include <grid_tricks.h> #include <grid_tricks.h>
#include <sch_edit_frame.h> #include <sch_edit_frame.h>
#include <bitmaps.h> #include <bitmaps.h>
#include <schematic.h>
#include <panel_eeschema_template_fieldnames.h> #include <panel_eeschema_template_fieldnames.h>
PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::PANEL_EESCHEMA_TEMPLATE_FIELDNAMES( SCH_EDIT_FRAME* aFrame, PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::PANEL_EESCHEMA_TEMPLATE_FIELDNAMES( SCH_EDIT_FRAME* aFrame,
@ -67,7 +67,9 @@ PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::~PANEL_EESCHEMA_TEMPLATE_FIELDNAMES()
bool PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::TransferDataToWindow() bool PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::TransferDataToWindow()
{ {
m_fields = m_frame->GetTemplateFieldNames( m_global ); SCHEMATIC& schematic = m_frame->Schematic();
m_fields = schematic.Settings().m_TemplateFieldNames.GetTemplateFieldNames( m_global );
return TransferDataToGrid(); return TransferDataToGrid();
} }
@ -164,10 +166,12 @@ bool PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::TransferDataFromWindow()
if( !TransferDataFromGrid() ) if( !TransferDataFromGrid() )
return false; return false;
m_frame->DeleteAllTemplateFieldNames( m_global ); SCHEMATIC& schematic = m_frame->Schematic();
schematic.Settings().m_TemplateFieldNames.DeleteAllFieldNameTemplates( m_global );
for( const TEMPLATE_FIELDNAME& field : m_fields ) for( const TEMPLATE_FIELDNAME& field : m_fields )
m_frame->AddTemplateFieldName( field, m_global ); schematic.Settings().m_TemplateFieldNames.AddTemplateFieldName( field, m_global );
return true; return true;
} }

View File

@ -375,26 +375,6 @@ void SCH_BASE_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
for( double& factor : aCfg->m_Window.zoom_factors ) for( double& factor : aCfg->m_Window.zoom_factors )
factor = std::min( factor, MAX_ZOOM_FACTOR ); factor = std::min( factor, MAX_ZOOM_FACTOR );
EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg );
if( cfg )
{
wxString templateFieldNames = cfg->m_Drawing.field_names;
if( !templateFieldNames.IsEmpty() )
{
TEMPLATE_FIELDNAMES_LEXER lexer( TO_UTF8( templateFieldNames ) );
try
{
m_templateFieldNames.Parse( &lexer, true );
}
catch( const IO_ERROR& )
{
}
}
}
} }
@ -403,19 +383,6 @@ void SCH_BASE_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
wxCHECK_RET( aCfg, "Call to SCH_BASE_FRAME::SaveSettings with null settings" ); wxCHECK_RET( aCfg, "Call to SCH_BASE_FRAME::SaveSettings with null settings" );
EDA_DRAW_FRAME::SaveSettings( aCfg ); EDA_DRAW_FRAME::SaveSettings( aCfg );
if( eeconfig() )
{
// Save template fieldnames
STRING_FORMATTER sf;
m_templateFieldNames.Format( &sf, 0, true );
wxString record = FROM_UTF8( sf.GetString().c_str() );
record.Replace( wxT("\n"), wxT(""), true ); // strip all newlines
record.Replace( wxT(" "), wxT(" "), true ); // double space to single
eeconfig()->m_Drawing.field_names = record.ToStdString();
}
} }

View File

@ -34,7 +34,7 @@
#include <widgets/grid_icon_text_helpers.h> #include <widgets/grid_icon_text_helpers.h>
#include <widgets/grid_text_button_helpers.h> #include <widgets/grid_text_button_helpers.h>
#include <wildcards_and_files_ext.h> #include <wildcards_and_files_ext.h>
#include <project/project_file.h>
#include "eda_doc.h" #include "eda_doc.h"
@ -307,8 +307,10 @@ wxGridCellAttr* FIELDS_GRID_TABLE<T>::GetAttr( int aRow, int aCol, wxGridCellAtt
} }
else else
{ {
wxString fieldname = GetValue( aRow, FDC_NAME ); wxString fn = GetValue( aRow, FDC_NAME );
const TEMPLATE_FIELDNAME* templateFn = m_frame->GetTemplateFieldName( fieldname );
SCHEMATIC_SETTINGS* settings = m_frame->Prj().GetProjectFile().m_SchematicSettings;
const TEMPLATE_FIELDNAME* templateFn = settings->m_TemplateFieldNames.GetFieldName( fn );
if( templateFn && templateFn->m_URL ) if( templateFn && templateFn->m_URL )
{ {

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2015 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2015 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2015-2018 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2015-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -90,10 +90,8 @@ LIB_PART* SchGetLibPart( const LIB_ID& aLibId, SYMBOL_LIB_TABLE* aLibTable,
class SCH_BASE_FRAME : public EDA_DRAW_FRAME class SCH_BASE_FRAME : public EDA_DRAW_FRAME
{ {
protected: protected:
TEMPLATES m_templateFieldNames;
/// These are only used by libedit. Eeschema should be using the one inside the SCHEMATIC. /// These are only used by libedit. Eeschema should be using the one inside the SCHEMATIC.
SCHEMATIC_SETTINGS m_base_frame_defaults; SCHEMATIC_SETTINGS m_base_frame_defaults;
SCHEMATIC_SETTINGS* m_defaults; SCHEMATIC_SETTINGS* m_defaults;
@ -180,33 +178,6 @@ public:
const LIB_ID* aHighlight = nullptr, const LIB_ID* aHighlight = nullptr,
bool aAllowFields = true ); bool aAllowFields = true );
/**
* Return a template field names list for read only access.
*/
const TEMPLATE_FIELDNAMES& GetTemplateFieldNames()
{
return m_templateFieldNames.GetTemplateFieldNames();
}
/**
* Return a specific template field names list (global or project) for read only access.
*/
const TEMPLATE_FIELDNAMES& GetTemplateFieldNames( bool aGlobal )
{
return m_templateFieldNames.GetTemplateFieldNames( aGlobal );
}
/**
* Search for \a aName in the the template field name list.
*
* @param aName A wxString object containing the field name to search for.
* @return the template fieldname if found; NULL otherwise.
*/
const TEMPLATE_FIELDNAME* GetTemplateFieldName( const wxString& aName )
{
return m_templateFieldNames.GetFieldName( aName );
}
/** /**
* Load symbol from symbol library table. * Load symbol from symbol library table.
* *

View File

@ -26,12 +26,9 @@
#include <class_library.h> #include <class_library.h>
#include <confirm.h> #include <confirm.h>
#include <connection_graph.h> #include <connection_graph.h>
#include <dialog_symbol_remap.h>
#include <dialogs/dialog_schematic_find.h> #include <dialogs/dialog_schematic_find.h>
#include <eeschema_config.h>
#include <eeschema_id.h> #include <eeschema_id.h>
#include <executable_names.h> #include <executable_names.h>
#include <fctsys.h>
#include <general.h> #include <general.h>
#include <gestfich.h> #include <gestfich.h>
#include <gr_basic.h> #include <gr_basic.h>
@ -54,7 +51,6 @@
#include <settings/settings_manager.h> #include <settings/settings_manager.h>
#include <advanced_config.h> #include <advanced_config.h>
#include <sim/sim_plot_frame.h> #include <sim/sim_plot_frame.h>
#include <symbol_lib_table.h>
#include <tool/action_manager.h> #include <tool/action_manager.h>
#include <tool/action_toolbar.h> #include <tool/action_toolbar.h>
#include <tool/common_control.h> #include <tool/common_control.h>
@ -526,7 +522,6 @@ void SCH_EDIT_FRAME::CreateScreens()
{ {
m_schematic->Reset(); m_schematic->Reset();
m_schematic->SetProject( &Prj() ); m_schematic->SetProject( &Prj() );
m_schematic->SetTemplateFieldNames( &m_templateFieldNames );
m_schematic->SetRoot( new SCH_SHEET( m_schematic ) ); m_schematic->SetRoot( new SCH_SHEET( m_schematic ) );
@ -678,7 +673,6 @@ void SCH_EDIT_FRAME::doCloseWindow()
SetScreen( nullptr ); SetScreen( nullptr );
GetSettingsManager()->SaveProject(); GetSettingsManager()->SaveProject();
Schematic().SetTemplateFieldNames( nullptr );
Schematic().Reset(); Schematic().Reset();
Destroy(); Destroy();

View File

@ -185,29 +185,6 @@ public:
void ShowSchematicSetupDialog( const wxString& aInitialPage = wxEmptyString ); void ShowSchematicSetupDialog( const wxString& aInitialPage = wxEmptyString );
/**
* Insert or append a wanted symbol field name into the field names template.
*
* Should be used for any symbol property editor. If the name already exists, it
* overwrites the same name.
*
* @param aFieldName is a full description of the wanted field, and it must not match
* any of the default field names.
* @param aGlobal indicates whether to add to the global or project table
*/
void AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName, bool aGlobal )
{
m_templateFieldNames.AddTemplateFieldName( aFieldName, aGlobal );
}
/**
* Remove all global or project fieldname templates.
*/
void DeleteAllTemplateFieldNames( bool aGlobal )
{
m_templateFieldNames.DeleteAllFieldNameTemplates( aGlobal );
}
void LoadSettings( APP_SETTINGS_BASE* aCfg ) override; void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
void SaveSettings( APP_SETTINGS_BASE* aCfg ) override; void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;

View File

@ -90,26 +90,12 @@ void SCHEMATIC::SetProject( PROJECT* aPrj )
project.m_ErcSettings = new ERC_SETTINGS( &project, "erc" ); project.m_ErcSettings = new ERC_SETTINGS( &project, "erc" );
project.m_SchematicSettings = new SCHEMATIC_SETTINGS( &project, "schematic" ); project.m_SchematicSettings = new SCHEMATIC_SETTINGS( &project, "schematic" );
project.m_SchematicSettings->m_TemplateFieldNames = project.m_TemplateFieldNames;
project.m_SchematicSettings->LoadFromFile(); project.m_SchematicSettings->LoadFromFile();
project.m_ErcSettings->LoadFromFile(); project.m_ErcSettings->LoadFromFile();
} }
} }
void SCHEMATIC::SetTemplateFieldNames( TEMPLATES* aTemplates )
{
wxASSERT( m_project );
PROJECT_FILE& project = m_project->GetProjectFile();
project.m_TemplateFieldNames = aTemplates;
if( project.m_SchematicSettings )
project.m_SchematicSettings->m_TemplateFieldNames = aTemplates;
}
void SCHEMATIC::SetRoot( SCH_SHEET* aRootSheet ) void SCHEMATIC::SetRoot( SCH_SHEET* aRootSheet )
{ {
wxCHECK_RET( aRootSheet, "Call to SetRoot with null SCH_SHEET!" ); wxCHECK_RET( aRootSheet, "Call to SetRoot with null SCH_SHEET!" );

View File

@ -81,9 +81,6 @@ public:
void SetProject( PROJECT* aPrj ); void SetProject( PROJECT* aPrj );
/// Sets up the template fieldnames link if this project is opened in eeschema
void SetTemplateFieldNames( TEMPLATES* aTemplates );
/** /**
* Builds and returns an updated schematic hierarchy * Builds and returns an updated schematic hierarchy
* TODO: can this be cached? * TODO: can this be cached?

View File

@ -41,8 +41,7 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin
m_TextOffsetRatio( 0.08 ), m_TextOffsetRatio( 0.08 ),
m_PinSymbolSize( DEFAULT_TEXT_SIZE * IU_PER_MILS / 2 ), m_PinSymbolSize( DEFAULT_TEXT_SIZE * IU_PER_MILS / 2 ),
m_JunctionSize( DEFAULT_JUNCTION_DIAM * IU_PER_MILS ), m_JunctionSize( DEFAULT_JUNCTION_DIAM * IU_PER_MILS ),
m_SpiceAdjustPassiveValues( false ), m_SpiceAdjustPassiveValues( false )
m_TemplateFieldNames( nullptr )
{ {
EESCHEMA_SETTINGS* appSettings = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ); EESCHEMA_SETTINGS* appSettings = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
@ -94,11 +93,8 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin
{ {
nlohmann::json ret = nlohmann::json::array(); nlohmann::json ret = nlohmann::json::array();
if( !m_TemplateFieldNames )
return ret;
for( const TEMPLATE_FIELDNAME& field : for( const TEMPLATE_FIELDNAME& field :
m_TemplateFieldNames->GetTemplateFieldNames( false ) ) m_TemplateFieldNames.GetTemplateFieldNames( false ) )
{ {
ret.push_back( nlohmann::json( { ret.push_back( nlohmann::json( {
{ "name", field.m_Name }, { "name", field.m_Name },
@ -107,14 +103,29 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin
} ) ); } ) );
} }
auto* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
if( cfg )
{
// Save global fieldname templates
STRING_FORMATTER sf;
m_TemplateFieldNames.Format( &sf, 0, true );
wxString record = FROM_UTF8( sf.GetString().c_str() );
record.Replace( wxT("\n"), wxT(""), true ); // strip all newlines
record.Replace( wxT(" "), wxT(" "), true ); // double space to single
cfg->m_Drawing.field_names = record.ToStdString();
}
return ret; return ret;
}, },
[&]( const nlohmann::json& aJson ) [&]( const nlohmann::json& aJson )
{ {
if( !m_TemplateFieldNames || aJson.empty() || !aJson.is_array() ) if( aJson.empty() || !aJson.is_array() )
return; return;
m_TemplateFieldNames->DeleteAllFieldNameTemplates( false ); m_TemplateFieldNames.DeleteAllFieldNameTemplates( false );
for( const nlohmann::json& entry : aJson ) for( const nlohmann::json& entry : aJson )
{ {
@ -125,7 +136,28 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin
TEMPLATE_FIELDNAME field( entry["name"].get<wxString>() ); TEMPLATE_FIELDNAME field( entry["name"].get<wxString>() );
field.m_URL = entry["url"].get<bool>(); field.m_URL = entry["url"].get<bool>();
field.m_Visible = entry["visible"].get<bool>(); field.m_Visible = entry["visible"].get<bool>();
m_TemplateFieldNames->AddTemplateFieldName( field, false ); m_TemplateFieldNames.AddTemplateFieldName( field, false );
}
auto* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
if( cfg )
{
// Read global fieldname templates
wxString templateFieldNames = cfg->m_Drawing.field_names;
if( !templateFieldNames.IsEmpty() )
{
TEMPLATE_FIELDNAMES_LEXER lexer( TO_UTF8( templateFieldNames ) );
try
{
m_TemplateFieldNames.Parse( &lexer, true );
}
catch( const IO_ERROR& )
{
}
}
} }
}, {} ) ); }, {} ) );

View File

@ -42,25 +42,24 @@ public:
// Default sizes are all stored in IU here, and im mils in the JSON file // Default sizes are all stored in IU here, and im mils in the JSON file
int m_DefaultLineWidth; int m_DefaultLineWidth;
int m_DefaultWireThickness; int m_DefaultWireThickness;
int m_DefaultBusThickness; int m_DefaultBusThickness;
int m_DefaultTextSize; int m_DefaultTextSize;
double m_TextOffsetRatio; double m_TextOffsetRatio;
int m_PinSymbolSize; int m_PinSymbolSize;
int m_JunctionSize; int m_JunctionSize;
wxString m_PageLayoutDescrFile; wxString m_PageLayoutDescrFile;
wxString m_PlotDirectoryName; wxString m_PlotDirectoryName;
wxString m_NetFormatName; wxString m_NetFormatName;
bool m_SpiceAdjustPassiveValues; bool m_SpiceAdjustPassiveValues;
wxString m_SpiceCommandString; // A command string to run external spice wxString m_SpiceCommandString; // A command string to run external spice
/// @see PROJECT_FILE::m_TemplateFieldNames TEMPLATES m_TemplateFieldNames;
TEMPLATES* m_TemplateFieldNames;
}; };
#endif #endif

View File

@ -137,17 +137,6 @@ public:
// Schematic editing and misc settings: lifecycle managed by SCHEMATIC // Schematic editing and misc settings: lifecycle managed by SCHEMATIC
SCHEMATIC_SETTINGS* m_SchematicSettings; SCHEMATIC_SETTINGS* m_SchematicSettings;
/**
* A pointer to the template fieldnames object owned by the parent SCH_BASE_FRAME.
* Note that this coupling is unfortunate; but the TEMPLATES object has to outlive any
* SCHEMATIC_SETTINGS object because it holds both global and project field names.
* This will be null if the project is opened outside a SCH_BASE_FRAME. It is placed here
* instead of in SCHEMATIC_SETTINGS because SCHEMATIC_SETTINGS objects are created and destroyed
* when schematics are loaded, and it's inconvenient to make sure this pointer is set early so
* that load of the SCHEMATIC_SETTINGS works.
*/
TEMPLATES* m_TemplateFieldNames;
// Legacy parameters LibDir and LibName, for importing old projects // Legacy parameters LibDir and LibName, for importing old projects
wxString m_LegacyLibDir; wxString m_LegacyLibDir;