KiCad PCB EDA Suite
Loading...
Searching...
No Matches
footprint_editor_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 Jon Evans <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
22
25#include <common.h>
26#include <layer_ids.h>
27#include <lset.h>
28#include <pgm_base.h>
29#include <eda_text.h>
30#include <pcb_dimension.h>
33#include <settings/parameters.h>
36#include <base_units.h>
37
38#include <wx/config.h>
39#include <wx/log.h>
40
41
43const int fpEditSchemaVersion = 5;
44
45
48 m_DesignSettings( nullptr, "fpedit.settings" ),
50 m_Display(),
51 m_UserGrid(),
52 m_PolarCoords( false ),
53 m_DisplayInvertXAxis( false ),
54 m_DisplayInvertYAxis( false ),
57 m_AutoConstraints( true ),
59 m_LibWidth( 250 ),
61{
64 m_MagneticItems.graphics = true;
65 m_MagneticItems.allLayers = false;
66
67 m_AuiPanels.appearance_panel_tab = 0;
68 m_AuiPanels.right_panel_width = -1;
69 m_AuiPanels.show_layer_manager = true;
70
71 m_params.emplace_back( new PARAM<int>( "window.lib_width",
72 &m_LibWidth, 250 ) );
73
74 m_params.emplace_back( new PARAM<bool>( "aui.show_layer_manager",
75 &m_AuiPanels.show_layer_manager, true ) );
76
77 m_params.emplace_back( new PARAM<int>( "aui.right_panel_width",
78 &m_AuiPanels.right_panel_width, -1 ) );
79
80 m_params.emplace_back( new PARAM<int>( "aui.appearance_panel_tab",
81 &m_AuiPanels.appearance_panel_tab, 0, 0, 2 ) );
82
83 m_params.emplace_back( new PARAM<int>( "aui.properties_panel_width",
84 &m_AuiPanels.properties_panel_width, -1 ) );
85
86 m_params.emplace_back( new PARAM<float>( "aui.properties_splitter_proportion",
87 &m_AuiPanels.properties_splitter, 0.5f ) );
88
89 m_params.emplace_back( new PARAM<bool>( "aui.show_properties",
90 &m_AuiPanels.show_properties, true ) );
91
92 m_params.emplace_back( new PARAM<int>( "library.sort_mode",
93 &m_LibrarySortMode, 0 ) );
94
95 m_params.emplace_back( new PARAM<wxString>( "system.last_import_export_path",
96 &m_LastExportPath, "" ) );
97
98 m_params.emplace_back( new PARAM<bool>( "pcb_display.graphics_fill",
99 &m_ViewersDisplay.m_DisplayGraphicsFill, true ) );
100
101 m_params.emplace_back( new PARAM<bool>( "pcb_display.text_fill",
102 &m_ViewersDisplay.m_DisplayTextFill, true ) );
103
104 m_params.emplace_back( new PARAM<bool>( "pcb_display.pad_fill",
105 &m_ViewersDisplay.m_DisplayPadFill, true ) );
106
107 m_params.emplace_back( new PARAM<bool>( "pcb_display.pad_numbers",
108 &m_ViewersDisplay.m_DisplayPadNumbers, true ) );
109
110 m_params.emplace_back( new PARAM<int>( "editing.magnetic_pads",
111 reinterpret_cast<int*>( &m_MagneticItems.pads ),
112 static_cast<int>( MAGNETIC_OPTIONS::CAPTURE_ALWAYS ) ) );
113
114 m_params.emplace_back( new PARAM<bool>( "editing.magnetic_graphics",
115 &m_MagneticItems.graphics, true ) );
116
117 m_params.emplace_back( new PARAM<bool>( "editing.magnetic_all_layers",
118 &m_MagneticItems.allLayers, false ) );
119
121
122 m_params.emplace_back( new PARAM<bool>( "editing.polar_coords",
123 &m_PolarCoords, false ) );
124
125 m_params.emplace_back( new PARAM<bool>( "origin_invert_x_axis",
126 &m_DisplayInvertXAxis, false ) );
127
128 m_params.emplace_back( new PARAM<bool>( "origin_invert_y_axis",
129 &m_DisplayInvertYAxis, false ) );
130
131 m_params.emplace_back( new PARAM_LAMBDA<int>( "editing.rotation_angle",
132 [this] () -> int
133 {
134 return m_RotationAngle.AsTenthsOfADegree();
135 },
136 [this] ( int aVal )
137 {
138 if( aVal )
140 },
141 900 ) );
142
143 m_params.emplace_back( new PARAM<int>( "editing.fp_angle_snap_mode",
144 reinterpret_cast<int*>( &m_AngleSnapMode ),
145 static_cast<int>( LEADER_MODE::DEG45 ) ) );
146
147 m_params.emplace_back( new PARAM<bool>( "editing.auto_constraints", &m_AutoConstraints, true ) );
148
149 m_params.emplace_back( new PARAM_LAYER_PRESET( "pcb_display.layer_presets", &m_LayerPresets ) );
150
151 m_params.emplace_back( new PARAM<wxString>( "pcb_display.active_layer_preset",
152 &m_ActiveLayerPreset, "" ) );
153
154 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "tabs.open",
155 [&]() -> nlohmann::json
156 {
157 nlohmann::json js = nlohmann::json::array();
158
159 for( const OPEN_TAB& tab : m_OpenTabs )
160 {
161 js.push_back( nlohmann::json( { { "lib", tab.m_lib.ToUTF8() },
162 { "fp_name", tab.m_fpName.ToUTF8() },
163 { "preview", tab.m_preview } } ) );
164 }
165
166 return js;
167 },
168 [&]( const nlohmann::json& aObj )
169 {
170 m_OpenTabs.clear();
171
172 if( !aObj.is_array() )
173 return;
174
175 for( const nlohmann::json& entry : aObj )
176 {
177 if( !entry.is_object() || !entry.contains( "lib" ) || !entry.contains( "fp_name" ) )
178 continue;
179
180 OPEN_TAB tab;
181 tab.m_lib = entry.at( "lib" ).get<wxString>();
182 tab.m_fpName = entry.at( "fp_name" ).get<wxString>();
183
184 // Older configs predate the preview flag and default to a permanent tab.
185 if( entry.contains( "preview" ) )
186 tab.m_preview = entry.at( "preview" ).get<bool>();
187
188 m_OpenTabs.push_back( std::move( tab ) );
189 }
190 },
191 nlohmann::json::array() ) );
192
193 m_params.emplace_back( new PARAM<wxString>( "tabs.active",
194 &m_ActiveTab, "" ) );
195
196 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>(
197 "design_settings.default_footprint_text_items",
198 [&] () -> nlohmann::json
199 {
200 nlohmann::json js = nlohmann::json::array();
201
202 for( const TEXT_ITEM_INFO& item : m_DesignSettings.m_DefaultFPTextItems )
203 {
204 js.push_back( nlohmann::json( { item.m_Text.ToUTF8(),
205 item.m_Visible,
206 LSET::Name( item.m_Layer ) } ) );
207 }
208
209 return js;
210 },
211 [&] ( const nlohmann::json& aObj )
212 {
213 m_DesignSettings.m_DefaultFPTextItems.clear();
214
215 if( !aObj.is_array() )
216 return;
217
218 for( const nlohmann::json& entry : aObj )
219 {
220 if( entry.empty() || !entry.is_array() )
221 continue;
222
223 TEXT_ITEM_INFO textInfo( wxT( "" ), true, F_SilkS );
224
225 textInfo.m_Text = entry.at(0).get<wxString>();
226 textInfo.m_Visible = entry.at(1).get<bool>();
227 wxString layerName = entry.at(2).get<wxString>();
228 int candidateLayer = LSET::NameToLayer( layerName );
229 textInfo.m_Layer = candidateLayer >= 0
230 ? static_cast<PCB_LAYER_ID>(candidateLayer)
231 : F_SilkS;
232
233 m_DesignSettings.m_DefaultFPTextItems.push_back( std::move( textInfo ) );
234 }
235 },
236 nlohmann::json::array( {
237 { "REF**", true, LSET::Name( F_SilkS ) },
238 { "", true, LSET::Name( F_Fab ) },
239 { "${REFERENCE}", true, LSET::Name( F_Fab ) }
240 } ) ) );
241
242 m_params.emplace_back( new PARAM_MAP<wxString>( "design_settings.default_footprint_layer_names",
243 &m_DesignSettings.m_UserLayerNames, {} ) );
244
245 m_params.emplace_back( new PARAM_LAMBDA<int>( "design_settings.user_layer_count",
246 [this]() { return m_DesignSettings.GetUserDefinedLayerCount(); },
247 [this]( int aCount ) { m_DesignSettings.SetUserDefinedLayerCount( aCount ); },
248 4 ) );
249
250 int minTextSize = pcbIUScale.mmToIU( TEXT_MIN_SIZE_MM );
251 int maxTextSize = pcbIUScale.mmToIU( TEXT_MAX_SIZE_MM );
252 int minStroke = 1;
253 int maxStroke = pcbIUScale.mmToIU( 100 );
254
255 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.silk_line_width",
256 &m_DesignSettings.m_LineThickness[ LAYER_CLASS_SILK ],
257 pcbIUScale.mmToIU( DEFAULT_SILK_LINE_WIDTH ), minStroke, maxStroke, pcbIUScale.MM_PER_IU ) );
258
259 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.silk_text_size_h",
260 &m_DesignSettings.m_TextSize[ LAYER_CLASS_SILK ].x,
261 pcbIUScale.mmToIU( DEFAULT_SILK_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
262
263 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.silk_text_size_v",
264 &m_DesignSettings.m_TextSize[ LAYER_CLASS_SILK ].y,
265 pcbIUScale.mmToIU( DEFAULT_SILK_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
266
267 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.silk_text_thickness",
268 &m_DesignSettings.m_TextThickness[ LAYER_CLASS_SILK ],
269 pcbIUScale.mmToIU( DEFAULT_SILK_TEXT_WIDTH ), 1, maxTextSize, pcbIUScale.MM_PER_IU ) );
270
271 m_params.emplace_back( new PARAM<bool>( "design_settings.silk_text_italic",
272 &m_DesignSettings.m_TextItalic[ LAYER_CLASS_SILK ], false ) );
273
274 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.copper_line_width",
275 &m_DesignSettings.m_LineThickness[ LAYER_CLASS_COPPER ],
276 pcbIUScale.mmToIU( DEFAULT_COPPER_LINE_WIDTH ), minStroke, maxStroke, pcbIUScale.MM_PER_IU ) );
277
278 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.copper_text_size_h",
279 &m_DesignSettings.m_TextSize[ LAYER_CLASS_COPPER ].x,
280 pcbIUScale.mmToIU( DEFAULT_COPPER_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
281
282 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.copper_text_size_v",
283 &m_DesignSettings.m_TextSize[ LAYER_CLASS_COPPER ].y,
284 pcbIUScale.mmToIU( DEFAULT_COPPER_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
285
286 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.copper_text_thickness",
287 &m_DesignSettings.m_TextThickness[ LAYER_CLASS_COPPER ],
288 pcbIUScale.mmToIU( DEFAULT_COPPER_TEXT_WIDTH ), minStroke, maxStroke, pcbIUScale.MM_PER_IU ) );
289
290 m_params.emplace_back( new PARAM<bool>( "design_settings.copper_text_italic",
291 &m_DesignSettings.m_TextItalic[ LAYER_CLASS_COPPER ], false ) );
292
293 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.edge_line_width",
294 &m_DesignSettings.m_LineThickness[ LAYER_CLASS_EDGES ],
295 pcbIUScale.mmToIU( DEFAULT_EDGE_WIDTH ), minStroke, maxStroke, pcbIUScale.MM_PER_IU ) );
296
297 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.courtyard_line_width",
298 &m_DesignSettings.m_LineThickness[ LAYER_CLASS_COURTYARD ],
299 pcbIUScale.mmToIU( DEFAULT_COURTYARD_WIDTH ), minStroke, maxStroke, pcbIUScale.MM_PER_IU ) );
300
301 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.fab_line_width",
302 &m_DesignSettings.m_LineThickness[ LAYER_CLASS_FAB ],
303 pcbIUScale.mmToIU( DEFAULT_LINE_WIDTH ), minStroke, maxStroke, pcbIUScale.MM_PER_IU ) );
304
305 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.fab_text_size_h",
306 &m_DesignSettings.m_TextSize[ LAYER_CLASS_FAB ].x,
307 pcbIUScale.mmToIU( DEFAULT_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
308
309 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.fab_text_size_v",
310 &m_DesignSettings.m_TextSize[ LAYER_CLASS_FAB ].y,
311 pcbIUScale.mmToIU( DEFAULT_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
312
313 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.fab_text_thickness",
314 &m_DesignSettings.m_TextThickness[ LAYER_CLASS_FAB ],
315 pcbIUScale.mmToIU( DEFAULT_TEXT_WIDTH ), 1, maxTextSize, pcbIUScale.MM_PER_IU ) );
316
317 m_params.emplace_back( new PARAM<bool>( "design_settings.fab_text_italic",
318 &m_DesignSettings.m_TextItalic[ LAYER_CLASS_FAB ], false ) );
319
320 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.others_line_width",
321 &m_DesignSettings.m_LineThickness[ LAYER_CLASS_OTHERS ],
322 pcbIUScale.mmToIU( DEFAULT_LINE_WIDTH ), minStroke, maxStroke, pcbIUScale.MM_PER_IU ) );
323
324 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.others_text_size_h",
325 &m_DesignSettings.m_TextSize[ LAYER_CLASS_OTHERS ].x,
326 pcbIUScale.mmToIU( DEFAULT_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
327
328 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.others_text_size_v",
329 &m_DesignSettings.m_TextSize[ LAYER_CLASS_OTHERS ].y,
330 pcbIUScale.mmToIU( DEFAULT_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
331
332 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.others_text_thickness",
333 &m_DesignSettings.m_TextThickness[ LAYER_CLASS_OTHERS ],
334 pcbIUScale.mmToIU( DEFAULT_TEXT_WIDTH ), 1, maxTextSize, pcbIUScale.MM_PER_IU ) );
335
336 m_params.emplace_back( new PARAM<bool>( "design_settings.others_text_italic",
337 &m_DesignSettings.m_TextItalic[ LAYER_CLASS_OTHERS ], false ) );
338
339
340 // ---------------------------------------------------------------------------------------------
341 // Dimension settings
342
343 m_params.emplace_back( new PARAM_ENUM<DIM_UNITS_MODE>( "design_settings.dimensions.units",
346
347 m_params.emplace_back( new PARAM_ENUM<DIM_PRECISION>( "design_settings.dimensions.precision",
349
350 m_params.emplace_back( new PARAM_ENUM<DIM_UNITS_FORMAT>( "design_settings.dimensions.units_format",
353
354 m_params.emplace_back( new PARAM<bool>( "design_settings.dimensions.suppress_zeroes",
355 &m_DesignSettings.m_DimensionSuppressZeroes, true ) );
356
357 // NOTE: excluding DIM_TEXT_POSITION::MANUAL from the valid range here
358 m_params.emplace_back( new PARAM_ENUM<DIM_TEXT_POSITION>( "design_settings.dimensions.text_position",
361
362 m_params.emplace_back( new PARAM<bool>( "design_settings.dimensions.keep_text_aligned",
363 &m_DesignSettings.m_DimensionKeepTextAligned, true ) );
364
365 m_params.emplace_back( new PARAM<int>( "design_settings.dimensions.arrow_length",
366 &m_DesignSettings.m_DimensionArrowLength,
368
369 m_params.emplace_back( new PARAM<int>( "design_settings.dimensions.extension_offset",
370 &m_DesignSettings.m_DimensionExtensionOffset,
372
373 // ---------------------------------------------------------------------------------------------
374
375 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "editing.selection_filter",
376 [&]() -> nlohmann::json
377 {
378 nlohmann::json ret;
379
380 ret["lockedItems"] = m_SelectionFilter.lockedItems;
381 ret["footprints"] = m_SelectionFilter.footprints;
382 ret["text"] = m_SelectionFilter.text;
383 ret["tracks"] = m_SelectionFilter.tracks;
384 ret["vias"] = m_SelectionFilter.vias;
385 ret["pads"] = m_SelectionFilter.pads;
386 ret["graphics"] = m_SelectionFilter.graphics;
387 ret["zones"] = m_SelectionFilter.zones;
388 ret["keepouts"] = m_SelectionFilter.keepouts;
389 ret["dimensions"] = m_SelectionFilter.dimensions;
390 ret["points"] = m_SelectionFilter.points;
391 ret["otherItems"] = m_SelectionFilter.otherItems;
392
393 return ret;
394 },
395 [&]( const nlohmann::json& aVal )
396 {
397 if( aVal.empty() || !aVal.is_object() )
398 return;
399
400 SetIfPresent( aVal, "lockedItems", m_SelectionFilter.lockedItems );
401 SetIfPresent( aVal, "footprints", m_SelectionFilter.footprints );
402 SetIfPresent( aVal, "text", m_SelectionFilter.text );
403 SetIfPresent( aVal, "tracks", m_SelectionFilter.tracks );
404 SetIfPresent( aVal, "vias", m_SelectionFilter.vias );
405 SetIfPresent( aVal, "pads", m_SelectionFilter.pads );
406 SetIfPresent( aVal, "graphics", m_SelectionFilter.graphics );
407 SetIfPresent( aVal, "zones", m_SelectionFilter.zones );
408 SetIfPresent( aVal, "keepouts", m_SelectionFilter.keepouts );
409 SetIfPresent( aVal, "dimensions", m_SelectionFilter.dimensions );
410 SetIfPresent( aVal, "points", m_SelectionFilter.points );
411 SetIfPresent( aVal, "otherItems", m_SelectionFilter.otherItems );
412 },
413 {
414 { "lockedItems", false },
415 { "footprints", true },
416 { "text", true },
417 { "tracks", true },
418 { "vias", true },
419 { "pads", true },
420 { "graphics", true },
421 { "zones", true },
422 { "keepouts", true },
423 { "dimensions", true },
424 { "points", true },
425 { "otherItems", true }
426 } ) );
427
428 registerMigration( 0, 1, std::bind( &FOOTPRINT_EDITOR_SETTINGS::migrateSchema0to1, this ) );
429
430 registerMigration( 1, 2,
431 [&]() -> bool
432 {
433 // This is actually a migration for APP_SETTINGS_BASE::m_LibTree
434 return migrateLibTreeWidth();
435 } );
436
437 registerMigration( 2, 3, std::bind( &FOOTPRINT_EDITOR_SETTINGS::migrateSchema2To3, this ) );
438 registerMigration( 3, 4, std::bind( &FOOTPRINT_EDITOR_SETTINGS::migrateSchema3To4, this ) );
439 registerMigration( 4, 5, std::bind( &FOOTPRINT_EDITOR_SETTINGS::migrateSchema4To5, this ) );
440}
441
442
444{
445 bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
446
447 //
448 // NOTE: there's no value in line-wrapping these; it just makes the table unreadable.
449 //
450 ret &= fromLegacy<int>( aCfg, "ModeditLibWidth", "window.lib_width" );
451 ret &= fromLegacyString( aCfg, "import_last_path", "system.last_import_export_path" );
452
453 ret &= fromLegacy<int>( aCfg, "FpEditorMagneticPads", "editing.magnetic_pads" );
454 ret &= fromLegacy<bool>( aCfg, "FpEditorDisplayPolarCoords", "editing.polar_coords" );
455 ret &= fromLegacy<int>( aCfg, "FpEditorUse45DegreeGraphicSegments", "editing.use_45_degree_graphic_segments" );
456
457 ret &= fromLegacy<bool>( aCfg, "FpEditorGraphicLinesDisplayMode", "pcb_display.graphic_items_fill" );
458 ret &= fromLegacy<bool>( aCfg, "FpEditorPadDisplayMode", "pcb_display.pad_fill" );
459 ret &= fromLegacy<bool>( aCfg, "FpEditorTextsDisplayMode", "pcb_display.footprint_text" );
460
461 ret &= fromLegacy<double>( aCfg, "FpEditorSilkLineWidth", "design_settings.silk_line_width" );
462 ret &= fromLegacy<double>( aCfg, "FpEditorSilkTextSizeH", "design_settings.silk_text_size_h" );
463 ret &= fromLegacy<double>( aCfg, "FpEditorSilkTextSizeV", "design_settings.silk_text_size_v" );
464 ret &= fromLegacy<double>( aCfg, "FpEditorSilkTextThickness", "design_settings.silk_text_thickness" );
465 ret &= fromLegacy<bool>( aCfg, "FpEditorSilkTextItalic", "design_settings.silk_text_italic" );
466 ret &= fromLegacy<double>( aCfg, "FpEditorCopperLineWidth", "design_settings.copper_line_width" );
467 ret &= fromLegacy<double>( aCfg, "FpEditorCopperTextSizeH", "design_settings.copper_text_size_h" );
468 ret &= fromLegacy<double>( aCfg, "FpEditorCopperTextSizeV", "design_settings.copper_text_size_v" );
469 ret &= fromLegacy<double>( aCfg, "FpEditorCopperTextThickness", "design_settings.copper_text_thickness" );
470 ret &= fromLegacy<bool>( aCfg, "FpEditorCopperTextItalic", "design_settings.copper_text_italic" );
471 ret &= fromLegacy<double>( aCfg, "FpEditorEdgeCutLineWidth", "design_settings.edge_line_width" );
472 ret &= fromLegacy<double>( aCfg, "FpEditorCourtyardLineWidth", "design_settings.courtyard_line_width" );
473 ret &= fromLegacy<double>( aCfg, "FpEditorOthersLineWidth", "design_settings.others_line_width" );
474 ret &= fromLegacy<double>( aCfg, "FpEditorOthersTextSizeH", "design_settings.others_text_size_h" );
475 ret &= fromLegacy<double>( aCfg, "FpEditorOthersTextSizeV", "design_settings.others_text_size_v" );
476 ret &= fromLegacy<double>( aCfg, "FpEditorOthersTextThickness", "design_settings.others_text_thickness" );
477 ret &= fromLegacy<bool>( aCfg, "FpEditorOthersTextItalic", "design_settings.others_text_italic" );
478
479 nlohmann::json textItems = nlohmann::json::array( {
480 { "REF**", true, F_SilkS },
481 { "", true, F_Fab }
482 } );
483
484 Set( "design_settings.default_footprint_text_items", std::move( textItems ) );
485
486 ret &= fromLegacyString( aCfg, "FpEditorRefDefaultText", "design_settings.default_footprint_text_items.0.0" );
487 ret &= fromLegacy<bool>( aCfg, "FpEditorRefDefaultVisibility", "design_settings.default_footprint_text_items.0.1" );
488 ret &= fromLegacy<int>( aCfg, "FpEditorRefDefaultLayer", "design_settings.default_footprint_text_items.0.2" );
489 ret &= fromLegacyString( aCfg, "FpEditorValueDefaultText", "design_settings.default_footprint_text_items.1.0" );
490 ret &= fromLegacy<bool>( aCfg, "FpEditorValueDefaultVisibility", "design_settings.default_footprint_text_items.1.1" );
491 ret &= fromLegacy<int>( aCfg, "FpEditorValueDefaultLayer", "design_settings.default_footprint_text_items.1.2" );
492
493
494 std::string f = "ModEdit";
495
496 // Migrate color settings that were stored in the pcbnew config file
497 // We create a copy of the user scheme for the footprint editor context
498
500 COLOR_SETTINGS* cs = manager.AddNewColorSettings( "user_footprints" );
501
502 cs->SetName( wxT( "User (Footprints)" ) );
503 manager.Save( cs );
504
505 auto migrateLegacyColor = [&] ( const std::string& aKey, int aLayerId )
506 {
507 wxString str;
508
509 if( aCfg->Read( aKey, &str ) )
510 cs->SetColor( aLayerId, COLOR4D( str ) );
511 };
512
513 for( int i = 0; i < PCB_LAYER_ID_COUNT; ++i )
514 {
515 wxString layer = LSET::Name( PCB_LAYER_ID( i ) );
516 migrateLegacyColor( f + "Color4DPCBLayer_" + layer.ToStdString(), PCB_LAYER_ID( i ) );
517 }
518
519 migrateLegacyColor( f + "Color4DAnchorEx", LAYER_ANCHOR );
520 migrateLegacyColor( f + "Color4DAuxItems", LAYER_AUX_ITEMS );
521 migrateLegacyColor( f + "Color4DGrid", LAYER_GRID );
522 migrateLegacyColor( f + "Color4DNonPlatedEx", LAYER_NON_PLATEDHOLES );
523 migrateLegacyColor( f + "Color4DPCBBackground", LAYER_PCB_BACKGROUND );
524 migrateLegacyColor( f + "Color4DPCBCursor", LAYER_CURSOR );
525 migrateLegacyColor( f + "Color4DRatsEx", LAYER_RATSNEST );
526 migrateLegacyColor( f + "Color4DViaBBlindEx", LAYER_VIA_BLIND );
527 migrateLegacyColor( f + "Color4DViaBBlindEx", LAYER_VIA_BURIED );
528 migrateLegacyColor( f + "Color4DViaMicroEx", LAYER_VIA_MICROVIA );
529 migrateLegacyColor( f + "Color4DViaThruEx", LAYER_VIA_THROUGH );
530 migrateLegacyColor( f + "Color4DWorksheet", LAYER_DRAWINGSHEET );
531
532 manager.SaveColorSettings( cs, "board" );
533
534 ( *m_internals )[m_internals->PointerFromString( "appearance.color_theme" )] = "user_footprints";
535
536 double x = 0, y = 0;
537 f = "ModEditFrame";
538
539 if( aCfg->Read( f + "PcbUserGrid_X", &x ) && aCfg->Read( f + "PcbUserGrid_Y", &y ) )
540 {
541 EDA_UNITS u = static_cast<EDA_UNITS>( aCfg->ReadLong( f + "PcbUserGrid_Unit",
542 static_cast<long>( EDA_UNITS::INCH ) ) );
543
544 // Convert to internal units
547
548 Set( "window.grid.user_grid_x", EDA_UNIT_UTILS::UI::StringFromValue( pcbIUScale, u, x ) );
549 Set( "window.grid.user_grid_y", EDA_UNIT_UTILS::UI::StringFromValue( pcbIUScale, u, y ) );
550 }
551
552 return ret;
553}
554
555
557{
564
565 if( !m_manager )
566 {
567 wxLogTrace( traceSettings,
568 wxT( "Error: FOOTPRINT_EDITOR_SETTINGS migration cannot run unmanaged!" ) );
569 return false;
570 }
571
572 std::string theme_ptr( "appearance.color_theme" );
573
574 if( !Contains( theme_ptr ) )
575 return true;
576
577 wxString selected = At( theme_ptr ).get<wxString>();
578 wxString search = selected + wxT( "_footprints" );
579
580 for( COLOR_SETTINGS* settings : Pgm().GetSettingsManager().GetColorSettingsList() )
581 {
582 if( settings->GetFilename() == search )
583 {
584 wxLogTrace( traceSettings, wxT( "Updating footprint editor theme from %s to %s" ),
585 selected, search );
586 Set( theme_ptr, search );
587 return true;
588 }
589 }
590
591 return true;
592}
593
594
600{
601 auto p( "/pcb_display/layer_presets"_json_pointer );
602
603 if( !m_internals->contains( p ) || !m_internals->at( p ).is_array() )
604 return true;
605
606 nlohmann::json& presets = m_internals->at( p );
607
608 for( nlohmann::json& entry : presets )
610
611 return true;
612}
613
614
619{
620 auto p( "/pcb_display/layer_presets"_json_pointer );
621
622 if( !m_internals->contains( p ) || !m_internals->at( p ).is_array() )
623 return true;
624
625 nlohmann::json& presets = m_internals->at( p );
626
627 for( nlohmann::json& entry : presets )
629
630 return true;
631}
632
633
638{
639 auto p( "/design_settings/default_footprint_text_items"_json_pointer );
640
641 if( !m_internals->contains( p ) || !m_internals->at( p ).is_array() )
642 return true;
643
644 nlohmann::json& defaults = m_internals->at( p );
645
646 bool reset = false;
647
648 for( nlohmann::json& entry : defaults )
649 {
650 TEXT_ITEM_INFO textInfo( wxT( "" ), true, F_SilkS );
651
652 textInfo.m_Text = entry.at(0).get<wxString>();
653 textInfo.m_Visible = entry.at(1).get<bool>();
654 textInfo.m_Layer = static_cast<PCB_LAYER_ID>( entry.at(2).get<int>() );
655
656 if( textInfo.m_Layer == Rescue || textInfo.m_Layer >= User_5 )
657 {
658 // KiCad pre-9.0 nightlies would write buggy preferences out with invalid layers.
659 // If we detect that, reset to defaults
660 reset = true;
661 }
662 else
663 {
664 // Coming from 8.0 or earlier, just migrate to named layers
665 entry.at(2) = LSET::Name( textInfo.m_Layer );
666 }
667 }
668
669 if( reset )
670 {
671 defaults = nlohmann::json::array( {
672 { "REF**", true, LSET::Name( F_SilkS ) },
673 { "", true, LSET::Name( F_Fab ) },
674 { "${REFERENCE}", true, LSET::Name( F_Fab ) }
675 } );
676 }
677
678 return true;
679}
ARC_EDIT_MODE
Settings for arc editing.
@ KEEP_CENTER_ADJUST_ANGLE_RADIUS
When editing endpoints, the angle and radius are adjusted.
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
@ LAYER_CLASS_OTHERS
@ LAYER_CLASS_FAB
@ LAYER_CLASS_COURTYARD
@ LAYER_CLASS_SILK
@ LAYER_CLASS_COPPER
@ LAYER_CLASS_EDGES
#define DEFAULT_TEXT_WIDTH
#define DEFAULT_COPPER_TEXT_WIDTH
#define DEFAULT_DIMENSION_EXTENSION_OFFSET
#define DEFAULT_DIMENSION_ARROW_LENGTH
#define DEFAULT_SILK_TEXT_SIZE
#define DEFAULT_COPPER_LINE_WIDTH
#define DEFAULT_SILK_LINE_WIDTH
#define DEFAULT_SILK_TEXT_WIDTH
#define DEFAULT_EDGE_WIDTH
#define DEFAULT_COPPER_TEXT_SIZE
#define DEFAULT_LINE_WIDTH
#define DEFAULT_COURTYARD_WIDTH
virtual bool MigrateFromLegacy(wxConfigBase *aCfg) 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...
void SetName(const wxString &aName)
void SetColor(int aLayer, const COLOR4D &aColor)
bool migrateSchema3To4()
Schema version 4: move layer presets to use named render layers.
BOARD_DESIGN_SETTINGS m_DesignSettings
Only some of these settings are actually used for footprint editing.
bool migrateSchema2To3()
Schema version 2: Bump for KiCad 9 layer numbering changes Migrate layer presets to use new enum valu...
wxString m_ActiveTab
Tab key ("lib:fpName") of the tab that was active when the editor last closed.
std::vector< LAYER_PRESET > m_LayerPresets
bool migrateSchema4To5()
Schema version 5: move text defaults to used named layers.
virtual bool MigrateFromLegacy(wxConfigBase *aLegacyConfig) override
Migrates from wxConfig to JSON-based configuration.
SNAP_INFERENCE_SETTINGS m_SnapInference
bool fromLegacyString(wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
Translates a legacy wxConfig string value to a given JSON pointer value.
bool fromLegacy(wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
Translates a legacy wxConfig value to a given JSON pointer value.
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...
SETTINGS_MANAGER * m_manager
A pointer to the settings manager managing this file (may be null)
bool Contains(const std::string &aPath) const
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
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::unique_ptr< JSON_SETTINGS_INTERNALS > m_internals
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
static int NameToLayer(wxString &aName)
Return the layer number from a layer name.
Definition lset.cpp:113
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition lset.cpp:184
Stores an enum as an integer.
Definition parameters.h:232
Like a normal param, but with custom getter and setter functions.
Definition parameters.h:299
static void MigrateToV9Layers(nlohmann::json &aJson)
static void MigrateToNamedRenderLayers(nlohmann::json &aJson)
Represents a map of <std::string, Value>.
Definition parameters.h:752
Represents a parameter that has a scaling factor between the value in the file and the value used int...
Definition parameters.h:410
PCB_VIEWERS_SETTINGS_BASE(const std::string &aFilename, int aSchemaVersion)
VIEWERS_DISPLAY_OPTIONS m_ViewersDisplay
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:124
void SaveColorSettings(COLOR_SETTINGS *aSettings, const std::string &aNamespace="")
Safely save a COLOR_SETTINGS to disk, preserving any changes outside the given namespace.
COLOR_SETTINGS * AddNewColorSettings(const wxString &aFilename)
Register a new color settings object with the given filename.
The common library.
#define DEFAULT_TEXT_SIZE
Ratio of the font height to the baseline of the text above the wire.
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:413
@ TENTHS_OF_A_DEGREE_T
Definition eda_angle.h:30
#define TEXT_MIN_SIZE_MM
Minimum text size (1 micron).
Definition eda_text.h:56
#define TEXT_MAX_SIZE_MM
Maximum text size in mm (~10 inches)
Definition eda_text.h:57
EDA_UNITS
Definition eda_units.h:44
const int fpEditSchemaVersion
! Update the schema version whenever a migration is required
LEADER_MODE
The kind of the leader line.
@ DEG45
45 Degree only
#define traceSettings
@ LAYER_GRID
Definition layer_ids.h:250
@ LAYER_NON_PLATEDHOLES
Draw usual through hole vias.
Definition layer_ids.h:235
@ LAYER_DRAWINGSHEET
Sheet frame and title block.
Definition layer_ids.h:274
@ LAYER_PCB_BACKGROUND
PCB background color.
Definition layer_ids.h:277
@ LAYER_CURSOR
PCB cursor.
Definition layer_ids.h:278
@ LAYER_AUX_ITEMS
Auxiliary items (guides, rule, etc).
Definition layer_ids.h:279
@ LAYER_RATSNEST
Definition layer_ids.h:249
@ LAYER_ANCHOR
Anchor of items having an anchor point (texts, footprints).
Definition layer_ids.h:244
@ LAYER_VIA_BURIED
Draw blind vias.
Definition layer_ids.h:231
@ LAYER_VIA_BLIND
Draw micro vias.
Definition layer_ids.h:230
@ LAYER_VIA_MICROVIA
Definition layer_ids.h:229
@ LAYER_VIA_THROUGH
Draw buried vias.
Definition layer_ids.h:232
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ User_5
Definition layer_ids.h:124
@ F_Fab
Definition layer_ids.h:115
@ F_SilkS
Definition layer_ids.h:96
@ Rescue
Definition layer_ids.h:117
@ PCB_LAYER_ID_COUNT
Definition layer_ids.h:167
KICOMMON_API double FromUserUnit(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnit, double aValue)
Return in internal units the value aValue given in a real unit such as "in", "mm",...
KICOMMON_API wxString StringFromValue(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, double aValue, bool aAddUnitsText=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Return the string from aValue according to aUnits (inch, mm ...) for display.
@ OUTSIDE
Text appears outside the dimension line (default)
@ INLINE
Text appears in line with the dimension line.
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
void AddSnapInferenceParams(std::vector< PARAM_BASE * > &aParams, SNAP_INFERENCE_SETTINGS &aSettings)
Register the snap inference parameters.
One open tab persisted across sessions.