diff --git a/eeschema/cmp_tree_model.cpp b/eeschema/cmp_tree_model.cpp index 99ba26c05c..b37b0c9579 100644 --- a/eeschema/cmp_tree_model.cpp +++ b/eeschema/cmp_tree_model.cpp @@ -132,8 +132,22 @@ CMP_TREE_NODE_LIB_ID::CMP_TREE_NODE_LIB_ID( CMP_TREE_NODE* aParent, LIB_ALIAS* a { wxASSERT( aParent && aAlias ); - Type = LIBID; - Parent = aParent; + Type = LIBID; + Parent = aParent; + Update( aAlias ); +} + + +CMP_TREE_NODE_UNIT& CMP_TREE_NODE_LIB_ID::AddUnit( int aUnit ) +{ + CMP_TREE_NODE_UNIT* unit = new CMP_TREE_NODE_UNIT( this, aUnit ); + Children.push_back( std::unique_ptr( unit ) ); + return *unit; +} + + +void CMP_TREE_NODE_LIB_ID::Update( LIB_ALIAS* aAlias ) +{ Name = aAlias->GetName(); Desc = aAlias->GetDescription(); @@ -165,24 +179,16 @@ CMP_TREE_NODE_LIB_ID::CMP_TREE_NODE_LIB_ID( CMP_TREE_NODE* aParent, LIB_ALIAS* a SearchText += footprint.Lower(); } + Children.clear(); + if( part && part->IsMulti() ) { for( int u = 1; u <= part->GetUnitCount(); ++u ) - { AddUnit( u ); - } } } -CMP_TREE_NODE_UNIT& CMP_TREE_NODE_LIB_ID::AddUnit( int aUnit ) -{ - CMP_TREE_NODE_UNIT* unit = new CMP_TREE_NODE_UNIT( this, aUnit ); - Children.push_back( std::unique_ptr( unit ) ); - return *unit; -} - - void CMP_TREE_NODE_LIB_ID::UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) { if( Score <= 0 ) diff --git a/eeschema/cmp_tree_model.h b/eeschema/cmp_tree_model.h index ab062ee4a0..e9e04cb7e5 100644 --- a/eeschema/cmp_tree_model.h +++ b/eeschema/cmp_tree_model.h @@ -202,6 +202,10 @@ public: */ CMP_TREE_NODE_LIB_ID( CMP_TREE_NODE* aParent, LIB_ALIAS* aAlias ); + /** + * Update the node using data from a LIB_ALIAS object. + */ + void Update( LIB_ALIAS* aAlias ); /** * Perform the actual search. diff --git a/eeschema/lib_manager.cpp b/eeschema/lib_manager.cpp index 53bd07d92e..4ea4fe10ca 100644 --- a/eeschema/lib_manager.cpp +++ b/eeschema/lib_manager.cpp @@ -318,7 +318,11 @@ LIB_PART* LIB_MANAGER::GetBufferedPart( const wxString& aAlias, const wxString& wxCHECK( alias, nullptr ); bufferedPart = new LIB_PART( *alias->GetPart(), nullptr ); libBuf.CreateBuffer( bufferedPart, new SCH_SCREEN( &m_frame.Kiway() ) ); - } catch( IO_ERROR& e ) {} + } + catch( IO_ERROR& e ) + { + bufferedPart = nullptr; + } } return bufferedPart; @@ -387,6 +391,7 @@ bool LIB_MANAGER::RevertPart( const wxString& aAlias, const wxString& aLibrary ) auto partBuf = it->second.GetBuffer( aAlias ); wxCHECK( partBuf, false ); partBuf->SetPart( new LIB_PART( *partBuf->GetOriginal() ) ); + m_frame.SyncLibraries( false ); return true; } @@ -587,6 +592,7 @@ LIB_MANAGER::LIB_BUFFER& LIB_MANAGER::getLibraryBuffer( const wxString& aLibrary if( it != m_libs.end() ) return it->second; + // The requested buffer does not exist yet, so create one auto ret = m_libs.emplace( aLibrary, LIB_BUFFER( aLibrary ) ); LIB_BUFFER& buf = ret.first->second; diff --git a/eeschema/lib_manager_adapter.cpp b/eeschema/lib_manager_adapter.cpp index 4507a48dc6..5cffedd073 100644 --- a/eeschema/lib_manager_adapter.cpp +++ b/eeschema/lib_manager_adapter.cpp @@ -113,13 +113,15 @@ int LIB_MANAGER_ADAPTER::GetLibrariesCount() const void LIB_MANAGER_ADAPTER::updateLibrary( CMP_TREE_NODE_LIB& aLibNode ) { - if( m_libHashes.count( aLibNode.Name ) == 0 ) + auto hashIt = m_libHashes.find( aLibNode.Name ); + + if( hashIt == m_libHashes.end() ) { // add a new library for( auto alias : m_libMgr->GetAliases( aLibNode.Name ) ) aLibNode.AddAlias( alias ); } - else + else if( hashIt->second != m_libMgr->GetLibraryHash( aLibNode.Name ) ) { // update an existing libary std::list aliases = m_libMgr->GetAliases( aLibNode.Name ); @@ -135,7 +137,8 @@ void LIB_MANAGER_ADAPTER::updateLibrary( CMP_TREE_NODE_LIB& aLibNode ) if( aliasIt != aliases.end() ) { // alias exists both in the component tree and the library manager, - // no need to update + // update only the node data + static_cast( nodeIt->get() )->Update( *aliasIt ); aliases.erase( aliasIt ); ++nodeIt; } @@ -194,7 +197,7 @@ bool LIB_MANAGER_ADAPTER::GetAttr( wxDataViewItem const& aItem, unsigned int aCo // mark modified libs with bold font aAttr.SetBold( m_libMgr->IsLibraryModified( node->Name ) ); - // mark current library with inverted colors + // mark the current library with inverted colors if( node->Name == m_libMgr->GetCurrentLib() ) aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) ); @@ -207,7 +210,7 @@ bool LIB_MANAGER_ADAPTER::GetAttr( wxDataViewItem const& aItem, unsigned int aCo // mark aliases with italic font aAttr.SetItalic( !node->IsRoot ); - // mark current library with inverted colors + // mark the current part with inverted colors if( node->LibId == m_libMgr->GetCurrentLibId() ) aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );