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