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