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, 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(),
43{
44 // Make Coverity happy
46
47 // Init settings:
48 SetLegacyFilename( wxS( "eeschema" ) );
49
50 m_params.emplace_back( new PARAM<bool>( "aui.show_properties",
51 &m_AuiPanels.show_properties, true ) );
52
53 m_params.emplace_back( new PARAM<int>( "aui.properties_panel_width",
54 &m_AuiPanels.properties_panel_width, -1 ) );
55
56 m_params.emplace_back( new PARAM<float>( "aui.properties_splitter_proportion",
57 &m_AuiPanels.properties_splitter, 0.5f ) );
58
59 m_params.emplace_back( new PARAM<int>( "defaults.line_width",
60 &m_Defaults.line_width, 0 ) );
61
62 m_params.emplace_back( new PARAM<int>( "defaults.text_size",
63 &m_Defaults.text_size, DEFAULT_TEXT_SIZE ) );
64
65 m_params.emplace_back( new PARAM<int>( "defaults.pin_length",
66 &m_Defaults.pin_length, DEFAULT_PIN_LENGTH ) );
67
68 m_params.emplace_back( new PARAM<int>( "defaults.pin_name_size",
69 &m_Defaults.pin_name_size, DEFAULT_PINNAME_SIZE ) );
70
71 m_params.emplace_back( new PARAM<int>( "defaults.pin_num_size",
72 &m_Defaults.pin_num_size, DEFAULT_PINNUM_SIZE ) );
73
74 m_params.emplace_back( new PARAM<int>( "repeat.label_delta",
75 &m_Repeat.label_delta, 1 ) );
76
77 m_params.emplace_back( new PARAM<int>( "repeat.pin_step",
78 &m_Repeat.pin_step, 100 ) );
79
80 m_params.emplace_back( new PARAM<bool>( "show_pin_electrical_type",
81 &m_ShowPinElectricalType, true ) );
82
83 m_params.emplace_back( new PARAM<bool>( "show_pin_alt_icons",
84 &m_ShowPinAltIcons, true ) );
85
86 m_params.emplace_back( new PARAM<bool>( "show_hidden_lib_fields",
87 &m_ShowHiddenFields, true ) );
88
89 m_params.emplace_back( new PARAM<bool>( "show_hidden_lib_pins",
90 &m_ShowHiddenPins, true ) );
91
92 m_params.emplace_back( new PARAM<bool>( "drag_pins_along_with_edges",
93 &m_dragPinsAlongWithEdges, true ) );
94
95 m_params.emplace_back( new PARAM<int>( "lib_table_width",
96 &m_LibWidth, 250 ) );
97
98 m_params.emplace_back( new PARAM<int>( "library.sort_mode",
99 &m_LibrarySortMode, 0 ) );
100
101 m_params.emplace_back( new PARAM<bool>( "use_eeschema_color_settings",
103
104 m_params.emplace_back( new PARAM_MAP<int>( "lib_field_editor.field_widths",
105 &m_LibFieldEditor.field_widths, {} ) );
106
107 m_params.emplace_back( new PARAM<int>( "lib_field_editor.sash_pos",
108 &m_LibFieldEditor.sash_pos, 400 ) );
109
110 m_params.emplace_back( new PARAM<bool>( "lib_field_editor.sidebar_collapsed",
111 &m_LibFieldEditor.sidebar_collapsed, false ) );
112
113 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "selection_filter",
114 [&]() -> nlohmann::json
115 {
116 nlohmann::json ret;
117
118 ret["lockedItems"] = m_SelectionFilter.lockedItems;
119 ret["symbols"] = m_SelectionFilter.symbols;
120 ret["text"] = m_SelectionFilter.text;
121 ret["wires"] = m_SelectionFilter.wires;
122 ret["labels"] = m_SelectionFilter.labels;
123 ret["pins"] = m_SelectionFilter.pins;
124 ret["graphics"] = m_SelectionFilter.graphics;
125 ret["images"] = m_SelectionFilter.images;
126 ret["otherItems"] = m_SelectionFilter.otherItems;
127
128 return ret;
129 },
130 [&]( const nlohmann::json& aVal )
131 {
132 if( aVal.empty() || !aVal.is_object() )
133 return;
134
135 SetIfPresent( aVal, "lockedItems", m_SelectionFilter.lockedItems );
136 SetIfPresent( aVal, "symbols", m_SelectionFilter.symbols );
137 SetIfPresent( aVal, "text", m_SelectionFilter.text );
138 SetIfPresent( aVal, "wires", m_SelectionFilter.wires );
139 SetIfPresent( aVal, "labels", m_SelectionFilter.labels );
140 SetIfPresent( aVal, "pins", m_SelectionFilter.pins );
141 SetIfPresent( aVal, "graphics", m_SelectionFilter.graphics );
142 SetIfPresent( aVal, "images", m_SelectionFilter.images );
143 SetIfPresent( aVal, "otherItems", m_SelectionFilter.otherItems );
144 },
145 {
146 { "lockedItems", false },
147 { "symbols", true },
148 { "text", true },
149 { "wires", true },
150 { "labels", true },
151 { "pins", true },
152 { "graphics", true },
153 { "images", true },
154 { "otherItems", true }
155 } ) );
156
157 registerMigration( 0, 1,
158 [&]() -> bool
159 {
160 // This is actually a migration for APP_SETTINGS_BASE::m_LibTree
161 return migrateLibTreeWidth();
162 } );
163}
164
165
167{
168 bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
169
170 // Now modify the loaded grid selection, because in earlier versions the grids index was shared
171 // between all applications and started at 1000 mils. There is a 4-position offset between
172 // this index and the possible eeschema grids list that we have to subtract.
173 std::string gridSizePtr = "window.grid.last_size";
174
175 if( std::optional<int> currentSize = Get<int>( gridSizePtr ) )
176 {
177 Set( gridSizePtr, *currentSize - 4 );
178 }
179 else
180 {
181 // Otherwise, default grid size should be 50 mils; index 1
182 Set( gridSizePtr, 1 );
183 }
184
185 ret &= fromLegacy<int>( aCfg, "DefaultWireWidth", "defaults.line_width" );
186 ret &= fromLegacy<int>( aCfg, "DefaultPinLength", "defaults.pin_length" );
187 ret &= fromLegacy<int>( aCfg, "LibeditPinNameSize", "defaults.pin_name_size" );
188 ret &= fromLegacy<int>( aCfg, "LibeditPinNumSize", "defaults.pin_num_size" );
189
190 ret &= fromLegacy<int>( aCfg, "LibeditRepeatLabelInc", "repeat.label_delta" );
191 ret &= fromLegacy<int>( aCfg, "LibeditPinRepeatStep", "repeat.pin_step" );
192 ret &= fromLegacy<int>( aCfg, "LibeditRepeatStepX", "repeat.x_step" );
193 ret &= fromLegacy<int>( aCfg, "LibeditRepeatStepY", "repeat.y_step" );
194
195 ret &= fromLegacy<int>( aCfg, "LibeditLibWidth", "lib_table_width" );
196 ret &= fromLegacy<bool>( aCfg, "LibeditShowPinElectricalType", "show_pin_electrical_type" );
197
198 return ret;
199}
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:296
Represents a map of <std::string, Value>.
Definition parameters.h:735
virtual bool MigrateFromLegacy(wxConfigBase *aLegacyConfig) override
Migrates from wxConfig to JSON-based configuration.
PANEL_LIB_FIELDS_TABLE m_LibFieldEditor
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.
const int libeditSchemaVersion
! Update the schema version whenever a migration is required