From c96b7bb4725cf842ab46026b3b05ba7659438bc2 Mon Sep 17 00:00:00 2001 From: Alex Shvartzkop Date: Sat, 9 Sep 2023 20:27:51 +0300 Subject: [PATCH] Altium import: set units for LIB_TEXTBOX. Still doesn't work on symbols in schematic for some reason. --- .../sch_plugins/altium/sch_altium_plugin.cpp | 47 ++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp index 021f30392d..ddea792ede 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp @@ -1302,7 +1302,7 @@ void SCH_ALTIUM_PLUGIN::ParseTextFrame( const std::map& aPro { ASCH_TEXT_FRAME elem( aProperties ); - if( aSymbol.empty() ) + if( aSymbol.empty() && elem.ownerpartid == ALTIUM_COMPONENT_NONE ) AddTextBox( &elem ); else AddLibTextBox( &elem, aSymbol, aFontSizes ); @@ -1383,17 +1383,45 @@ void SCH_ALTIUM_PLUGIN::AddTextBox(const ASCH_TEXT_FRAME *aElem ) void SCH_ALTIUM_PLUGIN::AddLibTextBox(const ASCH_TEXT_FRAME *aElem, std::vector& aSymbol, std::vector& aFontSizes ) { - if( aElem->ownerpartdisplaymode >= static_cast( aSymbol.size() ) ) - return; + LIB_SYMBOL* symbol = static_cast( aSymbol.size() ) <= aElem->ownerpartdisplaymode + ? nullptr + : aSymbol[aElem->ownerpartdisplaymode]; + SCH_SYMBOL* schsym = nullptr; + + if( !symbol ) + { + const auto& libSymbolIt = m_libSymbols.find( aElem->ownerindex ); + + if( libSymbolIt == m_libSymbols.end() ) + { + // TODO: e.g. can depend on Template (RECORD=39 + m_reporter->Report( + wxString::Format( wxT( "Label's owner (%d) not found." ), aElem->ownerindex ), + RPT_SEVERITY_DEBUG ); + return; + } + + symbol = libSymbolIt->second; + schsym = m_symbols.at( libSymbolIt->first ); + } - LIB_SYMBOL* symbol = aSymbol[aElem->ownerpartdisplaymode]; LIB_TEXTBOX* textBox = new LIB_TEXTBOX( symbol ); - VECTOR2I sheetTopRight = GetLibEditPosition( aElem->TopRight ); - VECTOR2I sheetBottomLeft = GetLibEditPosition( aElem->BottomLeft ); + textBox->SetUnit( std::max( 0, aElem->ownerpartid ) ); - textBox->SetStart( sheetTopRight ); - textBox->SetEnd( sheetBottomLeft ); + symbol->AddDrawItem( textBox, false ); + + /// Handle text frames that are in a library symbol, not on schematic + if( !schsym ) + { + textBox->SetStart( GetLibEditPosition( aElem->TopRight ) ); + textBox->SetEnd( GetLibEditPosition( aElem->BottomLeft ) ); + } + else + { + textBox->SetStart( GetRelativePosition( aElem->TopRight + m_sheetOffset, schsym ) ); + textBox->SetEnd( GetRelativePosition( aElem->BottomLeft + m_sheetOffset, schsym ) ); + } textBox->SetText( aElem->Text ); @@ -1429,9 +1457,6 @@ void SCH_ALTIUM_PLUGIN::AddLibTextBox(const ASCH_TEXT_FRAME *aElem, std::vector< int size = aFontSizes[aElem->FontID - 1]; textBox->SetTextSize( { size, size } ); } - - symbol->AddDrawItem( textBox, false ); - }