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( 0.08 ),
42  m_PinSymbolSize( DEFAULT_TEXT_SIZE * IU_PER_MILS / 2 ),
43  m_JunctionSize( DEFAULT_JUNCTION_DIAM * IU_PER_MILS ),
44  m_SpiceAdjustPassiveValues( false ),
45  m_TemplateFieldNames( nullptr )
46 {
47  EESCHEMA_SETTINGS* appSettings = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
48 
49  int defaultLineThickness =
50  appSettings ? appSettings->m_Drawing.default_line_thickness : DEFAULT_LINE_THICKNESS;
51  int defaultWireThickness =
52  appSettings ? appSettings->m_Drawing.default_wire_thickness : DEFAULT_WIRE_THICKNESS;
53  int defaultBusThickness =
54  appSettings ? appSettings->m_Drawing.default_bus_thickness : DEFAULT_BUS_THICKNESS;
55  int defaultTextSize =
56  appSettings ? appSettings->m_Drawing.default_text_size : DEFAULT_TEXT_SIZE;
57  int defaultPinSymbolSize =
58  appSettings ? appSettings->m_Drawing.pin_symbol_size : DEFAULT_TEXT_SIZE / 2;
59  int defaultJunctionSize =
60  appSettings ? appSettings->m_Drawing.default_junction_size : DEFAULT_JUNCTION_DIAM;
61 
62  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_line_thickness",
63  &m_DefaultLineWidth, Mils2iu( defaultLineThickness ),
64  Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
65 
66  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_wire_thickness",
67  &m_DefaultWireThickness, Mils2iu( defaultWireThickness ),
68  Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
69 
70  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_bus_thickness",
71  &m_DefaultBusThickness, Mils2iu( defaultBusThickness ),
72  Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
73 
74  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_text_size", &m_DefaultTextSize,
75  Mils2iu( defaultTextSize ), Mils2iu( 5 ), Mils2iu( 1000 ),
76  1 / IU_PER_MILS ) );
77 
78  m_params.emplace_back( new PARAM<double>( "drawing.text_offset_ratio", &m_TextOffsetRatio,
79  (double) TXT_MARGIN / DEFAULT_SIZE_TEXT, -200.0, 200.0 ) );
80 
81  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.pin_symbol_size", &m_PinSymbolSize,
82  Mils2iu( defaultPinSymbolSize ), Mils2iu( 5 ), Mils2iu( 1000 ),
83  1 / IU_PER_MILS ) );
84 
85  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_junction_size", &m_JunctionSize,
86  Mils2iu( defaultJunctionSize ), Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
87 
88  m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "drawing.field_names",
89  [&]() -> nlohmann::json
90  {
91  nlohmann::json ret = nlohmann::json::array();
92 
94  return ret;
95 
96  for( const TEMPLATE_FIELDNAME& field :
98  {
99  ret.push_back( nlohmann::json( {
100  { "name", field.m_Name },
101  { "visible", field.m_Visible },
102  { "url", field.m_URL }
103  } ) );
104  }
105 
106  return ret;
107  },
108  [&]( const nlohmann::json& aJson )
109  {
110  if( !m_TemplateFieldNames || aJson.empty() || !aJson.is_array() )
111  return;
112 
114 
115  for( const nlohmann::json& entry : aJson )
116  {
117  if( !entry.contains( "name" ) || !entry.contains( "url" )
118  || !entry.contains( "visible" ) )
119  continue;
120 
121  TEMPLATE_FIELDNAME field( entry["name"].get<wxString>() );
122  field.m_URL = entry["url"].get<bool>();
123  field.m_Visible = entry["visible"].get<bool>();
125  }
126  }, {} ) );
127 
128  // TOOD(JE) get rid of this static
129  m_params.emplace_back( new PARAM<wxString>(
130  "page_layout_descr_file", &BASE_SCREEN::m_PageLayoutDescrFileName, "" ) );
131 
132  m_params.emplace_back( new PARAM<wxString>( "plot_directory", &m_PlotDirectoryName, "" ) );
133 
134  m_params.emplace_back( new PARAM<wxString>( "net_format_name", &m_NetFormatName, "" ) );
135 
136  m_params.emplace_back(
137  new PARAM<bool>( "spice_adjust_passive_values", &m_SpiceAdjustPassiveValues, false ) );
138 
139  m_params.emplace_back( new PARAM<wxString>( "spice_external_command",
140  &m_SpiceCommandString, "spice \"%I\"" ) );
141 
142  // TODO(JE) should we keep these LIB_PART:: things around?
143  m_params.emplace_back( new PARAM<int>(
144  "subpart_id_separator", LIB_PART::SubpartIdSeparatorPtr(), 0, 0, 126 ) );
145 
146  m_params.emplace_back(
147  new PARAM<int>( "subpart_first_id", LIB_PART::SubpartFirstIdPtr(), 'A', '1', 'z' ) );
148 }
149 
150 
152 {
153  if( m_parent )
154  {
156  m_parent = nullptr;
157  }
158 }
#define DEFAULT_SIZE_TEXT
This is the "default-of-the-default" hardcoded text size; individual application define their own def...
Definition: eda_text.h:74
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)
Like a normal param, but with custom getter and setter functions.
Definition: parameters.h:296
void AddTemplateFieldName(const TEMPLATE_FIELDNAME &aFieldName, bool aGlobal)
Function AddTemplateFieldName inserts or appends a wanted symbol field name into the fieldnames templ...
#define DEFAULT_JUNCTION_DIAM
The default bus and wire enty size in mils.
TEMPLATES * m_TemplateFieldNames
void DeleteAllFieldNameTemplates(bool aGlobal)
Function DeleteAllFieldNameTemplates deletes the entire contents.
nlohmann::json json
Definition: gerbview.cpp:40
static wxString m_PageLayoutDescrFileName
the name of the page layout descr file, or emty to used the default pagelayout
Definition: base_screen.h:57
NESTED_SETTINGS is a JSON_SETTINGS that lives inside a JSON_SETTINGS.
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_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:138
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
void ReleaseNestedSettings(NESTED_SETTINGS *aSettings)
Saves and frees a nested settings object, if it exists within this one.
BASE_SCREEN class implementation.
const TEMPLATE_FIELDNAMES & GetTemplateFieldNames()
Function GetTemplateFieldName returns a template fieldnames list for read only access.