KiCad PCB EDA Suite
LIB_MANAGER Class Reference

Class to handle modifications to the symbol libraries. More...

#include <lib_manager.h>

Classes

class  LIB_BUFFER
 

Class to store a working copy of a library

More...
 
class  PART_BUFFER
 

Class to store a working copy of a LIB_PART object and editor context.

More...
 

Public Member Functions

 LIB_MANAGER (LIB_EDIT_FRAME &aFrame)
 
void Sync (bool aForce=false, std::function< void(int, int, const wxString &)> aProgressCallback=[](int, int, const wxString &){})
 Updates the LIB_MANAGER data to synchronize with Symbol Library Table. More...
 
int GetHash () const
 
bool HasModifications () const
 
int GetLibraryHash (const wxString &aLibrary) const
 Returns a library hash value to determine if it has changed. More...
 
wxArrayString GetLibraryNames () const
 Returns the array of library names. More...
 
SYMBOL_LIB_TABLE_ROWGetLibrary (const wxString &aLibrary) const
 Finds a single library within the (aggregate) library table. More...
 
std::list< LIB_ALIAS * > GetAliases (const wxString &aLibrary) const
 
bool CreateLibrary (const wxString &aFilePath, SYMBOL_LIB_TABLE *aTable)
 Creates an empty library and adds it to the library table. More...
 
bool AddLibrary (const wxString &aFilePath, SYMBOL_LIB_TABLE *aTable)
 Adds an existing library. More...
 
bool UpdatePart (LIB_PART *aPart, const wxString &aLibrary)
 Updates the part buffer with a new version of the part. More...
 
bool UpdatePartAfterRename (LIB_PART *aPart, const wxString &oldAlias, const wxString &aLibrary)
 Updates the part buffer with a new version of the part when the name has changed. More...
 
bool RemovePart (const wxString &aName, const wxString &aLibrary)
 Removes the part from the part buffer. More...
 
LIB_ALIASGetAlias (const wxString &aAlias, const wxString &aLibrary) const
 Returns either an alias of a working LIB_PART copy, or alias of the original part if there is no working copy. More...
 
LIB_PARTGetBufferedPart (const wxString &aAlias, const wxString &aLibrary)
 Returns the part copy from the buffer. More...
 
SCH_SCREENGetScreen (const wxString &aAlias, const wxString &aLibrary)
 Returns the screen used to edit a specific part. More...
 
bool PartExists (const wxString &aAlias, const wxString &aLibrary) const
 Returns true if part with a specific alias exists in library (either original one or buffered). More...
 
bool LibraryExists (const wxString &aLibrary, bool aCheckEnabled=false) const
 Returns true if library exists. More...
 
bool IsLibraryModified (const wxString &aLibrary) const
 Returns true if library has unsaved modifications. More...
 
bool IsPartModified (const wxString &aAlias, const wxString &aLibrary) const
 Returns true if part has unsaved modifications. More...
 
bool ClearLibraryModified (const wxString &aLibrary) const
 Clears the modified flag for all parts in a library. More...
 
bool ClearPartModified (const wxString &aAlias, const wxString &aLibrary) const
 Clears the modified flag for a part. More...
 
bool IsLibraryReadOnly (const wxString &aLibrary) const
 Returns true if the library is stored in a read-only file. More...
 
bool FlushPart (const wxString &aAlias, const wxString &aLibrary)
 Saves part changes to the library copy used by the schematic editor. More...
 
bool SaveLibrary (const wxString &aLibrary, const wxString &aFileName)
 Saves library to a file, including unsaved changes. More...
 
LIB_ID RevertPart (const wxString &aAlias, const wxString &aLibrary)
 Reverts unsaved changes for a particular part. More...
 
bool RevertLibrary (const wxString &aLibrary)
 Reverts unsaved changes for a particular library. More...
 
bool RevertAll ()
 Revert all pending changes. More...
 
wxString GetUniqueLibraryName () const
 Returns a library name that is not currently in use. More...
 
LIB_TREE_MODEL_ADAPTER::PTRGetAdapter ()
 Returns the adapter object that provides the stored data. More...
 
const wxString & GetCurrentLib () const
 Returns the currently modified library name. More...
 
void SetCurrentLib (const wxString &aLibrary)
 
const wxString & GetCurrentPart () const
 Returns the currently modified part name. More...
 
void SetCurrentPart (const wxString &aPart)
 
LIB_ID GetCurrentLibId () const
 Returns the current library and part name as LIB_ID. More...
 

Private Member Functions

bool addLibrary (const wxString &aFilePath, bool aCreate, SYMBOL_LIB_TABLE *aTable)
 

Helper function to add either existing or create new library

More...
 
SYMBOL_LIB_TABLEsymTable () const
 

Returns the current Symbol Library Table

More...
 
std::set< LIB_PART * > getOriginalParts (const wxString &aLibrary)
 

Returns a set of LIB_PART objects belonging to the original library

More...
 
LIB_BUFFERgetLibraryBuffer (const wxString &aLibrary)
 

Returns an existing library buffer or creates one to using Symbol Library Table to get the original data.

More...
 
SYMBOL_TREE_SYNCHRONIZING_ADAPTERgetAdapter ()
 

Static Private Member Functions

static wxString getLibraryName (const wxString &aFilePath)
 

Extracts library name basing on the file name

More...
 

Private Attributes

std::map< wxString, LIB_BUFFERm_libs
 

The library buffers

More...
 
LIB_EDIT_FRAMEm_frame
 
LIB_LOGGER m_logger
 
int m_syncHash
 
wxString m_currentLib
 
wxString m_currentPart
 
SYMBOL_TREE_SYNCHRONIZING_ADAPTER::PTR m_adapter
 

Detailed Description

Class to handle modifications to the symbol libraries.

Definition at line 99 of file lib_manager.h.

Constructor & Destructor Documentation

◆ LIB_MANAGER()

LIB_MANAGER::LIB_MANAGER ( LIB_EDIT_FRAME aFrame)

Definition at line 39 of file lib_manager.cpp.

39  :
40  m_frame( aFrame ),
41  m_syncHash( 0 )
42 {
44  m_adapter->ShowUnits( false );
45 }
static PTR Create(LIB_EDIT_FRAME *aParent, LIB_MANAGER *aLibs)
LIB_EDIT_FRAME & m_frame
Definition: lib_manager.h:428
SYMBOL_TREE_SYNCHRONIZING_ADAPTER::PTR m_adapter
Definition: lib_manager.h:435

References SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Create(), m_adapter, and m_frame.

Member Function Documentation

◆ AddLibrary()

bool LIB_MANAGER::AddLibrary ( const wxString &  aFilePath,
SYMBOL_LIB_TABLE aTable 
)
inline

Adds an existing library.

The library is added to the library table as well.

Definition at line 146 of file lib_manager.h.

147  {
148  return addLibrary( aFilePath, false, aTable );
149  }
bool addLibrary(const wxString &aFilePath, bool aCreate, SYMBOL_LIB_TABLE *aTable)
Helper function to add either existing or create new library

References addLibrary().

Referenced by LIB_EDIT_FRAME::AddLibraryFile(), and LIB_EDIT_FRAME::ExportPart().

◆ addLibrary()

bool LIB_MANAGER::addLibrary ( const wxString &  aFilePath,
bool  aCreate,
SYMBOL_LIB_TABLE aTable 
)
private

Helper function to add either existing or create new library

Definition at line 570 of file lib_manager.cpp.

571 {
572  wxCHECK( aTable, false );
573  wxString libName = getLibraryName( aFilePath );
574  wxCHECK( !LibraryExists( libName ), false ); // either create or add an existing one
575 
576  // try to use path normalized to an environmental variable or project path
577  wxString relPath = NormalizePath( aFilePath, &Pgm().GetLocalEnvVariables(), &m_frame.Prj() );
578 
579  if( relPath.IsEmpty() )
580  relPath = aFilePath;
581 
582  wxString typeName = SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_LEGACY );
583  SYMBOL_LIB_TABLE_ROW* libRow = new SYMBOL_LIB_TABLE_ROW( libName, relPath, typeName );
584  aTable->InsertRow( libRow );
585 
586  if( aCreate )
587  {
588  try
589  {
590  aTable->CreateSymbolLib( libName );
591  }
592  catch( const IO_ERROR& e )
593  {
594  aTable->RemoveRow( libRow );
595  return false;
596  }
597  }
598 
599  m_frame.SyncLibraries( false );
600 
601  return true;
602 }
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
void CreateSymbolLib(const wxString &aNickname)
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:76
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
LIB_EDIT_FRAME & m_frame
Definition: lib_manager.h:428
bool RemoveRow(LIB_TABLE_ROW *aRow)
Removes a row from the table.
void SyncLibraries(bool aShowProgress)
Synchronize the library manager to the symbol library table, and then the symbol tree to the library ...
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Returns true if library exists.
static wxString getLibraryName(const wxString &aFilePath)
Extracts library name basing on the file name
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
wxString NormalizePath(const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath)
Normalizes a file path to an environmental variable, if possible.
Definition: env_paths.cpp:67

References SYMBOL_LIB_TABLE::CreateSymbolLib(), getLibraryName(), LIB_TABLE::InsertRow(), LibraryExists(), m_frame, NormalizePath(), Pgm(), KIWAY_HOLDER::Prj(), LIB_TABLE::RemoveRow(), SCH_IO_MGR::ShowType(), and LIB_EDIT_FRAME::SyncLibraries().

Referenced by AddLibrary(), and CreateLibrary().

◆ ClearLibraryModified()

bool LIB_MANAGER::ClearLibraryModified ( const wxString &  aLibrary) const

Clears the modified flag for all parts in a library.

Definition at line 207 of file lib_manager.cpp.

208 {
209  auto libIt = m_libs.find( aLibrary );
210 
211  if( libIt == m_libs.end() )
212  return false;
213 
214  for( auto& partBuf : libIt->second.GetBuffers() )
215  {
216  SCH_SCREEN* screen = partBuf->GetScreen();
217 
218  if( screen )
219  screen->ClrModify();
220  }
221 
222  return true;
223 }
void ClrModify()
Definition: base_screen.h:225
std::map< wxString, LIB_BUFFER > m_libs
The library buffers
Definition: lib_manager.h:426

References BASE_SCREEN::ClrModify(), and m_libs.

Referenced by LIB_EDIT_FRAME::saveLibrary().

◆ ClearPartModified()

bool LIB_MANAGER::ClearPartModified ( const wxString &  aAlias,
const wxString &  aLibrary 
) const

Clears the modified flag for a part.

Definition at line 226 of file lib_manager.cpp.

227 {
228  auto libI = m_libs.find( aLibrary );
229 
230  if( libI == m_libs.end() )
231  return false;
232 
233  auto partBuf = libI->second.GetBuffer( aAlias );
234  wxCHECK( partBuf, false );
235 
236  partBuf->GetScreen()->ClrModify();
237  return true;
238 }
std::map< wxString, LIB_BUFFER > m_libs
The library buffers
Definition: lib_manager.h:426

References m_libs.

Referenced by LIB_EDIT_FRAME::Revert(), LIB_EDIT_FRAME::Save(), and LIB_EDIT_FRAME::saveCurrentPart().

◆ CreateLibrary()

bool LIB_MANAGER::CreateLibrary ( const wxString &  aFilePath,
SYMBOL_LIB_TABLE aTable 
)
inline

Creates an empty library and adds it to the library table.

The library file is created.

Definition at line 138 of file lib_manager.h.

139  {
140  return addLibrary( aFilePath, true, aTable );
141  }
bool addLibrary(const wxString &aFilePath, bool aCreate, SYMBOL_LIB_TABLE *aTable)
Helper function to add either existing or create new library

References addLibrary().

Referenced by LIB_EDIT_FRAME::AddLibraryFile().

◆ FlushPart()

bool LIB_MANAGER::FlushPart ( const wxString &  aAlias,
const wxString &  aLibrary 
)

Saves part changes to the library copy used by the schematic editor.

Not it is not necessarily saved to the file.

Returns
True on success, false otherwise.

Definition at line 388 of file lib_manager.cpp.

389 {
390  auto it = m_libs.find( aLibrary );
391 
392  if( it == m_libs.end() ) // no items to flush
393  return true;
394 
395  auto partBuf = it->second.GetBuffer( aAlias );
396  wxCHECK( partBuf, false );
397 
398  return it->second.SaveBuffer( partBuf, symTable() );
399 }
SYMBOL_LIB_TABLE * symTable() const
Returns the current Symbol Library Table
std::map< wxString, LIB_BUFFER > m_libs
The library buffers
Definition: lib_manager.h:426

References m_libs, and symTable().

Referenced by LIB_EDIT_FRAME::Save(), and LIB_EDIT_FRAME::saveCurrentPart().

◆ GetAdapter()

LIB_TREE_MODEL_ADAPTER::PTR& LIB_MANAGER::GetAdapter ( )
inline

Returns the adapter object that provides the stored data.

Definition at line 269 of file lib_manager.h.

269 { return m_adapter; }
SYMBOL_TREE_SYNCHRONIZING_ADAPTER::PTR m_adapter
Definition: lib_manager.h:435

References m_adapter.

Referenced by LIB_EDIT_FRAME::FreezeSearchTree(), SYMBOL_TREE_PANE::SYMBOL_TREE_PANE(), LIB_EDIT_FRAME::SyncLibraries(), LIB_EDIT_FRAME::ThawSearchTree(), and LIB_EDIT_FRAME::UpdateAfterSymbolProperties().

◆ getAdapter()

SYMBOL_TREE_SYNCHRONIZING_ADAPTER* LIB_MANAGER::getAdapter ( )
inlineprivate

Definition at line 436 of file lib_manager.h.

437  {
438  return static_cast<SYMBOL_TREE_SYNCHRONIZING_ADAPTER*>( m_adapter.get() );
439  }
SYMBOL_TREE_SYNCHRONIZING_ADAPTER::PTR m_adapter
Definition: lib_manager.h:435

References m_adapter.

Referenced by Sync().

◆ GetAlias()

LIB_ALIAS * LIB_MANAGER::GetAlias ( const wxString &  aAlias,
const wxString &  aLibrary 
) const

Returns either an alias of a working LIB_PART copy, or alias of the original part if there is no working copy.

Definition at line 480 of file lib_manager.cpp.

481 {
482  // Try the library buffers first
483  auto libIt = m_libs.find( aLibrary );
484 
485  if( libIt != m_libs.end() )
486  {
487  LIB_PART* part = libIt->second.GetPart( aAlias );
488 
489  if( part )
490  return part->GetAlias( aAlias );
491  }
492 
493  // Get the original part
494  LIB_ALIAS* alias = nullptr;
495 
496  try
497  {
498  alias = symTable()->LoadSymbol( aLibrary, aAlias );
499  }
500  catch( const IO_ERROR& e )
501  {
502  wxLogMessage( _( "Cannot load symbol \"%s\" from library \"%s\" (%s)" ),
503  aAlias, aLibrary, e.What() );
504  }
505 
506  return alias;
507 }
LIB_ALIAS * LoadSymbol(const wxString &aNickname, const wxString &aAliasName)
Load a LIB_ALIAS having aAliasName from the library given by aNickname.
Part library alias object definition.
LIB_ALIAS * GetAlias(size_t aIndex) const
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
Define a library symbol object.
#define _(s)
SYMBOL_LIB_TABLE * symTable() const
Returns the current Symbol Library Table
std::map< wxString, LIB_BUFFER > m_libs
The library buffers
Definition: lib_manager.h:426
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76

References _, LIB_PART::GetAlias(), SYMBOL_LIB_TABLE::LoadSymbol(), m_libs, symTable(), and IO_ERROR::What().

Referenced by LIB_EDIT_FRAME::getTargetPart().

◆ GetAliases()

std::list< LIB_ALIAS * > LIB_MANAGER::GetAliases ( const wxString &  aLibrary) const

Definition at line 249 of file lib_manager.cpp.

250 {
251  std::list<LIB_ALIAS*> ret;
252  wxCHECK( LibraryExists( aLibrary ), ret );
253 
254  auto libIt = m_libs.find( aLibrary );
255 
256  if( libIt != m_libs.end() )
257  {
258  for( auto& partBuf : libIt->second.GetBuffers() )
259  {
260  for( unsigned int i = 0; i < partBuf->GetPart()->GetAliasCount(); ++i )
261  ret.push_back( partBuf->GetPart()->GetAlias( i ) );
262  }
263  }
264  else
265  {
266  std::vector<LIB_ALIAS*> aliases;
267 
268  try
269  {
270  symTable()->LoadSymbolLib( aliases, aLibrary );
271  }
272  catch( const IO_ERROR& e )
273  {
274  wxLogWarning( e.Problem() );
275  }
276 
277  std::copy( aliases.begin(), aliases.end(), std::back_inserter( ret ) );
278  }
279 
280  return ret;
281 }
void LoadSymbolLib(std::vector< LIB_ALIAS * > &aAliasList, const wxString &aNickname, bool aPowerSymbolsOnly=false)
virtual const wxString Problem() const
what was the problem?
Definition: exceptions.cpp:49
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Returns true if library exists.
SYMBOL_LIB_TABLE * symTable() const
Returns the current Symbol Library Table
size_t i
Definition: json11.cpp:597
std::map< wxString, LIB_BUFFER > m_libs
The library buffers
Definition: lib_manager.h:426
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76

References i, LibraryExists(), SYMBOL_LIB_TABLE::LoadSymbolLib(), m_libs, IO_ERROR::Problem(), and symTable().

Referenced by SYMBOL_TREE_SYNCHRONIZING_ADAPTER::updateLibrary().

◆ GetBufferedPart()

LIB_PART * LIB_MANAGER::GetBufferedPart ( const wxString &  aAlias,
const wxString &  aLibrary 
)

Returns the part copy from the buffer.

In case it does not exist yet, the copy is created. LIB_MANAGER retains the ownership.

Definition at line 284 of file lib_manager.cpp.

285 {
286  wxCHECK( LibraryExists( aLibrary ), nullptr );
287 
288  // try the library buffers first
289  LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary );
290  LIB_PART* bufferedPart = libBuf.GetPart( aAlias );
291 
292  if( !bufferedPart ) // no buffer part found
293  {
294  // create a copy of the part
295  try
296  {
297  LIB_ALIAS* alias = symTable()->LoadSymbol( aLibrary, aAlias );
298 
299  if( alias == nullptr )
300  THROW_IO_ERROR( _( "Symbol not found." ) );
301 
302  bufferedPart = new LIB_PART( *alias->GetPart(), nullptr );
303  libBuf.CreateBuffer( bufferedPart, new SCH_SCREEN( &m_frame.Kiway() ) );
304  }
305  catch( const IO_ERROR& e )
306  {
307  wxLogMessage( _( "Error loading symbol \"%s\" from library \"%s\". (%s)" ),
308  aAlias, aLibrary, e.What() );
309  bufferedPart = nullptr;
310  }
311  }
312 
313  return bufferedPart;
314 }
LIB_ALIAS * LoadSymbol(const wxString &aNickname, const wxString &aAliasName)
Load a LIB_ALIAS having aAliasName from the library given by aNickname.
Part library alias object definition.
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_holder.h:56
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
LIB_EDIT_FRAME & m_frame
Definition: lib_manager.h:428
Define a library symbol object.
#define THROW_IO_ERROR(msg)
LIB_PART * GetPart() const
Get the shared LIB_PART.
#define _(s)
LIB_BUFFER & getLibraryBuffer(const wxString &aLibrary)
Returns an existing library buffer or creates one to using Symbol Library Table to get the original d...
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Returns true if library exists.
SYMBOL_LIB_TABLE * symTable() const
Returns the current Symbol Library Table
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76

References _, LIB_MANAGER::LIB_BUFFER::CreateBuffer(), getLibraryBuffer(), LIB_ALIAS::GetPart(), LIB_MANAGER::LIB_BUFFER::GetPart(), KIWAY_HOLDER::Kiway(), LIB_PART::LIB_PART(), LibraryExists(), SYMBOL_LIB_TABLE::LoadSymbol(), m_frame, symTable(), THROW_IO_ERROR, and IO_ERROR::What().

Referenced by LIB_EDIT_FRAME::CopyPartToClipboard(), LIB_EDIT_FRAME::DuplicatePart(), LIB_EDIT_FRAME::isCurrentPart(), LIB_EDIT_FRAME::LoadOneLibraryPartAux(), LIB_EDIT_FRAME::LoadPart(), and LIB_EDIT_FRAME::savePartAs().

◆ GetCurrentLib()

const wxString& LIB_MANAGER::GetCurrentLib ( ) const
inline

Returns the currently modified library name.

Definition at line 274 of file lib_manager.h.

274 { return m_currentLib; }
wxString m_currentLib
Definition: lib_manager.h:432

References m_currentLib.

Referenced by SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr().

◆ GetCurrentLibId()

LIB_ID LIB_MANAGER::GetCurrentLibId ( ) const
inline

Returns the current library and part name as LIB_ID.

Definition at line 286 of file lib_manager.h.

287  {
288  return LIB_ID( m_currentLib, m_currentPart );
289  }
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
wxString m_currentLib
Definition: lib_manager.h:432
wxString m_currentPart
Definition: lib_manager.h:433

References m_currentLib, and m_currentPart.

Referenced by SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr().

◆ GetCurrentPart()

const wxString& LIB_MANAGER::GetCurrentPart ( ) const
inline

Returns the currently modified part name.

Definition at line 280 of file lib_manager.h.

280 { return m_currentPart; }
wxString m_currentPart
Definition: lib_manager.h:433

References m_currentPart.

◆ GetHash()

int LIB_MANAGER::GetHash ( ) const

Definition at line 77 of file lib_manager.cpp.

78 {
79  int hash = symTable()->GetModifyHash();
80 
81  for( const auto& lib : m_libs )
82  hash += lib.second.GetHash();
83 
84  return hash;
85 }
SYMBOL_LIB_TABLE * symTable() const
Returns the current Symbol Library Table
std::map< wxString, LIB_BUFFER > m_libs
The library buffers
Definition: lib_manager.h:426

References SYMBOL_LIB_TABLE::GetModifyHash(), m_libs, and symTable().

Referenced by RevertAll(), and SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync().

◆ GetLibrary()

SYMBOL_LIB_TABLE_ROW * LIB_MANAGER::GetLibrary ( const wxString &  aLibrary) const

Finds a single library within the (aggregate) library table.

Definition at line 113 of file lib_manager.cpp.

114 {
115  SYMBOL_LIB_TABLE_ROW* row = nullptr;
116 
117  try
118  {
119  row = symTable()->FindRow( aLibrary );
120  }
121  catch( const IO_ERROR& e )
122  {
123  wxLogMessage( _( "Cannot find library \"%s\" in the Symbol Library Table (%s)" ),
124  aLibrary, e.What() );
125  }
126 
127  return row;
128 }
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
#define _(s)
SYMBOL_LIB_TABLE * symTable() const
Returns the current Symbol Library Table
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76

References _, SYMBOL_LIB_TABLE::FindRow(), symTable(), and IO_ERROR::What().

Referenced by GetLibraryHash(), SaveLibrary(), and SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync().

◆ getLibraryBuffer()

LIB_MANAGER::LIB_BUFFER & LIB_MANAGER::getLibraryBuffer ( const wxString &  aLibrary)
private

Returns an existing library buffer or creates one to using Symbol Library Table to get the original data.

Definition at line 636 of file lib_manager.cpp.

637 {
638  auto it = m_libs.find( aLibrary );
639 
640  if( it != m_libs.end() )
641  return it->second;
642 
643  // The requested buffer does not exist yet, so create one
644  auto ret = m_libs.emplace( aLibrary, LIB_BUFFER( aLibrary ) );
645  LIB_BUFFER& buf = ret.first->second;
646 
647  for( auto part : getOriginalParts( aLibrary ) )
648  buf.CreateBuffer( new LIB_PART( *part, nullptr ), new SCH_SCREEN( &m_frame.Kiway() ) );
649 
650  return buf;
651 }
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_holder.h:56
LIB_EDIT_FRAME & m_frame
Definition: lib_manager.h:428
Define a library symbol object.
std::set< LIB_PART * > getOriginalParts(const wxString &aLibrary)
Returns a set of LIB_PART objects belonging to the original library
std::map< wxString, LIB_BUFFER > m_libs
The library buffers
Definition: lib_manager.h:426

References LIB_MANAGER::LIB_BUFFER::CreateBuffer(), getOriginalParts(), KIWAY_HOLDER::Kiway(), LIB_PART::LIB_PART(), m_frame, and m_libs.

Referenced by GetBufferedPart(), RemovePart(), UpdatePart(), and UpdatePartAfterRename().

◆ GetLibraryHash()

int LIB_MANAGER::GetLibraryHash ( const wxString &  aLibrary) const

Returns a library hash value to determine if it has changed.

For buffered libraries, it returns a number corresponding to the number of modifications. For original libraries, hash is computed basing on the library URI. Returns -1 when the requested library does not exist.

Definition at line 88 of file lib_manager.cpp.

89 {
90  const auto libBufIt = m_libs.find( aLibrary );
91 
92  if( libBufIt != m_libs.end() )
93  return libBufIt->second.GetHash();
94 
95  auto row = GetLibrary( aLibrary );
96 
97  // return -1 if library does not exist or 0 if not modified
98  return row ? std::hash<std::string>{}( aLibrary.ToStdString() + row->GetFullURI( true ).ToStdString() ) : -1;
99 }
SYMBOL_LIB_TABLE_ROW * GetLibrary(const wxString &aLibrary) const
Finds a single library within the (aggregate) library table.
std::map< wxString, LIB_BUFFER > m_libs
The library buffers
Definition: lib_manager.h:426

References GetLibrary(), and m_libs.

Referenced by SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync(), and SYMBOL_TREE_SYNCHRONIZING_ADAPTER::updateLibrary().

◆ getLibraryName()

wxString LIB_MANAGER::getLibraryName ( const wxString &  aFilePath)
staticprivate

Extracts library name basing on the file name

Definition at line 563 of file lib_manager.cpp.

564 {
565  wxFileName fn( aFilePath );
566  return fn.GetName();
567 }

Referenced by addLibrary().

◆ GetLibraryNames()

wxArrayString LIB_MANAGER::GetLibraryNames ( ) const

Returns the array of library names.

Definition at line 102 of file lib_manager.cpp.

103 {
104  wxArrayString res;
105 
106  for( const auto& libName : symTable()->GetLogicalLibs() )
107  res.Add( libName );
108 
109  return res;
110 }
SYMBOL_LIB_TABLE * symTable() const
Returns the current Symbol Library Table

References symTable().

Referenced by SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetLibrariesCount(), LIB_EDIT_FRAME::saveAllLibraries(), and SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync().

◆ getOriginalParts()

std::set< LIB_PART * > LIB_MANAGER::getOriginalParts ( const wxString &  aLibrary)
private

Returns a set of LIB_PART objects belonging to the original library

Definition at line 611 of file lib_manager.cpp.

612 {
613  std::set<LIB_PART*> parts;
614  wxCHECK( LibraryExists( aLibrary ), parts );
615 
616  try
617  {
618  wxArrayString aliases;
619  symTable()->EnumerateSymbolLib( aLibrary, aliases );
620 
621  for( const auto& aliasName : aliases )
622  {
623  LIB_ALIAS* alias = symTable()->LoadSymbol( aLibrary, aliasName );
624  parts.insert( alias->GetPart() );
625  }
626  }
627  catch( const IO_ERROR& e )
628  {
629  wxLogMessage( _( "Cannot enumerate library \"%s\" (%s)" ), aLibrary, e.What() );
630  }
631 
632  return parts;
633 }
LIB_ALIAS * LoadSymbol(const wxString &aNickname, const wxString &aAliasName)
Load a LIB_ALIAS having aAliasName from the library given by aNickname.
void EnumerateSymbolLib(const wxString &aNickname, wxArrayString &aAliasNames, bool aPowerSymbolsOnly=false)
Return a list of symbol alias names contained within the library given by aNickname.
Part library alias object definition.
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
LIB_PART * GetPart() const
Get the shared LIB_PART.
#define _(s)
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Returns true if library exists.
SYMBOL_LIB_TABLE * symTable() const
Returns the current Symbol Library Table
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76

References _, SYMBOL_LIB_TABLE::EnumerateSymbolLib(), LIB_ALIAS::GetPart(), LibraryExists(), SYMBOL_LIB_TABLE::LoadSymbol(), symTable(), and IO_ERROR::What().

Referenced by getLibraryBuffer(), and SaveLibrary().

◆ GetScreen()

SCH_SCREEN * LIB_MANAGER::GetScreen ( const wxString &  aAlias,
const wxString &  aLibrary 
)

Returns the screen used to edit a specific part.

LIB_MANAGER retains the ownership.

Definition at line 317 of file lib_manager.cpp.

318 {
319  wxCHECK( LibraryExists( aLibrary ), nullptr );
320  wxCHECK( !aAlias.IsEmpty(), nullptr );
321  auto it = m_libs.find( aLibrary );
322  wxCHECK( it != m_libs.end(), nullptr );
323 
324  LIB_BUFFER& buf = it->second;
325  auto partBuf = buf.GetBuffer( aAlias );
326  return partBuf ? partBuf->GetScreen() : nullptr;
327 }
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Returns true if library exists.
std::map< wxString, LIB_BUFFER > m_libs
The library buffers
Definition: lib_manager.h:426

References LIB_MANAGER::LIB_BUFFER::GetBuffer(), LibraryExists(), and m_libs.

Referenced by LIB_EDIT_FRAME::LoadOneLibraryPartAux().

◆ GetUniqueLibraryName()

wxString LIB_MANAGER::GetUniqueLibraryName ( ) const

Returns a library name that is not currently in use.

Used for generating names for new libraries.

Definition at line 543 of file lib_manager.cpp.

544 {
545  wxString name = "New_Library";
546 
547  if( !LibraryExists( name ) )
548  return name;
549 
550  name += "_";
551 
552  for( unsigned int i = 0; i < std::numeric_limits<unsigned int>::max(); ++i )
553  {
554  if( !LibraryExists( name + wxString::Format( "%u", i ) ) )
555  return name + wxString::Format( "%u", i );
556  }
557 
558  wxFAIL;
559  return wxEmptyString;
560 }
const char * name
Definition: DXF_plotter.cpp:61
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define max(a, b)
Definition: auxiliary.h:86
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Returns true if library exists.
size_t i
Definition: json11.cpp:597

References Format(), i, LibraryExists(), max, and name.

Referenced by LIB_EDIT_FRAME::AddLibraryFile().

◆ HasModifications()

bool LIB_MANAGER::HasModifications ( ) const

Definition at line 65 of file lib_manager.cpp.

66 {
67  for( const auto& lib : m_libs )
68  {
69  if( lib.second.IsModified() )
70  return true;
71  }
72 
73  return false;
74 }
std::map< wxString, LIB_BUFFER > m_libs
The library buffers
Definition: lib_manager.h:426

References m_libs.

Referenced by LIB_EDIT_FRAME::HasLibModifications().

◆ IsLibraryModified()

bool LIB_MANAGER::IsLibraryModified ( const wxString &  aLibrary) const

Returns true if library has unsaved modifications.

Definition at line 187 of file lib_manager.cpp.

188 {
189  auto it = m_libs.find( aLibrary );
190  return it != m_libs.end() ? it->second.IsModified() : false;
191 }
std::map< wxString, LIB_BUFFER > m_libs
The library buffers
Definition: lib_manager.h:426

References m_libs.

Referenced by SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr(), SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetValue(), LIB_EDIT_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::saveAllLibraries(), and LIB_EDIT_FRAME::SyncToolbars().

◆ IsLibraryReadOnly()

bool LIB_MANAGER::IsLibraryReadOnly ( const wxString &  aLibrary) const

Returns true if the library is stored in a read-only file.

Returns
True on success, false otherwise.

Definition at line 241 of file lib_manager.cpp.

242 {
243  wxCHECK( LibraryExists( aLibrary ), true );
244  wxFileName fn( symTable()->GetFullURI( aLibrary ) );
245  return ( fn.FileExists() && !fn.IsFileWritable() ) || !fn.IsDirWritable();
246 }
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Returns true if library exists.
SYMBOL_LIB_TABLE * symTable() const
Returns the current Symbol Library Table

References LibraryExists(), and symTable().

Referenced by LIB_EDIT_FRAME::ReCreateMenuBar().

◆ IsPartModified()

bool LIB_MANAGER::IsPartModified ( const wxString &  aAlias,
const wxString &  aLibrary 
) const

Returns true if part has unsaved modifications.

Definition at line 194 of file lib_manager.cpp.

195 {
196  auto libIt = m_libs.find( aLibrary );
197 
198  if( libIt == m_libs.end() )
199  return false;
200 
201  const LIB_BUFFER& buf = libIt->second;
202  auto partBuf = buf.GetBuffer( aAlias );
203  return partBuf ? partBuf->IsModified() : false;
204 }
std::map< wxString, LIB_BUFFER > m_libs
The library buffers
Definition: lib_manager.h:426

References LIB_MANAGER::LIB_BUFFER::GetBuffer(), and m_libs.

Referenced by LIB_EDIT_FRAME::DeletePartFromLibrary(), SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr(), SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetValue(), LIB_EDIT_FRAME::ReCreateMenuBar(), and LIB_EDIT_FRAME::SyncToolbars().

◆ LibraryExists()

bool LIB_MANAGER::LibraryExists ( const wxString &  aLibrary,
bool  aCheckEnabled = false 
) const

Returns true if library exists.

If aCheckEnabled is set, then the library must also be enabled in the library table.

Definition at line 531 of file lib_manager.cpp.

532 {
533  if( aLibrary.IsEmpty() )
534  return false;
535 
536  if( m_libs.count( aLibrary ) > 0 )
537  return true;
538 
539  return symTable()->HasLibrary( aLibrary, aCheckEnabled );
540 }
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
SYMBOL_LIB_TABLE * symTable() const
Returns the current Symbol Library Table
std::map< wxString, LIB_BUFFER > m_libs
The library buffers
Definition: lib_manager.h:426

References LIB_TABLE::HasLibrary(), m_libs, and symTable().

Referenced by addLibrary(), LIB_EDIT_FRAME::AddLibraryFile(), LIB_EDIT_FRAME::CreateNewPart(), LIB_EDIT_FRAME::DuplicatePart(), GetAliases(), GetBufferedPart(), getOriginalParts(), GetScreen(), GetUniqueLibraryName(), LIB_EDIT_FRAME::ImportPart(), IsLibraryReadOnly(), SaveLibrary(), SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync(), and UpdatePart().

◆ PartExists()

bool LIB_MANAGER::PartExists ( const wxString &  aAlias,
const wxString &  aLibrary 
) const

Returns true if part with a specific alias exists in library (either original one or buffered).

Definition at line 510 of file lib_manager.cpp.

511 {
512  auto libBufIt = m_libs.find( aLibrary );
513  LIB_ALIAS* alias = nullptr;
514 
515  if( libBufIt != m_libs.end() )
516  return !!libBufIt->second.GetBuffer( aAlias );
517 
518  try
519  {
520  alias = symTable()->LoadSymbol( aLibrary, aAlias );
521  }
522  catch( IO_ERROR& )
523  {
524  // checking if certain symbol exists, so its absence is perfectly fine
525  }
526 
527  return alias != nullptr;
528 }
LIB_ALIAS * LoadSymbol(const wxString &aNickname, const wxString &aAliasName)
Load a LIB_ALIAS having aAliasName from the library given by aNickname.
Part library alias object definition.
SYMBOL_LIB_TABLE * symTable() const
Returns the current Symbol Library Table
std::map< wxString, LIB_BUFFER > m_libs
The library buffers
Definition: lib_manager.h:426
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76

References SYMBOL_LIB_TABLE::LoadSymbol(), m_libs, and symTable().

Referenced by LIB_EDIT_FRAME::CreateNewPart(), LIB_EDIT_FRAME::fixDuplicateAliases(), LIB_EDIT_FRAME::ImportPart(), LIB_EDIT_FRAME::LoadPart(), LIB_EDIT_FRAME::Revert(), LIB_EDIT_FRAME::savePartAs(), and LIB_EDIT_FRAME::UpdateAfterSymbolProperties().

◆ RemovePart()

bool LIB_MANAGER::RemovePart ( const wxString &  aName,
const wxString &  aLibrary 
)

Removes the part from the part buffer.

It is required to save the library to have the part removed in the schematic editor.

Definition at line 467 of file lib_manager.cpp.

468 {
469  LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary );
470  auto partBuf = libBuf.GetBuffer( aAlias );
471  wxCHECK( partBuf, false );
472 
473  bool res = libBuf.DeleteBuffer( partBuf );
474  m_frame.SyncLibraries( false );
475 
476  return res;
477 }
LIB_EDIT_FRAME & m_frame
Definition: lib_manager.h:428
void SyncLibraries(bool aShowProgress)
Synchronize the library manager to the symbol library table, and then the symbol tree to the library ...
LIB_BUFFER & getLibraryBuffer(const wxString &aLibrary)
Returns an existing library buffer or creates one to using Symbol Library Table to get the original d...

References LIB_MANAGER::LIB_BUFFER::DeleteBuffer(), LIB_MANAGER::LIB_BUFFER::GetBuffer(), getLibraryBuffer(), m_frame, and LIB_EDIT_FRAME::SyncLibraries().

Referenced by LIB_EDIT_FRAME::DeletePartFromLibrary().

◆ RevertAll()

bool LIB_MANAGER::RevertAll ( )

Revert all pending changes.

Returns
True if all changes successfully reverted.

Definition at line 441 of file lib_manager.cpp.

442 {
443  bool retv = true;
444 
445  // Nothing to revert.
446  if( GetHash() == 0 )
447  return true;
448 
449  for( auto lib : m_libs )
450  {
451  if( !lib.second.IsModified() )
452  continue;
453 
454  for( auto buffer : lib.second.GetBuffers() )
455  {
456  if( !buffer->IsModified() )
457  continue;
458 
459  RevertPart( lib.first, buffer->GetOriginal()->GetName() );
460  }
461  }
462 
463  return retv;
464 }
LIB_ID RevertPart(const wxString &aAlias, const wxString &aLibrary)
Reverts unsaved changes for a particular part.
int GetHash() const
Definition: lib_manager.cpp:77
std::map< wxString, LIB_BUFFER > m_libs
The library buffers
Definition: lib_manager.h:426

References GetHash(), m_libs, and RevertPart().

Referenced by LIB_EDIT_FRAME::RevertAll().

◆ RevertLibrary()

bool LIB_MANAGER::RevertLibrary ( const wxString &  aLibrary)

Reverts unsaved changes for a particular library.

Returns
True on success, false otherwise.

Definition at line 427 of file lib_manager.cpp.

428 {
429  auto it = m_libs.find( aLibrary );
430 
431  if( it == m_libs.end() ) // nothing to reverse
432  return false;
433 
434  m_libs.erase( it );
435  m_frame.SyncLibraries( false );
436 
437  return true;
438 }
LIB_EDIT_FRAME & m_frame
Definition: lib_manager.h:428
void SyncLibraries(bool aShowProgress)
Synchronize the library manager to the symbol library table, and then the symbol tree to the library ...
std::map< wxString, LIB_BUFFER > m_libs
The library buffers
Definition: lib_manager.h:426

References m_frame, m_libs, and LIB_EDIT_FRAME::SyncLibraries().

Referenced by LIB_EDIT_FRAME::Revert().

◆ RevertPart()

LIB_ID LIB_MANAGER::RevertPart ( const wxString &  aAlias,
const wxString &  aLibrary 
)

Reverts unsaved changes for a particular part.

Returns
The LIB_ID of the reverted part (which may be different in the case of a rename)

Definition at line 402 of file lib_manager.cpp.

403 {
404  auto it = m_libs.find( aLibrary );
405 
406  if( it == m_libs.end() ) // no items to flush
407  return LIB_ID( aLibrary, aAlias );
408 
409  auto partBuf = it->second.GetBuffer( aAlias );
410  wxCHECK( partBuf, LIB_ID( aLibrary, aAlias ) );
411  LIB_PART original( *partBuf->GetOriginal() );
412 
413  if( original.GetName() != aAlias )
414  {
415  UpdatePartAfterRename( &original, aAlias, aLibrary );
416  }
417  else
418  {
419  partBuf->SetPart( new LIB_PART( original ) );
420  m_frame.SyncLibraries( false );
421  }
422 
423  return LIB_ID( aLibrary, original.GetName() );
424 }
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
LIB_EDIT_FRAME & m_frame
Definition: lib_manager.h:428
Define a library symbol object.
void SyncLibraries(bool aShowProgress)
Synchronize the library manager to the symbol library table, and then the symbol tree to the library ...
std::map< wxString, LIB_BUFFER > m_libs
The library buffers
Definition: lib_manager.h:426
bool UpdatePartAfterRename(LIB_PART *aPart, const wxString &oldAlias, const wxString &aLibrary)
Updates the part buffer with a new version of the part when the name has changed.

References LIB_PART::LIB_PART(), m_frame, m_libs, LIB_EDIT_FRAME::SyncLibraries(), and UpdatePartAfterRename().

Referenced by LIB_EDIT_FRAME::Revert(), and RevertAll().

◆ SaveLibrary()

bool LIB_MANAGER::SaveLibrary ( const wxString &  aLibrary,
const wxString &  aFileName 
)

Saves library to a file, including unsaved changes.

Parameters
aLibraryis the library name.
aFileNameis the target file name.
Returns
True on success, false otherwise.

Definition at line 131 of file lib_manager.cpp.

132 {
133  wxCHECK( LibraryExists( aLibrary ), false );
134  wxFileName fn( aFileName );
135  wxCHECK( !fn.FileExists() || fn.IsFileWritable(), false );
136  SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );
137  bool res = true; // assume all libraries are successfully saved
138 
139  auto it = m_libs.find( aLibrary );
140 
141  if( it != m_libs.end() )
142  {
143  // Handle buffered library
144  LIB_BUFFER& libBuf = it->second;
145 
146  const auto& partBuffers = libBuf.GetBuffers();
147 
148  for( const auto& partBuf : partBuffers )
149  {
150  if( !libBuf.SaveBuffer( partBuf, &*pi, true ) )
151  {
152  // Something went wrong, but try to save other libraries
153  res = false;
154  }
155  }
156 
157  // clear the deleted parts buffer only if data is saved to the original file
158  wxFileName original, destination( aFileName );
159  auto row = GetLibrary( aLibrary );
160 
161  if( row )
162  {
163  original = row->GetFullURI( true );
164  original.Normalize();
165  }
166 
167  destination.Normalize();
168 
169  if( res && original == destination )
170  libBuf.ClearDeletedBuffer();
171  }
172  else
173  {
174  // Handle original library
175  PROPERTIES properties;
176  properties.emplace( SCH_LEGACY_PLUGIN::PropBuffering, "" );
177 
178  for( auto part : getOriginalParts( aLibrary ) )
179  pi->SaveSymbol( aLibrary, new LIB_PART( *part ), &properties );
180  }
181 
182  pi->SaveLibrary( aFileName );
183  return res;
184 }
Class PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
Define a library symbol object.
SYMBOL_LIB_TABLE_ROW * GetLibrary(const wxString &aLibrary) const
Finds a single library within the (aggregate) library table.
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:520
std::set< LIB_PART * > getOriginalParts(const wxString &aLibrary)
Returns a set of LIB_PART objects belonging to the original library
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Returns true if library exists.
static const char * PropBuffering
const char* PropBuffering
std::map< wxString, LIB_BUFFER > m_libs
The library buffers
Definition: lib_manager.h:426

References LIB_MANAGER::LIB_BUFFER::ClearDeletedBuffer(), LIB_MANAGER::LIB_BUFFER::GetBuffers(), GetLibrary(), getOriginalParts(), LIB_PART::LIB_PART(), LibraryExists(), m_libs, SCH_LEGACY_PLUGIN::PropBuffering, and LIB_MANAGER::LIB_BUFFER::SaveBuffer().

Referenced by LIB_EDIT_FRAME::saveLibrary().

◆ SetCurrentLib()

void LIB_MANAGER::SetCurrentLib ( const wxString &  aLibrary)
inline

Definition at line 275 of file lib_manager.h.

275 { m_currentLib = aLibrary; }
wxString m_currentLib
Definition: lib_manager.h:432

References m_currentLib.

Referenced by LIB_EDIT_FRAME::SetCurLib().

◆ SetCurrentPart()

void LIB_MANAGER::SetCurrentPart ( const wxString &  aPart)
inline

Definition at line 281 of file lib_manager.h.

281 { m_currentPart = aPart; }
wxString m_currentPart
Definition: lib_manager.h:433

References m_currentPart.

Referenced by LIB_EDIT_FRAME::SetCurPart(), and UpdatePartAfterRename().

◆ symTable()

SYMBOL_LIB_TABLE * LIB_MANAGER::symTable ( ) const
private

Returns the current Symbol Library Table

Definition at line 605 of file lib_manager.cpp.

606 {
607  return m_frame.Prj().SchSymbolLibTable();
608 }
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
LIB_EDIT_FRAME & m_frame
Definition: lib_manager.h:428

References m_frame, and KIWAY_HOLDER::Prj().

Referenced by FlushPart(), GetAlias(), GetAliases(), GetBufferedPart(), GetHash(), GetLibrary(), GetLibraryNames(), getOriginalParts(), IsLibraryReadOnly(), LibraryExists(), PartExists(), and Sync().

◆ Sync()

void LIB_MANAGER::Sync ( bool  aForce = false,
std::function< void(int, int, const wxString &)>  aProgressCallback = [](int, int, const wxString&){} 
)

Updates the LIB_MANAGER data to synchronize with Symbol Library Table.

Definition at line 48 of file lib_manager.cpp.

50 {
52  {
53  int libTableHash = symTable()->GetModifyHash();
54 
55  if( aForce || m_syncHash != libTableHash )
56  {
57  getAdapter()->Sync( aForce, aProgressCallback );
58  m_syncHash = libTableHash;
59  }
60  }
62 }
LIB_LOGGER m_logger
Definition: lib_manager.h:429
void Activate()
Definition: lib_manager.h:60
void Deactivate()
Definition: lib_manager.h:70
SYMBOL_LIB_TABLE * symTable() const
Returns the current Symbol Library Table
void Sync(bool aForce=false, std::function< void(int, int, const wxString &)> aProgressCallback=[](int, int, const wxString &){})
SYMBOL_TREE_SYNCHRONIZING_ADAPTER * getAdapter()
Definition: lib_manager.h:436

References LIB_LOGGER::Activate(), LIB_LOGGER::Deactivate(), getAdapter(), SYMBOL_LIB_TABLE::GetModifyHash(), m_logger, m_syncHash, symTable(), and SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync().

Referenced by LIB_EDIT_FRAME::SyncLibraries().

◆ UpdatePart()

bool LIB_MANAGER::UpdatePart ( LIB_PART aPart,
const wxString &  aLibrary 
)

Updates the part buffer with a new version of the part.

The library buffer creates a copy of the part. It is required to save the library to use the updated part in the schematic editor.

Definition at line 330 of file lib_manager.cpp.

331 {
332  wxCHECK( LibraryExists( aLibrary ), false );
333  wxCHECK( aPart, false );
334  LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary );
335  auto partBuf = libBuf.GetBuffer( aPart->GetName() );
336  LIB_PART* partCopy = new LIB_PART( *aPart, nullptr );
337 
338  partCopy->SetLibId( LIB_ID( aLibrary, aPart->GetLibId().GetLibItemName() ) );
339 
340  if( partBuf )
341  {
342  libBuf.UpdateBuffer( partBuf, partCopy );
343  }
344  else // New entry
345  {
346  SCH_SCREEN* screen = new SCH_SCREEN( &m_frame.Kiway() );
347  libBuf.CreateBuffer( partCopy, screen );
348  screen->SetModify();
349  }
350 
351  return true;
352 }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_holder.h:56
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
LIB_EDIT_FRAME & m_frame
Definition: lib_manager.h:428
const LIB_ID & GetLibId() const
Define a library symbol object.
LIB_BUFFER & getLibraryBuffer(const wxString &aLibrary)
Returns an existing library buffer or creates one to using Symbol Library Table to get the original d...
const wxString & GetName() const
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Returns true if library exists.
void SetModify()
Definition: base_screen.h:224
void SetLibId(const LIB_ID &aLibId)

References LIB_MANAGER::LIB_BUFFER::CreateBuffer(), LIB_MANAGER::LIB_BUFFER::GetBuffer(), LIB_PART::GetLibId(), LIB_ID::GetLibItemName(), getLibraryBuffer(), LIB_PART::GetName(), KIWAY_HOLDER::Kiway(), LIB_PART::LIB_PART(), LibraryExists(), m_frame, LIB_PART::SetLibId(), BASE_SCREEN::SetModify(), and LIB_MANAGER::LIB_BUFFER::UpdateBuffer().

Referenced by LIB_EDIT_FRAME::CreateNewPart(), LIB_EDIT_FRAME::DuplicatePart(), LIB_EDIT_FRAME::ImportPart(), LIB_EDIT_FRAME::savePartAs(), LIB_EDIT_FRAME::storeCurrentPart(), and UpdatePartAfterRename().

◆ UpdatePartAfterRename()

bool LIB_MANAGER::UpdatePartAfterRename ( LIB_PART aPart,
const wxString &  oldAlias,
const wxString &  aLibrary 
)

Updates the part buffer with a new version of the part when the name has changed.

The old library buffer will be deleted and a new one created with the new name.

Definition at line 355 of file lib_manager.cpp.

357 {
358  // This is essentially a delete/update.
359 
360  LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary );
361  auto partBuf = libBuf.GetBuffer( oldAlias );
362  wxCHECK( partBuf, false );
363 
364  // Save the original record so it is transferred to the new buffer
365  std::unique_ptr<LIB_PART> original( new LIB_PART( *partBuf->GetOriginal() ) );
366 
367  // Save the screen object, so it is transferred to the new buffer
368  std::unique_ptr<SCH_SCREEN> screen = partBuf->RemoveScreen();
369 
370  if( !libBuf.DeleteBuffer( partBuf ) )
371  return false;
372 
373  if( !UpdatePart( aPart, aLibrary ) )
374  return false;
375 
376  partBuf = libBuf.GetBuffer( aPart->GetName() );
377  partBuf->SetScreen( std::move( screen ) );
378  wxCHECK( partBuf, false );
379  partBuf->SetOriginal( original.release() ); // part buffer takes ownership of pointer
380 
381  SetCurrentPart( aPart->GetName() );
382  m_frame.SyncLibraries( false );
383 
384  return true;
385 }
LIB_EDIT_FRAME & m_frame
Definition: lib_manager.h:428
Define a library symbol object.
void SetCurrentPart(const wxString &aPart)
Definition: lib_manager.h:281
bool UpdatePart(LIB_PART *aPart, const wxString &aLibrary)
Updates the part buffer with a new version of the part.
void SyncLibraries(bool aShowProgress)
Synchronize the library manager to the symbol library table, and then the symbol tree to the library ...
LIB_BUFFER & getLibraryBuffer(const wxString &aLibrary)
Returns an existing library buffer or creates one to using Symbol Library Table to get the original d...
const wxString & GetName() const

References LIB_MANAGER::LIB_BUFFER::DeleteBuffer(), LIB_MANAGER::LIB_BUFFER::GetBuffer(), getLibraryBuffer(), LIB_PART::GetName(), LIB_PART::LIB_PART(), m_frame, SetCurrentPart(), LIB_EDIT_FRAME::SyncLibraries(), and UpdatePart().

Referenced by LIB_EDIT_FRAME::GetComponentFromRedoList(), LIB_EDIT_FRAME::GetComponentFromUndoList(), RevertPart(), and LIB_EDIT_FRAME::UpdateAfterSymbolProperties().

Member Data Documentation

◆ m_adapter

SYMBOL_TREE_SYNCHRONIZING_ADAPTER::PTR LIB_MANAGER::m_adapter
private

Definition at line 435 of file lib_manager.h.

Referenced by GetAdapter(), getAdapter(), and LIB_MANAGER().

◆ m_currentLib

wxString LIB_MANAGER::m_currentLib
private

Definition at line 432 of file lib_manager.h.

Referenced by GetCurrentLib(), GetCurrentLibId(), and SetCurrentLib().

◆ m_currentPart

wxString LIB_MANAGER::m_currentPart
private

Definition at line 433 of file lib_manager.h.

Referenced by GetCurrentLibId(), GetCurrentPart(), and SetCurrentPart().

◆ m_frame

◆ m_libs

◆ m_logger

LIB_LOGGER LIB_MANAGER::m_logger
private

Definition at line 429 of file lib_manager.h.

Referenced by Sync().

◆ m_syncHash

int LIB_MANAGER::m_syncHash
private

Definition at line 430 of file lib_manager.h.

Referenced by Sync().


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