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