mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 10:13:19 +02:00
Fix footprint defaults setting storage after layer ID changes
Fixes https://gitlab.com/kicad/code/kicad/-/issues/19873
This commit is contained in:
parent
1ecf1d97ae
commit
1911cfe61b
@ -210,11 +210,11 @@ enum
|
|||||||
|
|
||||||
struct TEXT_ITEM_INFO
|
struct TEXT_ITEM_INFO
|
||||||
{
|
{
|
||||||
wxString m_Text;
|
wxString m_Text;
|
||||||
bool m_Visible;
|
bool m_Visible;
|
||||||
int m_Layer;
|
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_Text = aText;
|
||||||
m_Visible = aVisible;
|
m_Visible = aVisible;
|
||||||
|
@ -101,6 +101,8 @@ private:
|
|||||||
bool migrateSchema2To3();
|
bool migrateSchema2To3();
|
||||||
|
|
||||||
bool migrateSchema3To4();
|
bool migrateSchema3To4();
|
||||||
|
|
||||||
|
bool migrateSchema4To5();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ public:
|
|||||||
void SetValueAsLong( int row, int col, long value ) override
|
void SetValueAsLong( int row, int col, long value ) override
|
||||||
{
|
{
|
||||||
if( col == 0 )
|
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
|
bool AppendRows( size_t aNumRows = 1 ) override
|
||||||
@ -102,7 +102,7 @@ public:
|
|||||||
if( IsUserLayer( static_cast<PCB_LAYER_ID>( layer ) ) )
|
if( IsUserLayer( static_cast<PCB_LAYER_ID>( layer ) ) )
|
||||||
{
|
{
|
||||||
layers.insert( layer );
|
layers.insert( layer );
|
||||||
m_items.emplace_back( wxT( "" ), true, layer );
|
m_items.emplace_back( wxT( "" ), true, static_cast<PCB_LAYER_ID>( layer ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -205,7 +205,7 @@ public:
|
|||||||
void SetValueAsLong( int row, int col, long value ) override
|
void SetValueAsLong( int row, int col, long value ) override
|
||||||
{
|
{
|
||||||
if( col == 2 )
|
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
|
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 } )
|
for( int i : { REFERENCE_FIELD, VALUE_FIELD } )
|
||||||
{
|
{
|
||||||
wxString text = table->GetValue( i, 0 );
|
wxString text = table->GetValue( i, 0 );
|
||||||
bool visible = table->GetValueAsBool( i, 1 );
|
bool visible = table->GetValueAsBool( i, 1 );
|
||||||
int layer = (int) table->GetValueAsLong( i, 2 );
|
PCB_LAYER_ID layer = static_cast<PCB_LAYER_ID>( table->GetValueAsLong( i, 2 ) );
|
||||||
|
|
||||||
cfg.m_DefaultFPTextItems.emplace_back( text, visible, layer );
|
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 )
|
for( int i = 0; i < m_textItemsGrid->GetNumberRows(); ++i )
|
||||||
{
|
{
|
||||||
wxString text = table->GetValue( i, 0 );
|
wxString text = table->GetValue( i, 0 );
|
||||||
bool visible = table->GetValueAsBool( i, 1 );
|
bool visible = table->GetValueAsBool( i, 1 );
|
||||||
int layer = (int) table->GetValueAsLong( i, 2 );
|
PCB_LAYER_ID layer = static_cast<PCB_LAYER_ID>( table->GetValueAsLong( i, 2 ) );
|
||||||
|
|
||||||
cfg.m_DefaultFPTextItems.emplace_back( text, visible, layer );
|
cfg.m_DefaultFPTextItems.emplace_back( text, visible, layer );
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
|
|
||||||
///! Update the schema version whenever a migration is required
|
///! Update the schema version whenever a migration is required
|
||||||
const int fpEditSchemaVersion = 4;
|
const int fpEditSchemaVersion = 5;
|
||||||
|
|
||||||
|
|
||||||
FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS() :
|
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(),
|
js.push_back( nlohmann::json( { item.m_Text.ToUTF8(),
|
||||||
item.m_Visible,
|
item.m_Visible,
|
||||||
item.m_Layer } ) );
|
LSET::Name( item.m_Layer ) } ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return js;
|
return js;
|
||||||
@ -177,15 +177,19 @@ FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS() :
|
|||||||
|
|
||||||
textInfo.m_Text = entry.at(0).get<wxString>();
|
textInfo.m_Text = entry.at(0).get<wxString>();
|
||||||
textInfo.m_Visible = entry.at(1).get<bool>();
|
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 ) );
|
m_DesignSettings.m_DefaultFPTextItems.push_back( std::move( textInfo ) );
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
nlohmann::json::array( {
|
nlohmann::json::array( {
|
||||||
{ "REF**", true, F_SilkS },
|
{ "REF**", true, LSET::Name( F_SilkS ) },
|
||||||
{ "", true, F_Fab },
|
{ "", true, LSET::Name( F_Fab ) },
|
||||||
{ "${REFERENCE}", true, F_Fab }
|
{ "${REFERENCE}", true, LSET::Name( F_Fab ) }
|
||||||
} ) ) );
|
} ) ) );
|
||||||
|
|
||||||
m_params.emplace_back( new PARAM_MAP<wxString>( "design_settings.default_footprint_layer_names",
|
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( 2, 3, std::bind( &FOOTPRINT_EDITOR_SETTINGS::migrateSchema2To3, this ) );
|
||||||
registerMigration( 3, 4, std::bind( &FOOTPRINT_EDITOR_SETTINGS::migrateSchema3To4, 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;
|
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;
|
||||||
|
}
|
||||||
|
@ -1282,7 +1282,7 @@ FOOTPRINT* PCB_BASE_FRAME::CreateNewFootprint( wxString aFootprintName, const wx
|
|||||||
|
|
||||||
footprint->Reference().SetText( settings.m_DefaultFPTextItems[0].m_Text );
|
footprint->Reference().SetText( settings.m_DefaultFPTextItems[0].m_Text );
|
||||||
footprint->Reference().SetVisible( settings.m_DefaultFPTextItems[0].m_Visible );
|
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 );
|
footprint->Reference().SetLayer( txt_layer );
|
||||||
default_pos.y -= settings.GetTextSize( txt_layer ).y / 2;
|
default_pos.y -= settings.GetTextSize( txt_layer ).y / 2;
|
||||||
footprint->Reference().SetPosition( default_pos );
|
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().SetText( settings.m_DefaultFPTextItems[1].m_Text );
|
||||||
footprint->Value().SetVisible( settings.m_DefaultFPTextItems[1].m_Visible );
|
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 );
|
footprint->Value().SetLayer( txt_layer );
|
||||||
default_pos.y += settings.GetTextSize( txt_layer ).y / 2;
|
default_pos.y += settings.GetTextSize( txt_layer ).y / 2;
|
||||||
footprint->Value().SetPosition( default_pos );
|
footprint->Value().SetPosition( default_pos );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user