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 The 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, see <https://www.gnu.org/licenses/>.
18*/
19
20#include <json_common.h>
21
23#include <settings/parameters.h>
27#include <default_values.h>
28
29
32
33
35 APP_SETTINGS_BASE( "symbol_editor", libeditSchemaVersion ),
36 m_Defaults(),
37 m_Repeat(),
39 m_LibWidth(),
41{
42 // Make Coverity happy
44
45 // Init settings:
46 SetLegacyFilename( wxS( "eeschema" ) );
47
48 m_params.emplace_back( new PARAM<bool>( "aui.show_properties",
49 &m_AuiPanels.show_properties, true ) );
50
51 m_params.emplace_back( new PARAM<int>( "aui.properties_panel_width",
52 &m_AuiPanels.properties_panel_width, -1 ) );
53
54 m_params.emplace_back( new PARAM<float>( "aui.properties_splitter_proportion",
55 &m_AuiPanels.properties_splitter, 0.5f ) );
56
57 m_params.emplace_back( new PARAM<int>( "defaults.line_width",
58 &m_Defaults.line_width, 0 ) );
59
60 m_params.emplace_back( new PARAM<int>( "defaults.text_size",
61 &m_Defaults.text_size, DEFAULT_TEXT_SIZE ) );
62
63 m_params.emplace_back( new PARAM<int>( "defaults.pin_length",
64 &m_Defaults.pin_length, DEFAULT_PIN_LENGTH ) );
65
66 m_params.emplace_back( new PARAM<int>( "defaults.pin_name_size",
67 &m_Defaults.pin_name_size, DEFAULT_PINNAME_SIZE ) );
68
69 m_params.emplace_back( new PARAM<int>( "defaults.pin_num_size",
70 &m_Defaults.pin_num_size, DEFAULT_PINNUM_SIZE ) );
71
72 m_params.emplace_back( new PARAM<int>( "repeat.label_delta",
73 &m_Repeat.label_delta, 1 ) );
74
75 m_params.emplace_back( new PARAM<int>( "repeat.pin_step",
76 &m_Repeat.pin_step, 100 ) );
77
78 m_params.emplace_back( new PARAM<bool>( "show_pin_electrical_type",
79 &m_ShowPinElectricalType, true ) );
80
81 m_params.emplace_back( new PARAM<bool>( "show_pin_alt_icons",
82 &m_ShowPinAltIcons, true ) );
83
84 m_params.emplace_back( new PARAM<bool>( "show_hidden_lib_fields",
85 &m_ShowHiddenFields, true ) );
86
87 m_params.emplace_back( new PARAM<bool>( "show_hidden_lib_pins",
88 &m_ShowHiddenPins, true ) );
89
90 m_params.emplace_back( new PARAM<bool>( "drag_pins_along_with_edges",
91 &m_dragPinsAlongWithEdges, true ) );
92
93 m_params.emplace_back( new PARAM<int>( "lib_table_width",
94 &m_LibWidth, 250 ) );
95
96 m_params.emplace_back( new PARAM<int>( "library.sort_mode",
97 &m_LibrarySortMode, 0 ) );
98
99 m_params.emplace_back( new PARAM<bool>( "use_eeschema_color_settings",
101
102 m_params.emplace_back( new PARAM<int>( "editing.arc_edit_mode",
103 reinterpret_cast<int*>( &m_ArcEditMode ),
105
107
108 m_params.emplace_back( new PARAM_MAP<int>( "lib_field_editor.field_widths",
109 &m_LibFieldEditor.field_widths, {} ) );
110
111 m_params.emplace_back( new PARAM<int>( "lib_field_editor.sash_pos",
112 &m_LibFieldEditor.sash_pos, 400 ) );
113
114 m_params.emplace_back( new PARAM<bool>( "lib_field_editor.sidebar_collapsed",
115 &m_LibFieldEditor.sidebar_collapsed, false ) );
116
117 m_params.emplace_back( new PARAM<bool>( "pin_table.crossprobe_on_selection",
118 &m_PinTable.crossprobe_on_selection, true ) );
119
120 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "selection_filter",
121 [&]() -> nlohmann::json
122 {
123 nlohmann::json ret;
124
125 ret["lockedItems"] = m_SelectionFilter.lockedItems;
126 ret["symbols"] = m_SelectionFilter.symbols;
127 ret["text"] = m_SelectionFilter.text;
128 ret["wires"] = m_SelectionFilter.wires;
129 ret["labels"] = m_SelectionFilter.labels;
130 ret["pins"] = m_SelectionFilter.pins;
131 ret["graphics"] = m_SelectionFilter.graphics;
132 ret["images"] = m_SelectionFilter.images;
133 ret["otherItems"] = m_SelectionFilter.otherItems;
134
135 return ret;
136 },
137 [&]( const nlohmann::json& aVal )
138 {
139 if( aVal.empty() || !aVal.is_object() )
140 return;
141
142 SetIfPresent( aVal, "lockedItems", m_SelectionFilter.lockedItems );
143 SetIfPresent( aVal, "symbols", m_SelectionFilter.symbols );
144 SetIfPresent( aVal, "text", m_SelectionFilter.text );
145 SetIfPresent( aVal, "wires", m_SelectionFilter.wires );
146 SetIfPresent( aVal, "labels", m_SelectionFilter.labels );
147 SetIfPresent( aVal, "pins", m_SelectionFilter.pins );
148 SetIfPresent( aVal, "graphics", m_SelectionFilter.graphics );
149 SetIfPresent( aVal, "images", m_SelectionFilter.images );
150 SetIfPresent( aVal, "otherItems", m_SelectionFilter.otherItems );
151 },
152 {
153 { "lockedItems", false },
154 { "symbols", true },
155 { "text", true },
156 { "wires", true },
157 { "labels", true },
158 { "pins", true },
159 { "graphics", true },
160 { "images", true },
161 { "otherItems", true }
162 } ) );
163
164 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "open_tabs",
165 [&]() -> nlohmann::json
166 {
167 nlohmann::json ret = nlohmann::json::array();
168
169 for( const OPEN_TAB& tab : m_OpenTabs )
170 {
171 nlohmann::json entry;
172
173 entry["lib"] = tab.lib.ToUTF8();
174 entry["name"] = tab.name.ToUTF8();
175 entry["unit"] = tab.unit;
176 entry["body_style"] = tab.bodyStyle;
177 entry["preview"] = tab.preview;
178
179 ret.push_back( entry );
180 }
181
182 return ret;
183 },
184 [&]( const nlohmann::json& aVal )
185 {
186 m_OpenTabs.clear();
187
188 if( !aVal.is_array() )
189 return;
190
191 for( const nlohmann::json& entry : aVal )
192 {
193 if( !entry.is_object() || !entry.contains( "lib" ) || !entry.contains( "name" ) )
194 continue;
195
196 OPEN_TAB tab;
197
198 tab.lib = wxString::FromUTF8( entry["lib"].get<std::string>() );
199 tab.name = wxString::FromUTF8( entry["name"].get<std::string>() );
200
201 if( entry.contains( "unit" ) )
202 tab.unit = entry["unit"].get<int>();
203
204 if( entry.contains( "body_style" ) )
205 tab.bodyStyle = entry["body_style"].get<int>();
206
207 if( entry.contains( "preview" ) )
208 tab.preview = entry["preview"].get<bool>();
209
210 m_OpenTabs.push_back( tab );
211 }
212 },
213 nlohmann::json::array() ) );
214
215 m_params.emplace_back( new PARAM<wxString>( "active_tab", &m_ActiveTabKey, wxEmptyString ) );
216
217 registerMigration( 0, 1,
218 [&]() -> bool
219 {
220 // This is actually a migration for APP_SETTINGS_BASE::m_LibTree
221 return migrateLibTreeWidth();
222 } );
223}
224
225
227{
228 bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
229
230 // Now modify the loaded grid selection, because in earlier versions the grids index was shared
231 // between all applications and started at 1000 mils. There is a 4-position offset between
232 // this index and the possible eeschema grids list that we have to subtract.
233 std::string gridSizePtr = "window.grid.last_size";
234
235 if( std::optional<int> currentSize = Get<int>( gridSizePtr ) )
236 {
237 Set( gridSizePtr, *currentSize - 4 );
238 }
239 else
240 {
241 // Otherwise, default grid size should be 50 mils; index 1
242 Set( gridSizePtr, 1 );
243 }
244
245 ret &= fromLegacy<int>( aCfg, "DefaultWireWidth", "defaults.line_width" );
246 ret &= fromLegacy<int>( aCfg, "DefaultPinLength", "defaults.pin_length" );
247 ret &= fromLegacy<int>( aCfg, "LibeditPinNameSize", "defaults.pin_name_size" );
248 ret &= fromLegacy<int>( aCfg, "LibeditPinNumSize", "defaults.pin_num_size" );
249
250 ret &= fromLegacy<int>( aCfg, "LibeditRepeatLabelInc", "repeat.label_delta" );
251 ret &= fromLegacy<int>( aCfg, "LibeditPinRepeatStep", "repeat.pin_step" );
252 ret &= fromLegacy<int>( aCfg, "LibeditRepeatStepX", "repeat.x_step" );
253 ret &= fromLegacy<int>( aCfg, "LibeditRepeatStepY", "repeat.y_step" );
254
255 ret &= fromLegacy<int>( aCfg, "LibeditLibWidth", "lib_table_width" );
256 ret &= fromLegacy<bool>( aCfg, "LibeditShowPinElectricalType", "show_pin_electrical_type" );
257
258 return ret;
259}
ARC_EDIT_MODE
Settings for arc editing.
@ KEEP_CENTER_ADJUST_ANGLE_RADIUS
When editing endpoints, the angle and radius are adjusted.
APP_SETTINGS_BASE(const std::string &aFilename, int aSchemaVersion)
virtual bool MigrateFromLegacy(wxConfigBase *aCfg) override
Migrates from wxConfig to JSON-based configuration.
bool migrateLibTreeWidth()
Migrate the library tree width setting from a single column (Item) to multi-column.
bool fromLegacy(wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
Translates a legacy wxConfig 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::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 SetLegacyFilename(const wxString &aFilename)
Like a normal param, but with custom getter and setter functions.
Definition parameters.h:299
Represents a map of <std::string, Value>.
Definition parameters.h:752
virtual bool MigrateFromLegacy(wxConfigBase *aLegacyConfig) override
Migrates from wxConfig to JSON-based configuration.
SNAP_INFERENCE_SETTINGS m_SnapInference
PANEL_LIB_FIELDS_TABLE m_LibFieldEditor
std::vector< OPEN_TAB > m_OpenTabs
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.
void AddSnapInferenceParams(std::vector< PARAM_BASE * > &aParams, SNAP_INFERENCE_SETTINGS &aSettings)
Register the snap inference parameters.
One persisted open editor tab, restored on the next session.
const int libeditSchemaVersion
! Update the schema version whenever a migration is required