diff --git a/common/project/net_settings.cpp b/common/project/net_settings.cpp index 110ff2c18d..190dacb860 100644 --- a/common/project/net_settings.cpp +++ b/common/project/net_settings.cpp @@ -21,14 +21,17 @@ #include + #include #include +#include #include #include #include -const int netSettingsSchemaVersion = 0; +// const int netSettingsSchemaVersion = 0; +const int netSettingsSchemaVersion = 1; // new overbar syntax static OPT getInPcbUnits( const nlohmann::json& aObj, const std::string& aKey, @@ -245,6 +248,8 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) : } }, {} ) ); + + registerMigration( 0, 1, std::bind( &NET_SETTINGS::migrateSchema0to1, this ) ); } @@ -259,6 +264,28 @@ NET_SETTINGS::~NET_SETTINGS() } +bool NET_SETTINGS::migrateSchema0to1() +{ + if( m_internals->contains( "classes" ) && m_internals->At( "classes" ).is_array() ) + { + for( auto& netClass : m_internals->At( "classes" ).items() ) + { + if( netClass.value().contains( "nets" ) && netClass.value()["nets"].is_array() ) + { + nlohmann::json migrated = nlohmann::json::array(); + + for( auto& net : netClass.value()["nets"].items() ) + migrated.push_back( ConvertToNewOverbarNotation( net.value().get() ) ); + + netClass.value()["nets"] = migrated; + } + } + } + + return true; +} + + const wxString& NET_SETTINGS::GetNetclassName( const wxString& aNetName ) const { static wxString defaultNetname = NETCLASS::Default; diff --git a/include/project/net_settings.h b/include/project/net_settings.h index 12ca712cf4..6fd7484442 100644 --- a/include/project/net_settings.h +++ b/include/project/net_settings.h @@ -88,7 +88,9 @@ public: void ResolveNetClassAssignments( bool aRebuildFromScratch = false ); private: - // TODO: Add diff pairs, bus information, etc here. + bool migrateSchema0to1(); + + // TODO: Add diff pairs, bus information, etc. }; #endif // KICAD_NET_SETTINGS_H