7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-03-30 05:26:55 +00:00

Fix footprint defaults setting storage after layer ID changes

Fixes https://gitlab.com/kicad/code/kicad/-/issues/19873
This commit is contained in:
Jon Evans 2025-02-07 08:40:11 -05:00
parent 1ecf1d97ae
commit 1911cfe61b
5 changed files with 74 additions and 19 deletions

View File

@ -210,11 +210,11 @@ enum
struct TEXT_ITEM_INFO
{
wxString m_Text;
bool m_Visible;
int m_Layer;
wxString m_Text;
bool m_Visible;
PCB_LAYER_ID m_Layer;
TEXT_ITEM_INFO( const wxString& aText, bool aVisible, int aLayer )
TEXT_ITEM_INFO( const wxString& aText, bool aVisible, PCB_LAYER_ID aLayer )
{
m_Text = aText;
m_Visible = aVisible;

View File

@ -101,6 +101,8 @@ private:
bool migrateSchema2To3();
bool migrateSchema3To4();
bool migrateSchema4To5();
};

View File

@ -82,7 +82,7 @@ public:
void SetValueAsLong( int row, int col, long value ) override
{
if( col == 0 )
m_items[row].m_Layer = static_cast<int>( value );
m_items[row].m_Layer = static_cast<PCB_LAYER_ID>( value );
}
bool AppendRows( size_t aNumRows = 1 ) override
@ -102,7 +102,7 @@ public:
if( IsUserLayer( static_cast<PCB_LAYER_ID>( layer ) ) )
{
layers.insert( layer );
m_items.emplace_back( wxT( "" ), true, layer );
m_items.emplace_back( wxT( "" ), true, static_cast<PCB_LAYER_ID>( layer ) );
}
else
{
@ -205,7 +205,7 @@ public:
void SetValueAsLong( int row, int col, long value ) override
{
if( col == 2 )
m_items[row].m_Layer = (int) value;
m_items[row].m_Layer = static_cast<PCB_LAYER_ID>( value );
}
bool AppendRows( size_t aNumRows = 1 ) override
@ -405,8 +405,8 @@ bool PANEL_FP_EDITOR_FIELD_DEFAULTS::TransferDataFromWindow()
for( int i : { REFERENCE_FIELD, VALUE_FIELD } )
{
wxString text = table->GetValue( i, 0 );
bool visible = table->GetValueAsBool( i, 1 );
int layer = (int) table->GetValueAsLong( i, 2 );
bool visible = table->GetValueAsBool( i, 1 );
PCB_LAYER_ID layer = static_cast<PCB_LAYER_ID>( table->GetValueAsLong( i, 2 ) );
cfg.m_DefaultFPTextItems.emplace_back( text, visible, layer );
}
@ -416,8 +416,8 @@ bool PANEL_FP_EDITOR_FIELD_DEFAULTS::TransferDataFromWindow()
for( int i = 0; i < m_textItemsGrid->GetNumberRows(); ++i )
{
wxString text = table->GetValue( i, 0 );
bool visible = table->GetValueAsBool( i, 1 );
int layer = (int) table->GetValueAsLong( i, 2 );
bool visible = table->GetValueAsBool( i, 1 );
PCB_LAYER_ID layer = static_cast<PCB_LAYER_ID>( table->GetValueAsLong( i, 2 ) );
cfg.m_DefaultFPTextItems.emplace_back( text, visible, layer );
}

View File

@ -37,7 +37,7 @@
///! Update the schema version whenever a migration is required
const int fpEditSchemaVersion = 4;
const int fpEditSchemaVersion = 5;
FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS() :
@ -156,7 +156,7 @@ FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS() :
{
js.push_back( nlohmann::json( { item.m_Text.ToUTF8(),
item.m_Visible,
item.m_Layer } ) );
LSET::Name( item.m_Layer ) } ) );
}
return js;
@ -177,15 +177,19 @@ FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS() :
textInfo.m_Text = entry.at(0).get<wxString>();
textInfo.m_Visible = entry.at(1).get<bool>();
textInfo.m_Layer = entry.at(2).get<int>();
wxString layerName = entry.at(2).get<wxString>();
int candidateLayer = LSET::NameToLayer( layerName );
textInfo.m_Layer = candidateLayer >= 0
? static_cast<PCB_LAYER_ID>(candidateLayer)
: F_SilkS;
m_DesignSettings.m_DefaultFPTextItems.push_back( std::move( textInfo ) );
}
},
nlohmann::json::array( {
{ "REF**", true, F_SilkS },
{ "", true, F_Fab },
{ "${REFERENCE}", true, F_Fab }
{ "REF**", true, LSET::Name( F_SilkS ) },
{ "", true, LSET::Name( F_Fab ) },
{ "${REFERENCE}", true, LSET::Name( F_Fab ) }
} ) ) );
m_params.emplace_back( new PARAM_MAP<wxString>( "design_settings.default_footprint_layer_names",
@ -377,6 +381,7 @@ FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS() :
registerMigration( 2, 3, std::bind( &FOOTPRINT_EDITOR_SETTINGS::migrateSchema2To3, this ) );
registerMigration( 3, 4, std::bind( &FOOTPRINT_EDITOR_SETTINGS::migrateSchema3To4, this ) );
registerMigration( 4, 5, std::bind( &FOOTPRINT_EDITOR_SETTINGS::migrateSchema4To5, this ) );
}
@ -569,3 +574,51 @@ bool FOOTPRINT_EDITOR_SETTINGS::migrateSchema3To4()
return true;
}
/**
* Schema version 5: move text defaults to used named layers
*/
bool FOOTPRINT_EDITOR_SETTINGS::migrateSchema4To5 ()
{
auto p( "/design_settings/default_footprint_text_items"_json_pointer );
if( !m_internals->contains( p ) || !m_internals->at( p ).is_array() )
return true;
nlohmann::json& defaults = m_internals->at( p );
bool reset = false;
for( nlohmann::json& entry : defaults )
{
TEXT_ITEM_INFO textInfo( wxT( "" ), true, F_SilkS );
textInfo.m_Text = entry.at(0).get<wxString>();
textInfo.m_Visible = entry.at(1).get<bool>();
textInfo.m_Layer = static_cast<PCB_LAYER_ID>( entry.at(2).get<int>() );
if( textInfo.m_Layer == Rescue || textInfo.m_Layer >= User_5 )
{
// KiCad pre-9.0 nightlies would write buggy preferences out with invalid layers.
// If we detect that, reset to defaults
reset = true;
}
else
{
// Coming from 8.0 or earlier, just migrate to named layers
entry.at(2) = LSET::Name( textInfo.m_Layer );
}
}
if( reset )
{
defaults = nlohmann::json::array( {
{ "REF**", true, LSET::Name( F_SilkS ) },
{ "", true, LSET::Name( F_Fab ) },
{ "${REFERENCE}", true, LSET::Name( F_Fab ) }
} );
}
return true;
}

