altium: Improve handling of footprint references

Don't assume the implementation list index is always correct by order.
This commit is contained in:
Thomas Pointhuber 2021-07-07 21:01:49 +02:00
parent 4207165c26
commit 5e9a8e3488
4 changed files with 38 additions and 27 deletions

View File

@ -720,10 +720,7 @@ ASCH_IMPLEMENTATION::ASCH_IMPLEMENTATION( const std::map<wxString, wxString>& aP
{
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 );
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", "" );

View File

@ -713,8 +713,7 @@ struct ASCH_DESIGNATOR
struct ASCH_IMPLEMENTATION
{
// IMPLEMENTATION_LIST -> ownerindex must be read and used for these IMPLEMENTATIONs
// int ownerindex;
int ownerindex;
wxString name;
wxString type;

View File

@ -342,9 +342,6 @@ void SCH_ALTIUM_PLUGIN::ParseFileHeader( const CFB::CompoundFileReader& aReader
m_currentTitleBlock = std::make_unique<TITLE_BLOCK>();
// 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++ )
{
@ -454,13 +451,10 @@ 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;
}
ParseImplementationList( index, properties );
break;
case ALTIUM_SCH_RECORD::IMPLEMENTATION:
ParseImplementation( properties, implementationlistindex );
ParseImplementation( properties );
break;
case ALTIUM_SCH_RECORD::RECORD_46:
break;
@ -2350,29 +2344,48 @@ void SCH_ALTIUM_PLUGIN::ParseParameter( const std::map<wxString, wxString>& aPro
}
}
void SCH_ALTIUM_PLUGIN::ParseImplementation( const std::map<wxString, wxString>& aProperties,
int ownerindex )
void SCH_ALTIUM_PLUGIN::ParseImplementationList( int aIndex, const std::map<wxString, wxString>& aProperties )
{
ASCH_IMPLEMENTATION_LIST elem( aProperties );
m_altiumImplementationList.emplace( aIndex, elem.ownerindex );
}
void SCH_ALTIUM_PLUGIN::ParseImplementation( const std::map<wxString, wxString>& aProperties )
{
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's owner (%d) not found." ),
ownerindex ),
const auto& implementationOwnerindexIt = m_altiumImplementationList.find( elem.ownerindex );
if( implementationOwnerindexIt == m_altiumImplementationList.end() ) {
m_reporter->Report( wxString::Format( _( "Implementation list's owner (%d) not found." ),
elem.ownerindex ),
RPT_SEVERITY_ERROR );
return;
}
const auto& libSymbolIt = m_libSymbols.find( implementationOwnerindexIt->second );
if( libSymbolIt == m_libSymbols.end() )
{
m_reporter->Report( wxString::Format( _( "Footprint's owner (%d) not found." ),
implementationOwnerindexIt->second ),
RPT_SEVERITY_ERROR );
return;
}
LIB_ID fpLibId = AltiumToKiCadLibID( elem.libname, elem.name );
wxArrayString fpFilters;
fpFilters.Add( fpLibId.Format() );
libSymbolIt->second->SetFPFilters( fpFilters ); // TODO: not ideal as we overwrite it
SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
if( elem.libname != "" )
symbol->SetFootprint( elem.libname + wxT( ":" ) + elem.name );
else
symbol->SetFootprint( elem.name );
symbol->SetFootprint( fpLibId.Format() );
}
}

View File

@ -140,7 +140,8 @@ private:
void ParseDesignator( const std::map<wxString, wxString>& aProperties );
void ParseBusEntry( const std::map<wxString, wxString>& aProperties );
void ParseParameter( const std::map<wxString, wxString>& aProperties );
void ParseImplementation( const std::map<wxString, wxString>& aProperties, int ownerindex );
void ParseImplementationList( int aIndex, const std::map<wxString, wxString>& aProperties );
void ParseImplementation( const std::map<wxString, wxString>& aProperties );
private:
REPORTER* m_reporter; // current reporter for warnings/errors
@ -166,6 +167,7 @@ private:
std::vector<ASCH_STORAGE_FILE> m_altiumStorage;
std::map<int, ASCH_SYMBOL> m_altiumComponents;
std::map<int, int> m_altiumImplementationList;
std::vector<ASCH_PORT> m_altiumPortsCurrentSheet; // we require all connections first
};