From 292aff48fde9ef8f8267baf04a4f0d8ea85a2d35 Mon Sep 17 00:00:00 2001 From: WhiteChairFromIkea Date: Tue, 2 Mar 2021 10:42:16 +0200 Subject: [PATCH] Import footprint to symbols. Subsheet is name is prepended to footprint name, which is probably NOT OK when syncing with PCB. --- .../sch_plugins/altium/altium_parser_sch.cpp | 21 ++++++++++ .../sch_plugins/altium/altium_parser_sch.h | 19 +++++++++ .../sch_plugins/altium/sch_altium_plugin.cpp | 41 ++++++++++++++++++- .../sch_plugins/altium/sch_altium_plugin.h | 1 + 4 files changed, 80 insertions(+), 2 deletions(-) diff --git a/eeschema/sch_plugins/altium/altium_parser_sch.cpp b/eeschema/sch_plugins/altium/altium_parser_sch.cpp index 5c3ff702a3..77aa2c88fe 100644 --- a/eeschema/sch_plugins/altium/altium_parser_sch.cpp +++ b/eeschema/sch_plugins/altium/altium_parser_sch.cpp @@ -678,6 +678,27 @@ ASCH_DESIGNATOR::ASCH_DESIGNATOR( const std::map& aPropertie -PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.Y" ) ); } +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 ) { diff --git a/eeschema/sch_plugins/altium/altium_parser_sch.h b/eeschema/sch_plugins/altium/altium_parser_sch.h index 4aab310fdb..96dab895d5 100644 --- a/eeschema/sch_plugins/altium/altium_parser_sch.h +++ b/eeschema/sch_plugins/altium/altium_parser_sch.h @@ -646,6 +646,25 @@ struct ASCH_DESIGNATOR explicit ASCH_DESIGNATOR( const std::map& aProperties ); }; +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 { diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp index 8e408105e7..2b14e266be 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp @@ -302,7 +302,9 @@ void SCH_ALTIUM_PLUGIN::Parse( 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(); @@ -409,8 +411,13 @@ void SCH_ALTIUM_PLUGIN::Parse( 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; @@ -2079,7 +2086,7 @@ void SCH_ALTIUM_PLUGIN::ParseParameter( const std::map& aPro const wxPoint position = elem.location + m_sheetOffset; SCH_FIELD* field = nullptr; - if( elem.name == "Value" ) + if( elem.name == "Comment" ) { field = component->GetField( VALUE_FIELD ); field->SetPosition( position ); @@ -2110,3 +2117,33 @@ void SCH_ALTIUM_PLUGIN::ParseParameter( const std::map& aPro } } } +void SCH_ALTIUM_PLUGIN::ParseImplementation( const std::map& aProperties, + int ownerindex ) +{ + ASCH_IMPLEMENTATION elem( aProperties ); + // wxLogWarning( "Current footprint is: %i, %s, %s, %i, last impl list index was: %i\n", + // elem.ownerindex, TO_UTF8( elem.name ), TO_UTF8( elem.type ), (int) elem.isCurrent, + // ownerindex ); + // Only get footprint, currently assigned only + if( ( elem.type == "PCBLIB" ) && ( elem.isCurrent ) ) + { + const auto& symbol = m_symbols.find( ownerindex ); + if( symbol == m_symbols.end() ) + { + wxLogWarning( + wxString::Format( "Footprint has non-existent ownerindex %d", ownerindex ) ); + return; + } + const auto& component = m_components.at( symbol->first ); + if( elem.libname != "" ) + { +// component->SetFootprint( elem.libname + wxT( ":" ) + elem.name ); + } + else + { + // component->SetFootprint( elem.name ); + } + + 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 d287fcfe4c..b9ce5790fb 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.h +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.h @@ -132,6 +132,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: SCH_SHEET* m_rootSheet; // The root sheet of the schematic being loaded..