From 14ceece4f6a2ca5e0164b26b37dca1d907ed2faf Mon Sep 17 00:00:00 2001 From: WhiteChairFromIkea Date: Tue, 9 Aug 2022 15:00:45 +0300 Subject: [PATCH] Import HARNESS_CONNECTOR as Hierarchical sheet --- .../sch_plugins/altium/altium_parser_sch.cpp | 15 +++++++ .../sch_plugins/altium/altium_parser_sch.h | 22 +++++++++- .../sch_plugins/altium/sch_altium_plugin.cpp | 43 ++++++++++++++++++- .../sch_plugins/altium/sch_altium_plugin.h | 4 ++ 4 files changed, 82 insertions(+), 2 deletions(-) diff --git a/eeschema/sch_plugins/altium/altium_parser_sch.cpp b/eeschema/sch_plugins/altium/altium_parser_sch.cpp index 6a820120a8..2084b91e86 100644 --- a/eeschema/sch_plugins/altium/altium_parser_sch.cpp +++ b/eeschema/sch_plugins/altium/altium_parser_sch.cpp @@ -433,6 +433,21 @@ ASCH_SIGNAL_HARNESS::ASCH_SIGNAL_HARNESS( const std::map& aP } +ASCH_HARNESS_CONNECTOR::ASCH_HARNESS_CONNECTOR( const std::map& aProps ) +{ + wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::HARNESS_CONNECTOR ); + + ownerpartid = ReadOwnerPartId( aProps ); + + location = VECTOR2I( ReadKiCadUnitFrac( aProps, "LOCATION.X" ), + -ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) ); + size = wxSize( ReadKiCadUnitFrac( aProps, "XSIZE" ), ReadKiCadUnitFrac( aProps, "YSIZE" ) ); + + color = ALTIUM_PARSER::ReadInt( aProps, "COLOR", 0 ); + areaColor = ALTIUM_PARSER::ReadInt( aProps, "AREACOLOR", 0 ); +} + + ASCH_RECTANGLE::ASCH_RECTANGLE( const std::map& aProps ) { wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::RECTANGLE ); diff --git a/eeschema/sch_plugins/altium/altium_parser_sch.h b/eeschema/sch_plugins/altium/altium_parser_sch.h index 84fe5eea5e..85d4fc3dbc 100644 --- a/eeschema/sch_plugins/altium/altium_parser_sch.h +++ b/eeschema/sch_plugins/altium/altium_parser_sch.h @@ -99,7 +99,7 @@ enum class ALTIUM_SCH_RECORD RECORD_48 = 48, NOTE = 209, COMPILE_MASK = 211, - RECORD_215 = 215, + HARNESS_CONNECTOR = 215, RECORD_216 = 216, RECORD_217 = 217, SIGNAL_HARNESS = 218, @@ -423,6 +423,26 @@ struct ASCH_SIGNAL_HARNESS }; +struct ASCH_HARNESS_CONNECTOR +{ + int ownerpartid; // always -1, can be safely ignored I think + + VECTOR2I location; + wxSize size; + + int areaColor; + int color; + int indexInSheet; // Keeps increasing nicely + int lineWidth; + //int locationX; // keep just in case + //int locationY; + int locationPrimaryConnectionPosition; + //int xSize; // keep just in case + //int ySize; + + explicit ASCH_HARNESS_CONNECTOR( const std::map& aProps ); +}; + struct ASCH_RECTANGLE : ASCH_SHAPE_INTERFACE { diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp index ba748cad3a..2bb6506cec 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp @@ -375,7 +375,8 @@ void SCH_ALTIUM_PLUGIN::ParseAdditional( const ALTIUM_COMPOUND_FILE& aAltiumSchF // see: https://github.com/vadmium/python-altium/blob/master/format.md switch( record ) { - case ALTIUM_SCH_RECORD::RECORD_215: + case ALTIUM_SCH_RECORD::HARNESS_CONNECTOR: + ParseHarnessConnector( index, properties ); break; case ALTIUM_SCH_RECORD::RECORD_216: break; @@ -1483,6 +1484,46 @@ void SCH_ALTIUM_PLUGIN::ParseSignalHarness( const std::map& } +void SCH_ALTIUM_PLUGIN::ParseHarnessConnector( int aIndex, const std::map& aProperties ) +{ + ASCH_HARNESS_CONNECTOR elem( aProperties ); + + if( elem.ownerpartid == ALTIUM_COMPONENT_NONE ) + { + SCH_SHEET* sheet = new SCH_SHEET( + /* aParent */ m_currentSheet, + /* aPosition */ elem.location + m_sheetOffset, + /* aSize */ elem.size ); + SCH_SCREEN* screen = new SCH_SCREEN( m_schematic ); + + sheet->SetBackgroundColor( GetColorFromInt( elem.areaColor ) ); + sheet->SetBorderColor( GetColorFromInt( elem.color ) ); + + sheet->SetScreen( screen ); + + sheet->SetFlags( IS_NEW ); + m_currentSheet->GetScreen()->Append( sheet ); + + SCH_SHEET_PATH sheetpath; + m_rootSheet->LocatePathOfScreen( m_currentSheet->GetScreen(), &sheetpath ); + sheetpath.push_back( sheet ); + + sheet->AddInstance( sheetpath ); + sheet->SetPageNumber( sheetpath, "Harness #" ); + + m_harnessEntryParent = aIndex + m_harnessOwnerIndexOffset; + m_sheets.insert( { m_harnessEntryParent, sheet } ); + } + else + { + // I have no clue if this situation can ever exist + m_reporter->Report( + _( "Harness connector, belonging to the part is not currently supported." ), + RPT_SEVERITY_ERROR ); + } +} + + void SCH_ALTIUM_PLUGIN::ParseRectangle( const std::map& aProperties ) { ASCH_RECTANGLE elem( aProperties ); diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.h b/eeschema/sch_plugins/altium/sch_altium_plugin.h index c408f70dad..d063cd2297 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.h +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.h @@ -122,6 +122,7 @@ private: void ParseArc( const std::map& aProperties ); void ParseLine( const std::map& aProperties ); void ParseSignalHarness( const std::map& aProperties ); + void ParseHarnessConnector( int aIndex, const std::map& aProperties ); void ParseRectangle( const std::map& aProperties ); void ParseSheetSymbol( int aIndex, const std::map& aProperties ); void ParseSheetEntry( const std::map& aProperties ); @@ -169,6 +170,9 @@ private: std::map m_altiumComponents; std::map m_altiumImplementationList; std::vector m_altiumPortsCurrentSheet; // we require all connections first + + int m_harnessOwnerIndexOffset; // Add offset to all harness ownerIndex'es after parsing FileHeader + int m_harnessEntryParent; // used to identify harness connector for harness entry element }; #endif // _SCH_ALTIUM_PLUGIN_H_