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