CADSTAR PCB Archive Importer: Re-write loading of power symbols
Ensure all each power symbol is unique for each net name even if it uses the same graphical symbol. Fixes https://gitlab.com/kicad/code/kicad/-/issues/7722
This commit is contained in:
parent
f226373324
commit
76ef98339d
|
@ -481,28 +481,50 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances()
|
||||||
{
|
{
|
||||||
SYMDEF_ID symID = sym.SymdefID;
|
SYMDEF_ID symID = sym.SymdefID;
|
||||||
LIB_PART* kiPart = nullptr;
|
LIB_PART* kiPart = nullptr;
|
||||||
//KiCad requires parts to be named the same as the net:
|
|
||||||
wxString partName = sym.SymbolVariant.Reference;
|
|
||||||
|
|
||||||
partName = LIB_ID::FixIllegalChars( partName );
|
// In CADSTAR "GlobalSignal" is a special type of symbol which defines
|
||||||
|
// a Power Symbol. The "Alternate" name defines the default net name of
|
||||||
|
// the power symbol but this can be overriden in the design itself.
|
||||||
|
wxString libraryNetName = Library.SymbolDefinitions.at( symID ).Alternate;
|
||||||
|
|
||||||
if( m_powerSymLibMap.find( symID ) == m_powerSymLibMap.end()
|
// Name of the net that the symbol instance in CADSTAR refers to:
|
||||||
|| m_powerSymLibMap.at( symID )->GetName() != partName )
|
wxString symbolInstanceNetName = sym.SymbolVariant.Reference;
|
||||||
|
symbolInstanceNetName = LIB_ID::FixIllegalChars( symbolInstanceNetName );
|
||||||
|
|
||||||
|
// Name of the symbol we will use for saving the part in KiCad
|
||||||
|
// Note: In CADSTAR all power symbols will start have the reference name be
|
||||||
|
// "GLOBALSIGNAL" followed by the default net name, so it makes sense to save
|
||||||
|
// the symbol in KiCad as the default net name as well.
|
||||||
|
wxString libPartName = libraryNetName;
|
||||||
|
|
||||||
|
// In CADSTAR power symbol instances can refer to a different net to that defined
|
||||||
|
// in the library. This causes problems in KiCad v6 as it breaks connectivity when
|
||||||
|
// the user decides to update all symbols from library. We handle this by creating
|
||||||
|
// individual versions of the power symbol for each net name.
|
||||||
|
if( libPartName != symbolInstanceNetName )
|
||||||
{
|
{
|
||||||
kiPart = new LIB_PART( partName );
|
libPartName += wxT( " (" ) + symbolInstanceNetName + wxT( ")" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( m_powerSymLibMap.find( libPartName ) == m_powerSymLibMap.end() )
|
||||||
|
{
|
||||||
|
SYMDEF_SCM symbolDef = Library.SymbolDefinitions.at( symID );
|
||||||
|
|
||||||
|
kiPart = new LIB_PART( libPartName );
|
||||||
kiPart->SetPower();
|
kiPart->SetPower();
|
||||||
loadSymDefIntoLibrary( symID, nullptr, "A", kiPart );
|
loadSymDefIntoLibrary( symID, nullptr, "A", kiPart );
|
||||||
|
|
||||||
kiPart->GetValueField().SetText( partName );
|
kiPart->GetValueField().SetText( symbolInstanceNetName );
|
||||||
SYMDEF_SCM symbolDef = Library.SymbolDefinitions.at( symID );
|
|
||||||
|
|
||||||
if( symbolDef.TextLocations.find( SIGNALNAME_ORIGIN_ATTRID )
|
if( symbolDef.TextLocations.find( SIGNALNAME_ORIGIN_ATTRID )
|
||||||
!= symbolDef.TextLocations.end() )
|
!= symbolDef.TextLocations.end() )
|
||||||
{
|
{
|
||||||
TEXT_LOCATION signameOrigin =
|
TEXT_LOCATION txtLoc =
|
||||||
symbolDef.TextLocations.at( SIGNALNAME_ORIGIN_ATTRID );
|
symbolDef.TextLocations.at( SIGNALNAME_ORIGIN_ATTRID );
|
||||||
kiPart->GetValueField().SetPosition(
|
|
||||||
getKiCadLibraryPoint( signameOrigin.Position, symbolDef.Origin ) );
|
wxPoint valPos = getKiCadLibraryPoint( txtLoc.Position, symbolDef.Origin );
|
||||||
|
|
||||||
|
kiPart->GetValueField().SetPosition( valPos );
|
||||||
kiPart->GetValueField().SetVisible( true );
|
kiPart->GetValueField().SetVisible( true );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -513,18 +535,16 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances()
|
||||||
kiPart->GetReferenceField().SetText( "#PWR" );
|
kiPart->GetReferenceField().SetText( "#PWR" );
|
||||||
kiPart->GetReferenceField().SetVisible( false );
|
kiPart->GetReferenceField().SetVisible( false );
|
||||||
( *m_plugin )->SaveSymbol( m_libraryFileName.GetFullPath(), kiPart );
|
( *m_plugin )->SaveSymbol( m_libraryFileName.GetFullPath(), kiPart );
|
||||||
m_powerSymLibMap.insert( { symID, kiPart } );
|
m_powerSymLibMap.insert( { libPartName, kiPart } );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
kiPart = m_powerSymLibMap.at( symID );
|
kiPart = m_powerSymLibMap.at( libPartName );
|
||||||
|
wxASSERT( kiPart->GetValueField().GetText() == symbolInstanceNetName );
|
||||||
}
|
}
|
||||||
|
|
||||||
double compOrientationTenthDegree = 0.0;
|
double returnedOrientation = 0.0;
|
||||||
|
SCH_COMPONENT* component = loadSchematicSymbol( sym, *kiPart, returnedOrientation );
|
||||||
SCH_COMPONENT* component =
|
|
||||||
loadSchematicSymbol( sym, *kiPart, compOrientationTenthDegree );
|
|
||||||
|
|
||||||
m_powerSymMap.insert( { sym.ID, component } );
|
m_powerSymMap.insert( { sym.ID, component } );
|
||||||
}
|
}
|
||||||
else if( sym.SymbolVariant.Type == SYMBOLVARIANT::TYPE::SIGNALREF )
|
else if( sym.SymbolVariant.Type == SYMBOLVARIANT::TYPE::SIGNALREF )
|
||||||
|
|
|
@ -97,8 +97,7 @@ private:
|
||||||
m_sheetPinMap; ///< Map between Cadstar and KiCad Sheets Pins
|
m_sheetPinMap; ///< Map between Cadstar and KiCad Sheets Pins
|
||||||
std::map<PART_ID, LIB_PART*> m_partMap; ///< Map between Cadstar and KiCad Parts
|
std::map<PART_ID, LIB_PART*> m_partMap; ///< Map between Cadstar and KiCad Parts
|
||||||
std::map<PART_ID, TERMINAL_TO_PINNUM_MAP> m_pinNumsMap; ///< Map of pin numbers in CADSTAR parts
|
std::map<PART_ID, TERMINAL_TO_PINNUM_MAP> m_pinNumsMap; ///< Map of pin numbers in CADSTAR parts
|
||||||
std::map<SYMDEF_ID, LIB_PART*>
|
std::map<wxString, LIB_PART*> m_powerSymLibMap; ///< Map of KiCad Power Symbol Library items
|
||||||
m_powerSymLibMap; ///< Map between Cadstar and KiCad Power Symbol Library items
|
|
||||||
std::map<SYMBOL_ID, SCH_COMPONENT*>
|
std::map<SYMBOL_ID, SCH_COMPONENT*>
|
||||||
m_powerSymMap; ///< Map between Cadstar and KiCad Power Symbols
|
m_powerSymMap; ///< Map between Cadstar and KiCad Power Symbols
|
||||||
std::map<SYMBOL_ID, SCH_GLOBALLABEL*>
|
std::map<SYMBOL_ID, SCH_GLOBALLABEL*>
|
||||||
|
|
Loading…
Reference in New Issue