ADDED: Handle PIECHART in Altium import

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16895
This commit is contained in:
Seth Hillbrand 2024-05-05 08:39:02 -07:00
parent 4c0fd6e791
commit 5bd94f118d
4 changed files with 110 additions and 11 deletions

View File

@ -453,7 +453,8 @@ ASCH_ROUND_RECTANGLE::ASCH_ROUND_RECTANGLE( const std::map<wxString, wxString>&
ASCH_ARC::ASCH_ARC( const std::map<wxString, wxString>& aProps ) :
ASCH_OWNER_INTERFACE( aProps ),
ASCH_BORDER_INTERFACE( aProps )
ASCH_BORDER_INTERFACE( aProps ),
ASCH_FILL_INTERFACE( aProps )
{
m_IsElliptical = ReadRecord( aProps ) == ALTIUM_SCH_RECORD::ELLIPTICAL_ARC;
wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::ARC || m_IsElliptical );
@ -471,6 +472,11 @@ ASCH_ARC::ASCH_ARC( const std::map<wxString, wxString>& aProps ) :
}
ASCH_PIECHART::ASCH_PIECHART( const std::map<wxString, wxString>& aProps ) :
ASCH_ARC( aProps )
{}
ASCH_ELLIPSE::ASCH_ELLIPSE( const std::map<wxString, wxString>& aProps ) :
ASCH_OWNER_INTERFACE( aProps ),
ASCH_FILL_INTERFACE( aProps ),

View File

