diff --git a/eeschema/sch_plugins/altium/altium_parser_sch.cpp b/eeschema/sch_plugins/altium/altium_parser_sch.cpp index baf099f080..ab18598c14 100644 --- a/eeschema/sch_plugins/altium/altium_parser_sch.cpp +++ b/eeschema/sch_plugins/altium/altium_parser_sch.cpp @@ -742,6 +742,28 @@ ASCH_DESIGNATOR::ASCH_DESIGNATOR( const std::map& aPropertie } +ASCH_IMPLEMENTATION::ASCH_IMPLEMENTATION( const std::map& aProperties ) +{ + wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::IMPLEMENTATION ); + + // "OWNERINDEX" points to unknown item. Use ASCH_IMPLEMENTATION_LIST -> OWNERINDEX prior in order to get real ownerindex for this particular implementation + //ownerindex = + // ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERINDEX", ALTIUM_COMPONENT_NONE ); + name = ALTIUM_PARSER::PropertiesReadString( aProperties, "MODELNAME", "" ); + type = ALTIUM_PARSER::PropertiesReadString( aProperties, "MODELTYPE", "" ); + libname = ALTIUM_PARSER::PropertiesReadString( aProperties, "MODELDATAFILE0", "" ); + isCurrent = ALTIUM_PARSER::PropertiesReadBool( aProperties, "ISCURRENT", false ); +} + + +ASCH_IMPLEMENTATION_LIST::ASCH_IMPLEMENTATION_LIST( const std::map& aProperties ) +{ + wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::IMPLEMENTATION_LIST ); + + ownerindex = + ALTIUM_PARSER::PropertiesReadInt( aProperties, "OWNERINDEX", ALTIUM_COMPONENT_NONE ); +} + ASCH_BUS_ENTRY::ASCH_BUS_ENTRY( const std::map& aProperties ) { wxASSERT( PropertiesReadRecord( aProperties ) == ALTIUM_SCH_RECORD::BUS_ENTRY ); diff --git a/eeschema/sch_plugins/altium/altium_parser_sch.h b/eeschema/sch_plugins/altium/altium_parser_sch.h index e3d76e0896..9ccce4ed53 100644 --- a/eeschema/sch_plugins/altium/altium_parser_sch.h +++ b/eeschema/sch_plugins/altium/altium_parser_sch.h @@ -703,6 +703,28 @@ struct ASCH_DESIGNATOR }; +struct ASCH_IMPLEMENTATION +{ + // IMPLEMENTATION_LIST -> ownerindex must be read and used for these IMPLEMENTATIONs + // int ownerindex; + + wxString name; + wxString type; + wxString libname; + + bool isCurrent; + + explicit ASCH_IMPLEMENTATION( const std::map& aProperties ); +}; + + +struct ASCH_IMPLEMENTATION_LIST +{ + int ownerindex; + explicit ASCH_IMPLEMENTATION_LIST( const std::map& aProperties ); +}; + + struct ASCH_BUS_ENTRY { wxPoint location; diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp index 5d759c24b3..8b0c95ff47 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp @@ -347,7 +347,10 @@ void SCH_ALTIUM_PLUGIN::ParseFileHeader( const CFB::CompoundFileReader& aReader m_currentTitleBlock = std::make_unique(); - // index is required required to resolve OWNERINDEX + // Track implementation_list ownerindex, because subsequent implementations will depend on it + int implementationlistindex = -1; + + // index is required to resolve OWNERINDEX for( int index = 0; reader.GetRemainingBytes() > 0; index++ ) { std::map properties = reader.ReadProperties(); @@ -429,7 +432,9 @@ void SCH_ALTIUM_PLUGIN::ParseFileHeader( const CFB::CompoundFileReader& aReader case ALTIUM_SCH_RECORD::JUNCTION: ParseJunction( properties ); break; - case ALTIUM_SCH_RECORD::IMAGE: ParseImage( properties ); break; + case ALTIUM_SCH_RECORD::IMAGE: + ParseImage( properties ); + break; case ALTIUM_SCH_RECORD::SHEET: ParseSheet( properties ); break; @@ -453,8 +458,13 @@ void SCH_ALTIUM_PLUGIN::ParseFileHeader( const CFB::CompoundFileReader& aReader case ALTIUM_SCH_RECORD::WARNING_SIGN: break; case ALTIUM_SCH_RECORD::IMPLEMENTATION_LIST: + { + ASCH_IMPLEMENTATION_LIST elem( properties ); + implementationlistindex = elem.ownerindex; + } break; case ALTIUM_SCH_RECORD::IMPLEMENTATION: + ParseImplementation( properties, implementationlistindex ); break; case ALTIUM_SCH_RECORD::RECORD_46: break; @@ -1058,9 +1068,7 @@ void SCH_ALTIUM_PLUGIN::ParsePolyline( const std::map& aProp line->SetUnit( elem.ownerpartid ); for( wxPoint& point : elem.points ) - { line->AddPoint( GetRelativePosition( point + m_sheetOffset, symbol ) ); - } line->SetWidth( elem.lineWidth ); } @@ -1227,6 +1235,7 @@ void SCH_ALTIUM_PLUGIN::ParseArc( const std::map& aPropertie else { const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex ); + if( libSymbolIt == m_libSymbols.end() ) { // TODO: e.g. can depend on Template (RECORD=39 @@ -2051,7 +2060,6 @@ void SCH_ALTIUM_PLUGIN::ParseSheet( const std::map& aPropert PAGE_INFO pageInfo; bool isPortrait = m_altiumSheet->sheetOrientation == ASCH_SHEET_WORKSPACEORIENTATION::PORTRAIT; - switch( m_altiumSheet->sheetSize ) { default: @@ -2276,3 +2284,30 @@ void SCH_ALTIUM_PLUGIN::ParseParameter( const std::map& aPro } } } + +void SCH_ALTIUM_PLUGIN::ParseImplementation( const std::map& aProperties, + int ownerindex ) +{ + ASCH_IMPLEMENTATION elem( aProperties ); + + // Only get footprint, currently assigned only + if( ( elem.type == "PCBLIB" ) && ( elem.isCurrent ) ) + { + const auto& libSymbolIt = m_libSymbols.find( ownerindex ); + + if( libSymbolIt == m_libSymbols.end() ) + { + m_reporter->Report( wxString::Format( _( "Footprint has non-existent ownerindex %d." ), + ownerindex ), + RPT_SEVERITY_WARNING ); + return; + } + + const auto& component = m_symbols.at( libSymbolIt->first ); + + if( elem.libname != "" ) + component->SetFootprint( elem.libname + wxT( ":" ) + elem.name ); + else + component->SetFootprint( elem.name ); + } +} diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.h b/eeschema/sch_plugins/altium/sch_altium_plugin.h index 02e6488120..c7d0fbb4d0 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.h +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.h @@ -139,6 +139,7 @@ private: void ParseDesignator( const std::map& aProperties ); void ParseBusEntry( const std::map& aProperties ); void ParseParameter( const std::map& aProperties ); + void ParseImplementation( const std::map& aProperties, int ownerindex ); private: REPORTER* m_reporter; // current reporter for warnings/errors