From 5bd94f118d5d3c810a632813c130fffdd80bb018 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sun, 5 May 2024 08:39:02 -0700 Subject: [PATCH] ADDED: Handle PIECHART in Altium import Fixes https://gitlab.com/kicad/code/kicad/-/issues/16895 --- eeschema/sch_io/altium/altium_parser_sch.cpp | 8 +- eeschema/sch_io/altium/altium_parser_sch.h | 8 +- eeschema/sch_io/altium/sch_io_altium.cpp | 104 +++++++++++++++++-- eeschema/sch_io/altium/sch_io_altium.h | 1 + 4 files changed, 110 insertions(+), 11 deletions(-) diff --git a/eeschema/sch_io/altium/altium_parser_sch.cpp b/eeschema/sch_io/altium/altium_parser_sch.cpp index ec53227c25..0b0cd04a57 100644 --- a/eeschema/sch_io/altium/altium_parser_sch.cpp +++ b/eeschema/sch_io/altium/altium_parser_sch.cpp @@ -453,7 +453,8 @@ ASCH_ROUND_RECTANGLE::ASCH_ROUND_RECTANGLE( const std::map& ASCH_ARC::ASCH_ARC( const std::map& 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& aProps ) : } +ASCH_PIECHART::ASCH_PIECHART( const std::map& aProps ) : + ASCH_ARC( aProps ) +{} + + ASCH_ELLIPSE::ASCH_ELLIPSE( const std::map& aProps ) : ASCH_OWNER_INTERFACE( aProps ), ASCH_FILL_INTERFACE( aProps ), diff --git a/eeschema/sch_io/altium/altium_parser_sch.h b/eeschema/sch_io/altium/altium_parser_sch.h index 201bef7ab0..825b05ae12 100644 --- a/eeschema/sch_io/altium/altium_parser_sch.h +++ b/eeschema/sch_io/altium/altium_parser_sch.h @@ -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& aProps ); +}; + + struct ASCH_ELLIPSE : ASCH_OWNER_INTERFACE, ASCH_FILL_INTERFACE, ASCH_BORDER_INTERFACE { VECTOR2I Center; diff --git a/eeschema/sch_io/altium/sch_io_altium.cpp b/eeschema/sch_io/altium/sch_io_altium.cpp index 83f7e70f5e..f4408f0439 100644 --- a/eeschema/sch_io/altium/sch_io_altium.cpp +++ b/eeschema/sch_io/altium/sch_io_altium.cpp @@ -884,7 +884,7 @@ void SCH_IO_ALTIUM::ParseRecord( int index, std::map& 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& 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& 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& 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& 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& aPro } +void SCH_IO_ALTIUM::ParsePieChart( const std::map& aProperties, + std::vector& 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& aProperties, std::vector& aSymbol ) { @@ -4204,12 +4295,7 @@ std::map 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; diff --git a/eeschema/sch_io/altium/sch_io_altium.h b/eeschema/sch_io/altium/sch_io_altium.h index 53be6841f3..480bfb7993 100644 --- a/eeschema/sch_io/altium/sch_io_altium.h +++ b/eeschema/sch_io/altium/sch_io_altium.h @@ -153,6 +153,7 @@ private: void ParseHarnessType( const std::map& aProperties ); void ParseHarnessPort( const ASCH_PORT& aElem ); void ParseHyperlink( const std::map& aProperties, std::vector& aSymbol = nullsym); + void ParsePieChart( const std::map& aProperties, std::vector& aSymbol = nullsym); void ParseRectangle( const std::map& aProperties, std::vector& aSymbol = nullsym); void ParseSheetSymbol( int aIndex, const std::map& aProperties ); void ParseSheetEntry( const std::map& aProperties );