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