KiCad PCB EDA Suite
Loading...
Searching...
No Matches
schematic_settings.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2020 CERN
5 * Copyright (C) 2021-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Jon Evans <[email protected]>
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include <base_screen.h>
23#include <lib_symbol.h>
24#include <default_values.h>
25#include <eeschema_settings.h>
26#include <macros.h>
27#include <pgm_base.h>
28#include <schematic_settings.h>
30#include <settings/parameters.h>
33#include <sim/spice_settings.h>
34
35
37
38
39SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
40 NESTED_SETTINGS( "schematic", schSettingsSchemaVersion, aParent, aPath, false ),
41 m_DefaultLineWidth( DEFAULT_LINE_WIDTH_MILS * schIUScale.IU_PER_MILS ),
42 m_DefaultTextSize( DEFAULT_TEXT_SIZE * schIUScale.IU_PER_MILS ),
43 m_LabelSizeRatio( DEFAULT_LABEL_SIZE_RATIO ),
44 m_TextOffsetRatio( DEFAULT_TEXT_OFFSET_RATIO ),
45 m_PinSymbolSize( DEFAULT_TEXT_SIZE * schIUScale.IU_PER_MILS / 2 ),
46 m_JunctionSizeChoice( 3 ),
48 m_ConnectionGridSize( DEFAULT_CONNECTION_GRID_MILS * schIUScale.IU_PER_MILS ),
49 m_AnnotateStartNum( 0 ),
50 m_IntersheetRefsShow( false ),
51 m_IntersheetRefsListOwnPage( true ),
52 m_IntersheetRefsFormatShort( false ),
53 m_IntersheetRefsPrefix( DEFAULT_IREF_PREFIX ),
54 m_IntersheetRefsSuffix( DEFAULT_IREF_SUFFIX ),
55 m_DashedLineDashRatio( 12.0 ),
56 m_DashedLineGapRatio( 3.0 ),
57 m_OPO_VPrecision( 3 ),
58 m_OPO_VRange( wxS( "~V" ) ),
59 m_OPO_IPrecision( 3 ),
60 m_OPO_IRange( wxS( "~A" ) ),
61 m_SpiceCurSheetAsRoot( false ),
62 m_SpiceSaveAllVoltages( false ),
63 m_SpiceSaveAllCurrents( false ),
64 m_SpiceSaveAllDissipations( false ),
65 m_SpiceSaveAllEvents( true ),
66 m_SpiceModelCurSheetAsRoot( true ),
67 m_NgspiceSettings( nullptr )
68{
70 EESCHEMA_SETTINGS* cfg = mgr.GetAppSettings<EESCHEMA_SETTINGS>( "eeschema" );
71
72 int defaultLineThickness = cfg ? cfg->m_Drawing.default_line_thickness : DEFAULT_LINE_WIDTH_MILS;
73 int defaultTextSize = cfg ? cfg->m_Drawing.default_text_size : DEFAULT_TEXT_SIZE;
74 int defaultPinSymbolSize = cfg ? cfg->m_Drawing.pin_symbol_size : DEFAULT_TEXT_SIZE / 2;
75 int defaultJunctionSizeChoice = cfg ? cfg->m_Drawing.junction_size_choice : 3;
76 bool defaultIntersheetsRefShow = cfg ? cfg->m_Drawing.intersheets_ref_show : false;
77 bool defaultIntersheetsRefOwnPage = cfg ? cfg->m_Drawing.intersheets_ref_own_page : true;
78 bool defaultIntersheetsRefFormatShort = cfg ? cfg->m_Drawing.intersheets_ref_short : false;
79 wxString defaultIntersheetsRefPrefix = cfg ? cfg->m_Drawing.intersheets_ref_prefix
80 : wxString( wxS( DEFAULT_IREF_PREFIX ) );
81 wxString defaultIntersheetsRefSuffix = cfg ? cfg->m_Drawing.intersheets_ref_suffix
82 : wxString( wxS( DEFAULT_IREF_SUFFIX ) );
83
84 m_params.emplace_back( new PARAM<bool>( "drawing.intersheets_ref_show",
85 &m_IntersheetRefsShow, defaultIntersheetsRefShow ) );
86
87 m_params.emplace_back( new PARAM<bool>( "drawing.intersheets_ref_own_page",
88 &m_IntersheetRefsListOwnPage, defaultIntersheetsRefOwnPage ) );
89
90 m_params.emplace_back( new PARAM<bool>( "drawing.intersheets_ref_short",
91 &m_IntersheetRefsFormatShort, defaultIntersheetsRefFormatShort ) );
92
93 m_params.emplace_back( new PARAM<wxString>( "drawing.intersheets_ref_prefix",
94 &m_IntersheetRefsPrefix, defaultIntersheetsRefPrefix ) );
95
96 m_params.emplace_back( new PARAM<wxString>( "drawing.intersheets_ref_suffix",
97 &m_IntersheetRefsSuffix, defaultIntersheetsRefSuffix ) );
98
99 m_params.emplace_back( new PARAM<double>( "drawing.dashed_lines_dash_length_ratio",
100 &m_DashedLineDashRatio, 12.0 ) ); // Default from ISO 128-2
101
102 m_params.emplace_back( new PARAM<double>( "drawing.dashed_lines_gap_length_ratio",
103 &m_DashedLineGapRatio, 3.0 ) ); // Default from ISO 128-2
104
105 m_params.emplace_back( new PARAM<int>( "drawing.operating_point_overlay_v_precision",
106 &m_OPO_VPrecision, 3 ) );
107
108 m_params.emplace_back( new PARAM<wxString>( "drawing.operating_point_overlay_v_range",
109 &m_OPO_VRange, wxS( "~V" ) ) );
110
111 m_params.emplace_back( new PARAM<int>( "drawing.operating_point_overlay_i_precision",
112 &m_OPO_IPrecision, 3 ) );
113
114 m_params.emplace_back( new PARAM<wxString>( "drawing.operating_point_overlay_i_range",
115 &m_OPO_IRange, wxS( "~A" ) ) );
116
117 m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_line_thickness",
118 &m_DefaultLineWidth, schIUScale.MilsToIU( defaultLineThickness ),
120
121 m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_text_size",
122 &m_DefaultTextSize, schIUScale.MilsToIU( defaultTextSize ),
124
125 m_params.emplace_back( new PARAM<double>( "drawing.text_offset_ratio",
127
128 m_params.emplace_back( new PARAM<double>( "drawing.label_size_ratio",
130
131 m_params.emplace_back( new PARAM<double>( "drawing.overbar_offset_ratio",
133
134 m_params.emplace_back( new PARAM_SCALED<int>( "drawing.pin_symbol_size",
135 &m_PinSymbolSize, schIUScale.MilsToIU( defaultPinSymbolSize ),
137
138 m_params.emplace_back( new PARAM_SCALED<int>( "connection_grid_size",
141 1 / schIUScale.IU_PER_MILS ) );
142
143 // m_JunctionSize is only a run-time cache of the calculated size. Do not save it.
144
145 // User choice for junction dot size ( e.g. none = 0, smallest = 1, small = 2, etc )
146 m_params.emplace_back( new PARAM<int>( "drawing.junction_size_choice",
147 &m_JunctionSizeChoice, defaultJunctionSizeChoice ) );
148
149 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "drawing.field_names",
150 [&]() -> nlohmann::json
151 {
152 nlohmann::json ret = nlohmann::json::array();
153
154 for( const TEMPLATE_FIELDNAME& field :
156 {
157 ret.push_back( nlohmann::json( {
158 { "name", field.m_Name },
159 { "visible", field.m_Visible },
160 { "url", field.m_URL }
161 } ) );
162 }
163
164 return ret;
165 },
166 [&]( const nlohmann::json& aJson )
167 {
168 if( !aJson.empty() && aJson.is_array() )
169 {
171
172 for( const nlohmann::json& entry : aJson )
173 {
174 if( !entry.contains( "name" ) || !entry.contains( "url" )
175 || !entry.contains( "visible" ) )
176 {
177 continue;
178 }
179
180 TEMPLATE_FIELDNAME field( entry["name"].get<wxString>() );
181 field.m_URL = entry["url"].get<bool>();
182 field.m_Visible = entry["visible"].get<bool>();
184 }
185 }
186
187 // Read global fieldname templates
189 EESCHEMA_SETTINGS* curr_cfg = curr_mgr.GetAppSettings<EESCHEMA_SETTINGS>( "eeschema" );
190
191 if( curr_cfg && !curr_cfg->m_Drawing.field_names.IsEmpty() )
193 }, {} ) );
194
195 m_params.emplace_back( new PARAM<wxString>( "bom_export_filename",
196 &m_BomExportFileName, "${PROJECTNAME}.csv" ) );
197
198 m_params.emplace_back(
200 m_params.emplace_back( new PARAM_LIST<BOM_PRESET>( "bom_presets",
201 &m_BomPresets, {} ) );
202
203 m_params.emplace_back( new PARAM<BOM_FMT_PRESET>( "bom_fmt_settings",
205 m_params.emplace_back( new PARAM_LIST<BOM_FMT_PRESET>( "bom_fmt_presets",
206 &m_BomFmtPresets, {} ) );
207
208 m_params.emplace_back( new PARAM<wxString>( "page_layout_descr_file",
210
211 m_params.emplace_back( new PARAM<wxString>( "plot_directory",
212 &m_PlotDirectoryName, "" ) );
213
214 m_params.emplace_back( new PARAM<wxString>( "net_format_name",
215 &m_NetFormatName, "" ) );
216
217 m_params.emplace_back( new PARAM<bool>( "spice_current_sheet_as_root",
218 &m_SpiceCurSheetAsRoot, false ) );
219
220 m_params.emplace_back( new PARAM<bool>( "spice_save_all_voltages",
221 &m_SpiceSaveAllVoltages, false ) );
222
223 m_params.emplace_back( new PARAM<bool>( "spice_save_all_currents",
224 &m_SpiceSaveAllCurrents, false ) );
225
226 m_params.emplace_back( new PARAM<bool>( "spice_save_all_dissipations",
227 &m_SpiceSaveAllDissipations, false ) );
228
229 m_params.emplace_back( new PARAM<bool>( "space_save_all_events",
230 &m_SpiceSaveAllEvents, true ) );
231
232 m_params.emplace_back( new PARAM<bool>( "spice_model_current_sheet_as_root",
234
235 m_params.emplace_back( new PARAM<wxString>( "spice_external_command",
236 &m_SpiceCommandString, "spice \"%I\"" ) );
237
238 // TODO(JE) should we keep these LIB_SYMBOL:: things around?
239 m_params.emplace_back( new PARAM<int>( "subpart_id_separator",
240 &m_SubpartIdSeparator, 0, 0, 126 ) );
241
242 m_params.emplace_back( new PARAM<int>( "subpart_first_id",
243 &m_SubpartFirstId, 'A', '1', 'z' ) );
244
245 m_params.emplace_back( new PARAM<int>( "annotate_start_num",
246 &m_AnnotateStartNum, 0 ) );
247
248 m_NgspiceSettings = std::make_shared<NGSPICE_SETTINGS>( this, "ngspice" );
249
250 registerMigration( 0, 1,
251 [&]() -> bool
252 {
253 std::optional<double> tor = Get<double>( "drawing.text_offset_ratio" );
254
255 if( tor )
256 Set( "drawing.label_size_ratio", *tor );
257
258 return true;
259 } );
260}
261
262
264{
266 m_NgspiceSettings.reset();
267
268 if( m_parent )
269 {
271 m_parent = nullptr;
272 }
273}
274
275
276wxString SCHEMATIC_SETTINGS::SubReference( int aUnit, bool aAddSeparator ) const
277{
278 wxString subRef;
279
280 if( aUnit < 1 )
281 return subRef;
282
283 if( m_SubpartIdSeparator != 0 && aAddSeparator )
284 subRef << wxChar( m_SubpartIdSeparator );
285
286 if( m_SubpartFirstId >= '0' && m_SubpartFirstId <= '9' )
287 subRef << aUnit;
288 else
290
291 return subRef;
292}
BASE_SCREEN class implementation.
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
void Set(const std::string &aPath, ValueType aVal)
Stores a value into the JSON document Will throw an exception if ValueType isn't something that the l...
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
void registerMigration(int aOldSchemaVersion, int aNewSchemaVersion, std::function< bool(void)> aMigrator)
Registers a migration from one schema version to another.
void ReleaseNestedSettings(NESTED_SETTINGS *aSettings)
Saves and frees a nested settings object, if it exists within this one.
double m_OverbarHeight
Definition: font.h:123
static wxString LetterSubReference(int aUnit, int aFirstId)
Definition: lib_symbol.cpp:447
NESTED_SETTINGS is a JSON_SETTINGS that lives inside a JSON_SETTINGS.
JSON_SETTINGS * m_parent
A pointer to the parent object to load and store from.
Like a normal param, but with custom getter and setter functions.
Definition: parameters.h:295
Represents a parameter that has a scaling factor between the value in the file and the value used int...
Definition: parameters.h:392
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
wxString m_SchDrawingSheetFileName
BOM_FMT_PRESET m_BomFmtSettings
List of stored BOM format presets.
wxString SubReference(int aUnit, bool aAddSeparator=true) const
SCHEMATIC_SETTINGS(JSON_SETTINGS *aParent, const std::string &aPath)
std::vector< BOM_PRESET > m_BomPresets
std::vector< BOM_FMT_PRESET > m_BomFmtPresets
KIFONT::METRICS m_FontMetrics
std::shared_ptr< NGSPICE_SETTINGS > m_NgspiceSettings
Ngspice simulator settings.
BOM_PRESET m_BomSettings
List of stored BOM presets.
T * GetAppSettings(const wxString &aFilename)
Returns a handle to the a given settings by type If the settings have already been loaded,...
void AddTemplateFieldName(const TEMPLATE_FIELDNAME &aFieldName, bool aGlobal)
Insert or append a wanted symbol field name into the field names template.
void AddTemplateFieldNames(const wxString &aSerializedFieldNames)
Add a serialized list of template field names.
void DeleteAllFieldNameTemplates(bool aGlobal)
Delete the entire contents.
const TEMPLATE_FIELDNAMES & GetTemplateFieldNames()
Return a template field name list for read only access.
#define DEFAULT_IREF_PREFIX
The intersheets references suffix string.
#define DEFAULT_LABEL_SIZE_RATIO
The offset of the pin name string from the end of the pin in mils.
#define DEFAULT_JUNCTION_DIAM
The default bus and wire entry size in mils.
#define DEFAULT_LINE_WIDTH_MILS
The default wire width in mils. (can be changed in preference menu)
#define DEFAULT_TEXT_OFFSET_RATIO
Ratio of the font height to space around global labels.
#define DEFAULT_IREF_SUFFIX
Radius of snap "gravity well".
#define DEFAULT_TEXT_SIZE
Ratio of the font height to the baseline of the text above the wire.
This file contains miscellaneous commonly used macros and functions.
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1060
see class PGM_BASE
#define IU_PER_MILS
Definition: plotter.cpp:129
const int schSettingsSchemaVersion
#define MIN_CONNECTION_GRID_MILS
#define DEFAULT_CONNECTION_GRID_MILS
static BOM_FMT_PRESET CSV()
static BOM_PRESET DefaultEditing()
const double IU_PER_MILS
Definition: base_units.h:77
constexpr int MilsToIU(int mils) const
Definition: base_units.h:93
Hold a name of a symbol's field, field value, and default visibility.