View File

@ -1282,7 +1282,7 @@ FOOTPRINT* PCB_BASE_FRAME::CreateNewFootprint( wxString aFootprintName, const wx
footprint->Reference().SetText( settings.m_DefaultFPTextItems[0].m_Text );
footprint->Reference().SetVisible( settings.m_DefaultFPTextItems[0].m_Visible );
txt_layer = (PCB_LAYER_ID) settings.m_DefaultFPTextItems[0].m_Layer;
txt_layer = settings.m_DefaultFPTextItems[0].m_Layer;
footprint->Reference().SetLayer( txt_layer );
default_pos.y -= settings.GetTextSize( txt_layer ).y / 2;
footprint->Reference().SetPosition( default_pos );
@ -1290,7 +1290,7 @@ FOOTPRINT* PCB_BASE_FRAME::CreateNewFootprint( wxString aFootprintName, const wx
footprint->Value().SetText( settings.m_DefaultFPTextItems[1].m_Text );
footprint->Value().SetVisible( settings.m_DefaultFPTextItems[1].m_Visible );
txt_layer = (PCB_LAYER_ID) settings.m_DefaultFPTextItems[1].m_Layer;
txt_layer = settings.m_DefaultFPTextItems[1].m_Layer;
footprint->Value().SetLayer( txt_layer );
default_pos.y += settings.GetTextSize( txt_layer ).y / 2;
footprint->Value().SetPosition( default_pos );