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  * @author Jon Evans <jon@craftyjon.com>
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <base_screen.h>
22 #include <class_libentry.h>
23 #include <convert_to_biu.h>
24 #include <default_values.h>
25 #include <eda_text.h>
26 #include <eeschema_settings.h>
27 #include <kiface_i.h>
28 #include <schematic_settings.h>
29 #include <settings/parameters.h>
30 
31 
33 
34 
35 SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
36  NESTED_SETTINGS( "schematic", schSettingsSchemaVersion, aParent, aPath ),
37  m_DefaultLineWidth( DEFAULT_LINE_THICKNESS * IU_PER_MILS ),
38  m_DefaultWireThickness( DEFAULT_WIRE_THICKNESS * IU_PER_MILS ),
39  m_DefaultBusThickness( DEFAULT_BUS_THICKNESS * IU_PER_MILS ),
40  m_DefaultTextSize( DEFAULT_TEXT_SIZE * IU_PER_MILS ),
41  m_TextOffsetRatio( DEFAULT_TEXT_OFFSET_RATIO ),
42  m_PinSymbolSize( DEFAULT_TEXT_SIZE * IU_PER_MILS / 2 ),
43  m_JunctionSize( DEFAULT_JUNCTION_DIAM * IU_PER_MILS ),
44  m_JunctionSizeChoice( 3 ),
45  m_IntersheetRefsShow( false ),
46  m_IntersheetRefsFormatShort( false ),
47  m_IntersheetRefsPrefix( DEFAULT_IREF_PREFIX ),
48  m_IntersheetRefsSuffix( DEFAULT_IREF_SUFFIX ),
49  m_SpiceAdjustPassiveValues( false )
50 {
51  EESCHEMA_SETTINGS* appSettings = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
52 
53  int defaultLineThickness =
54  appSettings ? appSettings->m_Drawing.default_line_thickness : DEFAULT_LINE_THICKNESS;
55  int defaultWireThickness =
56  appSettings ? appSettings->m_Drawing.default_wire_thickness : DEFAULT_WIRE_THICKNESS;
57  int defaultBusThickness =
58  appSettings ? appSettings->m_Drawing.default_bus_thickness : DEFAULT_BUS_THICKNESS;
59  int defaultTextSize =
60  appSettings ? appSettings->m_Drawing.default_text_size : DEFAULT_TEXT_SIZE;
61  int defaultPinSymbolSize =
62  appSettings ? appSettings->m_Drawing.pin_symbol_size : DEFAULT_TEXT_SIZE / 2;
63  int defaultJunctionSize =
64  appSettings ? appSettings->m_Drawing.default_junction_size : DEFAULT_JUNCTION_DIAM;
65  int defaultJunctionSizeChoice =
66  appSettings ? appSettings->m_Drawing.junction_size_choice : 3;
67  bool defaultIntersheetsRefShow =
68  appSettings ? appSettings->m_Drawing.intersheets_ref_show : false;
69  bool defaultIntersheetsRefFormatShort =
70  appSettings ? appSettings->m_Drawing.intersheets_ref_short : false;
71  wxString defaultIntersheetsRefPrefix =
72  appSettings ? appSettings->m_Drawing.intersheets_ref_prefix : DEFAULT_IREF_PREFIX;
73  wxString defaultIntersheetsRefSuffix =
74  appSettings ? appSettings->m_Drawing.intersheets_ref_suffix : DEFAULT_IREF_SUFFIX;
75 
76  m_params.emplace_back( new PARAM<bool>( "drawing.intersheets_ref_show",
77  &m_IntersheetRefsShow, defaultIntersheetsRefShow ) );
78 
79  m_params.emplace_back( new PARAM<bool>( "drawing.intersheets_ref_short",
80  &m_IntersheetRefsFormatShort, defaultIntersheetsRefFormatShort ) );
81 
82  m_params.emplace_back( new PARAM<wxString>( "drawing.intersheets_ref_prefix",
83  &m_IntersheetRefsPrefix, defaultIntersheetsRefPrefix ) );
84 
85  m_params.emplace_back( new PARAM<wxString>( "drawing.intersheets_ref_suffix",
86  &m_IntersheetRefsSuffix, defaultIntersheetsRefSuffix ) );
87 
88  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_line_thickness",
89  &m_DefaultLineWidth, Mils2iu( defaultLineThickness ),
90  Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
91 
92  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_wire_thickness",
93  &m_DefaultWireThickness, Mils2iu( defaultWireThickness ),
94  Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
95 
96  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_bus_thickness",
97  &m_DefaultBusThickness, Mils2iu( defaultBusThickness ),
98  Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
99 
100  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_text_size",
102  Mils2iu( defaultTextSize ), Mils2iu( 5 ), Mils2iu( 1000 ),
103  1 / IU_PER_MILS ) );
104 
105  m_params.emplace_back( new PARAM<double>( "drawing.text_offset_ratio",
107  (double) TXT_MARGIN / DEFAULT_SIZE_TEXT, -200.0, 200.0 ) );
108 
109  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.pin_symbol_size",
111  Mils2iu( defaultPinSymbolSize ), Mils2iu( 5 ), Mils2iu( 1000 ),
112  1 / IU_PER_MILS ) );
113 
114  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_junction_size",
116  Mils2iu( defaultJunctionSize ), Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
117 
118  // User choice for junction dot size ( e.g. none = 0, smallest = 1, small = 2, etc )
119  m_params.emplace_back(new PARAM<int>("drawing.junction_size_choice",
121  defaultJunctionSizeChoice) );
122 
123  m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "drawing.field_names",
124  [&]() -> nlohmann::json
125  {
126  nlohmann::json ret = nlohmann::json::array();
127 
128  for( const TEMPLATE_FIELDNAME& field :
130  {
131  ret.push_back( nlohmann::json( {
132  { "name", field.m_Name },
133  { "visible", field.m_Visible },
134  { "url", field.m_URL }
135  } ) );
136  }
137 
138  return ret;
139  },
140  [&]( const nlohmann::json& aJson )
141  {
142  if( !aJson.empty() && aJson.is_array() )
143  {
145 
146  for( const nlohmann::json& entry : aJson )
147  {
148  if( !entry.contains( "name" ) || !entry.contains( "url" )
149  || !entry.contains( "visible" ) )
150  continue;
151 
152  TEMPLATE_FIELDNAME field( entry["name"].get<wxString>() );
153  field.m_URL = entry["url"].get<bool>();
154  field.m_Visible = entry["visible"].get<bool>();
156  }
157  }
158 
159  auto* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
160 
161  if( cfg )
162  {
163  // Read global fieldname templates
164  wxString templateFieldNames = cfg->m_Drawing.field_names;
165 
166  if( !templateFieldNames.IsEmpty() )
167  {
168  TEMPLATE_FIELDNAMES_LEXER field_lexer( TO_UTF8( templateFieldNames ) );
169 
170  try
171  {
172  m_TemplateFieldNames.Parse( &field_lexer, true );
173  }
174  catch( const IO_ERROR& )
175  {
176  }
177  }
178  }
179  }, {} ) );
180 
181  // TOOD(JE) get rid of this static
182  m_params.emplace_back( new PARAM<wxString>( "page_layout_descr_file",
184 
185  m_params.emplace_back( new PARAM<wxString>( "plot_directory",
186  &m_PlotDirectoryName, "" ) );
187 
188  m_params.emplace_back( new PARAM<wxString>( "net_format_name",
189  &m_NetFormatName, "" ) );
190 
191  m_params.emplace_back( new PARAM<bool>( "spice_adjust_passive_values",
192  &m_SpiceAdjustPassiveValues, false ) );
193 
194  m_params.emplace_back( new PARAM<wxString>( "spice_external_command",
195  &m_SpiceCommandString, "spice \"%I\"" ) );
196 
197  // TODO(JE) should we keep these LIB_PART:: things around?
198  m_params.emplace_back( new PARAM<int>( "subpart_id_separator",
199  LIB_PART::SubpartIdSeparatorPtr(), 0, 0, 126 ) );
200 
201  m_params.emplace_back( new PARAM<int>( "subpart_first_id",
202  LIB_PART::SubpartFirstIdPtr(), 'A', '1', 'z' ) );
203 }
204 
205 
207 {
208  if( m_parent )
209  {
211  m_parent = nullptr;
212  }
213 }
#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
static int * SubpartFirstIdPtr()
return a reference to m_subpartFirstId, only for read/save setting functions
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
void AddTemplateFieldName(const TEMPLATE_FIELDNAME &aFieldName, bool aGlobal)
Function AddTemplateFieldName inserts or appends a wanted symbol field name into the fieldnames templ...
void Parse(TEMPLATE_FIELDNAMES_LEXER *in, bool aGlobal)
Function Parse fills this object from information in the input stream handled by TEMPLATE_FIELDNAMES_...
TEMPLATES m_TemplateFieldNames
#define DEFAULT_JUNCTION_DIAM
The default bus and wire enty size in mils.
void DeleteAllFieldNameTemplates(bool aGlobal)
Function DeleteAllFieldNameTemplates deletes the entire contents.
nlohmann::json json
Definition: gerbview.cpp:39
static wxString m_PageLayoutDescrFileName
the name of the page layout descr file, or emty to used the default pagelayout
Definition: base_screen.h:84
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
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:388
#define DEFAULT_IREF_SUFFIX
#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)
#define DEFAULT_WIRE_THICKNESS
The default bus width in mils. (can be changed in preference menu)
#define IU_PER_MILS
Definition: plotter.cpp:137
static int * SubpartIdSeparatorPtr()
return a reference to m_subpartIdSeparator, only for read/save setting functions
Struct TEMPLATE_FIELDNAME holds a name of a component'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.
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
const TEMPLATE_FIELDNAMES & GetTemplateFieldNames()
Function GetTemplateFieldName returns a template fieldnames 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.