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

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

780 {
781  wxASSERT( m_aliases.count( aCopy->GetName() ) == 0 ); // only for new parts
782  wxASSERT( aCopy->GetLib() == nullptr );
783  std::unique_ptr<SCH_SCREEN> screen( aScreen );
784  auto partBuf = std::make_shared<PART_BUFFER>( aCopy, std::move( screen ) );
785  m_parts.push_back( partBuf );
786  addAliases( partBuf );
787 
788  // Set the parent library name,
789  // otherwise it is empty as no library has been given as the owner during object construction
790  LIB_ID& libId = (LIB_ID&) aCopy->GetLibId();
791  libId.SetLibNickname( m_libName );
792  ++m_hash;
793 
794  return true;
795 }
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 811 of file lib_manager.cpp.

812 {
813  auto partBufIt = std::find( m_parts.begin(), m_parts.end(), aPartBuf );
814  wxCHECK( partBufIt != m_parts.end(), false );
815  m_deleted.emplace_back( *partBufIt );
816  m_parts.erase( partBufIt );
817  ++m_hash;
818 
819  return removeAliases( aPartBuf );
820 }
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 768 of file lib_manager.cpp.

769 {
770  wxArrayString ret;
771 
772  for( const auto& alias : m_aliases )
773  ret.push_back( alias.first );
774 
775  return ret;
776 }
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 878 of file lib_manager.cpp.

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

825 {
826  wxCHECK( aPartBuf, false );
827  LIB_PART* part = aPartBuf->GetPart();
828  wxCHECK( part, false );
829  wxCHECK( aLibTable->SaveSymbol( m_libName, new LIB_PART( *part ) ) == SYMBOL_LIB_TABLE::SAVE_OK, false );
830 
831  aPartBuf->SetOriginal( new LIB_PART( *part ) );
832  ++m_hash;
833  return true;
834 }
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 837 of file lib_manager.cpp.

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

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