Fix another case of the instance data getting messed up.

(Or, more accurately in this case, of the instance data not getting
applied to the current view.)

Fixes https://gitlab.com/kicad/code/kicad/issues/11390

(cherry picked from commit 5295342f42)
This commit is contained in:
Jeff Young 2022-07-27 12:27:58 +01:00
parent afc491c5a5
commit 3bca4f8835
2 changed files with 29 additions and 12 deletions

View File

@ -504,27 +504,27 @@ bool SCH_SYMBOL::IsReferenceStringValid( const wxString& aReferenceString )
void SCH_SYMBOL::SetRef( const SCH_SHEET_PATH* sheet, const wxString& ref )
{
KIID_PATH path = sheet->Path();
bool notInArray = true;
bool found = false;
// check to see if it is already there before inserting it
for( SYMBOL_INSTANCE_REFERENCE& instance : m_instanceReferences )
{
if( instance.m_Path == path )
{
found = true;
instance.m_Reference = ref;
notInArray = false;
break;
}
}
if( notInArray )
if( !found )
AddHierarchicalReference( path, ref, m_unit );
for( std::unique_ptr<SCH_PIN>& pin : m_pins )
pin->ClearDefaultNetName( sheet );
SCH_FIELD* rf = GetField( REFERENCE_FIELD );
rf->SetText( ref ); // for drawing.
if( Schematic() && *sheet == Schematic()->CurrentSheet() )
m_fields[ REFERENCE_FIELD ].SetText( ref );
// Reinit the m_prefix member if needed
m_prefix = UTIL::GetRefDesPrefix( ref );
@ -634,20 +634,28 @@ void SCH_SYMBOL::SetValue( const SCH_SHEET_PATH* sheet, const wxString& aValue )
}
KIID_PATH path = sheet->Path();
bool found = false;
// check to see if it is already there before inserting it
for( SYMBOL_INSTANCE_REFERENCE& instance : m_instanceReferences )
{
if( instance.m_Path == path )
{
found = true;
instance.m_Value = aValue;
return;
break;
}
}
// didn't find it; better add it
AddHierarchicalReference( path, UTIL::GetRefDesUnannotated( m_prefix ), m_unit,
aValue, wxEmptyString );
if( !found )
{
AddHierarchicalReference( path, UTIL::GetRefDesUnannotated( m_prefix ), m_unit, aValue,
wxEmptyString );
}
if( Schematic() && *sheet == Schematic()->CurrentSheet() )
m_fields[ VALUE_FIELD ].SetText( aValue );
}
@ -685,22 +693,30 @@ void SCH_SYMBOL::SetFootprint( const SCH_SHEET_PATH* sheet, const wxString& aFoo
}
KIID_PATH path = sheet->Path();
bool found = false;
// check to see if it is already there before inserting it
for( SYMBOL_INSTANCE_REFERENCE& instance : m_instanceReferences )
{
if( instance.m_Path == path )
{
found = true;
instance.m_Footprint = aFootprint;
return;
break;
}
}
// didn't find it; better add it
if( !found )
{
AddHierarchicalReference( path, UTIL::GetRefDesUnannotated( m_prefix ), m_unit,
wxEmptyString, aFootprint );
}
if( Schematic() && *sheet == Schematic()->CurrentSheet() )
m_fields[ FOOTPRINT_FIELD ].SetText( aFootprint );
}
SCH_FIELD* SCH_SYMBOL::GetField( MANDATORY_FIELD_T aFieldType )
{

View File

@ -263,6 +263,7 @@ SYMBOL_EDIT_FRAME::~SYMBOL_EDIT_FRAME()
delete screen;
m_isSymbolFromSchematic = false;
}
// current screen is destroyed in EDA_DRAW_FRAME
SetScreen( m_dummyScreen );