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_extra" },
50 { "path", "bom_csv_grouped_extra.py" }
51 },
52 {
53 { "name", "bom_csv_grouped_by_value" },
54 { "path", "bom_csv_grouped_by_value.py" }
55 },
56 {
57 { "name", "bom_csv_grouped_by_value_with_fp" },
58 { "path", "bom_csv_grouped_by_value_with_fp.py" }
59 },
60 };
61
62
65 m_Appearance(),
66 m_AutoplaceFields(),
67 m_Drawing(),
68 m_FindReplaceExtra(),
69 m_Input(),
70 m_PageSettings(),
71 m_AnnotatePanel(),
72 m_BomPanel(),
73 m_FieldEditorPanel(),
74 m_LibViewPanel(),
75 m_NetlistPanel(),
76 m_PlotPanel(),
77 m_SymChooserPanel(),
78 m_Selection(),
79 m_Simulator(),
80 m_RescueNeverShow( false )
81{
82 m_params.emplace_back( new PARAM<wxString>( "appearance.edit_symbol_visible_columns",
83 &m_Appearance.edit_symbol_visible_columns, "0 1 2 3 4 5 6 7" ) );
84
85 m_params.emplace_back( new PARAM<int>( "appearance.edit_symbol_width",
87
88 m_params.emplace_back( new PARAM<int>( "appearance.edit_symbol_height",
90
91 m_params.emplace_back( new PARAM<wxString>( "appearance.edit_sheet_visible_columns",
92 &m_Appearance.edit_sheet_visible_columns, "0 1 2 3 4 5 6 7" ) );
93
94 m_params.emplace_back( new PARAM<int>( "appearance.edit_sheet_width",
96
97 m_params.emplace_back( new PARAM<int>( "appearance.edit_sheet_height",
99
100 m_params.emplace_back( new PARAM<wxString>( "appearance.edit_label_visible_columns",
101 &m_Appearance.edit_label_visible_columns, "0 1 2 3 4 5 6 7" ) );
102
103 m_params.emplace_back( new PARAM<int>( "appearance.edit_label_width",
105
106 m_params.emplace_back( new PARAM<int>( "appearance.edit_label_height",
108
109 m_params.emplace_back( new PARAM<int>( "appearance.erc_severities",
111
112 m_params.emplace_back( new PARAM<bool>( "appearance.footprint_preview",
114
115 m_params.emplace_back( new PARAM<bool>( "appearance.print_sheet_reference",
117
118 m_params.emplace_back( new PARAM<wxString>( "appearance.default_font",
119 &m_Appearance.default_font, "KiCad Font" ) );
120
121 m_params.emplace_back( new PARAM<bool>( "appearance.show_hidden_pins",
122 &m_Appearance.show_hidden_pins, false ) );
123
124 m_params.emplace_back( new PARAM<bool>( "appearance.show_hidden_fields",
126
127 m_params.emplace_back( new PARAM<bool>( "appearance.show_erc_warnings",
129
130 m_params.emplace_back( new PARAM<bool>( "appearance.show_erc_errors",
131 &m_Appearance.show_erc_errors, true ) );
132
133 m_params.emplace_back( new PARAM<bool>( "appearance.show_erc_exclusions",
135
136 m_params.emplace_back( new PARAM<bool>( "appearance.show_illegal_symbol_lib_dialog",
138
139 m_params.emplace_back( new PARAM<bool>( "appearance.show_page_limits",
141
142 m_params.emplace_back( new PARAM<bool>( "appearance.show_sexpr_file_convert_warning",
144
145 m_params.emplace_back(
146 new PARAM<bool>( "appearance.show_sheet_filename_case_sensitivity_dialog",
148
149 m_params.emplace_back( new PARAM<bool>( "aui.show_schematic_hierarchy",
151
152 m_params.emplace_back( new PARAM<int>( "aui.hierarchy_panel_docked_width",
154
155 m_params.emplace_back( new PARAM<int>( "aui.hierarchy_panel_float_width",
157
158 m_params.emplace_back( new PARAM<int>( "aui.hierarchy_panel_float_height",
160
161 m_params.emplace_back( new PARAM<bool>( "aui.schematic_hierarchy_float",
163
164 m_params.emplace_back( new PARAM<bool>( "autoplace_fields.enable",
165 &m_AutoplaceFields.enable, true ) );
166
167 m_params.emplace_back( new PARAM<bool>( "autoplace_fields.allow_rejustify",
169
170 m_params.emplace_back( new PARAM<bool>( "autoplace_fields.align_to_grid",
172
173 m_params.emplace_back( new PARAM<int>( "drawing.default_bus_thickness",
175
176 m_params.emplace_back( new PARAM<int>( "drawing.default_junction_size",
178
179 m_params.emplace_back( new PARAM<int>( "drawing.pin_symbol_size",
181
182 m_params.emplace_back( new PARAM<double>( "drawing.text_offset_ratio",
183 &m_Drawing.text_offset_ratio, 0.08 ) );
184
185 m_params.emplace_back( new PARAM<int>( "drawing.default_line_thickness",
187
188 m_params.emplace_back( new PARAM<int>( "drawing.default_repeat_offset_x",
190
191 m_params.emplace_back( new PARAM<int>( "drawing.default_repeat_offset_y",
193
194 m_params.emplace_back( new PARAM<int>( "drawing.default_wire_thickness",
196
197 m_params.emplace_back( new PARAM<int>( "drawing.default_text_size",
199
200 m_params.emplace_back( new PARAM<wxString>( "drawing.field_names",
201 &m_Drawing.field_names, "" ) );
202
203 m_params.emplace_back( new PARAM<int>( "drawing.line_mode", &m_Drawing.line_mode,
205
206 m_params.emplace_back( new PARAM<bool>( "drawing.auto_start_wires",
207 &m_Drawing.auto_start_wires, true ) );
208
209 m_params.emplace_back( new PARAM<int>( "drawing.repeat_label_increment",
211
212 m_params.emplace_back( new PARAM<COLOR4D>( "drawing.default_sheet_border_color",
213 &m_Drawing.default_sheet_border_color, COLOR4D::UNSPECIFIED ) );
214
215 m_params.emplace_back( new PARAM<COLOR4D>( "drawing.default_sheet_background_color",
216 &m_Drawing.default_sheet_background_color, COLOR4D::UNSPECIFIED ) );
217
218 m_params.emplace_back( new PARAM_LIST<double>( "drawing.junction_size_mult_list",
219 &m_Drawing.junction_size_mult_list, { 0.0, 1.7, 4.0, 6.0, 9.0, 12.0 } ) );
220
221 m_params.emplace_back(new PARAM <int>( "drawing.junction_size_choice",
223
224 m_params.emplace_back( new PARAM<bool>( "find_replace.search_all_fields",
226
227 m_params.emplace_back( new PARAM<bool>( "find_replace.search_all_pins",
229
230 m_params.emplace_back( new PARAM<bool>( "find_replace.search_current_sheet_only",
232 false ) );
233
234 m_params.emplace_back( new PARAM<bool>( "find_replace.replace_references",
236
237 m_params.emplace_back( new PARAM<bool>( "input.drag_is_move",
238 &m_Input.drag_is_move, false ) );
239
240 m_params.emplace_back( new PARAM<bool>( "input.esc_clears_net_highlight",
242
243 m_params.emplace_back( new PARAM<int>( "selection.thickness",
245
246 m_params.emplace_back( new PARAM<int>( "selection.highlight_thickness",
248
249 m_params.emplace_back( new PARAM<bool>( "selection.draw_selected_children",
251
252 m_params.emplace_back( new PARAM<bool>( "selection.fill_shapes",
253 &m_Selection.fill_shapes, false ) );
254
255 m_params.emplace_back( new PARAM<bool>( "selection.select_pin_selects_symbol",
257
258 m_params.emplace_back( new PARAM<bool>( "annotation.automatic",
259 &m_AnnotatePanel.automatic, true ) );
260
261 m_params.emplace_back( new PARAM<bool>( "annotation.recursive",
262 &m_AnnotatePanel.recursive, true ) );
263
264 m_params.emplace_back( new PARAM<int>( "annotation.method",
265 &m_AnnotatePanel.method, 0, 0, 2 ) );
266
267 m_params.emplace_back( new PARAM<int>( "annotation.scope",
268 &m_AnnotatePanel.scope, 0, 0, 2 ) );
269
270 m_params.emplace_back( new PARAM<int>( "annotation.options",
271 &m_AnnotatePanel.options, 0, 0, 2 ) );
272
273 m_params.emplace_back( new PARAM<int>( "annotation.messages_filter",
275
276 m_params.emplace_back( new PARAM<int>( "annotation.sort_order",
277 &m_AnnotatePanel.sort_order, 0, 0, 1 ) );
278
279 m_params.emplace_back( new PARAM<wxString>( "bom.selected_plugin",
281
282 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "bom.plugins",
283 std::bind( &EESCHEMA_SETTINGS::bomSettingsToJson, this ),
284 [&]( const nlohmann::json& aObj )
285 {
286 if( !aObj.is_array() )
287 return;
288
289 const nlohmann::json& list = aObj.empty() ? defaultBomPlugins : aObj;
290
292 },
294
295 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "netlist.plugins",
297 [&]( const nlohmann::json& aObj )
298 {
299 if( !aObj.is_array() )
300 return;
301
302 if( aObj.empty() )
303 return;
304
305 const nlohmann::json& list = aObj;
306
308 },
309 nullptr ) );
310
311 m_params.emplace_back( new PARAM<bool>( "page_settings.export_paper",
312 &m_PageSettings.export_paper, false ) );
313
314 m_params.emplace_back( new PARAM<bool>( "page_settings.export_revision",
316
317 m_params.emplace_back( new PARAM<bool>( "page_settings.export_date",
318 &m_PageSettings.export_date, false ) );
319
320 m_params.emplace_back( new PARAM<bool>( "page_settings.export_title",
321 &m_PageSettings.export_title, false ) );
322
323 m_params.emplace_back( new PARAM<bool>( "page_settings.export_company",
324 &m_PageSettings.export_company, false ) );
325
326 m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment1",
328
329 m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment2",
331
332 m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment3",
334
335 m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment4",
337
338 m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment5",
340
341 m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment6",
343
344 m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment7",
346
347 m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment8",
349
350 m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment9",
352
353 m_params.emplace_back( new PARAM_MAP<bool>( "field_editor.fields_show",
355
356 m_params.emplace_back( new PARAM_MAP<bool>( "field_editor.fields_group_by",
358
359 m_params.emplace_back( new PARAM_MAP<int>( "field_editor.column_widths",
361
362 m_params.emplace_back( new PARAM<bool>( "plot.background_color",
363 &m_PlotPanel.background_color, false ) );
364
365 m_params.emplace_back( new PARAM<bool>( "plot.color",
366 &m_PlotPanel.color, true ) );
367
368 m_params.emplace_back( new PARAM<wxString>( "plot.color_theme",
369 &m_PlotPanel.color_theme, wxT( "user" ) ) );
370
371 m_params.emplace_back( new PARAM<int>( "plot.format",
372 &m_PlotPanel.format, 0 ) );
373
374 m_params.emplace_back( new PARAM<bool>( "plot.frame_reference",
375 &m_PlotPanel.frame_reference, true ) );
376
377 m_params.emplace_back( new PARAM<int>( "plot.hpgl_paper_size",
379
380 m_params.emplace_back( new PARAM<double>( "plot.hpgl_pen_size",
381 &m_PlotPanel.hpgl_pen_size, 0.5 ) );
382
383 m_params.emplace_back( new PARAM<int>( "plot.hpgl_origin",
384 &m_PlotPanel.hpgl_origin, 0 ) );
385
386 m_params.emplace_back( new PARAM<bool>( "plot.other_open_file_after_plot",
388
389 m_params.emplace_back( new PARAM<int>( "simulator.window.pos_x",
391
392 m_params.emplace_back( new PARAM<int>( "simulator.window.pos_y",
394
395 m_params.emplace_back( new PARAM<int>( "simulator.window.size_x",
396 &m_Simulator.window.state.size_x, 500 ) );
397
398 m_params.emplace_back( new PARAM<int>( "simulator.window.size_y",
399 &m_Simulator.window.state.size_y, 400 ) );
400
401 m_params.emplace_back( new PARAM<unsigned int>( "simulator.window.display",
403
404 m_params.emplace_back( new PARAM<bool>( "simulator.window.maximized",
405 &m_Simulator.window.state.maximized, false ) );
406
407 m_params.emplace_back( new PARAM<wxString>( "simulator.window.perspective",
409
410 m_params.emplace_back( new PARAM<int>( "simulator.plot_panel_width",
412
413 m_params.emplace_back( new PARAM<int>( "simulator.plot_panel_height",
415
416 m_params.emplace_back( new PARAM<int>( "simulator.signal_panel_height",
418
419 m_params.emplace_back( new PARAM<int>( "simulator.cursors_panel_height",
421
422 m_params.emplace_back( new PARAM<bool>( "simulator.white_background",
423 &m_Simulator.white_background, false ) );
424
425 m_params.emplace_back( new PARAM<int>( "symbol_chooser.sash_pos_h",
427
428 m_params.emplace_back( new PARAM<int>( "symbol_chooser.sash_pos_v",
430
431 m_params.emplace_back( new PARAM<int>( "symbol_chooser.width",
432 &m_SymChooserPanel.width, -1 ) );
433
434 m_params.emplace_back( new PARAM<int>( "symbol_chooser.height",
435 &m_SymChooserPanel.height, -1 ) );
436
437 m_params.emplace_back( new PARAM<bool>( "symbol_chooser.keep_symbol",
438 &m_SymChooserPanel.keep_symbol, false ) );
439
440 m_params.emplace_back( new PARAM<bool>( "symbol_chooser.place_all_units",
442
443 m_params.emplace_back( new PARAM<bool>( "system.never_show_rescue_dialog",
444 &m_RescueNeverShow, false ) );
445
446 m_params.emplace_back( new PARAM<int>( "lib_view.window.pos_x",
448
449 m_params.emplace_back( new PARAM<int>( "lib_view.window.pos_y",
451
452 m_params.emplace_back( new PARAM<int>( "lib_view.window.size_x",
454
455 m_params.emplace_back( new PARAM<int>( "lib_view.window.size_y",
457
458 m_params.emplace_back( new PARAM<unsigned int>( "lib_view.window.display",
460
461 m_params.emplace_back( new PARAM<bool>( "lib_view.window.maximized",
463
464 m_params.emplace_back( new PARAM<wxString>( "lib_view.window.perspective",
466
467 m_params.emplace_back( new PARAM<int>( "lib_view.lib_list_width",
469
470 m_params.emplace_back( new PARAM<int>( "lib_view.cmp_list_width",
472
473 m_params.emplace_back( new PARAM<bool>( "lib_view.show_pin_electrical_type",
475
476 m_params.emplace_back( new PARAM<wxString>( "system.last_symbol_lib_dir",
477 &m_lastSymbolLibDir, "" ) );
478
479
480 // Migrations
481
482 registerMigration( 0, 1,
483 [&]() -> bool
484 {
485 // Version 0 to 1: BOM plugin settings moved from sexpr to JSON
486 return migrateBomSettings();
487 } );
488
489
490 registerMigration( 1, 2,
491 [&]() -> bool
492 {
493 // We used to have a bug on GTK which would set the lib tree column width way
494 // too narrow.
495 if( std::optional<int> optval = Get<int>( "lib_tree.column_width" ) )
496 {
497 if( optval < 150 )
498 Set( "lib_tree.column_width", 300 );
499 }
500
501 return true;
502 } );
503
504 registerMigration( 2, 3,
505 [&]() -> bool
506 {
507 // This is actually a migration for APP_SETTINGS_BASE::m_LibTree
508 return migrateLibTreeWidth();
509 } );
510}
511
512
513bool EESCHEMA_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
514{
515 bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
516
517 // Now modify the loaded grid selection, because in earlier versions the grids index was shared
518 // between all applications and started at 1000 mils. There is a 4-position offset between
519 // this index and the possible eeschema grids list that we have to subtract.
520 std::string gridSizePtr = "window.grid.last_size";
521
522 if( std::optional<int> currentSize = Get<int>( gridSizePtr ) )
523 {
524 Set( gridSizePtr, *currentSize - 4 );
525 }
526 else
527 {
528 // Otherwise, default grid size should be 50 mils; index 1
529 Set( gridSizePtr, 1 );
530 }
531
532 ret &= fromLegacy<bool>( aCfg, "FootprintPreview", "appearance.footprint_preview" );
533 ret &= fromLegacy<bool>( aCfg, "NavigatorStaysOpen", "appearance.navigator_stays_open" );
534 ret &= fromLegacy<bool>( aCfg, "PrintSheetReferenceAndTitleBlock",
535 "appearance.print_sheet_reference" );
536 ret &= fromLegacy<bool>( aCfg, "ShowHiddenPins", "appearance.show_hidden_pins" );
537 ret &= fromLegacy<bool>( aCfg, "ShowIllegalSymbolLibDialog",
538 "appearance.show_illegal_symbol_lib_dialog" );
539 ret &= fromLegacy<bool>( aCfg, "ShowPageLimits", "appearance.show_page_limits" );
540 ret &= fromLegacy<bool>( aCfg, "ShowSheetFileNameCaseSensitivityDlg",
541 "appearance.show_sheet_filename_case_sensitivity_dialog" );
542
543 ret &= fromLegacy<bool>( aCfg, "AutoplaceFields", "autoplace_fields.enable" );
544 ret &= fromLegacy<bool>( aCfg, "AutoplaceJustify", "autoplace_fields.allow_rejustify" );
545 ret &= fromLegacy<bool>( aCfg, "AutoplaceAlign", "autoplace_fields.align_to_grid" );
546
547 ret &= fromLegacy<int>( aCfg, "DefaultBusWidth", "drawing.default_bus_thickness" );
548 ret &= fromLegacy<int>( aCfg, "DefaultJunctionSize", "drawing.default_junction_size" );
549 ret &= fromLegacy<int>( aCfg, "DefaultDrawLineWidth", "drawing.default_line_thickness" );
550 ret &= fromLegacy<int>( aCfg, "RepeatStepX", "drawing.default_repeat_offset_x" );
551 ret &= fromLegacy<int>( aCfg, "RepeatStepY", "drawing.default_repeat_offset_y" );
552 ret &= fromLegacy<int>( aCfg, "DefaultWireWidth", "drawing.default_wire_thickness" );
553 ret &= fromLegacyString( aCfg, "FieldNames", "drawing.field_names" );
554 ret &= fromLegacy<bool>( aCfg, "HorizVertLinesOnly", "drawing.line_mode" );
555 ret &= fromLegacy<int>( aCfg, "RepeatLabelIncrement", "drawing.repeat_label_increment" );
556
557 ret &= fromLegacy<bool>( aCfg, "DragActionIsMove", "input.drag_is_move" );
558
559 ret &= fromLegacy<int>( aCfg, "SelectionThickness", "selection.thickness" );
560 ret &= fromLegacy<bool>( aCfg, "SelectionDrawChildItems", "selection.draw_selected_children" );
561 ret &= fromLegacy<bool>( aCfg, "SelectionFillShapes", "selection.fill_shapes" );
562 ret &= fromLegacy<bool>( aCfg, "SelectPinSelectSymbolOpt",
563 "selection.select_pin_selects_symbol" );
564
565 ret &= fromLegacy<int>( aCfg, "AnnotateAlgoOption", "annotation.method" );
566 ret &= fromLegacy<int>( aCfg, "AnnotateFilterMsg", "annotation.messages_filter" );
567 ret &= fromLegacy<int>( aCfg, "AnnotateSortOption", "annotation.sort_order" );
568
569 ret &= fromLegacyString( aCfg, "bom_plugin_selected", "bom.selected_plugin" );
570 ret &= fromLegacyString( aCfg, "bom_plugins", "bom.plugins" );
571
573
574 ret &= fromLegacyString( aCfg, "SymbolFieldsShownColumns",
575 "edit_sch_component.visible_columns" );
576
577 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportRevision", "page_settings.export_revision" );
578 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportDate", "page_settings.export_date" );
579 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportTitle", "page_settings.export_title" );
580 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportCompany", "page_settings.export_company" );
581 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment1", "page_settings.export_comment1" );
582 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment2", "page_settings.export_comment2" );
583 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment3", "page_settings.export_comment3" );
584 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment4", "page_settings.export_comment4" );
585 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment5", "page_settings.export_comment5" );
586 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment6", "page_settings.export_comment6" );
587 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment7", "page_settings.export_comment7" );
588 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment8", "page_settings.export_comment8" );
589 ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment9", "page_settings.export_comment9" );
590
591 #if 0 // To do: move this code to the new netlist plugin management in settings
592 {
593 constexpr int max_custom_commands = 8; // from DIALOG_NETLIST
594 nlohmann::json js_cmd = nlohmann::json::array();
595 nlohmann::json js_title = nlohmann::json::array();
596 wxString cmd_key, title_key, cmd, title;
597
598 for( int i = 1; i <= max_custom_commands; ++i )
599 {
600 // Only migrate if both title and command are specified
601 cmd_key.Printf( "CustomNetlistCommand%d", i );
602 title_key.Printf( "CustomNetlistTitle%d", i );
603
604 if( aCfg->Read( cmd_key, &cmd ) && aCfg->Read( title_key, &title )
605 && !cmd.IsEmpty() && !title.IsEmpty() )
606 {
607 js_cmd.push_back( cmd.ToUTF8() );
608 js_title.push_back( title.ToUTF8() );
609 }
610 }
611
612 Set( "netlist.custom_command_titles", js_title );
613 Set( "netlist.custom_command_paths", js_cmd );
614 }
615 #endif
616
617 {
618 // NOTE(JE) These parameters should move to project-local storage before V6, but we are
619 // migrating them here in order to preserve data. There is a bug here that is preserved:
620 // keys are taken directly from the (translated) UI and stored in the config, so if the user
621 // changes languages the keys will no longer work.
622 aCfg->SetPath( "SymbolFieldEditor/Show/" );
623
625 wxString key;
626 bool value = false;
627 long index = 0;
628
629 while( aCfg->GetNextEntry( key, index ) )
630 {
631 if( aCfg->Read( key, &value ) )
632 {
633 std::string key_utf( key.ToUTF8() );
634
635 try
636 {
637 js[key_utf] = value;
638 }
639 catch(...)
640 {
641 continue;
642 }
643 }
644 }
645
646 Set( "field_editor.fields_show", js );
647
648 aCfg->SetPath( "../GroupBy" );
649
650 while( aCfg->GetNextEntry( key, index ) )
651 {
652 if( aCfg->Read( key, &value ) )
653 {
654 std::string key_utf( key.ToUTF8() );
655
656 try
657 {
658 js[key_utf] = value;
659 }
660 catch(...)
661 {
662 continue;
663 }
664 }
665 }
666
667 Set( "field_editor.fields_group_by", js );
668
669 aCfg->SetPath( "../.." );
670 }
671
672 ret &= fromLegacy<bool>( aCfg, "PlotModeColor", "plot.color" );
673 ret &= fromLegacy<int>( aCfg, "PlotFormat", "plot.format" );
674 ret &= fromLegacy<bool>( aCfg, "PlotFrameRef", "plot.frame_reference" );
675 ret &= fromLegacy<bool>( aCfg, "PlotHPGLOrg", "plot.hpgl_origin" );
676 ret &= fromLegacy<int>( aCfg, "PlotHPGLPaperSize", "plot.hpgl_paper_size" );
677 ret &= fromLegacy<double>( aCfg, "PlotHPGLPenSize", "plot.hpgl_pen_size" );
678
679 ret &= fromLegacy<int>( aCfg, "SIM_PLOT_FRAMEPos_x", "simulator.window.pos_x" );
680 ret &= fromLegacy<int>( aCfg, "SIM_PLOT_FRAMEPos_y", "simulator.window.pos_y" );
681 ret &= fromLegacy<int>( aCfg, "SIM_PLOT_FRAMESize_x", "simulator.window.size_x" );
682 ret &= fromLegacy<int>( aCfg, "SIM_PLOT_FRAMESize_y", "simulator.window.size_y" );
683 ret &= fromLegacy<bool>( aCfg, "SIM_PLOT_FRAMEMaximized", "simulator.window.maximized" );
684 ret &= fromLegacyString( aCfg, "SIM_PLOT_FRAMEPerspective", "simulator.window.perspective" );
685 ret &= fromLegacyString( aCfg, "SIM_PLOT_FRAMEMostRecentlyUsedPath", "simulator.mru_path" );
686 ret &= fromLegacy<int>( aCfg, "SimPlotPanelWidth", "simulator.plot_panel_width" );
687 ret &= fromLegacy<int>( aCfg, "SimPlotPanelHeight", "simulator.plot_panel_height" );
688 ret &= fromLegacy<int>( aCfg, "SimSignalPanelHeight", "simulator.signal_panel_height" );
689 ret &= fromLegacy<int>( aCfg, "SimCursorsPanelHeight", "simulator.cursors_panel_height" );
690 ret &= fromLegacy<bool>( aCfg, "SimPlotWhiteBg", "simulator.white_background" );
691
692 ret &= fromLegacy<int>( aCfg, "SymbolChooserHSashPosition", "symbol_chooser.sash_pos_h" );
693 ret &= fromLegacy<int>( aCfg, "SymbolChooserVSashPosition", "symbol_chooser.sash_pos_v" );
694 ret &= fromLegacy<int>( aCfg, "SymbolChooserWidth", "symbol_chooser.width" );
695 ret &= fromLegacy<int>( aCfg, "SymbolChooserHeight", "symbol_chooser.height" );
696 ret &= fromLegacy<bool>( aCfg, "SymbolChooserKeepSymbol", "symbol_chooser.keep_symbol" );
697 ret &= fromLegacy<bool>( aCfg, "SymbolChooserUseUnits", "symbol_chooser.place_all_units" );
698
699 const std::string vlf = "ViewlibFrame";
700 ret &= fromLegacy<bool>( aCfg, vlf + "Maximized", "lib_view.window.maximized" );
701 ret &= fromLegacyString( aCfg, vlf + "MostRecentlyUsedPath", "lib_view.window.mru_path" );
702 ret &= fromLegacy<int>( aCfg, vlf + "Size_x", "lib_view.window.size_x" );
703 ret &= fromLegacy<int>( aCfg, vlf + "Size_y", "lib_view.window.size_y" );
704 ret &= fromLegacyString( aCfg, vlf + "Perspective", "lib_view.window.perspective" );
705 ret &= fromLegacy<int>( aCfg, vlf + "Pos_x", "lib_view.window.pos_x" );
706 ret &= fromLegacy<int>( aCfg, vlf + "Pos_y", "lib_view.window.pos_y" );
707 ret &= fromLegacy<int>( aCfg, "ViewLiblistWidth", "lib_view.lib_list_width" );
708 ret &= fromLegacy<int>( aCfg, "ViewCmplistWidth", "lib_view.cmp_list_width" );
709 ret &= fromLegacy<bool>( aCfg,
710 "ViewCmpShowPinElectricalType", "lib_view.show_pin_electrical_type" );
711 ret &= fromLegacy<bool>( aCfg, vlf + "ShowGrid", "lib_view.grid.show" );
712 ret &= fromLegacy<int>( aCfg, vlf + "_LastGridSize", "lib_view.grid.last_size" );
713
714 ret &= fromLegacy<bool>( aCfg, "RescueNeverShow", "system.never_show_rescue_dialog" );
715
716 // Legacy version stored this setting in eeschema, so move it to common if it exists
717 bool tmp;
718
719 if( aCfg->Read( "MoveWarpsCursor", &tmp ) )
720 Pgm().GetCommonSettings()->m_Input.warp_mouse_on_move = tmp;
721
722 COLOR_SETTINGS* cs = Pgm().GetSettingsManager().GetMigratedColorSettings();
723
724 auto migrateLegacyColor = [&] ( const std::string& aKey, int aLayerId ) {
725 wxString str;
726
727 if( aCfg->Read( aKey, &str ) )
728 cs->SetColor( aLayerId, COLOR4D( str ) );
729 };
730
731 migrateLegacyColor( "Color4DBgCanvasEx", LAYER_SCHEMATIC_BACKGROUND );
732 migrateLegacyColor( "Color4DBodyBgEx", LAYER_DEVICE_BACKGROUND );
733 migrateLegacyColor( "Color4DBodyEx", LAYER_DEVICE );
734 migrateLegacyColor( "Color4DBrightenedEx", LAYER_BRIGHTENED );
735 migrateLegacyColor( "Color4DBusEx", LAYER_BUS );
736 migrateLegacyColor( "Color4DConnEx", LAYER_JUNCTION );
737 migrateLegacyColor( "Color4DCursorEx", LAYER_SCHEMATIC_CURSOR );
738 migrateLegacyColor( "Color4DErcEEx", LAYER_ERC_ERR );
739 migrateLegacyColor( "Color4DErcWEx", LAYER_ERC_WARN );
740 migrateLegacyColor( "Color4DFieldEx", LAYER_FIELDS );
741 migrateLegacyColor( "Color4DGLabelEx", LAYER_GLOBLABEL );
742 migrateLegacyColor( "Color4DGridEx", LAYER_SCHEMATIC_GRID );
743 migrateLegacyColor( "Color4DHLabelEx", LAYER_HIERLABEL );
744 migrateLegacyColor( "Color4DHiddenEx", LAYER_HIDDEN );
745 migrateLegacyColor( "Color4DLLabelEx", LAYER_LOCLABEL );
746 migrateLegacyColor( "Color4DNoConnectEx", LAYER_NOCONNECT );
747 migrateLegacyColor( "Color4DNoteEx", LAYER_NOTES );
748 migrateLegacyColor( "Color4DPinEx", LAYER_PIN );
749 migrateLegacyColor( "Color4DPinNameEx", LAYER_PINNAM );
750 migrateLegacyColor( "Color4DPinNumEx", LAYER_PINNUM );
751 migrateLegacyColor( "Color4DReferenceEx", LAYER_REFERENCEPART );
752 migrateLegacyColor( "Color4DShadowEx", LAYER_SELECTION_SHADOWS );
753 migrateLegacyColor( "Color4DSheetEx", LAYER_SHEET );
754 migrateLegacyColor( "Color4DSheetFileNameEx", LAYER_SHEETFILENAME );
755 migrateLegacyColor( "Color4DSheetLabelEx", LAYER_SHEETLABEL );
756 migrateLegacyColor( "Color4DSheetNameEx", LAYER_SHEETNAME );
757 migrateLegacyColor( "Color4DValueEx", LAYER_VALUEPART );
758 migrateLegacyColor( "Color4DWireEx", LAYER_WIRE );
759 migrateLegacyColor( "Color4DWorksheetEx", LAYER_SCHEMATIC_DRAWINGSHEET );
760
761 Pgm().GetSettingsManager().SaveColorSettings( cs, "schematic" );
762
763 Set( "appearance.color_theme", cs->GetFilename() );
764
765 // LibEdit settings were stored with eeschema. If eeschema is the first app to run,
766 // we need to migrate the LibEdit settings here
767
768 auto libedit = Pgm().GetSettingsManager().GetAppSettings<SYMBOL_EDITOR_SETTINGS>( false );
769 libedit->MigrateFromLegacy( aCfg );
770 libedit->Load();
771
772 return ret;
773}
774
775
780class BOM_CFG_PARSER : public DIALOG_BOM_CFG_LEXER
781{
782 std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS>* m_pluginList;
783
784public:
785 BOM_CFG_PARSER( std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS>* aPluginList,
786 const char* aData, const wxString& aSource );
787
788 void Parse();
789
790private:
791 void parseGenerator();
792};
793
794
795std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS> EESCHEMA_SETTINGS::DefaultBomPlugins()
796{
798}
799
800
802{
803 if( !Contains( "bom.plugins" ) )
804 return false;
805
806 wxString list = *Get<wxString>( "bom.plugins" );
807
808 BOM_CFG_PARSER cfg_parser( &m_BomPanel.plugins, TO_UTF8( list ), wxT( "plugins" ) );
809
810 try
811 {
812 cfg_parser.Parse();
813 }
814 catch( const IO_ERROR& )
815 {
816 return false;
817 }
818
819 // Parser will have loaded up our array, let's dump it out to JSON
820 At( "bom.plugins" ) = bomSettingsToJson();
821
822 return true;
823}
824
825
827{
828 nlohmann::json js = nlohmann::json::array();
829
830 for( const BOM_PLUGIN_SETTINGS& plugin : m_BomPanel.plugins )
831 {
832 nlohmann::json pluginJson;
833
834 pluginJson["name"] = plugin.name.ToUTF8();
835 pluginJson["path"] = plugin.path.ToUTF8();
836 pluginJson["command"] = plugin.command.ToUTF8();
837
838 js.push_back( pluginJson );
839 }
840
841 return js;
842}
843
844
845std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS> EESCHEMA_SETTINGS::bomSettingsFromJson(
846 const nlohmann::json& aObj )
847{
848 std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS> ret;
849
850 wxASSERT( aObj.is_array() );
851
852 for( const nlohmann::json& entry : aObj )
853 {
854 if( entry.empty() || !entry.is_object() )
855 continue;
856
857 if( !entry.contains( "name" ) || !entry.contains( "path" ) )
858 continue;
859
860 BOM_PLUGIN_SETTINGS plugin( entry.at( "name" ).get<wxString>(),
861 entry.at( "path" ).get<wxString>() );
862
863 if( entry.contains( "command" ) )
864 plugin.command = entry.at( "command" ).get<wxString>();
865
866 ret.emplace_back( plugin );
867 }
868
869 return ret;
870}
871
872
874{
875 nlohmann::json js = nlohmann::json::array();
876
877 for( const NETLIST_PLUGIN_SETTINGS& plugin : m_NetlistPanel.plugins )
878 {
879 nlohmann::json pluginJson;
880
881 pluginJson["name"] = plugin.name.ToUTF8();
882 pluginJson["path"] = plugin.path.ToUTF8();
883 pluginJson["command"] = plugin.command.ToUTF8();
884
885 js.push_back( pluginJson );
886 }
887
888 return js;
889}
890
891
892std::vector<EESCHEMA_SETTINGS::NETLIST_PLUGIN_SETTINGS> EESCHEMA_SETTINGS::netlistSettingsFromJson(
893 const nlohmann::json& aObj )
894{
895 std::vector<EESCHEMA_SETTINGS::NETLIST_PLUGIN_SETTINGS> ret;
896
897 wxASSERT( aObj.is_array() );
898
899 for( const nlohmann::json& entry : aObj )
900 {
901 if( entry.empty() || !entry.is_object() )
902 continue;
903
904 if( !entry.contains( "name" ) || !entry.contains( "path" ) )
905 continue;
906
907 NETLIST_PLUGIN_SETTINGS plugin( entry.at( "name" ).get<wxString>(),
908 entry.at( "path" ).get<wxString>() );
909
910 if( entry.contains( "command" ) )
911 plugin.command = entry.at( "command" ).get<wxString>();
912
913 ret.emplace_back( plugin );
914 }
915
916 return ret;
917}
918
919
920BOM_CFG_PARSER::BOM_CFG_PARSER( std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS>* aPluginList,
921 const char* aLine, const wxString& aSource ) :
922 DIALOG_BOM_CFG_LEXER( aLine, aSource )
923{
924 wxASSERT( aPluginList );
925 m_pluginList = aPluginList;
926}
927
928
930{
931 T token;
932
933 while( ( token = NextTok() ) != T_RIGHT )
934 {
935 if( token == T_EOF)
936 break;
937
938 if( token == T_LEFT )
939 token = NextTok();
940
941 if( token == T_plugins )
942 continue;
943
944 switch( token )
945 {
946 case T_plugin: // Defines a new plugin
948 break;
949
950 default:
951// Unexpected( CurText() );
952 break;
953 }
954 }
955}
956
957
959{
960 wxString str;
962
963 NeedSYMBOLorNUMBER();
964 settings.path = FromUTF8();
965
966 T token;
967
968 while( ( token = NextTok() ) != T_RIGHT )
969 {
970 if( token == T_EOF)
971 break;
972
973 switch( token )
974 {
975 case T_LEFT:
976 break;
977
978 case T_cmd:
979 NeedSYMBOLorNUMBER();
980
981 settings.command = FromUTF8();
982
983 NeedRIGHT();
984 break;
985
986 case T_opts:
987 {
988 NeedSYMBOLorNUMBER();
989
990 wxString option = FromUTF8();
991
992 if( option.StartsWith( wxS( "nickname=" ), &str ) )
993 settings.name = str;
994
995 NeedRIGHT();
996 break;
997 }
998
999 default:
1000 Unexpected( CurText() );
1001 break;
1002 }
1003 }
1004
1005 m_pluginList->emplace_back( settings );
1006}
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:110
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:93
wxString perspective
Definition: app_settings.h:95
unsigned int display
Definition: app_settings.h:85
Functions to provide common constants and other functions to assist in making a consistent UI.