KiCad PCB EDA Suite
Loading...
Searching...
No Matches
symbol_editor_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-2023 KiCad Developers, see AUTHORS.txt for contributors.
5*
6* This program is free software; you can redistribute it and/or
7* modify it under the terms of the GNU General Public License
8* as published by the Free Software Foundation; either version 2
9* of the License, or (at your option) any later version.
10*
11* This program is distributed in the hope that it will be useful,
12* but WITHOUT ANY WARRANTY; without even the implied warranty of
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14* GNU General Public License for more details.
15*
16* You should have received a copy of the GNU General Public License
17* along with this program; if not, you may find one here:
18* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19* or you may search the http://www.gnu.org website for the version 2 license,
20* or you may write to the Free Software Foundation, Inc.,
21* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22*/
23
24#include <json_common.h>
25
27#include <settings/parameters.h>
30#include <default_values.h>
31
32
35
36
38 APP_SETTINGS_BASE( "symbol_editor", libeditSchemaVersion ),
39 m_Defaults(),
40 m_Repeat(),
41 m_ImportGraphics(),
42 m_ShowPinElectricalType( true ),
43 m_LibWidth(),
44 m_EditSymbolVisibleColumns()
45{
46 // Make Coverity happy
48
49 // Init settings:
50 SetLegacyFilename( wxS( "eeschema" ) );
51
52 m_params.emplace_back( new PARAM<bool>( "aui.show_properties",
54
55 m_params.emplace_back( new PARAM<int>( "aui.properties_panel_width",
57
58 m_params.emplace_back( new PARAM<float>( "aui.properties_splitter_proportion",
60
61 m_params.emplace_back( new PARAM<int>( "defaults.line_width",
62 &m_Defaults.line_width, 0 ) );
63
64 m_params.emplace_back( new PARAM<int>( "defaults.text_size",
66
67 m_params.emplace_back( new PARAM<int>( "defaults.pin_length",
69
70 m_params.emplace_back( new PARAM<int>( "defaults.pin_name_size",
72
73 m_params.emplace_back( new PARAM<int>( "defaults.pin_num_size",
75
76 m_params.emplace_back( new PARAM<int>( "repeat.label_delta",
77 &m_Repeat.label_delta, 1 ) );
78
79 m_params.emplace_back( new PARAM<int>( "repeat.pin_step",
80 &m_Repeat.pin_step, 100 ) );
81
82 m_params.emplace_back( new PARAM<bool>( "import_graphics.interactive_placement",
84
85 m_params.emplace_back( new PARAM<int>( "import_graphics.line_width_units",
87
88 m_params.emplace_back( new PARAM<double>( "import_graphics.line_width",
90
91 m_params.emplace_back( new PARAM<int>( "import_graphics.origin_units",
93
94 m_params.emplace_back( new PARAM<double>( "import_graphics.origin_x",
96
97 m_params.emplace_back( new PARAM<double>( "import_graphics.origin_y",
99
100 m_params.emplace_back( new PARAM<int>( "import_graphics.dxf_units",
102
103 m_params.emplace_back( new PARAM<bool>( "show_pin_electrical_type",
104 &m_ShowPinElectricalType, true ) );
105
106 m_params.emplace_back( new PARAM<bool>( "show_pin_alt_icons",
107 &m_ShowPinAltIcons, true ) );
108
109 m_params.emplace_back( new PARAM<bool>( "show_hidden_lib_fields",
110 &m_ShowHiddenFields, true ) );
111
112 m_params.emplace_back( new PARAM<bool>( "show_hidden_lib_pins",
113 &m_ShowHiddenPins, true ) );
114
115 m_params.emplace_back( new PARAM<bool>( "drag_pins_along_with_edges",
116 &m_dragPinsAlongWithEdges, true ) );
117
118 m_params.emplace_back( new PARAM<int>( "lib_table_width",
119 &m_LibWidth, 250 ) );
120
121 m_params.emplace_back( new PARAM<int>( "library.sort_mode",
122 &m_LibrarySortMode, 0 ) );
123
124 m_params.emplace_back( new PARAM<wxString>( "edit_symbol_visible_columns",
125 &m_EditSymbolVisibleColumns, "0 1 2 3 4 5 6 7" ) );
126
127 m_params.emplace_back( new PARAM<wxString>( "pin_table_visible_columns",
128 &m_PinTableVisibleColumns, "0 1 2 3 4 5 9 10" ) );
129
130 m_params.emplace_back( new PARAM<bool>( "use_eeschema_color_settings",
132
133 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "selection_filter",
134 [&]() -> nlohmann::json
135 {
136 nlohmann::json ret;
137
138 ret["lockedItems"] = m_SelectionFilter.lockedItems;
139 ret["symbols"] = m_SelectionFilter.symbols;
140 ret["text"] = m_SelectionFilter.text;
141 ret["wires"] = m_SelectionFilter.wires;
142 ret["labels"] = m_SelectionFilter.labels;
143 ret["pins"] = m_SelectionFilter.pins;
144 ret["graphics"] = m_SelectionFilter.graphics;
145 ret["images"] = m_SelectionFilter.images;
146 ret["otherItems"] = m_SelectionFilter.otherItems;
147
148 return ret;
149 },
150 [&]( const nlohmann::json& aVal )
151 {
152 if( aVal.empty() || !aVal.is_object() )
153 return;
154
155 SetIfPresent( aVal, "lockedItems", m_SelectionFilter.lockedItems );
156 SetIfPresent( aVal, "symbols", m_SelectionFilter.symbols );
157 SetIfPresent( aVal, "text", m_SelectionFilter.text );
158 SetIfPresent( aVal, "wires", m_SelectionFilter.wires );
159 SetIfPresent( aVal, "labels", m_SelectionFilter.labels );
160 SetIfPresent( aVal, "pins", m_SelectionFilter.pins );
161 SetIfPresent( aVal, "graphics", m_SelectionFilter.graphics );
162 SetIfPresent( aVal, "images", m_SelectionFilter.images );
163 SetIfPresent( aVal, "otherItems", m_SelectionFilter.otherItems );
164 },
165 {
166 { "lockedItems", false },
167 { "symbols", true },
168 { "text", true },
169 { "wires", true },
170 { "labels", true },
171 { "pins", true },
172 { "graphics", true },
173 { "images", true },
174 { "otherItems", true }
175 } ) );
176
177 registerMigration( 0, 1,
178 [&]() -> bool
179 {
180 // This is actually a migration for APP_SETTINGS_BASE::m_LibTree
181 return migrateLibTreeWidth();
182 } );
183}
184
185
187{
188 bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
189
190 // Now modify the loaded grid selection, because in earlier versions the grids index was shared
191 // between all applications and started at 1000 mils. There is a 4-position offset between
192 // this index and the possible eeschema grids list that we have to subtract.
193 std::string gridSizePtr = "window.grid.last_size";
194
195 if( std::optional<int> currentSize = Get<int>( gridSizePtr ) )
196 {
197 Set( gridSizePtr, *currentSize - 4 );
198 }
199 else
200 {
201 // Otherwise, default grid size should be 50 mils; index 1
202 Set( gridSizePtr, 1 );
203 }
204
205 ret &= fromLegacy<int>( aCfg, "DefaultWireWidth", "defaults.line_width" );
206 ret &= fromLegacy<int>( aCfg, "DefaultPinLength", "defaults.pin_length" );
207 ret &= fromLegacy<int>( aCfg, "LibeditPinNameSize", "defaults.pin_name_size" );
208 ret &= fromLegacy<int>( aCfg, "LibeditPinNumSize", "defaults.pin_num_size" );
209
210 ret &= fromLegacy<int>( aCfg, "LibeditRepeatLabelInc", "repeat.label_delta" );
211 ret &= fromLegacy<int>( aCfg, "LibeditPinRepeatStep", "repeat.pin_step" );
212 ret &= fromLegacy<int>( aCfg, "LibeditRepeatStepX", "repeat.x_step" );
213 ret &= fromLegacy<int>( aCfg, "LibeditRepeatStepY", "repeat.y_step" );
214
215 ret &= fromLegacy<int>( aCfg, "LibeditLibWidth", "lib_table_width" );
216 ret &= fromLegacy<bool>( aCfg, "LibeditShowPinElectricalType", "show_pin_electrical_type" );
217
218 ret &= fromLegacyString( aCfg, "LibEditFieldsShownColumns", "edit_symbol_visible_columns" );
219
220 ret &= fromLegacyString( aCfg, "PinTableShownColumns", "pin_table_visible_columns" );
221
222 return ret;
223}
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:92
virtual bool MigrateFromLegacy(wxConfigBase *aCfg) override
Migrates from wxConfig to JSON-based configuration.
bool migrateLibTreeWidth()
Migrates the library tree width setting from a single column (Item) to multi-column.
bool fromLegacyString(wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
Translates a legacy wxConfig string value to a given JSON pointer value.
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...
static bool SetIfPresent(const nlohmann::json &aObj, const std::string &aPath, wxString &aTarget)
Sets the given string if the given key/path is present.
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 SetLegacyFilename(const wxString &aFilename)
Definition: json_settings.h:89
Like a normal param, but with custom getter and setter functions.
Definition: parameters.h:293
virtual bool MigrateFromLegacy(wxConfigBase *aLegacyConfig) override
Migrates from wxConfig to JSON-based configuration.
DIALOG_IMPORT_GRAPHICS m_ImportGraphics
SCH_SELECTION_FILTER_OPTIONS m_SelectionFilter
bool m_ShowPinAltIcons
When true, dragging an outline edge will drag pins rooted on it.
#define DEFAULT_PINNUM_SIZE
The default pin name size when creating pins(can be changed in preference menu)
#define DEFAULT_PINNAME_SIZE
The default selection highlight thickness (can be changed in preference menu)
#define DEFAULT_PIN_LENGTH
The default pin number size when creating pins(can be changed in preference menu)
#define DEFAULT_TEXT_SIZE
Ratio of the font height to the baseline of the text above the wire.
bool symbols
Allow selecting symbols and sheet symbols.
bool labels
Net and bus labels.
bool pins
Symbol and sheet pins.
bool graphics
Graphic lines, shapes, polygons.
bool lockedItems
Allow selecting locked items.
bool images
Bitmap/vector images.
bool otherItems
Anything not fitting one of the above categories.
bool wires
Net and bus wires and junctions.
const int libeditSchemaVersion
! Update the schema version whenever a migration is required