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
This commit is contained in:
Jeff Young 2020-11-21 23:09:57 +00:00
parent 3a4bd6fb8b
commit a9271e43cc
5 changed files with 32 additions and 239 deletions

View File

@ -58,8 +58,6 @@
#include <sch_line.h>
#include <lib_pin.h>
#include <sch_draw_panel.h>
#include <class_libentry.h>
#include <eeschema_config.h>
#include <kiface_i.h>
#include <vector>
#include <algorithm>

View File

@ -29,6 +29,7 @@
#include <bitmaps.h>
#include <schematic.h>
#include <panel_eeschema_template_fieldnames.h>
#include <kiface_i.h>
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<EESCHEMA_SETTINGS*>( 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;
}

View File

@ -30,8 +30,6 @@
#include <dialogs/panel_sym_color_settings.h>
#include <dialogs/panel_sym_editing_options.h>
#include <dialogs/dialog_schematic_setup.h>
#include <eeschema_config.h>
#include <erc_settings.h>
#include <kiway.h>
#include <symbol_edit_frame.h>
#include <panel_gal_display_options.h>
@ -50,157 +48,6 @@
#include <page_layout/ws_data_model.h>
#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 )
{

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef EESCHEMA_CONFIG_H
#define EESCHEMA_CONFIG_H
#include <config_params.h>
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

View File

@ -135,40 +135,25 @@ 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;
},
[&]( 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;
m_TemplateFieldNames.DeleteAllFieldNameTemplates( false );
TEMPLATE_FIELDNAME field( entry["name"].get<wxString>() );
field.m_URL = entry["url"].get<bool>();
field.m_Visible = entry["visible"].get<bool>();
m_TemplateFieldNames.AddTemplateFieldName( field, false );
for( const nlohmann::json& entry : aJson )
{
if( !entry.contains( "name" ) || !entry.contains( "url" )
|| !entry.contains( "visible" ) )
continue;
TEMPLATE_FIELDNAME field( entry["name"].get<wxString>() );
field.m_URL = entry["url"].get<bool>();
field.m_Visible = entry["visible"].get<bool>();
m_TemplateFieldNames.AddTemplateFieldName( field, false );
}
}
auto* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );