7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-21 00:21:25 +00:00

Migrate legacy layer presets to V9

Fixes https://gitlab.com/kicad/code/kicad/-/issues/18718
This commit is contained in:
Jon Evans 2024-11-16 09:27:31 -05:00
parent 0d9f49ee2e
commit 4dbe295e80
8 changed files with 127 additions and 3 deletions

View File

@ -18,6 +18,7 @@
*/
#include <layer_ids.h>
#include <magic_enum.hpp>
#include <wx/translation.h>
/**
@ -252,3 +253,53 @@ PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayerId, int aCopperLayersCount )
return aLayerId;
}
}
PCB_LAYER_ID BoardLayerFromLegacyId( int aLegacyId )
{
switch( aLegacyId )
{
case 0: return F_Cu;
case 31: return B_Cu;
default:
if( aLegacyId < 0 )
return magic_enum::enum_cast<PCB_LAYER_ID>( aLegacyId ).value_or( UNDEFINED_LAYER );
if( aLegacyId < 31 )
return static_cast<PCB_LAYER_ID>( In1_Cu + ( aLegacyId - 1 ) * 2 );
switch( aLegacyId )
{
case 32: return B_Adhes;
case 33: return F_Adhes;
case 34: return B_Paste;
case 35: return F_Paste;
case 36: return B_SilkS;
case 37: return F_SilkS;
case 38: return B_Mask;
case 39: return F_Mask;
case 40: return Dwgs_User;
case 41: return Cmts_User;
case 42: return Eco1_User;
case 43: return Eco2_User;
case 44: return Edge_Cuts;
case 45: return Margin;
case 46: return B_CrtYd;
case 47: return F_CrtYd;
case 48: return B_Fab;
case 49: return F_Fab;
case 50: return User_1;
case 51: return User_2;
case 52: return User_3;
case 53: return User_4;
case 54: return User_5;
case 55: return User_6;
case 56: return User_7;
case 57: return User_8;
case 58: return User_9;
case 59: return Rescue;
default: return UNDEFINED_LAYER;
}
}
}

View File

@ -132,6 +132,23 @@ void PARAM_LAYER_PRESET::jsonToPresets( const nlohmann::json& aJson )
}
void PARAM_LAYER_PRESET::MigrateToV9Layers( nlohmann::json& aJson )
{
if( !aJson.is_object() || !aJson.contains( "layers" ) )
return;
std::vector<int> newLayers;
for( const nlohmann::json& layer : aJson.at( "layers" ) )
{
wxCHECK2( layer.is_number_integer(), continue );
newLayers.emplace_back( BoardLayerFromLegacyId( layer.get<int>() ) );
}
aJson["layers"] = newLayers;
}
PARAM_VIEWPORT::PARAM_VIEWPORT( const std::string& aPath, std::vector<VIEWPORT>* aViewportList ) :
PARAM_LAMBDA<nlohmann::json>( aPath,
std::bind( &PARAM_VIEWPORT::viewportsToJson, this ),
@ -368,4 +385,4 @@ void PARAM_LAYER_PAIRS::jsonToLayerPairs( const nlohmann::json& aJson )
m_layerPairInfos.emplace_back( LAYER_PAIR_INFO( pair, enabled, std::move( name ) ) );
}
}
}
}

View File

@ -31,7 +31,7 @@
///! Update the schema version whenever a migration is required
const int projectFileSchemaVersion = 1;
const int projectFileSchemaVersion = 2;
PROJECT_FILE::PROJECT_FILE( const wxString& aFullPath ) :
@ -140,6 +140,28 @@ PROJECT_FILE::PROJECT_FILE( const wxString& aFullPath ) :
m_params.emplace_back( new PARAM<wxString>( "board.ipc2581.dist",
&m_IP2581Bom.dist, wxEmptyString ) );
registerMigration( 1, 2, std::bind( &PROJECT_FILE::migrateSchema1To2, this ) );
}
/**
* Schema version 2: Bump for KiCad 9 layer numbering changes
* Migrate layer presets to use new enum values for copper layers
*/
bool PROJECT_FILE::migrateSchema1To2()
{
auto p( "/board/layer_presets"_json_pointer );
if( !m_internals->contains( p ) || !m_internals->at( p ).is_array() )
return true;
nlohmann::json& presets = m_internals->at( p );
for( nlohmann::json& entry : presets )
PARAM_LAYER_PRESET::MigrateToV9Layers( entry );
return true;
}

View File

@ -97,6 +97,8 @@ protected:
private:
bool migrateSchema0to1();
bool migrateSchema2To3();
};

View File

@ -749,6 +749,12 @@ inline size_t CopperLayerToOrdinal( PCB_LAYER_ID aLayer )
}
/**
* Retrieves a layer ID from an integer converted from a legacy (pre-V9) enum value
*/
KICOMMON_API PCB_LAYER_ID BoardLayerFromLegacyId( int aLegacyId );
KICOMMON_API PCB_LAYER_ID ToLAYER_ID( int aLayer );
#endif // LAYER_IDS_H

View File

@ -190,6 +190,8 @@ class KICOMMON_API PARAM_LAYER_PRESET : public PARAM_LAMBDA<nlohmann::json>
public:
PARAM_LAYER_PRESET( const std::string& aPath, std::vector<LAYER_PRESET>* aPresetList );
static void MigrateToV9Layers( nlohmann::json& aJson );
private:
nlohmann::json presetsToJson();

View File

@ -186,6 +186,8 @@ public:
struct IP2581_BOM m_IP2581Bom; /// IPC-2581 BOM settings
private:
bool migrateSchema1To2();
/// An list of schematic sheets in this project
std::vector<FILE_INFO_PAIR> m_sheets;

View File

@ -35,7 +35,7 @@
///! Update the schema version whenever a migration is required
const int fpEditSchemaVersion = 2;
const int fpEditSchemaVersion = 3;
FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS() :
@ -333,6 +333,8 @@ FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS() :
// This is actually a migration for APP_SETTINGS_BASE::m_LibTree
return migrateLibTreeWidth();
} );
registerMigration( 2, 3, std::bind( &FOOTPRINT_EDITOR_SETTINGS::migrateSchema2To3, this ) );
}
@ -487,3 +489,23 @@ bool FOOTPRINT_EDITOR_SETTINGS::migrateSchema0to1()
return true;
}
/**
* Schema version 2: Bump for KiCad 9 layer numbering changes
* Migrate layer presets to use new enum values for copper layers
*/
bool FOOTPRINT_EDITOR_SETTINGS::migrateSchema2To3()
{
auto p( "/pcb_display/layer_presets"_json_pointer );
if( !m_internals->contains( p ) || !m_internals->at( p ).is_array() )
return true;
nlohmann::json& presets = m_internals->at( p );
for( nlohmann::json& entry : presets )
PARAM_LAYER_PRESET::MigrateToV9Layers( entry );
return true;
}