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-2021 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>
29 #include <symbol_editor_settings.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 
40 using namespace T_BOMCFG_T; // for the BOM_CFG_PARSER parser and its keywords
41 
43 const int eeschemaSchemaVersion = 1;
44 
47  {
48  { "name", "bom_csv_grouped_by_value" },
49  { "path", "bom_csv_grouped_by_value.py" }
50  },
51  {
52  { "name", "bom_csv_grouped_by_value_with_fp" },
53  { "path", "bom_csv_grouped_by_value_with_fp.py" }
54  },
55  };
56 
57 
60  m_Appearance(),
61  m_AutoplaceFields(),
62  m_Drawing(),
63  m_Input(),
64  m_PageSettings(),
65  m_AnnotatePanel(),
66  m_BomPanel(),
67  m_FieldEditorPanel(),
68  m_LibViewPanel(),
69  m_NetlistPanel(),
70  m_PlotPanel(),
71  m_SymChooserPanel(),
72  m_Selection(),
73  m_Simulator(),
74  m_RescueNeverShow( false )
75 {
76  m_params.emplace_back( new PARAM<wxString>( "appearance.edit_component_visible_columns",
77  &m_Appearance.edit_component_visible_columns, "0 1 2 3 4 5 6 7" ) );
78 
79  m_params.emplace_back( new PARAM<wxString>( "appearance.edit_sheet_visible_columns",
80  &m_Appearance.edit_sheet_visible_columns, "0 1 2 3 4 5 6 7" ) );
81 
82  m_params.emplace_back( new PARAM<int>( "appearance.erc_severities",
84 
85  m_params.emplace_back( new PARAM<bool>( "appearance.footprint_preview",
87 
88  m_params.emplace_back( new PARAM<bool>( "appearance.navigator_stays_open",
90 
91  m_params.emplace_back( new PARAM<bool>( "appearance.print_sheet_reference",
93 
94  m_params.emplace_back( new PARAM<bool>( "appearance.show_hidden_pins",
95  &m_Appearance.show_hidden_pins, false ) );
96 
97  m_params.emplace_back( new PARAM<bool>( "appearance.show_hidden_fields",
98  &m_Appearance.show_hidden_fields, false ) );
99 
100  m_params.emplace_back( new PARAM<bool>( "appearance.show_illegal_symbol_lib_dialog",
102 
103  m_params.emplace_back( new PARAM<bool>( "appearance.show_page_limits",
104  &m_Appearance.show_page_limits, true ) );
105 
106  m_params.emplace_back( new PARAM<bool>( "appearance.show_sexpr_file_convert_warning",
108 
109  m_params.emplace_back(
110  new PARAM<bool>( "appearance.show_sheet_filename_case_sensitivity_dialog",
112 
113  m_params.emplace_back( new PARAM<bool>( "autoplace_fields.enable",
114  &m_AutoplaceFields.enable, true ) );
115 
116  m_params.emplace_back( new PARAM<bool>( "autoplace_fields.allow_rejustify",
118 
119  m_params.emplace_back( new PARAM<bool>( "autoplace_fields.align_to_grid",
120  &m_AutoplaceFields.align_to_grid, true ) );
121 
122  m_params.emplace_back( new PARAM<int>( "drawing.default_bus_thickness",
124 
125  m_params.emplace_back( new PARAM<int>( "drawing.default_junction_size",
127 
128  m_params.emplace_back( new PARAM<int>( "drawing.pin_symbol_size",
130 
131  m_params.emplace_back( new PARAM<double>( "drawing.text_offset_ratio",
132  &m_Drawing.text_offset_ratio, 0.08 ) );
133 
134  m_params.emplace_back( new PARAM<int>( "drawing.default_line_thickness",
136 
137  m_params.emplace_back( new PARAM<int>( "drawing.default_repeat_offset_x",
139 
140  m_params.emplace_back( new PARAM<int>( "drawing.default_repeat_offset_y",
142 
143  m_params.emplace_back( new PARAM<int>( "drawing.default_wire_thickness",
145 
146  m_params.emplace_back( new PARAM<int>( "drawing.default_text_size",
148 
149  m_params.emplace_back( new PARAM<wxString>( "drawing.field_names",
150  &m_Drawing.field_names, "" ) );
151 
152  m_params.emplace_back( new PARAM<bool>( "drawing.hv_lines_only",
153  &m_Drawing.hv_lines_only, true ) );
154 
155  m_params.emplace_back( new PARAM<bool>( "drawing.auto_start_wires",
156  &m_Drawing.auto_start_wires, true ) );
157 
158  m_params.emplace_back( new PARAM<int>( "drawing.repeat_label_increment",
159  &m_Drawing.repeat_label_increment, 1, -10, 10 ) );
160 
161  m_params.emplace_back( new PARAM<COLOR4D>( "drawing.default_sheet_border_color",
162  &m_Drawing.default_sheet_border_color, COLOR4D::UNSPECIFIED ) );
163 
164  m_params.emplace_back( new PARAM<COLOR4D>( "drawing.default_sheet_background_color",
165  &m_Drawing.default_sheet_background_color, COLOR4D::UNSPECIFIED ) );
166 
167  m_params.emplace_back( new PARAM_LIST<double>( "drawing.junction_size_mult_list",
168  &m_Drawing.junction_size_mult_list, { 0.0, 1.7, 4.0, 6.0, 9.0, 12.0 } ) );
169 
170  m_params.emplace_back(new PARAM <int>( "drawing.junction_size_choice",
172 
173  m_params.emplace_back( new PARAM<bool>( "input.drag_is_move",
174  &m_Input.drag_is_move, true ) );
175 
176  m_params.emplace_back( new PARAM<int>( "selection.thickness",
177  &m_Selection.thickness, 3 ) );
178 
179  m_params.emplace_back( new PARAM<bool>( "selection.draw_selected_children",
181 
182  m_params.emplace_back( new PARAM<bool>( "selection.fill_shapes",
183  &m_Selection.fill_shapes, false ) );
184 
185  m_params.emplace_back( new PARAM<bool>( "selection.select_pin_selects_symbol",
187 
188  m_params.emplace_back( new PARAM<bool>( "selection.text_as_box",
189  &m_Selection.text_as_box, false ) );
190 
191  m_params.emplace_back( new PARAM<int>( "annotation.method",
192  &m_AnnotatePanel.method, 0, 0, 2 ) );
193 
194  m_params.emplace_back( new PARAM<int>( "annotation.scope",
195  &m_AnnotatePanel.scope, 0, 0, 2 ) );
196 
197  m_params.emplace_back( new PARAM<int>( "annotation.options",
198  &m_AnnotatePanel.options, 0, 0, 2 ) );
199 
200  m_params.emplace_back( new PARAM<int>( "annotation.messages_filter",
202 
203  m_params.emplace_back( new PARAM<int>( "annotation.sort_order",
204  &m_AnnotatePanel.sort_order, 0, 0, 1 ) );
205 
206  m_params.emplace_back( new PARAM<wxString>( "bom.selected_plugin",
207  &m_BomPanel.selected_plugin, "" ) );
208 
209  m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "bom.plugins",
210  std::bind( &EESCHEMA_SETTINGS::bomSettingsToJson, this ),
211  [&]( const nlohmann::json& aObj )
212  {
213  if( !aObj.is_array() )
214  return;
215 
216  const nlohmann::json& list = aObj.empty() ? defaultBomPlugins : aObj;
217 
219  },
220  defaultBomPlugins ) );
221 
222  m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "netlist.plugins",
223  std::bind( &EESCHEMA_SETTINGS::netlistSettingsToJson, this ),
224  [&]( const nlohmann::json& aObj )
225  {
226  if( !aObj.is_array() )
227  return;
228 
229  if( aObj.empty() )
230  return;
231 
232  const nlohmann::json& list = aObj;
233 
235  },
236  nullptr ) );
237 
238  m_params.emplace_back( new PARAM<bool>( "page_settings.export_paper",
239  &m_PageSettings.export_paper, false ) );
240 
241  m_params.emplace_back( new PARAM<bool>( "page_settings.export_revision",
242  &m_PageSettings.export_revision, false ) );
243 
244  m_params.emplace_back( new PARAM<bool>( "page_settings.export_date",
245  &m_PageSettings.export_date, false ) );
246 
247  m_params.emplace_back( new PARAM<bool>( "page_settings.export_title",
248  &m_PageSettings.export_title, false ) );
249 
250  m_params.emplace_back( new PARAM<bool>( "page_settings.export_company",
251  &m_PageSettings.export_company, false ) );
252 
253  m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment1",
254  &m_PageSettings.export_comment1, false ) );
255 
256  m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment2",
257  &m_PageSettings.export_comment2, false ) );
258 
259  m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment3",
260  &m_PageSettings.export_comment3, false ) );
261 
262  m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment4",
263  &m_PageSettings.export_comment4, false ) );
264 
265  m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment5",
266  &m_PageSettings.export_comment5, false ) );
267 
268  m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment6",
269  &m_PageSettings.export_comment6, false ) );
270 
271  m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment7",
272  &m_PageSettings.export_comment7, false ) );
273 
274  m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment8",
275  &m_PageSettings.export_comment8, false ) );
276 
277  m_params.emplace_back( new PARAM<bool>( "page_settings.export_comment9",
278  &m_PageSettings.export_comment9, false ) );
279 
280  m_params.emplace_back( new PARAM_MAP<bool>( "field_editor.fields_show",
282 
283  m_params.emplace_back( new PARAM_MAP<bool>( "field_editor.fields_group_by",
285 
286  m_params.emplace_back( new PARAM_MAP<int>( "field_editor.column_widths",
288 
289  m_params.emplace_back( new PARAM<bool>( "plot.background_color",
290  &m_PlotPanel.background_color, false ) );
291 
292  m_params.emplace_back( new PARAM<bool>( "plot.color",
293  &m_PlotPanel.color, true ) );
294 
295  m_params.emplace_back( new PARAM<wxString>( "plot.color_theme",
296  &m_PlotPanel.color_theme, wxT( "user" ) ) );
297 
298  m_params.emplace_back( new PARAM<int>( "plot.format",
299  &m_PlotPanel.format, 0 ) );
300 
301  m_params.emplace_back( new PARAM<bool>( "plot.frame_reference",
302  &m_PlotPanel.frame_reference, true ) );
303 
304  m_params.emplace_back( new PARAM<int>( "plot.hpgl_paper_size",
306 
307  m_params.emplace_back( new PARAM<double>( "plot.hpgl_pen_size",
308  &m_PlotPanel.hpgl_pen_size, 0.5 ) );
309 
310  m_params.emplace_back( new PARAM<int>( "plot.hpgl_origin",
311  &m_PlotPanel.hpgl_origin, 0 ) );
312 
313  m_params.emplace_back( new PARAM<int>( "simulator.window.pos_x",
314  &m_Simulator.window.state.pos_x, 0 ) );
315 
316  m_params.emplace_back( new PARAM<int>( "simulator.window.pos_y",
317  &m_Simulator.window.state.pos_y, 0 ) );
318 
319  m_params.emplace_back( new PARAM<int>( "simulator.window.size_x",
320  &m_Simulator.window.state.size_x, 500 ) );
321 
322  m_params.emplace_back( new PARAM<int>( "simulator.window.size_y",
323  &m_Simulator.window.state.size_y, 400 ) );
324 
325  m_params.emplace_back( new PARAM<unsigned int>( "simulator.window.display",
327 
328  m_params.emplace_back( new PARAM<bool>( "simulator.window.maximized",
329  &m_Simulator.window.state.maximized, false ) );
330 
331  m_params.emplace_back( new PARAM<wxString>( "simulator.window.perspective",
332  &m_Simulator.window.perspective, "" ) );
333 
334  m_params.emplace_back( new PARAM<int>( "simulator.plot_panel_width",
336 
337  m_params.emplace_back( new PARAM<int>( "simulator.plot_panel_height",
339 
340  m_params.emplace_back( new PARAM<int>( "simulator.signal_panel_height",
342 
343  m_params.emplace_back( new PARAM<int>( "simulator.cursors_panel_height",
345 
346  m_params.emplace_back( new PARAM<bool>( "simulator.white_background",
347  &m_Simulator.white_background, false ) );
348 
349  m_params.emplace_back( new PARAM<int>( "symbol_chooser.sash_pos_h",
350  &m_SymChooserPanel.sash_pos_h, -1 ) );
351 
352  m_params.emplace_back( new PARAM<int>( "symbol_chooser.sash_pos_v",
353  &m_SymChooserPanel.sash_pos_v, -1 ) );
354 
355  m_params.emplace_back( new PARAM<int>( "symbol_chooser.width",
356  &m_SymChooserPanel.width, -1 ) );
357 
358  m_params.emplace_back( new PARAM<int>( "symbol_chooser.height",
359  &m_SymChooserPanel.height, -1 ) );
360 
361  m_params.emplace_back( new PARAM<bool>( "symbol_chooser.keep_symbol",
362  &m_SymChooserPanel.keep_symbol, false ) );
363 
364  m_params.emplace_back( new PARAM<bool>( "symbol_chooser.place_all_units",
366 
367  m_params.emplace_back( new PARAM<bool>( "system.never_show_rescue_dialog",
368  &m_RescueNeverShow, false ) );
369 
370  m_params.emplace_back( new PARAM<int>( "lib_view.window.pos_x",
372 
373  m_params.emplace_back( new PARAM<int>( "lib_view.window.pos_y",
375 
376  m_params.emplace_back( new PARAM<int>( "lib_view.window.size_x",
377  &m_LibViewPanel.window.state.size_x, 500 ) );
378 
379  m_params.emplace_back( new PARAM<int>( "lib_view.window.size_y",
380  &m_LibViewPanel.window.state.size_y, 400 ) );
381 
382  m_params.emplace_back( new PARAM<unsigned int>( "lib_view.window.display",
384 
385  m_params.emplace_back( new PARAM<bool>( "lib_view.window.maximized",
386  &m_LibViewPanel.window.state.maximized, false ) );
387 
388  m_params.emplace_back( new PARAM<wxString>( "lib_view.window.perspective",
390 
391  m_params.emplace_back( new PARAM<int>( "lib_view.lib_list_width",
392  &m_LibViewPanel.lib_list_width, 150 ) );
393 
394  m_params.emplace_back( new PARAM<int>( "lib_view.cmp_list_width",
395  &m_LibViewPanel.cmp_list_width, 150 ) );
396 
397  m_params.emplace_back( new PARAM<bool>( "lib_view.show_pin_electrical_type",
399 
400  m_params.emplace_back( new PARAM<wxString>( "system.last_symbol_lib_dir",
401  &m_lastSymbolLibDir, "" ) );
402 
403 
404  // Migrations
405 
406  registerMigration( 0, 1,
407  [&]() -> bool
408  {
409  // Version 0 to 1: BOM plugin settings moved from sexpr to JSON
410  return migrateBomSettings();
411  } );
412 }
413 
414 
415 bool EESCHEMA_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
416 {
417  bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
418 
419  // Now modify the loaded grid selection, because in earlier versions the grids index was shared
420  // between all applications and started at 1000 mils. There is a 4-position offset between
421  // this index and the possible eeschema grids list that we have to subtract.
422  std::string gridSizePtr = "window.grid.last_size";
423 
424  if( OPT<int> currentSize = Get<int>( gridSizePtr ) )
425  {
426  Set( gridSizePtr, *currentSize - 4 );
427  }
428  else
429  {
430  // Otherwise, default grid size should be 50 mils; index 1
431  Set( gridSizePtr, 1 );
432  }
433 
434  ret &= fromLegacy<bool>( aCfg, "FootprintPreview", "appearance.footprint_preview" );
435  ret &= fromLegacy<bool>( aCfg, "NavigatorStaysOpen", "appearance.navigator_stays_open" );
436  ret &= fromLegacy<bool>( aCfg, "PrintSheetReferenceAndTitleBlock",
437  "appearance.print_sheet_reference" );
438  ret &= fromLegacy<bool>( aCfg, "ShowHiddenPins", "appearance.show_hidden_pins" );
439  ret &= fromLegacy<bool>( aCfg, "ShowIllegalSymbolLibDialog",
440  "appearance.show_illegal_symbol_lib_dialog" );
441  ret &= fromLegacy<bool>( aCfg, "ShowPageLimits", "appearance.show_page_limits" );
442  ret &= fromLegacy<bool>( aCfg, "ShowSheetFileNameCaseSensitivityDlg",
443  "appearance.show_sheet_filename_case_sensitivity_dialog" );
444 
445  ret &= fromLegacy<bool>( aCfg, "AutoplaceFields", "autoplace_fields.enable" );
446  ret &= fromLegacy<bool>( aCfg, "AutoplaceJustify", "autoplace_fields.allow_rejustify" );
447  ret &= fromLegacy<bool>( aCfg, "AutoplaceAlign", "autoplace_fields.align_to_grid" );
448 
449  ret &= fromLegacy<int>( aCfg, "DefaultBusWidth", "drawing.default_bus_thickness" );
450  ret &= fromLegacy<int>( aCfg, "DefaultJunctionSize", "drawing.default_junction_size" );
451  ret &= fromLegacy<int>( aCfg, "DefaultDrawLineWidth", "drawing.default_line_thickness" );
452  ret &= fromLegacy<int>( aCfg, "RepeatStepX", "drawing.default_repeat_offset_x" );
453  ret &= fromLegacy<int>( aCfg, "RepeatStepY", "drawing.default_repeat_offset_y" );
454  ret &= fromLegacy<int>( aCfg, "DefaultWireWidth", "drawing.default_wire_thickness" );
455  ret &= fromLegacyString( aCfg, "FieldNames", "drawing.field_names" );
456  ret &= fromLegacy<bool>( aCfg, "HorizVertLinesOnly", "drawing.hv_lines_only" );
457  ret &= fromLegacy<int>( aCfg, "RepeatLabelIncrement", "drawing.repeat_label_increment" );
458 
459  ret &= fromLegacy<bool>( aCfg, "DragActionIsMove", "input.drag_is_move" );
460 
461  ret &= fromLegacy<int>( aCfg, "SelectionThickness", "selection.thickness" );
462  ret &= fromLegacy<bool>( aCfg, "SelectionDrawChildItems", "selection.draw_selected_children" );
463  ret &= fromLegacy<bool>( aCfg, "SelectionFillShapes", "selection.fill_shapes" );
464  ret &= fromLegacy<bool>( aCfg, "SelectPinSelectSymbolOpt",
465  "selection.select_pin_selects_symbol" );
466  ret &= fromLegacy<bool>( aCfg, "SelectionTextAsBox", "selection.text_as_box" );
467 
468  ret &= fromLegacy<int>( aCfg, "AnnotateAlgoOption", "annotation.method" );
469  ret &= fromLegacy<int>( aCfg, "AnnotateFilterMsg", "annotation.messages_filter" );
470  ret &= fromLegacy<int>( aCfg, "AnnotateSortOption", "annotation.sort_order" );
471 
472  ret &= fromLegacyString( aCfg, "bom_plugin_selected", "bom.selected_plugin" );
473  ret &= fromLegacyString( aCfg, "bom_plugins", "bom.plugins" );
474 
476 
477  ret &= fromLegacyString( aCfg, "SymbolFieldsShownColumns",
478  "edit_sch_component.visible_columns" );
479 
480  ret &= fromLegacy<bool>( aCfg, "PageSettingsExportRevision", "page_settings.export_revision" );
481  ret &= fromLegacy<bool>( aCfg, "PageSettingsExportDate", "page_settings.export_date" );
482  ret &= fromLegacy<bool>( aCfg, "PageSettingsExportTitle", "page_settings.export_title" );
483  ret &= fromLegacy<bool>( aCfg, "PageSettingsExportCompany", "page_settings.export_company" );
484  ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment1", "page_settings.export_comment1" );
485  ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment2", "page_settings.export_comment2" );
486  ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment3", "page_settings.export_comment3" );
487  ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment4", "page_settings.export_comment4" );
488  ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment5", "page_settings.export_comment5" );
489  ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment6", "page_settings.export_comment6" );
490  ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment7", "page_settings.export_comment7" );
491  ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment8", "page_settings.export_comment8" );
492  ret &= fromLegacy<bool>( aCfg, "PageSettingsExportComment9", "page_settings.export_comment9" );
493 
494  #if 0 // To do: move this code to the new netlist plugin management in settings
495  {
496  constexpr int max_custom_commands = 8; // from DIALOG_NETLIST
497  nlohmann::json js_cmd = nlohmann::json::array();
498  nlohmann::json js_title = nlohmann::json::array();
499  wxString cmd_key, title_key, cmd, title;
500 
501  for( int i = 1; i <= max_custom_commands; ++i )
502  {
503  // Only migrate if both title and command are specified
504  cmd_key.Printf( "CustomNetlistCommand%d", i );
505  title_key.Printf( "CustomNetlistTitle%d", i );
506 
507  if( aCfg->Read( cmd_key, &cmd ) && aCfg->Read( title_key, &title )
508  && !cmd.IsEmpty() && !title.IsEmpty() )
509  {
510  js_cmd.push_back( cmd.ToUTF8() );
511  js_title.push_back( title.ToUTF8() );
512  }
513  }
514 
515  Set( "netlist.custom_command_titles", js_title );
516  Set( "netlist.custom_command_paths", js_cmd );
517  }
518  #endif
519 
520  {
521  // NOTE(JE) These parameters should move to project-local storage before V6, but we are
522  // migrating them here in order to preserve data. There is a bug here that is preserved:
523  // keys are taken directly from the (translated) UI and stored in the config, so if the user
524  // changes languages the keys will no longer work.
525  aCfg->SetPath( "SymbolFieldEditor/Show/" );
526 
527  nlohmann::json js = nlohmann::json( {} );
528  wxString key;
529  bool value = false;
530  long index = 0;
531 
532  while( aCfg->GetNextEntry( key, index ) )
533  {
534  if( aCfg->Read( key, &value ) )
535  {
536  std::string key_utf( key.ToUTF8() );
537  js[JSON_SETTINGS_INTERNALS::PointerFromString( key_utf )] = value;
538  }
539  }
540 
541  Set( "field_editor.fields_show", js );
542 
543  aCfg->SetPath( "../GroupBy" );
544 
545  while( aCfg->GetNextEntry( key, index ) )
546  {
547  if( aCfg->Read( key, &value ) )
548  {
549  std::string key_utf( key.ToUTF8() );
550  js[JSON_SETTINGS_INTERNALS::PointerFromString( key_utf )] = value;
551  }
552  }
553 
554  Set( "field_editor.fields_group_by", js );
555 
556  aCfg->SetPath( "../.." );
557  }
558 
559  ret &= fromLegacy<bool>( aCfg, "PlotModeColor", "plot.color" );
560  ret &= fromLegacy<int>( aCfg, "PlotFormat", "plot.format" );
561  ret &= fromLegacy<bool>( aCfg, "PlotFrameRef", "plot.frame_reference" );
562  ret &= fromLegacy<bool>( aCfg, "PlotHPGLOrg", "plot.hpgl_origin" );
563  ret &= fromLegacy<int>( aCfg, "PlotHPGLPaperSize", "plot.hpgl_paper_size" );
564  ret &= fromLegacy<double>( aCfg, "PlotHPGLPenSize", "plot.hpgl_pen_size" );
565 
566  ret &= fromLegacy<int>( aCfg, "SIM_PLOT_FRAMEPos_x", "simulator.window.pos_x" );
567  ret &= fromLegacy<int>( aCfg, "SIM_PLOT_FRAMEPos_y", "simulator.window.pos_y" );
568  ret &= fromLegacy<int>( aCfg, "SIM_PLOT_FRAMESize_x", "simulator.window.size_x" );
569  ret &= fromLegacy<int>( aCfg, "SIM_PLOT_FRAMESize_y", "simulator.window.size_y" );
570  ret &= fromLegacy<bool>( aCfg, "SIM_PLOT_FRAMEMaximized", "simulator.window.maximized" );
571  ret &= fromLegacyString( aCfg, "SIM_PLOT_FRAMEPerspective", "simulator.window.perspective" );
572  ret &= fromLegacyString( aCfg, "SIM_PLOT_FRAMEMostRecentlyUsedPath", "simulator.mru_path" );
573  ret &= fromLegacy<int>( aCfg, "SimPlotPanelWidth", "simulator.plot_panel_width" );
574  ret &= fromLegacy<int>( aCfg, "SimPlotPanelHeight", "simulator.plot_panel_height" );
575  ret &= fromLegacy<int>( aCfg, "SimSignalPanelHeight", "simulator.signal_panel_height" );
576  ret &= fromLegacy<int>( aCfg, "SimCursorsPanelHeight", "simulator.cursors_panel_height" );
577  ret &= fromLegacy<bool>( aCfg, "SimPlotWhiteBg", "simulator.white_background" );
578 
579  ret &= fromLegacy<int>( aCfg, "SymbolChooserHSashPosition", "symbol_chooser.sash_pos_h" );
580  ret &= fromLegacy<int>( aCfg, "SymbolChooserVSashPosition", "symbol_chooser.sash_pos_v" );
581  ret &= fromLegacy<int>( aCfg, "SymbolChooserWidth", "symbol_chooser.width" );
582  ret &= fromLegacy<int>( aCfg, "SymbolChooserHeight", "symbol_chooser.height" );
583  ret &= fromLegacy<bool>( aCfg, "SymbolChooserKeepSymbol", "symbol_chooser.keep_symbol" );
584  ret &= fromLegacy<bool>( aCfg, "SymbolChooserUseUnits", "symbol_chooser.place_all_units" );
585 
586  const std::string vlf = "ViewlibFrame";
587  ret &= fromLegacy<bool>( aCfg, vlf + "Maximized", "lib_view.window.maximized" );
588  ret &= fromLegacyString( aCfg, vlf + "MostRecentlyUsedPath", "lib_view.window.mru_path" );
589  ret &= fromLegacy<int>( aCfg, vlf + "Size_x", "lib_view.window.size_x" );
590  ret &= fromLegacy<int>( aCfg, vlf + "Size_y", "lib_view.window.size_y" );
591  ret &= fromLegacyString( aCfg, vlf + "Perspective", "lib_view.window.perspective" );
592  ret &= fromLegacy<int>( aCfg, vlf + "Pos_x", "lib_view.window.pos_x" );
593  ret &= fromLegacy<int>( aCfg, vlf + "Pos_y", "lib_view.window.pos_y" );
594  ret &= fromLegacy<int>( aCfg, "ViewLiblistWidth", "lib_view.lib_list_width" );
595  ret &= fromLegacy<int>( aCfg, "ViewCmplistWidth", "lib_view.cmp_list_width" );
596  ret &= fromLegacy<bool>( aCfg,
597  "ViewCmpShowPinElectricalType", "lib_view.show_pin_electrical_type" );
598  ret &= fromLegacy<bool>( aCfg, vlf + "ShowGrid", "lib_view.grid.show" );
599  ret &= fromLegacy<int>( aCfg, vlf + "_LastGridSize", "lib_view.grid.last_size" );
600 
601  ret &= fromLegacy<bool>( aCfg, "RescueNeverShow", "system.never_show_rescue_dialog" );
602 
603  // Legacy version stored this setting in eeschema, so move it to common if it exists
604  bool tmp;
605 
606  if( aCfg->Read( "MoveWarpsCursor", &tmp ) )
607  Pgm().GetCommonSettings()->m_Input.warp_mouse_on_move = tmp;
608 
609  COLOR_SETTINGS* cs = Pgm().GetSettingsManager().GetMigratedColorSettings();
610 
611  auto migrateLegacyColor = [&] ( const std::string& aKey, int aLayerId ) {
612  wxString str;
613 
614  if( aCfg->Read( aKey, &str ) )
615  cs->SetColor( aLayerId, COLOR4D( str ) );
616  };
617 
618  migrateLegacyColor( "Color4DBgCanvasEx", LAYER_SCHEMATIC_BACKGROUND );
619  migrateLegacyColor( "Color4DBodyBgEx", LAYER_DEVICE_BACKGROUND );
620  migrateLegacyColor( "Color4DBodyEx", LAYER_DEVICE );
621  migrateLegacyColor( "Color4DBrightenedEx", LAYER_BRIGHTENED );
622  migrateLegacyColor( "Color4DBusEx", LAYER_BUS );
623  migrateLegacyColor( "Color4DConnEx", LAYER_JUNCTION );
624  migrateLegacyColor( "Color4DCursorEx", LAYER_SCHEMATIC_CURSOR );
625  migrateLegacyColor( "Color4DErcEEx", LAYER_ERC_ERR );
626  migrateLegacyColor( "Color4DErcWEx", LAYER_ERC_WARN );
627  migrateLegacyColor( "Color4DFieldEx", LAYER_FIELDS );
628  migrateLegacyColor( "Color4DGLabelEx", LAYER_GLOBLABEL );
629  migrateLegacyColor( "Color4DGridEx", LAYER_SCHEMATIC_GRID );
630  migrateLegacyColor( "Color4DHLabelEx", LAYER_HIERLABEL );
631  migrateLegacyColor( "Color4DHiddenEx", LAYER_HIDDEN );
632  migrateLegacyColor( "Color4DLLabelEx", LAYER_LOCLABEL );
633  migrateLegacyColor( "Color4DNoConnectEx", LAYER_NOCONNECT );
634  migrateLegacyColor( "Color4DNoteEx", LAYER_NOTES );
635  migrateLegacyColor( "Color4DPinEx", LAYER_PIN );
636  migrateLegacyColor( "Color4DPinNameEx", LAYER_PINNAM );
637  migrateLegacyColor( "Color4DPinNumEx", LAYER_PINNUM );
638  migrateLegacyColor( "Color4DReferenceEx", LAYER_REFERENCEPART );
639  migrateLegacyColor( "Color4DShadowEx", LAYER_SELECTION_SHADOWS );
640  migrateLegacyColor( "Color4DSheetEx", LAYER_SHEET );
641  migrateLegacyColor( "Color4DSheetFileNameEx", LAYER_SHEETFILENAME );
642  migrateLegacyColor( "Color4DSheetLabelEx", LAYER_SHEETLABEL );
643  migrateLegacyColor( "Color4DSheetNameEx", LAYER_SHEETNAME );
644  migrateLegacyColor( "Color4DValueEx", LAYER_VALUEPART );
645  migrateLegacyColor( "Color4DWireEx", LAYER_WIRE );
646  migrateLegacyColor( "Color4DWorksheetEx", LAYER_SCHEMATIC_DRAWINGSHEET );
647 
648  Pgm().GetSettingsManager().SaveColorSettings( cs, "schematic" );
649 
650  Set( "appearance.color_theme", cs->GetFilename() );
651 
652  // LibEdit settings were stored with eeschema. If eeschema is the first app to run,
653  // we need to migrate the LibEdit settings here
654 
655  auto libedit = Pgm().GetSettingsManager().GetAppSettings<SYMBOL_EDITOR_SETTINGS>( false );
656  libedit->MigrateFromLegacy( aCfg );
657  libedit->Load();
658 
659  return ret;
660 }
661 
662 
667 class BOM_CFG_PARSER : public DIALOG_BOM_CFG_LEXER
668 {
669  std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS>* m_pluginList;
670 
671 public:
672  BOM_CFG_PARSER( std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS>* aPluginList,
673  const char* aData, const wxString& aSource );
674 
675  void Parse();
676 
677 private:
678  void parseGenerator();
679 };
680 
681 
682 std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS> EESCHEMA_SETTINGS::DefaultBomPlugins()
683 {
685 }
686 
687 
689 {
690  if( !Contains( "bom.plugins" ) )
691  return false;
692 
693  wxString list = Get<wxString>( "bom.plugins" ).value();
694 
695  BOM_CFG_PARSER cfg_parser( &m_BomPanel.plugins, TO_UTF8( list ), wxT( "plugins" ) );
696 
697  try
698  {
699  cfg_parser.Parse();
700  }
701  catch( const IO_ERROR& )
702  {
703  return false;
704  }
705 
706  // Parser will have loaded up our array, let's dump it out to JSON
707  At( "bom.plugins" ) = bomSettingsToJson();
708 
709  return true;
710 }
711 
712 
714 {
715  nlohmann::json js = nlohmann::json::array();
716 
717  for( const BOM_PLUGIN_SETTINGS& plugin : m_BomPanel.plugins )
718  {
719  nlohmann::json pluginJson;
720 
721  pluginJson["name"] = plugin.name.ToUTF8();
722  pluginJson["path"] = plugin.path.ToUTF8();
723  pluginJson["command"] = plugin.command.ToUTF8();
724 
725  js.push_back( pluginJson );
726  }
727 
728  return js;
729 }
730 
731 
732 std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS> EESCHEMA_SETTINGS::bomSettingsFromJson(
733  const nlohmann::json& aObj )
734 {
735  std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS> ret;
736 
737  wxASSERT( aObj.is_array() );
738 
739  for( const nlohmann::json& entry : aObj )
740  {
741  if( entry.empty() || !entry.is_object() )
742  continue;
743 
744  if( !entry.contains( "name" ) || !entry.contains( "path" ) )
745  continue;
746 
747  BOM_PLUGIN_SETTINGS plugin( entry.at( "name" ).get<wxString>(),
748  entry.at( "path" ).get<wxString>() );
749 
750  if( entry.contains( "command" ) )
751  plugin.command = entry.at( "command" ).get<wxString>();
752 
753  ret.emplace_back( plugin );
754  }
755 
756  return ret;
757 }
758 
759 
761 {
762  nlohmann::json js = nlohmann::json::array();
763 
764  for( const NETLIST_PLUGIN_SETTINGS& plugin : m_NetlistPanel.plugins )
765  {
766  nlohmann::json pluginJson;
767 
768  pluginJson["name"] = plugin.name.ToUTF8();
769  pluginJson["path"] = plugin.path.ToUTF8();
770  pluginJson["command"] = plugin.command.ToUTF8();
771 
772  js.push_back( pluginJson );
773  }
774 
775  return js;
776 }
777 
778 
779 std::vector<EESCHEMA_SETTINGS::NETLIST_PLUGIN_SETTINGS> EESCHEMA_SETTINGS::netlistSettingsFromJson(
780  const nlohmann::json& aObj )
781 {
782  std::vector<EESCHEMA_SETTINGS::NETLIST_PLUGIN_SETTINGS> ret;
783 
784  wxASSERT( aObj.is_array() );
785 
786  for( const nlohmann::json& entry : aObj )
787  {
788  if( entry.empty() || !entry.is_object() )
789  continue;
790 
791  if( !entry.contains( "name" ) || !entry.contains( "path" ) )
792  continue;
793 
794  NETLIST_PLUGIN_SETTINGS plugin( entry.at( "name" ).get<wxString>(),
795  entry.at( "path" ).get<wxString>() );
796 
797  if( entry.contains( "command" ) )
798  plugin.command = entry.at( "command" ).get<wxString>();
799 
800  ret.emplace_back( plugin );
801  }
802 
803  return ret;
804 }
805 
806 
807 BOM_CFG_PARSER::BOM_CFG_PARSER( std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS>* aPluginList,
808  const char* aLine, const wxString& aSource ) :
809  DIALOG_BOM_CFG_LEXER( aLine, aSource )
810 {
811  wxASSERT( aPluginList );
812  m_pluginList = aPluginList;
813 }
814 
815 
817 {
818  T token;
819 
820  while( ( token = NextTok() ) != T_RIGHT )
821  {
822  if( token == T_EOF)
823  break;
824 
825  if( token == T_LEFT )
826  token = NextTok();
827 
828  if( token == T_plugins )
829  continue;
830 
831  switch( token )
832  {
833  case T_plugin: // Defines a new plugin
834  parseGenerator();
835  break;
836 
837  default:
838 // Unexpected( CurText() );
839  break;
840  }
841  }
842 }
843 
844 
846 {
847  wxString str;
849 
850  NeedSYMBOLorNUMBER();
851  settings.path = FromUTF8();
852 
853  T token;
854 
855  while( ( token = NextTok() ) != T_RIGHT )
856  {
857  if( token == T_EOF)
858  break;
859 
860  switch( token )
861  {
862  case T_LEFT:
863  break;
864 
865  case T_cmd:
866  NeedSYMBOLorNUMBER();
867 
868  settings.command = FromUTF8();
869 
870  NeedRIGHT();
871  break;
872 
873  case T_opts:
874  {
875  NeedSYMBOLorNUMBER();
876 
877  wxString option = FromUTF8();
878 
879  if( option.StartsWith( "nickname=", &str ) )
880  settings.name = str;
881 
882  NeedRIGHT();
883  break;
884  }
885 
886  default:
887  Unexpected( CurText() );
888  break;
889  }
890  }
891 
892  m_pluginList->emplace_back( settings );
893 }
BOM_CFG_PARSER(std::vector< EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS > *aPluginList, const char *aData, const wxString &aSource)
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...
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
#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)
const nlohmann::json defaultBomPlugins
Default value for bom.plugins.
virtual bool MigrateFromLegacy(wxConfigBase *aCfg) override
Migrates from wxConfig to JSON-based configuration.
Represents a map of <std::string, Value>.
Definition: parameters.h:511
wxString GetFilename() const
Definition: json_settings.h:72
std::vector< BOM_PLUGIN_SETTINGS > plugins
PANEL_ANNOTATE m_AnnotatePanel
void SetColor(int aLayer, const COLOR4D &aColor)
#define DEFAULT_JUNCTION_DIAM
The default bus and wire entry size in mils.
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
nlohmann::json json
Definition: gerbview.cpp:41
PANEL_SYM_CHOOSER m_SymChooserPanel
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...
std::vector< NETLIST_PLUGIN_SETTINGS > plugins
This file contains miscellaneous commonly used macros and functions.
PANEL_FIELD_EDITOR m_FieldEditorPanel
PAGE_SETTINGS m_PageSettings
static std::vector< BOM_PLUGIN_SETTINGS > bomSettingsFromJson(const nlohmann::json &aObj)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
wxString perspective
Definition: app_settings.h:85
AUTOPLACE_FIELDS m_AutoplaceFields
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
nlohmann::json netlistSettingsToJson() const
Functions to provide common constants and other functions to assist in making a consistent UI.
std::vector< EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS > * m_pluginList
Used for parsing legacy-format bom plugin configurations.
std::map< std::string, int > column_widths
nlohmann::json bomSettingsToJson() const
PANEL_LIB_VIEW m_LibViewPanel
bool fromLegacyString(wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
Translates a legacy wxConfig string value to a given JSON pointer value.
see class PGM_BASE
#define DEFAULT_BUS_WIDTH_MILS
The default noconnect size in mils.
void registerMigration(int aOldSchemaVersion, int aNewSchemaVersion, std::function< bool(void)> aMigrator)
Registers a migration from one schema version to another.
WINDOW_STATE state
Definition: app_settings.h:83
virtual bool MigrateFromLegacy(wxConfigBase *aLegacyConfig) override
Migrates from wxConfig to JSON-based configuration.
boost::optional< T > OPT
Definition: optional.h:7
Color settings are a bit different than most of the settings objects in that there can be more than o...
#define DEFAULT_TEXT_SIZE
Ratio of the font height to the baseline of the text above the wire.
bool Contains(const std::string &aPath) const
std::vector< double > junction_size_mult_list
const int eeschemaSchemaVersion
! Update the schema version whenever a migration is required
std::map< std::string, bool > fields_group_by
unsigned int display
Definition: app_settings.h:75
std::map< std::string, bool > fields_show
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75
PANEL_NETLIST m_NetlistPanel
static std::vector< BOM_PLUGIN_SETTINGS > DefaultBomPlugins()
static std::vector< NETLIST_PLUGIN_SETTINGS > netlistSettingsFromJson(const nlohmann::json &aObj)
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103