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.

622 lines
22 KiB

5 years ago
5 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2020 CERN
  5. * Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
  6. * @author Jon Evans <jon@craftyjon.com>
  7. *
  8. * This program is free software: you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation, either version 3 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <config_params.h>
  22. #include <project.h>
  23. #include <project/net_settings.h>
  24. #include <settings/json_settings_internals.h>
  25. #include <project/project_file.h>
  26. #include <settings/common_settings.h>
  27. #include <settings/parameters.h>
  28. #include <wildcards_and_files_ext.h>
  29. #include <wx/config.h>
  30. #include <wx/log.h>
  31. ///! Update the schema version whenever a migration is required
  32. const int projectFileSchemaVersion = 1;
  33. PROJECT_FILE::PROJECT_FILE( const wxString& aFullPath ) :
  34. JSON_SETTINGS( aFullPath, SETTINGS_LOC::PROJECT, projectFileSchemaVersion ),
  35. m_ErcSettings( nullptr ),
  36. m_SchematicSettings( nullptr ),
  37. m_BoardSettings(),
  38. m_sheets(),
  39. m_boards(),
  40. m_project( nullptr )
  41. {
  42. // Keep old files around
  43. m_deleteLegacyAfterMigration = false;
  44. m_params.emplace_back( new PARAM_LIST<FILE_INFO_PAIR>( "sheets", &m_sheets, {} ) );
  45. m_params.emplace_back( new PARAM_LIST<FILE_INFO_PAIR>( "boards", &m_boards, {} ) );
  46. m_params.emplace_back( new PARAM_WXSTRING_MAP( "text_variables", &m_TextVars, {} ) );
  47. m_params.emplace_back(
  48. new PARAM_LIST<wxString>( "libraries.pinned_symbol_libs", &m_PinnedSymbolLibs, {} ) );
  49. m_params.emplace_back( new PARAM_LIST<wxString>(
  50. "libraries.pinned_footprint_libs", &m_PinnedFootprintLibs, {} ) );
  51. m_params.emplace_back(
  52. new PARAM_PATH_LIST( "cvpcb.equivalence_files", &m_EquivalenceFiles, {} ) );
  53. m_params.emplace_back(
  54. new PARAM_PATH( "pcbnew.page_layout_descr_file", &m_BoardDrawingSheetFile, "" ) );
  55. m_params.emplace_back(
  56. new PARAM_PATH( "pcbnew.last_paths.netlist", &m_PcbLastPath[LAST_PATH_NETLIST], "" ) );
  57. m_params.emplace_back(
  58. new PARAM_PATH( "pcbnew.last_paths.step", &m_PcbLastPath[LAST_PATH_STEP], "" ) );
  59. m_params.emplace_back(
  60. new PARAM_PATH( "pcbnew.last_paths.idf", &m_PcbLastPath[LAST_PATH_IDF], "" ) );
  61. m_params.emplace_back(
  62. new PARAM_PATH( "pcbnew.last_paths.vrml", &m_PcbLastPath[LAST_PATH_VRML], "" ) );
  63. m_params.emplace_back( new PARAM_PATH(
  64. "pcbnew.last_paths.specctra_dsn", &m_PcbLastPath[LAST_PATH_SPECCTRADSN], "" ) );
  65. m_params.emplace_back(
  66. new PARAM_PATH( "pcbnew.last_paths.gencad", &m_PcbLastPath[LAST_PATH_GENCAD], "" ) );
  67. m_params.emplace_back( new PARAM<wxString>( "schematic.legacy_lib_dir", &m_LegacyLibDir, "" ) );
  68. m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "schematic.legacy_lib_list",
  69. [&]() -> nlohmann::json
  70. {
  71. nlohmann::json ret = nlohmann::json::array();
  72. for( const wxString& libName : m_LegacyLibNames )
  73. ret.push_back( libName );
  74. return ret;
  75. },
  76. [&]( const nlohmann::json& aJson )
  77. {
  78. if( aJson.empty() || !aJson.is_array() )
  79. return;
  80. m_LegacyLibNames.clear();
  81. for( const nlohmann::json& entry : aJson )
  82. m_LegacyLibNames.push_back( entry.get<wxString>() );
  83. }, {} ) );
  84. m_NetSettings = std::make_shared<NET_SETTINGS>( this, "net_settings" );
  85. m_params.emplace_back( new PARAM_LAYER_PRESET( "board.layer_presets", &m_LayerPresets ) );
  86. m_params.emplace_back( new PARAM_VIEWPORT( "board.viewports", &m_Viewports ) );
  87. m_params.emplace_back( new PARAM_VIEWPORT3D( "board.3dviewports", &m_Viewports3D ) );
  88. }
  89. bool PROJECT_FILE::MigrateFromLegacy( wxConfigBase* aCfg )
  90. {
  91. bool ret = true;
  92. wxString str;
  93. long index = 0;
  94. std::set<wxString> group_blacklist;
  95. // Legacy files don't store board info; they assume board matches project name
  96. // We will leave m_boards empty here so it can be populated with other code
  97. // First handle migration of data that will be stored locally in this object
  98. auto loadPinnedLibs =
  99. [&]( const std::string& aDest )
  100. {
  101. int libIndex = 1;
  102. wxString libKey = wxT( "PinnedItems" );
  103. libKey << libIndex;
  104. nlohmann::json libs = nlohmann::json::array();
  105. while( aCfg->Read( libKey, &str ) )
  106. {
  107. libs.push_back( str );
  108. aCfg->DeleteEntry( libKey, true );
  109. libKey = wxT( "PinnedItems" );
  110. libKey << ++libIndex;
  111. }
  112. Set( aDest, libs );
  113. };
  114. aCfg->SetPath( wxT( "/LibeditFrame" ) );
  115. loadPinnedLibs( "libraries.pinned_symbol_libs" );
  116. aCfg->SetPath( wxT( "/ModEditFrame" ) );
  117. loadPinnedLibs( "libraries.pinned_footprint_libs" );
  118. aCfg->SetPath( wxT( "/cvpcb/equfiles" ) );
  119. {
  120. int eqIdx = 1;
  121. wxString eqKey = wxT( "EquName" );
  122. eqKey << eqIdx;
  123. nlohmann::json eqs = nlohmann::json::array();
  124. while( aCfg->Read( eqKey, &str ) )
  125. {
  126. eqs.push_back( str );
  127. eqKey = wxT( "EquName" );
  128. eqKey << ++eqIdx;
  129. }
  130. Set( "cvpcb.equivalence_files", eqs );
  131. }
  132. // All CvPcb params that we want to keep have been migrated above
  133. group_blacklist.insert( wxT( "/cvpcb" ) );
  134. aCfg->SetPath( wxT( "/eeschema" ) );
  135. fromLegacyString( aCfg, "LibDir", "schematic.legacy_lib_dir" );
  136. aCfg->SetPath( wxT( "/eeschema/libraries" ) );
  137. {
  138. int libIdx = 1;
  139. wxString libKey = wxT( "LibName" );
  140. libKey << libIdx;
  141. nlohmann::json libs = nlohmann::json::array();
  142. while( aCfg->Read( libKey, &str ) )
  143. {
  144. libs.push_back( str );
  145. libKey = wxT( "LibName" );
  146. libKey << ++libIdx;
  147. }
  148. Set( "schematic.legacy_lib_list", libs );
  149. }
  150. group_blacklist.insert( wxT( "/eeschema" ) );
  151. aCfg->SetPath( wxT( "/text_variables" ) );
  152. {
  153. int txtIdx = 1;
  154. wxString txtKey;
  155. txtKey << txtIdx;
  156. nlohmann::json vars = nlohmann::json();
  157. while( aCfg->Read( txtKey, &str ) )
  158. {
  159. wxArrayString tokens = wxSplit( str, ':' );
  160. if( tokens.size() == 2 )
  161. vars[ tokens[0].ToStdString() ] = tokens[1];
  162. txtKey.clear();
  163. txtKey << ++txtIdx;
  164. }
  165. Set( "text_variables", vars );
  166. }
  167. group_blacklist.insert( wxT( "/text_variables" ) );
  168. aCfg->SetPath( wxT( "/schematic_editor" ) );
  169. fromLegacyString( aCfg, "PageLayoutDescrFile", "schematic.page_layout_descr_file" );
  170. fromLegacyString( aCfg, "PlotDirectoryName", "schematic.plot_directory" );
  171. fromLegacyString( aCfg, "NetFmtName", "schematic.net_format_name" );
  172. fromLegacy<bool>( aCfg, "SpiceAjustPassiveValues", "schematic.spice_adjust_passive_values" );
  173. fromLegacy<int>( aCfg, "SubpartIdSeparator", "schematic.subpart_id_separator" );
  174. fromLegacy<int>( aCfg, "SubpartFirstId", "schematic.subpart_first_id" );
  175. fromLegacy<int>( aCfg, "LineThickness", "schematic.drawing.default_line_thickness" );
  176. fromLegacy<int>( aCfg, "WireThickness", "schematic.drawing.default_wire_thickness" );
  177. fromLegacy<int>( aCfg, "BusThickness", "schematic.drawing.default_bus_thickness" );
  178. fromLegacy<int>( aCfg, "LabSize", "schematic.drawing.default_text_size" );
  179. if( !fromLegacy<int>( aCfg, "PinSymbolSize", "schematic.drawing.pin_symbol_size" ) )
  180. {
  181. // Use the default symbol size algorithm of Eeschema V5 (based on pin name/number size)
  182. Set( "schematic.drawing.pin_symbol_size", 0 );
  183. }
  184. fromLegacy<int>( aCfg, "JunctionSize", "schematic.drawing.default_junction_size" );
  185. fromLegacyString( aCfg, "FieldNameTemplates", "schematic.drawing.field_names" );
  186. if( !fromLegacy<double>( aCfg, "TextOffsetRatio", "schematic.drawing.text_offset_ratio" ) )
  187. {
  188. // Use the spacing of Eeschema V5
  189. Set( "schematic.drawing.text_offset_ratio", 0.08 );
  190. Set( "schematic.drawing.label_size_ratio", 0.25 );
  191. }
  192. // All schematic_editor keys we keep are migrated above
  193. group_blacklist.insert( wxT( "/schematic_editor" ) );
  194. aCfg->SetPath( wxT( "/pcbnew" ) );
  195. fromLegacyString( aCfg, "PageLayoutDescrFile", "pcbnew.page_layout_descr_file" );
  196. fromLegacyString( aCfg, "LastNetListRead", "pcbnew.last_paths.netlist" );
  197. fromLegacyString( aCfg, "LastSTEPExportPath", "pcbnew.last_paths.step" );
  198. fromLegacyString( aCfg, "LastIDFExportPath", "pcbnew.last_paths.idf" );
  199. fromLegacyString( aCfg, "LastVRMLExportPath", "pcbnew.last_paths.vmrl" );
  200. fromLegacyString( aCfg, "LastSpecctraDSNExportPath", "pcbnew.last_paths.specctra_dsn" );
  201. fromLegacyString( aCfg, "LastGenCADExportPath", "pcbnew.last_paths.gencad" );
  202. std::string bp = "board.design_settings.";
  203. {
  204. int idx = 1;
  205. wxString key = wxT( "DRCExclusion" );
  206. key << idx;
  207. nlohmann::json exclusions = nlohmann::json::array();
  208. while( aCfg->Read( key, &str ) )
  209. {
  210. exclusions.push_back( str );
  211. key = wxT( "DRCExclusion" );
  212. key << ++idx;
  213. }
  214. Set( bp + "drc_exclusions", exclusions );
  215. }
  216. fromLegacy<bool>( aCfg, "AllowMicroVias", bp + "rules.allow_microvias" );
  217. fromLegacy<bool>( aCfg, "AllowBlindVias", bp + "rules.allow_blind_buried_vias" );
  218. fromLegacy<double>( aCfg, "MinClearance", bp + "rules.min_clearance" );
  219. fromLegacy<double>( aCfg, "MinTrackWidth", bp + "rules.min_track_width" );
  220. fromLegacy<double>( aCfg, "MinViaAnnulus", bp + "rules.min_via_annulus" );
  221. fromLegacy<double>( aCfg, "MinViaDiameter", bp + "rules.min_via_diameter" );
  222. if( !fromLegacy<double>( aCfg, "MinThroughDrill", bp + "rules.min_through_hole_diameter" ) )
  223. fromLegacy<double>( aCfg, "MinViaDrill", bp + "rules.min_through_hole_diameter" );
  224. fromLegacy<double>( aCfg, "MinMicroViaDiameter", bp + "rules.min_microvia_diameter" );
  225. fromLegacy<double>( aCfg, "MinMicroViaDrill", bp + "rules.min_microvia_drill" );
  226. fromLegacy<double>( aCfg, "MinHoleToHole", bp + "rules.min_hole_to_hole" );
  227. fromLegacy<double>( aCfg, "CopperEdgeClearance", bp + "rules.min_copper_edge_clearance" );
  228. fromLegacy<double>( aCfg, "SolderMaskClearance", bp + "rules.solder_mask_clearance" );
  229. fromLegacy<double>( aCfg, "SolderMaskMinWidth", bp + "rules.solder_mask_min_width" );
  230. fromLegacy<double>( aCfg, "SolderPasteClearance", bp + "rules.solder_paste_clearance" );
  231. fromLegacy<double>( aCfg, "SolderPasteRatio", bp + "rules.solder_paste_margin_ratio" );
  232. if( !fromLegacy<double>( aCfg, "SilkLineWidth", bp + "defaults.silk_line_width" ) )
  233. fromLegacy<double>( aCfg, "ModuleOutlineThickness", bp + "defaults.silk_line_width" );
  234. if( !fromLegacy<double>( aCfg, "SilkTextSizeV", bp + "defaults.silk_text_size_v" ) )
  235. fromLegacy<double>( aCfg, "ModuleTextSizeV", bp + "defaults.silk_text_size_v" );
  236. if( !fromLegacy<double>( aCfg, "SilkTextSizeH", bp + "defaults.silk_text_size_h" ) )
  237. fromLegacy<double>( aCfg, "ModuleTextSizeH", bp + "defaults.silk_text_size_h" );
  238. if( !fromLegacy<double>( aCfg, "SilkTextSizeThickness", bp + "defaults.silk_text_thickness" ) )
  239. fromLegacy<double>( aCfg, "ModuleTextSizeThickness", bp + "defaults.silk_text_thickness" );
  240. fromLegacy<bool>( aCfg, "SilkTextItalic", bp + "defaults.silk_text_italic" );
  241. fromLegacy<bool>( aCfg, "SilkTextUpright", bp + "defaults.silk_text_upright" );
  242. if( !fromLegacy<double>( aCfg, "CopperLineWidth", bp + "defaults.copper_line_width" ) )
  243. fromLegacy<double>( aCfg, "DrawSegmentWidth", bp + "defaults.copper_line_width" );
  244. if( !fromLegacy<double>( aCfg, "CopperTextSizeV", bp + "defaults.copper_text_size_v" ) )
  245. fromLegacy<double>( aCfg, "PcbTextSizeV", bp + "defaults.copper_text_size_v" );
  246. if( !fromLegacy<double>( aCfg, "CopperTextSizeH", bp + "defaults.copper_text_size_h" ) )
  247. fromLegacy<double>( aCfg, "PcbTextSizeH", bp + "defaults.copper_text_size_h" );
  248. if( !fromLegacy<double>( aCfg, "CopperTextThickness", bp + "defaults.copper_text_thickness" ) )
  249. fromLegacy<double>( aCfg, "PcbTextThickness", bp + "defaults.copper_text_thickness" );
  250. fromLegacy<bool>( aCfg, "CopperTextItalic", bp + "defaults.copper_text_italic" );
  251. fromLegacy<bool>( aCfg, "CopperTextUpright", bp + "defaults.copper_text_upright" );
  252. if( !fromLegacy<double>( aCfg, "EdgeCutLineWidth", bp + "defaults.board_outline_line_width" ) )
  253. fromLegacy<double>( aCfg, "BoardOutlineThickness", bp + "defaults.board_outline_line_width" );
  254. fromLegacy<double>( aCfg, "CourtyardLineWidth", bp + "defaults.courtyard_line_width" );
  255. fromLegacy<double>( aCfg, "FabLineWidth", bp + "defaults.fab_line_width" );
  256. fromLegacy<double>( aCfg, "FabTextSizeV", bp + "defaults.fab_text_size_v" );
  257. fromLegacy<double>( aCfg, "FabTextSizeH", bp + "defaults.fab_text_size_h" );
  258. fromLegacy<double>( aCfg, "FabTextSizeThickness", bp + "defaults.fab_text_thickness" );
  259. fromLegacy<bool>( aCfg, "FabTextItalic", bp + "defaults.fab_text_italic" );
  260. fromLegacy<bool>( aCfg, "FabTextUpright", bp + "defaults.fab_text_upright" );
  261. if( !fromLegacy<double>( aCfg, "OthersLineWidth", bp + "defaults.other_line_width" ) )
  262. fromLegacy<double>( aCfg, "ModuleOutlineThickness", bp + "defaults.other_line_width" );
  263. fromLegacy<double>( aCfg, "OthersTextSizeV", bp + "defaults.other_text_size_v" );
  264. fromLegacy<double>( aCfg, "OthersTextSizeH", bp + "defaults.other_text_size_h" );
  265. fromLegacy<double>( aCfg, "OthersTextSizeThickness", bp + "defaults.other_text_thickness" );
  266. fromLegacy<bool>( aCfg, "OthersTextItalic", bp + "defaults.other_text_italic" );
  267. fromLegacy<bool>( aCfg, "OthersTextUpright", bp + "defaults.other_text_upright" );
  268. fromLegacy<int>( aCfg, "DimensionUnits", bp + "defaults.dimension_units" );
  269. fromLegacy<int>( aCfg, "DimensionPrecision", bp + "defaults.dimension_precision" );
  270. std::string sev = bp + "rule_severities";
  271. fromLegacy<bool>( aCfg, "RequireCourtyardDefinitions", sev + "legacy_no_courtyard_defined" );
  272. fromLegacy<bool>( aCfg, "ProhibitOverlappingCourtyards", sev + "legacy_courtyards_overlap" );
  273. {
  274. int idx = 1;
  275. wxString keyBase = "TrackWidth";
  276. wxString key = keyBase;
  277. double val;
  278. nlohmann::json widths = nlohmann::json::array();
  279. key << idx;
  280. while( aCfg->Read( key, &val ) )
  281. {
  282. widths.push_back( val );
  283. key = keyBase;
  284. key << ++idx;
  285. }
  286. Set( bp + "track_widths", widths );
  287. }
  288. {
  289. int idx = 1;
  290. wxString keyBase = "ViaDiameter";
  291. wxString key = keyBase;
  292. double diameter;
  293. double drill = 1.0;
  294. nlohmann::json vias = nlohmann::json::array();
  295. key << idx;
  296. while( aCfg->Read( key, &diameter ) )
  297. {
  298. key = "ViaDrill";
  299. aCfg->Read( key << idx, &drill );
  300. nlohmann::json via = { { "diameter", diameter }, { "drill", drill } };
  301. vias.push_back( via );
  302. key = keyBase;
  303. key << ++idx;
  304. }
  305. Set( bp + "via_dimensions", vias );
  306. }
  307. {
  308. int idx = 1;
  309. wxString keyBase = "dPairWidth";
  310. wxString key = keyBase;
  311. double width;
  312. double gap = 1.0;
  313. double via_gap = 1.0;
  314. nlohmann::json pairs = nlohmann::json::array();
  315. key << idx;
  316. while( aCfg->Read( key, &width ) )
  317. {
  318. key = "dPairGap";
  319. aCfg->Read( key << idx, &gap );
  320. key = "dPairViaGap";
  321. aCfg->Read( key << idx, &via_gap );
  322. nlohmann::json pair = { { "width", width }, { "gap", gap }, { "via_gap", via_gap } };
  323. pairs.push_back( pair );
  324. key = keyBase;
  325. key << ++idx;
  326. }
  327. Set( bp + "diff_pair_dimensions", pairs );
  328. }
  329. group_blacklist.insert( wxT( "/pcbnew" ) );
  330. // General group is unused these days, we can throw it away
  331. group_blacklist.insert( wxT( "/general" ) );
  332. // Next load sheet names and put all other legacy data in the legacy dict
  333. aCfg->SetPath( wxT( "/" ) );
  334. auto loadSheetNames =
  335. [&]() -> bool
  336. {
  337. int sheet = 1;
  338. wxString entry;
  339. nlohmann::json arr = nlohmann::json::array();
  340. wxLogTrace( traceSettings, wxT( "Migrating sheet names" ) );
  341. aCfg->SetPath( wxT( "/sheetnames" ) );
  342. while( aCfg->Read( wxString::Format( "%d", sheet++ ), &entry ) )
  343. {
  344. wxArrayString tokens = wxSplit( entry, ':' );
  345. if( tokens.size() == 2 )
  346. {
  347. wxLogTrace( traceSettings, wxT( "%d: %s = %s" ), sheet, tokens[0],
  348. tokens[1] );
  349. arr.push_back( nlohmann::json::array( { tokens[0], tokens[1] } ) );
  350. }
  351. }
  352. Set( "sheets", arr );
  353. aCfg->SetPath( "/" );
  354. // TODO: any reason we want to fail on this?
  355. return true;
  356. };
  357. std::vector<wxString> groups;
  358. groups.emplace_back( wxEmptyString );
  359. auto loadLegacyPairs =
  360. [&]( const std::string& aGroup ) -> bool
  361. {
  362. wxLogTrace( traceSettings, wxT( "Migrating group %s" ), aGroup );
  363. bool success = true;
  364. wxString keyStr;
  365. wxString val;
  366. index = 0;
  367. while( aCfg->GetNextEntry( keyStr, index ) )
  368. {
  369. if( !aCfg->Read( keyStr, &val ) )
  370. continue;
  371. std::string key( keyStr.ToUTF8() );
  372. wxLogTrace( traceSettings, wxT( " %s = %s" ), key, val );
  373. try
  374. {
  375. Set( "legacy." + aGroup + "." + key, val );
  376. }
  377. catch( ... )
  378. {
  379. success = false;
  380. }
  381. }
  382. return success;
  383. };
  384. for( size_t i = 0; i < groups.size(); i++ )
  385. {
  386. aCfg->SetPath( groups[i] );
  387. if( groups[i] == wxT( "/sheetnames" ) )
  388. {
  389. ret |= loadSheetNames();
  390. continue;
  391. }
  392. aCfg->DeleteEntry( wxT( "last_client" ), true );
  393. aCfg->DeleteEntry( wxT( "update" ), true );
  394. aCfg->DeleteEntry( wxT( "version" ), true );
  395. ret &= loadLegacyPairs( groups[i].ToStdString() );
  396. index = 0;
  397. while( aCfg->GetNextGroup( str, index ) )
  398. {
  399. wxString group = groups[i] + "/" + str;
  400. if( !group_blacklist.count( group ) )
  401. groups.emplace_back( group );
  402. }
  403. aCfg->SetPath( "/" );
  404. }
  405. return ret;
  406. }
  407. bool PROJECT_FILE::SaveToFile( const wxString& aDirectory, bool aForce )
  408. {
  409. wxASSERT( m_project );
  410. Set( "meta.filename", m_project->GetProjectName() + "." + ProjectFileExtension );
  411. return JSON_SETTINGS::SaveToFile( aDirectory, aForce );
  412. }
  413. bool PROJECT_FILE::SaveAs( const wxString& aDirectory, const wxString& aFile )
  414. {
  415. wxFileName oldFilename( GetFilename() );
  416. wxString oldProjectName = oldFilename.GetName();
  417. Set( "meta.filename", aFile + "." + ProjectFileExtension );
  418. SetFilename( aFile );
  419. auto updatePath =
  420. [&]( wxString& aPath )
  421. {
  422. if( aPath.StartsWith( oldProjectName + wxS( "." ) ) )
  423. aPath.Replace( oldProjectName, aFile, false );
  424. };
  425. updatePath( m_PcbLastPath[ LAST_PATH_NETLIST ] );
  426. updatePath( m_PcbLastPath[ LAST_PATH_STEP ] );
  427. updatePath( m_PcbLastPath[ LAST_PATH_IDF ] );
  428. updatePath( m_PcbLastPath[ LAST_PATH_VRML ] );
  429. updatePath( m_PcbLastPath[ LAST_PATH_SPECCTRADSN ] );
  430. updatePath( m_PcbLastPath[ LAST_PATH_GENCAD ] );
  431. // While performing Save As, we have already checked that we can write to the directory
  432. // so don't carry the previous flag
  433. SetReadOnly( false );
  434. return JSON_SETTINGS::SaveToFile( aDirectory, true );
  435. }
  436. wxString PROJECT_FILE::getFileExt() const
  437. {
  438. return ProjectFileExtension;
  439. }
  440. wxString PROJECT_FILE::getLegacyFileExt() const
  441. {
  442. return LegacyProjectFileExtension;
  443. }
  444. void to_json( nlohmann::json& aJson, const FILE_INFO_PAIR& aPair )
  445. {
  446. aJson = nlohmann::json::array( { aPair.first.AsString().ToUTF8(), aPair.second.ToUTF8() } );
  447. }
  448. void from_json( const nlohmann::json& aJson, FILE_INFO_PAIR& aPair )
  449. {
  450. wxCHECK( aJson.is_array() && aJson.size() == 2, /* void */ );
  451. aPair.first = KIID( wxString( aJson[0].get<std::string>().c_str(), wxConvUTF8 ) );
  452. aPair.second = wxString( aJson[1].get<std::string>().c_str(), wxConvUTF8 );
  453. }