You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

468 lines
22 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
  5. * Copyright (C) 2020-2023 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. #include <common.h>
  21. #include <footprint_editor_settings.h>
  22. #include <layer_ids.h>
  23. #include <pgm_base.h>
  24. #include <eda_text.h>
  25. #include <settings/common_settings.h>
  26. #include <settings/json_settings_internals.h>
  27. #include <settings/parameters.h>
  28. #include <settings/settings_manager.h>
  29. #include <wx/config.h>
  30. #include <base_units.h>
  31. #include <wx/log.h>
  32. ///! Update the schema version whenever a migration is required
  33. const int fpEditSchemaVersion = 2;
  34. FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS() :
  35. APP_SETTINGS_BASE( "fpedit", fpEditSchemaVersion ),
  36. m_DesignSettings( nullptr, "fpedit.settings" ),
  37. m_MagneticItems(),
  38. m_Display(),
  39. m_UserGrid(),
  40. m_PolarCoords( false ),
  41. m_RotationAngle( ANGLE_90 ),
  42. m_Use45Limit( true ),
  43. m_ArcEditMode( ARC_EDIT_MODE::KEEP_CENTER_ADJUST_ANGLE_RADIUS ),
  44. m_LibWidth( 250 ),
  45. m_LastExportPath(),
  46. m_FootprintTextShownColumns()
  47. {
  48. m_MagneticItems.pads = MAGNETIC_OPTIONS::CAPTURE_ALWAYS;
  49. m_MagneticItems.tracks = MAGNETIC_OPTIONS::NO_EFFECT;
  50. m_MagneticItems.graphics = true;
  51. m_MagneticItems.allLayers = false;
  52. m_AuiPanels.appearance_panel_tab = 0;
  53. m_AuiPanels.right_panel_width = -1;
  54. m_AuiPanels.show_layer_manager = true;
  55. m_params.emplace_back( new PARAM<int>( "window.lib_width",
  56. &m_LibWidth, 250 ) );
  57. m_params.emplace_back( new PARAM<bool>( "aui.show_layer_manager",
  58. &m_AuiPanels.show_layer_manager, true ) );
  59. m_params.emplace_back( new PARAM<int>( "aui.right_panel_width",
  60. &m_AuiPanels.right_panel_width, -1 ) );
  61. m_params.emplace_back( new PARAM<int>( "aui.appearance_panel_tab",
  62. &m_AuiPanels.appearance_panel_tab, 0, 0, 2 ) );
  63. m_params.emplace_back( new PARAM<int>( "aui.properties_panel_width",
  64. &m_AuiPanels.properties_panel_width, -1 ) );
  65. m_params.emplace_back( new PARAM<float>( "aui.properties_splitter_proportion",
  66. &m_AuiPanels.properties_splitter, 0.5f ) );
  67. m_params.emplace_back( new PARAM<bool>( "aui.show_properties",
  68. &m_AuiPanels.show_properties, false ) );
  69. m_params.emplace_back( new PARAM<int>( "library.sort_mode",
  70. &m_LibrarySortMode, 0 ) );
  71. m_params.emplace_back( new PARAM<wxString>( "system.last_import_export_path",
  72. &m_LastExportPath, "" ) );
  73. m_params.emplace_back( new PARAM<wxString>( "window.footprint_text_shown_columns",
  74. &m_FootprintTextShownColumns, "0 1 2 3 4 5 6" ) );
  75. m_params.emplace_back( new PARAM<int>( "editing.magnetic_pads",
  76. reinterpret_cast<int*>( &m_MagneticItems.pads ),
  77. static_cast<int>( MAGNETIC_OPTIONS::CAPTURE_ALWAYS ) ) );
  78. m_params.emplace_back( new PARAM<bool>( "editing.magnetic_graphics",
  79. &m_MagneticItems.graphics, true ) );
  80. m_params.emplace_back( new PARAM<bool>( "editing.magnetic_all_layers",
  81. &m_MagneticItems.allLayers, false ) );
  82. m_params.emplace_back( new PARAM<bool>( "editing.polar_coords",
  83. &m_PolarCoords, false ) );
  84. m_params.emplace_back( new PARAM_LAMBDA<int>( "editing.rotation_angle",
  85. [this] () -> int
  86. {
  87. return m_RotationAngle.AsTenthsOfADegree();
  88. },
  89. [this] ( int aVal )
  90. {
  91. if( aVal )
  92. m_RotationAngle = EDA_ANGLE( aVal, TENTHS_OF_A_DEGREE_T );
  93. },
  94. 900 ) );
  95. m_params.emplace_back( new PARAM<bool>( "editing.fp_use_45_degree_limit",
  96. &m_Use45Limit, false ) );
  97. m_params.emplace_back( new PARAM_LAYER_PRESET( "pcb_display.layer_presets", &m_LayerPresets ) );
  98. m_params.emplace_back( new PARAM<wxString>( "pcb_display.active_layer_preset",
  99. &m_ActiveLayerPreset, "" ) );
  100. m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>(
  101. "design_settings.default_footprint_text_items",
  102. [&] () -> nlohmann::json
  103. {
  104. nlohmann::json js = nlohmann::json::array();
  105. for( const TEXT_ITEM_INFO& item : m_DesignSettings.m_DefaultFPTextItems )
  106. {
  107. js.push_back( nlohmann::json( { item.m_Text.ToUTF8(),
  108. item.m_Visible,
  109. item.m_Layer } ) );
  110. }
  111. return js;
  112. },
  113. [&] ( const nlohmann::json& aObj )
  114. {
  115. m_DesignSettings.m_DefaultFPTextItems.clear();
  116. if( !aObj.is_array() )
  117. return;
  118. for( const nlohmann::json& entry : aObj )
  119. {
  120. if( entry.empty() || !entry.is_array() )
  121. continue;
  122. TEXT_ITEM_INFO textInfo( wxT( "" ), true, F_SilkS );
  123. textInfo.m_Text = entry.at(0).get<wxString>();
  124. textInfo.m_Visible = entry.at(1).get<bool>();
  125. textInfo.m_Layer = entry.at(2).get<int>();
  126. m_DesignSettings.m_DefaultFPTextItems.push_back( std::move( textInfo ) );
  127. }
  128. },
  129. nlohmann::json::array( {
  130. { "REF**", true, F_SilkS },
  131. { "", true, F_Fab },
  132. { "${REFERENCE}", true, F_Fab }
  133. } ) ) );
  134. int minTextSize = pcbIUScale.MilsToIU( TEXT_MIN_SIZE_MILS );
  135. int maxTextSize = pcbIUScale.MilsToIU( TEXT_MAX_SIZE_MILS );
  136. int minStroke = 1;
  137. int maxStroke = pcbIUScale.mmToIU( 100 );
  138. m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.silk_line_width",
  139. &m_DesignSettings.m_LineThickness[ LAYER_CLASS_SILK ],
  140. pcbIUScale.mmToIU( DEFAULT_SILK_LINE_WIDTH ), minStroke, maxStroke, pcbIUScale.MM_PER_IU ) );
  141. m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.silk_text_size_h",
  142. &m_DesignSettings.m_TextSize[ LAYER_CLASS_SILK ].x,
  143. pcbIUScale.mmToIU( DEFAULT_SILK_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
  144. m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.silk_text_size_v",
  145. &m_DesignSettings.m_TextSize[ LAYER_CLASS_SILK ].y,
  146. pcbIUScale.mmToIU( DEFAULT_SILK_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
  147. m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.silk_text_thickness",
  148. &m_DesignSettings.m_TextThickness[ LAYER_CLASS_SILK ],
  149. pcbIUScale.mmToIU( DEFAULT_SILK_TEXT_WIDTH ), 1, maxTextSize, pcbIUScale.MM_PER_IU ) );
  150. m_params.emplace_back( new PARAM<bool>( "design_settings.silk_text_italic",
  151. &m_DesignSettings.m_TextItalic[ LAYER_CLASS_SILK ], false ) );
  152. m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.copper_line_width",
  153. &m_DesignSettings.m_LineThickness[ LAYER_CLASS_COPPER ],
  154. pcbIUScale.mmToIU( DEFAULT_COPPER_LINE_WIDTH ), minStroke, maxStroke, pcbIUScale.MM_PER_IU ) );
  155. m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.copper_text_size_h",
  156. &m_DesignSettings.m_TextSize[ LAYER_CLASS_COPPER ].x,
  157. pcbIUScale.mmToIU( DEFAULT_COPPER_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
  158. m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.copper_text_size_v",
  159. &m_DesignSettings.m_TextSize[ LAYER_CLASS_COPPER ].y,
  160. pcbIUScale.mmToIU( DEFAULT_COPPER_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
  161. m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.copper_text_thickness",
  162. &m_DesignSettings.m_TextThickness[ LAYER_CLASS_COPPER ],
  163. pcbIUScale.mmToIU( DEFAULT_COPPER_TEXT_WIDTH ), minStroke, maxStroke, pcbIUScale.MM_PER_IU ) );
  164. m_params.emplace_back( new PARAM<bool>( "design_settings.copper_text_italic",
  165. &m_DesignSettings.m_TextItalic[ LAYER_CLASS_COPPER ], false ) );
  166. m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.edge_line_width",
  167. &m_DesignSettings.m_LineThickness[ LAYER_CLASS_EDGES ],
  168. pcbIUScale.mmToIU( DEFAULT_EDGE_WIDTH ), minStroke, maxStroke, pcbIUScale.MM_PER_IU ) );
  169. m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.courtyard_line_width",
  170. &m_DesignSettings.m_LineThickness[ LAYER_CLASS_COURTYARD ],
  171. pcbIUScale.mmToIU( DEFAULT_COURTYARD_WIDTH ), minStroke, maxStroke, pcbIUScale.MM_PER_IU ) );
  172. m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.fab_line_width",
  173. &m_DesignSettings.m_LineThickness[ LAYER_CLASS_FAB ],
  174. pcbIUScale.mmToIU( DEFAULT_LINE_WIDTH ), minStroke, maxStroke, pcbIUScale.MM_PER_IU ) );
  175. m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.fab_text_size_h",
  176. &m_DesignSettings.m_TextSize[ LAYER_CLASS_FAB ].x,
  177. pcbIUScale.mmToIU( DEFAULT_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
  178. m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.fab_text_size_v",
  179. &m_DesignSettings.m_TextSize[ LAYER_CLASS_FAB ].y,
  180. pcbIUScale.mmToIU( DEFAULT_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
  181. m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.fab_text_thickness",
  182. &m_DesignSettings.m_TextThickness[ LAYER_CLASS_FAB ],
  183. pcbIUScale.mmToIU( DEFAULT_TEXT_WIDTH ), 1, maxTextSize, pcbIUScale.MM_PER_IU ) );
  184. m_params.emplace_back( new PARAM<bool>( "design_settings.fab_text_italic",
  185. &m_DesignSettings.m_TextItalic[ LAYER_CLASS_FAB ], false ) );
  186. m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.others_line_width",
  187. &m_DesignSettings.m_LineThickness[ LAYER_CLASS_OTHERS ],
  188. pcbIUScale.mmToIU( DEFAULT_LINE_WIDTH ), minStroke, maxStroke, pcbIUScale.MM_PER_IU ) );
  189. m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.others_text_size_h",
  190. &m_DesignSettings.m_TextSize[ LAYER_CLASS_OTHERS ].x,
  191. pcbIUScale.mmToIU( DEFAULT_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
  192. m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.others_text_size_v",
  193. &m_DesignSettings.m_TextSize[ LAYER_CLASS_OTHERS ].y,
  194. pcbIUScale.mmToIU( DEFAULT_TEXT_SIZE ), minTextSize, maxTextSize, pcbIUScale.MM_PER_IU ) );
  195. m_params.emplace_back( new PARAM_SCALED<int>( "design_settings.others_text_thickness",
  196. &m_DesignSettings.m_TextThickness[ LAYER_CLASS_OTHERS ],
  197. pcbIUScale.mmToIU( DEFAULT_TEXT_WIDTH ), 1, maxTextSize, pcbIUScale.MM_PER_IU ) );
  198. m_params.emplace_back( new PARAM<bool>( "design_settings.others_text_italic",
  199. &m_DesignSettings.m_TextItalic[ LAYER_CLASS_OTHERS ], false ) );
  200. m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "editing.selection_filter",
  201. [&]() -> nlohmann::json
  202. {
  203. nlohmann::json ret;
  204. ret["lockedItems"] = m_SelectionFilter.lockedItems;
  205. ret["footprints"] = m_SelectionFilter.footprints;
  206. ret["text"] = m_SelectionFilter.text;
  207. ret["tracks"] = m_SelectionFilter.tracks;
  208. ret["vias"] = m_SelectionFilter.vias;
  209. ret["pads"] = m_SelectionFilter.pads;
  210. ret["graphics"] = m_SelectionFilter.graphics;
  211. ret["zones"] = m_SelectionFilter.zones;
  212. ret["keepouts"] = m_SelectionFilter.keepouts;
  213. ret["dimensions"] = m_SelectionFilter.dimensions;
  214. ret["otherItems"] = m_SelectionFilter.otherItems;
  215. return ret;
  216. },
  217. [&]( const nlohmann::json& aVal )
  218. {
  219. if( aVal.empty() || !aVal.is_object() )
  220. return;
  221. SetIfPresent( aVal, "lockedItems", m_SelectionFilter.lockedItems );
  222. SetIfPresent( aVal, "footprints", m_SelectionFilter.footprints );
  223. SetIfPresent( aVal, "text", m_SelectionFilter.text );
  224. SetIfPresent( aVal, "tracks", m_SelectionFilter.tracks );
  225. SetIfPresent( aVal, "vias", m_SelectionFilter.vias );
  226. SetIfPresent( aVal, "pads", m_SelectionFilter.pads );
  227. SetIfPresent( aVal, "graphics", m_SelectionFilter.graphics );
  228. SetIfPresent( aVal, "zones", m_SelectionFilter.zones );
  229. SetIfPresent( aVal, "keepouts", m_SelectionFilter.keepouts );
  230. SetIfPresent( aVal, "dimensions", m_SelectionFilter.dimensions );
  231. SetIfPresent( aVal, "otherItems", m_SelectionFilter.otherItems );
  232. },
  233. {
  234. { "lockedItems", false },
  235. { "footprints", true },
  236. { "text", true },
  237. { "tracks", true },
  238. { "vias", true },
  239. { "pads", true },
  240. { "graphics", true },
  241. { "zones", true },
  242. { "keepouts", true },
  243. { "dimensions", true },
  244. { "otherItems", true }
  245. } ) );
  246. registerMigration( 0, 1, std::bind( &FOOTPRINT_EDITOR_SETTINGS::migrateSchema0to1, this ) );
  247. registerMigration( 1, 2,
  248. [&]() -> bool
  249. {
  250. // This is actually a migration for APP_SETTINGS_BASE::m_LibTree
  251. return migrateLibTreeWidth();
  252. } );
  253. }
  254. bool FOOTPRINT_EDITOR_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
  255. {
  256. bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
  257. //
  258. // NOTE: there's no value in line-wrapping these; it just makes the table unreadable.
  259. //
  260. ret &= fromLegacy<int>( aCfg, "ModeditLibWidth", "window.lib_width" );
  261. ret &= fromLegacyString( aCfg, "import_last_path", "system.last_import_export_path" );
  262. ret &= fromLegacyString( aCfg, "LibFootprintTextShownColumns", "window.footprint_text_shown_columns" );
  263. ret &= fromLegacy<int>( aCfg, "FpEditorMagneticPads", "editing.magnetic_pads" );
  264. ret &= fromLegacy<bool>( aCfg, "FpEditorDisplayPolarCoords", "editing.polar_coords" );
  265. ret &= fromLegacy<int>( aCfg, "FpEditorUse45DegreeGraphicSegments", "editing.use_45_degree_graphic_segments" );
  266. ret &= fromLegacy<bool>( aCfg, "FpEditorGraphicLinesDisplayMode", "pcb_display.graphic_items_fill" );
  267. ret &= fromLegacy<bool>( aCfg, "FpEditorPadDisplayMode", "pcb_display.pad_fill" );
  268. ret &= fromLegacy<bool>( aCfg, "FpEditorTextsDisplayMode", "pcb_display.footprint_text" );
  269. ret &= fromLegacy<double>( aCfg, "FpEditorSilkLineWidth", "design_settings.silk_line_width" );
  270. ret &= fromLegacy<double>( aCfg, "FpEditorSilkTextSizeH", "design_settings.silk_text_size_h" );
  271. ret &= fromLegacy<double>( aCfg, "FpEditorSilkTextSizeV", "design_settings.silk_text_size_v" );
  272. ret &= fromLegacy<double>( aCfg, "FpEditorSilkTextThickness", "design_settings.silk_text_thickness" );
  273. ret &= fromLegacy<bool>( aCfg, "FpEditorSilkTextItalic", "design_settings.silk_text_italic" );
  274. ret &= fromLegacy<double>( aCfg, "FpEditorCopperLineWidth", "design_settings.copper_line_width" );
  275. ret &= fromLegacy<double>( aCfg, "FpEditorCopperTextSizeH", "design_settings.copper_text_size_h" );
  276. ret &= fromLegacy<double>( aCfg, "FpEditorCopperTextSizeV", "design_settings.copper_text_size_v" );
  277. ret &= fromLegacy<double>( aCfg, "FpEditorCopperTextThickness", "design_settings.copper_text_thickness" );
  278. ret &= fromLegacy<bool>( aCfg, "FpEditorCopperTextItalic", "design_settings.copper_text_italic" );
  279. ret &= fromLegacy<double>( aCfg, "FpEditorEdgeCutLineWidth", "design_settings.edge_line_width" );
  280. ret &= fromLegacy<double>( aCfg, "FpEditorCourtyardLineWidth", "design_settings.courtyard_line_width" );
  281. ret &= fromLegacy<double>( aCfg, "FpEditorOthersLineWidth", "design_settings.others_line_width" );
  282. ret &= fromLegacy<double>( aCfg, "FpEditorOthersTextSizeH", "design_settings.others_text_size_h" );
  283. ret &= fromLegacy<double>( aCfg, "FpEditorOthersTextSizeV", "design_settings.others_text_size_v" );
  284. ret &= fromLegacy<double>( aCfg, "FpEditorOthersTextThickness", "design_settings.others_text_thickness" );
  285. ret &= fromLegacy<bool>( aCfg, "FpEditorOthersTextItalic", "design_settings.others_text_italic" );
  286. nlohmann::json textItems = nlohmann::json::array( {
  287. { "REF**", true, F_SilkS },
  288. { "", true, F_Fab }
  289. } );
  290. Set( "design_settings.default_footprint_text_items", textItems );
  291. ret &= fromLegacyString( aCfg, "FpEditorRefDefaultText", "design_settings.default_footprint_text_items.0.0" );
  292. ret &= fromLegacy<bool>( aCfg, "FpEditorRefDefaultVisibility", "design_settings.default_footprint_text_items.0.1" );
  293. ret &= fromLegacy<int>( aCfg, "FpEditorRefDefaultLayer", "design_settings.default_footprint_text_items.0.2" );
  294. ret &= fromLegacyString( aCfg, "FpEditorValueDefaultText", "design_settings.default_footprint_text_items.1.0" );
  295. ret &= fromLegacy<bool>( aCfg, "FpEditorValueDefaultVisibility", "design_settings.default_footprint_text_items.1.1" );
  296. ret &= fromLegacy<int>( aCfg, "FpEditorValueDefaultLayer", "design_settings.default_footprint_text_items.1.2" );
  297. std::string f = "ModEdit";
  298. // Migrate color settings that were stored in the pcbnew config file
  299. // We create a copy of the user scheme for the footprint editor context
  300. SETTINGS_MANAGER& manager = Pgm().GetSettingsManager();
  301. COLOR_SETTINGS* cs = manager.AddNewColorSettings( "user_footprints" );
  302. cs->SetName( wxT( "User (Footprints)" ) );
  303. manager.Save( cs );
  304. auto migrateLegacyColor = [&] ( const std::string& aKey, int aLayerId )
  305. {
  306. wxString str;
  307. if( aCfg->Read( aKey, &str ) )
  308. cs->SetColor( aLayerId, COLOR4D( str ) );
  309. };
  310. for( int i = 0; i < PCB_LAYER_ID_COUNT; ++i )
  311. {
  312. wxString layer = LSET::Name( PCB_LAYER_ID( i ) );
  313. migrateLegacyColor( f + "Color4DPCBLayer_" + layer.ToStdString(), PCB_LAYER_ID( i ) );
  314. }
  315. migrateLegacyColor( f + "Color4DAnchorEx", LAYER_ANCHOR );
  316. migrateLegacyColor( f + "Color4DAuxItems", LAYER_AUX_ITEMS );
  317. migrateLegacyColor( f + "Color4DGrid", LAYER_GRID );
  318. migrateLegacyColor( f + "Color4DNonPlatedEx", LAYER_NON_PLATEDHOLES );
  319. migrateLegacyColor( f + "Color4DPadThruHoleEx", LAYER_PADS_TH );
  320. migrateLegacyColor( f + "Color4DPCBBackground", LAYER_PCB_BACKGROUND );
  321. migrateLegacyColor( f + "Color4DPCBCursor", LAYER_CURSOR );
  322. migrateLegacyColor( f + "Color4DRatsEx", LAYER_RATSNEST );
  323. migrateLegacyColor( f + "Color4DTxtInvisEx", LAYER_HIDDEN_TEXT );
  324. migrateLegacyColor( f + "Color4DViaBBlindEx", LAYER_VIA_BBLIND );
  325. migrateLegacyColor( f + "Color4DViaMicroEx", LAYER_VIA_MICROVIA );
  326. migrateLegacyColor( f + "Color4DViaThruEx", LAYER_VIA_THROUGH );
  327. migrateLegacyColor( f + "Color4DWorksheet", LAYER_DRAWINGSHEET );
  328. manager.SaveColorSettings( cs, "board" );
  329. ( *m_internals )[m_internals->PointerFromString( "appearance.color_theme" )] = "user_footprints";
  330. double x = 0, y = 0;
  331. f = "ModEditFrame";
  332. if( aCfg->Read( f + "PcbUserGrid_X", &x ) && aCfg->Read( f + "PcbUserGrid_Y", &y ) )
  333. {
  334. EDA_UNITS u = static_cast<EDA_UNITS>( aCfg->ReadLong( f + "PcbUserGrid_Unit",
  335. static_cast<long>( EDA_UNITS::INCHES ) ) );
  336. // Convert to internal units
  337. x = EDA_UNIT_UTILS::UI::FromUserUnit( pcbIUScale, u, x );
  338. y = EDA_UNIT_UTILS::UI::FromUserUnit( pcbIUScale, u, y );
  339. Set( "window.grid.user_grid_x", EDA_UNIT_UTILS::UI::StringFromValue( pcbIUScale, u, x ) );
  340. Set( "window.grid.user_grid_y", EDA_UNIT_UTILS::UI::StringFromValue( pcbIUScale, u, y ) );
  341. }
  342. return ret;
  343. }
  344. bool FOOTPRINT_EDITOR_SETTINGS::migrateSchema0to1()
  345. {
  346. /**
  347. * Schema version 0 to 1:
  348. *
  349. * - Check to see if a footprints version of the currently selected theme exists.
  350. * - If so, select it
  351. */
  352. if( !m_manager )
  353. {
  354. wxLogTrace( traceSettings,
  355. wxT( "Error: FOOTPRINT_EDITOR_SETTINGS migration cannot run unmanaged!" ) );
  356. return false;
  357. }
  358. std::string theme_ptr( "appearance.color_theme" );
  359. if( !Contains( theme_ptr ) )
  360. return true;
  361. wxString selected = At( theme_ptr ).get<wxString>();
  362. wxString search = selected + wxT( "_footprints" );
  363. for( COLOR_SETTINGS* settings : Pgm().GetSettingsManager().GetColorSettingsList() )
  364. {
  365. if( settings->GetFilename() == search )
  366. {
  367. wxLogTrace( traceSettings, wxT( "Updating footprint editor theme from %s to %s" ),
  368. selected, search );
  369. Set( theme_ptr, search );
  370. return true;
  371. }
  372. }
  373. return true;
  374. }