diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index 704c5b445e..fa9ef699d8 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -32,6 +32,7 @@ #include +#include #include #include #include @@ -483,27 +484,17 @@ 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(); + std::vector otherUnits; - SCH_REFERENCE_LIST components; - GetParent()->GetCurrentSheet().GetComponents( components ); + CollectOtherUnits( GetParent()->GetCurrentSheet(), m_cmp, &otherUnits ); - for( unsigned i = 0; i < components.GetCount(); i++ ) + for( SCH_COMPONENT* otherUnit : otherUnits ) { - SCH_REFERENCE component = components[i]; - - if( component.GetLibPart()->GetLibId() == thisLibId - && component.GetRef() == thisRef - && component.GetUnit() != thisUnit ) - { - SCH_COMPONENT* otherUnit = component.GetComp(); - GetParent()->SaveCopyInUndoList( otherUnit, UR_CHANGED, true /* append */); - otherUnit->GetField( VALUE )->SetText( m_fields->at( VALUE ).GetText() ); - otherUnit->GetField( FOOTPRINT )->SetText( m_fields->at( FOOTPRINT ).GetText() ); - otherUnit->GetField( DATASHEET )->SetText( m_fields->at( DATASHEET ).GetText() ); - } + GetParent()->SaveCopyInUndoList( otherUnit, UR_CHANGED, true /* append */); + otherUnit->GetField( VALUE )->SetText( m_fields->at( VALUE ).GetText() ); + otherUnit->GetField( FOOTPRINT )->SetText( m_fields->at( FOOTPRINT ).GetText() ); + otherUnit->GetField( DATASHEET )->SetText( m_fields->at( DATASHEET ).GetText() ); + GetParent()->RefreshItem( otherUnit ); } } diff --git a/eeschema/dialogs/dialog_edit_one_field.cpp b/eeschema/dialogs/dialog_edit_one_field.cpp index 0eaf7db91c..d73d0aa78d 100644 --- a/eeschema/dialogs/dialog_edit_one_field.cpp +++ b/eeschema/dialogs/dialog_edit_one_field.cpp @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include #include #include @@ -242,12 +244,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 ) { - EDA_ITEM* parent = aField->GetParent(); + SCH_EDIT_FRAME* editFrame = dynamic_cast( GetParent() ); + SCH_ITEM* parent = dynamic_cast( aField->GetParent() ); + int fieldType = aField->GetId(); - if( parent && parent->Type() == SCH_COMPONENT_T && aField->GetId() == REFERENCE ) + if( parent && parent->Type() == SCH_COMPONENT_T && fieldType == REFERENCE ) { wxASSERT( aSheetPath ); - static_cast( parent )->SetRef( aSheetPath, m_text ); } @@ -268,6 +271,24 @@ void DIALOG_SCH_EDIT_ONE_FIELD::UpdateField( SCH_FIELD* aField, SCH_SHEET_PATH* aField->SetText( m_text ); updateText( aField ); + // The value, footprint and datasheet fields should be kept in sync in multi-unit + // parts. + if( editFrame && parent && parent->Type() == SCH_COMPONENT_T + && ( fieldType == VALUE || fieldType == FOOTPRINT || fieldType == DATASHEET ) ) + { + SCH_COMPONENT* thisUnit = static_cast( parent ); + std::vector otherUnits; + + CollectOtherUnits( editFrame->GetCurrentSheet(), thisUnit, &otherUnits ); + + for( SCH_COMPONENT* otherUnit : otherUnits ) + { + editFrame->SaveCopyInUndoList( otherUnit, UR_CHANGED, true /* append */); + otherUnit->GetField( fieldType )->SetText( m_text ); + editFrame->RefreshItem( otherUnit ); + } + } + if( positioningModified && parent ) - static_cast( parent )->ClearFieldsAutoplaced(); + parent->ClearFieldsAutoplaced(); } diff --git a/eeschema/ee_collectors.cpp b/eeschema/ee_collectors.cpp index 19832e30d1..f053518bae 100644 --- a/eeschema/ee_collectors.cpp +++ b/eeschema/ee_collectors.cpp @@ -25,7 +25,6 @@ #include #include - #include #include #include @@ -33,6 +32,7 @@ #include #include #include +#include "sch_reference_list.h" const KICAD_T EE_COLLECTOR::AllItems[] = { @@ -166,3 +166,28 @@ bool EE_COLLECTOR::IsDraggableJunction() const return false; } + + +void CollectOtherUnits( SCH_SHEET_PATH& aSheet, SCH_COMPONENT* aUnit, + std::vector* otherUnits ) +{ + if( aUnit->GetUnitCount() > 1 ) + { + const LIB_ID thisLibId = aUnit->GetLibId(); + const wxString thisRef = aUnit->GetRef( &aSheet ); + int thisUnit = aUnit->GetUnit(); + + SCH_REFERENCE_LIST components; + aSheet.GetComponents( components ); + + for( unsigned i = 0; i < components.GetCount(); i++ ) + { + SCH_REFERENCE component = components[i]; + + if( component.GetRef() == thisRef && component.GetUnit() != thisUnit ) + otherUnits->push_back( component.GetComp() ); + } + } +} + + diff --git a/eeschema/ee_collectors.h b/eeschema/ee_collectors.h index 5f04e1aeb5..86d5b13459 100644 --- a/eeschema/ee_collectors.h +++ b/eeschema/ee_collectors.h @@ -30,7 +30,10 @@ #include #include #include -#include + + +class SCH_SHEET_PATH; +class SCH_COMPONENT; /** @@ -123,4 +126,7 @@ public: }; +void CollectOtherUnits( SCH_SHEET_PATH& aSheet, SCH_COMPONENT* aUnit, + std::vector* otherUnits ); + #endif // EE_COLLECTORS_H