KiCad PCB EDA Suite
eeschema_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-2022 KiCad Developers, see AUTHORS.txt for contributors.
5*
6* This program is free software; you can redistribute it and/or
7* modify it under the terms of the GNU General Public License
8* as published by the Free Software Foundation; either version 2
9* of the License, or (at your option) any later version.
10*
11* This program is distributed in the hope that it will be useful,
12* but WITHOUT ANY WARRANTY; without even the implied warranty of
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14* GNU General Public License for more details.
15*
16* You should have received a copy of the GNU General Public License
17* along with this program; if not, you may find one here:
18* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19* or you may search the http://www.gnu.org website for the version 2 license,
20* or you may write to the Free Software Foundation, Inc.,
21* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22*/
23
24#include <functional>
25
26#include <dialogs/dialog_bom_cfg_lexer.h>
27#include <eeschema_settings.h>
28#include <layer_ids.h>
30#include <macros.h>
31#include <pgm_base.h>
34#include <settings/parameters.h>
36#include <wx/config.h>
37#include <widgets/ui_common.h>
38#include <default_values.h> // For some default values
39
40using namespace T_BOMCFG_T; // for the BOM_CFG_PARSER parser and its keywords
41
44
47 {
48 {
49 { "name", "bom_csv_grouped_by_value" },
50 { "path", "bom_csv_grouped_by_value.py" }
51 },
52 {
53 { "name", "bom_csv_grouped_by_value_with_fp" },
54 { "path", "bom_csv_grouped_by_value_with_fp.py" }
55 },
56 };
57
58
61 m_Appearance(),
62 m_AutoplaceFields(),
63 m_Drawing(),
64 m_FindReplaceExtra(),
65 m_Input(),
66 m_PageSettings(),
67 m_AnnotatePanel(),
68 m_BomPanel(),
69 m_FieldEditorPanel(),
70 m_LibViewPanel(),
71 m_NetlistPanel(),
72 m_PlotPanel(),
73 m_SymChooserPanel(),
74 m_Selection(),
75 m_Simulator(),
76 m_RescueNeverShow( false )
77{
78 m_params.emplace_back( new PARAM<wxString>( "appearance.edit_symbol_visible_columns",
79 &m_Appearance.edit_symbol_visible_columns, "0 1 2 3 4 5 6 7" ) );
80
81 m_params.emplace_back( new PARAM<wxString>( "appearance.edit_sheet_visible_columns",
82 &m_Appearance.edit_sheet_visible_columns, "0 1 2 3 4 5 6 7" ) );
83
84 m_params.emplace_back( new PARAM<wxString>( "appearance.edit_label_visible_columns",
85 &m_Appearance.edit_label_visible_columns, "0 1 2 3 4 5 6 7" ) );
86
87 m_params.emplace_back( new PARAM<int>( "appearance.erc_severities",
89
90 m_params.emplace_back( new PARAM<bool>( "appearance.footprint_preview",
92
93 m_params.emplace_back( new PARAM<bool>( "appearance.print_sheet_reference",
95
96 m_params.emplace_back( new PARAM<wxString>( "appearance.default_font",
97 &m_Appearance.default_font, "KiCad Font" ) );
98
99 m_params.emplace_back( new PARAM<bool>( "appearance.show_hidden_pins",
100 &m_Appearance.show_hidden_pins, false ) );
101
102 m_params.emplace_back( new PARAM<bool>( "appearance.show_hidden_fields",
104
105 m_params.emplace_back( new PARAM<bool>( "appearance.show_erc_warnings",
107
108 m_params.emplace_back( new PARAM<bool>( "appearance.show_erc_errors",
109 &m_Appearance.show_erc_errors, true ) );
110
111 m_params.emplace_back( new PARAM<bool>( "appearance.show_erc_exclusions",
113
114 m_params.emplace_back( new PARAM<bool>( "appearance.show_illegal_symbol_lib_dialog",
116
117 m_params.emplace_back( new PARAM<bool>( "appearance.show_page_limits",
119
120 m_params.emplace_back( new PARAM<bool>( "appearance.show_sexpr_file_convert_warning",
122
123 m_params.emplace_back(
124 new PARAM<bool>( "appearance.show_sheet_filename_case_sensitivity_dialog",
126
127 m_params.emplace_back( new PARAM<bool>( "aui.show_schematic_hierarchy",
129
130 m_params.emplace_back( new PARAM<int>( "aui.hierarchy_panel_docked_width",
132
133 m_params.emplace_back( new PARAM<int>( "aui.hierarchy_panel_float_width",
135
136 m_params.emplace_back( new PARAM<int>( "aui.hierarchy_panel_float_height",
138
139 m_params.emplace_back( new PARAM<bool>( "aui.schematic_hierarchy_float",
141
142 m_params.emplace_back( new PARAM<bool>( "autoplace_fields.enable",
143 &m_AutoplaceFields.enable, true ) );
144
145 m_params.emplace_back( new PARAM<bool>( "autoplace_fields.allow_rejustify",
147
148 m_params.emplace_back( new PARAM<bool>( "autoplace_fields.align_to_grid",
150
151 m_params.emplace_back( new PARAM<int>( "drawing.default_bus_thickness",
153
154 m_params.emplace_back( new PARAM<int>( "drawing.default_junction_size",
156
157 m_params.emplace_back( new PARAM<int>( "drawing.pin_symbol_size",
159
160 m_params.emplace_back( new PARAM<double>( "drawing.text_offset_ratio",
161 &m_Drawing.text_offset_ratio, 0.08 ) );
162
163 m_params.emplace_back( new PARAM<int>( "drawing.default_line_thickness",
165
166 m_params.emplace_back( new PARAM<int>( "drawing.default_repeat_offset_x",
168
169 m_params.emplace_back( new PARAM<int>( "drawing.default_repeat_offset_y",
171
172 m_params.emplace_back( new PARAM<int>( "drawing.default_wire_thickness",
174
175 m_params.emplace_back( new PARAM<int>( "drawing.default_text_size",
177
178 m_params.emplace_back( new PARAM<wxString>( "drawing.field_names",
179 &m_Drawing.field_names, "" ) );
180
181 m_params.emplace_back( new PARAM<int>( "drawing.line_mode", &m_Drawing.line_mode,
183
184 m_params.emplace_back( new PARAM<bool>( "drawing.auto_start_wires",
185 &m_Drawing.auto_start_wires, true ) );
186
187 m_params.emplace_back( new PARAM<int>( "drawing.repeat_label_increment",
189
190 m_params.emplace_back( new PARAM<COLOR4D>( "drawing.default_sheet_border_color",
191 &m_Drawing.default_sheet_border_color, COLOR4D::UNSPECIFIED ) );
192
193 m_params.emplace_back( new PARAM<COLOR4D>( "drawing.default_sheet_background_color",
194 &m_Drawing.default_sheet_background_color, COLOR4D::UNSPECIFIED ) );
195
196 m_params.emplace_back( new PARAM_LIST<double>( "drawing.junction_size_mult_list",
197 &m_Drawing.junction_size_mult_list, { 0.0, 1.7, 4.0, 6.0, 9.0, 12.0 } ) );
198
199 m_params.emplace_back(new PARAM <int>( "drawing.junction_size_choice",
201
202 m_params.emplace_back( new PARAM<bool>( "find_replace.search_all_fields",
204
205 m_params.emplace_back( new PARAM<bool>( "find_replace.search_all_pins",
207
208 m_params.emplace_back( new PARAM<bool>( "find_replace.search_current_sheet_only",
210 false ) );
211
212 m_params.emplace_back( new PARAM<bool>( "find_replace.replace_references",
214
215 m_params.emplace_back( new PARAM<bool>( "input.drag_is_move",
216 &m_Input.drag_is_move, false ) );
217
218 m_params.emplace_back( new PARAM<bool>( "input.esc_clears_net_highlight",
220
221 m_params.emplace_back( new PARAM<int>( "selection.thickness",
223
224 m_params.emplace_back( new PARAM<int>( "selection.highlight_thickness",
226
227 m_params.emplace_back( new PARAM<bool>( "selection.draw_selected_children",
229
230 m_params.emplace_back( new PARAM<bool>( "selection.fill_shapes",
231 &m_Selection.fill_shapes, false ) );
232
233 m_params.emplace_back( new PARAM<bool>( "selection.select_pin_selects_symbol",
235
236 m_params.emplace_back( new PARAM<bool>( "annotation.automatic",
237 &m_AnnotatePanel.automatic, true ) );
238
239 m_params.emplace_back( new PARAM<bool>( "annotation.recursive",
240 &m_AnnotatePanel.recursive, true ) );
241
242 m_params.emplace_back( new PARAM<int>( "annotation.method",
243 &m_AnnotatePanel.method, 0, 0, 2 ) );
244
245 m_params.emplace_back( new PARAM<int>( "annotation.scope",
246 &m_AnnotatePanel.scope, 0, 0, 2 ) );
247
248 m_params.emplace_back( new PARAM<int>( "annotation.options",
249 &m_AnnotatePanel.options, 0, 0, 2 ) );
250
251 m_params.emplace_back( new PARAM<int>( "annotation.messages_filter",
253
254 m_params.emplace_back( new PARAM<int>( "annotation.sort_order",
255 &m_AnnotatePanel.sort_order, 0, 0, 1 ) );
256
257 m_params.emplace_back( new PARAM<wxString>( "bom.selected_plugin",
259
260 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "bom.plugins",
261 std::bind( &EESCHEMA_SETTINGS::bomSettingsToJson, this ),
262 [&]( const nlohmann::json& aObj )
263 {
264 if( !aObj.is_array() )
265 return;
266
267 const nlohmann::json& list = aObj.empty() ? defaultBomPlugins : aObj;
268
270 },
272
273 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "netlist.plugins",
275 [&]( const nlohmann::json& aObj )
276 {
277 if( !aObj.is_array() )
278 return;
279
280 if( aObj.empty() )
281 return;
282
283 const nlohmann::json& list = aObj;
284
286 },
287 nullptr ) );
288
289 m_params.emplace_back( new PARAM<bool>( "page_settings.export_paper",
290 &m_PageSettings.export_paper, false ) );
291
292 m_params.emplace_back( new PARAM<bool>( "page_settings.export_revision",
294
295 m_params.emplace_back( new PARAM<bool>( "page_settings.export_date",
296 &m_PageSettings.export_date, false ) );
297
298 m_params.emplace_back( new PARAM<bool>( "page_settings.export_title",
299 &m_PageSettings.export_title, false ) );
300
301 m_params.emplace_back( new PARAM<bool>( "page_settings.export_company",
302 &m_PageSettings.export_company, false ) );
303
304 m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment1",
306
307 m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment2",
309
310 m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment3",
312
313 m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment4",
315
316 m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment5",
318
319 m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment6",
321
322 m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment7",
324
325 m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment8",
327
328 m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment9",
330
331 m_params.emplace_back( new PARAM_MAP<bool>( "field_editor.fields_show",
333
334 m_params.emplace_back( new PARAM_MAP<bool>( "field_editor.fields_group_by",
336
337 m_params.emplace_back( new PARAM_MAP<int>( "field_editor.column_widths",
339
340 m_params.emplace_back( new PARAM<bool>( "plot.background_color",
341 &m_PlotPanel.background_color, false ) );
342
343 m_params.emplace_back( new PARAM<bool>( "plot.color",
344 &m_PlotPanel.color, true ) );
345
346 m_params.emplace_back( new PARAM<wxString>( "plot.color_theme",
347 &m_PlotPanel.color_theme, wxT( "user" ) ) );
348
349 m_params.emplace_back( new PARAM<int>( "plot.format",
350 &m_PlotPanel.format, 0 ) );
351
352 m_params.emplace_back( new PARAM<bool>( "plot.frame_reference",
353 &m_PlotPanel.frame_reference, true ) );
354
355 m_params.emplace_back( new PARAM<int>( "plot.hpgl_paper_size",
357
358 m_params.emplace_back( new PARAM<double>( "plot.hpgl_pen_size",
359 &m_PlotPanel.hpgl_pen_size, 0.5 ) );
360
361 m_params.emplace_back( new PARAM<int>( "plot.hpgl_origin",
362 &m_PlotPanel.hpgl_origin, 0 ) );
363
364 m_params.emplace_back( new PARAM<bool>( "plot.other_open_file_after_plot",
366
367 m_params.emplace_back( new PARAM<int>( "simulator.window.pos_x",
369
370 m_params.emplace_back( new PARAM<int>( "simulator.window.pos_y",
372
373 m_params.emplace_back( new PARAM<int>( "simulator.window.size_x",
374 &m_Simulator.window.state.size_x, 500 ) );
375
376 m_params.emplace_back( new PARAM<int>( "simulator.window.size_y",
377 &m_Simulator.window.state.size_y, 400 ) );
378
379 m_params.emplace_back( new PARAM<unsigned int>( "simulator.window.display",
381
382 m_params.emplace_back( new PARAM<bool>( "simulator.window.maximized",
383 &m_Simulator.window.state.maximized, false ) );
384
385 m_params.emplace_back( new PARAM<wxString>( "simulator.window.perspective",
387
388 m_params.emplace_back( new PARAM<int>( "simulator.plot_panel_width",
390
391 m_params.emplace_back( new PARAM<int>( "simulator.plot_panel_height",
393
394 m_params.emplace_back( new PARAM<int>( "simulator.signal_panel_height",
396
397 m_params.emplace_back( new PARAM<int>( "simulator.cursors_panel_height",
399
400 m_params.emplace_back( new PARAM<bool>( "simulator.white_background",
401 &m_Simulator.white_background, false ) );
402
403 m_params.emplace_back( new PARAM<int>( "symbol_chooser.sash_pos_h",
405
406 m_params.emplace_back( new PARAM<int>( "symbol_chooser.sash_pos_v",
408
409 m_params.emplace_back( new PARAM<int>( "symbol_chooser.width",
410 &m_SymChooserPanel.width, -1 ) );
411
412 m_params.emplace_back( new PARAM<int>( "symbol_chooser.height",
413 &m_SymChooserPanel.height, -1 ) );
414
415 m_params.emplace_back( new PARAM<bool>( "symbol_chooser.keep_symbol",
416 &m_SymChooserPanel.keep_symbol, false ) );
417
418 m_params.emplace_back( new PARAM<bool>( "symbol_chooser.place_all_units",
420
421 m_params.emplace_back( new PARAM<bool>( "system.never_show_rescue_dialog",
422 &m_RescueNeverShow, false ) );
423
424 m_params.emplace_back( new PARAM<int>( "lib_view.window.pos_x",
426
427 m_params.emplace_back( new PARAM<int>( "lib_view.window.pos_y",
429
430 m_params.emplace_back( new PARAM<int>( "lib_view.window.size_x",
432
433 m_params.emplace_back( new PARAM<int>( "lib_view.window.size_y",
435
436 m_params.emplace_back( new PARAM<unsigned int>( "lib_view.window.display",
438
439 m_params.emplace_back( new PARAM<bool>( "lib_view.window.maximized",
441
442 m_params.emplace_back( new PARAM<wxString>( "lib_view.window.perspective",
444
445 m_params.emplace_back( new PARAM<int>( "lib_view.lib_list_width",
447
448 m_params.emplace_back( new PARAM<int>( "lib_view.cmp_list_width",
450
451 m_params.emplace_back( new PARAM<bool>( "lib_view.show_pin_electrical_type",
453
454 m_params.emplace_back( new PARAM<wxString>( "system.last_symbol_lib_dir",
455 &m_lastSymbolLibDir, "" ) );
456
457
458 // Migrations
459
460 registerMigration( 0, 1,
461 [&]() -> bool
462 {
463 // Version 0 to 1: BOM plugin settings moved from sexpr to JSON
464 return migrateBomSettings();
465 } );
466
467
468 registerMigration( 1, 2,
469 [&]() -> bool
470 {
471 // We used to have a bug on GTK which would set the lib tree column width way
472 // too narrow.
473 if( std::optional<int> optval = Get<int>( "lib_tree.column_width" ) )
474 {
475 if( optval < 150 )
476 Set( "lib_tree.column_width", 300 );
477 }
478
479 return true;
480 } );
481
482 registerMigration( 2, 3,
483 [&]() -> bool
484 {
485 // This is actually a migration for APP_SETTINGS_BASE::m_LibTree
486 return migrateLibTreeWidth();
487 } );
488}
489
490
491bool EESCHEMA_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
492{
493 bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
494
495 // Now modify the loaded grid selection, because in earlier versions the grids index was shared
496 // between all applications and started at 1000 mils. There is a 4-position offset between
497 // this index and the possible eeschema grids list that we have to subtract.
498 std::string gridSizePtr = "window.grid.last_size";
499
500 if( std::optional<int> currentSize = Get<int>( gridSizePtr ) )
501 {
502 Set( gridSizePtr, *currentSize - 4 );
503 }
504 else
505 {
506 // Otherwise, default grid size should be 50 mils; index 1
507 Set( gridSizePtr, 1 );
508 }
509
510 ret &= fromLegacy<bool>( aCfg, "FootprintPreview", "appearance.footprint_preview" );
511 ret &= fromLegacy<bool>( aCfg, "NavigatorStaysOpen", "appearance.navigator_stays_open" );
512 ret &= fromLegacy<bool>( aCfg, "PrintSheetReferenceAndTitleBlock",
513 "appearance.print_sheet_reference" );
514 ret &= fromLegacy<bool>( aCfg, "ShowHiddenPins", "appearance.show_hidden_pins" );
515 ret &= fromLegacy<bool>( aCfg, "ShowIllegalSymbolLibDialog",
516 "appearance.show_illegal_symbol_lib_dialog" );
517 ret &= fromLegacy<bool>( aCfg, "ShowPageLimits", "appearance.show_page_limits" );
518 ret &= fromLegacy<bool>( aCfg, "ShowSheetFileNameCaseSensitivityDlg",
519 "appearance.show_sheet_filename_case_sensitivity_dialog" );
520
521 ret &= fromLegacy<bool>( aCfg, "AutoplaceFields", "autoplace_fields.enable" );
522 ret &= fromLegacy<bool>( aCfg, "AutoplaceJustify", "autoplace_fields.allow_rejustify" );
523 ret &= fromLegacy<bool>( aCfg, "AutoplaceAlign", "autoplace_fields.align_to_grid" );
524
525 ret &= fromLegacy<int>( aCfg, "DefaultBusWidth", "drawing.default_bus_thickness" );
526 ret &= fromLegacy<int>( aCfg, "DefaultJunctionSize", "drawing.default_junction_size" );
527 ret &= fromLegacy<int>( aCfg, "DefaultDrawLineWidth", "drawing.default_line_thickness" );
528 ret &= fromLegacy<int>( aCfg, "RepeatStepX", "drawing.default_repeat_offset_x" );
529 ret &= fromLegacy<int>( aCfg, "RepeatStepY", "drawing.default_repeat_offset_y" );
530 ret &= fromLegacy<int>( aCfg, "DefaultWireWidth", "drawing.default_wire_thickness" );
531 ret &= fromLegacyString( aCfg, "FieldNames", "drawing.field_names" );
532 ret &= fromLegacy<bool>( aCfg, "HorizVertLinesOnly", "drawing.line_mode" );
533 ret &= fromLegacy<int>( aCfg, "RepeatLabelIncrement", "drawing.repeat_label_increment" );
534
535 ret &= fromLegacy<bool>( aCfg, "DragActionIsMove", "input.drag_is_move" );
536
537 ret &= fromLegacy<int>( aCfg, "SelectionThickness", "selection.thickness" );
538 ret &= fromLegacy<bool>( aCfg, "SelectionDrawChildItems", "selection.draw_selected_children" );
539 ret &= fromLegacy<bool>( aCfg, "SelectionFillShapes", "selection.fill_shapes" );
540 ret &= fromLegacy<bool>( aCfg, "SelectPinSelectSymbolOpt",
541 "selection.select_pin_selects_symbol" );
542
543 ret &= fromLegacy<int>( aCfg, "AnnotateAlgoOption", "annotation.method" );
544 ret &= fromLegacy<int>( aCfg, "AnnotateFilterMsg", "annotation.messages_filter" );
545 ret &= fromLegacy<int>( aCfg, "AnnotateSortOption", "annotation.sort_order" );
546
547 ret &= fromLegacyString( aCfg, "bom_plugin_selected", "bom.selected_plugin" );
548 ret &= fromLegacyString( aCfg, "bom_plugins", "bom.plugins" );
549
551
552 ret &= fromLegacyString( aCfg, "SymbolFieldsShownColumns",
553 "edit_sch_component.visible_columns" );
554
555 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportRevision", "page_settings.export_revision" );
556 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportDate", "page_settings.export_date" );
557 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportTitle", "page_settings.export_title" );
558 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportCompany", "page_settings.export_company" );
559 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment1", "page_settings.export_comment1" );
560 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment2", "page_settings.export_comment2" );
561 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment3", "page_settings.export_comment3" );
562 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment4", "page_settings.export_comment4" );
563 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment5", "page_settings.export_comment5" );
564 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment6", "page_settings.export_comment6" );
565 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment7", "page_settings.export_comment7" );
566 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment8", "page_settings.export_comment8" );
567 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment9", "page_settings.export_comment9" );
568
569 #if 0 // To do: move this code to the new netlist plugin management in settings
570 {
571 constexpr int max_custom_commands = 8; // from DIALOG_NETLIST
572 nlohmann::json js_cmd = nlohmann::json::array();
573 nlohmann::json js_title = nlohmann::json::array();
574 wxString cmd_key, title_key, cmd, title;
575
576 for( int i = 1; i <= max_custom_commands; ++i )
577 {
578 // Only migrate if both title and command are specified
579 cmd_key.Printf( "CustomNetlistCommand%d", i );
580 title_key.Printf( "CustomNetlistTitle%d", i );
581
582 if( aCfg->Read( cmd_key, &cmd ) && aCfg->Read( title_key, &title )
583 && !cmd.IsEmpty() && !title.IsEmpty() )
584 {
585 js_cmd.push_back( cmd.ToUTF8() );
586 js_title.push_back( title.ToUTF8() );
587 }
588 }
589
590 Set( "netlist.custom_command_titles", js_title );
591 Set( "netlist.custom_command_paths", js_cmd );
592 }
593 #endif
594
595 {
596 // NOTE(JE) These parameters should move to project-local storage before V6, but we are
597 // migrating them here in order to preserve data. There is a bug here that is preserved:
598 // keys are taken directly from the (translated) UI and stored in the config, so if the user
599 // changes languages the keys will no longer work.
600 aCfg->SetPath( "SymbolFieldEditor/Show/" );
601
603 wxString key;
604 bool value = false;
605 long index = 0;
606
607 while( aCfg->GetNextEntry( key, index ) )
608 {
609 if( aCfg->Read( key, &value ) )
610 {
611 std::string key_utf( key.ToUTF8() );
612
613 try
614 {
615 js[key_utf] = value;
616 }
617 catch(...)
618 {
619 continue;
620 }
621 }
622 }
623
624 Set( "field_editor.fields_show", js );
625
626 aCfg->SetPath( "../GroupBy" );
627
628 while( aCfg->GetNextEntry( key, index ) )
629 {
630 if( aCfg->Read( key, &value ) )
631 {
632 std::string key_utf( key.ToUTF8() );
633
634 try
635 {
636 js[key_utf] = value;
637 }
638 catch(...)
639 {
640 continue;
641 }
642 }
643 }
644
645 Set( "field_editor.fields_group_by", js );
646
647 aCfg->SetPath( "../.." );
648 }
649
650 ret &= fromLegacy<bool>( aCfg, "PlotModeColor", "plot.color" );
651 ret &= fromLegacy<int>( aCfg, "PlotFormat", "plot.format" );
652 ret &= fromLegacy<bool>( aCfg, "PlotFrameRef", "plot.frame_reference" );
653 ret &= fromLegacy<bool>( aCfg, "PlotHPGLOrg", "plot.hpgl_origin" );
654 ret &= fromLegacy<int>( aCfg, "PlotHPGLPaperSize", "plot.hpgl_paper_size" );
655 ret &= fromLegacy<double>( aCfg, "PlotHPGLPenSize", "plot.hpgl_pen_size" );
656
657 ret &= fromLegacy<int>( aCfg, "SIM_PLOT_FRAMEPos_x", "simulator.window.pos_x" );
658 ret &= fromLegacy<int>( aCfg, "SIM_PLOT_FRAMEPos_y", "simulator.window.pos_y" );
659 ret &= fromLegacy<int>( aCfg, "SIM_PLOT_FRAMESize_x", "simulator.window.size_x" );
660 ret &= fromLegacy<int>( aCfg, "SIM_PLOT_FRAMESize_y", "simulator.window.size_y" );
661 ret &= fromLegacy<bool>( aCfg, "SIM_PLOT_FRAMEMaximized", "simulator.window.maximized" );
662 ret &= fromLegacyString( aCfg, "SIM_PLOT_FRAMEPerspective", "simulator.window.perspective" );
663 ret &= fromLegacyString( aCfg, "SIM_PLOT_FRAMEMostRecentlyUsedPath", "simulator.mru_path" );
664 ret &= fromLegacy<int>( aCfg, "SimPlotPanelWidth", "simulator.plot_panel_width" );
665 ret &= fromLegacy<int>( aCfg, "SimPlotPanelHeight", "simulator.plot_panel_height" );
666 ret &= fromLegacy<int>( aCfg, "SimSignalPanelHeight", "simulator.signal_panel_height" );
667 ret &= fromLegacy<int>( aCfg, "SimCursorsPanelHeight", "simulator.cursors_panel_height" );
668 ret &= fromLegacy<bool>( aCfg, "SimPlotWhiteBg", "simulator.white_background" );
669
670 ret &= fromLegacy<int>( aCfg, "SymbolChooserHSashPosition", "symbol_chooser.sash_pos_h" );
671 ret &= fromLegacy<int>( aCfg, "SymbolChooserVSashPosition", "symbol_chooser.sash_pos_v" );
672 ret &= fromLegacy<int>( aCfg, "SymbolChooserWidth", "symbol_chooser.width" );
673 ret &= fromLegacy<int>( aCfg, "SymbolChooserHeight", "symbol_chooser.height" );
674 ret &= fromLegacy<bool>( aCfg, "SymbolChooserKeepSymbol", "symbol_chooser.keep_symbol" );
675 ret &= fromLegacy<bool>( aCfg, "SymbolChooserUseUnits", "symbol_chooser.place_all_units" );
676
677 const std::string vlf = "ViewlibFrame";
678 ret &= fromLegacy<bool>( aCfg, vlf + "Maximized", "lib_view.window.maximized" );
679 ret &= fromLegacyString( aCfg, vlf + "MostRecentlyUsedPath", "lib_view.window.mru_path" );
680 ret &= fromLegacy<int>( aCfg, vlf + "Size_x", "lib_view.window.size_x" );
681 ret &= fromLegacy<int>( aCfg, vlf + "Size_y", "lib_view.window.size_y" );
682 ret &= fromLegacyString( aCfg, vlf + "Perspective", "lib_view.window.perspective" );
683 ret &= fromLegacy<int>( aCfg, vlf + "Pos_x", "lib_view.window.pos_x" );
684 ret &= fromLegacy<int>( aCfg, vlf + "Pos_y", "lib_view.window.pos_y" );
685 ret &= fromLegacy<int>( aCfg, "ViewLiblistWidth", "lib_view.lib_list_width" );
686 ret &= fromLegacy<int>( aCfg, "ViewCmplistWidth", "lib_view.cmp_list_width" );
687 ret &= fromLegacy<bool>( aCfg,
688 "ViewCmpShowPinElectricalType", "lib_view.show_pin_electrical_type" );
689 ret &= fromLegacy<bool>( aCfg, vlf + "ShowGrid", "lib_view.grid.show" );
690 ret &= fromLegacy<int>( aCfg, vlf + "_LastGridSize", "lib_view.grid.last_size" );
691
692 ret &= fromLegacy<bool>( aCfg, "RescueNeverShow", "system.never_show_rescue_dialog" );
693
694 // Legacy version stored this setting in eeschema, so move it to common if it exists
695 bool tmp;
696
697 if( aCfg->Read( "MoveWarpsCursor", &tmp ) )
698 Pgm().GetCommonSettings()->m_Input.warp_mouse_on_move = tmp;
699
700 COLOR_SETTINGS* cs = Pgm().GetSettingsManager().GetMigratedColorSettings();
701
702 auto migrateLegacyColor = [&] ( const std::string& aKey, int aLayerId ) {
703 wxString str;
704
705 if( aCfg->Read( aKey, &str ) )
706 cs->SetColor( aLayerId, COLOR4D( str ) );
707 };
708
709 migrateLegacyColor( "Color4DBgCanvasEx", LAYER_SCHEMATIC_BACKGROUND );
710 migrateLegacyColor( "Color4DBodyBgEx", LAYER_DEVICE_BACKGROUND );
711 migrateLegacyColor( "Color4DBodyEx", LAYER_DEVICE );
712 migrateLegacyColor( "Color4DBrightenedEx", LAYER_BRIGHTENED );
713 migrateLegacyColor( "Color4DBusEx", LAYER_BUS );
714 migrateLegacyColor( "Color4DConnEx", LAYER_JUNCTION );
715 migrateLegacyColor( "Color4DCursorEx", LAYER_SCHEMATIC_CURSOR );
716 migrateLegacyColor( "Color4DErcEEx", LAYER_ERC_ERR );
717 migrateLegacyColor( "Color4DErcWEx", LAYER_ERC_WARN );
718 migrateLegacyColor( "Color4DFieldEx", LAYER_FIELDS );
719 migrateLegacyColor( "Color4DGLabelEx", LAYER_GLOBLABEL );
720 migrateLegacyColor( "Color4DGridEx", LAYER_SCHEMATIC_GRID );
721 migrateLegacyColor( "Color4DHLabelEx", LAYER_HIERLABEL );
722 migrateLegacyColor( "Color4DHiddenEx", LAYER_HIDDEN );
723 migrateLegacyColor( "Color4DLLabelEx", LAYER_LOCLABEL );
724 migrateLegacyColor( "Color4DNoConnectEx", LAYER_NOCONNECT );
725 migrateLegacyColor( "Color4DNoteEx", LAYER_NOTES );
726 migrateLegacyColor( "Color4DPinEx", LAYER_PIN );
727 migrateLegacyColor( "Color4DPinNameEx", LAYER_PINNAM );
728 migrateLegacyColor( "Color4DPinNumEx", LAYER_PINNUM );
729 migrateLegacyColor( "Color4DReferenceEx", LAYER_REFERENCEPART );
730 migrateLegacyColor( "Color4DShadowEx", LAYER_SELECTION_SHADOWS );
731 migrateLegacyColor( "Color4DSheetEx", LAYER_SHEET );
732 migrateLegacyColor( "Color4DSheetFileNameEx", LAYER_SHEETFILENAME );
733 migrateLegacyColor( "Color4DSheetLabelEx", LAYER_SHEETLABEL );
734 migrateLegacyColor( "Color4DSheetNameEx", LAYER_SHEETNAME );
735 migrateLegacyColor( "Color4DValueEx", LAYER_VALUEPART );
736 migrateLegacyColor( "Color4DWireEx", LAYER_WIRE );
737 migrateLegacyColor( "Color4DWorksheetEx", LAYER_SCHEMATIC_DRAWINGSHEET );
738
739 Pgm().GetSettingsManager().SaveColorSettings( cs, "schematic" );
740
741 Set( "appearance.color_theme", cs->GetFilename() );
742
743 // LibEdit settings were stored with eeschema. If eeschema is the first app to run,
744 // we need to migrate the LibEdit settings here
745
746 auto libedit = Pgm().GetSettingsManager().GetAppSettings<SYMBOL_EDITOR_SETTINGS>( false );
747 libedit->MigrateFromLegacy( aCfg );
748 libedit->Load();
749
750 return ret;
751}
752
753
758class BOM_CFG_PARSER : public DIALOG_BOM_CFG_LEXER
759{
760 std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS>* m_pluginList;
761
762public:
763 BOM_CFG_PARSER( std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS>* aPluginList,
764 const char* aData, const wxString& aSource );
765
766 void Parse();
767
768private:
769 void parseGenerator();
770};
771
772
773std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS> EESCHEMA_SETTINGS::DefaultBomPlugins()
774{
776}
777
778
780{
781 if( !Contains( "bom.plugins" ) )
782 return false;
783
784 wxString list = *Get<wxString>( "bom.plugins" );
785
786 BOM_CFG_PARSER cfg_parser( &m_BomPanel.plugins, TO_UTF8( list ), wxT( "plugins" ) );
787
788 try
789 {
790 cfg_parser.Parse();
791 }
792 catch( const IO_ERROR& )
793 {
794 return false;
795 }
796
797 // Parser will have loaded up our array, let's dump it out to JSON
798 At( "bom.plugins" ) = bomSettingsToJson();
799
800 return true;
801}
802
803
805{
806 nlohmann::json js = nlohmann::json::array();
807
808 for( const BOM_PLUGIN_SETTINGS& plugin : m_BomPanel.plugins )
809 {
810 nlohmann::json pluginJson;
811
812 pluginJson["name"] = plugin.name.ToUTF8();
813 pluginJson["path"] = plugin.path.ToUTF8();
814 pluginJson["command"] = plugin.command.ToUTF8();
815
816 js.push_back( pluginJson );
817 }
818
819 return js;
820}
821
822
823std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS> EESCHEMA_SETTINGS::bomSettingsFromJson(
824 const nlohmann::json& aObj )
825{
826 std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS> ret;
827
828 wxASSERT( aObj.is_array() );
829
830 for( const nlohmann::json& entry : aObj )
831 {
832 if( entry.empty() || !entry.is_object() )
833 continue;
834
835 if( !entry.contains( "name" ) || !entry.contains( "path" ) )
836 continue;
837
838 BOM_PLUGIN_SETTINGS plugin( entry.at( "name" ).get<wxString>(),
839 entry.at( "path" ).get<wxString>() );
840
841 if( entry.contains( "command" ) )
842 plugin.command = entry.at( "command" ).get<wxString>();
843
844 ret.emplace_back( plugin );
845 }
846
847 return ret;
848}
849
850
852{
853 nlohmann::json js = nlohmann::json::array();
854
855 for( const NETLIST_PLUGIN_SETTINGS& plugin : m_NetlistPanel.plugins )
856 {
857 nlohmann::json pluginJson;
858
859 pluginJson["name"] = plugin.name.ToUTF8();
860 pluginJson["path"] = plugin.path.ToUTF8();
861 pluginJson["command"] = plugin.command.ToUTF8();
862
863 js.push_back( pluginJson );
864 }
865
866 return js;
867}
868
869
870std::vector<EESCHEMA_SETTINGS::NETLIST_PLUGIN_SETTINGS> EESCHEMA_SETTINGS::netlistSettingsFromJson(
871 const nlohmann::json& aObj )
872{
873 std::vector<EESCHEMA_SETTINGS::NETLIST_PLUGIN_SETTINGS> ret;
874
875 wxASSERT( aObj.is_array() );
876
877 for( const nlohmann::json& entry : aObj )
878 {
879 if( entry.empty() || !entry.is_object() )
880 continue;
881
882 if( !entry.contains( "name" ) || !entry.contains( "path" ) )
883 continue;
884
885 NETLIST_PLUGIN_SETTINGS plugin( entry.at( "name" ).get<wxString>(),
886 entry.at( "path" ).get<wxString>() );
887
888 if( entry.contains( "command" ) )
889 plugin.command = entry.at( "command" ).get<wxString>();
890
891 ret.emplace_back( plugin );
892 }
893
894 return ret;
895}
896
897
898BOM_CFG_PARSER::BOM_CFG_PARSER( std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS>* aPluginList,
899 const char* aLine, const wxString& aSource ) :
900 DIALOG_BOM_CFG_LEXER( aLine, aSource )
901{
902 wxASSERT( aPluginList );
903 m_pluginList = aPluginList;
904}
905
906
908{
909 T token;
910
911 while( ( token = NextTok() ) != T_RIGHT )
912 {
913 if( token == T_EOF)
914 break;
915
916 if( token == T_LEFT )
917 token = NextTok();
918
919 if( token == T_plugins )
920 continue;
921
922 switch( token )
923 {
924 case T_plugin: // Defines a new plugin
926 break;
927
928 default:
929// Unexpected( CurText() );
930 break;
931 }
932 }
933}
934
935
937{
938 wxString str;
940
941 NeedSYMBOLorNUMBER();
942 settings.path = FromUTF8();
943
944 T token;
945
946 while( ( token = NextTok() ) != T_RIGHT )
947 {
948 if( token == T_EOF)
949 break;
950
951 switch( token )
952 {
953 case T_LEFT:
954 break;
955
956 case T_cmd:
957 NeedSYMBOLorNUMBER();
958
959 settings.command = FromUTF8();
960
961 NeedRIGHT();
962 break;
963
964 case T_opts:
965 {
966 NeedSYMBOLorNUMBER();
967
968 wxString option = FromUTF8();
969
970 if( option.StartsWith( "nickname=", &str ) )
971 settings.name = str;
972
973 NeedRIGHT();
974 break;
975 }
976
977 default:
978 Unexpected( CurText() );
979 break;
980 }
981 }
982
983 m_pluginList->emplace_back( settings );
984}
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:101
virtual bool MigrateFromLegacy(wxConfigBase *aCfg) override
Migrates from wxConfig to JSON-based configuration.
bool migrateLibTreeWidth()
Migrates the library tree width setting from a single column (Item) to multi-column.
Used for parsing legacy-format bom plugin configurations.
BOM_CFG_PARSER(std::vector< EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS > *aPluginList, const char *aData, const wxString &aSource)
std::vector< EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS > * m_pluginList
Color settings are a bit different than most of the settings objects in that there can be more than o...
void SetColor(int aLayer, const COLOR4D &aColor)
PANEL_ANNOTATE m_AnnotatePanel
static std::vector< BOM_PLUGIN_SETTINGS > DefaultBomPlugins()
PANEL_NETLIST m_NetlistPanel
nlohmann::json bomSettingsToJson() const
virtual bool MigrateFromLegacy(wxConfigBase *aLegacyConfig) override
Migrates from wxConfig to JSON-based configuration.
nlohmann::json netlistSettingsToJson() const
PANEL_SYM_CHOOSER m_SymChooserPanel
PAGE_SETTINGS m_PageSettings
static std::vector< BOM_PLUGIN_SETTINGS > bomSettingsFromJson(const nlohmann::json &aObj)
FIND_REPLACE_EXTRA m_FindReplaceExtra
PANEL_LIB_VIEW m_LibViewPanel
AUTOPLACE_FIELDS m_AutoplaceFields
static std::vector< NETLIST_PLUGIN_SETTINGS > netlistSettingsFromJson(const nlohmann::json &aObj)
PANEL_FIELD_EDITOR m_FieldEditorPanel
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
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 Contains(const std::string &aPath) const
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
void registerMigration(int aOldSchemaVersion, int aNewSchemaVersion, std::function< bool(void)> aMigrator)
Registers a migration from one schema version to another.
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...
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 GetFilename() const
Definition: json_settings.h:73
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Represents a map of <std::string, Value>.
Definition: parameters.h:548
#define DEFAULT_BUS_WIDTH_MILS
The default noconnect size in mils.
#define DEFAULT_JUNCTION_DIAM
The default bus and wire entry size in mils.
#define DEFAULT_WIRE_WIDTH_MILS
The default bus width in mils. (can be changed in preference menu)
#define DEFAULT_LINE_WIDTH_MILS
The default wire width in mils. (can be changed in preference menu)
#define DEFAULT_TEXT_SIZE
Ratio of the font height to the baseline of the text above the wire.
const nlohmann::json defaultBomPlugins
Default value for bom.plugins.
const int eeschemaSchemaVersion
! Update the schema version whenever a migration is required
@ LINE_MODE_90
nlohmann::json json
Definition: gerbview.cpp:44
@ LAYER_SHEETNAME
Definition: layer_ids.h:363
@ LAYER_ERC_WARN
Definition: layer_ids.h:369
@ LAYER_SHEETLABEL
Definition: layer_ids.h:366
@ LAYER_PINNUM
Definition: layer_ids.h:350
@ LAYER_DEVICE
Definition: layer_ids.h:357
@ LAYER_BRIGHTENED
Definition: layer_ids.h:379
@ LAYER_HIDDEN
Definition: layer_ids.h:380
@ LAYER_HIERLABEL
Definition: layer_ids.h:349
@ LAYER_PINNAM
Definition: layer_ids.h:351
@ LAYER_GLOBLABEL
Definition: layer_ids.h:348
@ LAYER_WIRE
Definition: layer_ids.h:344
@ LAYER_NOTES
Definition: layer_ids.h:358
@ LAYER_ERC_ERR
Definition: layer_ids.h:370
@ LAYER_PIN
Definition: layer_ids.h:361
@ LAYER_VALUEPART
Definition: layer_ids.h:353
@ LAYER_BUS
Definition: layer_ids.h:345
@ LAYER_SCHEMATIC_CURSOR
Definition: layer_ids.h:377
@ LAYER_FIELDS
Definition: layer_ids.h:354
@ LAYER_DEVICE_BACKGROUND
Definition: layer_ids.h:372
@ LAYER_SCHEMATIC_DRAWINGSHEET
Definition: layer_ids.h:382
@ LAYER_LOCLABEL
Definition: layer_ids.h:347
@ LAYER_JUNCTION
Definition: layer_ids.h:346
@ LAYER_REFERENCEPART
Definition: layer_ids.h:352
@ LAYER_SHEET
Definition: layer_ids.h:362
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:381
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:376
@ LAYER_SHEETFILENAME
Definition: layer_ids.h:364
@ LAYER_NOCONNECT
Definition: layer_ids.h:367
@ LAYER_SCHEMATIC_GRID
Definition: layer_ids.h:374
This file contains miscellaneous commonly used macros and functions.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
see class PGM_BASE
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_ERROR
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
std::vector< double > junction_size_mult_list
std::vector< BOM_PLUGIN_SETTINGS > plugins
std::map< std::string, bool > fields_show
std::map< std::string, int > column_widths
std::map< std::string, bool > fields_group_by
std::vector< NETLIST_PLUGIN_SETTINGS > plugins
WINDOW_STATE state
Definition: app_settings.h:84
wxString perspective
Definition: app_settings.h:86
unsigned int display
Definition: app_settings.h:76
Functions to provide common constants and other functions to assist in making a consistent UI.