From e9b059ee94e407f173343c1be781f8978a61907b Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 30 Mar 2020 20:21:55 +0100 Subject: [PATCH] Re-implement change from cbef95256b73a3f7ca81a50e63ba3bf1f3382c3 Fixes: lp:4103 * https://bugs.launchpad.net/kicad/+bug/4103 --- .../dialog_edit_component_in_schematic.cpp | 5 +-- eeschema/dialogs/dialog_edit_one_field.cpp | 38 +++++++++++++++---- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index 53a38cb00e..ac4a727530 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -484,7 +484,6 @@ bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::TransferDataFromWindow() // parts. if( m_cmp->GetUnitCount() > 1 ) { - const LIB_ID thisLibId = m_cmp->GetLibId(); const wxString thisRef = m_cmp->GetRef( &( GetParent()->GetCurrentSheet() ) ); int thisUnit = m_cmp->GetUnit(); @@ -495,9 +494,7 @@ bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::TransferDataFromWindow() { SCH_REFERENCE component = components[i]; - if( component.GetLibPart()->GetLibId() == thisLibId - && component.GetRef() == thisRef - && component.GetUnit() != thisUnit ) + if( component.GetRef() == thisRef && component.GetUnit() != thisUnit ) { SCH_COMPONENT* otherUnit = component.GetComp(); GetParent()->SaveCopyInUndoList( otherUnit, UR_CHANGED, true /* append */); diff --git a/eeschema/dialogs/dialog_edit_one_field.cpp b/eeschema/dialogs/dialog_edit_one_field.cpp index 3f758c8312..cfe0a0d5cf 100644 --- a/eeschema/dialogs/dialog_edit_one_field.cpp +++ b/eeschema/dialogs/dialog_edit_one_field.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -43,7 +44,7 @@ #include #include - +#include // These should probably moved into some other file as helpers. EDA_TEXT_HJUSTIFY_T IntToEdaTextHorizJustify( int aHorizJustify ) @@ -275,12 +276,13 @@ DIALOG_SCH_EDIT_ONE_FIELD::DIALOG_SCH_EDIT_ONE_FIELD( SCH_BASE_FRAME* aParent, void DIALOG_SCH_EDIT_ONE_FIELD::UpdateField( SCH_FIELD* aField, SCH_SHEET_PATH* aSheetPath ) { + SCH_EDIT_FRAME* editFrame = dynamic_cast( GetParent() ); + SCH_COMPONENT* component = dynamic_cast( aField->GetParent() ); + int fieldType = aField->GetId(); + if( aField->GetId() == REFERENCE ) { wxASSERT( aSheetPath ); - - SCH_COMPONENT* component = dynamic_cast< SCH_COMPONENT* >( aField->GetParent() ); - wxASSERT( component ); if( component ) @@ -304,9 +306,31 @@ void DIALOG_SCH_EDIT_ONE_FIELD::UpdateField( SCH_FIELD* aField, SCH_SHEET_PATH* aField->SetText( m_text ); updateText( aField ); - if( positioningModified ) + // The value, footprint and datasheet fields should be kept in sync in multi-unit + // parts. + if( editFrame && component && component->GetUnitCount() > 1 + && ( fieldType == VALUE || fieldType == FOOTPRINT || fieldType == DATASHEET ) ) { - auto component = static_cast< SCH_COMPONENT* >( aField->GetParent() ); - component->ClearFieldsAutoplaced(); + const wxString thisRef = component->GetRef( &( editFrame->GetCurrentSheet() ) ); + int thisUnit = component->GetUnit(); + + SCH_REFERENCE_LIST components; + editFrame->GetCurrentSheet().GetComponents( components ); + + for( unsigned i = 0; i < components.GetCount(); i++ ) + { + SCH_REFERENCE componentRef = components[i]; + + if( componentRef.GetRef() == thisRef && componentRef.GetUnit() != thisUnit ) + { + SCH_COMPONENT* otherUnit = componentRef.GetComp(); + editFrame->SaveCopyInUndoList( otherUnit, UR_CHANGED, true /* append */); + otherUnit->GetField( fieldType )->SetText( m_text ); + editFrame->RefreshItem( otherUnit ); + } + } } + + if( component && positioningModified ) + component->ClearFieldsAutoplaced(); }