KiCad PCB EDA Suite
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 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Jon Evans <jon@craftyjon.com>
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 <convert_to_biu.h>
25 #include <default_values.h>
26 #include <eda_text.h>
27 #include <eeschema_settings.h>
28 #include <kiface_i.h>
29 #include <macros.h>
30 #include <schematic_settings.h>
32 #include <settings/parameters.h>
33 #include <sim/spice_settings.h>
34 
35 
37 
38 
39 SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
40  NESTED_SETTINGS( "schematic", schSettingsSchemaVersion, aParent, aPath ),
41  m_DefaultLineWidth( DEFAULT_LINE_THICKNESS * IU_PER_MILS ),
42  m_DefaultWireThickness( DEFAULT_WIRE_THICKNESS * IU_PER_MILS ),
43  m_DefaultBusThickness( DEFAULT_BUS_THICKNESS * IU_PER_MILS ),
44  m_DefaultTextSize( DEFAULT_TEXT_SIZE * IU_PER_MILS ),
45  m_TextOffsetRatio( DEFAULT_TEXT_OFFSET_RATIO ),
46  m_PinSymbolSize( DEFAULT_TEXT_SIZE * IU_PER_MILS / 2 ),
47  m_JunctionSize( DEFAULT_JUNCTION_DIAM * IU_PER_MILS ),
48  m_JunctionSizeChoice( 3 ),
49  m_IntersheetRefsShow( false ),
50  m_IntersheetRefsListOwnPage( true ),
51  m_IntersheetRefsFormatShort( false ),
52  m_IntersheetRefsPrefix( DEFAULT_IREF_PREFIX ),
53  m_IntersheetRefsSuffix( DEFAULT_IREF_SUFFIX ),
54  m_SpiceAdjustPassiveValues( false ),
55  m_NgspiceSimulatorSettings( nullptr ),
56  m_AnnotateStartNum( 0 )
57 {
58  EESCHEMA_SETTINGS* appSettings = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
59 
60  int defaultLineThickness =
61  appSettings ? appSettings->m_Drawing.default_line_thickness : DEFAULT_LINE_THICKNESS;
62  int defaultWireThickness =
63  appSettings ? appSettings->m_Drawing.default_wire_thickness : DEFAULT_WIRE_THICKNESS;
64  int defaultBusThickness =
65  appSettings ? appSettings->m_Drawing.default_bus_thickness : DEFAULT_BUS_THICKNESS;
66  int defaultTextSize =
67  appSettings ? appSettings->m_Drawing.default_text_size : DEFAULT_TEXT_SIZE;
68  int defaultPinSymbolSize =
69  appSettings ? appSettings->m_Drawing.pin_symbol_size : DEFAULT_TEXT_SIZE / 2;
70  int defaultJunctionSize =
71  appSettings ? appSettings->m_Drawing.default_junction_size : DEFAULT_JUNCTION_DIAM;
72  int defaultJunctionSizeChoice =
73  appSettings ? appSettings->m_Drawing.junction_size_choice : 3;
74  bool defaultIntersheetsRefShow =
75  appSettings ? appSettings->m_Drawing.intersheets_ref_show : false;
76  bool defaultIntersheetsRefOwnPage =
77  appSettings ? appSettings->m_Drawing.intersheets_ref_own_page : true;
78  bool defaultIntersheetsRefFormatShort =
79  appSettings ? appSettings->m_Drawing.intersheets_ref_short : false;
80  wxString defaultIntersheetsRefPrefix =
81  appSettings ? appSettings->m_Drawing.intersheets_ref_prefix : DEFAULT_IREF_PREFIX;
82  wxString defaultIntersheetsRefSuffix =
83  appSettings ? appSettings->m_Drawing.intersheets_ref_suffix : DEFAULT_IREF_SUFFIX;
84 
85  m_params.emplace_back( new PARAM<bool>( "drawing.intersheets_ref_show",
86  &m_IntersheetRefsShow, defaultIntersheetsRefShow ) );
87 
88  m_params.emplace_back( new PARAM<bool>( "drawing.intersheets_ref_own_page",
89  &m_IntersheetRefsListOwnPage, defaultIntersheetsRefOwnPage ) );
90 
91  m_params.emplace_back( new PARAM<bool>( "drawing.intersheets_ref_short",
92  &m_IntersheetRefsFormatShort, defaultIntersheetsRefFormatShort ) );
93 
94  m_params.emplace_back( new PARAM<wxString>( "drawing.intersheets_ref_prefix",
95  &m_IntersheetRefsPrefix, defaultIntersheetsRefPrefix ) );
96 
97  m_params.emplace_back( new PARAM<wxString>( "drawing.intersheets_ref_suffix",
98  &m_IntersheetRefsSuffix, defaultIntersheetsRefSuffix ) );
99 
100  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_line_thickness",
101  &m_DefaultLineWidth, Mils2iu( defaultLineThickness ),
102  Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
103 
104  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_wire_thickness",
105  &m_DefaultWireThickness, Mils2iu( defaultWireThickness ),
106  Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
107 
108  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_bus_thickness",
109  &m_DefaultBusThickness, Mils2iu( defaultBusThickness ),
110  Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
111 
112  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_text_size",
114  Mils2iu( defaultTextSize ), Mils2iu( 5 ), Mils2iu( 1000 ),
115  1 / IU_PER_MILS ) );
116 
117  m_params.emplace_back( new PARAM<double>( "drawing.text_offset_ratio",
119  (double) TXT_MARGIN / DEFAULT_SIZE_TEXT, -200.0, 200.0 ) );
120 
121  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.pin_symbol_size",
123  Mils2iu( defaultPinSymbolSize ), Mils2iu( 5 ), Mils2iu( 1000 ),
124  1 / IU_PER_MILS ) );
125 
126  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_junction_size",
128  Mils2iu( defaultJunctionSize ), Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
129 
130  // User choice for junction dot size ( e.g. none = 0, smallest = 1, small = 2, etc )
131  m_params.emplace_back( new PARAM<int>( "drawing.junction_size_choice",
133  defaultJunctionSizeChoice ) );
134 
135  m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "drawing.field_names",
136  [&]() -> nlohmann::json
137  {
138  nlohmann::json ret = nlohmann::json::array();
139 
140  for( const TEMPLATE_FIELDNAME& field :
142  {
143  ret.push_back( nlohmann::json( {
144  { "name", field.m_Name },
145  { "visible", field.m_Visible },
146  { "url", field.m_URL }
147  } ) );
148  }
149 
150  return ret;
151  },
152  [&]( const nlohmann::json& aJson )
153  {
154  if( !aJson.empty() && aJson.is_array() )
155  {
157 
158  for( const nlohmann::json& entry : aJson )
159  {
160  if( !entry.contains( "name" ) || !entry.contains( "url" )
161  || !entry.contains( "visible" ) )
162  continue;
163 
164  TEMPLATE_FIELDNAME field( entry["name"].get<wxString>() );
165  field.m_URL = entry["url"].get<bool>();
166  field.m_Visible = entry["visible"].get<bool>();
168  }
169  }
170 
171  auto* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
172 
173  if( cfg )
174  {
175  // Read global fieldname templates
176  wxString templateFieldNames = cfg->m_Drawing.field_names;
177 
178  if( !templateFieldNames.IsEmpty() )
179  {
180  TEMPLATE_FIELDNAMES_LEXER field_lexer( TO_UTF8( templateFieldNames ) );
181 
182  try
183  {
184  m_TemplateFieldNames.Parse( &field_lexer, true );
185  }
186  catch( const IO_ERROR& )
187  {
188  }
189  }
190  }
191  }, {} ) );
192 
193  // TODO(JE) get rid of this static
194  m_params.emplace_back( new PARAM<wxString>( "page_layout_descr_file",
196 
197  m_params.emplace_back( new PARAM<wxString>( "plot_directory",
198  &m_PlotDirectoryName, "" ) );
199 
200  m_params.emplace_back( new PARAM<wxString>( "net_format_name",
201  &m_NetFormatName, "" ) );
202 
203  m_params.emplace_back( new PARAM<bool>( "spice_adjust_passive_values",
204  &m_SpiceAdjustPassiveValues, false ) );
205 
206  m_params.emplace_back( new PARAM<wxString>( "spice_external_command",
207  &m_SpiceCommandString, "spice \"%I\"" ) );
208 
209  // TODO(JE) should we keep these LIB_SYMBOL:: things around?
210  m_params.emplace_back( new PARAM<int>( "subpart_id_separator",
211  LIB_SYMBOL::SubpartIdSeparatorPtr(), 0, 0, 126 ) );
212 
213  m_params.emplace_back( new PARAM<int>( "subpart_first_id",
214  LIB_SYMBOL::SubpartFirstIdPtr(), 'A', '1', 'z' ) );
215 
216  m_params.emplace_back( new PARAM<int>( "annotate_start_num",
217  &m_AnnotateStartNum, 0 ) );
218 
220  std::make_shared<NGSPICE_SIMULATOR_SETTINGS>( this, "ngspice" );
221 }
222 
223 
225 {
228 
229  if( m_parent )
230  {
232  m_parent = nullptr;
233  }
234 }
#define DEFAULT_SIZE_TEXT
This is the "default-of-the-default" hardcoded text size; individual application define their own def...
Definition: eda_text.h:80
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
void AddTemplateFieldName(const TEMPLATE_FIELDNAME &aFieldName, bool aGlobal)
Insert or append a wanted symbol field name into the field names template.
void Parse(TEMPLATE_FIELDNAMES_LEXER *in, bool aGlobal)
Fill this object from information in the input stream handled by #TEMPLATE_FIELDNAMES_LEXER.
TEMPLATES m_TemplateFieldNames
static int * SubpartFirstIdPtr()
Return a reference to m_subpartFirstId, only for read/save setting functions.
Definition: lib_symbol.h:525
#define DEFAULT_JUNCTION_DIAM
The default bus and wire entry size in mils.
void DeleteAllFieldNameTemplates(bool aGlobal)
Delete the entire contents.
nlohmann::json json
Definition: gerbview.cpp:41
std::shared_ptr< NGSPICE_SIMULATOR_SETTINGS > m_NgspiceSimulatorSettings
Ngspice simulator settings.
This file contains miscellaneous commonly used macros and functions.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
NESTED_SETTINGS is a JSON_SETTINGS that lives inside a JSON_SETTINGS.
#define DEFAULT_IREF_PREFIX
The intersheets references suffix string.
const int schSettingsSchemaVersion
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
JSON_SETTINGS * m_parent
A pointer to the parent object to load and store from.
Represents a parameter that has a scaling factor between the value in the file and the value used int...
Definition: parameters.h:354
#define DEFAULT_IREF_SUFFIX
Radius of snap "gravity well".
#define DEFAULT_LINE_THICKNESS
The default wire width in mils. (can be changed in preference menu)
#define DEFAULT_BUS_THICKNESS
The default noconnect size in mils.
SCHEMATIC_SETTINGS(JSON_SETTINGS *aParent, const std::string &aPath)
#define TXT_MARGIN
The default pin len value when creating pins(can be changed in preference menu)
static int * SubpartIdSeparatorPtr()
Return a reference to m_subpartIdSeparator, only for read/save setting functions.
Definition: lib_symbol.h:519
static wxString m_DrawingSheetFileName
the name of the drawing sheet file, or empty to use the default drawing sheet
Definition: base_screen.h:85
#define DEFAULT_WIRE_THICKNESS
The default bus width in mils. (can be changed in preference menu)
#define IU_PER_MILS
Definition: plotter.cpp:137
Hold a name of a symbol's field, field value, and default visibility.
#define DEFAULT_TEXT_SIZE
Ratio of the font height to the baseline of the text above the wire.
void ReleaseNestedSettings(NESTED_SETTINGS *aSettings)
Saves and frees a nested settings object, if it exists within this one.
BASE_SCREEN class implementation.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75
const TEMPLATE_FIELDNAMES & GetTemplateFieldNames()
Return a template field name list for read only access.
#define DEFAULT_TEXT_OFFSET_RATIO
The offset of the pin name string from the end of the pin in mils.