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_BUFFER()

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

◆ addAliases()

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

Creates alias entries for a particular part buffer

Definition at line 853 of file lib_manager.cpp.

854 {
855  LIB_PART* part = aPartBuf->GetPart();
856  wxCHECK( part, false );
857  bool ret = true; // Assume everything is ok
858 
859  for( unsigned int i = 0; i < part->GetAliasCount(); ++i )
860  {
861  bool newAlias;
862  std::tie( std::ignore, newAlias ) = m_aliases.emplace( part->GetAlias( i )->GetName(), aPartBuf );
863 
864  if( !newAlias ) // Overwrite check
865  {
866  wxFAIL;
867  ret = false;
868  }
869  }
870 
871  return ret;
872 }
LIB_ALIAS * GetAlias(size_t aIndex)
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
size_t GetAliasCount() const

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

◆ ClearDeletedBuffer()

void LIB_MANAGER::LIB_BUFFER::ClearDeletedBuffer ( )
inline

Definition at line 379 of file lib_manager.h.

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

References m_deleted.

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

◆ CreateBuffer()

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 776 of file lib_manager.cpp.

777 {
778  wxASSERT( m_aliases.count( aCopy->GetName() ) == 0 ); // only for new parts
779  wxASSERT( aCopy->GetLib() == nullptr );
780  std::unique_ptr<SCH_SCREEN> screen( aScreen );
781  auto partBuf = std::make_shared<PART_BUFFER>( aCopy, std::move( screen ) );
782  m_parts.push_back( partBuf );
783  addAliases( partBuf );
784 
785  // Set the parent library name,
786  // otherwise it is empty as no library has been given as the owner during object construction
787  LIB_ID& libId = (LIB_ID&) aCopy->GetLibId();
788  libId.SetLibNickname( m_libName );
789  ++m_hash;
790 
791  return true;
792 }
PART_LIB * GetLib()
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
const LIB_ID & GetLibId() const
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
const wxString & GetName() const
std::map< wxString, PART_BUFFER::WEAK_PTR > m_aliases
Definition: lib_manager.h:418
const wxString m_libName
Buffered library name.
Definition: lib_manager.h:425
std::deque< PART_BUFFER::PTR > m_parts
Definition: lib_manager.h:419

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

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

◆ DeleteBuffer()

bool LIB_MANAGER::LIB_BUFFER::DeleteBuffer ( PART_BUFFER::PTR  aPartBuf)

Definition at line 808 of file lib_manager.cpp.

809 {
810  auto partBufIt = std::find( m_parts.begin(), m_parts.end(), aPartBuf );
811  wxCHECK( partBufIt != m_parts.end(), false );
812  m_deleted.emplace_back( *partBufIt );
813  m_parts.erase( partBufIt );
814  ++m_hash;
815 
816  return removeAliases( aPartBuf );
817 }
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

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

◆ GetAliases()

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

References m_aliases.

◆ GetAliasNames()

wxArrayString LIB_MANAGER::LIB_BUFFER::GetAliasNames ( ) const

Returns all alias names for stored parts

Definition at line 765 of file lib_manager.cpp.

766 {
767  wxArrayString ret;
768 
769  for( const auto& alias : m_aliases )
770  ret.push_back( alias.first );
771 
772  return ret;
773 }
std::map< wxString, PART_BUFFER::WEAK_PTR > m_aliases
Definition: lib_manager.h:418

◆ GetBuffer()

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.

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

References m_aliases.

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

◆ GetBuffers()

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.

401  {
402  return m_parts;
403  }
std::deque< PART_BUFFER::PTR > m_parts
Definition: lib_manager.h:419

References m_parts.

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

◆ GetHash()

int LIB_MANAGER::LIB_BUFFER::GetHash ( ) const
inline

Definition at line 356 of file lib_manager.h.

357  {
358  return m_hash;
359  }

References m_hash.

◆ GetPart()

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.

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

References GetBuffer().

Referenced by LIB_MANAGER::GetBufferedPart().

◆ IsModified()

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

References m_deleted, and m_parts.

◆ removeAliases()

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

Removes alias entries for a particular part buffer

Definition at line 875 of file lib_manager.cpp.

876 {
877  LIB_PART* part = aPartBuf->GetPart();
878  wxCHECK( part, false );
879  bool ret = true; // Assume everything is ok
880 
881  for( unsigned int i = 0; i < part->GetAliasCount(); ++i )
882  {
883  auto aliasIt = m_aliases.find( part->GetAlias( i )->GetName() );
884 
885  if( aliasIt == m_aliases.end() )
886  {
887  wxFAIL;
888  ret = false;
889  continue;
890  }
891 
892  // Be sure the alias belongs to the assigned owner
893  wxASSERT( aliasIt->second.lock() == aPartBuf );
894 
895  m_aliases.erase( aliasIt );
896  }
897 
898  return ret;
899 }
LIB_ALIAS * GetAlias(size_t aIndex)
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
size_t GetAliasCount() const

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

◆ SaveBuffer() [1/2]

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 820 of file lib_manager.cpp.

822 {
823  wxCHECK( aPartBuf, false );
824  LIB_PART* part = aPartBuf->GetPart();
825  wxCHECK( part, false );
826  wxCHECK( aLibTable->SaveSymbol( m_libName, new LIB_PART( *part ) ) == SYMBOL_LIB_TABLE::SAVE_OK, false );
827 
828  aPartBuf->SetOriginal( new LIB_PART( *part ) );
829  ++m_hash;
830  return true;
831 }
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

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

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

◆ SaveBuffer() [2/2]

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 834 of file lib_manager.cpp.

836 {
837  wxCHECK( aPartBuf, false );
838  LIB_PART* part = aPartBuf->GetPart();
839  wxCHECK( part, false );
840 
841  // set properties to prevent save file on every symbol save
842  PROPERTIES properties;
843  properties.emplace( SCH_LEGACY_PLUGIN::PropBuffering, "" );
844 
845  // TODO there is no way to check if symbol has been successfully saved
846  aPlugin->SaveSymbol( m_libName, new LIB_PART( *part ), aBuffer ? &properties : nullptr );
847  aPartBuf->SetOriginal( new LIB_PART( *part ) );
848  ++m_hash;
849  return true;
850 }
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

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

◆ UpdateBuffer()

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 795 of file lib_manager.cpp.

796 {
797  bool ret = true;
798 
799  ret &= removeAliases( aPartBuf );
800  aPartBuf->SetPart( aCopy );
801  ret &= addAliases( aPartBuf );
802  ++m_hash;
803 
804  return ret;
805 }
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

Referenced by LIB_MANAGER::UpdatePart().

Friends And Related Function Documentation

◆ PART_BUFFER

friend class PART_BUFFER
friend

Definition at line 429 of file lib_manager.h.

Member Data Documentation

◆ m_aliases

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

Definition at line 418 of file lib_manager.h.

Referenced by GetAliases(), and GetBuffer().

◆ m_deleted

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.

Referenced by ClearDeletedBuffer(), and IsModified().

◆ m_hash

int LIB_MANAGER::LIB_BUFFER::m_hash
private

Definition at line 427 of file lib_manager.h.

Referenced by GetHash().

◆ m_libName

const wxString LIB_MANAGER::LIB_BUFFER::m_libName
private

Buffered library name.

Definition at line 425 of file lib_manager.h.

◆ m_parts

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

Definition at line 419 of file lib_manager.h.

Referenced by GetBuffers(), and IsModified().


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