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