diff --git a/common/project/project_file.cpp b/common/project/project_file.cpp index 62a393a873..31afbbb44b 100644 --- a/common/project/project_file.cpp +++ b/common/project/project_file.cpp @@ -41,7 +41,6 @@ PROJECT_FILE::PROJECT_FILE( const wxString& aFullPath ) : m_project( nullptr ), m_ErcSettings( nullptr ), m_SchematicSettings( nullptr ), - m_TemplateFieldNames( nullptr ), m_BoardSettings() { // Keep old files around diff --git a/common/settings/settings_manager.cpp b/common/settings/settings_manager.cpp index 7ef6a26cc4..d57352ed3e 100644 --- a/common/settings/settings_manager.cpp +++ b/common/settings/settings_manager.cpp @@ -798,7 +798,7 @@ bool SETTINGS_MANAGER::SaveProject( const wxString& aFullPath ) return false; PROJECT_FILE* project = m_project_files.at( path ); - wxString projectPath = GetPathForSettingsFile( project ); + wxString projectPath = GetPathForSettingsFile( project ); project->SaveToFile( projectPath ); Prj().GetLocalSettings().SaveToFile( projectPath ); diff --git a/common/template_fieldnames.cpp b/common/template_fieldnames.cpp index 29d4bda831..0d8ed17217 100644 --- a/common/template_fieldnames.cpp +++ b/common/template_fieldnames.cpp @@ -23,7 +23,6 @@ */ #include -#include #include #include #include diff --git a/common/widgets/paged_dialog.cpp b/common/widgets/paged_dialog.cpp index 96c52ff0a5..e7b40e1666 100644 --- a/common/widgets/paged_dialog.cpp +++ b/common/widgets/paged_dialog.cpp @@ -64,13 +64,13 @@ PAGED_DIALOG::PAGED_DIALOG( wxWindow* aParent, const wxString& aTitle, bool aUse if( aUseReset ) { 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() ) { 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(); diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index 77a26fe144..ae1d98dd1e 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -149,7 +149,8 @@ bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::TransferDataToWindow() } // 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 ) { @@ -400,6 +401,7 @@ bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::TransferDataFromWindow() return false; SCH_SCREEN* currentScreen = GetParent()->GetScreen(); + SCHEMATIC& schematic = GetParent()->Schematic(); 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 // with empty values. - TEMPLATE_FIELDNAMES templateFieldnames = GetParent()->GetTemplateFieldNames(); - SCH_FIELDS& fields = m_cmp->GetFields(); + SCH_FIELDS& fields = m_cmp->GetFields(); fields.clear(); @@ -495,7 +496,8 @@ bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::TransferDataFromWindow() 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() ) { @@ -746,7 +748,8 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::UpdateFieldsFromLibrary( wxCommandEvent } // 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 ) { diff --git a/eeschema/dialogs/dialog_fields_editor_global.cpp b/eeschema/dialogs/dialog_fields_editor_global.cpp index df80a339d9..c919e72cea 100644 --- a/eeschema/dialogs/dialog_fields_editor_global.cpp +++ b/eeschema/dialogs/dialog_fields_editor_global.cpp @@ -957,10 +957,11 @@ void DIALOG_FIELDS_EDITOR_GLOBAL::LoadFieldNames() AddField( fieldName, true, false ); // 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 ) - AddField( templateFieldName.m_Name, false, false ); + if( userFieldNames.count( templateFieldname.m_Name ) == 0 ) + AddField( templateFieldname.m_Name, false, false ); } } diff --git a/eeschema/dialogs/dialog_schematic_setup.cpp b/eeschema/dialogs/dialog_schematic_setup.cpp index fa1a43c4fd..c8dc374315 100644 --- a/eeschema/dialogs/dialog_schematic_setup.cpp +++ b/eeschema/dialogs/dialog_schematic_setup.cpp @@ -153,23 +153,20 @@ void DIALOG_SCHEMATIC_SETUP::OnAuxiliaryAction( wxCommandEvent& event ) return; } - PROJECT* otherPrj = m_frame->GetSettingsManager()->GetProject( projectFn.GetFullPath() ); - - SCHEMATIC otherSch( otherPrj ); - - TEMPLATES templateMgr; + PROJECT* otherPrj = m_frame->GetSettingsManager()->GetProject( projectFn.GetFullPath() ); + SCHEMATIC otherSch( otherPrj ); + TEMPLATES templateMgr; PROJECT_FILE& file = otherPrj->GetProjectFile(); wxASSERT( file.m_SchematicSettings ); - file.m_SchematicSettings->m_TemplateFieldNames = &templateMgr; file.m_SchematicSettings->LoadFromFile(); if( importDlg.m_FormattingOpt->GetValue() ) m_formatting->ImportSettingsFrom( *file.m_SchematicSettings ); 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() ) m_pinMap->ImportSettingsFrom( file.m_ErcSettings->m_PinMap ); diff --git a/eeschema/dialogs/panel_eeschema_template_fieldnames.cpp b/eeschema/dialogs/panel_eeschema_template_fieldnames.cpp index a6934147e0..f858a279f2 100644 --- a/eeschema/dialogs/panel_eeschema_template_fieldnames.cpp +++ b/eeschema/dialogs/panel_eeschema_template_fieldnames.cpp @@ -28,7 +28,7 @@ #include #include #include - +#include #include 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() { - m_fields = m_frame->GetTemplateFieldNames( m_global ); + SCHEMATIC& schematic = m_frame->Schematic(); + + m_fields = schematic.Settings().m_TemplateFieldNames.GetTemplateFieldNames( m_global ); return TransferDataToGrid(); } @@ -164,10 +166,12 @@ bool PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::TransferDataFromWindow() if( !TransferDataFromGrid() ) 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 ) - m_frame->AddTemplateFieldName( field, m_global ); + schematic.Settings().m_TemplateFieldNames.AddTemplateFieldName( field, m_global ); return true; } diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index f1616d535f..646b8d38ad 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -375,26 +375,6 @@ void SCH_BASE_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) for( double& factor : aCfg->m_Window.zoom_factors ) factor = std::min( factor, MAX_ZOOM_FACTOR ); - - EESCHEMA_SETTINGS* cfg = dynamic_cast( 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" ); 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(); - } } diff --git a/eeschema/fields_grid_table.cpp b/eeschema/fields_grid_table.cpp index 3f0cac1830..937638c72b 100644 --- a/eeschema/fields_grid_table.cpp +++ b/eeschema/fields_grid_table.cpp @@ -34,7 +34,7 @@ #include #include #include - +#include #include "eda_doc.h" @@ -307,8 +307,10 @@ wxGridCellAttr* FIELDS_GRID_TABLE::GetAttr( int aRow, int aCol, wxGridCellAtt } else { - wxString fieldname = GetValue( aRow, FDC_NAME ); - const TEMPLATE_FIELDNAME* templateFn = m_frame->GetTemplateFieldName( fieldname ); + wxString fn = GetValue( aRow, FDC_NAME ); + + SCHEMATIC_SETTINGS* settings = m_frame->Prj().GetProjectFile().m_SchematicSettings; + const TEMPLATE_FIELDNAME* templateFn = settings->m_TemplateFieldNames.GetFieldName( fn ); if( templateFn && templateFn->m_URL ) { diff --git a/eeschema/sch_base_frame.h b/eeschema/sch_base_frame.h index 680c556b0e..b9b7012a5d 100644 --- a/eeschema/sch_base_frame.h +++ b/eeschema/sch_base_frame.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015 SoftPLC Corporation, Dick Hollenbeck - * 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 * 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 { protected: - TEMPLATES m_templateFieldNames; - /// 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; @@ -180,33 +178,6 @@ public: const LIB_ID* aHighlight = nullptr, 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. * diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index cf8a7e5c62..dce5e0f5b1 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -26,12 +26,9 @@ #include #include #include -#include #include -#include #include #include -#include #include #include #include @@ -54,7 +51,6 @@ #include #include #include -#include #include #include #include @@ -526,7 +522,6 @@ void SCH_EDIT_FRAME::CreateScreens() { m_schematic->Reset(); m_schematic->SetProject( &Prj() ); - m_schematic->SetTemplateFieldNames( &m_templateFieldNames ); m_schematic->SetRoot( new SCH_SHEET( m_schematic ) ); @@ -678,7 +673,6 @@ void SCH_EDIT_FRAME::doCloseWindow() SetScreen( nullptr ); GetSettingsManager()->SaveProject(); - Schematic().SetTemplateFieldNames( nullptr ); Schematic().Reset(); Destroy(); diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index ebe146fe0a..f3d5dc3f36 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -185,29 +185,6 @@ public: 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 SaveSettings( APP_SETTINGS_BASE* aCfg ) override; diff --git a/eeschema/schematic.cpp b/eeschema/schematic.cpp index 09799ff47f..485a7aab24 100644 --- a/eeschema/schematic.cpp +++ b/eeschema/schematic.cpp @@ -90,26 +90,12 @@ void SCHEMATIC::SetProject( PROJECT* aPrj ) project.m_ErcSettings = new ERC_SETTINGS( &project, "erc" ); project.m_SchematicSettings = new SCHEMATIC_SETTINGS( &project, "schematic" ); - project.m_SchematicSettings->m_TemplateFieldNames = project.m_TemplateFieldNames; project.m_SchematicSettings->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 ) { wxCHECK_RET( aRootSheet, "Call to SetRoot with null SCH_SHEET!" ); diff --git a/eeschema/schematic.h b/eeschema/schematic.h index 15608e6226..80dc581245 100644 --- a/eeschema/schematic.h +++ b/eeschema/schematic.h @@ -81,9 +81,6 @@ public: 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 * TODO: can this be cached? diff --git a/eeschema/schematic_settings.cpp b/eeschema/schematic_settings.cpp index 943a2588b2..29a1120f20 100644 --- a/eeschema/schematic_settings.cpp +++ b/eeschema/schematic_settings.cpp @@ -41,8 +41,7 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin m_TextOffsetRatio( 0.08 ), m_PinSymbolSize( DEFAULT_TEXT_SIZE * IU_PER_MILS / 2 ), m_JunctionSize( DEFAULT_JUNCTION_DIAM * IU_PER_MILS ), - m_SpiceAdjustPassiveValues( false ), - m_TemplateFieldNames( nullptr ) + m_SpiceAdjustPassiveValues( false ) { EESCHEMA_SETTINGS* appSettings = dynamic_cast( Kiface().KifaceSettings() ); @@ -94,11 +93,8 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin { nlohmann::json ret = nlohmann::json::array(); - if( !m_TemplateFieldNames ) - return ret; - for( const TEMPLATE_FIELDNAME& field : - m_TemplateFieldNames->GetTemplateFieldNames( false ) ) + m_TemplateFieldNames.GetTemplateFieldNames( false ) ) { ret.push_back( nlohmann::json( { { "name", field.m_Name }, @@ -107,14 +103,29 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin } ) ); } + auto* cfg = dynamic_cast( 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; }, [&]( const nlohmann::json& aJson ) { - if( !m_TemplateFieldNames || aJson.empty() || !aJson.is_array() ) + if( aJson.empty() || !aJson.is_array() ) return; - m_TemplateFieldNames->DeleteAllFieldNameTemplates( false ); + m_TemplateFieldNames.DeleteAllFieldNameTemplates( false ); 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() ); field.m_URL = entry["url"].get(); field.m_Visible = entry["visible"].get(); - m_TemplateFieldNames->AddTemplateFieldName( field, false ); + m_TemplateFieldNames.AddTemplateFieldName( field, false ); + } + + auto* cfg = dynamic_cast( 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& ) + { + } + } } }, {} ) ); diff --git a/eeschema/schematic_settings.h b/eeschema/schematic_settings.h index 2e27cbde02..a4f7ff3320 100644 --- a/eeschema/schematic_settings.h +++ b/eeschema/schematic_settings.h @@ -42,25 +42,24 @@ public: // Default sizes are all stored in IU here, and im mils in the JSON file - int m_DefaultLineWidth; - int m_DefaultWireThickness; - int m_DefaultBusThickness; - int m_DefaultTextSize; - double m_TextOffsetRatio; - int m_PinSymbolSize; - int m_JunctionSize; + int m_DefaultLineWidth; + int m_DefaultWireThickness; + int m_DefaultBusThickness; + int m_DefaultTextSize; + double m_TextOffsetRatio; + int m_PinSymbolSize; + int m_JunctionSize; - wxString m_PageLayoutDescrFile; + wxString m_PageLayoutDescrFile; - wxString m_PlotDirectoryName; + wxString m_PlotDirectoryName; - wxString m_NetFormatName; + wxString m_NetFormatName; - bool m_SpiceAdjustPassiveValues; - wxString m_SpiceCommandString; // A command string to run external spice + bool m_SpiceAdjustPassiveValues; + wxString m_SpiceCommandString; // A command string to run external spice - /// @see PROJECT_FILE::m_TemplateFieldNames - TEMPLATES* m_TemplateFieldNames; + TEMPLATES m_TemplateFieldNames; }; #endif diff --git a/include/project/project_file.h b/include/project/project_file.h index 84e01c7898..bfbd741885 100644 --- a/include/project/project_file.h +++ b/include/project/project_file.h @@ -137,17 +137,6 @@ public: // Schematic editing and misc settings: lifecycle managed by SCHEMATIC 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 wxString m_LegacyLibDir;