From a9271e43ccd9d5c7e35e8d73ac86d4126638db9a Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 21 Nov 2020 23:09:57 +0000 Subject: [PATCH] Read global fieldNameTemplates for project but don't write them. Writing responsibility goes to the preferences dialog handler. Fixes https://gitlab.com/kicad/code/kicad/issues/6450 --- eeschema/autoplace_fields.cpp | 2 - .../panel_eeschema_template_fieldnames.cpp | 19 +++ eeschema/eeschema_config.cpp | 160 ------------------ eeschema/eeschema_config.h | 49 ------ eeschema/schematic_settings.cpp | 43 ++--- 5 files changed, 33 insertions(+), 240 deletions(-) delete mode 100644 eeschema/eeschema_config.h diff --git a/eeschema/autoplace_fields.cpp b/eeschema/autoplace_fields.cpp index 5f2191f491..5426fcd6f5 100644 --- a/eeschema/autoplace_fields.cpp +++ b/eeschema/autoplace_fields.cpp @@ -58,8 +58,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/eeschema/dialogs/panel_eeschema_template_fieldnames.cpp b/eeschema/dialogs/panel_eeschema_template_fieldnames.cpp index 2851a76244..906bfe6007 100644 --- a/eeschema/dialogs/panel_eeschema_template_fieldnames.cpp +++ b/eeschema/dialogs/panel_eeschema_template_fieldnames.cpp @@ -29,6 +29,7 @@ #include #include #include +#include PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::PANEL_EESCHEMA_TEMPLATE_FIELDNAMES( SCH_EDIT_FRAME* aFrame, wxWindow* aWindow, @@ -172,6 +173,24 @@ bool PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::TransferDataFromWindow() for( const TEMPLATE_FIELDNAME& field : m_fields ) schematic.Settings().m_TemplateFieldNames.AddTemplateFieldName( field, m_global ); + if( m_global ) + { + auto* cfg = dynamic_cast( Kiface().KifaceSettings() ); + + if( cfg ) + { + // Save global fieldname templates + STRING_FORMATTER sf; + schematic.Settings().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 true; } diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index cfcd068bac..25153c3a31 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -30,8 +30,6 @@ #include #include #include -#include -#include #include #include #include @@ -50,157 +48,6 @@ #include -#define FieldNameTemplatesKey wxT( "FieldNameTemplates" ) - - -PARAM_CFG_FIELDNAMES::PARAM_CFG_FIELDNAMES( TEMPLATES * ptparam, const wxChar* group ) : - PARAM_CFG( wxEmptyString, PARAM_SEVERITIES, group ) -{ - m_Pt_param = ptparam; -} - -void PARAM_CFG_FIELDNAMES::ReadParam( wxConfigBase* aConfig ) const -{ - if( !m_Pt_param || !aConfig ) - return; - - wxString templateFieldNames = aConfig->Read( FieldNameTemplatesKey, wxEmptyString ); - - if( !templateFieldNames.IsEmpty() ) - { - TEMPLATE_FIELDNAMES_LEXER lexer( TO_UTF8( templateFieldNames ) ); - - try - { - m_Pt_param->Parse( &lexer, false ); - } - catch( const IO_ERROR& ) - { - // @todo show error msg - } - } -} - -void PARAM_CFG_FIELDNAMES::SaveParam( wxConfigBase* aConfig ) const -{ - if( !m_Pt_param || !aConfig ) - return; - - STRING_FORMATTER sf; - m_Pt_param->Format( &sf, 0, false ); - - 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 - - aConfig->Write( FieldNameTemplatesKey, record ); -} - - -class PARAM_CFG_SEVERITIES : public PARAM_CFG -{ -protected: - ERC_SETTINGS* m_Pt_param; ///< Pointer to the parameter value - -public: - PARAM_CFG_SEVERITIES( ERC_SETTINGS* ptparam, const wxChar* group = nullptr ) : - PARAM_CFG( wxEmptyString, PARAM_SEVERITIES, group ) - { - m_Pt_param = ptparam; - } - - void ReadParam( wxConfigBase* aConfig ) const override - { - if( !m_Pt_param || !aConfig ) - return; - - wxString oldPath = aConfig->GetPath(); - - // Read legacy settings first so that modern settings will overwrite them - bool flag; - - if( aConfig->Read( wxT( "ERC_TestSimilarLabels" ), &flag, true ) ) - { - if( flag ) - m_Pt_param->m_Severities[ ERCE_SIMILAR_LABELS ] = RPT_SEVERITY_WARNING; - else - m_Pt_param->m_Severities[ ERCE_SIMILAR_LABELS ] = RPT_SEVERITY_IGNORE; - } - - if( aConfig->Read( wxT( "ERC_CheckUniqueGlobalLabels" ), &flag, true ) ) - { - if( flag ) - m_Pt_param->m_Severities[ ERCE_GLOBLABEL ] = RPT_SEVERITY_WARNING; - else - m_Pt_param->m_Severities[ ERCE_GLOBLABEL ] = RPT_SEVERITY_IGNORE; - } - - if( aConfig->Read( wxT( "ERC_CheckBusDriverConflicts" ), &flag, true ) ) - { - if( flag ) - m_Pt_param->m_Severities[ ERCE_DRIVER_CONFLICT ] = RPT_SEVERITY_WARNING; - else - m_Pt_param->m_Severities[ ERCE_DRIVER_CONFLICT ] = RPT_SEVERITY_IGNORE; - } - - if( aConfig->Read( wxT( "ERC_CheckBusEntryConflicts" ), &flag, true ) ) - { - if( flag ) - m_Pt_param->m_Severities[ ERCE_BUS_ENTRY_CONFLICT ] = RPT_SEVERITY_WARNING; - else - m_Pt_param->m_Severities[ ERCE_BUS_ENTRY_CONFLICT ] = RPT_SEVERITY_IGNORE; - } - - if( aConfig->Read( wxT( "ERC_CheckBusToBusConflicts" ), &flag, true ) ) - { - if( flag ) - m_Pt_param->m_Severities[ ERCE_BUS_TO_BUS_CONFLICT ] = RPT_SEVERITY_ERROR; - else - m_Pt_param->m_Severities[ ERCE_BUS_TO_BUS_CONFLICT ] = RPT_SEVERITY_IGNORE; - } - - if( aConfig->Read( wxT( "ERC_CheckBusToNetConflicts" ), &flag, true ) ) - { - if( flag ) - m_Pt_param->m_Severities[ ERCE_BUS_TO_NET_CONFLICT ] = RPT_SEVERITY_ERROR; - else - m_Pt_param->m_Severities[ ERCE_BUS_TO_NET_CONFLICT ] = RPT_SEVERITY_IGNORE; - } - - // TO DO: figure out what we're going to use as keys here so we can read/write these.... - - aConfig->SetPath( oldPath ); - } - - void SaveParam( wxConfigBase* aConfig ) const override - { - if( !m_Pt_param || !aConfig ) - return; - - wxString oldPath = aConfig->GetPath(); - - // TO DO: figure out what we're going to use as keys here so we can read/write these.... - - // TO DO: for now just write out the legacy ones so we don't lose them - // TO DO: remove this once the new scheme is in place - aConfig->Write( wxT( "ERC_TestSimilarLabels" ), - m_Pt_param->IsTestEnabled( ERCE_SIMILAR_LABELS ) ); - aConfig->Write( wxT( "ERC_CheckUniqueGlobalLabels" ), - m_Pt_param->IsTestEnabled( ERCE_GLOBLABEL ) ); - aConfig->Write( wxT( "ERC_CheckBusDriverConflicts" ), - m_Pt_param->IsTestEnabled( ERCE_DRIVER_CONFLICT ) ); - aConfig->Write( wxT( "ERC_CheckBusEntryConflicts" ), - m_Pt_param->IsTestEnabled( ERCE_BUS_ENTRY_CONFLICT ) ); - aConfig->Write( wxT( "ERC_CheckBusToBusConflicts" ), - m_Pt_param->IsTestEnabled( ERCE_BUS_TO_BUS_CONFLICT ) ); - aConfig->Write( wxT( "ERC_CheckBusToNetConflicts" ), - m_Pt_param->IsTestEnabled( ERCE_BUS_TO_NET_CONFLICT ) ); - - aConfig->SetPath( oldPath ); - } -}; - - /// Helper for all the old plotting/printing code while it still exists COLOR4D GetLayerColor( SCH_LAYER_ID aLayer ) { @@ -208,13 +55,6 @@ COLOR4D GetLayerColor( SCH_LAYER_ID aLayer ) } -// Color to draw items flagged invisible, in symbol_editor (they are invisible in Eeschema) -COLOR4D GetInvisibleItemColor() -{ - return COLOR4D( DARKGRAY ); -} - - void SCH_EDIT_FRAME::InstallPreferences( PAGED_DIALOG* aParent, PANEL_HOTKEYS_EDITOR* aHotkeysPanel ) { diff --git a/eeschema/eeschema_config.h b/eeschema/eeschema_config.h deleted file mode 100644 index 8b6e5a2405..0000000000 --- a/eeschema/eeschema_config.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2009-2018 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 as published by the - * Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#ifndef EESCHEMA_CONFIG_H -#define EESCHEMA_CONFIG_H - -#include - -extern const wxChar RescueNeverShowEntry[]; -extern const wxChar AutoplaceFieldsEntry[]; -extern const wxChar AutoplaceJustifyEntry[]; -extern const wxChar AutoplaceAlignEntry[]; -extern const wxChar LibIconScaleEntry[]; -extern const wxChar SchIconScaleEntry[]; - -class TEMPLATES; - - -class PARAM_CFG_FIELDNAMES : public PARAM_CFG -{ -protected: - TEMPLATES* m_Pt_param; ///< Pointer to the parameter value - -public: - PARAM_CFG_FIELDNAMES( TEMPLATES* ptparam, const wxChar* group = nullptr ); - - void ReadParam( wxConfigBase* aConfig ) const override; - void SaveParam( wxConfigBase* aConfig ) const override; -}; - - - -#endif // EESCHEMA_CONFIG_H diff --git a/eeschema/schematic_settings.cpp b/eeschema/schematic_settings.cpp index a2ddc4bc75..cab3caa576 100644 --- a/eeschema/schematic_settings.cpp +++ b/eeschema/schematic_settings.cpp @@ -135,40 +135,25 @@ 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( aJson.empty() || !aJson.is_array() ) - return; - - m_TemplateFieldNames.DeleteAllFieldNameTemplates( false ); - - for( const nlohmann::json& entry : aJson ) + if( !aJson.empty() && aJson.is_array() ) { - if( !entry.contains( "name" ) || !entry.contains( "url" ) - || !entry.contains( "visible" ) ) - continue; - - 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.DeleteAllFieldNameTemplates( false ); + + for( const nlohmann::json& entry : aJson ) + { + if( !entry.contains( "name" ) || !entry.contains( "url" ) + || !entry.contains( "visible" ) ) + continue; + + TEMPLATE_FIELDNAME field( entry["name"].get() ); + field.m_URL = entry["url"].get(); + field.m_Visible = entry["visible"].get(); + m_TemplateFieldNames.AddTemplateFieldName( field, false ); + } } auto* cfg = dynamic_cast( Kiface().KifaceSettings() );