Add option for text updating to Update Symbol.

Fixes https://gitlab.com/kicad/code/kicad/issues/6420
This commit is contained in:
Jeff Young 2021-02-22 00:35:37 +00:00
parent afb4bbde47
commit 781d293b60
9 changed files with 172 additions and 20 deletions

View File

@ -42,6 +42,7 @@ bool g_selectValue = false;
// { change, update }
bool g_removeExtraFields[2] = { false, false };
bool g_resetEmptyFields[2] = { false, false };
bool g_resetFieldText[2] = { true, true };
bool g_resetFieldVisibilities[2] = { true, false };
bool g_resetFieldEffects[2] = { true, false };
bool g_resetFieldPositions[2] = { true, false };
@ -130,13 +131,16 @@ DIALOG_CHANGE_SYMBOLS::DIALOG_CHANGE_SYMBOLS( SCH_EDIT_FRAME* aParent, SCH_COMPO
m_updateFieldsSizer->GetStaticBox()->SetLabel( _( "Update Fields" ) );
m_removeExtraBox->SetLabel( _( "Remove fields if not in new symbol" ) );
m_resetEmptyFields->SetLabel( _( "Reset fields if empty in new symbol" ) );
m_resetFieldText->SetLabel( _( "Update field text" ) );
m_resetFieldVisibilities->SetLabel( _( "Update field visibilities" ) );
m_resetFieldEffects->SetLabel( _( "Update field sizes and styles" ) );
m_resetFieldPositions->SetLabel( _( "Update field positions" ) );
m_resetAttributes->SetLabel( _( "Update symbol attributes" ) );
}
m_removeExtraBox->SetValue( g_removeExtraFields[ (int) m_mode ] );
m_resetEmptyFields->SetValue( g_resetEmptyFields[ (int) m_mode ] );
m_resetFieldText->SetValue( g_resetFieldText[ (int) m_mode ] );
m_resetFieldVisibilities->SetValue( g_resetFieldVisibilities[ (int) m_mode ] );
m_resetFieldEffects->SetValue( g_resetFieldEffects[ (int) m_mode ] );
m_resetFieldPositions->SetValue( g_resetFieldPositions[ (int) m_mode ] );
@ -208,6 +212,7 @@ DIALOG_CHANGE_SYMBOLS::~DIALOG_CHANGE_SYMBOLS()
g_removeExtraFields[ (int) m_mode ] = m_removeExtraBox->GetValue();
g_resetEmptyFields[ (int) m_mode ] = m_resetEmptyFields->GetValue();
g_resetFieldText[ (int) m_mode ] = m_resetFieldText->GetValue();
g_resetFieldVisibilities[ (int) m_mode ] = m_resetFieldVisibilities->GetValue();
g_resetFieldEffects[ (int) m_mode ] = m_resetFieldEffects->GetValue();
g_resetFieldPositions[ (int) m_mode ] = m_resetFieldPositions->GetValue();
@ -281,9 +286,13 @@ void DIALOG_CHANGE_SYMBOLS::updateFieldsList()
for( unsigned i = MANDATORY_FIELDS; i < fields.size(); ++i )
fieldNames.insert( fields[i]->GetName() );
if( m_mode == MODE::UPDATE && symbol->GetPartRef() )
if( m_mode == MODE::UPDATE && symbol->GetLibId().IsValid() )
{
std::unique_ptr<LIB_PART> flattenedPart = symbol->GetPartRef()->Flatten();
LIB_PART* libSymbol = frame->GetLibPart( symbol->GetLibId() );
if( libSymbol )
{
std::unique_ptr<LIB_PART> flattenedPart = libSymbol->Flatten();
flattenedPart->GetFields( libFields );
@ -294,6 +303,7 @@ void DIALOG_CHANGE_SYMBOLS::updateFieldsList()
}
}
}
}
// Load non-mandatory fields from the change-to library part
if( m_mode == MODE::CHANGE )
@ -556,7 +566,6 @@ bool DIALOG_CHANGE_SYMBOLS::processSymbol( SCH_COMPONENT* aSymbol, const SCH_SHE
}
bool removeExtras = m_removeExtraBox->GetValue();
bool resetEmpty = m_resetEmptyFields->GetValue();
bool resetVis = m_resetFieldVisibilities->GetValue();
bool resetEffects = m_resetFieldEffects->GetValue();
bool resetPositions = m_resetFieldPositions->GetValue();
@ -576,7 +585,10 @@ bool DIALOG_CHANGE_SYMBOLS::processSymbol( SCH_COMPONENT* aSymbol, const SCH_SHE
if( libField )
{
if( !libField->GetText().IsEmpty() || resetEmpty )
bool resetText = libField->GetText().IsEmpty() ? m_resetEmptyFields->GetValue()
: m_resetFieldText->GetValue();
if( resetText )
{
if( i == REFERENCE_FIELD )
aSymbol->SetRef( aInstance, libField->GetText() );

View File

@ -125,7 +125,10 @@ DIALOG_CHANGE_SYMBOLS_BASE::DIALOG_CHANGE_SYMBOLS_BASE( wxWindow* parent, wxWind
m_updateOptionsSizer->Add( m_resetEmptyFields, 0, wxBOTTOM|wxRIGHT, 4 );
m_updateOptionsSizer->Add( 0, 15, 0, wxEXPAND, 5 );
m_updateOptionsSizer->Add( 0, 10, 0, wxEXPAND, 5 );
m_resetFieldText = new wxCheckBox( m_updateOptionsSizer->GetStaticBox(), wxID_ANY, _("Update/reset field text"), wxDefaultPosition, wxDefaultSize, 0 );
m_updateOptionsSizer->Add( m_resetFieldText, 0, wxBOTTOM|wxRIGHT, 4 );
m_resetFieldVisibilities = new wxCheckBox( m_updateOptionsSizer->GetStaticBox(), wxID_ANY, _("Update/reset field visibilities"), wxDefaultPosition, wxDefaultSize, 0 );
m_updateOptionsSizer->Add( m_resetFieldVisibilities, 0, wxBOTTOM|wxRIGHT, 4 );
@ -137,7 +140,7 @@ DIALOG_CHANGE_SYMBOLS_BASE::DIALOG_CHANGE_SYMBOLS_BASE( wxWindow* parent, wxWind
m_updateOptionsSizer->Add( m_resetFieldPositions, 0, wxBOTTOM|wxRIGHT, 4 );
m_updateOptionsSizer->Add( 0, 15, 1, wxEXPAND, 5 );
m_updateOptionsSizer->Add( 0, 10, 1, wxEXPAND, 5 );
m_resetAttributes = new wxCheckBox( m_updateOptionsSizer->GetStaticBox(), wxID_ANY, _("Update/reset symbol attributes"), wxDefaultPosition, wxDefaultSize, 0 );
m_updateOptionsSizer->Add( m_resetAttributes, 0, wxBOTTOM|wxRIGHT, 5 );

View File

@ -1382,11 +1382,75 @@
<property name="flag">wxEXPAND</property>
<property name="proportion">0</property>
<object class="spacer" expanded="1">
<property name="height">15</property>
<property name="height">10</property>
<property name="permission">protected</property>
<property name="width">0</property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">4</property>
<property name="flag">wxBOTTOM|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="checked">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Update/reset field text</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_resetFieldText</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">4</property>
<property name="flag">wxBOTTOM|wxRIGHT</property>
@ -1584,7 +1648,7 @@
<property name="flag">wxEXPAND</property>
<property name="proportion">1</property>
<object class="spacer" expanded="1">
<property name="height">15</property>
<property name="height">10</property>
<property name="permission">protected</property>
<property name="width">0</property>
</object>

View File

@ -68,6 +68,7 @@ class DIALOG_CHANGE_SYMBOLS_BASE : public DIALOG_SHIM
wxStaticBoxSizer* m_updateOptionsSizer;
wxCheckBox* m_removeExtraBox;
wxCheckBox* m_resetEmptyFields;
wxCheckBox* m_resetFieldText;
wxCheckBox* m_resetFieldVisibilities;
wxCheckBox* m_resetFieldEffects;
wxCheckBox* m_resetFieldPositions;

View File

@ -29,6 +29,7 @@
bool g_removeExtraLibFields = false;
bool g_resetEmptyLibFields = false;
bool g_resetLibFieldText = true;
bool g_resetLibFieldVisibilities = true;
bool g_resetLibFieldEffects = true;
bool g_resetLibFieldPositions = true;
@ -55,6 +56,7 @@ DIALOG_UPDATE_SYMBOL_FIELDS::DIALOG_UPDATE_SYMBOL_FIELDS( SYMBOL_EDIT_FRAME* aPa
m_removeExtraBox->SetValue( g_removeExtraLibFields );
m_resetEmptyFields->SetValue( g_resetEmptyLibFields );
m_resetFieldText->SetValue( g_resetLibFieldText );
m_resetFieldVisibilities->SetValue( g_resetLibFieldVisibilities );
m_resetFieldEffects->SetValue( g_resetLibFieldEffects );
m_resetFieldPositions->SetValue( g_resetLibFieldPositions );
@ -70,6 +72,7 @@ DIALOG_UPDATE_SYMBOL_FIELDS::~DIALOG_UPDATE_SYMBOL_FIELDS()
{
g_removeExtraLibFields = m_removeExtraBox->GetValue();
g_resetEmptyLibFields = m_resetEmptyFields->GetValue();
g_resetLibFieldText = m_resetFieldText->GetValue();
g_resetLibFieldVisibilities = m_resetFieldVisibilities->GetValue();
g_resetLibFieldEffects = m_resetFieldEffects->GetValue();
g_resetLibFieldPositions = m_resetFieldPositions->GetValue();
@ -135,7 +138,6 @@ void DIALOG_UPDATE_SYMBOL_FIELDS::onOkButtonClicked( wxCommandEvent& aEvent )
std::unique_ptr<LIB_PART> flattenedParent = m_symbol->GetParent().lock()->Flatten();
bool removeExtras = m_removeExtraBox->GetValue();
bool resetEmpty = m_resetEmptyFields->GetValue();
bool resetVis = m_resetFieldVisibilities->GetValue();
bool resetEffects = m_resetFieldEffects->GetValue();
bool resetPositions = m_resetFieldPositions->GetValue();
@ -155,7 +157,10 @@ void DIALOG_UPDATE_SYMBOL_FIELDS::onOkButtonClicked( wxCommandEvent& aEvent )
if( parentField )
{
if( !parentField->GetText().IsEmpty() || resetEmpty )
bool resetText = parentField->GetText().IsEmpty() ? m_resetEmptyFields->GetValue()
: m_resetFieldText->GetValue();
if( resetText )
field.SetText( parentField->GetText() );
if( resetVis )

View File

@ -69,6 +69,9 @@ DIALOG_UPDATE_SYMBOL_FIELDS_BASE::DIALOG_UPDATE_SYMBOL_FIELDS_BASE( wxWindow* pa
m_updateOptionsSizer->Add( 0, 15, 0, wxEXPAND, 5 );
m_resetFieldText = new wxCheckBox( m_updateOptionsSizer->GetStaticBox(), wxID_ANY, _("Update/reset field text"), wxDefaultPosition, wxDefaultSize, 0 );
m_updateOptionsSizer->Add( m_resetFieldText, 0, wxBOTTOM|wxRIGHT, 4 );
m_resetFieldVisibilities = new wxCheckBox( m_updateOptionsSizer->GetStaticBox(), wxID_ANY, _("Update/reset field visibilities"), wxDefaultPosition, wxDefaultSize, 0 );
m_updateOptionsSizer->Add( m_resetFieldVisibilities, 0, wxBOTTOM|wxRIGHT, 4 );

View File

@ -587,6 +587,70 @@
<property name="width">0</property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">4</property>
<property name="flag">wxBOTTOM|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="checked">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Update/reset field text</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_resetFieldText</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">4</property>
<property name="flag">wxBOTTOM|wxRIGHT</property>

View File

@ -49,6 +49,7 @@ class DIALOG_UPDATE_SYMBOL_FIELDS_BASE : public DIALOG_SHIM
wxStaticBoxSizer* m_updateOptionsSizer;
wxCheckBox* m_removeExtraBox;
wxCheckBox* m_resetEmptyFields;
wxCheckBox* m_resetFieldText;
wxCheckBox* m_resetFieldVisibilities;
wxCheckBox* m_resetFieldEffects;
wxCheckBox* m_resetFieldPositions;

View File

@ -68,8 +68,7 @@ SELECTION_CONDITION EE_CONDITIONS::SingleSymbol = [] (const SELECTION& aSel )
SELECTION_CONDITION EE_CONDITIONS::SingleSymbolOrPower = []( const SELECTION& aSel )
{
if( aSel.GetSize() == 1 )
return dynamic_cast<SCH_COMPONENT*>( aSel.Front() ) != nullptr;
return aSel.GetSize() == 1 && aSel.Front()->Type() == SCH_COMPONENT_T;
};