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 along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
22
23#include <common.h>
24#include <layer_ids.h>
25#include <lset.h>
26#include <pgm_base.h>
27#include <eda_text.h>
28#include <pcb_dimension.h>
31#include <settings/parameters.h>
33#include <base_units.h>
34
35#include <wx/config.h>
36#include <wx/log.h>
37
38
40const int fpEditSchemaVersion = 5;
41
42
45 m_DesignSettings( nullptr, "fpedit.settings" ),
47 m_Display(),
48 m_UserGrid(),
49 m_PolarCoords( false ),
50 m_DisplayInvertXAxis( false ),
51 m_DisplayInvertYAxis( false ),
55 m_LibWidth( 250 ),
57{
60 m_MagneticItems.graphics = true;
61 m_MagneticItems.allLayers = false;
62
63 m_AuiPanels.appearance_panel_tab = 0;
64 m_AuiPanels.right_panel_width = -1;
65 m_AuiPanels.show_layer_manager = true;
66
67 m_params.emplace_back( new PARAM<int>( "window.lib_width",
68 &m_LibWidth, 250 ) );
69
70 m_params.emplace_back( new PARAM<bool>( "aui.show_layer_manager",
71 &m_AuiPanels.show_layer_manager, true ) );
72
73 m_params.emplace_back( new PARAM<int>( "aui.right_panel_width",
74 &m_AuiPanels.right_panel_width, -1 ) );
75
76 m_params.emplace_back( new PARAM<int>( "aui.appearance_panel_tab",
77 &m_AuiPanels.appearance_panel_tab, 0, 0, 2 ) );
78
79 m_params.emplace_back( new PARAM<int>( "aui.properties_panel_width",
80 &m_AuiPanels.properties_panel_width, -1 ) );
81
82 m_params.emplace_back( new PARAM<float>( "aui.properties_splitter_proportion",
83 &m_AuiPanels.properties_splitter, 0.5f ) );
84
85 m_params.emplace_back( new PARAM<bool>( "aui.show_properties",
86 &m_AuiPanels.show_properties, false ) );
87
88 m_params.emplace_back( new PARAM<int>( "library.sort_mode",
89 &m_LibrarySortMode, 0 ) );
90
91 m_params.emplace_back( new PARAM<wxString>( "system.last_import_export_path",
92 &m_LastExportPath, "" ) );
93
94 m_params.emplace_back( new PARAM<bool>( "pcb_display.graphics_fill",
95 &m_ViewersDisplay.m_DisplayGraphicsFill, true ) );
96
97 m_params.emplace_back( new PARAM<bool>( "pcb_display.text_fill",
98 &m_ViewersDisplay.m_DisplayTextFill, true ) );
99
100 m_params.emplace_back( new PARAM<bool>( "pcb_display.pad_fill",
101 &m_ViewersDisplay.m_DisplayPadFill, true ) );
102
103 m_params.emplace_back( new PARAM<bool>( "pcb_display.pad_numbers",
104 &m_ViewersDisplay.m_DisplayPadNumbers, true ) );
105
106 m_params.emplace_back( new PARAM<int>( "editing.magnetic_pads",
107 reinterpret_cast<int*>( &m_MagneticItems.pads ),
108 static_cast<int>( MAGNETIC_OPTIONS::CAPTURE_ALWAYS ) ) );
109
110 m_params.emplace_back( new PARAM<bool>( "editing.magnetic_graphics",
111 &m_MagneticItems.graphics, true ) );
112
113 m_params.emplace_back( new PARAM<bool>( "editing.magnetic_all_layers",
114 &m_MagneticItems.allLayers, false ) );
115
116 m_params.emplace_back( new PARAM<bool>( "editing.polar_coords",
117 &m_PolarCoords, false ) );
118
119 m_params.emplace_back( new PARAM<bool>( "origin_invert_x_axis",
120 &m_DisplayInvertXAxis, false ) );
121
122 m_params.emplace_back( new PARAM<bool>( "origin_invert_y_axis",
123 &m_DisplayInvertYAxis, false ) );
124
125 m_params.emplace_back( new PARAM_LAMBDA<int>( "editing.rotation_angle",
126 [this] () -> int
127 {
128 return m_RotationAngle.AsTenthsOfADegree();
129 },
130 [this] ( int aVal )
131 {
132 if( aVal )
133 m_RotationAngle = EDA_ANGLE( aVal, TENTHS_OF_A_DEGREE_T );
134 },
135 900 ) );
136
137 m_params.emplace_back( new PARAM<int>( "editing.fp_angle_snap_mode",
138 reinterpret_cast<int*>( &m_AngleSnapMode ),
139 static_cast<int>( LEADER_MODE::DEG45 ) ) );
140
141 m_params.emplace_back( new PARAM_LAYER_PRESET( "pcb_display.layer_presets", &m_LayerPresets ) );
142
143 m_params.emplace_back( new PARAM<wxString>( "pcb_display.active_layer_preset",
144 &m_ActiveLayerPreset, "" ) );
145
146 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>(
147 "design_settings.default_footprint_text_items",
148 [&] () -> nlohmann::json
149 {
150 nlohmann::json js = nlohmann::json::array();
151
152 for( const TEXT_ITEM_INFO& item : m_DesignSettings.m_DefaultFPTextItems )
153 {
154 js.push_back( nlohmann::json( { item.m_Text.ToUTF8(),
155 item.m_Visible,
156 LSET::Name( item.m_Layer ) } ) );
157 }
158
159 return js;
160 },
161 [&] ( const nlohmann::json& aObj )
162 {
163 m_DesignSettings.m_DefaultFPTextItems.clear();
164
165 if( !aObj.is_array() )
166 return;
167
168 for( const nlohmann::json& entry : aObj )
169 {
170 if( entry.empty() || !entry.is_array() )
171 continue;
172
173 TEXT_ITEM_INFO textInfo( wxT( "" ), true, F_SilkS );
174
175 textInfo.m_Text = entry.at(0).get<wxString>();
176 textInfo.m_Visible = entry.at(1).get<bool>();
177 wxString layerName = entry.at(2).get<wxString>();
178 int candidateLayer = LSET::NameToLayer( layerName );
179 textInfo.m_Layer = candidateLayer >= 0
180 ? static_cast<PCB_LAYER_ID>(candidateLayer)
181 : F_SilkS;
182
183 m_DesignSettings.m_DefaultFPTextItems.push_back( std::move( textInfo ) );
184 }
185 },
186 nlohmann::json::array( {
187 { "REF**", true, LSET::Name( F_SilkS ) },
188 { "", true, LSET::Name( F_Fab ) },
189 { "${REFERENCE}", true, LSET::Name( F_Fab ) }
190 } ) ) );
191
192 m_params.emplace_back( new PARAM_MAP<wxString>( "design_settings.default_footprint_layer_names",
193 &m_DesignSettings.m_UserLayerNames, {} ) );
194
195 m_params.emplace_back( new PARAM_LAMBDA<int>( "design_settings.user_layer_count",
196 [this]() { return m_DesignSettings.GetUserDefinedLayerCount(); },
197 [this]( int aCount ) { m_DesignSettings.SetUserDefinedLayerCount( aCount ); },
198 4 ) );
199
200 int minTextSize = pcbIUScale.mmToIU( TEXT_MIN_SIZE_MM );
201 int maxTextSize = pcbIUScale.mmToIU( TEXT_MAX_SIZE_MM );
202 int minStroke = 1;
203 int maxStroke = pcbIUScale.mmToIU( 100 );
204
205 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.silk_line_width",
206 &m_DesignSettings.m_LineThickness[ LAYER_CLASS_SILK ],
207 pcbIUScale.mmToIU( DEFAULT_SILK_LINE_WIDTH ), minStroke, maxStroke, pcbIUScale.MM_PER_IU ) );
208
209 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.silk_text_size_h",
210 &m_DesignSettings.m_TextSize[ LAYER_CLASS_SILK ].x,
211 pcbIUScale.mmToIU( DEFAULT_SILK_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
212
213 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.silk_text_size_v",
214 &m_DesignSettings.m_TextSize[ LAYER_CLASS_SILK ].y,
215 pcbIUScale.mmToIU( DEFAULT_SILK_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
216
217 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.silk_text_thickness",
218 &m_DesignSettings.m_TextThickness[ LAYER_CLASS_SILK ],
219 pcbIUScale.mmToIU( DEFAULT_SILK_TEXT_WIDTH ), 1, maxTextSize, pcbIUScale.MM_PER_IU ) );
220
221 m_params.emplace_back( new PARAM<bool>( "design_settings.silk_text_italic",
222 &m_DesignSettings.m_TextItalic[ LAYER_CLASS_SILK ], false ) );
223
224 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.copper_line_width",
225 &m_DesignSettings.m_LineThickness[ LAYER_CLASS_COPPER ],
226 pcbIUScale.mmToIU( DEFAULT_COPPER_LINE_WIDTH ), minStroke, maxStroke, pcbIUScale.MM_PER_IU ) );
227
228 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.copper_text_size_h",
229 &m_DesignSettings.m_TextSize[ LAYER_CLASS_COPPER ].x,
230 pcbIUScale.mmToIU( DEFAULT_COPPER_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
231
232 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.copper_text_size_v",
233 &m_DesignSettings.m_TextSize[ LAYER_CLASS_COPPER ].y,
234 pcbIUScale.mmToIU( DEFAULT_COPPER_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
235
236 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.copper_text_thickness",
237 &m_DesignSettings.m_TextThickness[ LAYER_CLASS_COPPER ],
238 pcbIUScale.mmToIU( DEFAULT_COPPER_TEXT_WIDTH ), minStroke, maxStroke, pcbIUScale.MM_PER_IU ) );
239
240 m_params.emplace_back( new PARAM<bool>( "design_settings.copper_text_italic",
241 &m_DesignSettings.m_TextItalic[ LAYER_CLASS_COPPER ], false ) );
242
243 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.edge_line_width",
244 &m_DesignSettings.m_LineThickness[ LAYER_CLASS_EDGES ],
245 pcbIUScale.mmToIU( DEFAULT_EDGE_WIDTH ), minStroke, maxStroke, pcbIUScale.MM_PER_IU ) );
246
247 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.courtyard_line_width",
248 &m_DesignSettings.m_LineThickness[ LAYER_CLASS_COURTYARD ],
249 pcbIUScale.mmToIU( DEFAULT_COURTYARD_WIDTH ), minStroke, maxStroke, pcbIUScale.MM_PER_IU ) );
250
251 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.fab_line_width",
252 &m_DesignSettings.m_LineThickness[ LAYER_CLASS_FAB ],
253 pcbIUScale.mmToIU( DEFAULT_LINE_WIDTH ), minStroke, maxStroke, pcbIUScale.MM_PER_IU ) );
254
255 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.fab_text_size_h",
256 &m_DesignSettings.m_TextSize[ LAYER_CLASS_FAB ].x,
257 pcbIUScale.mmToIU( DEFAULT_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
258
259 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.fab_text_size_v",
260 &m_DesignSettings.m_TextSize[ LAYER_CLASS_FAB ].y,
261 pcbIUScale.mmToIU( DEFAULT_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
262
263 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.fab_text_thickness",
264 &m_DesignSettings.m_TextThickness[ LAYER_CLASS_FAB ],
265 pcbIUScale.mmToIU( DEFAULT_TEXT_WIDTH ), 1, maxTextSize, pcbIUScale.MM_PER_IU ) );
266
267 m_params.emplace_back( new PARAM<bool>( "design_settings.fab_text_italic",
268 &m_DesignSettings.m_TextItalic[ LAYER_CLASS_FAB ], false ) );
269
270 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.others_line_width",
271 &m_DesignSettings.m_LineThickness[ LAYER_CLASS_OTHERS ],
272 pcbIUScale.mmToIU( DEFAULT_LINE_WIDTH ), minStroke, maxStroke, pcbIUScale.MM_PER_IU ) );
273
274 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.others_text_size_h",
275 &m_DesignSettings.m_TextSize[ LAYER_CLASS_OTHERS ].x,
276 pcbIUScale.mmToIU( DEFAULT_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
277
278 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.others_text_size_v",
279 &m_DesignSettings.m_TextSize[ LAYER_CLASS_OTHERS ].y,
280 pcbIUScale.mmToIU( DEFAULT_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
281
282 m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.others_text_thickness",
283 &m_DesignSettings.m_TextThickness[ LAYER_CLASS_OTHERS ],
284 pcbIUScale.mmToIU( DEFAULT_TEXT_WIDTH ), 1, maxTextSize, pcbIUScale.MM_PER_IU ) );
285
286 m_params.emplace_back( new PARAM<bool>( "design_settings.others_text_italic",
287 &m_DesignSettings.m_TextItalic[ LAYER_CLASS_OTHERS ], false ) );
288
289
290 // ---------------------------------------------------------------------------------------------
291 // Dimension settings
292
293 m_params.emplace_back( new PARAM_ENUM<DIM_UNITS_MODE>( "design_settings.dimensions.units",
296
297 m_params.emplace_back( new PARAM_ENUM<DIM_PRECISION>( "design_settings.dimensions.precision",
299
300 m_params.emplace_back( new PARAM_ENUM<DIM_UNITS_FORMAT>( "design_settings.dimensions.units_format",
303
304 m_params.emplace_back( new PARAM<bool>( "design_settings.dimensions.suppress_zeroes",
305 &m_DesignSettings.m_DimensionSuppressZeroes, true ) );
306
307 // NOTE: excluding DIM_TEXT_POSITION::MANUAL from the valid range here
308 m_params.emplace_back( new PARAM_ENUM<DIM_TEXT_POSITION>( "design_settings.dimensions.text_position",
311
312 m_params.emplace_back( new PARAM<bool>( "design_settings.dimensions.keep_text_aligned",
313 &m_DesignSettings.m_DimensionKeepTextAligned, true ) );
314
315 m_params.emplace_back( new PARAM<int>( "design_settings.dimensions.arrow_length",
316 &m_DesignSettings.m_DimensionArrowLength,
318
319 m_params.emplace_back( new PARAM<int>( "design_settings.dimensions.extension_offset",
320 &m_DesignSettings.m_DimensionExtensionOffset,
322
323 // ---------------------------------------------------------------------------------------------
324
325 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "editing.selection_filter",
326 [&]() -> nlohmann::json
327 {
328 nlohmann::json ret;
329
330 ret["lockedItems"] = m_SelectionFilter.lockedItems;
331 ret["footprints"] = m_SelectionFilter.footprints;
332 ret["text"] = m_SelectionFilter.text;
333 ret["tracks"] = m_SelectionFilter.tracks;
334 ret["vias"] = m_SelectionFilter.vias;
335 ret["pads"] = m_SelectionFilter.pads;
336 ret["graphics"] = m_SelectionFilter.graphics;
337 ret["zones"] = m_SelectionFilter.zones;
338 ret["keepouts"] = m_SelectionFilter.keepouts;
339 ret["dimensions"] = m_SelectionFilter.dimensions;
340 ret["points"] = m_SelectionFilter.points;
341 ret["otherItems"] = m_SelectionFilter.otherItems;
342
343 return ret;
344 },
345 [&]( const nlohmann::json& aVal )
346 {
347 if( aVal.empty() || !aVal.is_object() )
348 return;
349
350 SetIfPresent( aVal, "lockedItems", m_SelectionFilter.lockedItems );
351 SetIfPresent( aVal, "footprints", m_SelectionFilter.footprints );
352 SetIfPresent( aVal, "text", m_SelectionFilter.text );
353 SetIfPresent( aVal, "tracks", m_SelectionFilter.tracks );
354 SetIfPresent( aVal, "vias", m_SelectionFilter.vias );
355 SetIfPresent( aVal, "pads", m_SelectionFilter.pads );
356 SetIfPresent( aVal, "graphics", m_SelectionFilter.graphics );
357 SetIfPresent( aVal, "zones", m_SelectionFilter.zones );
358 SetIfPresent( aVal, "keepouts", m_SelectionFilter.keepouts );
359 SetIfPresent( aVal, "dimensions", m_SelectionFilter.dimensions );
360 SetIfPresent( aVal, "points", m_SelectionFilter.points );
361 SetIfPresent( aVal, "otherItems", m_SelectionFilter.otherItems );
362 },
363 {
364 { "lockedItems", false },
365 { "footprints", true },
366 { "text", true },
367 { "tracks", true },
368 { "vias", true },
369 { "pads", true },
370 { "graphics", true },
371 { "zones", true },
372 { "keepouts", true },
373 { "dimensions", true },
374 { "points", true },
375 { "otherItems", true }
376 } ) );
377
378 registerMigration( 0, 1, std::bind( &FOOTPRINT_EDITOR_SETTINGS::migrateSchema0to1, this ) );
379
380 registerMigration( 1, 2,
381 [&]() -> bool
382 {
383 // This is actually a migration for APP_SETTINGS_BASE::m_LibTree
384 return migrateLibTreeWidth();
385 } );
386
387 registerMigration( 2, 3, std::bind( &FOOTPRINT_EDITOR_SETTINGS::migrateSchema2To3, this ) );
388 registerMigration( 3, 4, std::bind( &FOOTPRINT_EDITOR_SETTINGS::migrateSchema3To4, this ) );
389 registerMigration( 4, 5, std::bind( &FOOTPRINT_EDITOR_SETTINGS::migrateSchema4To5, this ) );
390}
391
392
394{
395 bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
396
397 //
398 // NOTE: there's no value in line-wrapping these; it just makes the table unreadable.
399 //
400 ret &= fromLegacy<int>( aCfg, "ModeditLibWidth", "window.lib_width" );
401 ret &= fromLegacyString( aCfg, "import_last_path", "system.last_import_export_path" );
402
403 ret &= fromLegacy<int>( aCfg, "FpEditorMagneticPads", "editing.magnetic_pads" );
404 ret &= fromLegacy<bool>( aCfg, "FpEditorDisplayPolarCoords", "editing.polar_coords" );
405 ret &= fromLegacy<int>( aCfg, "FpEditorUse45DegreeGraphicSegments", "editing.use_45_degree_graphic_segments" );
406
407 ret &= fromLegacy<bool>( aCfg, "FpEditorGraphicLinesDisplayMode", "pcb_display.graphic_items_fill" );
408 ret &= fromLegacy<bool>( aCfg, "FpEditorPadDisplayMode", "pcb_display.pad_fill" );
409 ret &= fromLegacy<bool>( aCfg, "FpEditorTextsDisplayMode", "pcb_display.footprint_text" );
410
411 ret &= fromLegacy<double>( aCfg, "FpEditorSilkLineWidth", "design_settings.silk_line_width" );
412 ret &= fromLegacy<double>( aCfg, "FpEditorSilkTextSizeH", "design_settings.silk_text_size_h" );
413 ret &= fromLegacy<double>( aCfg, "FpEditorSilkTextSizeV", "design_settings.silk_text_size_v" );
414 ret &= fromLegacy<double>( aCfg, "FpEditorSilkTextThickness", "design_settings.silk_text_thickness" );
415 ret &= fromLegacy<bool>( aCfg, "FpEditorSilkTextItalic", "design_settings.silk_text_italic" );
416 ret &= fromLegacy<double>( aCfg, "FpEditorCopperLineWidth", "design_settings.copper_line_width" );
417 ret &= fromLegacy<double>( aCfg, "FpEditorCopperTextSizeH", "design_settings.copper_text_size_h" );
418 ret &= fromLegacy<double>( aCfg, "FpEditorCopperTextSizeV", "design_settings.copper_text_size_v" );
419 ret &= fromLegacy<double>( aCfg, "FpEditorCopperTextThickness", "design_settings.copper_text_thickness" );
420 ret &= fromLegacy<bool>( aCfg, "FpEditorCopperTextItalic", "design_settings.copper_text_italic" );
421 ret &= fromLegacy<double>( aCfg, "FpEditorEdgeCutLineWidth", "design_settings.edge_line_width" );
422 ret &= fromLegacy<double>( aCfg, "FpEditorCourtyardLineWidth", "design_settings.courtyard_line_width" );
423 ret &= fromLegacy<double>( aCfg, "FpEditorOthersLineWidth", "design_settings.others_line_width" );
424 ret &= fromLegacy<double>( aCfg, "FpEditorOthersTextSizeH", "design_settings.others_text_size_h" );
425 ret &= fromLegacy<double>( aCfg, "FpEditorOthersTextSizeV", "design_settings.others_text_size_v" );
426 ret &= fromLegacy<double>( aCfg, "FpEditorOthersTextThickness", "design_settings.others_text_thickness" );
427 ret &= fromLegacy<bool>( aCfg, "FpEditorOthersTextItalic", "design_settings.others_text_italic" );
428
429 nlohmann::json textItems = nlohmann::json::array( {
430 { "REF**", true, F_SilkS },
431 { "", true, F_Fab }
432 } );
433
434 Set( "design_settings.default_footprint_text_items", std::move( textItems ) );
435
436 ret &= fromLegacyString( aCfg, "FpEditorRefDefaultText", "design_settings.default_footprint_text_items.0.0" );
437 ret &= fromLegacy<bool>( aCfg, "FpEditorRefDefaultVisibility", "design_settings.default_footprint_text_items.0.1" );
438 ret &= fromLegacy<int>( aCfg, "FpEditorRefDefaultLayer", "design_settings.default_footprint_text_items.0.2" );
439 ret &= fromLegacyString( aCfg, "FpEditorValueDefaultText", "design_settings.default_footprint_text_items.1.0" );
440 ret &= fromLegacy<bool>( aCfg, "FpEditorValueDefaultVisibility", "design_settings.default_footprint_text_items.1.1" );
441 ret &= fromLegacy<int>( aCfg, "FpEditorValueDefaultLayer", "design_settings.default_footprint_text_items.1.2" );
442
443
444 std::string f = "ModEdit";
445
446 // Migrate color settings that were stored in the pcbnew config file
447 // We create a copy of the user scheme for the footprint editor context
448
450 COLOR_SETTINGS* cs = manager.AddNewColorSettings( "user_footprints" );
451
452 cs->SetName( wxT( "User (Footprints)" ) );
453 manager.Save( cs );
454
455 auto migrateLegacyColor = [&] ( const std::string& aKey, int aLayerId )
456 {
457 wxString str;
458
459 if( aCfg->Read( aKey, &str ) )
460 cs->SetColor( aLayerId, COLOR4D( str ) );
461 };
462
463 for( int i = 0; i < PCB_LAYER_ID_COUNT; ++i )
464 {
465 wxString layer = LSET::Name( PCB_LAYER_ID( i ) );
466 migrateLegacyColor( f + "Color4DPCBLayer_" + layer.ToStdString(), PCB_LAYER_ID( i ) );
467 }
468
469 migrateLegacyColor( f + "Color4DAnchorEx", LAYER_ANCHOR );
470 migrateLegacyColor( f + "Color4DAuxItems", LAYER_AUX_ITEMS );
471 migrateLegacyColor( f + "Color4DGrid", LAYER_GRID );
472 migrateLegacyColor( f + "Color4DNonPlatedEx", LAYER_NON_PLATEDHOLES );
473 migrateLegacyColor( f + "Color4DPCBBackground", LAYER_PCB_BACKGROUND );
474 migrateLegacyColor( f + "Color4DPCBCursor", LAYER_CURSOR );
475 migrateLegacyColor( f + "Color4DRatsEx", LAYER_RATSNEST );
476 migrateLegacyColor( f + "Color4DViaBBlindEx", LAYER_VIA_BLIND );
477 migrateLegacyColor( f + "Color4DViaBBlindEx", LAYER_VIA_BURIED );
478 migrateLegacyColor( f + "Color4DViaMicroEx", LAYER_VIA_MICROVIA );
479 migrateLegacyColor( f + "Color4DViaThruEx", LAYER_VIA_THROUGH );
480 migrateLegacyColor( f + "Color4DWorksheet", LAYER_DRAWINGSHEET );
481
482 manager.SaveColorSettings( cs, "board" );
483
484 ( *m_internals )[m_internals->PointerFromString( "appearance.color_theme" )] = "user_footprints";
485
486 double x = 0, y = 0;
487 f = "ModEditFrame";
488
489 if( aCfg->Read( f + "PcbUserGrid_X", &x ) && aCfg->Read( f + "PcbUserGrid_Y", &y ) )
490 {
491 EDA_UNITS u = static_cast<EDA_UNITS>( aCfg->ReadLong( f + "PcbUserGrid_Unit",
492 static_cast<long>( EDA_UNITS::INCH ) ) );
493
494 // Convert to internal units
497
498 Set( "window.grid.user_grid_x", EDA_UNIT_UTILS::UI::StringFromValue( pcbIUScale, u, x ) );
499 Set( "window.grid.user_grid_y", EDA_UNIT_UTILS::UI::StringFromValue( pcbIUScale, u, y ) );
500 }
501
502 return ret;
503}
504
505
507{
514
515 if( !m_manager )
516 {
517 wxLogTrace( traceSettings,
518 wxT( "Error: FOOTPRINT_EDITOR_SETTINGS migration cannot run unmanaged!" ) );
519 return false;
520 }
521
522 std::string theme_ptr( "appearance.color_theme" );
523
524 if( !Contains( theme_ptr ) )
525 return true;
526
527 wxString selected = At( theme_ptr ).get<wxString>();
528 wxString search = selected + wxT( "_footprints" );
529
530 for( COLOR_SETTINGS* settings : Pgm().GetSettingsManager().GetColorSettingsList() )
531 {
532 if( settings->GetFilename() == search )
533 {
534 wxLogTrace( traceSettings, wxT( "Updating footprint editor theme from %s to %s" ),
535 selected, search );
536 Set( theme_ptr, search );
537 return true;
538 }
539 }
540
541 return true;
542}
543
544
550{
551 auto p( "/pcb_display/layer_presets"_json_pointer );
552
553 if( !m_internals->contains( p ) || !m_internals->at( p ).is_array() )
554 return true;
555
556 nlohmann::json& presets = m_internals->at( p );
557
558 for( nlohmann::json& entry : presets )
560
561 return true;
562}
563
564
569{
570 auto p( "/pcb_display/layer_presets"_json_pointer );
571
572 if( !m_internals->contains( p ) || !m_internals->at( p ).is_array() )
573 return true;
574
575 nlohmann::json& presets = m_internals->at( p );
576
577 for( nlohmann::json& entry : presets )
579
580 return true;
581}
582
583
588{
589 auto p( "/design_settings/default_footprint_text_items"_json_pointer );
590
591 if( !m_internals->contains( p ) || !m_internals->at( p ).is_array() )
592 return true;
593
594 nlohmann::json& defaults = m_internals->at( p );
595
596 bool reset = false;
597
598 for( nlohmann::json& entry : defaults )
599 {
600 TEXT_ITEM_INFO textInfo( wxT( "" ), true, F_SilkS );
601
602 textInfo.m_Text = entry.at(0).get<wxString>();
603 textInfo.m_Visible = entry.at(1).get<bool>();
604 textInfo.m_Layer = static_cast<PCB_LAYER_ID>( entry.at(2).get<int>() );
605
606 if( textInfo.m_Layer == Rescue || textInfo.m_Layer >= User_5 )
607 {
608 // KiCad pre-9.0 nightlies would write buggy preferences out with invalid layers.
609 // If we detect that, reset to defaults
610 reset = true;
611 }
612 else
613 {
614 // Coming from 8.0 or earlier, just migrate to named layers
615 entry.at(2) = LSET::Name( textInfo.m_Layer );
616 }
617 }
618
619 if( reset )
620 {
621 defaults = nlohmann::json::array( {
622 { "REF**", true, LSET::Name( F_SilkS ) },
623 { "", true, LSET::Name( F_Fab ) },
624 { "${REFERENCE}", true, LSET::Name( F_Fab ) }
625 } );
626 }
627
628 return true;
629}
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:112
@ 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...
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.
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:105
static int NameToLayer(wxString &aName)
Return the layer number from a layer name.
Definition lset.cpp:117
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition lset.cpp:188
Stores an enum as an integer.
Definition parameters.h:229
Like a normal param, but with custom getter and setter functions.
Definition parameters.h:296
static void MigrateToV9Layers(nlohmann::json &aJson)
static void MigrateToNamedRenderLayers(nlohmann::json &aJson)
Represents a map of <std::string, Value>.
Definition parameters.h:735
Represents a parameter that has a scaling factor between the value in the file and the value used int...
Definition parameters.h:393
PCB_VIEWERS_SETTINGS_BASE(const std::string &aFilename, int aSchemaVersion)
VIEWERS_DISPLAY_OPTIONS m_ViewersDisplay
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:132
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
#define TEXT_MIN_SIZE_MM
Minimum text size (1 micron).
Definition eda_text.h:47
#define TEXT_MAX_SIZE_MM
Maximum text size in mm (~10 inches)
Definition eda_text.h:48
EDA_UNITS
Definition eda_units.h:48
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:254
@ LAYER_NON_PLATEDHOLES
Draw usual through hole vias.
Definition layer_ids.h:239
@ LAYER_DRAWINGSHEET
Sheet frame and title block.
Definition layer_ids.h:278
@ LAYER_PCB_BACKGROUND
PCB background color.
Definition layer_ids.h:281
@ LAYER_CURSOR
PCB cursor.
Definition layer_ids.h:282
@ LAYER_AUX_ITEMS
Auxiliary items (guides, rule, etc).
Definition layer_ids.h:283
@ LAYER_RATSNEST
Definition layer_ids.h:253
@ LAYER_ANCHOR
Anchor of items having an anchor point (texts, footprints).
Definition layer_ids.h:248
@ LAYER_VIA_BURIED
Draw blind vias.
Definition layer_ids.h:235
@ LAYER_VIA_BLIND
Draw micro vias.
Definition layer_ids.h:234
@ LAYER_VIA_MICROVIA
Definition layer_ids.h:233
@ LAYER_VIA_THROUGH
Draw buried vias.
Definition layer_ids.h:236
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
@ User_5
Definition layer_ids.h:128
@ F_Fab
Definition layer_ids.h:119
@ F_SilkS
Definition layer_ids.h:100
@ Rescue
Definition layer_ids.h:121
@ PCB_LAYER_ID_COUNT
Definition layer_ids.h:171
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.
SETTINGS_MANAGER * GetSettingsManager()
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE