From fa8208182a64cb959edbee34d0cc5e5ab7607476 Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Sat, 10 Oct 2020 16:56:19 +0200 Subject: [PATCH] altium: add support for bezier (symbol only) and polyline --- .../sch_plugins/altium/altium_parser_sch.cpp | 42 ++++++++++ .../sch_plugins/altium/altium_parser_sch.h | 26 ++++++ .../sch_plugins/altium/sch_altium_plugin.cpp | 80 +++++++++++++++++++ .../sch_plugins/altium/sch_altium_plugin.h | 2 + 4 files changed, 150 insertions(+) diff --git a/eeschema/sch_plugins/altium/altium_parser_sch.cpp b/eeschema/sch_plugins/altium/altium_parser_sch.cpp index e2294b8f35..7d428e9bbd 100644 --- a/eeschema/sch_plugins/altium/altium_parser_sch.cpp +++ b/eeschema/sch_plugins/altium/altium_parser_sch.cpp @@ -153,6 +153,48 @@ ASCH_PIN::ASCH_PIN( const std::map& aProperties ) } +ASCH_BEZIER::ASCH_BEZIER( const std::map& aProperties ) +{ + wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::BEZIER ); + + ownerindex = + ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERINDEX", ALTIUM_COMPONENT_NONE ); + ownerpartid = + ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTID", ALTIUM_COMPONENT_NONE ); + + int locationCount = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATIONCOUNT", 0 ); + for( int i = 1; i <= locationCount; i++ ) + { + const wxString si = std::to_string( i ); + points.emplace_back( PropertiesReadKiCadUnitFrac( aProperties, "X" + si ), + -PropertiesReadKiCadUnitFrac( aProperties, "Y" + si ) ); + } + + lineWidth = PropertiesReadKiCadUnitFrac( aProperties, "LINEWIDTH" ); +} + + +ASCH_POLYLINE::ASCH_POLYLINE( const std::map& aProperties ) +{ + wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::POLYLINE ); + + ownerindex = + ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERINDEX", ALTIUM_COMPONENT_NONE ); + ownerpartid = + ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERPARTID", ALTIUM_COMPONENT_NONE ); + + int locationCount = ALTIUM_PARSER::PropertiesReadInt( aProperties, "LOCATIONCOUNT", 0 ); + for( int i = 1; i <= locationCount; i++ ) + { + const wxString si = std::to_string( i ); + points.emplace_back( PropertiesReadKiCadUnitFrac( aProperties, "X" + si ), + -PropertiesReadKiCadUnitFrac( aProperties, "Y" + si ) ); + } + + lineWidth = PropertiesReadKiCadUnitFrac( aProperties, "LINEWIDTH" ); +} + + ASCH_POLYGON::ASCH_POLYGON( const std::map& aProperties ) { wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::POLYGON ); diff --git a/eeschema/sch_plugins/altium/altium_parser_sch.h b/eeschema/sch_plugins/altium/altium_parser_sch.h index ed118fb7fe..a49f101234 100644 --- a/eeschema/sch_plugins/altium/altium_parser_sch.h +++ b/eeschema/sch_plugins/altium/altium_parser_sch.h @@ -196,6 +196,32 @@ struct ASCH_PIN }; +struct ASCH_BEZIER +{ + int ownerindex; + int ownerpartid; + + std::vector points; + + int lineWidth; + + explicit ASCH_BEZIER( const std::map& aProperties ); +}; + + +struct ASCH_POLYLINE +{ + int ownerindex; + int ownerpartid; + + std::vector points; + + int lineWidth; + + explicit ASCH_POLYLINE( const std::map& aProperties ); +}; + + struct ASCH_POLYGON { int ownerindex; diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp index 73df58436e..df6cdab962 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -308,8 +309,10 @@ void SCH_ALTIUM_PLUGIN::Parse( const CFB::CompoundFileReader& aReader ) case ALTIUM_SCH_RECORD::LABEL: break; case ALTIUM_SCH_RECORD::BEZIER: + ParseBezier( properties ); break; case ALTIUM_SCH_RECORD::POLYLINE: + ParsePolyline( properties ); break; case ALTIUM_SCH_RECORD::POLYGON: ParsePolygon( properties ); @@ -591,6 +594,83 @@ void SCH_ALTIUM_PLUGIN::ParsePin( const std::map& aPropertie } +void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map& aProperties ) +{ + ASCH_BEZIER elem( aProperties ); + + if( elem.ownerpartid == ALTIUM_COMPONENT_NONE ) + { + wxLogError( "Bezier drawing is not possible for now on schematic." ); + } + else + { + const auto& symbol = m_symbols.find( elem.ownerindex ); + if( symbol == m_symbols.end() ) + { + // TODO: e.g. can depend on Template (RECORD=39 + wxLogWarning( wxString::Format( + "Rectangle tries to access symbol with ownerindex %d which does not exist", + elem.ownerindex ) ); + return; + } + + const auto& component = m_components.at( symbol->first ); + + LIB_BEZIER* bezier = new LIB_BEZIER( symbol->second ); + symbol->second->AddDrawItem( bezier ); + + for( wxPoint& point : elem.points ) + { + bezier->AddPoint( GetRelativePosition( point, component ) ); + } + + bezier->SetWidth( elem.lineWidth ); + } +} + + +void SCH_ALTIUM_PLUGIN::ParsePolyline( const std::map& aProperties ) +{ + ASCH_POLYLINE elem( aProperties ); + + if( elem.ownerpartid == ALTIUM_COMPONENT_NONE ) + { + for( int i = 0; i < (int) elem.points.size() - 1; i++ ) + { + SCH_LINE* line = new SCH_LINE( elem.points.at( i ), SCH_LAYER_ID::LAYER_NOTES ); + line->SetEndPoint( elem.points.at( i + 1 ) ); + + line->SetFlags( IS_NEW ); + m_currentSheet->GetScreen()->Append( line ); + } + } + else + { + const auto& symbol = m_symbols.find( elem.ownerindex ); + if( symbol == m_symbols.end() ) + { + // TODO: e.g. can depend on Template (RECORD=39 + wxLogWarning( wxString::Format( + "Rectangle tries to access symbol with ownerindex %d which does not exist", + elem.ownerindex ) ); + return; + } + + const auto& component = m_components.at( symbol->first ); + + LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second ); + symbol->second->AddDrawItem( line ); + + for( wxPoint& point : elem.points ) + { + line->AddPoint( GetRelativePosition( point, component ) ); + } + + line->SetWidth( elem.lineWidth ); + } +} + + void SCH_ALTIUM_PLUGIN::ParsePolygon( const std::map& aProperties ) { ASCH_POLYGON elem( aProperties ); diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.h b/eeschema/sch_plugins/altium/sch_altium_plugin.h index f51cdf3ee4..fa0600a088 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.h +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.h @@ -100,6 +100,8 @@ public: private: void ParseComponent( int index, const std::map& aProperties ); void ParsePin( const std::map& aProperties ); + void ParseBezier( const std::map& aProperties ); + void ParsePolyline( const std::map& aProperties ); void ParsePolygon( const std::map& aProperties ); void ParseRectangle( const std::map& aProperties ); void ParseNetLabel( const std::map& aProperties );