altium: Correctly parse multiunit symbols

Followup to https://gitlab.com/kicad/code/kicad/-/issues/6055
This commit is contained in:
Thomas Pointhuber 2020-10-23 17:20:07 +02:00
parent adfc74f93a
commit b7c2d64333
2 changed files with 38 additions and 13 deletions

View File

@ -442,15 +442,14 @@ void SCH_ALTIUM_PLUGIN::Parse( const CFB::CompoundFileReader& aReader )
m_currentSheet->SetModified(); m_currentSheet->SetModified();
} }
bool SCH_ALTIUM_PLUGIN::IsCmpPartVisible(
int aOwnerindex, int aOwnerpartid, int aOwnerpartdisplaymode ) const bool SCH_ALTIUM_PLUGIN::IsComponentPartVisible( int aOwnerindex, int aOwnerpartdisplaymode ) const
{ {
const auto& component = m_altiumComponents.find( aOwnerindex ); const auto& component = m_altiumComponents.find( aOwnerindex );
if( component == m_altiumComponents.end() ) if( component == m_altiumComponents.end() )
return false; return false;
const ASCH_COMPONENT& cmp = component->second; return component->second.displaymode == aOwnerpartdisplaymode;
return ( cmp.currentpartid == aOwnerpartid ) && ( cmp.displaymode == aOwnerpartdisplaymode );
} }
@ -475,6 +474,8 @@ void SCH_ALTIUM_PLUGIN::ParseComponent( int index, const std::map<wxString, wxSt
component->SetLibId( libId ); component->SetLibId( libId );
//component->SetLibSymbol( kpart ); // this has to be done after parsing the LIB_PART! //component->SetLibSymbol( kpart ); // this has to be done after parsing the LIB_PART!
component->SetUnit( elem.currentpartid );
m_currentSheet->GetScreen()->Append( component ); m_currentSheet->GetScreen()->Append( component );
m_components.insert( { index, component } ); m_components.insert( { index, component } );
@ -495,7 +496,7 @@ void SCH_ALTIUM_PLUGIN::ParsePin( const std::map<wxString, wxString>& aPropertie
return; return;
} }
if( !IsCmpPartVisible( elem.ownerindex, elem.ownerpartid, elem.ownerpartdisplaymode ) ) if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
return; return;
const auto& component = m_components.at( symbol->first ); const auto& component = m_components.at( symbol->first );
@ -503,6 +504,8 @@ void SCH_ALTIUM_PLUGIN::ParsePin( const std::map<wxString, wxString>& aPropertie
LIB_PIN* pin = new LIB_PIN( symbol->second ); LIB_PIN* pin = new LIB_PIN( symbol->second );
symbol->second->AddDrawItem( pin ); symbol->second->AddDrawItem( pin );
pin->SetUnit( elem.ownerpartid );
pin->SetName( elem.name ); pin->SetName( elem.name );
pin->SetNumber( elem.designator ); pin->SetNumber( elem.designator );
pin->SetLength( elem.pinlength ); pin->SetLength( elem.pinlength );
@ -705,6 +708,8 @@ void SCH_ALTIUM_PLUGIN::ParseLabel( const std::map<wxString, wxString>& aPropert
LIB_TEXT* text = new LIB_TEXT( symbol->second ); LIB_TEXT* text = new LIB_TEXT( symbol->second );
symbol->second->AddDrawItem( text ); symbol->second->AddDrawItem( text );
text->SetUnit( elem.ownerpartid );
text->SetPosition( GetRelativePosition( elem.location + m_sheetOffset, component ) ); text->SetPosition( GetRelativePosition( elem.location + m_sheetOffset, component ) );
text->SetText( elem.text ); text->SetText( elem.text );
@ -787,7 +792,7 @@ void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map<wxString, wxString>& aProper
return; return;
} }
if( !IsCmpPartVisible( elem.ownerindex, elem.ownerpartid, elem.ownerpartdisplaymode ) ) if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
return; return;
const auto& component = m_components.at( symbol->first ); const auto& component = m_components.at( symbol->first );
@ -800,6 +805,8 @@ void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map<wxString, wxString>& aProper
LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second ); LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second );
symbol->second->AddDrawItem( line ); symbol->second->AddDrawItem( line );
line->SetUnit( elem.ownerpartid );
for( size_t j = i; j < elem.points.size() && j < i + 2; j++ ) for( size_t j = i; j < elem.points.size() && j < i + 2; j++ )
{ {
line->AddPoint( line->AddPoint(
@ -814,6 +821,8 @@ void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map<wxString, wxString>& aProper
LIB_BEZIER* bezier = new LIB_BEZIER( symbol->second ); LIB_BEZIER* bezier = new LIB_BEZIER( symbol->second );
symbol->second->AddDrawItem( bezier ); symbol->second->AddDrawItem( bezier );
bezier->SetUnit( elem.ownerpartid );
for( size_t j = i; j < elem.points.size() && j < i + 4; j++ ) for( size_t j = i; j < elem.points.size() && j < i + 4; j++ )
{ {
bezier->AddPoint( bezier->AddPoint(
@ -875,7 +884,7 @@ void SCH_ALTIUM_PLUGIN::ParsePolyline( const std::map<wxString, wxString>& aProp
return; return;
} }
if( !IsCmpPartVisible( elem.ownerindex, elem.ownerpartid, elem.ownerpartdisplaymode ) ) if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
return; return;
const auto& component = m_components.at( symbol->first ); const auto& component = m_components.at( symbol->first );
@ -883,6 +892,8 @@ void SCH_ALTIUM_PLUGIN::ParsePolyline( const std::map<wxString, wxString>& aProp
LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second ); LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second );
symbol->second->AddDrawItem( line ); symbol->second->AddDrawItem( line );
line->SetUnit( elem.ownerpartid );
for( wxPoint& point : elem.points ) for( wxPoint& point : elem.points )
{ {
line->AddPoint( GetRelativePosition( point + m_sheetOffset, component ) ); line->AddPoint( GetRelativePosition( point + m_sheetOffset, component ) );
@ -934,7 +945,7 @@ void SCH_ALTIUM_PLUGIN::ParsePolygon( const std::map<wxString, wxString>& aPrope
return; return;
} }
if( !IsCmpPartVisible( elem.ownerindex, elem.ownerpartid, elem.ownerpartdisplaymode ) ) if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
return; return;
const auto& component = m_components.at( symbol->first ); const auto& component = m_components.at( symbol->first );
@ -942,6 +953,8 @@ void SCH_ALTIUM_PLUGIN::ParsePolygon( const std::map<wxString, wxString>& aPrope
LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second ); LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second );
symbol->second->AddDrawItem( line ); symbol->second->AddDrawItem( line );
line->SetUnit( elem.ownerpartid );
for( wxPoint& point : elem.points ) for( wxPoint& point : elem.points )
{ {
line->AddPoint( GetRelativePosition( point + m_sheetOffset, component ) ); line->AddPoint( GetRelativePosition( point + m_sheetOffset, component ) );
@ -1014,7 +1027,7 @@ void SCH_ALTIUM_PLUGIN::ParseRoundRectangle( const std::map<wxString, wxString>&
return; return;
} }
if( !IsCmpPartVisible( elem.ownerindex, elem.ownerpartid, elem.ownerpartdisplaymode ) ) if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
return; return;
const auto& component = m_components.at( symbol->first ); const auto& component = m_components.at( symbol->first );
@ -1022,6 +1035,9 @@ void SCH_ALTIUM_PLUGIN::ParseRoundRectangle( const std::map<wxString, wxString>&
// TODO: misses rounded edges // TODO: misses rounded edges
LIB_RECTANGLE* rect = new LIB_RECTANGLE( symbol->second ); LIB_RECTANGLE* rect = new LIB_RECTANGLE( symbol->second );
symbol->second->AddDrawItem( rect ); symbol->second->AddDrawItem( rect );
rect->SetUnit( elem.ownerpartid );
rect->SetPosition( GetRelativePosition( elem.topRight + m_sheetOffset, component ) ); rect->SetPosition( GetRelativePosition( elem.topRight + m_sheetOffset, component ) );
rect->SetEnd( GetRelativePosition( elem.bottomLeft + m_sheetOffset, component ) ); rect->SetEnd( GetRelativePosition( elem.bottomLeft + m_sheetOffset, component ) );
rect->SetWidth( elem.lineWidth ); rect->SetWidth( elem.lineWidth );
@ -1056,7 +1072,7 @@ void SCH_ALTIUM_PLUGIN::ParseArc( const std::map<wxString, wxString>& aPropertie
return; return;
} }
if( !IsCmpPartVisible( elem.ownerindex, elem.ownerpartid, elem.ownerpartdisplaymode ) ) if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
return; return;
const auto& component = m_components.at( symbol->first ); const auto& component = m_components.at( symbol->first );
@ -1066,6 +1082,8 @@ void SCH_ALTIUM_PLUGIN::ParseArc( const std::map<wxString, wxString>& aPropertie
LIB_CIRCLE* circle = new LIB_CIRCLE( symbol->second ); LIB_CIRCLE* circle = new LIB_CIRCLE( symbol->second );
symbol->second->AddDrawItem( circle ); symbol->second->AddDrawItem( circle );
circle->SetUnit( elem.ownerpartid );
circle->SetPosition( GetRelativePosition( elem.center + m_sheetOffset, component ) ); circle->SetPosition( GetRelativePosition( elem.center + m_sheetOffset, component ) );
circle->SetRadius( elem.radius ); circle->SetRadius( elem.radius );
circle->SetWidth( elem.lineWidth ); circle->SetWidth( elem.lineWidth );
@ -1075,6 +1093,8 @@ void SCH_ALTIUM_PLUGIN::ParseArc( const std::map<wxString, wxString>& aPropertie
LIB_ARC* arc = new LIB_ARC( symbol->second ); LIB_ARC* arc = new LIB_ARC( symbol->second );
symbol->second->AddDrawItem( arc ); symbol->second->AddDrawItem( arc );
arc->SetUnit( elem.ownerpartid );
// TODO: correct? // TODO: correct?
arc->SetPosition( GetRelativePosition( elem.center + m_sheetOffset, component ) ); arc->SetPosition( GetRelativePosition( elem.center + m_sheetOffset, component ) );
arc->SetRadius( elem.radius ); arc->SetRadius( elem.radius );
@ -1112,7 +1132,7 @@ void SCH_ALTIUM_PLUGIN::ParseLine( const std::map<wxString, wxString>& aProperti
return; return;
} }
if( !IsCmpPartVisible( elem.ownerindex, elem.ownerpartid, elem.ownerpartdisplaymode ) ) if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
return; return;
const auto& component = m_components.at( symbol->first ); const auto& component = m_components.at( symbol->first );
@ -1120,6 +1140,8 @@ void SCH_ALTIUM_PLUGIN::ParseLine( const std::map<wxString, wxString>& aProperti
LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second ); LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second );
symbol->second->AddDrawItem( line ); symbol->second->AddDrawItem( line );
line->SetUnit( elem.ownerpartid );
line->AddPoint( GetRelativePosition( elem.point1 + m_sheetOffset, component ) ); line->AddPoint( GetRelativePosition( elem.point1 + m_sheetOffset, component ) );
line->AddPoint( GetRelativePosition( elem.point2 + m_sheetOffset, component ) ); line->AddPoint( GetRelativePosition( elem.point2 + m_sheetOffset, component ) );
@ -1181,13 +1203,16 @@ void SCH_ALTIUM_PLUGIN::ParseRectangle( const std::map<wxString, wxString>& aPro
return; return;
} }
if( !IsCmpPartVisible( elem.ownerindex, elem.ownerpartid, elem.ownerpartdisplaymode ) ) if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
return; return;
const auto& component = m_components.at( symbol->first ); const auto& component = m_components.at( symbol->first );
LIB_RECTANGLE* rect = new LIB_RECTANGLE( symbol->second ); LIB_RECTANGLE* rect = new LIB_RECTANGLE( symbol->second );
symbol->second->AddDrawItem( rect ); symbol->second->AddDrawItem( rect );
rect->SetUnit( elem.ownerpartid );
rect->SetPosition( GetRelativePosition( sheetTopRight, component ) ); rect->SetPosition( GetRelativePosition( sheetTopRight, component ) );
rect->SetEnd( GetRelativePosition( sheetBottomLeft, component ) ); rect->SetEnd( GetRelativePosition( sheetBottomLeft, component ) );
rect->SetWidth( elem.lineWidth ); rect->SetWidth( elem.lineWidth );

View File

@ -102,7 +102,7 @@ public:
void Parse( const CFB::CompoundFileReader& aReader ); void Parse( const CFB::CompoundFileReader& aReader );
private: private:
bool IsCmpPartVisible( int aOwnerindex, int aOwnerpartid, int aOwnerpartdisplaymode ) const; bool IsComponentPartVisible( int aOwnerindex, int aOwnerpartdisplaymode ) const;
void ParseComponent( int index, const std::map<wxString, wxString>& aProperties ); void ParseComponent( int index, const std::map<wxString, wxString>& aProperties );
void ParsePin( const std::map<wxString, wxString>& aProperties ); void ParsePin( const std::map<wxString, wxString>& aProperties );