From 6860320b1b382f0e52c03f74235e622f30a93e7e Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 8 Nov 2018 21:26:01 +0000 Subject: [PATCH] Init LibEdit with unit & conversion when opening from schematic. --- eeschema/libedit/lib_edit_frame.h | 9 +++++++-- eeschema/libedit/libedit.cpp | 22 ++++++++-------------- eeschema/sch_edit_frame.cpp | 2 +- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/eeschema/libedit/lib_edit_frame.h b/eeschema/libedit/lib_edit_frame.h index c428de8e15..37dbb25e77 100644 --- a/eeschema/libedit/lib_edit_frame.h +++ b/eeschema/libedit/lib_edit_frame.h @@ -516,9 +516,12 @@ private: * @param aLibEntry A pointer to the LIB_ALIAS object to an already loaded. * @param aLibrary the path to the library file that \a aLibEntry was loaded from. This is * for error messaging purposes only. + * @param aUnit the initial unit to show. + * @param aConvert the initial DeMorgan variant to show. * @return True if a copy of \a aLibEntry was successfully copied. */ - bool LoadOneLibraryPartAux( LIB_ALIAS* aLibEntry, const wxString& aLibrary ); + bool LoadOneLibraryPartAux( LIB_ALIAS* aLibEntry, const wxString& aLibrary, + int aUnit, int aConvert ); /** * Display the documentation of the selected component. @@ -617,9 +620,11 @@ public: * Selects the currently active library and loads the symbol from \a aLibId. * * @param aLibId is the #LIB_ID of the symbol to select. + * @param aUnit the unit to show + * @param aConvert the DeMorgan variant to show * @return true if the symbol defined by \a aLibId was loaded. */ - bool LoadComponentAndSelectLib( const LIB_ID& aLibId ); + bool LoadComponentAndSelectLib( const LIB_ID& aLibId, int aUnit, int aConvert ); /* Block commands: */ diff --git a/eeschema/libedit/libedit.cpp b/eeschema/libedit/libedit.cpp index 10efc4e381..f9b4e6ae63 100644 --- a/eeschema/libedit/libedit.cpp +++ b/eeschema/libedit/libedit.cpp @@ -100,7 +100,7 @@ bool LIB_EDIT_FRAME::saveCurrentPart() } -bool LIB_EDIT_FRAME::LoadComponentAndSelectLib( const LIB_ID& aLibId ) +bool LIB_EDIT_FRAME::LoadComponentAndSelectLib( const LIB_ID& aLibId, int aUnit, int aConvert ) { if( GetScreen()->IsModify() && GetCurPart() ) { @@ -112,7 +112,7 @@ bool LIB_EDIT_FRAME::LoadComponentAndSelectLib( const LIB_ID& aLibId ) } SelectActiveLibrary( aLibId.GetLibNickname() ); - return LoadComponentFromCurrentLib( aLibId.GetLibItemName() ); + return LoadComponentFromCurrentLib( aLibId.GetLibItemName(), aUnit, aConvert ); } @@ -135,15 +135,9 @@ bool LIB_EDIT_FRAME::LoadComponentFromCurrentLib( const wxString& aAliasName, in return false; } - if( !alias || !LoadOneLibraryPartAux( alias, GetCurLib() ) ) + if( !alias || !LoadOneLibraryPartAux( alias, GetCurLib(), aUnit, aConvert ) ) return false; - if( aUnit > 0 ) - m_unit = aUnit; - - if( aConvert > 0 ) - m_convert = aConvert; - // Enable synchronized pin edit mode for symbols with interchangeable units m_syncPinEdit = !GetCurPart()->UnitsLocked(); @@ -158,7 +152,8 @@ bool LIB_EDIT_FRAME::LoadComponentFromCurrentLib( const wxString& aAliasName, in } -bool LIB_EDIT_FRAME::LoadOneLibraryPartAux( LIB_ALIAS* aEntry, const wxString& aLibrary ) +bool LIB_EDIT_FRAME::LoadOneLibraryPartAux( LIB_ALIAS* aEntry, const wxString& aLibrary, + int aUnit, int aConvert ) { wxString msg, rootName; @@ -174,8 +169,8 @@ bool LIB_EDIT_FRAME::LoadOneLibraryPartAux( LIB_ALIAS* aEntry, const wxString& a LIB_PART* lib_part = m_libMgr->GetBufferedPart( aEntry->GetName(), aLibrary ); wxASSERT( lib_part ); - m_unit = 1; - m_convert = 1; + m_unit = aUnit > 0 ? aUnit : 1; + m_convert = aConvert > 0 ? aConvert : 1; auto s = m_libMgr->GetScreen( lib_part->GetName(), aLibrary ); SetScreen( s ); @@ -636,14 +631,13 @@ void LIB_EDIT_FRAME::loadPart( const wxString& aAlias, const wxString& aLibrary, m_lastDrawItem = nullptr; SetDrawItem( NULL ); - m_unit = ( aUnit <= part->GetUnitCount() ? aUnit : 1 ); // Optimize default edit options for this symbol // Usually if units are locked, graphic items are specific to each unit // and if units are interchangeable, graphic items are common to units m_drawSpecificUnit = part->UnitsLocked() ? true : false; - LoadOneLibraryPartAux( alias, aLibrary ); + LoadOneLibraryPartAux( alias, aLibrary, m_unit, 0 ); } diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index c93152ea3f..dd7304fa89 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -1236,7 +1236,7 @@ void SCH_EDIT_FRAME::OnOpenLibraryEditor( wxCommandEvent& event ) if( !entry ) // Should not occur return; - libeditFrame->LoadComponentAndSelectLib( id ); + libeditFrame->LoadComponentAndSelectLib( id, component->GetUnit(), component->GetConvert() ); } SchematicCleanUp();