KiCad PCB EDA Suite
LIB_MANAGER::LIB_BUFFER Class Reference

Class to store a working copy of a library

More...

Public Member Functions

 LIB_BUFFER (const wxString &aLibrary)
 
bool IsModified () const
 
int GetHash () const
 
wxArrayString GetAliasNames () const
 

Returns all alias names for stored parts

More...
 
LIB_PARTGetPart (const wxString &aAlias) const
 

Returns the working copy of a LIB_PART object with specified alias

More...
 
bool CreateBuffer (LIB_PART *aCopy, SCH_SCREEN *aScreen)
 

Creates a new buffer to store a part. LIB_BUFFER takes ownership of aCopy.

More...
 
bool UpdateBuffer (PART_BUFFER::PTR aPartBuf, LIB_PART *aCopy)
 

Updates the stored part. LIB_BUFFER takes ownership of aCopy.

More...
 
bool DeleteBuffer (PART_BUFFER::PTR aPartBuf)
 
void ClearDeletedBuffer ()
 
bool SaveBuffer (PART_BUFFER::PTR aPartBuf, SYMBOL_LIB_TABLE *aLibTable)
 

Saves stored modifications to Symbol Lib Table.

More...
 
bool SaveBuffer (PART_BUFFER::PTR aPartBuf, SCH_PLUGIN *aPlugin, bool aBuffer)
 

Saves stored modificatiosn using a plugin.

More...
 
PART_BUFFER::PTR GetBuffer (const wxString &aAlias) const
 

Returns a part buffer with LIB_PART holding a particular alias

More...
 
const std::deque< PART_BUFFER::PTR > & GetBuffers () const
 

Returns all buffered parts

More...
 
const std::map< wxString, PART_BUFFER::WEAK_PTR > & GetAliases () const
 

Returns all aliases of buffered parts

More...
 

Private Member Functions

bool addAliases (PART_BUFFER::PTR aPartBuf)
 

Creates alias entries for a particular part buffer

More...
 
bool removeAliases (PART_BUFFER::PTR aPartBuf)
 

Removes alias entries for a particular part buffer

More...
 

Private Attributes

std::map< wxString, PART_BUFFER::WEAK_PTRm_aliases
 
std::deque< PART_BUFFER::PTRm_parts
 
std::deque< PART_BUFFER::PTRm_deleted
 

Buffer to keep deleted parts until the library is saved

More...
 
const wxString m_libName
 Buffered library name. More...
 
int m_hash
 

Friends

class PART_BUFFER
 

Detailed Description

Class to store a working copy of a library

Definition at line 334 of file lib_manager.h.

Constructor & Destructor Documentation

LIB_MANAGER::LIB_BUFFER::LIB_BUFFER ( const wxString &  aLibrary)
inline

Definition at line 337 of file lib_manager.h.

338  : m_libName( aLibrary ), m_hash( 1 )
339  {
340  }
const wxString m_libName
Buffered library name.
Definition: lib_manager.h:425

Member Function Documentation

bool LIB_MANAGER::LIB_BUFFER::addAliases ( PART_BUFFER::PTR  aPartBuf)
private

Creates alias entries for a particular part buffer

Definition at line 829 of file lib_manager.cpp.

References LIB_PART::GetAlias(), LIB_PART::GetAliasCount(), LIB_ALIAS::GetName(), and i.

830 {
831  LIB_PART* part = aPartBuf->GetPart();
832  wxCHECK( part, false );
833  bool ret = true; // Assume everything is ok
834 
835  for( unsigned int i = 0; i < part->GetAliasCount(); ++i )
836  {
837  bool newAlias;
838  std::tie( std::ignore, newAlias ) = m_aliases.emplace( part->GetAlias( i )->GetName(), aPartBuf );
839 
840  if( !newAlias ) // Overwrite check
841  {
842  wxFAIL;
843  ret = false;
844  }
845  }
846 
847  return ret;
848 }
LIB_ALIAS * GetAlias(size_t aIndex)
size_t GetAliasCount() const
Define a library symbol object.
const wxString & GetName() const override
std::map< wxString, PART_BUFFER::WEAK_PTR > m_aliases
Definition: lib_manager.h:418
size_t i
Definition: json11.cpp:597
void LIB_MANAGER::LIB_BUFFER::ClearDeletedBuffer ( )
inline

Definition at line 379 of file lib_manager.h.

Referenced by LIB_MANAGER::FlushLibrary(), and LIB_MANAGER::SaveLibrary().

380  {
381  m_deleted.clear();
382  }
std::deque< PART_BUFFER::PTR > m_deleted
Buffer to keep deleted parts until the library is saved
Definition: lib_manager.h:422
bool LIB_MANAGER::LIB_BUFFER::CreateBuffer ( LIB_PART aCopy,
SCH_SCREEN aScreen 
)

Creates a new buffer to store a part. LIB_BUFFER takes ownership of aCopy.

Definition at line 752 of file lib_manager.cpp.

References LIB_PART::GetLib(), LIB_PART::GetName(), and LIB_ID::SetLibNickname().

Referenced by LIB_MANAGER::GetBufferedPart(), LIB_MANAGER::getLibraryBuffer(), and LIB_MANAGER::UpdatePart().

753 {
754  wxASSERT( m_aliases.count( aCopy->GetName() ) == 0 ); // only for new parts
755  wxASSERT( aCopy->GetLib() == nullptr );
756  std::unique_ptr<SCH_SCREEN> screen( aScreen );
757  auto partBuf = std::make_shared<PART_BUFFER>( aCopy, std::move( screen ) );
758  m_parts.push_back( partBuf );
759  addAliases( partBuf );
760 
761  // Set the parent library name,
762  // otherwise it is empty as no library has been given as the owner during object construction
763  LIB_ID& libId = (LIB_ID&) aCopy->GetLibId();
764  libId.SetLibNickname( m_libName );
765  ++m_hash;
766 
767  return true;
768 }
PART_LIB * GetLib()
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
bool addAliases(PART_BUFFER::PTR aPartBuf)
Creates alias entries for a particular part buffer
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:193
std::map< wxString, PART_BUFFER::WEAK_PTR > m_aliases
Definition: lib_manager.h:418
const wxString & GetName() const
const wxString m_libName
Buffered library name.
Definition: lib_manager.h:425
std::deque< PART_BUFFER::PTR > m_parts
Definition: lib_manager.h:419
bool LIB_MANAGER::LIB_BUFFER::DeleteBuffer ( PART_BUFFER::PTR  aPartBuf)

Definition at line 784 of file lib_manager.cpp.

Referenced by LIB_MANAGER::RemovePart(), and LIB_MANAGER::UpdatePartAfterRename().

785 {
786  auto partBufIt = std::find( m_parts.begin(), m_parts.end(), aPartBuf );
787  wxCHECK( partBufIt != m_parts.end(), false );
788  m_deleted.emplace_back( *partBufIt );
789  m_parts.erase( partBufIt );
790  ++m_hash;
791 
792  return removeAliases( aPartBuf );
793 }
std::deque< PART_BUFFER::PTR > m_deleted
Buffer to keep deleted parts until the library is saved
Definition: lib_manager.h:422
bool removeAliases(PART_BUFFER::PTR aPartBuf)
Removes alias entries for a particular part buffer
std::deque< PART_BUFFER::PTR > m_parts
Definition: lib_manager.h:419
const std::map<wxString, PART_BUFFER::WEAK_PTR>& LIB_MANAGER::LIB_BUFFER::GetAliases ( ) const
inline

Returns all aliases of buffered parts

Definition at line 406 of file lib_manager.h.

407  {
408  return m_aliases;
409  }
std::map< wxString, PART_BUFFER::WEAK_PTR > m_aliases
Definition: lib_manager.h:418
wxArrayString LIB_MANAGER::LIB_BUFFER::GetAliasNames ( ) const

Returns all alias names for stored parts

Definition at line 741 of file lib_manager.cpp.

742 {
743  wxArrayString ret;
744 
745  for( const auto& alias : m_aliases )
746  ret.push_back( alias.first );
747 
748  return ret;
749 }
std::map< wxString, PART_BUFFER::WEAK_PTR > m_aliases
Definition: lib_manager.h:418
PART_BUFFER::PTR LIB_MANAGER::LIB_BUFFER::GetBuffer ( const wxString &  aAlias) const
inline

Returns a part buffer with LIB_PART holding a particular alias

Definition at line 393 of file lib_manager.h.

Referenced by LIB_MANAGER::GetScreen(), LIB_MANAGER::IsPartModified(), LIB_MANAGER::RemovePart(), LIB_MANAGER::UpdatePart(), and LIB_MANAGER::UpdatePartAfterRename().

394  {
395  auto it = m_aliases.find( aAlias );
396  return it != m_aliases.end() ? it->second.lock() : PART_BUFFER::PTR( nullptr );
397  }
std::map< wxString, PART_BUFFER::WEAK_PTR > m_aliases
Definition: lib_manager.h:418
std::shared_ptr< PART_BUFFER > PTR
Definition: lib_manager.h:319
const std::deque<PART_BUFFER::PTR>& LIB_MANAGER::LIB_BUFFER::GetBuffers ( ) const
inline

Returns all buffered parts

Definition at line 400 of file lib_manager.h.

Referenced by LIB_MANAGER::FlushLibrary(), and LIB_MANAGER::SaveLibrary().

401  {
402  return m_parts;
403  }
std::deque< PART_BUFFER::PTR > m_parts
Definition: lib_manager.h:419
int LIB_MANAGER::LIB_BUFFER::GetHash ( ) const
inline

Definition at line 356 of file lib_manager.h.

References LIB_MANAGER::GetAliasNames().

357  {
358  return m_hash;
359  }
LIB_PART* LIB_MANAGER::LIB_BUFFER::GetPart ( const wxString &  aAlias) const
inline

Returns the working copy of a LIB_PART object with specified alias

Definition at line 365 of file lib_manager.h.

Referenced by LIB_MANAGER::GetBufferedPart().

366  {
367  auto buf = GetBuffer( aAlias );
368  return buf ? buf->GetPart() : nullptr;
369  }
PART_BUFFER::PTR GetBuffer(const wxString &aAlias) const
Returns a part buffer with LIB_PART holding a particular alias
Definition: lib_manager.h:393
bool LIB_MANAGER::LIB_BUFFER::IsModified ( ) const
inline

Definition at line 342 of file lib_manager.h.

343  {
344  if( !m_deleted.empty() )
345  return true;
346 
347  for( const auto& partBuf : m_parts )
348  {
349  if( partBuf->IsModified() )
350  return true;
351  }
352 
353  return false;
354  }
std::deque< PART_BUFFER::PTR > m_deleted
Buffer to keep deleted parts until the library is saved
Definition: lib_manager.h:422
std::deque< PART_BUFFER::PTR > m_parts
Definition: lib_manager.h:419
bool LIB_MANAGER::LIB_BUFFER::removeAliases ( PART_BUFFER::PTR  aPartBuf)
private

Removes alias entries for a particular part buffer

Definition at line 851 of file lib_manager.cpp.

References LIB_PART::GetAlias(), LIB_PART::GetAliasCount(), LIB_ALIAS::GetName(), and i.

852 {
853  LIB_PART* part = aPartBuf->GetPart();
854  wxCHECK( part, false );
855  bool ret = true; // Assume everything is ok
856 
857  for( unsigned int i = 0; i < part->GetAliasCount(); ++i )
858  {
859  auto aliasIt = m_aliases.find( part->GetAlias( i )->GetName() );
860 
861  if( aliasIt == m_aliases.end() )
862  {
863  wxFAIL;
864  ret = false;
865  continue;
866  }
867 
868  // Be sure the alias belongs to the assigned owner
869  wxASSERT( aliasIt->second.lock() == aPartBuf );
870 
871  m_aliases.erase( aliasIt );
872  }
873 
874  return ret;
875 }
LIB_ALIAS * GetAlias(size_t aIndex)
size_t GetAliasCount() const
Define a library symbol object.
const wxString & GetName() const override
std::map< wxString, PART_BUFFER::WEAK_PTR > m_aliases
Definition: lib_manager.h:418
size_t i
Definition: json11.cpp:597
bool LIB_MANAGER::LIB_BUFFER::SaveBuffer ( PART_BUFFER::PTR  aPartBuf,
SYMBOL_LIB_TABLE aLibTable 
)

Saves stored modifications to Symbol Lib Table.

It may result in saving the symbol

to disk as well, depending on the row properties.

Definition at line 796 of file lib_manager.cpp.

References SYMBOL_LIB_TABLE::SAVE_OK, and SYMBOL_LIB_TABLE::SaveSymbol().

Referenced by LIB_MANAGER::FlushLibrary(), and LIB_MANAGER::SaveLibrary().

798 {
799  wxCHECK( aPartBuf, false );
800  LIB_PART* part = aPartBuf->GetPart();
801  wxCHECK( part, false );
802  wxCHECK( aLibTable->SaveSymbol( m_libName, new LIB_PART( *part ) ) == SYMBOL_LIB_TABLE::SAVE_OK, false );
803 
804  aPartBuf->SetOriginal( new LIB_PART( *part ) );
805  ++m_hash;
806  return true;
807 }
SAVE_T SaveSymbol(const wxString &aNickname, const LIB_PART *aSymbol, bool aOverwrite=true)
Write aSymbol to an existing library given by aNickname.
Define a library symbol object.
const wxString m_libName
Buffered library name.
Definition: lib_manager.h:425
bool LIB_MANAGER::LIB_BUFFER::SaveBuffer ( PART_BUFFER::PTR  aPartBuf,
SCH_PLUGIN aPlugin,
bool  aBuffer 
)

Saves stored modificatiosn using a plugin.

aBuffer decides whether the changes

should be cached or stored directly to the disk (for SCH_LEGACY_PLUGIN).

Definition at line 810 of file lib_manager.cpp.

References SCH_LEGACY_PLUGIN::PropBuffering, and SCH_PLUGIN::SaveSymbol().

812 {
813  wxCHECK( aPartBuf, false );
814  LIB_PART* part = aPartBuf->GetPart();
815  wxCHECK( part, false );
816 
817  // set properties to prevent save file on every symbol save
818  PROPERTIES properties;
819  properties.emplace( SCH_LEGACY_PLUGIN::PropBuffering, "" );
820 
821  // TODO there is no way to check if symbol has been successfully saved
822  aPlugin->SaveSymbol( m_libName, new LIB_PART( *part ), aBuffer ? &properties : nullptr );
823  aPartBuf->SetOriginal( new LIB_PART( *part ) );
824  ++m_hash;
825  return true;
826 }
Class PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
Define a library symbol object.
static const char * PropBuffering
const char* PropBuffering
const wxString m_libName
Buffered library name.
Definition: lib_manager.h:425
virtual void SaveSymbol(const wxString &aLibraryPath, const LIB_PART *aSymbol, const PROPERTIES *aProperties=NULL)
Write aSymbol to an existing library located at aLibraryPath.
Definition: sch_plugin.cpp:102
bool LIB_MANAGER::LIB_BUFFER::UpdateBuffer ( PART_BUFFER::PTR  aPartBuf,
LIB_PART aCopy 
)

Updates the stored part. LIB_BUFFER takes ownership of aCopy.

Definition at line 771 of file lib_manager.cpp.

Referenced by LIB_MANAGER::UpdatePart().

772 {
773  bool ret = true;
774 
775  ret &= removeAliases( aPartBuf );
776  aPartBuf->SetPart( aCopy );
777  ret &= addAliases( aPartBuf );
778  ++m_hash;
779 
780  return ret;
781 }
bool addAliases(PART_BUFFER::PTR aPartBuf)
Creates alias entries for a particular part buffer
bool removeAliases(PART_BUFFER::PTR aPartBuf)
Removes alias entries for a particular part buffer

Friends And Related Function Documentation

friend class PART_BUFFER
friend

Definition at line 429 of file lib_manager.h.

Member Data Documentation

std::map<wxString, PART_BUFFER::WEAK_PTR> LIB_MANAGER::LIB_BUFFER::m_aliases
private

Definition at line 418 of file lib_manager.h.

std::deque<PART_BUFFER::PTR> LIB_MANAGER::LIB_BUFFER::m_deleted
private

Buffer to keep deleted parts until the library is saved

Definition at line 422 of file lib_manager.h.

int LIB_MANAGER::LIB_BUFFER::m_hash
private

Definition at line 427 of file lib_manager.h.

const wxString LIB_MANAGER::LIB_BUFFER::m_libName
private

Buffered library name.

Definition at line 425 of file lib_manager.h.

std::deque<PART_BUFFER::PTR> LIB_MANAGER::LIB_BUFFER::m_parts
private

Definition at line 419 of file lib_manager.h.


The documentation for this class was generated from the following files: