Share multi-unit updating code between Sym Props and Edit Field.
Fixes https://gitlab.com/kicad/code/kicad/issues/4103
This commit is contained in:
parent
7f8f17bd82
commit
cbef95256b
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
#include <widgets/wx_grid.h>
|
#include <widgets/wx_grid.h>
|
||||||
|
|
||||||
|
#include <ee_collectors.h>
|
||||||
#include <class_library.h>
|
#include <class_library.h>
|
||||||
#include <eeschema_settings.h>
|
#include <eeschema_settings.h>
|
||||||
#include <fields_grid_table.h>
|
#include <fields_grid_table.h>
|
||||||
|
@ -483,27 +484,17 @@ bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::TransferDataFromWindow()
|
||||||
// parts.
|
// parts.
|
||||||
if( m_cmp->GetUnitCount() > 1 )
|
if( m_cmp->GetUnitCount() > 1 )
|
||||||
{
|
{
|
||||||
const LIB_ID thisLibId = m_cmp->GetLibId();
|
std::vector<SCH_COMPONENT*> otherUnits;
|
||||||
const wxString thisRef = m_cmp->GetRef( &( GetParent()->GetCurrentSheet() ) );
|
|
||||||
int thisUnit = m_cmp->GetUnit();
|
|
||||||
|
|
||||||
SCH_REFERENCE_LIST components;
|
CollectOtherUnits( GetParent()->GetCurrentSheet(), m_cmp, &otherUnits );
|
||||||
GetParent()->GetCurrentSheet().GetComponents( components );
|
|
||||||
|
|
||||||
for( unsigned i = 0; i < components.GetCount(); i++ )
|
for( SCH_COMPONENT* otherUnit : otherUnits )
|
||||||
{
|
{
|
||||||
SCH_REFERENCE component = components[i];
|
GetParent()->SaveCopyInUndoList( otherUnit, UR_CHANGED, true /* append */);
|
||||||
|
otherUnit->GetField( VALUE )->SetText( m_fields->at( VALUE ).GetText() );
|
||||||
if( component.GetLibPart()->GetLibId() == thisLibId
|
otherUnit->GetField( FOOTPRINT )->SetText( m_fields->at( FOOTPRINT ).GetText() );
|
||||||
&& component.GetRef() == thisRef
|
otherUnit->GetField( DATASHEET )->SetText( m_fields->at( DATASHEET ).GetText() );
|
||||||
&& component.GetUnit() != thisUnit )
|
GetParent()->RefreshItem( otherUnit );
|
||||||
{
|
|
||||||
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() );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
#include <confirm.h>
|
#include <confirm.h>
|
||||||
#include <kicad_string.h>
|
#include <kicad_string.h>
|
||||||
#include <sch_base_frame.h>
|
#include <sch_base_frame.h>
|
||||||
|
#include <sch_edit_frame.h>
|
||||||
|
#include <ee_collectors.h>
|
||||||
#include <sch_component.h>
|
#include <sch_component.h>
|
||||||
#include <class_libentry.h>
|
#include <class_libentry.h>
|
||||||
#include <lib_field.h>
|
#include <lib_field.h>
|
||||||
|
@ -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 )
|
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<SCH_EDIT_FRAME*>( GetParent() );
|
||||||
|
SCH_ITEM* parent = dynamic_cast<SCH_ITEM*>( 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 );
|
wxASSERT( aSheetPath );
|
||||||
|
|
||||||
static_cast<SCH_COMPONENT*>( parent )->SetRef( aSheetPath, m_text );
|
static_cast<SCH_COMPONENT*>( 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 );
|
aField->SetText( m_text );
|
||||||
updateText( aField );
|
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<SCH_COMPONENT*>( parent );
|
||||||
|
std::vector<SCH_COMPONENT*> 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 )
|
if( positioningModified && parent )
|
||||||
static_cast<SCH_ITEM*>( parent )->ClearFieldsAutoplaced();
|
parent->ClearFieldsAutoplaced();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
|
|
||||||
#include <macros.h>
|
#include <macros.h>
|
||||||
#include <trace_helpers.h>
|
#include <trace_helpers.h>
|
||||||
|
|
||||||
#include <ee_collectors.h>
|
#include <ee_collectors.h>
|
||||||
#include <lib_item.h>
|
#include <lib_item.h>
|
||||||
#include <sch_bus_entry.h>
|
#include <sch_bus_entry.h>
|
||||||
|
@ -33,6 +32,7 @@
|
||||||
#include <sch_line.h>
|
#include <sch_line.h>
|
||||||
#include <sch_sheet_path.h>
|
#include <sch_sheet_path.h>
|
||||||
#include <transform.h>
|
#include <transform.h>
|
||||||
|
#include "sch_reference_list.h"
|
||||||
|
|
||||||
|
|
||||||
const KICAD_T EE_COLLECTOR::AllItems[] = {
|
const KICAD_T EE_COLLECTOR::AllItems[] = {
|
||||||
|
@ -166,3 +166,28 @@ bool EE_COLLECTOR::IsDraggableJunction() const
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CollectOtherUnits( SCH_SHEET_PATH& aSheet, SCH_COMPONENT* aUnit,
|
||||||
|
std::vector<SCH_COMPONENT*>* 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() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,10 @@
|
||||||
#include <collector.h>
|
#include <collector.h>
|
||||||
#include <dialogs/dialog_schematic_find.h>
|
#include <dialogs/dialog_schematic_find.h>
|
||||||
#include <sch_item.h>
|
#include <sch_item.h>
|
||||||
#include <sch_sheet_path.h>
|
|
||||||
|
|
||||||
|
class SCH_SHEET_PATH;
|
||||||
|
class SCH_COMPONENT;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -123,4 +126,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void CollectOtherUnits( SCH_SHEET_PATH& aSheet, SCH_COMPONENT* aUnit,
|
||||||
|
std::vector<SCH_COMPONENT*>* otherUnits );
|
||||||
|
|
||||||
#endif // EE_COLLECTORS_H
|
#endif // EE_COLLECTORS_H
|
||||||
|
|
Loading…
Reference in New Issue