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 ),
77 m_IntersheetRefsShow( false ),
85 m_OPO_VRange( wxS( "~V" ) ),
87 m_OPO_IRange( wxS( "~A" ) ),
89 m_NgspiceSettings( nullptr ),
90 m_refDesTracker( nullptr )
91{
93
94 int defaultLineThickness = cfg ? cfg->m_Drawing.default_line_thickness : DEFAULT_LINE_WIDTH_MILS;
95 int defaultTextSize = cfg ? cfg->m_Drawing.default_text_size : DEFAULT_TEXT_SIZE;
96 int defaultPinSymbolSize = cfg ? cfg->m_Drawing.pin_symbol_size : DEFAULT_TEXT_SIZE / 2;
97 int defaultJunctionSizeChoice = cfg ? cfg->m_Drawing.junction_size_choice : 3;
98 int defaultHopOverSizeChoice = cfg ? cfg->m_Drawing.hop_over_size_choice : 0;
99 bool defaultIntersheetsRefShow = cfg ? cfg->m_Drawing.intersheets_ref_show : false;
100 bool defaultIntersheetsRefOwnPage = cfg ? cfg->m_Drawing.intersheets_ref_own_page : true;
101 bool defaultIntersheetsRefFormatShort = cfg ? cfg->m_Drawing.intersheets_ref_short : false;
102 wxString defaultIntersheetsRefPrefix = cfg ? cfg->m_Drawing.intersheets_ref_prefix
103 : wxString( wxS( DEFAULT_IREF_PREFIX ) );
104 wxString defaultIntersheetsRefSuffix = cfg ? cfg->m_Drawing.intersheets_ref_suffix
105 : wxString( wxS( DEFAULT_IREF_SUFFIX ) );
106
107 m_params.emplace_back( new PARAM<bool>( "drawing.intersheets_ref_show",
108 &m_IntersheetRefsShow, defaultIntersheetsRefShow ) );
109
110 m_params.emplace_back( new PARAM<bool>( "drawing.intersheets_ref_own_page",
111 &m_IntersheetRefsListOwnPage, defaultIntersheetsRefOwnPage ) );
112
113 m_params.emplace_back( new PARAM<bool>( "drawing.intersheets_ref_short",
114 &m_IntersheetRefsFormatShort, defaultIntersheetsRefFormatShort ) );
115
116 m_params.emplace_back( new PARAM<wxString>( "drawing.intersheets_ref_prefix",
117 &m_IntersheetRefsPrefix, defaultIntersheetsRefPrefix ) );
118
119 m_params.emplace_back( new PARAM<wxString>( "drawing.intersheets_ref_suffix",
120 &m_IntersheetRefsSuffix, defaultIntersheetsRefSuffix ) );
121
122 m_params.emplace_back( new PARAM<double>( "drawing.dashed_lines_dash_length_ratio",
123 &m_DashedLineDashRatio, 12.0 ) ); // Default from ISO 128-2
124
125 m_params.emplace_back( new PARAM<double>( "drawing.dashed_lines_gap_length_ratio",
126 &m_DashedLineGapRatio, 3.0 ) ); // Default from ISO 128-2
127
128 m_params.emplace_back( new PARAM<bool>( "drawing.show_dnp_markers", &m_ShowDNPMarkers, true ) );
129
130 m_params.emplace_back( new PARAM<int>( "drawing.operating_point_overlay_v_precision",
131 &m_OPO_VPrecision, 3 ) );
132
133 m_params.emplace_back( new PARAM<wxString>( "drawing.operating_point_overlay_v_range",
134 &m_OPO_VRange, wxS( "~V" ) ) );
135
136 m_params.emplace_back( new PARAM<int>( "drawing.operating_point_overlay_i_precision",
137 &m_OPO_IPrecision, 3 ) );
138
139 m_params.emplace_back( new PARAM<wxString>( "drawing.operating_point_overlay_i_range",
140 &m_OPO_IRange, wxS( "~A" ) ) );
141
142 m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_line_thickness",
143 &m_DefaultLineWidth, schIUScale.MilsToIU( defaultLineThickness ),
144 schIUScale.MilsToIU( 5 ), schIUScale.MilsToIU( 1000 ), 1 / schIUScale.IU_PER_MILS ) );
145
146 m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_text_size",
147 &m_DefaultTextSize, schIUScale.MilsToIU( defaultTextSize ),
148 schIUScale.MilsToIU( 5 ), schIUScale.MilsToIU( 1000 ), 1 / schIUScale.IU_PER_MILS ) );
149
150 m_params.emplace_back( new PARAM<double>( "drawing.text_offset_ratio",
152
153 m_params.emplace_back( new PARAM<double>( "drawing.label_size_ratio",
155
156 m_params.emplace_back( new PARAM<double>( "drawing.overbar_offset_ratio",
157 &m_FontMetrics.m_OverbarHeight, m_FontMetrics.m_OverbarHeight ) );
158
159 m_params.emplace_back( new PARAM_SCALED<int>( "drawing.pin_symbol_size",
160 &m_PinSymbolSize, schIUScale.MilsToIU( defaultPinSymbolSize ),
161 schIUScale.MilsToIU( 0 ), schIUScale.MilsToIU( 1000 ), 1 / schIUScale.IU_PER_MILS ) );
162
163 m_params.emplace_back( new PARAM_SCALED<int>( "connection_grid_size",
165 schIUScale.MilsToIU( MIN_CONNECTION_GRID_MILS ), schIUScale.MilsToIU( 10000 ),
166 1 / schIUScale.IU_PER_MILS ) );
167
168 // User choice for junction dot size ( e.g. none = 0, smallest = 1, small = 2, etc )
169 m_params.emplace_back( new PARAM<int>( "drawing.junction_size_choice",
170 &m_JunctionSizeChoice, defaultJunctionSizeChoice, 0, 5 ) );
171
172 m_params.emplace_back( new PARAM<int>( "drawing.hop_over_size_choice",
173 &m_HopOverSizeChoice, defaultHopOverSizeChoice, 0, 5 ) );
174
175 m_params.emplace_back( new PARAM<bool>( "compare_symbols.missing_fields",
176 &m_SymbolParity.m_MissingFields, true ) );
177
178 m_params.emplace_back( new PARAM<bool>( "compare_symbols.extra_fields",
179 &m_SymbolParity.m_ExtraFields, false ) );
180
181 m_params.emplace_back( new PARAM<bool>( "compare_symbols.field_texts",
182 &m_SymbolParity.m_FieldTexts, true ) );
183
184 m_params.emplace_back( new PARAM<bool>( "compare_symbols.field_visibilities",
185 &m_SymbolParity.m_FieldVisibilities, false ) );
186
187 m_params.emplace_back( new PARAM<bool>( "compare_symbols.field_styles",
188 &m_SymbolParity.m_FieldStyles, false ) );
189
190 m_params.emplace_back( new PARAM<bool>( "compare_symbols.field_positions",
191 &m_SymbolParity.m_FieldPositions, false ) );
192
193 m_params.emplace_back( new PARAM<bool>( "compare_symbols.pin_name_number_visibilities",
194 &m_SymbolParity.m_PinVisibilities, false ) );
195
196 m_params.emplace_back( new PARAM<bool>( "compare_symbols.pin_alt_function_definitions",
197 &m_SymbolParity.m_PinAltFunctions, true ) );
198
199 m_params.emplace_back( new PARAM<bool>( "compare_symbols.exclude_from_board_flags",
200 &m_SymbolParity.m_ExcludeFromBoardFlags, true ) );
201
202 m_params.emplace_back( new PARAM<bool>( "compare_symbols.dnp_flags",
203 &m_SymbolParity.m_DNPFlags, false ) );
204
205 m_params.emplace_back( new PARAM<bool>( "compare_symbols.exclude_from_bom_flags",
206 &m_SymbolParity.m_ExcludeFromBOMFlags, false ) );
207
208 m_params.emplace_back( new PARAM<bool>( "compare_symbols.exclude_from_position_file_flags",
209 &m_SymbolParity.m_ExcludeFromPosFileFlags, true ) );
210
211 m_params.emplace_back( new PARAM<wxString>( "bom_export_filename",
212 &m_BomExportFileName, "${PROJECTNAME}.csv" ) );
213
214 m_params.emplace_back( new PARAM<BOM_PRESET>( "bom_settings",
215 &m_BomSettings, BOM_PRESET::DefaultEditing() ) );
216 m_params.emplace_back( new PARAM_LIST<BOM_PRESET>( "bom_presets",
217 &m_BomPresets, {} ) );
218
219 m_params.emplace_back( new PARAM<BOM_FMT_PRESET>( "bom_fmt_settings",
221 m_params.emplace_back( new PARAM_LIST<BOM_FMT_PRESET>( "bom_fmt_presets",
222 &m_BomFmtPresets, {} ) );
223
224 m_params.emplace_back( new PARAM<wxString>( "page_layout_descr_file",
226
227 m_params.emplace_back( new PARAM<wxString>( "plot_directory",
228 &m_PlotDirectoryName, "" ) );
229
230 m_params.emplace_back( new PARAM<int>( "subpart_id_separator",
231 &m_SubpartIdSeparator, 0, 0, 126 ) );
232
233 m_params.emplace_back( new PARAM<int>( "subpart_first_id",
234 &m_SubpartFirstId, 'A', '1', 'z' ) );
235
236 m_params.emplace_back( new PARAM<int>( "annotate_start_num",
237 &m_AnnotateStartNum, 0 ) );
238
239 m_params.emplace_back( new PARAM<int>( "annotation.sort_order",
240 &m_AnnotateSortOrder, 0, 0, 1 ) );
241
242 m_params.emplace_back( new PARAM<int>( "annotation.method",
243 &m_AnnotateMethod, 0, 0, 2 ) );
244
245 m_params.emplace_back( new PARAM<bool>( "annotation.reused_sheet_suffixes",
247
248 m_params.emplace_back( new PARAM<bool>( "annotation.increment_pasted_suffix",
249 &m_IncrementPastedSuffix, true ) );
250
251 m_NgspiceSettings = std::make_shared<NGSPICE_SETTINGS>( this, "ngspice" );
252
253 m_params.emplace_back( new PARAM_LAMBDA<bool>( "reuse_designators",
254 [&]() -> bool
255 {
256 return m_refDesTracker ? m_refDesTracker->GetReuseRefDes() : false;
257 },
258 [&]( bool aReuse )
259 {
260 if( !m_refDesTracker )
261 m_refDesTracker = std::make_shared<REFDES_TRACKER>();
262
263 m_refDesTracker->SetReuseRefDes( aReuse );
264 }, true ) );
265
266 m_params.emplace_back( new PARAM_LAMBDA<std::string>( "used_designators",
267 [&]() -> std::string
268 {
269 if( m_refDesTracker )
270 return m_refDesTracker->Serialize();
271
272 return std::string();
273 },
274 [&]( const std::string& aData )
275 {
276 if( !m_refDesTracker )
277 m_refDesTracker = std::make_shared<REFDES_TRACKER>();
278
279 m_refDesTracker->Deserialize( aData );
280 }, {} ) );
281
282 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "variants",
283 [&]() -> nlohmann::json
284 {
285 nlohmann::json ret = nlohmann::json::array();
286
287 for( const auto& [name, description] : m_VariantDescriptions )
288 {
289 nlohmann::json entry;
290 entry["name"] = name;
291
292 if( !description.IsEmpty() )
293 entry["description"] = description;
294
295 ret.push_back( entry );
296 }
297
298 return ret;
299 },
300 [&]( const nlohmann::json& aJson )
301 {
302 m_VariantDescriptions.clear();
303
304 if( aJson.is_array() )
305 {
306 for( const auto& entry : aJson )
307 {
308 if( entry.contains( "name" ) )
309 {
310 wxString name = entry["name"].get<wxString>();
311 wxString desc;
312
313 if( entry.contains( "description" ) )
314 desc = entry["description"].get<wxString>();
315
317 }
318 }
319 }
320 }, nlohmann::json::array() ) );
321
322 registerMigration( 0, 1,
323 [&]() -> bool
324 {
325 std::optional<double> tor = Get<double>( "drawing.text_offset_ratio" );
326
327 if( tor )
328 Set( "drawing.label_size_ratio", *tor );
329
330 return true;
331 } );
332}
333
334
336{
338 m_NgspiceSettings.reset();
339
340 if( m_parent )
341 {
342 m_parent->ReleaseNestedSettings( this );
343 m_parent = nullptr;
344 }
345}
346
347
348wxString SCHEMATIC_SETTINGS::SubReference( int aUnit, bool aAddSeparator ) const
349{
350 wxString subRef;
351
352 if( aUnit < 1 )
353 return subRef;
354
355 if( m_SubpartIdSeparator != 0 && aAddSeparator )
356 subRef << wxChar( m_SubpartIdSeparator );
357
358 if( m_SubpartFirstId >= '0' && m_SubpartFirstId <= '9' )
359 subRef << aUnit;
360 else
362
363 return subRef;
364}
365
366
368{
370
372 int dotSize = KiROUND( projectFile.NetSettings()->GetDefaultNetclass()->GetWireWidth() * multiplier );
373
374 return std::max( dotSize, 1 );
375}
376
377
382
383
385{
387
388 flags &= ~SCH_ITEM::COMPARE_FLAGS::IDENTITY;
389
390 if( !m_SymbolParity.m_MissingFields )
391 flags &= ~SCH_ITEM::COMPARE_FLAGS::MISSING_FIELDS;
392
393 if( !m_SymbolParity.m_ExtraFields )
394 flags &= ~SCH_ITEM::COMPARE_FLAGS::EXTRA_FIELDS;
395
396 if( !m_SymbolParity.m_FieldTexts )
397 flags &= ~SCH_ITEM::COMPARE_FLAGS::FIELD_TEXT;
398
399 if( !m_SymbolParity.m_FieldVisibilities )
400 flags &= ~SCH_ITEM::COMPARE_FLAGS::FIELD_VISIBILITY;
401
402 if( !m_SymbolParity.m_FieldStyles )
403 flags &= ~SCH_ITEM::COMPARE_FLAGS::FIELD_SIZE_AND_STYLE;
404
405 if( !m_SymbolParity.m_FieldPositions )
406 flags &= ~SCH_ITEM::COMPARE_FLAGS::FIELD_POSITIONS;
407
408 if( !m_SymbolParity.m_PinVisibilities )
409 flags &= ~SCH_ITEM::COMPARE_FLAGS::PIN_VISIBILITIES;
410
411 if( !m_SymbolParity.m_PinAltFunctions )
412 flags &= ~SCH_ITEM::COMPARE_FLAGS::PIN_ALT_DEFS;
413
414 flags &= ~SCH_ITEM::COMPARE_FLAGS::EXCLUDE_FROM_SIM;
415
416 if( !m_SymbolParity.m_ExcludeFromBoardFlags )
417 flags &= ~SCH_ITEM::COMPARE_FLAGS::EXCLUDE_FROM_BOARD;
418
419 if( !m_SymbolParity.m_DNPFlags )
420 flags &= ~SCH_ITEM::COMPARE_FLAGS::DNP;
421
422 if( !m_SymbolParity.m_ExcludeFromBOMFlags )
423 flags &= ~SCH_ITEM::COMPARE_FLAGS::EXCLUDE_FROM_BOM;
424
425 if( !m_SymbolParity.m_ExcludeFromPosFileFlags )
426 flags &= ~SCH_ITEM::COMPARE_FLAGS::EXCLUDE_FROM_POS_FILES;
427
428 return flags;
429}
const char * name
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:130
constexpr double ARC_LOW_DEF_MM
Definition base_units.h:134
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
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:229
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:124
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:170
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
#define DEFAULT_IREF_PREFIX
The intersheets references prefix string.
#define DEFAULT_LABEL_SIZE_RATIO
Ratio of the font height to space around global labels.
#define DEFAULT_LINE_WIDTH_MILS
The default line width in mils. (can be changed in preference menu)
#define DEFAULT_TEXT_OFFSET_RATIO
Ratio of the font height to the baseline of the text above the wire.
#define DEFAULT_IREF_SUFFIX
The intersheets references suffix string.
#define DEFAULT_TEXT_SIZE
The default text size in mils. (can be changed in preference menu)
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.