CADSTAR Schematic Archive Importer: Handle Pin Swaps
Each schematic symbol instance can have pin numbers that diverge from the pin number definitions in the library
This commit is contained in:
parent
4ea487936b
commit
cb90a4b7e6
|
@ -343,7 +343,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances()
|
||||||
LIB_PART* kiPart = mPartMap.at( sym.PartRef.RefID );
|
LIB_PART* kiPart = mPartMap.at( sym.PartRef.RefID );
|
||||||
double symOrientDeciDeg = 0.0;
|
double symOrientDeciDeg = 0.0;
|
||||||
|
|
||||||
SCH_COMPONENT* component = loadSchematicSymbol( sym, kiPart, symOrientDeciDeg );
|
SCH_COMPONENT* component = loadSchematicSymbol( sym, *kiPart, symOrientDeciDeg );
|
||||||
|
|
||||||
SCH_FIELD* refField = component->GetField( REFERENCE_FIELD );
|
SCH_FIELD* refField = component->GetField( REFERENCE_FIELD );
|
||||||
|
|
||||||
|
@ -478,7 +478,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances()
|
||||||
double compOrientationTenthDegree = 0.0;
|
double compOrientationTenthDegree = 0.0;
|
||||||
|
|
||||||
SCH_COMPONENT* component =
|
SCH_COMPONENT* component =
|
||||||
loadSchematicSymbol( sym, kiPart, compOrientationTenthDegree );
|
loadSchematicSymbol( sym, *kiPart, compOrientationTenthDegree );
|
||||||
|
|
||||||
mPowerSymMap.insert( { sym.ID, component } );
|
mPowerSymMap.insert( { sym.ID, component } );
|
||||||
}
|
}
|
||||||
|
@ -1078,6 +1078,8 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TERMINAL_TO_PINNUM_MAP pinNumMap;
|
||||||
|
|
||||||
for( std::pair<TERMINAL_ID, TERMINAL> termPair : symbol.Terminals )
|
for( std::pair<TERMINAL_ID, TERMINAL> termPair : symbol.Terminals )
|
||||||
{
|
{
|
||||||
TERMINAL term = termPair.second;
|
TERMINAL term = termPair.second;
|
||||||
|
@ -1103,6 +1105,8 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef
|
||||||
}
|
}
|
||||||
|
|
||||||
pin->SetType( getKiCadPinType( csPin.Type ) );
|
pin->SetType( getKiCadPinType( csPin.Type ) );
|
||||||
|
|
||||||
|
pinNumMap.insert( { term.ID, pinNum } );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1138,6 +1142,9 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef
|
||||||
aPart->AddDrawItem( pin );
|
aPart->AddDrawItem( pin );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(aCadstarPart)
|
||||||
|
mPinNumsMap.insert( { aCadstarPart->ID + aGateID, pinNumMap } );
|
||||||
|
|
||||||
for( std::pair<TEXT_ID, TEXT> textPair : symbol.Texts )
|
for( std::pair<TEXT_ID, TEXT> textPair : symbol.Texts )
|
||||||
{
|
{
|
||||||
TEXT csText = textPair.second;
|
TEXT csText = textPair.second;
|
||||||
|
@ -1411,16 +1418,16 @@ void CADSTAR_SCH_ARCHIVE_LOADER::applyToLibraryFieldAttribute(
|
||||||
|
|
||||||
|
|
||||||
SCH_COMPONENT* CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbol(
|
SCH_COMPONENT* CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbol(
|
||||||
const SYMBOL& aCadstarSymbol, LIB_PART* aKiCadPart, double& aComponentOrientationDeciDeg )
|
const SYMBOL& aCadstarSymbol, const LIB_PART& aKiCadPart, double& aComponentOrientationDeciDeg )
|
||||||
{
|
{
|
||||||
LIB_ID libId( mLibraryFileName.GetName(), aKiCadPart->GetName() );
|
LIB_ID libId( mLibraryFileName.GetName(), aKiCadPart.GetName() );
|
||||||
int unit = getKiCadUnitNumberFromGate( aCadstarSymbol.GateID );
|
int unit = getKiCadUnitNumberFromGate( aCadstarSymbol.GateID );
|
||||||
|
|
||||||
SCH_SHEET_PATH sheetpath;
|
SCH_SHEET_PATH sheetpath;
|
||||||
SCH_SHEET* kiSheet = mSheetMap.at( aCadstarSymbol.LayerID );
|
SCH_SHEET* kiSheet = mSheetMap.at( aCadstarSymbol.LayerID );
|
||||||
mRootSheet->LocatePathOfScreen( kiSheet->GetScreen(), &sheetpath );
|
mRootSheet->LocatePathOfScreen( kiSheet->GetScreen(), &sheetpath );
|
||||||
|
|
||||||
SCH_COMPONENT* component = new SCH_COMPONENT( *aKiCadPart, libId, &sheetpath, unit );
|
SCH_COMPONENT* component = new SCH_COMPONENT( aKiCadPart, libId, &sheetpath, unit );
|
||||||
|
|
||||||
if( aCadstarSymbol.IsComponent )
|
if( aCadstarSymbol.IsComponent )
|
||||||
{
|
{
|
||||||
|
@ -1463,6 +1470,50 @@ SCH_COMPONENT* CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbol(
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxString gate = ( aCadstarSymbol.GateID.IsEmpty() ) ? wxT( "A" ) : aCadstarSymbol.GateID;
|
||||||
|
wxString partGateIndex = aCadstarSymbol.PartRef.RefID + gate;
|
||||||
|
|
||||||
|
//Handle pin swaps
|
||||||
|
if( mPinNumsMap.find( partGateIndex ) != mPinNumsMap.end() )
|
||||||
|
{
|
||||||
|
TERMINAL_TO_PINNUM_MAP termNumMap = mPinNumsMap.at( partGateIndex );
|
||||||
|
|
||||||
|
std::map<wxString, LIB_PIN*> pinNumToLibPinMap;
|
||||||
|
|
||||||
|
for( auto& term : termNumMap )
|
||||||
|
{
|
||||||
|
wxString pinNum = term.second;
|
||||||
|
pinNumToLibPinMap.insert( { pinNum, component->GetPartRef()->GetPin( term.second ) } );
|
||||||
|
}
|
||||||
|
|
||||||
|
auto replacePinNumber = [&]( wxString aOldPinNum, wxString aNewPinNum )
|
||||||
|
{
|
||||||
|
if( aOldPinNum == aNewPinNum )
|
||||||
|
return;
|
||||||
|
|
||||||
|
LIB_PIN* libpin = pinNumToLibPinMap.at( aOldPinNum );
|
||||||
|
libpin->SetNumber( aNewPinNum );
|
||||||
|
};
|
||||||
|
|
||||||
|
//Older versions of Cadstar used pin numbers
|
||||||
|
for( auto& pinPair : aCadstarSymbol.PinNumbers )
|
||||||
|
{
|
||||||
|
SYMBOL::PIN_NUM pin = pinPair.second;
|
||||||
|
|
||||||
|
replacePinNumber( termNumMap.at( pin.TerminalID ),
|
||||||
|
wxString::Format( "%ld", pin.PinNum ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
//Newer versions of Cadstar use pin names
|
||||||
|
for( auto& pinPair : aCadstarSymbol.PinNames )
|
||||||
|
{
|
||||||
|
SYMPINNAME_LABEL pin = pinPair.second;
|
||||||
|
replacePinNumber( termNumMap.at( pin.TerminalID ), pin.NameOrLabel );
|
||||||
|
}
|
||||||
|
|
||||||
|
component->UpdatePins();
|
||||||
|
}
|
||||||
|
|
||||||
kiSheet->GetScreen()->Append( component );
|
kiSheet->GetScreen()->Append( component );
|
||||||
|
|
||||||
return component;
|
return component;
|
||||||
|
|
|
@ -78,6 +78,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::pair<BLOCK_ID, TERMINAL_ID> BLOCK_PIN_ID;
|
typedef std::pair<BLOCK_ID, TERMINAL_ID> BLOCK_PIN_ID;
|
||||||
|
typedef std::map<TERMINAL_ID, wxString> TERMINAL_TO_PINNUM_MAP;
|
||||||
|
|
||||||
::SCHEMATIC* mSchematic;
|
::SCHEMATIC* mSchematic;
|
||||||
::SCH_SHEET* mRootSheet;
|
::SCH_SHEET* mRootSheet;
|
||||||
|
@ -92,6 +93,7 @@ private:
|
||||||
std::map<BLOCK_PIN_ID, SCH_HIERLABEL*>
|
std::map<BLOCK_PIN_ID, SCH_HIERLABEL*>
|
||||||
mSheetPinMap; ///< Map between Cadstar and KiCad Sheets Pins
|
mSheetPinMap; ///< Map between Cadstar and KiCad Sheets Pins
|
||||||
std::map<PART_ID, LIB_PART*> mPartMap; ///< Map between Cadstar and KiCad Parts
|
std::map<PART_ID, LIB_PART*> mPartMap; ///< Map between Cadstar and KiCad Parts
|
||||||
|
std::map<PART_ID, TERMINAL_TO_PINNUM_MAP> mPinNumsMap; ///< Map of pin numbers
|
||||||
std::map<SYMDEF_ID, LIB_PART*>
|
std::map<SYMDEF_ID, LIB_PART*>
|
||||||
mPowerSymLibMap; ///< Map between Cadstar and KiCad Power Symbol Library items
|
mPowerSymLibMap; ///< Map between Cadstar and KiCad Power Symbol Library items
|
||||||
std::map<SYMBOL_ID, SCH_COMPONENT*>
|
std::map<SYMBOL_ID, SCH_COMPONENT*>
|
||||||
|
@ -134,7 +136,7 @@ private:
|
||||||
wxPoint aSymbolOrigin, LIB_FIELD* aKiCadField );
|
wxPoint aSymbolOrigin, LIB_FIELD* aKiCadField );
|
||||||
|
|
||||||
//Helper Functions for loading symbols in schematic
|
//Helper Functions for loading symbols in schematic
|
||||||
SCH_COMPONENT* loadSchematicSymbol( const SYMBOL& aCadstarSymbol, LIB_PART* aKiCadPart,
|
SCH_COMPONENT* loadSchematicSymbol( const SYMBOL& aCadstarSymbol, const LIB_PART& aKiCadPart,
|
||||||
double& aComponentOrientationDeciDeg );
|
double& aComponentOrientationDeciDeg );
|
||||||
|
|
||||||
void loadSymbolFieldAttribute( const ATTRIBUTE_LOCATION& aCadstarAttrLoc,
|
void loadSymbolFieldAttribute( const ATTRIBUTE_LOCATION& aCadstarAttrLoc,
|
||||||
|
|
Loading…
Reference in New Issue