2020-06-08 02:19:46 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 CERN
|
|
|
|
* @author Jon Evans <jon@craftyjon.com>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <base_screen.h>
|
|
|
|
#include <class_libentry.h>
|
|
|
|
#include <convert_to_biu.h>
|
|
|
|
#include <default_values.h>
|
|
|
|
#include <eda_text.h>
|
|
|
|
#include <eeschema_settings.h>
|
|
|
|
#include <kiface_i.h>
|
|
|
|
#include <schematic_settings.h>
|
|
|
|
#include <settings/parameters.h>
|
|
|
|
|
|
|
|
|
|
|
|
const int schSettingsSchemaVersion = 0;
|
|
|
|
|
|
|
|
|
|
|
|
SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
|
|
|
|
NESTED_SETTINGS( "schematic", schSettingsSchemaVersion, aParent, aPath ),
|
|
|
|
m_DefaultLineWidth( DEFAULT_LINE_THICKNESS * IU_PER_MILS ),
|
|
|
|
m_DefaultWireThickness( DEFAULT_WIRE_THICKNESS * IU_PER_MILS ),
|
|
|
|
m_DefaultBusThickness( DEFAULT_BUS_THICKNESS * IU_PER_MILS ),
|
|
|
|
m_DefaultTextSize( DEFAULT_TEXT_SIZE * IU_PER_MILS ),
|
|
|
|
m_TextOffsetRatio( 0.08 ),
|
|
|
|
m_PinSymbolSize( DEFAULT_TEXT_SIZE * IU_PER_MILS / 2 ),
|
|
|
|
m_JunctionSize( DEFAULT_JUNCTION_DIAM * IU_PER_MILS ),
|
2020-08-30 17:57:10 +00:00
|
|
|
m_SpiceAdjustPassiveValues( false )
|
2020-06-08 02:19:46 +00:00
|
|
|
{
|
|
|
|
EESCHEMA_SETTINGS* appSettings = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
|
|
|
|
|
|
|
|
int defaultLineThickness =
|
|
|
|
appSettings ? appSettings->m_Drawing.default_line_thickness : DEFAULT_LINE_THICKNESS;
|
|
|
|
int defaultWireThickness =
|
|
|
|
appSettings ? appSettings->m_Drawing.default_wire_thickness : DEFAULT_WIRE_THICKNESS;
|
|
|
|
int defaultBusThickness =
|
|
|
|
appSettings ? appSettings->m_Drawing.default_bus_thickness : DEFAULT_BUS_THICKNESS;
|
|
|
|
int defaultTextSize =
|
|
|
|
appSettings ? appSettings->m_Drawing.default_text_size : DEFAULT_TEXT_SIZE;
|
|
|
|
int defaultPinSymbolSize =
|
|
|
|
appSettings ? appSettings->m_Drawing.pin_symbol_size : DEFAULT_TEXT_SIZE / 2;
|
2020-07-07 19:05:15 +00:00
|
|
|
int defaultJunctionSize =
|
2020-07-08 00:44:24 +00:00
|
|
|
appSettings ? appSettings->m_Drawing.default_junction_size : DEFAULT_JUNCTION_DIAM;
|
2020-06-08 02:19:46 +00:00
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_line_thickness",
|
|
|
|
&m_DefaultLineWidth, Mils2iu( defaultLineThickness ),
|
|
|
|
Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
|
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_wire_thickness",
|
|
|
|
&m_DefaultWireThickness, Mils2iu( defaultWireThickness ),
|
|
|
|
Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
|
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_bus_thickness",
|
|
|
|
&m_DefaultBusThickness, Mils2iu( defaultBusThickness ),
|
|
|
|
Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
|
|
|
|
|
2020-08-30 16:46:01 +00:00
|
|
|
m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_text_size",
|
|
|
|
&m_DefaultTextSize,
|
2020-06-08 02:19:46 +00:00
|
|
|
Mils2iu( defaultTextSize ), Mils2iu( 5 ), Mils2iu( 1000 ),
|
|
|
|
1 / IU_PER_MILS ) );
|
|
|
|
|
2020-08-30 16:46:01 +00:00
|
|
|
m_params.emplace_back( new PARAM<double>( "drawing.text_offset_ratio",
|
|
|
|
&m_TextOffsetRatio,
|
2020-06-08 02:19:46 +00:00
|
|
|
(double) TXT_MARGIN / DEFAULT_SIZE_TEXT, -200.0, 200.0 ) );
|
|
|
|
|
2020-08-30 16:46:01 +00:00
|
|
|
m_params.emplace_back( new PARAM_SCALED<int>( "drawing.pin_symbol_size",
|
|
|
|
&m_PinSymbolSize,
|
2020-06-08 02:19:46 +00:00
|
|
|
Mils2iu( defaultPinSymbolSize ), Mils2iu( 5 ), Mils2iu( 1000 ),
|
|
|
|
1 / IU_PER_MILS ) );
|
|
|
|
|
2020-08-30 16:46:01 +00:00
|
|
|
m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_junction_size",
|
|
|
|
&m_JunctionSize,
|
2020-07-07 19:05:15 +00:00
|
|
|
Mils2iu( defaultJunctionSize ), Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
|
2020-06-08 02:19:46 +00:00
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "drawing.field_names",
|
|
|
|
[&]() -> nlohmann::json
|
|
|
|
{
|
|
|
|
nlohmann::json ret = nlohmann::json::array();
|
|
|
|
|
|
|
|
for( const TEMPLATE_FIELDNAME& field :
|
2020-08-30 17:57:10 +00:00
|
|
|
m_TemplateFieldNames.GetTemplateFieldNames( false ) )
|
2020-06-08 02:19:46 +00:00
|
|
|
{
|
|
|
|
ret.push_back( nlohmann::json( {
|
|
|
|
{ "name", field.m_Name },
|
|
|
|
{ "visible", field.m_Visible },
|
|
|
|
{ "url", field.m_URL }
|
|
|
|
} ) );
|
|
|
|
}
|
|
|
|
|
2020-08-30 17:57:10 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
[&]( const nlohmann::json& aJson )
|
|
|
|
{
|
2020-08-30 17:57:10 +00:00
|
|
|
if( aJson.empty() || !aJson.is_array() )
|
2020-06-08 02:19:46 +00:00
|
|
|
return;
|
|
|
|
|
2020-08-30 17:57:10 +00:00
|
|
|
m_TemplateFieldNames.DeleteAllFieldNameTemplates( false );
|
2020-06-08 02:19:46 +00:00
|
|
|
|
|
|
|
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>();
|
2020-08-30 17:57:10 +00:00
|
|
|
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& )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2020-06-08 02:19:46 +00:00
|
|
|
}
|
|
|
|
}, {} ) );
|
|
|
|
|
|
|
|
// TOOD(JE) get rid of this static
|
2020-08-30 16:46:01 +00:00
|
|
|
m_params.emplace_back( new PARAM<wxString>( "page_layout_descr_file",
|
|
|
|
&BASE_SCREEN::m_PageLayoutDescrFileName, "" ) );
|
2020-06-08 02:19:46 +00:00
|
|
|
|
2020-08-30 16:46:01 +00:00
|
|
|
m_params.emplace_back( new PARAM<wxString>( "plot_directory",
|
|
|
|
&m_PlotDirectoryName, "" ) );
|
2020-06-08 02:19:46 +00:00
|
|
|
|
2020-08-30 16:46:01 +00:00
|
|
|
m_params.emplace_back( new PARAM<wxString>( "net_format_name",
|
|
|
|
&m_NetFormatName, "" ) );
|
2020-06-08 02:19:46 +00:00
|
|
|
|
2020-08-30 16:46:01 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "spice_adjust_passive_values",
|
|
|
|
&m_SpiceAdjustPassiveValues, false ) );
|
2020-06-08 02:19:46 +00:00
|
|
|
|
2020-08-04 10:51:56 +00:00
|
|
|
m_params.emplace_back( new PARAM<wxString>( "spice_external_command",
|
2020-08-30 16:46:01 +00:00
|
|
|
&m_SpiceCommandString, "spice \"%I\"" ) );
|
2020-08-04 10:51:56 +00:00
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
// TODO(JE) should we keep these LIB_PART:: things around?
|
2020-08-30 16:46:01 +00:00
|
|
|
m_params.emplace_back( new PARAM<int>( "subpart_id_separator",
|
|
|
|
LIB_PART::SubpartIdSeparatorPtr(), 0, 0, 126 ) );
|
2020-06-08 02:19:46 +00:00
|
|
|
|
2020-08-30 16:46:01 +00:00
|
|
|
m_params.emplace_back( new PARAM<int>( "subpart_first_id",
|
|
|
|
LIB_PART::SubpartFirstIdPtr(), 'A', '1', 'z' ) );
|
2020-06-08 02:19:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCHEMATIC_SETTINGS::~SCHEMATIC_SETTINGS()
|
|
|
|
{
|
|
|
|
if( m_parent )
|
|
|
|
{
|
|
|
|
m_parent->ReleaseNestedSettings( this );
|
|
|
|
m_parent = nullptr;
|
|
|
|
}
|
|
|
|
}
|