KiCad PCB EDA Suite
Loading...
Searching...
No Matches
app_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 Jon Evans <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
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
22#include <common.h>
23#include <eda_units.h>
25#include <layer_ids.h>
26#include <pgm_base.h>
32#include <settings/parameters.h>
33#include <zoom_defines.h>
34
35
36APP_SETTINGS_BASE::APP_SETTINGS_BASE( const std::string& aFilename, int aSchemaVersion ) :
37 JSON_SETTINGS( aFilename, SETTINGS_LOC::USER, aSchemaVersion ),
40 m_Graphics(),
42 m_LibTree(),
43 m_Printing(),
45 m_System(),
46 m_Plugins(),
47 m_Window(),
48 m_CustomToolbars( false ),
49 m_appSettingsSchemaVersion( aSchemaVersion )
50{
51 // Build parameters list:
52 m_params.emplace_back(
53 new PARAM<int>( "find_replace.match_mode", &m_FindReplace.match_mode, 0 ) );
54
55 m_params.emplace_back(
56 new PARAM<bool>( "find_replace.match_case", &m_FindReplace.match_case, false ) );
57
58 m_params.emplace_back( new PARAM<bool>( "find_replace.search_and_replace",
59 &m_FindReplace.search_and_replace, false ) );
60
61 m_params.emplace_back( new PARAM<wxString>( "find_replace.find_string",
62 &m_FindReplace.find_string, wxS( "" ) ) );
63
64 m_params.emplace_back( new PARAM_LIST<wxString>( "find_replace.find_history",
65 &m_FindReplace.find_history, {} ) );
66
67 m_params.emplace_back( new PARAM<wxString>( "find_replace.replace_string",
68 &m_FindReplace.replace_string, "" ) );
69
70 m_params.emplace_back( new PARAM_LIST<wxString>( "find_replace.replace_history",
71 &m_FindReplace.replace_history, {} ) );
72
73 m_params.emplace_back( new PARAM<int>( "design_block_chooser.sash_pos_h",
74 &m_DesignBlockChooserPanel.sash_pos_h, -1 ) );
75
76 m_params.emplace_back( new PARAM<int>( "design_block_chooser.sash_pos_v",
77 &m_DesignBlockChooserPanel.sash_pos_v, -1 ) );
78
79 m_params.emplace_back( new PARAM<int>( "design_block_chooser.width",
80 &m_DesignBlockChooserPanel.width, -1 ) );
81
82 m_params.emplace_back( new PARAM<int>( "design_block_chooser.height",
83 &m_DesignBlockChooserPanel.height, -1 ) );
84
85 m_params.emplace_back( new PARAM<int>( "design_block_chooser.sort_mode",
86 &m_DesignBlockChooserPanel.sort_mode, 0 ) );
87
88 m_params.emplace_back( new PARAM<bool>( "design_block_chooser.repeated_placement",
89 &m_DesignBlockChooserPanel.repeated_placement, false ) );
90
91 m_params.emplace_back( new PARAM<bool>( "design_block_chooser.place_as_sheet",
92 &m_DesignBlockChooserPanel.place_as_sheet, false ) );
93
94 m_params.emplace_back( new PARAM<bool>( "design_block_chooser.place_as_group",
95 &m_DesignBlockChooserPanel.place_as_group, true ) );
96
97 m_params.emplace_back( new PARAM<bool>( "design_block_chooser.keep_annotations",
98 &m_DesignBlockChooserPanel.keep_annotations, false ) );
99
100 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>(
101 "design_block_chooser.lib_tree.column_widths",
102 [&]() -> nlohmann::json
103 {
104 nlohmann::json ret = {};
105
106 for( const auto& [name, width] : m_DesignBlockChooserPanel.tree.column_widths )
107 ret[std::string( name.ToUTF8() )] = width;
108
109 return ret;
110 },
111 [&]( const nlohmann::json& aJson )
112 {
113 if( !aJson.is_object() )
114 return;
115
116 m_DesignBlockChooserPanel.tree.column_widths.clear();
117
118 for( const auto& entry : aJson.items() )
119 {
120 if( !entry.value().is_number_integer() )
121 continue;
122
123 m_DesignBlockChooserPanel.tree.column_widths[entry.key()] = entry.value().get<int>();
124 }
125 },
126 {} ) );
127
128 m_params.emplace_back( new PARAM<float>( "graphics.highlight_factor",
129 &m_Graphics.highlight_factor, 0.5f, 0.0, 1.0f ) );
130
131 m_params.emplace_back( new PARAM<float>( "graphics.select_factor",
132 &m_Graphics.select_factor, 0.75f, 0.0, 1.0f ) );
133
134 m_params.emplace_back( new PARAM<int>( "color_picker.default_tab",
135 &m_ColorPicker.default_tab, 0 ) );
136
137 m_params.emplace_back( new PARAM_LIST<wxString>( "lib_tree.columns", &m_LibTree.columns, {} ) );
138
139 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "lib_tree.column_widths",
140 [&]() -> nlohmann::json
141 {
142 nlohmann::json ret = {};
143
144 for( const std::pair<const wxString, int>& pair : m_LibTree.column_widths )
145 ret[std::string( pair.first.ToUTF8() )] = pair.second;
146
147 return ret;
148 },
149 [&]( const nlohmann::json& aJson )
150 {
151 if( !aJson.is_object() )
152 return;
153
154 m_LibTree.column_widths.clear();
155
156 for( const auto& entry : aJson.items() )
157 {
158 if( !entry.value().is_number_integer() )
159 continue;
160
161 m_LibTree.column_widths[ entry.key() ] = entry.value().get<int>();
162 }
163 },
164 {} ) );
165
166 m_params.emplace_back(
167 new PARAM_LIST<wxString>( "lib_tree.open_libs", &m_LibTree.open_libs, {} ) );
168
169 m_params.emplace_back( new PARAM<bool>( "printing.background",
170 &m_Printing.background, false ) );
171
172 m_params.emplace_back( new PARAM<bool>( "printing.monochrome",
173 &m_Printing.monochrome, true ) );
174
175 m_params.emplace_back( new PARAM<double>( "printing.scale",
176 &m_Printing.scale, 1.0 ) );
177
178 m_params.emplace_back( new PARAM<bool>( "printing.use_theme",
179 &m_Printing.use_theme, false ) );
180
181 m_params.emplace_back( new PARAM<wxString>( "printing.color_theme",
182 &m_Printing.color_theme, wxS( "" ) ) );
183
184 m_params.emplace_back( new PARAM<bool>( "printing.title_block",
185 &m_Printing.title_block, false ) );
186
187 m_params.emplace_back( new PARAM_LIST<int>( "printing.layers",
188 &m_Printing.layers, {} ) );
189
190 m_params.emplace_back( new PARAM<int>( "search_pane.selection_zoom",
191 reinterpret_cast<int*>( &m_SearchPane.selection_zoom ),
192 static_cast<int>( SEARCH_PANE::SELECTION_ZOOM::PAN ) ) );
193
194 m_params.emplace_back( new PARAM<bool>( "search_pane.search_hidden_fields",
195 &m_SearchPane.search_hidden_fields, true ) );
196
197 m_params.emplace_back( new PARAM<bool>( "search_pane.search_metadata",
198 &m_SearchPane.search_metadata, false ) );
199
200 m_params.emplace_back( new PARAM<bool>( "system.first_run_shown",
201 &m_System.first_run_shown, false ) ); //@todo RFB remove? - not used
202
203 m_params.emplace_back( new PARAM<int>( "system.max_undo_items",
204 &m_System.max_undo_items, 0 ) );
205
206 // WARNING: "system.file_history" is a "known" key (see JSON_SETTINGS::GetFileHistories())
207 m_params.emplace_back( new PARAM_LIST<wxString>( "system.file_history",
208 &m_System.file_history, {} ) );
209
210 if( m_filename == wxS( "pl_editor" )
211 || ( m_filename == wxS( "eeschema" ) || m_filename == wxS( "symbol_editor" ) ) )
212 {
213 m_params.emplace_back( new PARAM<int>( "system.units",
214 &m_System.units, static_cast<int>( EDA_UNITS::MILS ) ) );
215 }
216 else
217 {
218 m_params.emplace_back( new PARAM<int>( "system.units",
219 &m_System.units, static_cast<int>( EDA_UNITS::MM ) ) );
220 }
221
222 m_params.emplace_back( new PARAM<int>( "system.last_metric_units",
223 &m_System.last_metric_units, static_cast<int>( EDA_UNITS::MM ) ) );
224
225 m_params.emplace_back( new PARAM<int>( "system.last_imperial_units",
226 &m_System.last_imperial_units, static_cast<int>( EDA_UNITS::MILS ) ) );
227
228 m_params.emplace_back( new PARAM<bool>( "system.show_import_issues",
229 &m_System.show_import_issues, true ) );
230
231 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "plugins.actions",
232 [&]() -> nlohmann::json
233 {
234 nlohmann::json js = nlohmann::json::array();
235
236 for( const auto& [identifier, visible] : m_Plugins.actions )
237 js.push_back( nlohmann::json( { { identifier.ToUTF8(), visible } } ) );
238
239 return js;
240 },
241 [&]( const nlohmann::json& aObj )
242 {
243 m_Plugins.actions.clear();
244
245 if( !aObj.is_array() )
246 {
247 return;
248 }
249
250 for( const auto& entry : aObj )
251 {
252 if( entry.empty() || !entry.is_object() )
253 continue;
254
255 for( const auto& pair : entry.items() )
256 {
257 m_Plugins.actions.emplace_back( std::make_pair(
258 wxString( pair.key().c_str(), wxConvUTF8 ), pair.value() ) );
259 }
260 }
261 },
262 nlohmann::json::array() ) );
263
264 m_params.emplace_back( new PARAM<wxString>( "appearance.color_theme",
265 &m_ColorTheme, COLOR_SETTINGS::COLOR_BUILTIN_DEFAULT ) );
266
267 m_params.emplace_back( new PARAM<bool>( "appearance.custom_toolbars",
268 &m_CustomToolbars, false ) );
269
270 addParamsForWindow( &m_Window, "window" );
271
272 m_params.emplace_back( new PARAM<bool>( "cross_probing.on_selection",
273 &m_CrossProbing.on_selection, true ) );
274
275 m_params.emplace_back( new PARAM<bool>( "cross_probing.center_on_items",
276 &m_CrossProbing.center_on_items, true ) );
277
278 m_params.emplace_back( new PARAM<bool>( "cross_probing.zoom_to_fit",
279 &m_CrossProbing.zoom_to_fit, true ) );
280
281 m_params.emplace_back( new PARAM<bool>( "cross_probing.auto_highlight",
282 &m_CrossProbing.auto_highlight, true ) );
283
284 m_params.emplace_back( new PARAM<bool>( "cross_probing.flash_selection",
285 &m_CrossProbing.flash_selection, false ) );
286}
287
288
289bool APP_SETTINGS_BASE::MigrateFromLegacy( wxConfigBase* aCfg )
290{
291 bool ret = true;
292
293 const std::string f = getLegacyFrameName();
294
295 ret &= fromLegacyString( aCfg, "LastFindString", "find_replace.find_string" );
296 ret &= fromLegacyString( aCfg, "LastReplaceString", "find_replace.replace_string" );
297
298 migrateFindReplace( aCfg );
299
300 ret &= fromLegacy<int>( aCfg, "P22LIB_TREE_MODEL_ADAPTERSelectorColumnWidth",
301 "lib_tree.column_width" );
302
303 ret &= fromLegacy<bool>( aCfg, "PrintMonochrome", "printing.monochrome" );
304 ret &= fromLegacy<double>( aCfg, "PrintScale", "printing.scale" );
305 ret &= fromLegacy<bool>( aCfg, "PrintPageFrame", "printing.title_block" );
306
307 {
308 nlohmann::json js = nlohmann::json::array();
309 wxString key;
310 bool val = false;
311
312 for( unsigned i = 0; i < PCB_LAYER_ID_COUNT; ++i )
313 {
314 key.Printf( wxT( "PlotLayer_%d" ), i );
315
316 if( aCfg->Read( key, &val ) && val )
317 js.push_back( i );
318 }
319
320 Set( "printing.layers", js );
321 }
322
323 ret &= fromLegacy<bool>( aCfg, f + "FirstRunShown", "system.first_run_shown" );
324 ret &= fromLegacy<int>( aCfg, f + "DevelMaxUndoItems", "system.max_undo_items" );
325 ret &= fromLegacy<int>( aCfg, f + "Units", "system.units" );
326
327 {
328 int max_history_size = Pgm().GetCommonSettings()->m_System.file_history_size;
329 wxString file, key;
330 nlohmann::json js = nlohmann::json::array();
331
332 for( int i = 1; i <= max_history_size; i++ )
333 {
334 key.Printf( "file%d", i );
335 file = aCfg->Read( key, wxEmptyString );
336
337 if( !file.IsEmpty() )
338 js.push_back( file.ToStdString() );
339 }
340
341 Set( "system.file_history", js );
342 }
343
344 ret &= migrateWindowConfig( aCfg, f, "window" );
345
346 return ret;
347}
348
349
351{
352 const int find_replace_history_size = 10;
353 nlohmann::json find_history = nlohmann::json::array();
354 nlohmann::json replace_history = nlohmann::json::array();
355 wxString tmp, find_key, replace_key;
356
357 for( int i = 0; i < find_replace_history_size; ++i )
358 {
359 find_key.Printf( "FindStringHistoryList%d", i );
360 replace_key.Printf( "ReplaceStringHistoryList%d", i );
361
362 if( aCfg->Read( find_key, &tmp ) )
363 find_history.push_back( tmp.ToStdString() );
364
365 if( aCfg->Read( replace_key, &tmp ) )
366 replace_history.push_back( tmp.ToStdString() );
367 }
368
369 Set( "find_replace.find_history", find_history );
370 Set( "find_replace.replace_history", replace_history );
371}
372
373
374bool APP_SETTINGS_BASE::migrateWindowConfig( wxConfigBase* aCfg, const std::string& aFrame,
375 const std::string& aJsonPath )
376{
377 bool ret = true;
378
379 const std::string frameGDO = aFrame + "GalDisplayOptions";
380 const std::string cursorPath = aJsonPath + ".cursor";
381 const std::string gridPath = aJsonPath + ".grid";
382
383 ret &= fromLegacy<bool>( aCfg, aFrame + "Maximized", aJsonPath + ".maximized" );
384 ret &= fromLegacyString( aCfg, aFrame + "MostRecentlyUsedPath", aJsonPath + ".mru_path" );
385 ret &= fromLegacy<int>( aCfg, aFrame + "Size_x", aJsonPath + ".size_x" );
386 ret &= fromLegacy<int>( aCfg, aFrame + "Size_y", aJsonPath + ".size_y" );
387 ret &= fromLegacyString( aCfg, aFrame + "Perspective", aJsonPath + ".perspective" );
388 ret &= fromLegacy<int>( aCfg, aFrame + "Pos_x", aJsonPath + ".pos_x" );
389 ret &= fromLegacy<int>( aCfg, aFrame + "Pos_y", aJsonPath + ".pos_y" );
390
391 ret &= fromLegacy<bool>( aCfg, frameGDO + "ForceDisplayCursor",
392 cursorPath + ".always_show_cursor" );
393 ret &= fromLegacy<int>( aCfg, frameGDO + "CursorFullscreen",
394 cursorPath + ".cross_hair_mode" );
395
396 ret &= fromLegacy<int>( aCfg, aFrame + "_LastGridSize", gridPath + ".last_size" );
397
398 ret &= fromLegacy<int>( aCfg, aFrame + "FastGrid1", gridPath + ".fast_grid_1" );
399 ret &= fromLegacy<int>( aCfg, aFrame + "FastGrid2", gridPath + ".fast_grid_2" );
400
401 ret &= fromLegacy<bool>( aCfg, frameGDO + "GridAxesEnabled", gridPath + ".axes_enabled" );
402 ret &= fromLegacy<double>( aCfg, frameGDO + "GridLineWidth", gridPath + ".line_width" );
403 ret &= fromLegacy<double>( aCfg, frameGDO + "GridMaxDensity", gridPath + ".min_spacing" );
404 ret &= fromLegacy<bool>( aCfg, frameGDO + "ShowGrid", gridPath + ".show" );
405 ret &= fromLegacy<int>( aCfg, frameGDO + "GridStyle", gridPath + ".style" );
406 ret &= fromLegacyColor( aCfg, frameGDO + "GridColor", gridPath + ".color" );
407
408 return ret;
409}
410
411
412void APP_SETTINGS_BASE::addParamsForWindow( WINDOW_SETTINGS* aWindow, const std::string& aJsonPath,
413 int aDefaultWidth, int aDefaultHeight )
414{
415 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".maximized",
416 &aWindow->state.maximized, false ) );
417
418 m_params.emplace_back( new PARAM<wxString>( aJsonPath + ".mru_path",
419 &aWindow->mru_path, wxS( "" ) ) );
420
421 m_params.emplace_back( new PARAM<int>( aJsonPath + ".size_x", &aWindow->state.size_x, aDefaultWidth ) );
422
423 m_params.emplace_back( new PARAM<int>( aJsonPath + ".size_y", &aWindow->state.size_y, aDefaultHeight ) );
424
425 m_params.emplace_back( new PARAM<wxString>( aJsonPath + ".perspective",
426 &aWindow->perspective, wxS( "" ) ) );
427
428 m_params.emplace_back( new PARAM<int>( aJsonPath + ".pos_x", &aWindow->state.pos_x, 0 ) );
429
430 m_params.emplace_back( new PARAM<int>( aJsonPath + ".pos_y", &aWindow->state.pos_y, 0 ) );
431
432 m_params.emplace_back( new PARAM<unsigned int>( aJsonPath + ".display",
433 &aWindow->state.display, 0 ) );
434
435 m_params.emplace_back( new PARAM_LIST<double>( aJsonPath + ".zoom_factors",
436 &aWindow->zoom_factors, DefaultZoomList(), true /* resetIfEmpty */ ) );
437
438 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.axes_enabled",
439 &aWindow->grid.axes_enabled, false ) );
440
441 int defaultGridIdx;
442
443 if( ( m_filename == wxS( "eeschema" ) || m_filename == wxS( "symbol_editor" ) ) )
444 {
445 defaultGridIdx = 1;
446 }
447 else if( m_filename == wxS( "pl_editor" ) )
448 {
449 defaultGridIdx = 4;
450 }
451 else
452 {
453 defaultGridIdx = 15;
454 }
455
456 m_params.emplace_back( new PARAM_LIST<GRID>( aJsonPath + ".grid.sizes", &aWindow->grid.grids,
457 DefaultGridSizeList(), true /* resetIfEmpty */ ) );
458
459 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.last_size",
460 &aWindow->grid.last_size_idx, defaultGridIdx ) );
461
462 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.fast_grid_1",
463 &aWindow->grid.fast_grid_1, defaultGridIdx ) );
464
465 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.fast_grid_2",
466 &aWindow->grid.fast_grid_2, defaultGridIdx + 1 ) );
467
468 // legacy values, leave blank by default so we don't convert them
469 m_params.emplace_back( new PARAM<wxString>( aJsonPath + ".grid.user_grid_x",
470 &aWindow->grid.user_grid_x, wxEmptyString ) );
471 m_params.emplace_back( new PARAM<wxString>( aJsonPath + ".grid.user_grid_y",
472 &aWindow->grid.user_grid_y, wxEmptyString ) );
473
474 // for grid overrides, give just the schematic and symbol editors sane values
475 if( m_filename == wxS( "eeschema" ) || m_filename == wxS( "symbol_editor" ) )
476 {
477 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.overrides_enabled",
478 &aWindow->grid.overrides_enabled, true ) );
479 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.override_connected",
480 &aWindow->grid.override_connected, true ) );
481 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.override_wires",
482 &aWindow->grid.override_wires, true ) );
483 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.override_vias",
484 &aWindow->grid.override_vias, false ) );
485 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.override_text",
486 &aWindow->grid.override_text, true ) );
487 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.override_graphics",
488 &aWindow->grid.override_graphics, false ) );
489
490 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.override_connected_idx",
491 &aWindow->grid.override_connected_idx, 1 ) );
492 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.override_wires_idx",
493 &aWindow->grid.override_wires_idx, 1 ) );
494 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.override_vias_idx",
495 &aWindow->grid.override_vias_idx, 0 ) );
496 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.override_text_idx",
497 &aWindow->grid.override_text_idx, 3 ) );
498 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.override_graphics_idx",
499 &aWindow->grid.override_graphics_idx, 2 ) );
500 }
501 else
502 {
503 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.overrides_enabled",
504 &aWindow->grid.overrides_enabled, true ) );
505 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.override_connected",
506 &aWindow->grid.override_connected, false ) );
507 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.override_wires",
508 &aWindow->grid.override_wires, false ) );
509 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.override_vias",
510 &aWindow->grid.override_vias, false ) );
511 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.override_text",
512 &aWindow->grid.override_text, false ) );
513 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.override_graphics",
514 &aWindow->grid.override_graphics, false ) );
515
516 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.override_connected_idx",
517 &aWindow->grid.override_connected_idx, 16 ) );
518 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.override_text_idx",
519 &aWindow->grid.override_text_idx, 18 ) );
520 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.override_wires_idx",
521 &aWindow->grid.override_wires_idx, 19 ) );
522 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.override_vias_idx",
523 &aWindow->grid.override_vias_idx, 18 ) );
524 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.override_graphics_idx",
525 &aWindow->grid.override_graphics_idx, 15 ) );
526 }
527
528 m_params.emplace_back( new PARAM<double>( aJsonPath + ".grid.line_width",
529 &aWindow->grid.line_width, 1.0 ) );
530
531 m_params.emplace_back( new PARAM<double>( aJsonPath + ".grid.min_spacing",
532 &aWindow->grid.min_spacing, 10 ) );
533
534 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.show",
535 &aWindow->grid.show, true ) );
536
537 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.style",
538 &aWindow->grid.style, 0 ) );
539
540 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.snap",
541 &aWindow->grid.snap, 0 ) );
542
543 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".cursor.always_show_cursor",
544 &aWindow->cursor.always_show_cursor, true ) );
545
546 m_params.emplace_back( new PARAM<KIGFX::CROSS_HAIR_MODE>( aJsonPath + ".cursor.cross_hair_mode",
548}
549
550
551const std::vector<double> APP_SETTINGS_BASE::DefaultZoomList() const
552{
553 if( m_filename == wxS( "eeschema" ) || m_filename == wxS( "symbol_editor" ) )
554 {
555 return { ZOOM_LIST_EESCHEMA };
556 }
557 else if( m_filename == wxS( "pl_editor" ) )
558 {
559 return { ZOOM_LIST_PL_EDITOR };
560 }
561 else if( m_filename == wxS( "gerbview" ) )
562 {
563 return { ZOOM_LIST_GERBVIEW };
564 }
565 else
566 {
567 if( ADVANCED_CFG::GetCfg().m_HyperZoom )
568 return { ZOOM_LIST_PCBNEW_HYPER };
569 else
570 return { ZOOM_LIST_PCBNEW };
571 }
572}
573
574
575const std::vector<GRID> APP_SETTINGS_BASE::DefaultGridSizeList() const
576{
577 if( m_filename == wxS( "eeschema" ) || m_filename == wxS( "symbol_editor" ) )
578 {
579 return { GRID{ wxEmptyString, wxS( "100 mil" ), wxS( "100 mil" ) },
580 GRID{ wxEmptyString, wxS( "50 mil" ), wxS( "50 mil" ) },
581 GRID{ wxEmptyString, wxS( "25 mil" ), wxS( "25 mil" ) },
582 GRID{ wxEmptyString, wxS( "10 mil" ), wxS( "10 mil" ) } };
583 }
584 else if( m_filename == wxS( "pl_editor" ) )
585 {
586 return { GRID{ wxEmptyString, wxS( "5.00 mm" ), wxS( "5.00 mm" ) },
587 GRID{ wxEmptyString, wxS( "2.50 mm" ), wxS( "2.50 mm" ) },
588 GRID{ wxEmptyString, wxS( "2.00 mm" ), wxS( "2.00 mm" ) },
589 GRID{ wxEmptyString, wxS( "1.00 mm" ), wxS( "1.00 mm" ) },
590 GRID{ wxEmptyString, wxS( "0.50 mm" ), wxS( "0.50 mm" ) },
591 GRID{ wxEmptyString, wxS( "0.25 mm" ), wxS( "0.25 mm" ) },
592 GRID{ wxEmptyString, wxS( "0.20 mm" ), wxS( "0.20 mm" ) },
593 GRID{ wxEmptyString, wxS( "0.10 mm" ), wxS( "0.10 mm" ) } };
594 }
595 else if( m_filename == wxS( "gerbview" ) )
596 {
597 return { GRID{ wxEmptyString, wxS( "100 mil" ), wxS( "100 mil" ) },
598 GRID{ wxEmptyString, wxS( "50 mil" ), wxS( "50 mil" ) },
599 GRID{ wxEmptyString, wxS( "25 mil" ), wxS( "25 mil" ) },
600 GRID{ wxEmptyString, wxS( "20 mil" ), wxS( "20 mil" ) },
601 GRID{ wxEmptyString, wxS( "10 mil" ), wxS( "10 mil" ) },
602 GRID{ wxEmptyString, wxS( "5 mil" ), wxS( "5 mil" ) },
603 GRID{ wxEmptyString, wxS( "2.5 mil" ), wxS( "2.5 mil" ) },
604 GRID{ wxEmptyString, wxS( "2 mil" ), wxS( "2 mil" ) },
605 GRID{ wxEmptyString, wxS( "1 mil" ), wxS( "1 mil" ) },
606 GRID{ wxEmptyString, wxS( "0.5 mil" ), wxS( "0.5 mil" ) },
607 GRID{ wxEmptyString, wxS( "0.2 mil" ), wxS( "0.2 mil" ) },
608 GRID{ wxEmptyString, wxS( "0.1 mil" ), wxS( "0.1 mil" ) },
609 GRID{ wxEmptyString, wxS( "5.0 mm" ), wxS( "5.0 mm" ) },
610 GRID{ wxEmptyString, wxS( "1.5 mm" ), wxS( "2.5 mm" ) },
611 GRID{ wxEmptyString, wxS( "1.0 mm" ), wxS( "1.0 mm" ) },
612 GRID{ wxEmptyString, wxS( "0.5 mm" ), wxS( "0.5 mm" ) },
613 GRID{ wxEmptyString, wxS( "0.25 mm" ), wxS( "0.25 mm" ) },
614 GRID{ wxEmptyString, wxS( "0.2 mm" ), wxS( "0.2 mm" ) },
615 GRID{ wxEmptyString, wxS( "0.1 mm" ), wxS( "0.1 mm" ) },
616 GRID{ wxEmptyString, wxS( "0.05 mm" ), wxS( "0.0 mm" ) },
617 GRID{ wxEmptyString, wxS( "0.025 mm" ), wxS( "0.0 mm" ) },
618 GRID{ wxEmptyString, wxS( "0.01 mm" ), wxS( "0.0 mm" ) } };
619 }
620 else
621 {
622 return { GRID{ wxEmptyString, wxS( "1000 mil" ), wxS( "1000 mil" ) },
623 GRID{ wxEmptyString, wxS( "500 mil" ), wxS( "500 mil" ) },
624 GRID{ wxEmptyString, wxS( "250 mil" ), wxS( "250 mil" ) },
625 GRID{ wxEmptyString, wxS( "200 mil" ), wxS( "200 mil" ) },
626 GRID{ wxEmptyString, wxS( "100 mil" ), wxS( "100 mil" ) },
627 GRID{ wxEmptyString, wxS( "50 mil" ), wxS( "50 mil" ) },
628 GRID{ wxEmptyString, wxS( "25 mil" ), wxS( "25 mil" ) },
629 GRID{ wxEmptyString, wxS( "20 mil" ), wxS( "20 mil" ) },
630 GRID{ wxEmptyString, wxS( "10 mil" ), wxS( "10 mil" ) },
631 GRID{ wxEmptyString, wxS( "5 mil" ), wxS( "5 mil" ) },
632 GRID{ wxEmptyString, wxS( "2 mil" ), wxS( "2 mil" ) },
633 GRID{ wxEmptyString, wxS( "1 mil" ), wxS( "1 mil" ) },
634 GRID{ wxEmptyString, wxS( "5.0 mm" ), wxS( "5.0 mm" ) },
635 GRID{ wxEmptyString, wxS( "2.5 mm" ), wxS( "2.5 mm" ) },
636 GRID{ wxEmptyString, wxS( "1.0 mm" ), wxS( "1.0 mm" ) },
637 GRID{ wxEmptyString, wxS( "0.5 mm" ), wxS( "0.5 mm" ) },
638 GRID{ wxEmptyString, wxS( "0.25 mm" ), wxS( "0.25 mm" ) },
639 GRID{ wxEmptyString, wxS( "0.2 mm" ), wxS( "0.2 mm" ) },
640 GRID{ wxEmptyString, wxS( "0.1 mm" ), wxS( "0.1 mm" ) },
641 GRID{ wxEmptyString, wxS( "0.05 mm" ), wxS( "0.05 mm" ) },
642 GRID{ wxEmptyString, wxS( "0.025 mm" ), wxS( "0.025 mm" ) },
643 GRID{ wxEmptyString, wxS( "0.01 mm" ), wxS( "0.01 mm" ) } };
644 }
645}
646
647
649{
650 // We used to store only the width of the first column, because there were only
651 // two possible columns.
652 if( std::optional<int> optWidth = Get<int>( "lib_tree.column_width" ) )
653 {
654 Set<nlohmann::json>( "lib_tree.column_widths", { { "Item", *optWidth } } );
655 At( "lib_tree" ).erase( "column_width" );
656 }
657
658 return true;
659}
const char * name
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
SEARCH_PANE m_SearchPane
WINDOW_SETTINGS m_Window
APP_SETTINGS_BASE(const std::string &aFilename, int aSchemaVersion)
FIND_REPLACE m_FindReplace
bool migrateWindowConfig(wxConfigBase *aCfg, const std::string &aFrameName, const std::string &aJsonPath)
Migrate legacy window settings into the JSON document.
bool m_CustomToolbars
Use custom toolbars.
const std::vector< GRID > DefaultGridSizeList() const
void migrateFindReplace(wxConfigBase *aCfg)
! Migrates the find/replace history string list.s
PANEL_DESIGN_BLOCK_CHOOSER m_DesignBlockChooserPanel
void addParamsForWindow(WINDOW_SETTINGS *aWindow, const std::string &aJsonPath, int aDefaultWidth=0, int aDefaultHeight=0)
Add parameters for the given window object.
const std::vector< double > DefaultZoomList() const
COLOR_PICKER m_ColorPicker
virtual std::string getLegacyFrameName() const
virtual bool MigrateFromLegacy(wxConfigBase *aCfg) override
Migrates from wxConfig to JSON-based configuration.
CROSS_PROBING_SETTINGS m_CrossProbing
bool migrateLibTreeWidth()
Migrate the library tree width setting from a single column (Item) to multi-column.
int m_appSettingsSchemaVersion
! Local schema version for common app settings.
static const wxString COLOR_BUILTIN_DEFAULT
bool fromLegacyString(wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
Translates a legacy wxConfig string value to a given JSON pointer value.
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...
wxString m_filename
The filename (not including path) of this settings file (inicode)
bool fromLegacyColor(wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
Translates a legacy COLOR4D stored in a wxConfig string to a given JSON pointer value.
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)
nlohmann::json & At(const std::string &aPath)
Wrappers for the underlying JSON API so that most consumers don't need json.hpp All of these function...
JSON_SETTINGS(const wxString &aFilename, SETTINGS_LOC aLocation, int aSchemaVersion)
Like a normal param, but with custom getter and setter functions.
Definition parameters.h:296
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:576
The common library.
template KICOMMON_API void JSON_SETTINGS::Set< nlohmann::json >(const std::string &aPath, nlohmann::json aValue)
SETTINGS_LOC
@ USER
The main config directory (e.g. ~/.config/kicad/)
@ PCB_LAYER_ID_COUNT
Definition layer_ids.h:171
PGM_BASE & Pgm()
The global program "get" accessor.
Definition pgm_base.cpp:913
see class PGM_BASE
KIGFX::CROSS_HAIR_MODE cross_hair_mode
wxString user_grid_x
int override_connected_idx
bool override_connected
std::vector< GRID > grids
int override_graphics_idx
wxString user_grid_y
Common grid settings, available to every frame.
Store the common settings that are saved and loaded for each window / frame.
CURSOR_SETTINGS cursor
WINDOW_STATE state
GRID_SETTINGS grid
wxString mru_path
std::vector< double > zoom_factors
wxString perspective
unsigned int display
#define ZOOM_LIST_PL_EDITOR
#define ZOOM_LIST_PCBNEW
#define ZOOM_LIST_PCBNEW_HYPER
#define ZOOM_LIST_EESCHEMA
#define ZOOM_LIST_GERBVIEW