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 The 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
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <lib_symbol.h>
23#include <default_values.h>
24#include <eeschema_settings.h>
25#include <pgm_base.h>
28#include <refdes_tracker.h>
29#include <schematic_settings.h>
31#include <settings/parameters.h>
34#include <sim/spice_settings.h>
35
36
37// Lists containing the scaling factors to apply for the junction/hop over sizes
38const std::vector<double> hopover_size_mult_list = { 0.0, 1.7, 4.0, 6.0, 9.0, 12.0 };
39const std::vector<double> junction_size_mult_list = { 0.0, 1.7, 4.0, 6.0, 9.0, 12.0 };
40
42
43
45 m_MissingFields( true ),
46 m_ExtraFields( false ),
47 m_FieldTexts( true ),
48 m_FieldVisibilities( false ),
49 m_FieldStyles( false ),
50 m_FieldPositions( false ),
51 m_PinVisibilities( false ),
52 m_PinAltFunctions( true ),
54 m_DNPFlags( false ),
55 m_ExcludeFromBOMFlags( false ),
57{
58};
59
60
61SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
62 NESTED_SETTINGS( "schematic", schSettingsSchemaVersion, aParent, aPath, false ),
70 m_ShowDNPMarkers( true ),
75 m_IntersheetRefsShow( false ),
83 m_OPO_VRange( wxS( "~V" ) ),
85 m_OPO_IRange( wxS( "~A" ) ),
87 m_NgspiceSettings( nullptr ),
88 m_refDesTracker( nullptr )
89{
91
92 int defaultLineThickness = cfg ? cfg->m_Drawing.default_line_thickness : DEFAULT_LINE_WIDTH_MILS;
93 int defaultTextSize = cfg ? cfg->m_Drawing.default_text_size : DEFAULT_TEXT_SIZE;
94 int defaultPinSymbolSize = cfg ? cfg->m_Drawing.pin_symbol_size : DEFAULT_TEXT_SIZE / 2;
95 int defaultJunctionSizeChoice = cfg ? cfg->m_Drawing.junction_size_choice : 3;
96 int defaultHopOverSizeChoice = cfg ? cfg->m_Drawing.hop_over_size_choice : 0;
97 bool defaultIntersheetsRefShow = cfg ? cfg->m_Drawing.intersheets_ref_show : false;
98 bool defaultIntersheetsRefOwnPage = cfg ? cfg->m_Drawing.intersheets_ref_own_page : true;
99 bool defaultIntersheetsRefFormatShort = cfg ? cfg->m_Drawing.intersheets_ref_short : false;
100 wxString defaultIntersheetsRefPrefix = cfg ? cfg->m_Drawing.intersheets_ref_prefix
101 : wxString( wxS( DEFAULT_IREF_PREFIX ) );
102 wxString defaultIntersheetsRefSuffix = cfg ? cfg->m_Drawing.intersheets_ref_suffix
103 : wxString( wxS( DEFAULT_IREF_SUFFIX ) );
104
105 m_params.emplace_back( new PARAM<bool>( "drawing.intersheets_ref_show",
106 &m_IntersheetRefsShow, defaultIntersheetsRefShow ) );
107
108 m_params.emplace_back( new PARAM<bool>( "drawing.intersheets_ref_own_page",
109 &m_IntersheetRefsListOwnPage, defaultIntersheetsRefOwnPage ) );
110
111 m_params.emplace_back( new PARAM<bool>( "drawing.intersheets_ref_short",
112 &m_IntersheetRefsFormatShort, defaultIntersheetsRefFormatShort ) );
113
114 m_params.emplace_back( new PARAM<wxString>( "drawing.intersheets_ref_prefix",
115 &m_IntersheetRefsPrefix, defaultIntersheetsRefPrefix ) );
116
117 m_params.emplace_back( new PARAM<wxString>( "drawing.intersheets_ref_suffix",
118 &m_IntersheetRefsSuffix, defaultIntersheetsRefSuffix ) );
119
120 m_params.emplace_back( new PARAM<double>( "drawing.dashed_lines_dash_length_ratio",
121 &m_DashedLineDashRatio, 12.0 ) ); // Default from ISO 128-2
122
123 m_params.emplace_back( new PARAM<double>( "drawing.dashed_lines_gap_length_ratio",
124 &m_DashedLineGapRatio, 3.0 ) ); // Default from ISO 128-2
125
126 m_params.emplace_back( new PARAM<bool>( "drawing.show_dnp_markers", &m_ShowDNPMarkers, true ) );
127
128 m_params.emplace_back( new PARAM<int>( "drawing.operating_point_overlay_v_precision",
129 &m_OPO_VPrecision, 3 ) );
130
131 m_params.emplace_back( new PARAM<wxString>( "drawing.operating_point_overlay_v_range",
132 &m_OPO_VRange, wxS( "~V" ) ) );
133
134 m_params.emplace_back( new PARAM<int>( "drawing.operating_point_overlay_i_precision",
135 &m_OPO_IPrecision, 3 ) );
136
137 m_params.emplace_back( new PARAM<wxString>( "drawing.operating_point_overlay_i_range",
138 &m_OPO_IRange, wxS( "~A" ) ) );
139
140 m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_line_thickness",
141 &m_DefaultLineWidth, schIUScale.MilsToIU( defaultLineThickness ),
142 schIUScale.MilsToIU( 5 ), schIUScale.MilsToIU( 1000 ), 1 / schIUScale.IU_PER_MILS ) );
143
144 m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_text_size",
145 &m_DefaultTextSize, schIUScale.MilsToIU( defaultTextSize ),
146 schIUScale.MilsToIU( 5 ), schIUScale.MilsToIU( 1000 ), 1 / schIUScale.IU_PER_MILS ) );
147
148 m_params.emplace_back( new PARAM<double>( "drawing.text_offset_ratio",
150
151 m_params.emplace_back( new PARAM<double>( "drawing.label_size_ratio",
153
154 m_params.emplace_back( new PARAM<double>( "drawing.overbar_offset_ratio",
155 &m_FontMetrics.m_OverbarHeight, m_FontMetrics.m_OverbarHeight ) );
156
157 m_params.emplace_back( new PARAM_SCALED<int>( "drawing.pin_symbol_size",
158 &m_PinSymbolSize, schIUScale.MilsToIU( defaultPinSymbolSize ),
159 schIUScale.MilsToIU( 0 ), schIUScale.MilsToIU( 1000 ), 1 / schIUScale.IU_PER_MILS ) );
160
161 m_params.emplace_back( new PARAM_SCALED<int>( "connection_grid_size",
163 schIUScale.MilsToIU( MIN_CONNECTION_GRID_MILS ), schIUScale.MilsToIU( 10000 ),
164 1 / schIUScale.IU_PER_MILS ) );
165
166 // User choice for junction dot size ( e.g. none = 0, smallest = 1, small = 2, etc )
167 m_params.emplace_back( new PARAM<int>( "drawing.junction_size_choice",
168 &m_JunctionSizeChoice, defaultJunctionSizeChoice ) );
169
170 m_params.emplace_back( new PARAM<int>( "drawing.hop_over_size_choice",
171 &m_HopOverSizeChoice, defaultHopOverSizeChoice ) );
172
173 m_params.emplace_back( new PARAM<bool>( "compare_symbols.missing_fields",
174 &m_SymbolParity.m_MissingFields, true ) );
175
176 m_params.emplace_back( new PARAM<bool>( "compare_symbols.extra_fields",
177 &m_SymbolParity.m_ExtraFields, false ) );
178
179 m_params.emplace_back( new PARAM<bool>( "compare_symbols.field_texts",
180 &m_SymbolParity.m_FieldTexts, true ) );
181
182 m_params.emplace_back( new PARAM<bool>( "compare_symbols.field_visibilities",
183 &m_SymbolParity.m_FieldVisibilities, false ) );
184
185 m_params.emplace_back( new PARAM<bool>( "compare_symbols.field_styles",
186 &m_SymbolParity.m_FieldStyles, false ) );
187
188 m_params.emplace_back( new PARAM<bool>( "compare_symbols.field_positions",
189 &m_SymbolParity.m_FieldPositions, false ) );
190
191 m_params.emplace_back( new PARAM<bool>( "compare_symbols.pin_name_number_visibilities",
192 &m_SymbolParity.m_PinVisibilities, false ) );
193
194 m_params.emplace_back( new PARAM<bool>( "compare_symbols.pin_alt_function_definitions",
195 &m_SymbolParity.m_PinAltFunctions, true ) );
196
197 m_params.emplace_back( new PARAM<bool>( "compare_symbols.exclude_from_board_flags",
198 &m_SymbolParity.m_ExcludeFromBoardFlags, true ) );
199
200 m_params.emplace_back( new PARAM<bool>( "compare_symbols.dnp_flags",
201 &m_SymbolParity.m_DNPFlags, false ) );
202
203 m_params.emplace_back( new PARAM<bool>( "compare_symbols.exclude_from_bom_flags",
204 &m_SymbolParity.m_ExcludeFromBOMFlags, false ) );
205
206 m_params.emplace_back( new PARAM<bool>( "compare_symbols.exclude_from_position_file_flags",
207 &m_SymbolParity.m_ExcludeFromPosFileFlags, true ) );
208
209 m_params.emplace_back( new PARAM<wxString>( "bom_export_filename",
210 &m_BomExportFileName, "${PROJECTNAME}.csv" ) );
211
212 m_params.emplace_back( new PARAM<BOM_PRESET>( "bom_settings",
213 &m_BomSettings, BOM_PRESET::DefaultEditing() ) );
214 m_params.emplace_back( new PARAM_LIST<BOM_PRESET>( "bom_presets",
215 &m_BomPresets, {} ) );
216
217 m_params.emplace_back( new PARAM<BOM_FMT_PRESET>( "bom_fmt_settings",
219 m_params.emplace_back( new PARAM_LIST<BOM_FMT_PRESET>( "bom_fmt_presets",
220 &m_BomFmtPresets, {} ) );
221
222 m_params.emplace_back( new PARAM<wxString>( "page_layout_descr_file",
224
225 m_params.emplace_back( new PARAM<wxString>( "plot_directory",
226 &m_PlotDirectoryName, "" ) );
227
228 m_params.emplace_back( new PARAM<int>( "subpart_id_separator",
229 &m_SubpartIdSeparator, 0, 0, 126 ) );
230
231 m_params.emplace_back( new PARAM<int>( "subpart_first_id",
232 &m_SubpartFirstId, 'A', '1', 'z' ) );
233
234 m_params.emplace_back( new PARAM<int>( "annotate_start_num",
235 &m_AnnotateStartNum, 0 ) );
236
237 m_params.emplace_back( new PARAM<int>( "annotation.sort_order",
238 &m_AnnotateSortOrder, 0, 0, 1 ) );
239
240 m_params.emplace_back( new PARAM<int>( "annotation.method",
241 &m_AnnotateMethod, 0, 0, 2 ) );
242
243 m_NgspiceSettings = std::make_shared<NGSPICE_SETTINGS>( this, "ngspice" );
244
245 m_params.emplace_back( new PARAM_LAMBDA<bool>( "reuse_designators",
246 [&]() -> bool
247 {
248 return m_refDesTracker ? m_refDesTracker->GetReuseRefDes() : false;
249 },
250 [&]( bool aReuse )
251 {
252 if( !m_refDesTracker )
253 m_refDesTracker = std::make_shared<REFDES_TRACKER>();
254
255 m_refDesTracker->SetReuseRefDes( aReuse );
256 }, true ) );
257
258 m_params.emplace_back( new PARAM_LAMBDA<std::string>( "used_designators",
259 [&]() -> std::string
260 {
261 if( m_refDesTracker )
262 return m_refDesTracker->Serialize();
263
264 return std::string();
265 },
266 [&]( const std::string& aData )
267 {
268 if( !m_refDesTracker )
269 m_refDesTracker = std::make_shared<REFDES_TRACKER>();
270
271 m_refDesTracker->Deserialize( aData );
272 }, {} ) );
273
274 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "variants",
275 [&]() -> nlohmann::json
276 {
277 nlohmann::json ret = nlohmann::json::array();
278
279 for( const auto& [name, description] : m_VariantDescriptions )
280 {
281 nlohmann::json entry;
282 entry["name"] = name;
283
284 if( !description.IsEmpty() )
285 entry["description"] = description;
286
287 ret.push_back( entry );
288 }
289
290 return ret;
291 },
292 [&]( const nlohmann::json& aJson )
293 {
294 m_VariantDescriptions.clear();
295
296 if( aJson.is_array() )
297 {
298 for( const auto& entry : aJson )
299 {
300 if( entry.contains( "name" ) )
301 {
302 wxString name = entry["name"].get<wxString>();
303 wxString desc;
304
305 if( entry.contains( "description" ) )
306 desc = entry["description"].get<wxString>();
307
309 }
310 }
311 }
312 }, nlohmann::json::array() ) );
313
314 registerMigration( 0, 1,
315 [&]() -> bool
316 {
317 std::optional<double> tor = Get<double>( "drawing.text_offset_ratio" );
318
319 if( tor )
320 Set( "drawing.label_size_ratio", *tor );
321
322 return true;
323 } );
324}
325
326
328{
330 m_NgspiceSettings.reset();
331
332 if( m_parent )
333 {
334 m_parent->ReleaseNestedSettings( this );
335 m_parent = nullptr;
336 }
337}
338
339
340wxString SCHEMATIC_SETTINGS::SubReference( int aUnit, bool aAddSeparator ) const
341{
342 wxString subRef;
343
344 if( aUnit < 1 )
345 return subRef;
346
347 if( m_SubpartIdSeparator != 0 && aAddSeparator )
348 subRef << wxChar( m_SubpartIdSeparator );
349
350 if( m_SubpartFirstId >= '0' && m_SubpartFirstId <= '9' )
351 subRef << aUnit;
352 else
354
355 return subRef;
356}
357
358
360{
362
364 int dotSize = KiROUND( projectFile.NetSettings()->GetDefaultNetclass()->GetWireWidth() * multiplier );
365
366 return std::max( dotSize, 1 );
367}
368
369
374
375
377{
379
380 flags &= ~SCH_ITEM::COMPARE_FLAGS::IDENTITY;
381
382 if( !m_SymbolParity.m_MissingFields )
383 flags &= ~SCH_ITEM::COMPARE_FLAGS::MISSING_FIELDS;
384
385 if( !m_SymbolParity.m_ExtraFields )
386 flags &= ~SCH_ITEM::COMPARE_FLAGS::EXTRA_FIELDS;
387
388 if( !m_SymbolParity.m_FieldTexts )
389 flags &= ~SCH_ITEM::COMPARE_FLAGS::FIELD_TEXT;
390
391 if( !m_SymbolParity.m_FieldVisibilities )
392 flags &= ~SCH_ITEM::COMPARE_FLAGS::FIELD_VISIBILITY;
393
394 if( !m_SymbolParity.m_FieldStyles )
395 flags &= ~SCH_ITEM::COMPARE_FLAGS::FIELD_SIZE_AND_STYLE;
396
397 if( !m_SymbolParity.m_FieldPositions )
398 flags &= ~SCH_ITEM::COMPARE_FLAGS::FIELD_POSITIONS;
399
400 if( !m_SymbolParity.m_PinVisibilities )
401 flags &= ~SCH_ITEM::COMPARE_FLAGS::PIN_VISIBILITIES;
402
403 if( !m_SymbolParity.m_PinAltFunctions )
404 flags &= ~SCH_ITEM::COMPARE_FLAGS::PIN_ALT_DEFS;
405
406 flags &= ~SCH_ITEM::COMPARE_FLAGS::EXCLUDE_FROM_SIM;
407
408 if( !m_SymbolParity.m_ExcludeFromBoardFlags )
409 flags &= ~SCH_ITEM::COMPARE_FLAGS::EXCLUDE_FROM_BOARD;
410
411 if( !m_SymbolParity.m_DNPFlags )
412 flags &= ~SCH_ITEM::COMPARE_FLAGS::DNP;
413
414 if( !m_SymbolParity.m_ExcludeFromBOMFlags )
415 flags &= ~SCH_ITEM::COMPARE_FLAGS::EXCLUDE_FROM_BOM;
416
417 if( !m_SymbolParity.m_ExcludeFromPosFileFlags )
418 flags &= ~SCH_ITEM::COMPARE_FLAGS::EXCLUDE_FROM_POS_FILES;
419
420 return flags;
421}
const char * name
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:123
constexpr double ARC_LOW_DEF_MM
Definition base_units.h:127
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:995
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::optional< ValueType > Get(const std::string &aPath) const
Fetches a value from within the JSON document.
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.
JSON_SETTINGS(const wxString &aFilename, SETTINGS_LOC aLocation, int aSchemaVersion)
static wxString LetterSubReference(int aUnit, wxChar aInitialLetter)
JSON_SETTINGS * m_parent
A pointer to the parent object to load and store from.
NESTED_SETTINGS(const std::string &aName, int aSchemaVersion, JSON_SETTINGS *aParent, const std::string &aPath, bool aLoadFromFile=true)
int GetWireWidth() const
Definition netclass.h:218
std::shared_ptr< NETCLASS > GetDefaultNetclass() const
Gets the default netclass for the project.
Like a normal param, but with custom getter and setter functions.
Definition parameters.h:299
Represents a parameter that has a scaling factor between the value in the file and the value used int...
Definition parameters.h:410
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:123
The backing store for a PROJECT, in JSON format.
std::shared_ptr< NET_SETTINGS > & NetSettings()
virtual PROJECT_FILE & GetProjectFile() const
Definition project.h:201
double GetHopOverScale()
Accessor that computes the current hop-over size.
SYMBOL_PARITY_SETTINGS m_SymbolParity
wxString SubReference(int aUnit, bool aAddSeparator=true) const
SCHEMATIC_SETTINGS(JSON_SETTINGS *aParent, const std::string &aPath)
std::shared_ptr< REFDES_TRACKER > m_refDesTracker
A list of previously used schematic reference designators.
std::map< wxString, wxString > m_VariantDescriptions
A map of variant names to their descriptions.
KIFONT::METRICS m_FontMetrics
int GetJunctionSize()
Accessor that computes the current junction size.
std::shared_ptr< NGSPICE_SETTINGS > m_NgspiceSettings
Ngspice simulator settings.
int m_MaxError
Max deviation allowable when approximating circles and curves (in IU).
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:165
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
#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_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.
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
#define IU_PER_MILS
Definition plotter.cpp:129
const std::vector< double > junction_size_mult_list
const std::vector< double > hopover_size_mult_list
const int schSettingsSchemaVersion
#define MIN_CONNECTION_GRID_MILS
#define DEFAULT_CONNECTION_GRID_MILS
T * GetAppSettings(const char *aFilename)
static BOM_FMT_PRESET CSV()
BOM_FMT_PRESET m_BomFmtSettings
List of stored BOM format presets.
BOM_PRESET m_BomSettings
List of stored BOM presets.
std::vector< BOM_PRESET > m_BomPresets
std::vector< BOM_FMT_PRESET > m_BomFmtPresets
static constexpr double IU_PER_MM
Mock up a conversion function.