CADSTAR Schematic: Fix loading of symbol attributes

Fixes an issue that resulted in incorrect field values being loaded
This commit is contained in:
Roberto Fernandez Bautista 2021-03-28 19:03:11 +01:00 committed by Wayne Stambaugh
parent 51db9cfcef
commit e6c7ddc271
3 changed files with 26 additions and 38 deletions

View File

@ -354,6 +354,8 @@ public:
size_t GetPinCount() const { return m_drawings.size( LIB_PIN_T ); } size_t GetPinCount() const { return m_drawings.size( LIB_PIN_T ); }
size_t GetFieldCount() const { return m_drawings.size( LIB_FIELD_T ); }
/** /**
* Return the next pin object from the draw list. * Return the next pin object from the draw list.
* *

View File

@ -47,7 +47,7 @@
#include <wildcards_and_files_ext.h> #include <wildcards_and_files_ext.h>
constexpr int PART_NAME = MANDATORY_FIELDS; // First field after mandatory ones const wxString PartNameFieldName = "Part Name";
void CADSTAR_SCH_ARCHIVE_LOADER::Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSheet, void CADSTAR_SCH_ARCHIVE_LOADER::Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSheet,
@ -407,16 +407,17 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances()
if( sym.HasPartRef ) if( sym.HasPartRef )
{ {
SCH_FIELD* partField = component->GetFieldById( PART_NAME ); SCH_FIELD* partField = component->FindField( PartNameFieldName );
if( !partField ) if( !partField )
{ {
component->AddField( SCH_FIELD( wxPoint(), PART_NAME, component, int fieldID = component->GetFieldCount();
wxT( "Part Name" ) ) ); partField = component->AddField( SCH_FIELD( wxPoint(), fieldID, component,
PartNameFieldName ) );
partField = component->GetFieldById( PART_NAME );
} }
wxASSERT( partField->GetName() == PartNameFieldName );
wxString partname = getPart( sym.PartRef.RefID ).Name; wxString partname = getPart( sym.PartRef.RefID ).Name;
partname.Replace( wxT( "\n" ), wxT( "\\n" ) ); partname.Replace( wxT( "\n" ), wxT( "\\n" ) );
partname.Replace( wxT( "\r" ), wxT( "\\r" ) ); partname.Replace( wxT( "\r" ), wxT( "\\r" ) );
@ -429,27 +430,24 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances()
partField->SetVisible( SymbolPartNameColor.IsVisible ); partField->SetVisible( SymbolPartNameColor.IsVisible );
} }
int fieldId = PART_NAME;
for( auto attr : sym.AttributeValues ) for( auto attr : sym.AttributeValues )
{ {
ATTRIBUTE_VALUE attrVal = attr.second; ATTRIBUTE_VALUE attrVal = attr.second;
if( attrVal.HasLocation ) if( attrVal.HasLocation )
{ {
//SCH_FIELD* attrField = getFieldByName( component );
wxString attrName = getAttributeName( attrVal.AttributeID ); wxString attrName = getAttributeName( attrVal.AttributeID );
SCH_FIELD* attrField = component->FindField( attrName ); SCH_FIELD* attrField = component->FindField( attrName );
if( !attrField ) if( !attrField )
{ {
component->AddField( SCH_FIELD( wxPoint(), ++fieldId, component, int fieldID = component->GetFieldCount();
attrName ) ); attrField = component->AddField( SCH_FIELD( wxPoint(), fieldID,
component, attrName ) );
attrField = component->GetFieldById( fieldId );
} }
wxASSERT( attrField->GetName() == attrName );
attrVal.Value.Replace( wxT( "\n" ), wxT( "\\n" ) ); attrVal.Value.Replace( wxT( "\n" ), wxT( "\\n" ) );
attrVal.Value.Replace( wxT( "\r" ), wxT( "\\r" ) ); attrVal.Value.Replace( wxT( "\r" ), wxT( "\\r" ) );
attrVal.Value.Replace( wxT( "\t" ), wxT( "\\t" ) ); attrVal.Value.Replace( wxT( "\t" ), wxT( "\\t" ) );
@ -1253,15 +1251,17 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef
if( symbol.TextLocations.find( PART_NAME_ATTRID ) != symbol.TextLocations.end() ) if( symbol.TextLocations.find( PART_NAME_ATTRID ) != symbol.TextLocations.end() )
{ {
TEXT_LOCATION textLoc = symbol.TextLocations.at( PART_NAME_ATTRID ); TEXT_LOCATION textLoc = symbol.TextLocations.at( PART_NAME_ATTRID );
LIB_FIELD* field = aPart->GetFieldById( PART_NAME ); LIB_FIELD* field = aPart->FindField( PartNameFieldName );
if( !field ) if( !field )
{ {
field = new LIB_FIELD( aPart, PART_NAME ); int fieldID = aPart->GetFieldCount();
field = new LIB_FIELD( aPart, fieldID );
field->SetName( PartNameFieldName );
aPart->AddField( field ); aPart->AddField( field );
} }
field->SetName( "Part Name" ); wxASSERT( field->GetName() == PartNameFieldName );
applyToLibraryFieldAttribute( textLoc, symbol.Origin, field ); applyToLibraryFieldAttribute( textLoc, symbol.Origin, field );
if( aCadstarPart ) if( aCadstarPart )
@ -1279,15 +1279,13 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef
if( aCadstarPart ) if( aCadstarPart )
{ {
int fieldId = PART_NAME;
wxString footprintRefName = wxEmptyString; wxString footprintRefName = wxEmptyString;
wxString footprintAlternateName = wxEmptyString; wxString footprintAlternateName = wxEmptyString;
auto loadLibraryField = auto loadLibraryField =
[&]( ATTRIBUTE_VALUE& aAttributeVal ) [&]( ATTRIBUTE_VALUE& aAttributeVal )
{ {
wxString attrName = getAttributeName( aAttributeVal.AttributeID ); wxString attrName = getAttributeName( aAttributeVal.AttributeID );
LIB_FIELD* attrField = nullptr;
//Remove invalid field characters //Remove invalid field characters
aAttributeVal.Value.Replace( wxT( "\n" ), wxT( "\\n" ) ); aAttributeVal.Value.Replace( wxT( "\n" ), wxT( "\\n" ) );
@ -1319,18 +1317,18 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef
footprintAlternateName = aAttributeVal.Value; footprintAlternateName = aAttributeVal.Value;
return; return;
} }
else
{ LIB_FIELD* attrField = aPart->FindField( attrName );
attrField = aPart->FindField( attrName );
}
if( !attrField ) if( !attrField )
{ {
aPart->AddField( new LIB_FIELD( aPart, ++fieldId ) ); int fieldID = aPart->GetFieldCount();
attrField = aPart->GetFieldById( fieldId ); attrField = new LIB_FIELD( aPart, fieldID );
attrField->SetName( attrName ); attrField->SetName( attrName );
aPart->AddField( attrField );
} }
wxASSERT( attrField->GetName() == attrName );
attrField->SetText( aAttributeVal.Value ); attrField->SetText( aAttributeVal.Value );
attrField->SetUnit( gateNumber ); attrField->SetUnit( gateNumber );
@ -2213,16 +2211,6 @@ CADSTAR_SCH_ARCHIVE_LOADER::ROUTECODE CADSTAR_SCH_ARCHIVE_LOADER::getRouteCode(
} }
wxString CADSTAR_SCH_ARCHIVE_LOADER::getAttributeValue( const ATTRIBUTE_ID& aCadstarAttributeID,
const std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE>& aCadstarAttributeMap )
{
wxCHECK( aCadstarAttributeMap.find( aCadstarAttributeID ) != aCadstarAttributeMap.end(),
wxEmptyString );
return aCadstarAttributeMap.at( aCadstarAttributeID ).Value;
}
CADSTAR_SCH_ARCHIVE_LOADER::PART::DEFINITION::PIN CADSTAR_SCH_ARCHIVE_LOADER::getPartDefinitionPin( CADSTAR_SCH_ARCHIVE_LOADER::PART::DEFINITION::PIN CADSTAR_SCH_ARCHIVE_LOADER::getPartDefinitionPin(
const PART& aCadstarPart, const GATE_ID& aGateID, const TERMINAL_ID& aTerminalID ) const PART& aCadstarPart, const GATE_ID& aGateID, const TERMINAL_ID& aTerminalID )
{ {

View File

@ -187,8 +187,6 @@ private:
ROUTECODE getRouteCode( const ROUTECODE_ID& aCadstarRouteCodeID ); ROUTECODE getRouteCode( const ROUTECODE_ID& aCadstarRouteCodeID );
TEXTCODE getTextCode( const TEXTCODE_ID& aCadstarTextCodeID ); TEXTCODE getTextCode( const TEXTCODE_ID& aCadstarTextCodeID );
wxString getAttributeName( const ATTRIBUTE_ID& aCadstarAttributeID ); wxString getAttributeName( const ATTRIBUTE_ID& aCadstarAttributeID );
wxString getAttributeValue( const ATTRIBUTE_ID& aCadstarAttributeID,
const std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE>& aCadstarAttributeMap );
PART::DEFINITION::PIN getPartDefinitionPin( PART::DEFINITION::PIN getPartDefinitionPin(
const PART& aCadstarPart, const GATE_ID& aGateID, const TERMINAL_ID& aTerminalID ); const PART& aCadstarPart, const GATE_ID& aGateID, const TERMINAL_ID& aTerminalID );