39 m_ErcSettings( nullptr ),
40 m_SchematicSettings( nullptr ),
45 m_wasMigrated( false )
100 [&]() -> nlohmann::json
102 nlohmann::json ret = nlohmann::json::array();
105 ret.push_back( libName );
109 [&](
const nlohmann::json& aJson )
111 if( aJson.empty() || !aJson.is_array() )
116 for(
const nlohmann::json& entry : aJson )
120 m_NetSettings = std::make_shared<NET_SETTINGS>(
this,
"net_settings" );
152 auto p(
"/board/layer_presets"_json_pointer );
159 for( nlohmann::json& entry : presets )
170 auto p(
"/board/layer_presets"_json_pointer );
177 for( nlohmann::json& entry : presets )
192 std::set<wxString> group_blacklist;
199 auto loadPinnedLibs =
200 [&](
const std::string& aDest )
203 wxString libKey = wxT(
"PinnedItems" );
206 nlohmann::json libs = nlohmann::json::array();
208 while( aCfg->Read( libKey, &str ) )
210 libs.push_back( str );
212 aCfg->DeleteEntry( libKey,
true );
214 libKey = wxT(
"PinnedItems" );
215 libKey << ++libIndex;
221 aCfg->SetPath( wxT(
"/LibeditFrame" ) );
222 loadPinnedLibs(
"libraries.pinned_symbol_libs" );
224 aCfg->SetPath( wxT(
"/ModEditFrame" ) );
225 loadPinnedLibs(
"libraries.pinned_footprint_libs" );
227 aCfg->SetPath( wxT(
"/cvpcb/equfiles" ) );
231 wxString eqKey = wxT(
"EquName" );
234 nlohmann::json eqs = nlohmann::json::array();
236 while( aCfg->Read( eqKey, &str ) )
238 eqs.push_back( str );
240 eqKey = wxT(
"EquName" );
244 Set(
"cvpcb.equivalence_files", eqs );
248 group_blacklist.insert( wxT(
"/cvpcb" ) );
250 aCfg->SetPath( wxT(
"/eeschema" ) );
253 aCfg->SetPath( wxT(
"/eeschema/libraries" ) );
257 wxString libKey = wxT(
"LibName" );
260 nlohmann::json libs = nlohmann::json::array();
262 while( aCfg->Read( libKey, &str ) )
264 libs.push_back( str );
266 libKey = wxT(
"LibName" );
270 Set(
"schematic.legacy_lib_list", libs );
273 group_blacklist.insert( wxT(
"/eeschema" ) );
275 aCfg->SetPath( wxT(
"/text_variables" ) );
282 nlohmann::json vars = nlohmann::json();
284 while( aCfg->Read( txtKey, &str ) )
286 wxArrayString tokens = wxSplit( str,
':' );
288 if( tokens.size() == 2 )
289 vars[ tokens[0].ToStdString() ] = tokens[1];
295 Set(
"text_variables", vars );
298 group_blacklist.insert( wxT(
"/text_variables" ) );
300 aCfg->SetPath( wxT(
"/schematic_editor" ) );
302 fromLegacyString( aCfg,
"PageLayoutDescrFile",
"schematic.page_layout_descr_file" );
305 fromLegacy<bool>( aCfg,
"SpiceAjustPassiveValues",
"schematic.spice_adjust_passive_values" );
306 fromLegacy<int>( aCfg,
"SubpartIdSeparator",
"schematic.subpart_id_separator" );
307 fromLegacy<int>( aCfg,
"SubpartFirstId",
"schematic.subpart_first_id" );
309 fromLegacy<int>( aCfg,
"LineThickness",
"schematic.drawing.default_line_thickness" );
310 fromLegacy<int>( aCfg,
"WireThickness",
"schematic.drawing.default_wire_thickness" );
311 fromLegacy<int>( aCfg,
"BusThickness",
"schematic.drawing.default_bus_thickness" );
312 fromLegacy<int>( aCfg,
"LabSize",
"schematic.drawing.default_text_size" );
314 if( !fromLegacy<int>( aCfg,
"PinSymbolSize",
"schematic.drawing.pin_symbol_size" ) )
317 Set(
"schematic.drawing.pin_symbol_size", 0 );
320 fromLegacy<int>( aCfg,
"JunctionSize",
"schematic.drawing.default_junction_size" );
322 fromLegacyString( aCfg,
"FieldNameTemplates",
"schematic.drawing.field_names" );
324 if( !fromLegacy<double>( aCfg,
"TextOffsetRatio",
"schematic.drawing.text_offset_ratio" ) )
327 Set(
"schematic.drawing.text_offset_ratio", 0.08 );
328 Set(
"schematic.drawing.label_size_ratio", 0.25 );
332 group_blacklist.insert( wxT(
"/schematic_editor" ) );
334 aCfg->SetPath( wxT(
"/pcbnew" ) );
336 fromLegacyString( aCfg,
"PageLayoutDescrFile",
"pcbnew.page_layout_descr_file" );
341 fromLegacyString( aCfg,
"LastSpecctraDSNExportPath",
"pcbnew.last_paths.specctra_dsn" );
342 fromLegacyString( aCfg,
"LastGenCADExportPath",
"pcbnew.last_paths.gencad" );
344 std::string bp =
"board.design_settings.";
348 wxString key = wxT(
"DRCExclusion" );
351 nlohmann::json exclusions = nlohmann::json::array();
353 while( aCfg->Read( key, &str ) )
355 exclusions.push_back( str );
357 key = wxT(
"DRCExclusion" );
361 Set( bp +
"drc_exclusions", exclusions );
364 fromLegacy<bool>( aCfg,
"AllowMicroVias", bp +
"rules.allow_microvias" );
365 fromLegacy<bool>( aCfg,
"AllowBlindVias", bp +
"rules.allow_blind_buried_vias" );
366 fromLegacy<double>( aCfg,
"MinClearance", bp +
"rules.min_clearance" );
367 fromLegacy<double>( aCfg,
"MinTrackWidth", bp +
"rules.min_track_width" );
368 fromLegacy<double>( aCfg,
"MinViaAnnulus", bp +
"rules.min_via_annulus" );
369 fromLegacy<double>( aCfg,
"MinViaDiameter", bp +
"rules.min_via_diameter" );
371 if( !fromLegacy<double>( aCfg,
"MinThroughDrill", bp +
"rules.min_through_hole_diameter" ) )
372 fromLegacy<double>( aCfg,
"MinViaDrill", bp +
"rules.min_through_hole_diameter" );
374 fromLegacy<double>( aCfg,
"MinMicroViaDiameter", bp +
"rules.min_microvia_diameter" );
375 fromLegacy<double>( aCfg,
"MinMicroViaDrill", bp +
"rules.min_microvia_drill" );
376 fromLegacy<double>( aCfg,
"MinHoleToHole", bp +
"rules.min_hole_to_hole" );
377 fromLegacy<double>( aCfg,
"CopperEdgeClearance", bp +
"rules.min_copper_edge_clearance" );
378 fromLegacy<double>( aCfg,
"SolderMaskClearance", bp +
"rules.solder_mask_clearance" );
379 fromLegacy<double>( aCfg,
"SolderMaskMinWidth", bp +
"rules.solder_mask_min_width" );
380 fromLegacy<double>( aCfg,
"SolderPasteClearance", bp +
"rules.solder_paste_clearance" );
381 fromLegacy<double>( aCfg,
"SolderPasteRatio", bp +
"rules.solder_paste_margin_ratio" );
383 if( !fromLegacy<double>( aCfg,
"SilkLineWidth", bp +
"defaults.silk_line_width" ) )
384 fromLegacy<double>( aCfg,
"ModuleOutlineThickness", bp +
"defaults.silk_line_width" );
386 if( !fromLegacy<double>( aCfg,
"SilkTextSizeV", bp +
"defaults.silk_text_size_v" ) )
387 fromLegacy<double>( aCfg,
"ModuleTextSizeV", bp +
"defaults.silk_text_size_v" );
389 if( !fromLegacy<double>( aCfg,
"SilkTextSizeH", bp +
"defaults.silk_text_size_h" ) )
390 fromLegacy<double>( aCfg,
"ModuleTextSizeH", bp +
"defaults.silk_text_size_h" );
392 if( !fromLegacy<double>( aCfg,
"SilkTextSizeThickness", bp +
"defaults.silk_text_thickness" ) )
393 fromLegacy<double>( aCfg,
"ModuleTextSizeThickness", bp +
"defaults.silk_text_thickness" );
395 fromLegacy<bool>( aCfg,
"SilkTextItalic", bp +
"defaults.silk_text_italic" );
396 fromLegacy<bool>( aCfg,
"SilkTextUpright", bp +
"defaults.silk_text_upright" );
398 if( !fromLegacy<double>( aCfg,
"CopperLineWidth", bp +
"defaults.copper_line_width" ) )
399 fromLegacy<double>( aCfg,
"DrawSegmentWidth", bp +
"defaults.copper_line_width" );
401 if( !fromLegacy<double>( aCfg,
"CopperTextSizeV", bp +
"defaults.copper_text_size_v" ) )
402 fromLegacy<double>( aCfg,
"PcbTextSizeV", bp +
"defaults.copper_text_size_v" );
404 if( !fromLegacy<double>( aCfg,
"CopperTextSizeH", bp +
"defaults.copper_text_size_h" ) )
405 fromLegacy<double>( aCfg,
"PcbTextSizeH", bp +
"defaults.copper_text_size_h" );
407 if( !fromLegacy<double>( aCfg,
"CopperTextThickness", bp +
"defaults.copper_text_thickness" ) )
408 fromLegacy<double>( aCfg,
"PcbTextThickness", bp +
"defaults.copper_text_thickness" );
410 fromLegacy<bool>( aCfg,
"CopperTextItalic", bp +
"defaults.copper_text_italic" );
411 fromLegacy<bool>( aCfg,
"CopperTextUpright", bp +
"defaults.copper_text_upright" );
413 if( !fromLegacy<double>( aCfg,
"EdgeCutLineWidth", bp +
"defaults.board_outline_line_width" ) )
414 fromLegacy<double>( aCfg,
"BoardOutlineThickness",
415 bp +
"defaults.board_outline_line_width" );
417 fromLegacy<double>( aCfg,
"CourtyardLineWidth", bp +
"defaults.courtyard_line_width" );
419 fromLegacy<double>( aCfg,
"FabLineWidth", bp +
"defaults.fab_line_width" );
420 fromLegacy<double>( aCfg,
"FabTextSizeV", bp +
"defaults.fab_text_size_v" );
421 fromLegacy<double>( aCfg,
"FabTextSizeH", bp +
"defaults.fab_text_size_h" );
422 fromLegacy<double>( aCfg,
"FabTextSizeThickness", bp +
"defaults.fab_text_thickness" );
423 fromLegacy<bool>( aCfg,
"FabTextItalic", bp +
"defaults.fab_text_italic" );
424 fromLegacy<bool>( aCfg,
"FabTextUpright", bp +
"defaults.fab_text_upright" );
426 if( !fromLegacy<double>( aCfg,
"OthersLineWidth", bp +
"defaults.other_line_width" ) )
427 fromLegacy<double>( aCfg,
"ModuleOutlineThickness", bp +
"defaults.other_line_width" );
429 fromLegacy<double>( aCfg,
"OthersTextSizeV", bp +
"defaults.other_text_size_v" );
430 fromLegacy<double>( aCfg,
"OthersTextSizeH", bp +
"defaults.other_text_size_h" );
431 fromLegacy<double>( aCfg,
"OthersTextSizeThickness", bp +
"defaults.other_text_thickness" );
432 fromLegacy<bool>( aCfg,
"OthersTextItalic", bp +
"defaults.other_text_italic" );
433 fromLegacy<bool>( aCfg,
"OthersTextUpright", bp +
"defaults.other_text_upright" );
435 fromLegacy<int>( aCfg,
"DimensionUnits", bp +
"defaults.dimension_units" );
436 fromLegacy<int>( aCfg,
"DimensionPrecision", bp +
"defaults.dimension_precision" );
438 std::string sev = bp +
"rule_severities";
440 fromLegacy<bool>( aCfg,
"RequireCourtyardDefinitions", sev +
"legacy_no_courtyard_defined" );
442 fromLegacy<bool>( aCfg,
"ProhibitOverlappingCourtyards", sev +
"legacy_courtyards_overlap" );
446 wxString keyBase =
"TrackWidth";
447 wxString key = keyBase;
450 nlohmann::json widths = nlohmann::json::array();
454 while( aCfg->Read( key, &val ) )
456 widths.push_back( val );
461 Set( bp +
"track_widths", widths );
466 wxString keyBase =
"ViaDiameter";
467 wxString key = keyBase;
471 nlohmann::json vias = nlohmann::json::array();
475 while( aCfg->Read( key, &diameter ) )
478 aCfg->Read( key << idx, &drill );
480 nlohmann::json
via = { {
"diameter", diameter }, {
"drill", drill } };
481 vias.push_back(
via );
487 Set( bp +
"via_dimensions", vias );
492 wxString keyBase =
"dPairWidth";
493 wxString key = keyBase;
496 double via_gap = 1.0;
498 nlohmann::json pairs = nlohmann::json::array();
502 while( aCfg->Read( key, &width ) )
505 aCfg->Read( key << idx, &gap );
508 aCfg->Read( key << idx, &via_gap );
510 nlohmann::json pair = { {
"width", width }, {
"gap", gap }, {
"via_gap", via_gap } };
511 pairs.push_back( pair );
517 Set( bp +
"diff_pair_dimensions", pairs );
520 group_blacklist.insert( wxT(
"/pcbnew" ) );
523 group_blacklist.insert( wxT(
"/general" ) );
526 aCfg->SetPath( wxT(
"/" ) );
528 auto loadSheetNames =
533 nlohmann::json arr = nlohmann::json::array();
537 aCfg->SetPath( wxT(
"/sheetnames" ) );
539 while( aCfg->Read( wxString::Format(
"%d", sheet++ ), &entry ) )
541 wxArrayString tokens = wxSplit( entry,
':' );
543 if( tokens.size() == 2 )
545 wxLogTrace(
traceSettings, wxT(
"%d: %s = %s" ), sheet, tokens[0],
547 arr.push_back( nlohmann::json::array( { tokens[0], tokens[1] } ) );
551 Set(
"sheets", arr );
553 aCfg->SetPath(
"/" );
559 std::vector<wxString> groups;
561 groups.emplace_back( wxEmptyString );
563 auto loadLegacyPairs =
564 [&](
const std::string& aGroup ) ->
bool
566 wxLogTrace(
traceSettings, wxT(
"Migrating group %s" ), aGroup );
573 while( aCfg->GetNextEntry( keyStr, index ) )
575 if( !aCfg->Read( keyStr, &val ) )
578 std::string key( keyStr.ToUTF8() );
584 Set(
"legacy." + aGroup +
"." + key, val );
595 for(
size_t i = 0; i < groups.size(); i++ )
597 aCfg->SetPath( groups[i] );
599 if( groups[i] == wxT(
"/sheetnames" ) )
601 ret |= loadSheetNames();
605 aCfg->DeleteEntry( wxT(
"last_client" ),
true );
606 aCfg->DeleteEntry( wxT(
"update" ),
true );
607 aCfg->DeleteEntry( wxT(
"version" ),
true );
609 ret &= loadLegacyPairs( groups[i].ToStdString() );
613 while( aCfg->GetNextGroup( str, index ) )
615 wxString
group = groups[i] +
"/" + str;
617 if( !group_blacklist.count(
group ) )
618 groups.emplace_back(
group );
621 aCfg->SetPath(
"/" );
648 wxString oldProjectName = oldFilename.GetName();
649 wxString oldProjectPath = oldFilename.GetPath();
655 [&]( wxString& aPath )
657 if( aPath.StartsWith( oldProjectName + wxS(
"." ) ) )
658 aPath.Replace( oldProjectName, aFile,
false );
659 else if( aPath.StartsWith( oldProjectPath + wxS(
"/" ) ) )
660 aPath.Replace( oldProjectPath, aDirectory,
false );
668 auto updatePathByPtr =
669 [&](
const std::string& aPtr )
671 if( std::optional<wxString>
path = Get<wxString>( aPtr ) )
673 updatePath(
path.value() );
678 updatePathByPtr(
"schematic.page_layout_descr_file" );
679 updatePathByPtr(
"schematic.plot_directory" );
680 updatePathByPtr(
"schematic.ngspice.workbook_filename" );
681 updatePathByPtr(
"pcbnew.page_layout_descr_file" );
704 aJson = nlohmann::json::array( { aPair.first.AsString().ToUTF8(), aPair.second.ToUTF8() } );
710 wxCHECK( aJson.is_array() && aJson.size() == 2, );
711 aPair.first =
KIID( wxString( aJson[0].get<std::string>().c_str(), wxConvUTF8 ) );
712 aPair.second = wxString( aJson[1].get<std::string>().c_str(), wxConvUTF8 );
bool fromLegacyString(wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
Translates a legacy wxConfig string 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...
void SetReadOnly(bool aReadOnly)
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
void registerMigration(int aOldSchemaVersion, int aNewSchemaVersion, std::function< bool(void)> aMigrator)
Registers a migration from one schema version to another.
bool m_deleteLegacyAfterMigration
Whether or not to delete legacy file after migration.
std::unique_ptr< JSON_SETTINGS_INTERNALS > m_internals
void SetFilename(const wxString &aFilename)
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
Calls Store() and then writes the contents of the JSON document to a file.
wxString GetFilename() const
Like a normal param, but with custom getter and setter functions.
static void MigrateToV9Layers(nlohmann::json &aJson)
static void MigrateToNamedRenderLayers(nlohmann::json &aJson)
Represents a list of strings holding directory paths.
Stores a path as a string with directory separators normalized to unix-style.
A helper for <wxString, wxString> maps.
std::map< wxString, wxString > m_TextVars
wxString getFileExt() const override
std::vector< LAYER_PAIR_INFO > m_LayerPairInfos
List of stored 3D viewports (view matrixes)
bool migrateSchema1To2()
IPC-2581 BOM settings.
wxString m_BoardDrawingSheetFile
PcbNew params.
std::shared_ptr< NET_SETTINGS > m_NetSettings
Net settings for this project (owned here)
struct IP2581_BOM m_IP2581Bom
Layer pair list for the board.
wxString m_PcbLastPath[LAST_PATH_SIZE]
MRU path storage.
PROJECT * m_project
A link to the owning PROJECT.
std::vector< VIEWPORT > m_Viewports
List of stored layer presets.
bool SaveAs(const wxString &aDirectory, const wxString &aFile)
std::vector< wxString > m_EquivalenceFiles
CvPcb params.
bool migrateSchema2To3()
Schema version 3: move layer presets to use named render layers.
wxString getLegacyFileExt() const override
std::vector< wxString > m_PinnedFootprintLibs
The list of pinned footprint libraries.
std::vector< FILE_INFO_PAIR > m_sheets
An list of schematic sheets in this project.
virtual bool MigrateFromLegacy(wxConfigBase *aCfg) override
Migrates from wxConfig to JSON-based configuration.
std::vector< LAYER_PRESET > m_LayerPresets
std::vector< FILE_INFO_PAIR > m_boards
A list of board files in this project.
wxArrayString m_LegacyLibNames
std::vector< wxString > m_PinnedSymbolLibs
Below are project-level settings that have not been moved to a dedicated file.
std::vector< VIEWPORT3D > m_Viewports3D
List of stored viewports (pos + zoom)
bool SaveToFile(const wxString &aDirectory="", bool aForce=false) override
Calls Store() and then writes the contents of the JSON document to a file.
PROJECT_FILE(const wxString &aFullPath)
Construct the project file for a project.
Container for project specific data.
virtual const wxString GetProjectName() const
Return the short name of the project.
static const std::string ProjectFileExtension
static const std::string LegacyProjectFileExtension
void to_json(nlohmann::json &aJson, const FILE_INFO_PAIR &aPair)
void from_json(const nlohmann::json &aJson, FILE_INFO_PAIR &aPair)
const int projectFileSchemaVersion
! Update the schema version whenever a migration is required
std::pair< KIID, wxString > FILE_INFO_PAIR
For files like sheets and boards, a pair of that object KIID and display name Display name is typical...
wxString mfg
Manufacturer name column.
wxString MPN
Manufacturer part number column.
wxString id
Internal ID column.
wxString dist
Distributor name column.
wxString distPN
Distributor part number column.
Definition of file extensions used in Kicad.