diff --git a/common/plugins/cadstar/cadstar_archive_parser.h b/common/plugins/cadstar/cadstar_archive_parser.h index 220aa836c6..baccc31dfe 100644 --- a/common/plugins/cadstar/cadstar_archive_parser.h +++ b/common/plugins/cadstar/cadstar_archive_parser.h @@ -884,9 +884,17 @@ public: }; PART_DEFINITION_PIN_ID ID; + + wxString Identifier = wxEmptyString; ///< This should match a pad identifier + ///< in the component footprint + ///< subnode="PINIDENTIFIER". It is assumed + ///< that this could be empty in earlier + ///< versions of CADSTAR wxString Name = wxEmptyString; ///< Can be empty. If empty the pin name ///< displayed wil be Identifier ///< (subnode="PINNAME") + ///< This seems to be equivalent to "Pin + ///< Number" in KiCad. wxString Label = wxEmptyString; ///< This Can be empty (subnode= ///< "PINLABEL") ///< From CADSTAR Help: "Pin @@ -900,6 +908,8 @@ public: ///< correctly placed after any Gate and ///< Pin Swaps are Back Annotated to the ///< Schematic design." + ///< This seems to be equivalent to "Pin + ///< Name" in KiCad. wxString Signal = wxEmptyString; ///< Usually for Power/Ground pins, ///< (subnode="PINSIGNAL") GATE_ID TerminalGate; ///< (subnode="PINTERM", param0) @@ -914,11 +924,6 @@ public: ///< the symbol is added to a schematic design ///< subnode="PINPOSITION" - wxString Identifier = - wxEmptyString; ///< This should match a pad identifier in the component - ///< footprint subnode="PINIDENTIFIER". It is assumed that - ///< this could be empty in earlier versions of CADSTAR - void Parse( XNODE* aNode ); }; diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp index 901b29f812..0909e8d602 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp @@ -774,13 +774,15 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef { PART::DEFINITION::PIN csPin = getPartDefinitionPin( *aCadstarPart, aGateID, term.ID ); - pinName = csPin.Name; - pinNum = wxString::Format( "%ld", csPin.ID ); + pinName = csPin.Label; + pinNum = csPin.Name; - if( pinName.IsEmpty() ) + if( pinNum.IsEmpty() ) { if( !csPin.Identifier.IsEmpty() ) - pinName = csPin.Identifier; + pinNum = csPin.Identifier; + else + pinNum = wxString::Format( "%ld", csPin.ID ); } } diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_parser.h b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_parser.h index d1e6e48893..cea5cff2d1 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_parser.h +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_parser.h @@ -279,9 +279,12 @@ public: VARIANT_ID VariantID = wxEmptyString; std::map TerminalAttributes; - std::map PinLabels; - std::map PinNames; - std::map PinNumbers; + std::map PinLabels; ///< Equivalent to KiCad's Pin Name + std::map PinNames; ///< Identifier of the pin in the PCB + ///< Equivalent to KiCad's Pin Number + std::map PinNumbers; ///< This seems to only appear in older + ///< designs and is similar to PinNames + ///< but only allowing numerical values std::map AttributeValues; void Parse( XNODE* aNode ); diff --git a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp index e67892f826..1bf3dc2d5c 100644 --- a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp +++ b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp @@ -1192,7 +1192,7 @@ void CADSTAR_PCB_ARCHIVE_LOADER::loadComponents() { for( std::pair compPair : Layout.Components ) { - COMPONENT& comp = compPair.second; + COMPONENT& comp = compPair.second; auto fpIter = mLibraryMap.find( comp.SymdefID ); @@ -1203,12 +1203,43 @@ void CADSTAR_PCB_ARCHIVE_LOADER::loadComponents() comp.Name, comp.SymdefID ) ); } + FOOTPRINT* libFootprint = fpIter->second; + // copy constructor to clone the footprint from the library - FOOTPRINT* footprint = new FOOTPRINT( *fpIter->second ); + FOOTPRINT* footprint = new FOOTPRINT( *libFootprint ); const_cast( footprint->m_Uuid ) = KIID(); mBoard->Add( footprint, ADD_MODE::APPEND ); + // First lets fix the pad names on the footprint. + // CADSTAR defines the pad name in the PART definition and the SYMDEF (i.e. the PCB + // footprint definition) uses a numerical sequence. COMP is the only object that has + // visibility of both the SYMDEF and PART. + if( Parts.PartDefinitions.find( comp.PartID ) != Parts.PartDefinitions.end() ) + { + PART part = Parts.PartDefinitions.at( comp.PartID ); + + // Only do this when the number of pins in the part definition equals the number of + // pads in the footprint. + if( part.Definition.Pins.size() == footprint->Pads().size() ) + { + for( std::pair pinPair : + part.Definition.Pins ) + { + PART::DEFINITION::PIN pin = pinPair.second; + wxString pinName = pin.Name; + + if( pinName.empty() ) + pinName = pin.Identifier; + + if( pinName.empty() ) + pinName = wxString::Format( wxT( "%ld" ), pin.ID ); + + footprint->Pads().at( pin.ID - (long long) 1 )->SetName( pinName ); + } + } + } + //Override pads with pad exceptions if( comp.PadExceptions.size() > 0 ) { @@ -1232,12 +1263,15 @@ void CADSTAR_PCB_ARCHIVE_LOADER::loadComponents() csPad.Side = padEx.Side; // Find the pad in the footprint definition - PAD* kiPad = footprint->Pads().at( padEx.ID - (long) 1 ); + PAD* kiPad = footprint->Pads().at( padEx.ID - (long long) 1 ); + wxString padName = kiPad->GetName(); if( kiPad ) delete kiPad; - footprint->Pads().at( padEx.ID - (long) 1 ) = getKiCadPad( csPad, footprint ); + kiPad = getKiCadPad( csPad, footprint ); + kiPad->SetName( padName ); + footprint->Pads().at( padEx.ID - (long long) 1 ) = kiPad; } }