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
 
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 modifications 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...
 

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
 
const wxString m_libName
 
int m_hash
 

Detailed Description

Class to store a working copy of a library

Definition at line 342 of file lib_manager.h.

Constructor & Destructor Documentation

◆ LIB_BUFFER()

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

Definition at line 345 of file lib_manager.h.

345  :
346  m_libName( aLibrary ),
347  m_hash( 1 )
348  { }
const wxString m_libName
Definition: lib_manager.h:414

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

787 {
788  LIB_PART* part = aPartBuf->GetPart();
789  wxCHECK( part, false );
790  bool ret = true; // Assume everything is ok
791 
792  for( unsigned int i = 0; i < part->GetAliasCount(); ++i )
793  {
794  bool newAlias;
795  std::tie( std::ignore, newAlias ) = m_aliases.emplace( part->GetAlias( i )->GetName(),
796  aPartBuf );
797 
798  if( !newAlias ) // Overwrite check
799  {
800  wxFAIL;
801  ret = false;
802  }
803  }
804 
805  return ret;
806 }
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:411
size_t i
Definition: json11.cpp:597
size_t GetAliasCount() const

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

◆ ClearDeletedBuffer()

void LIB_MANAGER::LIB_BUFFER::ClearDeletedBuffer ( )
inline

Definition at line 381 of file lib_manager.h.

382  {
383  m_deleted.clear();
384  }
std::deque< PART_BUFFER::PTR > m_deleted
Definition: lib_manager.h:413

References m_deleted.

Referenced by 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 707 of file lib_manager.cpp.

708 {
709  wxASSERT( m_aliases.count( aCopy->GetName() ) == 0 ); // only for new parts
710  wxASSERT( aCopy->GetLib() == nullptr );
711  std::unique_ptr<SCH_SCREEN> screen( aScreen );
712  auto partBuf = std::make_shared<PART_BUFFER>( aCopy, std::move( screen ) );
713  m_parts.push_back( partBuf );
714  addAliases( partBuf );
715 
716  // Set the parent library name,
717  // otherwise it is empty as no library has been given as the owner during object construction
718  LIB_ID& libId = (LIB_ID&) aCopy->GetLibId();
719  libId.SetLibNickname( m_libName );
720  ++m_hash;
721 
722  return true;
723 }
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:411
const wxString m_libName
Definition: lib_manager.h:414
std::deque< PART_BUFFER::PTR > m_parts
Definition: lib_manager.h:412

References LIB_PART::GetLib(), LIB_PART::GetLibId(), LIB_PART::GetName(), LIB_PART::m_aliases, 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 740 of file lib_manager.cpp.

741 {
742  auto partBufIt = std::find( m_parts.begin(), m_parts.end(), aPartBuf );
743  wxCHECK( partBufIt != m_parts.end(), false );
744  m_deleted.emplace_back( *partBufIt );
745  m_parts.erase( partBufIt );
746  ++m_hash;
747 
748  return removeAliases( aPartBuf );
749 }
std::deque< PART_BUFFER::PTR > m_deleted
Definition: lib_manager.h:413
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:412

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

◆ 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 395 of file lib_manager.h.

396  {
397  auto it = m_aliases.find( aAlias );
398  return it != m_aliases.end() ? it->second.lock() : PART_BUFFER::PTR( nullptr );
399  }
std::map< wxString, PART_BUFFER::WEAK_PTR > m_aliases
Definition: lib_manager.h:411
std::shared_ptr< PART_BUFFER > PTR
Definition: lib_manager.h:330

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 402 of file lib_manager.h.

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

References m_parts.

Referenced by LIB_MANAGER::SaveLibrary().

◆ GetHash()

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

Definition at line 364 of file lib_manager.h.

364 { return m_hash; }

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 367 of file lib_manager.h.

368  {
369  auto buf = GetBuffer( aAlias );
370  return buf ? buf->GetPart() : nullptr;
371  }
PART_BUFFER::PTR GetBuffer(const wxString &aAlias) const
Returns a part buffer with LIB_PART holding a particular alias
Definition: lib_manager.h:395

References GetBuffer().

Referenced by LIB_MANAGER::GetBufferedPart().

◆ IsModified()

