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
|
2023-01-23 23:40:58 +00:00
|
|
|
* Copyright (C) 2021-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-06-08 02:19:46 +00:00
|
|
|
* @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>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <lib_symbol.h>
|
2020-06-08 02:19:46 +00:00
|
|
|
#include <default_values.h>
|
|
|
|
#include <eeschema_settings.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <macros.h>
|
2022-08-31 09:35:27 +00:00
|
|
|
#include <pgm_base.h>
|
2020-06-08 02:19:46 +00:00
|
|
|
#include <schematic_settings.h>
|
2021-06-04 03:52:50 +00:00
|
|
|
#include <settings/json_settings_internals.h>
|
2020-06-08 02:19:46 +00:00
|
|
|
#include <settings/parameters.h>
|
2022-08-31 09:35:27 +00:00
|
|
|
#include <settings/settings_manager.h>
|
2023-03-27 20:48:37 +00:00
|
|
|
#include <settings/bom_settings.h>
|
2021-03-19 13:04:28 +00:00
|
|
|
#include <sim/spice_settings.h>
|
2020-06-08 02:19:46 +00:00
|
|
|
|
|
|
|
|
2021-07-25 11:42:19 +00:00
|
|
|
const int schSettingsSchemaVersion = 1;
|
2020-06-08 02:19:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
|
|
|
|
NESTED_SETTINGS( "schematic", schSettingsSchemaVersion, aParent, aPath ),
|
2022-09-16 23:25:07 +00:00
|
|
|
m_DefaultLineWidth( DEFAULT_LINE_WIDTH_MILS * schIUScale.IU_PER_MILS ),
|
|
|
|
m_DefaultTextSize( DEFAULT_TEXT_SIZE * schIUScale.IU_PER_MILS ),
|
2021-07-25 11:42:19 +00:00
|
|
|
m_LabelSizeRatio( DEFAULT_LABEL_SIZE_RATIO ),
|
2020-11-17 16:02:47 +00:00
|
|
|
m_TextOffsetRatio( DEFAULT_TEXT_OFFSET_RATIO ),
|
2022-09-16 23:25:07 +00:00
|
|
|
m_PinSymbolSize( DEFAULT_TEXT_SIZE * schIUScale.IU_PER_MILS / 2 ),
|
2020-11-11 00:18:35 +00:00
|
|
|
m_JunctionSizeChoice( 3 ),
|
2022-09-16 23:25:07 +00:00
|
|
|
m_JunctionSize( DEFAULT_JUNCTION_DIAM * schIUScale.IU_PER_MILS ),
|
2021-07-02 14:11:26 +00:00
|
|
|
m_AnnotateStartNum( 0 ),
|
2020-11-17 16:02:47 +00:00
|
|
|
m_IntersheetRefsShow( false ),
|
2021-03-04 21:29:41 +00:00
|
|
|
m_IntersheetRefsListOwnPage( true ),
|
2020-11-17 16:02:47 +00:00
|
|
|
m_IntersheetRefsFormatShort( false ),
|
|
|
|
m_IntersheetRefsPrefix( DEFAULT_IREF_PREFIX ),
|
|
|
|
m_IntersheetRefsSuffix( DEFAULT_IREF_SUFFIX ),
|
2021-12-25 14:00:57 +00:00
|
|
|
m_DashedLineDashRatio( 12.0 ),
|
2021-08-25 23:14:36 +00:00
|
|
|
m_DashedLineGapRatio( 3.0 ),
|
2023-02-09 17:18:56 +00:00
|
|
|
m_OPO_VPrecision( 3 ),
|
|
|
|
m_OPO_VRange( wxS( "~V" ) ),
|
|
|
|
m_OPO_IPrecision( 3 ),
|
|
|
|
m_OPO_IRange( wxS( "~A" ) ),
|
2022-09-09 13:34:56 +00:00
|
|
|
m_SpiceCurSheetAsRoot( false ),
|
2022-04-12 14:37:06 +00:00
|
|
|
m_SpiceSaveAllVoltages( false ),
|
|
|
|
m_SpiceSaveAllCurrents( false ),
|
2023-02-10 20:52:52 +00:00
|
|
|
m_SpiceSaveAllDissipations( false ),
|
2022-09-09 13:34:56 +00:00
|
|
|
m_SpiceModelCurSheetAsRoot( true ),
|
2023-07-14 09:21:58 +00:00
|
|
|
m_NgspiceSettings( nullptr )
|
2020-06-08 02:19:46 +00:00
|
|
|
{
|
2022-08-31 09:35:27 +00:00
|
|
|
EESCHEMA_SETTINGS* appSettings = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
|
2020-06-08 02:19:46 +00:00
|
|
|
|
|
|
|
int defaultLineThickness =
|
2021-08-25 18:36:37 +00:00
|
|
|
appSettings ? appSettings->m_Drawing.default_line_thickness : DEFAULT_LINE_WIDTH_MILS;
|
2020-06-08 02:19:46 +00:00
|
|
|
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-10-08 17:04:53 +00:00
|
|
|
int defaultJunctionSizeChoice =
|
2020-11-11 00:18:35 +00:00
|
|
|
appSettings ? appSettings->m_Drawing.junction_size_choice : 3;
|
2020-08-31 14:11:54 +00:00
|
|
|
bool defaultIntersheetsRefShow =
|
|
|
|
appSettings ? appSettings->m_Drawing.intersheets_ref_show : false;
|
2021-03-04 21:29:41 +00:00
|
|
|
bool defaultIntersheetsRefOwnPage =
|
|
|
|
appSettings ? appSettings->m_Drawing.intersheets_ref_own_page : true;
|
2020-08-31 14:11:54 +00:00
|
|
|
bool defaultIntersheetsRefFormatShort =
|
|
|
|
appSettings ? appSettings->m_Drawing.intersheets_ref_short : false;
|
|
|
|
wxString defaultIntersheetsRefPrefix =
|
2023-01-16 01:22:17 +00:00
|
|
|
appSettings ? appSettings->m_Drawing.intersheets_ref_prefix : wxString( wxS( DEFAULT_IREF_PREFIX ) );
|
2020-08-31 14:11:54 +00:00
|
|
|
wxString defaultIntersheetsRefSuffix =
|
2023-01-16 01:22:17 +00:00
|
|
|
appSettings ? appSettings->m_Drawing.intersheets_ref_suffix : wxString( wxS( DEFAULT_IREF_SUFFIX ) );
|
2020-08-31 14:11:54 +00:00
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<bool>( "drawing.intersheets_ref_show",
|
2020-11-17 16:02:47 +00:00
|
|
|
&m_IntersheetRefsShow, defaultIntersheetsRefShow ) );
|
2020-08-31 14:11:54 +00:00
|
|
|
|
2021-03-04 21:29:41 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "drawing.intersheets_ref_own_page",
|
|
|
|
&m_IntersheetRefsListOwnPage, defaultIntersheetsRefOwnPage ) );
|
|
|
|
|
2020-08-31 14:11:54 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "drawing.intersheets_ref_short",
|
2020-11-17 16:02:47 +00:00
|
|
|
&m_IntersheetRefsFormatShort, defaultIntersheetsRefFormatShort ) );
|
2020-08-31 14:11:54 +00:00
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<wxString>( "drawing.intersheets_ref_prefix",
|
2020-11-17 16:02:47 +00:00
|
|
|
&m_IntersheetRefsPrefix, defaultIntersheetsRefPrefix ) );
|
2020-08-31 14:11:54 +00:00
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<wxString>( "drawing.intersheets_ref_suffix",
|
2020-11-17 16:02:47 +00:00
|
|
|
&m_IntersheetRefsSuffix, defaultIntersheetsRefSuffix ) );
|
2020-06-08 02:19:46 +00:00
|
|
|
|
2021-07-22 23:05:01 +00:00
|
|
|
m_params.emplace_back( new PARAM<double>( "drawing.dashed_lines_dash_length_ratio",
|
2021-12-25 14:00:57 +00:00
|
|
|
&m_DashedLineDashRatio, 12.0 ) ); // Default from ISO 128-2
|
2021-07-22 23:05:01 +00:00
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<double>( "drawing.dashed_lines_gap_length_ratio",
|
2021-12-25 14:00:57 +00:00
|
|
|
&m_DashedLineGapRatio, 3.0 ) ); // Default from ISO 128-2
|
2021-07-22 23:05:01 +00:00
|
|
|
|
2023-02-09 17:18:56 +00:00
|
|
|
m_params.emplace_back( new PARAM<int>( "drawing.operating_point_overlay_v_precision",
|
|
|
|
&m_OPO_VPrecision, 3 ) );
|
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<wxString>( "drawing.operating_point_overlay_v_range",
|
|
|
|
&m_OPO_VRange, wxS( "~V" ) ) );
|
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<int>( "drawing.operating_point_overlay_i_precision",
|
2023-02-13 18:07:58 +00:00
|
|
|
&m_OPO_IPrecision, 3 ) );
|
2023-02-09 17:18:56 +00:00
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<wxString>( "drawing.operating_point_overlay_i_range",
|
2023-02-13 18:07:58 +00:00
|
|
|
&m_OPO_IRange, wxS( "~A" ) ) );
|
2023-02-09 17:18:56 +00:00
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_line_thickness",
|
2022-09-16 23:42:20 +00:00
|
|
|
&m_DefaultLineWidth, schIUScale.MilsToIU( defaultLineThickness ), schIUScale.MilsToIU( 5 ), schIUScale.MilsToIU( 1000 ),
|
2022-09-16 23:25:07 +00:00
|
|
|
1 / schIUScale.IU_PER_MILS ) );
|
2020-06-08 02:19:46 +00:00
|
|
|
|
2020-08-30 16:46:01 +00:00
|
|
|
m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_text_size",
|
2022-09-16 23:42:20 +00:00
|
|
|
&m_DefaultTextSize, schIUScale.MilsToIU( defaultTextSize ), schIUScale.MilsToIU( 5 ), schIUScale.MilsToIU( 1000 ),
|
2022-09-16 23:25:07 +00:00
|
|
|
1 / schIUScale.IU_PER_MILS ) );
|
2020-06-08 02:19:46 +00:00
|
|
|
|
2020-08-30 16:46:01 +00:00
|
|
|
m_params.emplace_back( new PARAM<double>( "drawing.text_offset_ratio",
|
2021-07-25 11:42:19 +00:00
|
|
|
&m_TextOffsetRatio, DEFAULT_TEXT_OFFSET_RATIO, 0.0, 2.0 ) );
|
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<double>( "drawing.label_size_ratio",
|
|
|
|
&m_LabelSizeRatio, DEFAULT_LABEL_SIZE_RATIO, 0.0, 2.0 ) );
|
2020-06-08 02:19:46 +00:00
|
|
|
|
2023-08-06 19:20:53 +00:00
|
|
|
m_params.emplace_back( new PARAM<double>( "drawing.overbar_offset_ratio",
|
|
|
|
&m_FontMetrics.m_OverbarHeight, m_FontMetrics.m_OverbarHeight ) );
|
|
|
|
|
2020-08-30 16:46:01 +00:00
|
|
|
m_params.emplace_back( new PARAM_SCALED<int>( "drawing.pin_symbol_size",
|
2022-09-16 23:42:20 +00:00
|
|
|
&m_PinSymbolSize, schIUScale.MilsToIU( defaultPinSymbolSize ), schIUScale.MilsToIU( 0 ), schIUScale.MilsToIU( 1000 ),
|
2022-09-16 23:25:07 +00:00
|
|
|
1 / schIUScale.IU_PER_MILS ) );
|
2020-06-08 02:19:46 +00:00
|
|
|
|
2021-09-02 11:40:45 +00:00
|
|
|
// m_JunctionSize is only a run-time cache of the calculated size. Do not save it.
|
2020-06-08 02:19:46 +00:00
|
|
|
|
2020-11-11 00:18:35 +00:00
|
|
|
// User choice for junction dot size ( e.g. none = 0, smallest = 1, small = 2, etc )
|
2021-06-21 01:41:15 +00:00
|
|
|
m_params.emplace_back( new PARAM<int>( "drawing.junction_size_choice",
|
|
|
|
&m_JunctionSizeChoice,
|
|
|
|
defaultJunctionSizeChoice ) );
|
2020-10-08 17:04:53 +00:00
|
|
|
|
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 }
|
|
|
|
} ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
[&]( const nlohmann::json& aJson )
|
|
|
|
{
|
2020-11-21 23:09:57 +00:00
|
|
|
if( !aJson.empty() && aJson.is_array() )
|
2020-06-08 02:19:46 +00:00
|
|
|
{
|
2020-11-21 23:09:57 +00:00
|
|
|
m_TemplateFieldNames.DeleteAllFieldNameTemplates( false );
|
|
|
|
|
|
|
|
for( const nlohmann::json& entry : aJson )
|
|
|
|
{
|
|
|
|
if( !entry.contains( "name" ) || !entry.contains( "url" )
|
|
|
|
|| !entry.contains( "visible" ) )
|
2021-09-01 18:05:46 +00:00
|
|
|
{
|
2020-11-21 23:09:57 +00:00
|
|
|
continue;
|
2021-09-01 18:05:46 +00:00
|
|
|
}
|
2020-11-21 23:09:57 +00:00
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
2020-08-30 17:57:10 +00:00
|
|
|
}
|
|
|
|
|
2023-01-23 23:40:58 +00:00
|
|
|
// Read global fieldname templates
|
2022-08-31 09:35:27 +00:00
|
|
|
auto* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
|
2020-08-30 17:57:10 +00:00
|
|
|
|
2023-01-23 23:40:58 +00:00
|
|
|
if( cfg && !cfg->m_Drawing.field_names.IsEmpty() )
|
|
|
|
m_TemplateFieldNames.AddTemplateFieldNames( cfg->m_Drawing.field_names );
|
2020-06-08 02:19:46 +00:00
|
|
|
}, {} ) );
|
|
|
|
|
2023-08-06 19:20:53 +00:00
|
|
|
m_params.emplace_back( new PARAM<BOM_PRESET>( "bom_settings",
|
|
|
|
&m_BomSettings, BOM_PRESET::GroupedByValue() ) );
|
|
|
|
m_params.emplace_back( new PARAM_LIST<BOM_PRESET>( "bom_presets",
|
|
|
|
&m_BomPresets, {} ) );
|
2023-03-27 20:48:37 +00:00
|
|
|
|
2023-08-06 19:20:53 +00:00
|
|
|
m_params.emplace_back( new PARAM<BOM_FMT_PRESET>( "bom_fmt_settings",
|
|
|
|
&m_BomFmtSettings, BOM_FMT_PRESET::CSV() ) );
|
|
|
|
m_params.emplace_back( new PARAM_LIST<BOM_FMT_PRESET>( "bom_fmt_presets",
|
|
|
|
&m_BomFmtPresets, {} ) );
|
2023-03-27 20:48:37 +00:00
|
|
|
|
2020-08-30 16:46:01 +00:00
|
|
|
m_params.emplace_back( new PARAM<wxString>( "page_layout_descr_file",
|
2022-08-31 09:35:27 +00:00
|
|
|
&m_SchDrawingSheetFileName, "" ) );
|
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
|
|
|
|
2023-01-23 22:56:06 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "spice_current_sheet_as_root",
|
|
|
|
&m_SpiceCurSheetAsRoot, false ) );
|
2020-06-08 02:19:46 +00:00
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "spice_save_all_voltages",
|
|
|
|
&m_SpiceSaveAllVoltages, false ) );
|
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<bool>( "spice_save_all_currents",
|
|
|
|
&m_SpiceSaveAllCurrents, false ) );
|
|
|
|
|
2023-02-10 20:52:52 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "spice_save_all_dissipations",
|
|
|
|
&m_SpiceSaveAllDissipations, false ) );
|
|
|
|
|
2023-01-23 22:56:06 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "spice_model_current_sheet_as_root",
|
|
|
|
&m_SpiceModelCurSheetAsRoot, true ) );
|
|
|
|
|
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
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
// TODO(JE) should we keep these LIB_SYMBOL:: things around?
|
2020-08-30 16:46:01 +00:00
|
|
|
m_params.emplace_back( new PARAM<int>( "subpart_id_separator",
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL::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",
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL::SubpartFirstIdPtr(), 'A', '1', 'z' ) );
|
2021-03-18 19:31:02 +00:00
|
|
|
|
2021-06-21 01:41:15 +00:00
|
|
|
m_params.emplace_back( new PARAM<int>( "annotate_start_num",
|
|
|
|
&m_AnnotateStartNum, 0 ) );
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
m_NgspiceSettings = std::make_shared<NGSPICE_SETTINGS>( this, "ngspice" );
|
2021-07-25 11:42:19 +00:00
|
|
|
|
2022-08-15 22:43:30 +00:00
|
|
|
registerMigration( 0, 1,
|
|
|
|
[&]() -> bool
|
|
|
|
{
|
2022-08-25 22:50:47 +00:00
|
|
|
std::optional<double> tor = Get<double>( "drawing.text_offset_ratio" );
|
2021-07-25 11:42:19 +00:00
|
|
|
|
2022-08-25 22:50:47 +00:00
|
|
|
if( tor )
|
2022-08-30 20:58:43 +00:00
|
|
|
Set( "drawing.label_size_ratio", *tor );
|
2021-07-25 11:42:19 +00:00
|
|
|
|
2022-08-15 22:43:30 +00:00
|
|
|
return true;
|
|
|
|
} );
|
2020-06-08 02:19:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCHEMATIC_SETTINGS::~SCHEMATIC_SETTINGS()
|
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
ReleaseNestedSettings( m_NgspiceSettings.get() );
|
|
|
|
m_NgspiceSettings.reset();
|
2021-03-19 23:04:27 +00:00
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
if( m_parent )
|
|
|
|
{
|
|
|
|
m_parent->ReleaseNestedSettings( this );
|
|
|
|
m_parent = nullptr;
|
|
|
|
}
|
|
|
|
}
|