From adfc74f93a2d815c6d12ea4436a9acdc9b20741c Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Fri, 23 Oct 2020 17:02:56 +0200 Subject: [PATCH] altium: Add initial support for multiunit symbols Fix: https://gitlab.com/kicad/code/kicad/-/issues/6055 --- .../sch_plugins/altium/altium_parser_sch.cpp | 16 ++++++++ .../sch_plugins/altium/altium_parser_sch.h | 8 ++++ .../sch_plugins/altium/sch_altium_plugin.cpp | 39 ++++++++++++++++++- .../sch_plugins/altium/sch_altium_plugin.h | 7 +++- 4 files changed, 67 insertions(+), 3 deletions(-) diff --git a/eeschema/sch_plugins/altium/altium_parser_sch.cpp b/eeschema/sch_plugins/altium/altium_parser_sch.cpp index 494f63f6cc..7aaa131462 100644 --- a/eeschema/sch_plugins/altium/altium_parser_sch.cpp +++ b/eeschema/sch_plugins/altium/altium_parser_sch.cpp @@ -96,6 +96,8 @@ ASCH_PIN::ASCH_PIN( const std::map& aProperties ) ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERINDEX", ALTIUM_COMPONENT_NONE ); ownerpartid = ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTID", ALTIUM_COMPONENT_NONE ); + ownerpartdisplaymode = + ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTDISPLAYMODE", 0 ); name = ALTIUM_PARSER::PropertiesReadString( aProperties, "NAME", "" ); text = ALTIUM_PARSER::PropertiesReadString( aProperties, "TEXT", "" ); @@ -199,6 +201,8 @@ ASCH_BEZIER::ASCH_BEZIER( const std::map& aProperties ) ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERINDEX", ALTIUM_COMPONENT_NONE ); ownerpartid = ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTID", ALTIUM_COMPONENT_NONE ); + ownerpartdisplaymode = + ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTDISPLAYMODE", 0 ); int locationCount = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATIONCOUNT", 0 ); for( int i = 1; i <= locationCount; i++ ) @@ -220,6 +224,8 @@ ASCH_POLYLINE::ASCH_POLYLINE( const std::map& aProperties ) ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERINDEX", ALTIUM_COMPONENT_NONE ); ownerpartid = ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTID", ALTIUM_COMPONENT_NONE ); + ownerpartdisplaymode = + ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTDISPLAYMODE", 0 ); int locationCount = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATIONCOUNT", 0 ); for( int i = 1; i <= locationCount; i++ ) @@ -248,6 +254,8 @@ ASCH_POLYGON::ASCH_POLYGON( const std::map& aProperties ) ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERINDEX", ALTIUM_COMPONENT_NONE ); ownerpartid = ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTID", ALTIUM_COMPONENT_NONE ); + ownerpartdisplaymode = + ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTDISPLAYMODE", 0 ); int locationCount = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATIONCOUNT", 0 ); for( int i = 1; i <= locationCount; i++ ) @@ -273,6 +281,8 @@ ASCH_ROUND_RECTANGLE::ASCH_ROUND_RECTANGLE( const std::map& ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERINDEX", ALTIUM_COMPONENT_NONE ); ownerpartid = ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTID", ALTIUM_COMPONENT_NONE ); + ownerpartdisplaymode = + ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTDISPLAYMODE", 0 ); bottomLeft = wxPoint( PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.X" ), -PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.Y" ) ); @@ -299,6 +309,8 @@ ASCH_ARC::ASCH_ARC( const std::map& aProperties ) ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERINDEX", ALTIUM_COMPONENT_NONE ); ownerpartid = ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTID", ALTIUM_COMPONENT_NONE ); + ownerpartdisplaymode = + ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTDISPLAYMODE", 0 ); center = wxPoint( PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.X" ), -PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.Y" ) ); @@ -319,6 +331,8 @@ ASCH_LINE::ASCH_LINE( const std::map& aProperties ) ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERINDEX", ALTIUM_COMPONENT_NONE ); ownerpartid = ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTID", ALTIUM_COMPONENT_NONE ); + ownerpartdisplaymode = + ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTDISPLAYMODE", 0 ); point1 = wxPoint( PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.X" ), -PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.Y" ) ); @@ -337,6 +351,8 @@ ASCH_RECTANGLE::ASCH_RECTANGLE( const std::map& aProperties ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERINDEX", ALTIUM_COMPONENT_NONE ); ownerpartid = ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTID", ALTIUM_COMPONENT_NONE ); + ownerpartdisplaymode = + ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTDISPLAYMODE", 0 ); bottomLeft = wxPoint( PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.X" ), -PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.Y" ) ); diff --git a/eeschema/sch_plugins/altium/altium_parser_sch.h b/eeschema/sch_plugins/altium/altium_parser_sch.h index 99320c98e4..761c31dd24 100644 --- a/eeschema/sch_plugins/altium/altium_parser_sch.h +++ b/eeschema/sch_plugins/altium/altium_parser_sch.h @@ -181,6 +181,7 @@ struct ASCH_PIN { int ownerindex; int ownerpartid; + int ownerpartdisplaymode; wxString name; wxString text; @@ -245,6 +246,7 @@ struct ASCH_BEZIER { int ownerindex; int ownerpartid; + int ownerpartdisplaymode; std::vector points; @@ -267,6 +269,7 @@ struct ASCH_POLYLINE { int ownerindex; int ownerpartid; + int ownerpartdisplaymode; std::vector points; @@ -282,6 +285,7 @@ struct ASCH_POLYGON { int ownerindex; int ownerpartid; + int ownerpartdisplaymode; std::vector points; @@ -299,6 +303,7 @@ struct ASCH_ROUND_RECTANGLE { int ownerindex; int ownerpartid; + int ownerpartdisplaymode; wxPoint bottomLeft; wxPoint topRight; @@ -320,6 +325,7 @@ struct ASCH_ARC { int ownerindex; int ownerpartid; + int ownerpartdisplaymode; wxPoint center; int radius; @@ -336,6 +342,7 @@ struct ASCH_LINE { int ownerindex; int ownerpartid; + int ownerpartdisplaymode; wxPoint point1; wxPoint point2; @@ -350,6 +357,7 @@ struct ASCH_RECTANGLE { int ownerindex; int ownerpartid; + int ownerpartdisplaymode; wxPoint bottomLeft; wxPoint topRight; diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp index 63edb5b865..dece36542c 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp @@ -442,10 +442,22 @@ void SCH_ALTIUM_PLUGIN::Parse( const CFB::CompoundFileReader& aReader ) m_currentSheet->SetModified(); } +bool SCH_ALTIUM_PLUGIN::IsCmpPartVisible( + int aOwnerindex, int aOwnerpartid, int aOwnerpartdisplaymode ) const +{ + const auto& component = m_altiumComponents.find( aOwnerindex ); + if( component == m_altiumComponents.end() ) + return false; + + const ASCH_COMPONENT& cmp = component->second; + return ( cmp.currentpartid == aOwnerpartid ) && ( cmp.displaymode == aOwnerpartdisplaymode ); +} + void SCH_ALTIUM_PLUGIN::ParseComponent( int index, const std::map& aProperties ) { - ASCH_COMPONENT elem( aProperties ); + auto pair = m_altiumComponents.insert( { index, ASCH_COMPONENT( aProperties ) } ); + const ASCH_COMPONENT& elem = pair.first->second; LIB_ID libId = AltiumToKiCadLibID( LIB_ID::ID_SCH, getLibName(), elem.libreference ); @@ -466,7 +478,6 @@ void SCH_ALTIUM_PLUGIN::ParseComponent( int index, const std::mapGetScreen()->Append( component ); m_components.insert( { index, component } ); - std::cout << "component index: " << index << " partid: " << elem.currentpartid << std::endl; } @@ -484,6 +495,9 @@ void SCH_ALTIUM_PLUGIN::ParsePin( const std::map& aPropertie return; } + if( !IsCmpPartVisible( elem.ownerindex, elem.ownerpartid, elem.ownerpartdisplaymode ) ) + return; + const auto& component = m_components.at( symbol->first ); LIB_PIN* pin = new LIB_PIN( symbol->second ); @@ -773,6 +787,9 @@ void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map& aProper return; } + if( !IsCmpPartVisible( elem.ownerindex, elem.ownerpartid, elem.ownerpartdisplaymode ) ) + return; + const auto& component = m_components.at( symbol->first ); for( size_t i = 0; i + 1 < elem.points.size(); i += 3 ) @@ -858,6 +875,9 @@ void SCH_ALTIUM_PLUGIN::ParsePolyline( const std::map& aProp return; } + if( !IsCmpPartVisible( elem.ownerindex, elem.ownerpartid, elem.ownerpartdisplaymode ) ) + return; + const auto& component = m_components.at( symbol->first ); LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second ); @@ -914,6 +934,9 @@ void SCH_ALTIUM_PLUGIN::ParsePolygon( const std::map& aPrope return; } + if( !IsCmpPartVisible( elem.ownerindex, elem.ownerpartid, elem.ownerpartdisplaymode ) ) + return; + const auto& component = m_components.at( symbol->first ); LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second ); @@ -991,6 +1014,9 @@ void SCH_ALTIUM_PLUGIN::ParseRoundRectangle( const std::map& return; } + if( !IsCmpPartVisible( elem.ownerindex, elem.ownerpartid, elem.ownerpartdisplaymode ) ) + return; + const auto& component = m_components.at( symbol->first ); // TODO: misses rounded edges @@ -1030,6 +1056,9 @@ void SCH_ALTIUM_PLUGIN::ParseArc( const std::map& aPropertie return; } + if( !IsCmpPartVisible( elem.ownerindex, elem.ownerpartid, elem.ownerpartdisplaymode ) ) + return; + const auto& component = m_components.at( symbol->first ); if( elem.startAngle == 0 && ( elem.endAngle == 0 || elem.endAngle == 360 ) ) @@ -1083,6 +1112,9 @@ void SCH_ALTIUM_PLUGIN::ParseLine( const std::map& aProperti return; } + if( !IsCmpPartVisible( elem.ownerindex, elem.ownerpartid, elem.ownerpartdisplaymode ) ) + return; + const auto& component = m_components.at( symbol->first ); LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second ); @@ -1149,6 +1181,9 @@ void SCH_ALTIUM_PLUGIN::ParseRectangle( const std::map& aPro return; } + if( !IsCmpPartVisible( elem.ownerindex, elem.ownerpartid, elem.ownerpartdisplaymode ) ) + return; + const auto& component = m_components.at( symbol->first ); LIB_RECTANGLE* rect = new LIB_RECTANGLE( symbol->second ); diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.h b/eeschema/sch_plugins/altium/sch_altium_plugin.h index ae0da369f0..ab39d171b2 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.h +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.h @@ -29,7 +29,8 @@ #include #include -struct ASCH_SHEET; +#include "altium_parser_sch.h" + class SCH_COMPONENT; @@ -101,6 +102,8 @@ public: void Parse( const CFB::CompoundFileReader& aReader ); private: + bool IsCmpPartVisible( int aOwnerindex, int aOwnerpartid, int aOwnerpartdisplaymode ) const; + void ParseComponent( int index, const std::map& aProperties ); void ParsePin( const std::map& aProperties ); void ParseLabel( const std::map& aProperties ); @@ -134,6 +137,8 @@ private: std::unique_ptr m_altiumSheet; std::map m_components; std::map m_symbols; // for the start, every component has its unique symbol + + std::map m_altiumComponents; }; #endif // _SCH_ALTIUM_PLUGIN_H_