bool LIB_MANAGER::LIB_BUFFER::IsModified ( ) const
inline

Definition at line 350 of file lib_manager.h.

351  {
352  if( !m_deleted.empty() )
353  return true;
354 
355  for( const auto& partBuf : m_parts )
356  {
357  if( partBuf->IsModified() )
358  return true;
359  }
360 
361  return false;
362  }
std::deque< PART_BUFFER::PTR > m_deleted
Definition: lib_manager.h:413
std::deque< PART_BUFFER::PTR > m_parts
Definition: lib_manager.h:412

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

810 {
811  LIB_PART* part = aPartBuf->GetPart();
812  wxCHECK( part, false );
813  bool ret = true; // Assume everything is ok
814 
815  for( unsigned int i = 0; i < part->GetAliasCount(); ++i )
816  {
817  auto aliasIt = m_aliases.find( part->GetAlias( i )->GetName() );
818 
819  if( aliasIt == m_aliases.end() )
820  {
821  wxFAIL;
822  ret = false;
823  continue;
824  }
825 
826  // Be sure the alias belongs to the assigned owner
827  wxASSERT( aliasIt->second.lock() == aPartBuf );
828 
829  m_aliases.erase( aliasIt );
830  }
831 
832  return ret;
833 }
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:411
size_t i
Definition: json11.cpp:597
size_t GetAliasCount() const

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

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

754 {
755  wxCHECK( aPartBuf, false );
756  LIB_PART* part = aPartBuf->GetPart();
757  wxCHECK( part, false );
758  SYMBOL_LIB_TABLE::SAVE_T result = aLibTable->SaveSymbol( m_libName, new LIB_PART( *part ) );
759  wxCHECK( result == SYMBOL_LIB_TABLE::SAVE_OK, false );
760 
761  aPartBuf->SetOriginal( new LIB_PART( *part ) );
762  ++m_hash;
763  return true;
764 }
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
Definition: lib_manager.h:414
SAVE_T
The set of return values from SaveSymbol() below.

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

Referenced by LIB_MANAGER::SaveLibrary().

◆ SaveBuffer() [2/2]

bool LIB_MANAGER::LIB_BUFFER::SaveBuffer ( PART_BUFFER::PTR  aPartBuf,
SCH_PLUGIN aPlugin,
bool  aBuffer 
)

Saves stored modifications using a plugin.

aBuffer decides whether the changes should be cached or stored directly to the disk (for SCH_LEGACY_PLUGIN).

Definition at line 767 of file lib_manager.cpp.

769 {
770  wxCHECK( aPartBuf, false );
771  LIB_PART* part = aPartBuf->GetPart();
772  wxCHECK( part, false );
773 
774  // set properties to prevent save file on every symbol save
775  PROPERTIES properties;
776  properties.emplace( SCH_LEGACY_PLUGIN::PropBuffering, "" );
777 
778  // TODO there is no way to check if symbol has been successfully saved
779  aPlugin->SaveSymbol( m_libName, new LIB_PART( *part ), aBuffer ? &properties : nullptr );
780  aPartBuf->SetOriginal( new LIB_PART( *part ) );
781  ++m_hash;
782  return true;
783 }
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
Definition: lib_manager.h:414
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:93

References LIB_PART::LIB_PART(), 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 726 of file lib_manager.cpp.

728 {
729  bool ret = true;
730 
731  ret &= removeAliases( aPartBuf );
732  aPartBuf->SetPart( aCopy );
733  ret &= addAliases( aPartBuf );
734  ++m_hash;
735 
736  return ret;
737 }
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().

Member Data Documentation

◆ m_aliases

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

Definition at line 411 of file lib_manager.h.

Referenced by GetBuffer().

◆ m_deleted

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

Definition at line 413 of file lib_manager.h.

Referenced by ClearDeletedBuffer(), and IsModified().

◆ m_hash

int LIB_MANAGER::LIB_BUFFER::m_hash
private

Definition at line 415 of file lib_manager.h.

Referenced by GetHash().

◆ m_libName

const wxString LIB_MANAGER::LIB_BUFFER::m_libName
private

Definition at line 414 of file lib_manager.h.

◆ m_parts

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

Definition at line 412 of file lib_manager.h.

Referenced by GetBuffers(), and IsModified().


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