diff --git a/common/template_fieldnames.cpp b/common/template_fieldnames.cpp index 3511f02ded..022a7bb53a 100644 --- a/common/template_fieldnames.cpp +++ b/common/template_fieldnames.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2015-2022 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2015-2023 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 @@ -135,7 +135,7 @@ void TEMPLATES::Format( OUTPUTFORMATTER* out, int nestLevel, bool aGlobal ) cons } -void TEMPLATES::Parse( TEMPLATE_FIELDNAMES_LEXER* in, bool aGlobal ) +void TEMPLATES::parse( TEMPLATE_FIELDNAMES_LEXER* in, bool aGlobal ) { T tok; @@ -229,6 +229,20 @@ void TEMPLATES::AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName, bool } +void TEMPLATES::AddTemplateFieldNames( const wxString& aSerializedFieldNames ) +{ + TEMPLATE_FIELDNAMES_LEXER field_lexer( TO_UTF8( aSerializedFieldNames ) ); + + try + { + parse( &field_lexer, true ); + } + catch( const IO_ERROR& ) + { + } +} + + void TEMPLATES::DeleteAllFieldNameTemplates( bool aGlobal ) { if( aGlobal ) diff --git a/eeschema/dialogs/panel_template_fieldnames.cpp b/eeschema/dialogs/panel_template_fieldnames.cpp index 2ec3732ab2..e1ae83c94a 100644 --- a/eeschema/dialogs/panel_template_fieldnames.cpp +++ b/eeschema/dialogs/panel_template_fieldnames.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2009 Wayne Stambaugh - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 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 @@ -50,24 +50,8 @@ PANEL_TEMPLATE_FIELDNAMES::PANEL_TEMPLATE_FIELDNAMES( wxWindow* aWindow, EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings(); - if( cfg ) - { - // Read global fieldname templates - wxString templateFieldNames = cfg->m_Drawing.field_names; - - if( !templateFieldNames.IsEmpty() ) - { - TEMPLATE_FIELDNAMES_LEXER field_lexer( TO_UTF8( templateFieldNames ) ); - - try - { - m_templateMgr->Parse( &field_lexer, true ); - } - catch( const IO_ERROR& ) - { - } - } - } + if( cfg && !cfg->m_Drawing.field_names.IsEmpty() ) + m_templateMgr->AddTemplateFieldNames( cfg->m_Drawing.field_names ); } m_addFieldButton->SetBitmap( KiBitmap( BITMAPS::small_plus ) ); diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index cd20971232..92a9441c9a 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 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 @@ -1530,9 +1530,10 @@ void SCH_EDIT_FRAME::ShowAllIntersheetRefs( bool aShow ) void SCH_EDIT_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) { + SCH_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged ); + SCHEMATIC_SETTINGS& settings = Schematic().Settings(); - SCH_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged ); settings.m_JunctionSize = GetSchematicJunctionSize(); ShowAllIntersheetRefs( settings.m_IntersheetRefsShow ); @@ -1546,6 +1547,11 @@ void SCH_EDIT_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVars view->SetLayerVisible( LAYER_ERC_WARN, cfg->m_Appearance.show_erc_warnings ); view->SetLayerVisible( LAYER_ERC_EXCLUSION, cfg->m_Appearance.show_erc_exclusions ); + settings.m_TemplateFieldNames.DeleteAllFieldNameTemplates( true /* global */ ); + + if( !cfg->m_Drawing.field_names.IsEmpty() ) + settings.m_TemplateFieldNames.AddTemplateFieldNames( cfg->m_Drawing.field_names ); + SCH_SCREEN* screen = GetCurrentSheet().LastScreen(); for( SCH_ITEM* item : screen->Items() ) diff --git a/eeschema/schematic_settings.cpp b/eeschema/schematic_settings.cpp index b6b63f20fe..625333d8ef 100644 --- a/eeschema/schematic_settings.cpp +++ b/eeschema/schematic_settings.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2020 CERN - * Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2021-2023 KiCad Developers, see AUTHORS.txt for contributors. * @author Jon Evans * * This program is free software: you can redistribute it and/or modify it @@ -163,26 +163,11 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin } } + // Read global fieldname templates auto* cfg = Pgm().GetSettingsManager().GetAppSettings(); - if( cfg ) - { - // Read global fieldname templates - wxString templateFieldNames = cfg->m_Drawing.field_names; - - if( !templateFieldNames.IsEmpty() ) - { - TEMPLATE_FIELDNAMES_LEXER field_lexer( TO_UTF8( templateFieldNames ) ); - - try - { - m_TemplateFieldNames.Parse( &field_lexer, true ); - } - catch( const IO_ERROR& ) - { - } - } - } + if( cfg && !cfg->m_Drawing.field_names.IsEmpty() ) + m_TemplateFieldNames.AddTemplateFieldNames( cfg->m_Drawing.field_names ); }, {} ) ); m_params.emplace_back( new PARAM( "page_layout_descr_file", diff --git a/include/template_fieldnames.h b/include/template_fieldnames.h index ea4d8171ba..7f64c81468 100644 --- a/include/template_fieldnames.h +++ b/include/template_fieldnames.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2014-2022 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2014-2023 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 @@ -131,13 +131,6 @@ public: */ void Format( OUTPUTFORMATTER* out, int nestLevel, bool aGlobal ) const ; - /** - * Fill this object from information in the input stream handled by - * #TEMPLATE_FIELDNAMES_LEXER. - */ - void Parse( TEMPLATE_FIELDNAMES_LEXER* in, bool aGlobal ); - - /** * Insert or append a wanted symbol field name into the field names template. * @@ -150,6 +143,11 @@ public: */ void AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName, bool aGlobal ); + /** + * Add a serialized list of template field names. + */ + void AddTemplateFieldNames( const wxString& aSerializedFieldNames ); + /** * Delete the entire contents. */ @@ -176,6 +174,8 @@ public: protected: void resolveTemplates(); + void parse( TEMPLATE_FIELDNAMES_LEXER* in, bool aGlobal ); + private: TEMPLATE_FIELDNAMES m_globals; TEMPLATE_FIELDNAMES m_project;