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",
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, false ) );
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 
538  try
539  {
540  js[key_utf] = value;
541  }
542  catch(...)
543  {
544  continue;
545  }
546  }
547  }
548 
549  Set( "field_editor.fields_show", js );
550 
551  aCfg->SetPath( "../GroupBy" );
552 
553  while( aCfg->GetNextEntry( key, index ) )
554  {
555  if( aCfg->Read( key, &value ) )
556  {
557  std::string key_utf( key.ToUTF8() );
558 
559  try
560  {
561  js[key_utf] = value;
562  }
563  catch(...)
564  {
565  continue;
566  }
567  }
568  }
569 
570  Set( "field_editor.fields_group_by", js );
571 
572  aCfg->SetPath( "../.." );
573  }
574 
575  ret &= fromLegacy<bool>( aCfg, "PlotModeColor", "plot.color" );
576  ret &= fromLegacy<int>( aCfg, "PlotFormat", "plot.format" );
577  ret &= fromLegacy<bool>( aCfg, "PlotFrameRef", "plot.frame_reference" );
578  ret &= fromLegacy<bool>( aCfg, "PlotHPGLOrg", "plot.hpgl_origin" );
579  ret &= fromLegacy<int>( aCfg, "PlotHPGLPaperSize", "plot.hpgl_paper_size" );
580  ret &= fromLegacy<double>( aCfg, "PlotHPGLPenSize", "plot.hpgl_pen_size" );
581 
582  ret &= fromLegacy<int>( aCfg, "SIM_PLOT_FRAMEPos_x", "simulator.window.pos_x" );
583  ret &= fromLegacy<int>( aCfg, "SIM_PLOT_FRAMEPos_y", "simulator.window.pos_y" );
584  ret &= fromLegacy<int>( aCfg, "SIM_PLOT_FRAMESize_x", "simulator.window.size_x" );
585  ret &= fromLegacy<int>( aCfg, "SIM_PLOT_FRAMESize_y", "simulator.window.size_y" );
586  ret &= fromLegacy<bool>( aCfg, "SIM_PLOT_FRAMEMaximized", "simulator.window.maximized" );
587  ret &= fromLegacyString( aCfg, "SIM_PLOT_FRAMEPerspective", "simulator.window.perspective" );
588  ret &= fromLegacyString( aCfg, "SIM_PLOT_FRAMEMostRecentlyUsedPath", "simulator.mru_path" );
589  ret &= fromLegacy<int>( aCfg, "SimPlotPanelWidth", "simulator.plot_panel_width" );
590  ret &= fromLegacy<int>( aCfg, "SimPlotPanelHeight", "simulator.plot_panel_height" );
591  ret &= fromLegacy<int>( aCfg, "SimSignalPanelHeight", "simulator.signal_panel_height" );
592  ret &= fromLegacy<int>( aCfg, "SimCursorsPanelHeight", "simulator.cursors_panel_height" );
593  ret &= fromLegacy<bool>( aCfg, "SimPlotWhiteBg", "simulator.white_background" );
594 
595  ret &= fromLegacy<int>( aCfg, "SymbolChooserHSashPosition", "symbol_chooser.sash_pos_h" );
596  ret &= fromLegacy<int>( aCfg, "SymbolChooserVSashPosition", "symbol_chooser.sash_pos_v" );
597  ret &= fromLegacy<int>( aCfg, "SymbolChooserWidth", "symbol_chooser.width" );
598  ret &= fromLegacy<int>( aCfg, "SymbolChooserHeight", "symbol_chooser.height" );
599  ret &= fromLegacy<bool>( aCfg, "SymbolChooserKeepSymbol", "symbol_chooser.keep_symbol" );
600  ret &= fromLegacy<bool>( aCfg, "SymbolChooserUseUnits", "symbol_chooser.place_all_units" );
601 
602  const std::string vlf = "ViewlibFrame";
603  ret &= fromLegacy<bool>( aCfg, vlf + "Maximized", "lib_view.window.maximized" );
604  ret &= fromLegacyString( aCfg, vlf + "MostRecentlyUsedPath", "lib_view.window.mru_path" );
605  ret &= fromLegacy<int>( aCfg, vlf + "Size_x", "lib_view.window.size_x" );
606  ret &= fromLegacy<int>( aCfg, vlf + "Size_y", "lib_view.window.size_y" );
607  ret &= fromLegacyString( aCfg, vlf + "Perspective", "lib_view.window.perspective" );
608  ret &= fromLegacy<int>( aCfg, vlf + "Pos_x", "lib_view.window.pos_x" );
609  ret &= fromLegacy<int>( aCfg, vlf + "Pos_y", "lib_view.window.pos_y" );
610  ret &= fromLegacy<int>( aCfg, "ViewLiblistWidth", "lib_view.lib_list_width" );
611  ret &= fromLegacy<int>( aCfg, "ViewCmplistWidth", "lib_view.cmp_list_width" );
612  ret &= fromLegacy<bool>( aCfg,
613  "ViewCmpShowPinElectricalType", "lib_view.show_pin_electrical_type" );
614  ret &= fromLegacy<bool>( aCfg, vlf + "ShowGrid", "lib_view.grid.show" );
615  ret &= fromLegacy<int>( aCfg, vlf + "_LastGridSize", "lib_view.grid.last_size" );
616 
617  ret &= fromLegacy<bool>( aCfg, "RescueNeverShow", "system.never_show_rescue_dialog" );
618 
619  // Legacy version stored this setting in eeschema, so move it to common if it exists
620  bool tmp;
621 
622  if( aCfg->Read( "MoveWarpsCursor", &tmp ) )
623  Pgm().GetCommonSettings()->m_Input.warp_mouse_on_move = tmp;
624 
625  COLOR_SETTINGS* cs = Pgm().GetSettingsManager().GetMigratedColorSettings();
626 
627  auto migrateLegacyColor = [&] ( const std::string& aKey, int aLayerId ) {
628  wxString str;
629 
630  if( aCfg->Read( aKey, &str ) )
631  cs->SetColor( aLayerId, COLOR4D( str ) );
632  };
633 
634  migrateLegacyColor( "Color4DBgCanvasEx", LAYER_SCHEMATIC_BACKGROUND );
635  migrateLegacyColor( "Color4DBodyBgEx", LAYER_DEVICE_BACKGROUND );
636  migrateLegacyColor( "Color4DBodyEx", LAYER_DEVICE );
637  migrateLegacyColor( "Color4DBrightenedEx", LAYER_BRIGHTENED );
638  migrateLegacyColor( "Color4DBusEx", LAYER_BUS );
639  migrateLegacyColor( "Color4DConnEx", LAYER_JUNCTION );
640  migrateLegacyColor( "Color4DCursorEx", LAYER_SCHEMATIC_CURSOR );
641  migrateLegacyColor( "Color4DErcEEx", LAYER_ERC_ERR );
642  migrateLegacyColor( "Color4DErcWEx", LAYER_ERC_WARN );
643  migrateLegacyColor( "Color4DFieldEx", LAYER_FIELDS );
644  migrateLegacyColor( "Color4DGLabelEx", LAYER_GLOBLABEL );
645  migrateLegacyColor( "Color4DGridEx", LAYER_SCHEMATIC_GRID );
646  migrateLegacyColor( "Color4DHLabelEx", LAYER_HIERLABEL );
647  migrateLegacyColor( "Color4DHiddenEx", LAYER_HIDDEN );
648  migrateLegacyColor( "Color4DLLabelEx", LAYER_LOCLABEL );
649  migrateLegacyColor( "Color4DNoConnectEx", LAYER_NOCONNECT );
650  migrateLegacyColor( "Color4DNoteEx", LAYER_NOTES );
651  migrateLegacyColor( "Color4DPinEx", LAYER_PIN );
652  migrateLegacyColor( "Color4DPinNameEx", LAYER_PINNAM );
653  migrateLegacyColor( "Color4DPinNumEx", LAYER_PINNUM );
654  migrateLegacyColor( "Color4DReferenceEx", LAYER_REFERENCEPART );
655  migrateLegacyColor( "Color4DShadowEx", LAYER_SELECTION_SHADOWS );
656  migrateLegacyColor( "Color4DSheetEx", LAYER_SHEET );
657  migrateLegacyColor( "Color4DSheetFileNameEx", LAYER_SHEETFILENAME );
658  migrateLegacyColor( "Color4DSheetLabelEx", LAYER_SHEETLABEL );
659  migrateLegacyColor( "Color4DSheetNameEx", LAYER_SHEETNAME );
660  migrateLegacyColor( "Color4DValueEx", LAYER_VALUEPART );
661  migrateLegacyColor( "Color4DWireEx", LAYER_WIRE );
662  migrateLegacyColor( "Color4DWorksheetEx", LAYER_SCHEMATIC_DRAWINGSHEET );
663 
664  Pgm().GetSettingsManager().SaveColorSettings( cs, "schematic" );
665 
666  Set( "appearance.color_theme", cs->GetFilename() );
667 
668  // LibEdit settings were stored with eeschema. If eeschema is the first app to run,
669  // we need to migrate the LibEdit settings here
670 
671  auto libedit = Pgm().GetSettingsManager().GetAppSettings<SYMBOL_EDITOR_SETTINGS>( false );
672  libedit->MigrateFromLegacy( aCfg );
673  libedit->Load();
674 
675  return ret;
676 }
677 
678 
683 class BOM_CFG_PARSER : public DIALOG_BOM_CFG_LEXER
684 {
685  std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS>* m_pluginList;
686 
687 public:
688  BOM_CFG_PARSER( std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS>* aPluginList,
689  const char* aData, const wxString& aSource );
690 
691  void Parse();
692 
693 private:
694  void parseGenerator();
695 };
696 
697 
698 std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS> EESCHEMA_SETTINGS::DefaultBomPlugins()
699 {
701 }
702 
703 
705 {
706  if( !Contains( "bom.plugins" ) )
707  return false;
708 
709  wxString list = Get<wxString>( "bom.plugins" ).value();
710 
711  BOM_CFG_PARSER cfg_parser( &m_BomPanel.plugins, TO_UTF8( list ), wxT( "plugins" ) );
712 
713  try
714  {
715  cfg_parser.Parse();
716  }
717  catch( const IO_ERROR& )
718  {
719  return false;
720  }
721 
722  // Parser will have loaded up our array, let's dump it out to JSON
723  At( "bom.plugins" ) = bomSettingsToJson();
724 
725  return true;
726 }
727 
728 
730 {
731  nlohmann::json js = nlohmann::json::array();
732 
733  for( const BOM_PLUGIN_SETTINGS& plugin : m_BomPanel.plugins )
734  {
735  nlohmann::json pluginJson;
736 
737  pluginJson["name"] = plugin.name.ToUTF8();
738  pluginJson["path"] = plugin.path.ToUTF8();
739  pluginJson["command"] = plugin.command.ToUTF8();
740 
741  js.push_back( pluginJson );
742  }
743 
744  return js;
745 }
746 
747 
748 std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS> EESCHEMA_SETTINGS::bomSettingsFromJson(
749  const nlohmann::json& aObj )
750 {
751  std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS> ret;
752 
753  wxASSERT( aObj.is_array() );
754 
755  for( const nlohmann::json& entry : aObj )
756  {
757  if( entry.empty() || !entry.is_object() )
758  continue;
759 
760  if( !entry.contains( "name" ) || !entry.contains( "path" ) )
761  continue;
762 
763  BOM_PLUGIN_SETTINGS plugin( entry.at( "name" ).get<wxString>(),
764  entry.at( "path" ).get<wxString>() );
765 
766  if( entry.contains( "command" ) )
767  plugin.command = entry.at( "command" ).get<wxString>();
768 
769  ret.emplace_back( plugin );
770  }
771 
772  return ret;
773 }
774 
775 
777 {
778  nlohmann::json js = nlohmann::json::array();
779 
780  for( const NETLIST_PLUGIN_SETTINGS& plugin : m_NetlistPanel.plugins )
781  {
782  nlohmann::json pluginJson;
783 
784  pluginJson["name"] = plugin.name.ToUTF8();
785  pluginJson["path"] = plugin.path.ToUTF8();
786  pluginJson["command"] = plugin.command.ToUTF8();
787 
788  js.push_back( pluginJson );
789  }
790 
791  return js;
792 }
793 
794 
795 std::vector<EESCHEMA_SETTINGS::NETLIST_PLUGIN_SETTINGS> EESCHEMA_SETTINGS::netlistSettingsFromJson(
796  const nlohmann::json& aObj )
797 {
798  std::vector<EESCHEMA_SETTINGS::NETLIST_PLUGIN_SETTINGS> ret;
799 
800  wxASSERT( aObj.is_array() );
801 
802  for( const nlohmann::json& entry : aObj )
803  {
804  if( entry.empty() || !entry.is_object() )
805  continue;
806 
807  if( !entry.contains( "name" ) || !entry.contains( "path" ) )
808  continue;
809 
810  NETLIST_PLUGIN_SETTINGS plugin( entry.at( "name" ).get<wxString>(),
811  entry.at( "path" ).get<wxString>() );
812 
813  if( entry.contains( "command" ) )
814  plugin.command = entry.at( "command" ).get<wxString>();
815 
816  ret.emplace_back( plugin );
817  }
818 
819  return ret;
820 }
821 
822 
823 BOM_CFG_PARSER::BOM_CFG_PARSER( std::vector<EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS>* aPluginList,
824  const char* aLine, const wxString& aSource ) :
825  DIALOG_BOM_CFG_LEXER( aLine, aSource )
826 {
827  wxASSERT( aPluginList );
828  m_pluginList = aPluginList;
829 }
830 
831 
833 {
834  T token;
835 
836  while( ( token = NextTok() ) != T_RIGHT )
837  {
838  if( token == T_EOF)
839  break;
840 
841  if( token == T_LEFT )
842  token = NextTok();
843 
844  if( token == T_plugins )
845  continue;
846 
847  switch( token )
848  {
849  case T_plugin: // Defines a new plugin
850  parseGenerator();
851  break;
852 
853  default:
854 // Unexpected( CurText() );
855  break;
856  }
857  }
858 }
859 
860 
862 {
863  wxString str;
865 
866  NeedSYMBOLorNUMBER();
867  settings.path = FromUTF8();
868 
869  T token;
870 
871  while( ( token = NextTok() ) != T_RIGHT )
872  {
873  if( token == T_EOF)
874  break;
875 
876  switch( token )
877  {
878  case T_LEFT:
879  break;
880 
881  case T_cmd:
882  NeedSYMBOLorNUMBER();
883 
884  settings.command = FromUTF8();
885 
886  NeedRIGHT();
887  break;
888 
889  case T_opts:
890  {
891  NeedSYMBOLorNUMBER();
892 
893  wxString option = FromUTF8();
894 
895  if( option.StartsWith( wxT( "nickname=" ), &str ) )
896  settings.name = str;
897 
898  NeedRIGHT();
899  break;
900  }
901 
902  default:
903  Unexpected( CurText() );
904  break;
905  }
906  }
907 
908  m_pluginList->emplace_back( settings );
909 }
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.
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