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<int>( "search_pane.selection_zoom",
193 reinterpret_cast<int*>( &m_SearchPane.selection_zoom ),
194 static_cast<int>( SEARCH_PANE::SELECTION_ZOOM::PAN ) ) );
195
196 m_params.emplace_back( new PARAM<bool>( "search_pane.search_hidden_fields",
197 &m_SearchPane.search_hidden_fields, true ) );
198
199 m_params.emplace_back( new PARAM<bool>( "search_pane.search_metadata",
200 &m_SearchPane.search_metadata, false ) );
201
202 m_params.emplace_back( new PARAM<bool>( "system.first_run_shown",
203 &m_System.first_run_shown, false ) ); //@todo RFB remove? - not used
204
205 m_params.emplace_back( new PARAM<int>( "system.max_undo_items",
206 &m_System.max_undo_items, 0 ) );
207
208 // WARNING: "system.file_history" is a "known" key (see JSON_SETTINGS::GetFileHistories())
209 m_params.emplace_back( new PARAM_LIST<wxString>( "system.file_history",
210 &m_System.file_history, {} ) );
211
212 if( m_filename == wxS( "pl_editor" )
213 || ( m_filename == wxS( "eeschema" ) || m_filename == wxS( "symbol_editor" ) ) )
214 {
215 m_params.emplace_back( new PARAM<int>( "system.units",
216 &m_System.units, static_cast<int>( EDA_UNITS::MILS ) ) );
217 }
218 else
219 {
220 m_params.emplace_back( new PARAM<int>( "system.units",
221 &m_System.units, static_cast<int>( EDA_UNITS::MM ) ) );
222 }
223
224 m_params.emplace_back( new PARAM<int>( "system.last_metric_units",
225 &m_System.last_metric_units, static_cast<int>( EDA_UNITS::MM ) ) );
226
227 m_params.emplace_back( new PARAM<int>( "system.last_imperial_units",
228 &m_System.last_imperial_units, static_cast<int>( EDA_UNITS::MILS ) ) );
229
230 m_params.emplace_back( new PARAM<bool>( "system.show_import_issues",
231 &m_System.show_import_issues, true ) );
232
233 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "plugins.actions",
234 [&]() -> nlohmann::json
235 {
236 nlohmann::json js = nlohmann::json::array();
237
238 for( const auto& [identifier, visible] : m_Plugins.actions )
239 js.push_back( nlohmann::json( { { identifier.ToUTF8(), visible } } ) );
240
241 return js;
242 },
243 [&]( const nlohmann::json& aObj )
244 {
245 m_Plugins.actions.clear();
246
247 if( !aObj.is_array() )
248 {
249 return;
250 }
251
252 for( const auto& entry : aObj )
253 {
254 if( entry.empty() || !entry.is_object() )
255 continue;
256
257 for( const auto& pair : entry.items() )
258 {
259 m_Plugins.actions.emplace_back( std::make_pair(
260 wxString( pair.key().c_str(), wxConvUTF8 ), pair.value() ) );
261 }
262 }
263 },
264 nlohmann::json::array() ) );
265
266 m_params.emplace_back( new PARAM<wxString>( "appearance.color_theme",
267 &m_ColorTheme, COLOR_SETTINGS::COLOR_BUILTIN_DEFAULT ) );
268
269 m_params.emplace_back( new PARAM<bool>( "appearance.custom_toolbars",
270 &m_CustomToolbars, false ) );
271
272 addParamsForWindow( &m_Window, "window" );
273
274 m_params.emplace_back( new PARAM<bool>( "cross_probing.on_selection",
275 &m_CrossProbing.on_selection, true ) );
276
277 m_params.emplace_back( new PARAM<bool>( "cross_probing.center_on_items",
278 &m_CrossProbing.center_on_items, true ) );
279
280 m_params.emplace_back( new PARAM<bool>( "cross_probing.zoom_to_fit",
281 &m_CrossProbing.zoom_to_fit, true ) );
282
283 m_params.emplace_back( new PARAM<bool>( "cross_probing.auto_highlight",
284 &m_CrossProbing.auto_highlight, true ) );
285
286 m_params.emplace_back( new PARAM<bool>( "cross_probing.flash_selection",
287 &m_CrossProbing.flash_selection, false ) );
288}
289
290
291bool APP_SETTINGS_BASE::MigrateFromLegacy( wxConfigBase* aCfg )
292{
293 bool ret = true;
294
295 const std::string f = getLegacyFrameName();
296
297 ret &= fromLegacyString( aCfg, "LastFindString", "find_replace.find_string" );
298 ret &= fromLegacyString( aCfg, "LastReplaceString", "find_replace.replace_string" );
299
300 migrateFindReplace( aCfg );
301
302 ret &= fromLegacy<int>( aCfg, "P22LIB_TREE_MODEL_ADAPTERSelectorColumnWidth",
303 "lib_tree.column_width" );
304
305 ret &= fromLegacy<bool>( aCfg, "PrintMonochrome", "printing.monochrome" );
306 ret &= fromLegacy<double>( aCfg, "PrintScale", "printing.scale" );
307 ret &= fromLegacy<bool>( aCfg, "PrintPageFrame", "printing.title_block" );
308
309 {
310 nlohmann::json js = nlohmann::json::array();
311 wxString key;
312 bool val = false;
313
314 for( unsigned i = 0; i < PCB_LAYER_ID_COUNT; ++i )
315 {
316 key.Printf( wxT( "PlotLayer_%d" ), i );
317
318 if( aCfg->Read( key, &val ) && val )
319 js.push_back( i );
320 }
321
322 Set( "printing.layers", js );
323 }
324
325 ret &= fromLegacy<bool>( aCfg, f + "FirstRunShown", "system.first_run_shown" );
326 ret &= fromLegacy<int>( aCfg, f + "DevelMaxUndoItems", "system.max_undo_items" );
327 ret &= fromLegacy<int>( aCfg, f + "Units", "system.units" );
328
329 {
330 int max_history_size = Pgm().GetCommonSettings()->m_System.file_history_size;
331 wxString file, key;
332 nlohmann::json js = nlohmann::json::array();
333
334 for( int i = 1; i <= max_history_size; i++ )
335 {
336 key.Printf( "file%d", i );
337 file = aCfg->Read( key, wxEmptyString );
338
339 if( !file.IsEmpty() )
340 js.push_back( file.ToStdString() );
341 }
342
343 Set( "system.file_history", js );
344 }
345
346 ret &= migrateWindowConfig( aCfg, f, "window" );
347
348 return ret;
349}
350
351
353{
354 const int find_replace_history_size = 10;
355 nlohmann::json find_history = nlohmann::json::array();
356 nlohmann::json replace_history = nlohmann::json::array();
357 wxString tmp, find_key, replace_key;
358
359 for( int i = 0; i < find_replace_history_size; ++i )
360 {
361 find_key.Printf( "FindStringHistoryList%d", i );
362 replace_key.Printf( "ReplaceStringHistoryList%d", i );
363
364 if( aCfg->Read( find_key, &tmp ) )
365 find_history.push_back( tmp.ToStdString() );
366
367 if( aCfg->Read( replace_key, &tmp ) )
368 replace_history.push_back( tmp.ToStdString() );
369 }
370
371 Set( "find_replace.find_history", find_history );
372 Set( "find_replace.replace_history", replace_history );
373}
374
375
376bool APP_SETTINGS_BASE::migrateWindowConfig( wxConfigBase* aCfg, const std::string& aFrame,
377 const std::string& aJsonPath )
378{
379 bool ret = true;
380
381 const std::string frameGDO = aFrame + "GalDisplayOptions";
382 const std::string cursorPath = aJsonPath + ".cursor";
383 const std::string gridPath = aJsonPath + ".grid";
384
385 ret &= fromLegacy<bool>( aCfg, aFrame + "Maximized", aJsonPath + ".maximized" );
386 ret &= fromLegacyString( aCfg, aFrame + "MostRecentlyUsedPath", aJsonPath + ".mru_path" );
387 ret &= fromLegacy<int>( aCfg, aFrame + "Size_x", aJsonPath + ".size_x" );
388 ret &= fromLegacy<int>( aCfg, aFrame + "Size_y", aJsonPath + ".size_y" );
389 ret &= fromLegacyString( aCfg, aFrame + "Perspective", aJsonPath + ".perspective" );
390 ret &= fromLegacy<int>( aCfg, aFrame + "Pos_x", aJsonPath + ".pos_x" );
391 ret &= fromLegacy<int>( aCfg, aFrame + "Pos_y", aJsonPath + ".pos_y" );
392
393 ret &= fromLegacy<bool>( aCfg, frameGDO + "ForceDisplayCursor",
394 cursorPath + ".always_show_cursor" );
395 ret &= fromLegacy<int>( aCfg, frameGDO + "CursorFullscreen",
396 cursorPath + ".cross_hair_mode" );
397
398 ret &= fromLegacy<int>( aCfg, aFrame + "_LastGridSize", gridPath + ".last_size" );
399
400 ret &= fromLegacy<int>( aCfg, aFrame + "FastGrid1", gridPath + ".fast_grid_1" );
401 ret &= fromLegacy<int>( aCfg, aFrame + "FastGrid2", gridPath + ".fast_grid_2" );
402
403 ret &= fromLegacy<bool>( aCfg, frameGDO + "GridAxesEnabled", gridPath + ".axes_enabled" );
404 ret &= fromLegacy<double>( aCfg, frameGDO + "GridLineWidth", gridPath + ".line_width" );
405 ret &= fromLegacy<double>( aCfg, frameGDO + "GridMaxDensity", gridPath + ".min_spacing" );
406 ret &= fromLegacy<bool>( aCfg, frameGDO + "ShowGrid", gridPath + ".show" );
407 ret &= fromLegacy<int>( aCfg, frameGDO + "GridStyle", gridPath + ".style" );
408 ret &= fromLegacyColor( aCfg, frameGDO + "GridColor", gridPath + ".color" );
409
410 return ret;
411}
412
413
414void APP_SETTINGS_BASE::addParamsForWindow( WINDOW_SETTINGS* aWindow, const std::string& aJsonPath,
415 int aDefaultWidth, int aDefaultHeight )
416{
417 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".maximized",
418 &aWindow->state.maximized, false ) );
419
420 m_params.emplace_back( new PARAM<wxString>( aJsonPath + ".mru_path",
421 &aWindow->mru_path, wxS( "" ) ) );
422
423 m_params.emplace_back( new PARAM<int>( aJsonPath + ".size_x", &aWindow->state.size_x, aDefaultWidth ) );
424
425 m_params.emplace_back( new PARAM<int>( aJsonPath + ".size_y", &aWindow->state.size_y, aDefaultHeight ) );
426
427 m_params.emplace_back( new PARAM<wxString>( aJsonPath + ".perspective",
428 &aWindow->perspective, wxS( "" ) ) );
429
430 m_params.emplace_back( new PARAM<nlohmann::json>( aJsonPath + ".aui_state",
431 &aWindow->aui_state, nlohmann::json() ) );
432
433 m_params.emplace_back( new PARAM<int>( aJsonPath + ".pos_x", &aWindow->state.pos_x, 0 ) );
434
435 m_params.emplace_back( new PARAM<int>( aJsonPath + ".pos_y", &aWindow->state.pos_y, 0 ) );
436
437 m_params.emplace_back( new PARAM<unsigned int>( aJsonPath + ".display",
438 &aWindow->state.display, 0 ) );
439
440 m_params.emplace_back( new PARAM_LIST<double>( aJsonPath + ".zoom_factors",
441 &aWindow->zoom_factors, DefaultZoomList(), true /* resetIfEmpty */ ) );
442
443 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.axes_enabled",
444 &aWindow->grid.axes_enabled, false ) );
445
446 int defaultGridIdx;
447
448 if( ( m_filename == wxS( "eeschema" ) || m_filename == wxS( "symbol_editor" ) ) )
449 {
450 defaultGridIdx = 1;
451 }
452 else if( m_filename == wxS( "pl_editor" ) )
453 {
454 defaultGridIdx = 4;
455 }
456 else
457 {
458 defaultGridIdx = 15;
459 }
460
461 m_params.emplace_back( new PARAM_LIST<GRID>( aJsonPath + ".grid.sizes", &aWindow->grid.grids,
462 DefaultGridSizeList(), true /* resetIfEmpty */ ) );
463
464 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.last_size",
465 &aWindow->grid.last_size_idx, defaultGridIdx ) );
466
467 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.fast_grid_1",
468 &aWindow->grid.fast_grid_1, defaultGridIdx ) );
469
470 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.fast_grid_2",
471 &aWindow->grid.fast_grid_2, defaultGridIdx + 1 ) );
472
473 // legacy values, leave blank by default so we don't convert them
474 m_params.emplace_back( new PARAM<wxString>( aJsonPath + ".grid.user_grid_x",
475 &aWindow->grid.user_grid_x, wxEmptyString ) );
476 m_params.emplace_back( new PARAM<wxString>( aJsonPath + ".grid.user_grid_y",
477 &aWindow->grid.user_grid_y, wxEmptyString ) );
478
479 // for grid overrides, give just the schematic and symbol editors sane values
480 if( m_filename == wxS( "eeschema" ) || m_filename == wxS( "symbol_editor" ) )
481 {
482 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.overrides_enabled",
483 &aWindow->grid.overrides_enabled, true ) );
484 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.override_connected",
485 &aWindow->grid.override_connected, true ) );
486 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.override_wires",
487 &aWindow->grid.override_wires, true ) );
488 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.override_vias",
489 &aWindow->grid.override_vias, false ) );
490 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.override_text",
491 &aWindow->grid.override_text, true ) );
492 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.override_graphics",
493 &aWindow->grid.override_graphics, false ) );
494
495 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.override_connected_idx",
496 &aWindow->grid.override_connected_idx, 1 ) );
497 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.override_wires_idx",
498 &aWindow->grid.override_wires_idx, 1 ) );
499 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.override_vias_idx",
500 &aWindow->grid.override_vias_idx, 0 ) );
501 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.override_text_idx",
502 &aWindow->grid.override_text_idx, 3 ) );
503 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.override_graphics_idx",
504 &aWindow->grid.override_graphics_idx, 2 ) );
505 }
506 else
507 {
508 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.overrides_enabled",
509 &aWindow->grid.overrides_enabled, true ) );
510 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.override_connected",
511 &aWindow->grid.override_connected, false ) );
512 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.override_wires",
513 &aWindow->grid.override_wires, false ) );
514 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.override_vias",
515 &aWindow->grid.override_vias, false ) );
516 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.override_text",
517 &aWindow->grid.override_text, false ) );
518 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.override_graphics",
519 &aWindow->grid.override_graphics, false ) );
520
521 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.override_connected_idx",
522 &aWindow->grid.override_connected_idx, 16 ) );
523 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.override_text_idx",
524 &aWindow->grid.override_text_idx, 18 ) );
525 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.override_wires_idx",
526 &aWindow->grid.override_wires_idx, 19 ) );
527 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.override_vias_idx",
528 &aWindow->grid.override_vias_idx, 18 ) );
529 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.override_graphics_idx",
530 &aWindow->grid.override_graphics_idx, 15 ) );
531 }
532
533 m_params.emplace_back( new PARAM<double>( aJsonPath + ".grid.line_width",
534 &aWindow->grid.line_width, 1.0 ) );
535
536 m_params.emplace_back( new PARAM<double>( aJsonPath + ".grid.min_spacing",
537 &aWindow->grid.min_spacing, 10 ) );
538
539 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.show",
540 &aWindow->grid.show, true ) );
541
542 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.style",
543 &aWindow->grid.style, 0 ) );
544
545 m_params.emplace_back( new PARAM<int>( aJsonPath + ".grid.snap",
546 &aWindow->grid.snap, 0 ) );
547
548 m_params.emplace_back( new PARAM<bool>( aJsonPath + ".cursor.always_show_cursor",
549 &aWindow->cursor.always_show_cursor, true ) );
550
551 m_params.emplace_back( new PARAM<KIGFX::CROSS_HAIR_MODE>( aJsonPath + ".cursor.cross_hair_mode",
553}
554
555
556const std::vector<double> APP_SETTINGS_BASE::DefaultZoomList() const
557{
558 if( m_filename == wxS( "eeschema" ) || m_filename == wxS( "symbol_editor" ) )
559 {
560 return { ZOOM_LIST_EESCHEMA };
561 }
562 else if( m_filename == wxS( "pl_editor" ) )
563 {
564 return { ZOOM_LIST_PL_EDITOR };
565 }
566 else if( m_filename == wxS( "gerbview" ) )
567 {
568 return { ZOOM_LIST_GERBVIEW };
569 }
570 else
571 {
572 if( ADVANCED_CFG::GetCfg().m_HyperZoom )
573 return { ZOOM_LIST_PCBNEW_HYPER };
574 else
575 return { ZOOM_LIST_PCBNEW };
576 }
577}
578
579
580const std::vector<GRID> APP_SETTINGS_BASE::DefaultGridSizeList() const
581{
582 if( m_filename == wxS( "eeschema" ) || m_filename == wxS( "symbol_editor" ) )
583 {
584 return { GRID{ wxEmptyString, wxS( "100 mil" ), wxS( "100 mil" ) },
585 GRID{ wxEmptyString, wxS( "50 mil" ), wxS( "50 mil" ) },
586 GRID{ wxEmptyString, wxS( "25 mil" ), wxS( "25 mil" ) },
587 GRID{ wxEmptyString, wxS( "10 mil" ), wxS( "10 mil" ) } };
588 }
589 else if( m_filename == wxS( "pl_editor" ) )
590 {
591 return { GRID{ wxEmptyString, wxS( "5.00 mm" ), wxS( "5.00 mm" ) },
592 GRID{ wxEmptyString, wxS( "2.50 mm" ), wxS( "2.50 mm" ) },
593 GRID{ wxEmptyString, wxS( "2.00 mm" ), wxS( "2.00 mm" ) },
594 GRID{ wxEmptyString, wxS( "1.00 mm" ), wxS( "1.00 mm" ) },
595 GRID{ wxEmptyString, wxS( "0.50 mm" ), wxS( "0.50 mm" ) },
596 GRID{ wxEmptyString, wxS( "0.25 mm" ), wxS( "0.25 mm" ) },
597 GRID{ wxEmptyString, wxS( "0.20 mm" ), wxS( "0.20 mm" ) },
598 GRID{ wxEmptyString, wxS( "0.10 mm" ), wxS( "0.10 mm" ) } };
599 }
600 else if( m_filename == wxS( "gerbview" ) )
601 {
602 return { GRID{ wxEmptyString, wxS( "100 mil" ), wxS( "100 mil" ) },
603 GRID{ wxEmptyString, wxS( "50 mil" ), wxS( "50 mil" ) },
604 GRID{ wxEmptyString, wxS( "25 mil" ), wxS( "25 mil" ) },
605 GRID{ wxEmptyString, wxS( "20 mil" ), wxS( "20 mil" ) },
606 GRID{ wxEmptyString, wxS( "10 mil" ), wxS( "10 mil" ) },
607 GRID{ wxEmptyString, wxS( "5 mil" ), wxS( "5 mil" ) },
608 GRID{ wxEmptyString, wxS( "2.5 mil" ), wxS( "2.5 mil" ) },
609 GRID{ wxEmptyString, wxS( "2 mil" ), wxS( "2 mil" ) },
610 GRID{ wxEmptyString, wxS( "1 mil" ), wxS( "1 mil" ) },
611 GRID{ wxEmptyString, wxS( "0.5 mil" ), wxS( "0.5 mil" ) },
612 GRID{ wxEmptyString, wxS( "0.2 mil" ), wxS( "0.2 mil" ) },
613 GRID{ wxEmptyString, wxS( "0.1 mil" ), wxS( "0.1 mil" ) },
614 GRID{ wxEmptyString, wxS( "5.0 mm" ), wxS( "5.0 mm" ) },
615 GRID{ wxEmptyString, wxS( "1.5 mm" ), wxS( "2.5 mm" ) },
616 GRID{ wxEmptyString, wxS( "1.0 mm" ), wxS( "1.0 mm" ) },
617 GRID{ wxEmptyString, wxS( "0.5 mm" ), wxS( "0.5 mm" ) },
618 GRID{ wxEmptyString, wxS( "0.25 mm" ), wxS( "0.25 mm" ) },
619 GRID{ wxEmptyString, wxS( "0.2 mm" ), wxS( "0.2 mm" ) },
620 GRID{ wxEmptyString, wxS( "0.1 mm" ), wxS( "0.1 mm" ) },
621 GRID{ wxEmptyString, wxS( "0.05 mm" ), wxS( "0.0 mm" ) },
622 GRID{ wxEmptyString, wxS( "0.025 mm" ), wxS( "0.0 mm" ) },
623 GRID{ wxEmptyString, wxS( "0.01 mm" ), wxS( "0.0 mm" ) } };
624 }
625 else
626 {
627 return { GRID{ wxEmptyString, wxS( "1000 mil" ), wxS( "1000 mil" ) },
628 GRID{ wxEmptyString, wxS( "500 mil" ), wxS( "500 mil" ) },
629 GRID{ wxEmptyString, wxS( "250 mil" ), wxS( "250 mil" ) },
630 GRID{ wxEmptyString, wxS( "200 mil" ), wxS( "200 mil" ) },
631 GRID{ wxEmptyString, wxS( "100 mil" ), wxS( "100 mil" ) },
632 GRID{ wxEmptyString, wxS( "50 mil" ), wxS( "50 mil" ) },
633 GRID{ wxEmptyString, wxS( "25 mil" ), wxS( "25 mil" ) },
634 GRID{ wxEmptyString, wxS( "20 mil" ), wxS( "20 mil" ) },
635 GRID{ wxEmptyString, wxS( "10 mil" ), wxS( "10 mil" ) },
636 GRID{ wxEmptyString, wxS( "5 mil" ), wxS( "5 mil" ) },
637 GRID{ wxEmptyString, wxS( "2 mil" ), wxS( "2 mil" ) },
638 GRID{ wxEmptyString, wxS( "1 mil" ), wxS( "1 mil" ) },
639 GRID{ wxEmptyString, wxS( "5.0 mm" ), wxS( "5.0 mm" ) },
640 GRID{ wxEmptyString, wxS( "2.5 mm" ), wxS( "2.5 mm" ) },
641 GRID{ wxEmptyString, wxS( "1.0 mm" ), wxS( "1.0 mm" ) },
642 GRID{ wxEmptyString, wxS( "0.5 mm" ), wxS( "0.5 mm" ) },
643 GRID{ wxEmptyString, wxS( "0.25 mm" ), wxS( "0.25 mm" ) },
644 GRID{ wxEmptyString, wxS( "0.2 mm" ), wxS( "0.2 mm" ) },
645 GRID{ wxEmptyString, wxS( "0.1 mm" ), wxS( "0.1 mm" ) },
646 GRID{ wxEmptyString, wxS( "0.05 mm" ), wxS( "0.05 mm" ) },
647 GRID{ wxEmptyString, wxS( "0.025 mm" ), wxS( "0.025 mm" ) },
648 GRID{ wxEmptyString, wxS( "0.01 mm" ), wxS( "0.01 mm" ) } };
649 }
650}
651
652
654{
655 // We used to store only the width of the first column, because there were only
656 // two possible columns.
657 if( std::optional<int> optWidth = Get<int>( "lib_tree.column_width" ) )
658 {
659 Set<nlohmann::json>( "lib_tree.column_widths", { { "Item", *optWidth } } );
660 At( "lib_tree" ).erase( "column_width" );
661 }
662
663 return true;
664}
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
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