diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index fdf480fc7c..6632d66cab 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -156,6 +156,49 @@ LIB_PART::~LIB_PART() } +const LIB_PART& LIB_PART::operator=( const LIB_PART& aPart ) +{ + if( &aPart == this ) + return aPart; + + LIB_ITEM* newItem; + + m_library = aPart.m_library; + m_name = aPart.m_name; + m_FootprintList = wxArrayString( aPart.m_FootprintList ); + m_unitCount = aPart.m_unitCount; + m_unitsLocked = aPart.m_unitsLocked; + m_pinNameOffset = aPart.m_pinNameOffset; + m_showPinNumbers = aPart.m_showPinNumbers; + m_showPinNames = aPart.m_showPinNames; + m_dateLastEdition = aPart.m_dateLastEdition; + m_options = aPart.m_options; + m_libId = aPart.m_libId; + m_description = aPart.m_description; + m_keyWords = aPart.m_keyWords; + m_docFileName = aPart.m_docFileName; + + m_drawings.clear(); + + for( const LIB_ITEM& oldItem : aPart.m_drawings ) + { + if( ( oldItem.GetFlags() & ( IS_NEW | STRUCT_DELETED ) ) != 0 ) + continue; + + newItem = (LIB_ITEM*) oldItem.Clone(); + newItem->SetParent( this ); + m_drawings.push_back( newItem ); + } + + PART_SPTR parent = aPart.m_parent.lock(); + + if( parent ) + SetParent( parent.get() ); + + return *this; +} + + int LIB_PART::Compare( const LIB_PART& aRhs ) const { if( m_me == aRhs.m_me ) diff --git a/eeschema/class_libentry.h b/eeschema/class_libentry.h index a9a949ac1f..08e76d6cb3 100644 --- a/eeschema/class_libentry.h +++ b/eeschema/class_libentry.h @@ -572,6 +572,8 @@ public: bool operator==( const LIB_PART* aPart ) const { return this == aPart; } bool operator==( const LIB_PART& aPart ) const { return Compare( aPart ) == 0; } + const LIB_PART& operator=( const LIB_PART& aPart ); + /** * Return a flattened symbol inheritance to the caller. * diff --git a/eeschema/libedit/lib_manager.cpp b/eeschema/libedit/lib_manager.cpp index 5f33df371b..d6e24322e7 100644 --- a/eeschema/libedit/lib_manager.cpp +++ b/eeschema/libedit/lib_manager.cpp @@ -384,36 +384,22 @@ bool LIB_MANAGER::UpdatePart( LIB_PART* aPart, const wxString& aLibrary ) wxCHECK( aPart, false ); LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary ); auto partBuf = libBuf.GetBuffer( aPart->GetName() ); - LIB_PART* partCopy = new LIB_PART( *aPart, nullptr ); - partCopy->SetLibId( LIB_ID( aLibrary, aPart->GetLibId().GetLibItemName() ) ); - - if( partBuf ) + if( partBuf ) // Existing symbol. { - if( partBuf->GetPart()->IsRoot() && libBuf.HasDerivedSymbols( aPart->GetName() ) ) - { - // Reparent derived symbols. - for( auto entry : libBuf.GetBuffers() ) - { - if( entry->GetPart()->IsRoot() ) - continue; + LIB_PART* bufferedPart = const_cast< LIB_PART* >( partBuf->GetPart() ); - if( entry->GetPart()->GetParent().lock() == partBuf->GetPart()->SharedPtr() ) - { - if( !libBuf.DeleteBuffer( entry ) ) - return false; + wxCHECK( bufferedPart, false ); - LIB_PART* reparentedPart = new LIB_PART( *entry->GetPart() ); - reparentedPart->SetParent( partCopy ); - libBuf.CreateBuffer( reparentedPart, new SCH_SCREEN( &m_frame.Kiway() ) ); - } - } - } - - libBuf.UpdateBuffer( partBuf, partCopy ); + *bufferedPart = *aPart; + partBuf->GetScreen()->SetModify(); } - else // New entry + else // New symbol { + LIB_PART* partCopy = new LIB_PART( *aPart, nullptr ); + + partCopy->SetLibId( LIB_ID( aLibrary, aPart->GetLibId().GetLibItemName() ) ); + SCH_SCREEN* screen = new SCH_SCREEN( &m_frame.Kiway() ); libBuf.CreateBuffer( partCopy, screen ); screen->SetModify(); @@ -431,11 +417,7 @@ bool LIB_MANAGER::UpdatePartAfterRename( LIB_PART* aPart, const wxString& aOldNa wxCHECK( partBuf, false ); - LIB_PART* bufferedPart = const_cast< LIB_PART* >( partBuf->GetPart() ); - - wxCHECK( bufferedPart, false ); - - bufferedPart->SetName( aPart->GetName() ); + libBuf.UpdateBuffer( partBuf, aPart ); SetCurrentPart( aPart->GetName() ); m_frame.SyncLibraries( false ); @@ -846,12 +828,16 @@ bool LIB_MANAGER::LIB_BUFFER::CreateBuffer( LIB_PART* aCopy, SCH_SCREEN* aScreen bool LIB_MANAGER::LIB_BUFFER::UpdateBuffer( LIB_MANAGER::PART_BUFFER::PTR aPartBuf, LIB_PART* aCopy ) { - bool ret = true; + wxCHECK( aCopy && aPartBuf, false ); - aPartBuf->SetPart( aCopy ); + LIB_PART* bufferedPart = aPartBuf->GetPart(); + + wxCHECK( bufferedPart, false ); + + *bufferedPart = *aCopy; ++m_hash; - return ret; + return true; } diff --git a/eeschema/libedit/lib_manager.h b/eeschema/libedit/lib_manager.h index 2f6a95bdbd..94b78ca9b1 100644 --- a/eeschema/libedit/lib_manager.h +++ b/eeschema/libedit/lib_manager.h @@ -379,7 +379,7 @@ private: ///> Creates a new buffer to store a part. LIB_BUFFER takes ownership of aCopy. bool CreateBuffer( LIB_PART* aCopy, SCH_SCREEN* aScreen ); - ///> Updates the stored part. LIB_BUFFER takes ownership of aCopy. + ///> Updates the buffered part with the contents of \a aCopy. bool UpdateBuffer( PART_BUFFER::PTR aPartBuf, LIB_PART* aCopy ); bool DeleteBuffer( PART_BUFFER::PTR aPartBuf ); diff --git a/include/multivector.h b/include/multivector.h index c7b39fcf1b..9012951bd2 100644 --- a/include/multivector.h +++ b/include/multivector.h @@ -204,6 +204,19 @@ public: return CONST_ITERATOR( this, operator[]( bucket ).end(), bucket, aType ); } + void clear( int aType = UNDEFINED_TYPE ) + { + if( aType != UNDEFINED_TYPE ) + { + operator[]( aType ).clear(); + } + else + { + for( int i = 0; i < TYPES_COUNT; ++i) + m_data[ i ].clear(); + } + } + size_t size( int aType = UNDEFINED_TYPE ) const { if( aType != UNDEFINED_TYPE )