@ -480,7 +480,7 @@ struct ASCH_ROUND_RECTANGLE : ASCH_OWNER_INTERFACE, ASCH_FILL_INTERFACE, ASCH_BO
};
struct ASCH_ARC : ASCH_OWNER_INTERFACE, ASCH_BORDER_INTERFACE
struct ASCH_ARC : ASCH_OWNER_INTERFACE, ASCH_BORDER_INTERFACE, ASCH_FILL_INTERFACE
{
bool m_IsElliptical;
VECTOR2I m_Center;
@ -493,6 +493,12 @@ struct ASCH_ARC : ASCH_OWNER_INTERFACE, ASCH_BORDER_INTERFACE
};
struct ASCH_PIECHART : ASCH_ARC
{
explicit ASCH_PIECHART( const std::map<wxString, wxString>& aProps );
};
struct ASCH_ELLIPSE : ASCH_OWNER_INTERFACE, ASCH_FILL_INTERFACE, ASCH_BORDER_INTERFACE
{
VECTOR2I Center;

View File

@ -884,7 +884,7 @@ void SCH_IO_ALTIUM::ParseRecord( int index, std::map<wxString, wxString>& proper
break;
case ALTIUM_SCH_RECORD::PIECHART:
m_reporter->Report( _( "Record 'PIECHART' not handled." ), RPT_SEVERITY_INFO );
ParsePieChart( properties );
break;
case ALTIUM_SCH_RECORD::ROUND_RECTANGLE:
@ -2165,7 +2165,9 @@ void SCH_IO_ALTIUM::ParseArc( const std::map<wxString, wxString>& aProperties,
circle->SetPosition( elem.m_Center + m_sheetOffset );
circle->SetEnd( circle->GetPosition() + VECTOR2I( arc_radius, 0 ) );
circle->SetStroke( STROKE_PARAMS( elem.LineWidth, LINE_STYLE::SOLID ) );
SetSchShapeLine( elem, circle );
SetSchShapeFillAndColor( elem, circle );
currentScreen->Append( circle );
}
@ -2177,7 +2179,8 @@ void SCH_IO_ALTIUM::ParseArc( const std::map<wxString, wxString>& aProperties,
arc->SetStart( elem.m_Center + startOffset + m_sheetOffset );
arc->SetEnd( elem.m_Center + endOffset + m_sheetOffset );
arc->SetStroke( STROKE_PARAMS( elem.LineWidth, LINE_STYLE::SOLID ) );
SetSchShapeLine( elem, arc );
SetSchShapeFillAndColor( elem, arc );
currentScreen->Append( arc );
}
@ -2223,6 +2226,7 @@ void SCH_IO_ALTIUM::ParseArc( const std::map<wxString, wxString>& aProperties,
circle->SetEnd( circle->GetPosition() + VECTOR2I( arc_radius, 0 ) );
SetLibShapeLine( elem, circle, ALTIUM_SCH_RECORD::ARC );
SetLibShapeFillAndColor( elem, circle, ALTIUM_SCH_RECORD::ARC, elem.Color );
}
else
{
@ -2238,6 +2242,7 @@ void SCH_IO_ALTIUM::ParseArc( const std::map<wxString, wxString>& aProperties,
arc->SetEnd( center + endOffset );
SetLibShapeLine( elem, arc, ALTIUM_SCH_RECORD::ARC );
SetLibShapeFillAndColor( elem, arc, ALTIUM_SCH_RECORD::ARC, elem.Color );
}
}
}
@ -2338,6 +2343,92 @@ void SCH_IO_ALTIUM::ParseEllipticalArc( const std::map<wxString, wxString>& aPro
}
void SCH_IO_ALTIUM::ParsePieChart( const std::map<wxString, wxString>& aProperties,
std::vector<LIB_SYMBOL*>& aSymbol )
{
ParseArc( aProperties, aSymbol );
ASCH_PIECHART elem( aProperties );
int arc_radius = elem.m_Radius;
VECTOR2I center = elem.m_Center;
EDA_ANGLE startAngle( elem.m_EndAngle, DEGREES_T );
EDA_ANGLE endAngle( elem.m_StartAngle, DEGREES_T );
VECTOR2I startOffset( KiROUND( arc_radius * startAngle.Cos() ),
-KiROUND( arc_radius * startAngle.Sin() ) );
VECTOR2I endOffset( KiROUND( arc_radius * endAngle.Cos() ),
-KiROUND( arc_radius * endAngle.Sin() ) );
if( aSymbol.empty() && ShouldPutItemOnSheet( elem.ownerindex ) )
{
SCH_SCREEN* screen = getCurrentScreen();
wxCHECK( screen, /* void */ );
// close polygon
SCH_LINE* line = new SCH_LINE( center + m_sheetOffset, SCH_LAYER_ID::LAYER_NOTES );
line->SetEndPoint( center + startOffset + m_sheetOffset );
line->SetStroke( STROKE_PARAMS( elem.LineWidth, LINE_STYLE::SOLID ) );
line->SetFlags( IS_NEW );
screen->Append( line );
line = new SCH_LINE( center + m_sheetOffset, SCH_LAYER_ID::LAYER_NOTES );
line->SetEndPoint( center + endOffset + m_sheetOffset );
line->SetStroke( STROKE_PARAMS( elem.LineWidth, LINE_STYLE::SOLID ) );
line->SetFlags( IS_NEW );
screen->Append( line );
}
else
{
LIB_SYMBOL* symbol = (int) aSymbol.size() <= elem.ownerpartdisplaymode
? nullptr
: aSymbol[elem.ownerpartdisplaymode];
SCH_SYMBOL* schsym = nullptr;
if( !symbol )
{
const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
if( libSymbolIt == m_libSymbols.end() )
{
// TODO: e.g. can depend on Template (RECORD=39
m_reporter->Report( wxString::Format( wxT( "Piechart's owner (%d) not found." ),
elem.ownerindex ),
RPT_SEVERITY_DEBUG );
return;
}
symbol = libSymbolIt->second;
schsym = m_symbols.at( libSymbolIt->first );
}
if( aSymbol.empty() && !IsComponentPartVisible( elem ) )
return;
SCH_SHAPE* line = new SCH_SHAPE( SHAPE_T::POLY, LAYER_DEVICE );
symbol->AddDrawItem( line, false );
line->SetUnit( std::max( 0, elem.ownerpartid ) );
if( !schsym )
{
line->AddPoint( center + startOffset );
line->AddPoint( center );
line->AddPoint( center + endOffset );
}
else
{
line->AddPoint( GetRelativePosition( center + startOffset + m_sheetOffset, schsym ) );
line->AddPoint( GetRelativePosition( center + m_sheetOffset, schsym ) );
line->AddPoint( GetRelativePosition( center + endOffset + m_sheetOffset, schsym ) );
}
SetLibShapeLine( elem, line, ALTIUM_SCH_RECORD::LINE );
}
}
void SCH_IO_ALTIUM::ParseEllipse( const std::map<wxString, wxString>& aProperties,
std::vector<LIB_SYMBOL*>& aSymbol )
{
@ -4204,12 +4295,7 @@ std::map<wxString,LIB_SYMBOL*> SCH_IO_ALTIUM::ParseLibFile( const ALTIUM_COMPOUN
case ALTIUM_SCH_RECORD::ELLIPSE: ParseEllipse( properties, symbols ); break;
case ALTIUM_SCH_RECORD::PIECHART:
m_reporter->Report( wxString::Format( _( "Record 'PIECHART' not handled, found "
"in %s." ),
symbols[0]->GetName() ),
RPT_SEVERITY_ERROR );
break;
case ALTIUM_SCH_RECORD::PIECHART: ParsePieChart( properties, symbols ); break;
case ALTIUM_SCH_RECORD::ROUND_RECTANGLE: ParseRoundRectangle( properties, symbols ); break;

View File

@ -153,6 +153,7 @@ private:
void ParseHarnessType( const std::map<wxString, wxString>& aProperties );
void ParseHarnessPort( const ASCH_PORT& aElem );
void ParseHyperlink( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
void ParsePieChart( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
void ParseRectangle( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
void ParseSheetSymbol( int aIndex, const std::map<wxString, wxString>& aProperties );
void ParseSheetEntry( const std::map<wxString, wxString>& aProperties );