Migrate net names in netclass info.

Fixes https://gitlab.com/kicad/code/kicad/issues/8606
This commit is contained in:
Jeff Young 2021-06-15 00:16:34 +01:00
parent 38312f0aca
commit abc5a6e775
2 changed files with 31 additions and 2 deletions

View File

@ -21,14 +21,17 @@
#include <nlohmann/json.hpp>
#include <project/net_settings.h>
#include <settings/parameters.h>
#include <settings/json_settings_internals.h>
#include <settings/settings_manager.h>
#include <kicad_string.h>
#include <convert_to_biu.h>
const int netSettingsSchemaVersion = 0;
// const int netSettingsSchemaVersion = 0;
const int netSettingsSchemaVersion = 1; // new overbar syntax
static OPT<int> 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<wxString>() ) );
netClass.value()["nets"] = migrated;
}
}
}
return true;
}
const wxString& NET_SETTINGS::GetNetclassName( const wxString& aNetName ) const
{
static wxString defaultNetname = NETCLASS::Default;

View File

@ -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