CADSTAR Schematic: Fix loading of symbol attributes
Fixes an issue that resulted in incorrect field values being loaded
This commit is contained in:
parent
51db9cfcef
commit
e6c7ddc271
|
@ -354,6 +354,8 @@ public:
|
|||
|
||||
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.
|
||||
*
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
#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,
|
||||
|
@ -407,16 +407,17 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances()
|
|||
|
||||
if( sym.HasPartRef )
|
||||
{
|
||||
SCH_FIELD* partField = component->GetFieldById( PART_NAME );
|
||||
SCH_FIELD* partField = component->FindField( PartNameFieldName );
|
||||
|
||||
if( !partField )
|
||||
{
|
||||
component->AddField( SCH_FIELD( wxPoint(), PART_NAME, component,
|
||||
wxT( "Part Name" ) ) );
|
||||
|
||||
partField = component->GetFieldById( PART_NAME );
|
||||
int fieldID = component->GetFieldCount();
|
||||
partField = component->AddField( SCH_FIELD( wxPoint(), fieldID, component,
|
||||
PartNameFieldName ) );
|
||||
}
|
||||
|
||||
wxASSERT( partField->GetName() == PartNameFieldName );
|
||||
|
||||
wxString partname = getPart( sym.PartRef.RefID ).Name;
|
||||
partname.Replace( wxT( "\n" ), wxT( "\\n" ) );
|
||||
partname.Replace( wxT( "\r" ), wxT( "\\r" ) );
|
||||
|
@ -429,27 +430,24 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances()
|
|||
partField->SetVisible( SymbolPartNameColor.IsVisible );
|
||||
}
|
||||
|
||||
int fieldId = PART_NAME;
|
||||
|
||||
for( auto attr : sym.AttributeValues )
|
||||
{
|
||||
ATTRIBUTE_VALUE attrVal = attr.second;
|
||||
|
||||
if( attrVal.HasLocation )
|
||||
{
|
||||
//SCH_FIELD* attrField = getFieldByName( component );
|
||||
wxString attrName = getAttributeName( attrVal.AttributeID );
|
||||
|
||||
SCH_FIELD* attrField = component->FindField( attrName );
|
||||
|
||||
if( !attrField )
|
||||
{
|
||||
component->AddField( SCH_FIELD( wxPoint(), ++fieldId, component,
|
||||
attrName ) );
|
||||
|
||||
attrField = component->GetFieldById( fieldId );
|
||||
int fieldID = component->GetFieldCount();
|
||||
attrField = component->AddField( SCH_FIELD( wxPoint(), fieldID,
|
||||
component, attrName ) );
|
||||
}
|
||||
|
||||
wxASSERT( attrField->GetName() == attrName );
|
||||
|
||||
attrVal.Value.Replace( wxT( "\n" ), wxT( "\\n" ) );
|
||||
attrVal.Value.Replace( wxT( "\r" ), wxT( "\\r" ) );
|
||||
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() )
|
||||
{
|
||||
TEXT_LOCATION textLoc = symbol.TextLocations.at( PART_NAME_ATTRID );
|
||||
LIB_FIELD* field = aPart->GetFieldById( PART_NAME );
|
||||
LIB_FIELD* field = aPart->FindField( PartNameFieldName );
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
field->SetName( "Part Name" );
|
||||
wxASSERT( field->GetName() == PartNameFieldName );
|
||||
applyToLibraryFieldAttribute( textLoc, symbol.Origin, field );
|
||||
|
||||
if( aCadstarPart )
|
||||
|
@ -1279,15 +1279,13 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef
|
|||
|
||||
if( aCadstarPart )
|
||||
{
|
||||
int fieldId = PART_NAME;
|
||||
wxString footprintRefName = wxEmptyString;
|
||||
wxString footprintAlternateName = wxEmptyString;
|
||||
|
||||
auto loadLibraryField =
|
||||
[&]( ATTRIBUTE_VALUE& aAttributeVal )
|
||||
{
|
||||
wxString attrName = getAttributeName( aAttributeVal.AttributeID );
|
||||
LIB_FIELD* attrField = nullptr;
|
||||
wxString attrName = getAttributeName( aAttributeVal.AttributeID );
|
||||
|
||||
//Remove invalid field characters
|
||||
aAttributeVal.Value.Replace( wxT( "\n" ), wxT( "\\n" ) );
|
||||
|
@ -1319,18 +1317,18 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef
|
|||
footprintAlternateName = aAttributeVal.Value;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
attrField = aPart->FindField( attrName );
|
||||
}
|
||||
|
||||
LIB_FIELD* attrField = aPart->FindField( attrName );
|
||||
|
||||
if( !attrField )
|
||||
{
|
||||
aPart->AddField( new LIB_FIELD( aPart, ++fieldId ) );
|
||||
attrField = aPart->GetFieldById( fieldId );
|
||||
int fieldID = aPart->GetFieldCount();
|
||||
attrField = new LIB_FIELD( aPart, fieldID );
|
||||
attrField->SetName( attrName );
|
||||
aPart->AddField( attrField );
|
||||
}
|
||||
|
||||
wxASSERT( attrField->GetName() == attrName );
|
||||
attrField->SetText( aAttributeVal.Value );
|
||||
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(
|
||||
const PART& aCadstarPart, const GATE_ID& aGateID, const TERMINAL_ID& aTerminalID )
|
||||
{
|
||||
|
|
|
@ -187,8 +187,6 @@ private:
|
|||
ROUTECODE getRouteCode( const ROUTECODE_ID& aCadstarRouteCodeID );
|
||||
TEXTCODE getTextCode( const TEXTCODE_ID& aCadstarTextCodeID );
|
||||
wxString getAttributeName( const ATTRIBUTE_ID& aCadstarAttributeID );
|
||||
wxString getAttributeValue( const ATTRIBUTE_ID& aCadstarAttributeID,
|
||||
const std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE>& aCadstarAttributeMap );
|
||||
|
||||
PART::DEFINITION::PIN getPartDefinitionPin(
|
||||
const PART& aCadstarPart, const GATE_ID& aGateID, const TERMINAL_ID& aTerminalID );
|
||||
|
|
Loading…
Reference in New Issue