altium: Add initial support for multiunit symbols

Fix: https://gitlab.com/kicad/code/kicad/-/issues/6055
This commit is contained in:
Thomas Pointhuber 2020-10-23 17:02:56 +02:00
parent 0d3d3e0d7c
commit adfc74f93a
4 changed files with 67 additions and 3 deletions

View File

@ -96,6 +96,8 @@ ASCH_PIN::ASCH_PIN( const std::map<wxString, wxString>& 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<wxString, wxString>& 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<wxString, wxString>& 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<wxString, wxString>& 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<wxString, wxString>&
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<wxString, wxString>& 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<wxString, wxString>& 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<wxString, wxString>& 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" ) );

View File

@ -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<wxPoint> points;
@ -267,6 +269,7 @@ struct ASCH_POLYLINE
{
int ownerindex;
int ownerpartid;
int ownerpartdisplaymode;
std::vector<wxPoint> points;
@ -282,6 +285,7 @@ struct ASCH_POLYGON
{
int ownerindex;
int ownerpartid;
int ownerpartdisplaymode;
std::vector<wxPoint> 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;

View File

@ -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<wxString, wxString>& 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::map<wxString, wxSt
m_currentSheet->GetScreen()->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<wxString, wxString>& 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<wxString, wxString>& 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<wxString, wxString>& 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<wxString, wxString>& 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<wxString, wxString>&
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<wxString, wxString>& 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<wxString, wxString>& 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<wxString, wxString>& 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 );

View File

@ -29,7 +29,8 @@
#include <wx/filename.h>
#include <wx/gdicmn.h>
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<wxString, wxString>& aProperties );
void ParsePin( const std::map<wxString, wxString>& aProperties );
void ParseLabel( const std::map<wxString, wxString>& aProperties );
@ -134,6 +137,8 @@ private:
std::unique_ptr<ASCH_SHEET> m_altiumSheet;
std::map<int, SCH_COMPONENT*> m_components;
std::map<int, LIB_PART*> m_symbols; // for the start, every component has its unique symbol
std::map<int, ASCH_COMPONENT> m_altiumComponents;
};
#endif // _SCH_ALTIUM_PLUGIN_H_