From 5273c77fbf762a5433aa38374014c2f7844d2205 Mon Sep 17 00:00:00 2001 From: Roberto Fernandez Bautista Date: Tue, 13 Oct 2020 22:40:44 +0100 Subject: [PATCH] CADSTAR PCB Archive Importer: Parse TRUNK and TRUNKREF, display error if present (no KiCad equivalent) --- .../cadstar/cadstar_archive_parser.cpp | 45 ++++++++++++------ .../plugins/cadstar/cadstar_archive_parser.h | 2 + .../cadstar/cadstar_pcb_archive_loader.cpp | 8 ++++ .../cadstar/cadstar_pcb_archive_parser.cpp | 46 ++++++++++++++++++- .../cadstar/cadstar_pcb_archive_parser.h | 21 +++++++++ 5 files changed, 107 insertions(+), 15 deletions(-) diff --git a/common/plugins/cadstar/cadstar_archive_parser.cpp b/common/plugins/cadstar/cadstar_archive_parser.cpp index 03ab721ff2..0d445d4e68 100644 --- a/common/plugins/cadstar/cadstar_archive_parser.cpp +++ b/common/plugins/cadstar/cadstar_archive_parser.cpp @@ -1727,28 +1727,45 @@ void CADSTAR_ARCHIVE_PARSER::PARTS::Parse( XNODE* aNode ) } -void CADSTAR_ARCHIVE_PARSER::NET::JUNCTION::Parse( XNODE* aNode ) +void CADSTAR_ARCHIVE_PARSER::NET::JUNCTION::ParseIdentifiers( XNODE* aNode ) { wxASSERT( aNode->GetName() == wxT( "JPT" ) ); - ID = GetXmlAttributeIDString( aNode, 0 ); - LayerID = GetXmlAttributeIDString( aNode, 1 ); + ID = GetXmlAttributeIDString( aNode, 0 ); + LayerID = GetXmlAttributeIDString( aNode, 1 ); +} + + +bool CADSTAR_ARCHIVE_PARSER::NET::JUNCTION::ParseSubNode( XNODE* aChildNode ) +{ + wxString cNodeName = aChildNode->GetName(); + + if( cNodeName == wxT( "PT" ) ) + Location.Parse( aChildNode ); + else if( cNodeName == wxT( "FIX" ) ) + Fixed = true; + else if( cNodeName == wxT( "GROUPREF" ) ) + GroupID = GetXmlAttributeIDString( aChildNode, 0 ); + else if( cNodeName == wxT( "REUSEBLOCKREF" ) ) + ReuseBlockRef.Parse( aChildNode ); + else + return false; + + return true; +} + + +void CADSTAR_ARCHIVE_PARSER::NET::JUNCTION::Parse( XNODE* aNode ) +{ + ParseIdentifiers( aNode ); XNODE* cNode = aNode->GetChildren(); for( ; cNode; cNode = cNode->GetNext() ) { - wxString cNodeName = cNode->GetName(); - - if( cNodeName == wxT( "PT" ) ) - Location.Parse( cNode ); - else if( cNodeName == wxT( "FIX" ) ) - Fixed = true; - else if( cNodeName == wxT( "GROUPREF" ) ) - GroupID = GetXmlAttributeIDString( cNode, 0 ); - else if( cNodeName == wxT( "REUSEBLOCKREF" ) ) - ReuseBlockRef.Parse( cNode ); + if( ParseSubNode( cNode ) ) + continue; else - THROW_UNKNOWN_NODE_IO_ERROR( cNodeName, aNode->GetName() ); + THROW_UNKNOWN_NODE_IO_ERROR( cNode->GetName(), aNode->GetName() ); } } diff --git a/common/plugins/cadstar/cadstar_archive_parser.h b/common/plugins/cadstar/cadstar_archive_parser.h index a1cb4f13b7..f238a0f6fc 100644 --- a/common/plugins/cadstar/cadstar_archive_parser.h +++ b/common/plugins/cadstar/cadstar_archive_parser.h @@ -1036,6 +1036,8 @@ public: REUSEBLOCKREF ReuseBlockRef; bool Fixed = false; + void ParseIdentifiers( XNODE* aNode ); + bool ParseSubNode( XNODE* aChildNode ); virtual 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 64cf762631..cd80b2140b 100644 --- a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp +++ b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp @@ -97,6 +97,14 @@ void CADSTAR_PCB_ARCHIVE_LOADER::Load( ::BOARD* aBoard ) loadCoppers(); loadNets(); + + if( Layout.Trunks.size() > 0 ) + { + wxLogWarning( + _( "The CADSTAR design contains Trunk routing elements, which have no KiCad " + "equivalent. These elements were not loaded." ) ); + } + if( Layout.VariantHierarchy.Variants.size() > 0 ) { wxLogWarning( diff --git a/pcbnew/plugins/cadstar/cadstar_pcb_archive_parser.cpp b/pcbnew/plugins/cadstar/cadstar_pcb_archive_parser.cpp index 74d041d658..21b7d07cc4 100644 --- a/pcbnew/plugins/cadstar/cadstar_pcb_archive_parser.cpp +++ b/pcbnew/plugins/cadstar/cadstar_pcb_archive_parser.cpp @@ -1894,6 +1894,15 @@ CADSTAR_PCB_ARCHIVE_PARSER::TESTLAND_SIDE CADSTAR_PCB_ARCHIVE_PARSER::ParseTestl } +void CADSTAR_PCB_ARCHIVE_PARSER::TRUNK::Parse( XNODE* aNode ) +{ + wxASSERT( aNode->GetName() == wxT( "TRUNK" ) ); + + ID = GetXmlAttributeIDString( aNode, 0 ); + Definition = GetXmlAttributeIDString( aNode, 1 ); +} + + void CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::PIN::Parse( XNODE* aNode ) { wxASSERT( aNode->GetName() == wxT( "PIN" ) ); @@ -1905,6 +1914,23 @@ void CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::PIN::Parse( XNODE* aNode ) } +void CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::JUNCTION_PCB::Parse( XNODE* aNode ) +{ + ParseIdentifiers( aNode ); + XNODE* cNode = aNode->GetChildren(); + + for( ; cNode; cNode = cNode->GetNext() ) + { + if( ParseSubNode( cNode ) ) + continue; + else if( cNode->GetName() == wxT( "TRUNKREF" ) ) + TrunkID = GetXmlAttributeIDString( cNode, 0 ); + else + THROW_UNKNOWN_NODE_IO_ERROR( cNode->GetName(), aNode->GetName() ); + } +} + + void CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::VIA::Parse( XNODE* aNode ) { wxASSERT( aNode->GetName() == wxT( "VIA" ) ); @@ -1929,6 +1955,8 @@ void CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::VIA::Parse( XNODE* aNode ) ReuseBlockRef.Parse( cNode ); else if( cNodeName == wxT( "TESTLAND" ) ) TestlandSide = ParseTestlandSide( cNode ); + else if( cNode->GetName() == wxT( "TRUNKREF" ) ) + TrunkID = GetXmlAttributeIDString( cNode, 0 ); else THROW_UNKNOWN_NODE_IO_ERROR( cNodeName, aNode->GetName() ); } @@ -2026,6 +2054,10 @@ void CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::CONNECTION_PCB::Parse( XNODE* aNode ) Unrouted = true; UnrouteLayerID = GetXmlAttributeIDString( cNode, 0 ); } + else if( cNode->GetName() == wxT( "TRUNKREF" ) ) + { + TrunkID = GetXmlAttributeIDString( cNode, 0 ); + } else { THROW_UNKNOWN_NODE_IO_ERROR( cNodeName, wxT( "CONN" ) ); @@ -2045,7 +2077,13 @@ void CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::Parse( XNODE* aNode ) { wxString cNodeName = cNode->GetName(); - if( ParseSubNode( cNode ) ) + if( cNodeName == wxT( "JPT" ) ) + { + JUNCTION_PCB jpt; + jpt.Parse( cNode ); + Junctions.insert( std::make_pair( jpt.ID, jpt ) ); + } + else if( ParseSubNode( cNode ) ) { continue; } @@ -2440,6 +2478,12 @@ void CADSTAR_PCB_ARCHIVE_PARSER::LAYOUT::Parse( XNODE* aNode ) comp.Parse( cNode ); Components.insert( std::make_pair( comp.ID, comp ) ); } + else if( cNodeName == wxT( "TRUNK" ) ) + { + TRUNK trunk; + trunk.Parse( cNode ); + Trunks.insert( std::make_pair( trunk.ID, trunk ) ); + } else if( cNodeName == wxT( "NET" ) ) { NET_PCB net; diff --git a/pcbnew/plugins/cadstar/cadstar_pcb_archive_parser.h b/pcbnew/plugins/cadstar/cadstar_pcb_archive_parser.h index c0da578f67..acd3e7081e 100644 --- a/pcbnew/plugins/cadstar/cadstar_pcb_archive_parser.h +++ b/pcbnew/plugins/cadstar/cadstar_pcb_archive_parser.h @@ -73,6 +73,7 @@ public: typedef long COPPER_TERM_ID; typedef wxString COPPER_ID; typedef wxString DRILL_TABLE_ID; + typedef wxString TRUNK_ID; /** * @brief Type of layer appropriate for the material being set up @@ -921,6 +922,15 @@ public: }; + struct TRUNK + { + TRUNK_ID ID; + wxString Definition; // TODO: more work required to fully parse the TRUNK structure + + void Parse( XNODE* aNode ); + }; + + struct NET_PCB : CADSTAR_ARCHIVE_PARSER::NET { struct PIN ///< "PIN" nodename (represents a PAD in a PCB component) @@ -931,6 +941,13 @@ public: void Parse( XNODE* aNode ); }; + + struct JUNCTION_PCB : CADSTAR_ARCHIVE_PARSER::NET::JUNCTION ///< "JPT" nodename + { + TRUNK_ID TrunkID; ///< TRUNKREF Statements + + void Parse( XNODE* aNode ) override; + }; struct VIA ///< "VIA" nodename { @@ -938,6 +955,7 @@ public: VIACODE_ID ViaCodeID; LAYERPAIR_ID LayerPairID; POINT Location; + TRUNK_ID TrunkID; ///< TRUNKREF Statements GROUP_ID GroupID = wxEmptyString; ///< If not empty, this VIA is part of a group. REUSEBLOCKREF ReuseBlockRef; TESTLAND_SIDE TestlandSide = TESTLAND_SIDE::NONE; @@ -983,11 +1001,13 @@ public: ///< as opposed to a route (track in KiCad terms) LAYER_ID UnrouteLayerID = wxEmptyString; ///< See Unrouted member variable. + TRUNK_ID TrunkID; ///< TRUNKREF Statements void Parse( XNODE* aNode ) override; }; std::map Pins; + std::map Junctions; std::map Vias; std::map CopperTerminals; std::vector Connections; @@ -1160,6 +1180,7 @@ public: std::map Areas; std::map Components; std::map DocumentationSymbols; + std::map Trunks; std::map Nets; ///< Contains tracks and vias std::map Templates; std::map Coppers;