KiCad PCB EDA Suite
LIB_SYMBOL_LIBRARY_MANAGER Class Reference

Symbol library management helper that is specific to the symbol library editor frame. More...

#include <lib_symbol_library_manager.h>

Inheritance diagram for LIB_SYMBOL_LIBRARY_MANAGER:
SYMBOL_LIBRARY_MANAGER

Public Member Functions

 LIB_SYMBOL_LIBRARY_MANAGER (SYMBOL_EDIT_FRAME &aFrame)
 
void Sync (const wxString &aForceRefresh, std::function< void(int, int, const wxString &)> aProgressCallback)
 Updates the SYMBOL_LIBRARY_MANAGER data to synchronize with Symbol Library Table. More...
 
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > & GetAdapter ()
 Return the adapter object that provides the stored data. More...
 
void Preload (PROGRESS_REPORTER &aReporter)
 Preloads all symbol libraries in the symbol library table using SYMBOL_ASYNC_LOADER. More...
 
int GetHash () const
 
bool HasModifications () const
 
int GetLibraryHash (const wxString &aLibrary) const
 Return a library hash value to determine if it has changed. More...
 
wxArrayString GetLibraryNames () const
 Return the array of library names. More...
 
SYMBOL_LIB_TABLE_ROWGetLibrary (const wxString &aLibrary) const
 Find a single library within the (aggregate) library table. More...
 
std::list< LIB_SYMBOL * > GetAliases (const wxString &aLibrary) const
 
bool CreateLibrary (const wxString &aFilePath, SYMBOL_LIB_TABLE *aTable)
 Create an empty library and adds it to the library table. More...
 
bool AddLibrary (const wxString &aFilePath, SYMBOL_LIB_TABLE *aTable)
 Add an existing library. More...
 
bool UpdateSymbol (LIB_SYMBOL *aSymbol, const wxString &aLibrary)
 Update the symbol buffer with a new version of the symbol. More...
 
bool UpdateSymbolAfterRename (LIB_SYMBOL *aSymbol, const wxString &oldAlias, const wxString &aLibrary)
 Update the symbol buffer with a new version of the symbol when the name has changed. More...
 
bool RemoveSymbol (const wxString &aName, const wxString &aLibrary)
 Remove the symbol from the symbol buffer. More...
 
LIB_SYMBOLGetAlias (const wxString &aAlias, const wxString &aLibrary) const
 Return either an alias of a working LIB_SYMBOL copy, or alias of the original symbol if there is no working copy. More...
 
LIB_SYMBOLGetBufferedSymbol (const wxString &aAlias, const wxString &aLibrary)
 Return the symbol copy from the buffer. More...
 
SCH_SCREENGetScreen (const wxString &aAlias, const wxString &aLibrary)
 Return the screen used to edit a specific symbol. More...
 
bool SymbolExists (const wxString &aAlias, const wxString &aLibrary) const
 Return true if symbol with a specific alias exists in library (either original one or buffered). More...
 
bool LibraryExists (const wxString &aLibrary, bool aCheckEnabled=false) const
 Return true if library exists. More...
 
bool IsLibraryLoaded (const wxString &aLibrary) const
 Return true if the library was successfully loaded. More...
 
bool IsLibraryModified (const wxString &aLibrary) const
 Return true if library has unsaved modifications. More...
 
bool IsSymbolModified (const wxString &aAlias, const wxString &aLibrary) const
 Return true if symbol has unsaved modifications. More...
 
void SetSymbolModified (const wxString &aAlias, const wxString &aLibrary)
 
bool ClearLibraryModified (const wxString &aLibrary) const
 Clear the modified flag for all symbols in a library. More...
 
bool ClearSymbolModified (const wxString &aAlias, const wxString &aLibrary) const
 Clear the modified flag for a symbol. More...
 
bool IsLibraryReadOnly (const wxString &aLibrary) const
 Return true if the library is stored in a read-only file. More...
 
bool FlushSymbol (const wxString &aAlias, const wxString &aLibrary)
 Save symbol changes to the library copy used by the schematic editor. More...
 
bool SaveLibrary (const wxString &aLibrary, const wxString &aFileName, SCH_IO_MGR::SCH_FILE_T aFileType=SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY)
 Save library to a file, including unsaved changes. More...
 
LIB_ID RevertSymbol (const wxString &aAlias, const wxString &aLibrary)
 Revert unsaved changes for a symbolicular symbol. More...
 
bool RevertLibrary (const wxString &aLibrary)
 Revert unsaved changes for a symbolicular library. More...
 
bool RevertAll ()
 Revert all pending changes. More...
 
wxString GetUniqueLibraryName () const
 Return a library name that is not currently in use. More...
 
void GetRootSymbolNames (const wxString &aLibName, wxArrayString &aRootSymbolNames)
 
bool HasDerivedSymbols (const wxString &aSymbolName, const wxString &aLibraryName)
 Check if symbol aSymbolName in library aLibraryName is a root symbol that has derived symbols. More...
 
size_t GetLibraryCount () const
 

Protected Member Functions

void OnDataChanged () const override
 Extract library name basing on the file name. More...
 
bool addLibrary (const wxString &aFilePath, bool aCreate, SYMBOL_LIB_TABLE *aTable)
 Return the current Symbol Library Table. More...
 
SYMBOL_LIB_TABLEsymTable () const
 Class to store a working copy of a LIB_SYMBOL object and editor context. More...
 
std::set< LIB_SYMBOL * > getOriginalSymbols (const wxString &aLibrary)
 Return a set of LIB_SYMBOL objects belonging to the original library. More...
 
LIB_BUFFERgetLibraryBuffer (const wxString &aLibrary)
 Return an existing library buffer or creates one to using Symbol Library Table to get the original data. More...
 

Static Protected Member Functions

static wxString getLibraryName (const wxString &aFilePath)
 Helper function to add either existing or create new library. More...
 

Protected Attributes

std::map< wxString, LIB_BUFFERm_libs
 
SCH_BASE_FRAMEm_frame
 Parent frame. More...
 
LIB_LOGGERm_logger
 

Private Member Functions

SYMBOL_TREE_SYNCHRONIZING_ADAPTERgetAdapter ()
 

Private Attributes

wxObjectDataPtr< LIB_TREE_MODEL_ADAPTERm_adapter
 
int m_syncHash
 Symbol lib table hash value from last synchronization. More...
 

Detailed Description

Symbol library management helper that is specific to the symbol library editor frame.

The base class handles library manipulation; this one also handles synchronizing the LIB_TREE.

Definition at line 32 of file lib_symbol_library_manager.h.

Constructor & Destructor Documentation

◆ LIB_SYMBOL_LIBRARY_MANAGER()

LIB_SYMBOL_LIBRARY_MANAGER::LIB_SYMBOL_LIBRARY_MANAGER ( SYMBOL_EDIT_FRAME aFrame)

Definition at line 25 of file lib_symbol_library_manager.cpp.

25 :
26 SYMBOL_LIBRARY_MANAGER( aFrame ),
27 m_syncHash( 0 )
28{
30 m_adapter->ShowUnits( false );
31}
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
int m_syncHash
Symbol lib table hash value from last synchronization.
SYMBOL_LIBRARY_MANAGER(SCH_BASE_FRAME &aFrame)
static wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > Create(SYMBOL_EDIT_FRAME *aParent, SYMBOL_LIBRARY_MANAGER *aLibs)

References SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Create(), and m_adapter.

Member Function Documentation

◆ addLibrary()

bool SYMBOL_LIBRARY_MANAGER::addLibrary ( const wxString &  aFilePath,
bool  aCreate,
SYMBOL_LIB_TABLE aTable 
)
protectedinherited

Return the current Symbol Library Table.

Definition at line 721 of file symbol_library_manager.cpp.

723{
724 wxCHECK( aTable, false );
725 wxString libName = getLibraryName( aFilePath );
726 wxCHECK( !LibraryExists( libName ), false ); // either create or add an existing one
727
728 // try to use path normalized to an environmental variable or project path
729 wxString relPath = NormalizePath( aFilePath, &Pgm().GetLocalEnvVariables(), &m_frame.Prj() );
730
731 SCH_IO_MGR::SCH_FILE_T schFileType = SCH_IO_MGR::GuessPluginTypeFromLibPath( aFilePath );
732 wxString typeName = SCH_IO_MGR::ShowType( schFileType );
733 SYMBOL_LIB_TABLE_ROW* libRow = new SYMBOL_LIB_TABLE_ROW( libName, relPath, typeName );
734 aTable->InsertRow( libRow );
735
736 if( aCreate )
737 {
738 wxCHECK( schFileType != SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY, false );
739
740 try
741 {
742 aTable->CreateSymbolLib( libName );
743 }
744 catch( const IO_ERROR& )
745 {
746 aTable->RemoveRow( libRow );
747 return false;
748 }
749 }
750
752
753 return true;
754}
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
bool RemoveRow(const LIB_TABLE_ROW *aRow)
Removes a row from the table.
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:81
static SCH_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath)
Return a plugin type given a symbol library using the file extension of aLibPath.
Definition: sch_io_mgr.cpp:156
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Return true if library exists.
static wxString getLibraryName(const wxString &aFilePath)
Helper function to add either existing or create new library.
virtual void OnDataChanged() const
Extract library name basing on the file name.
SCH_BASE_FRAME & m_frame
Parent frame.
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
void CreateSymbolLib(const wxString &aNickname)
wxString NormalizePath(const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath)
Normalize a file path to an environmental variable, if possible.
Definition: env_paths.cpp:71
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111

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

Referenced by SYMBOL_LIBRARY_MANAGER::AddLibrary(), and SYMBOL_LIBRARY_MANAGER::CreateLibrary().

◆ AddLibrary()

bool SYMBOL_LIBRARY_MANAGER::AddLibrary ( const wxString &  aFilePath,
SYMBOL_LIB_TABLE aTable 
)
inlineinherited

Add an existing library.

The library is added to the library table as well.

Definition at line 101 of file symbol_library_manager.h.

102 {
103 return addLibrary( aFilePath, false, aTable );
104 }
bool addLibrary(const wxString &aFilePath, bool aCreate, SYMBOL_LIB_TABLE *aTable)
Return the current Symbol Library Table.

References SYMBOL_LIBRARY_MANAGER::addLibrary().

Referenced by SYMBOL_EDIT_FRAME::AddLibraryFile(), SYMBOL_EDIT_FRAME::DdAddLibrary(), and SYMBOL_EDIT_FRAME::ExportSymbol().

◆ ClearLibraryModified()

bool SYMBOL_LIBRARY_MANAGER::ClearLibraryModified ( const wxString &  aLibrary) const
inherited

Clear the modified flag for all symbols in a library.

Definition at line 308 of file symbol_library_manager.cpp.

309{
310 auto libIt = m_libs.find( aLibrary );
311
312 if( libIt == m_libs.end() )
313 return false;
314
315 for( auto& symbolBuf : libIt->second.GetBuffers() )
316 {
317 SCH_SCREEN* screen = symbolBuf->GetScreen();
318
319 if( screen )
320 screen->SetContentModified( false );
321 }
322
323 return true;
324}
void SetContentModified(bool aModified=true)
Definition: base_screen.h:59
std::map< wxString, LIB_BUFFER > m_libs

References SYMBOL_LIBRARY_MANAGER::m_libs, and BASE_SCREEN::SetContentModified().

Referenced by SYMBOL_EDIT_FRAME::saveLibrary().

◆ ClearSymbolModified()

bool SYMBOL_LIBRARY_MANAGER::ClearSymbolModified ( const wxString &  aAlias,
const wxString &  aLibrary 
) const
inherited

Clear the modified flag for a symbol.

Definition at line 327 of file symbol_library_manager.cpp.

329{
330 auto libI = m_libs.find( aLibrary );
331
332 if( libI == m_libs.end() )
333 return false;
334
335 auto symbolBuf = libI->second.GetBuffer( aAlias );
336 wxCHECK( symbolBuf, false );
337
338 symbolBuf->GetScreen()->SetContentModified( false );
339 return true;
340}

References SYMBOL_LIBRARY_MANAGER::m_libs.

Referenced by SYMBOL_EDIT_FRAME::Revert(), and SYMBOL_EDIT_FRAME::saveCurrentSymbol().

◆ CreateLibrary()

bool SYMBOL_LIBRARY_MANAGER::CreateLibrary ( const wxString &  aFilePath,
SYMBOL_LIB_TABLE aTable 
)
inlineinherited

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

The library file is created.

Definition at line 93 of file symbol_library_manager.h.

94 {
95 return addLibrary( aFilePath, true, aTable );
96 }

References SYMBOL_LIBRARY_MANAGER::addLibrary().

Referenced by SYMBOL_EDIT_FRAME::AddLibraryFile(), and SCH_EDITOR_CONTROL::ExportSymbolsToLibrary().

◆ FlushSymbol()

bool SYMBOL_LIBRARY_MANAGER::FlushSymbol ( const wxString &  aAlias,
const wxString &  aLibrary 
)
inherited

Save symbol 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 510 of file symbol_library_manager.cpp.

511{
512 auto it = m_libs.find( aLibrary );
513
514 if( it == m_libs.end() ) // no items to flush
515 return true;
516
517 auto symbolBuf = it->second.GetBuffer( aAlias );
518 wxCHECK( symbolBuf, false );
519
520 return it->second.SaveBuffer( symbolBuf, symTable() );
521}
SYMBOL_LIB_TABLE * symTable() const
Class to store a working copy of a LIB_SYMBOL object and editor context.

References SYMBOL_LIBRARY_MANAGER::m_libs, and SYMBOL_LIBRARY_MANAGER::symTable().

Referenced by SYMBOL_EDIT_FRAME::saveCurrentSymbol().

◆ GetAdapter()

wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > & LIB_SYMBOL_LIBRARY_MANAGER::GetAdapter ( )
inline

◆ getAdapter()

SYMBOL_TREE_SYNCHRONIZING_ADAPTER * LIB_SYMBOL_LIBRARY_MANAGER::getAdapter ( )
inlineprivate

Definition at line 52 of file lib_symbol_library_manager.h.

References m_adapter.

Referenced by Sync().

◆ GetAlias()

LIB_SYMBOL * SYMBOL_LIBRARY_MANAGER::GetAlias ( const wxString &  aAlias,
const wxString &  aLibrary 
) const
inherited

Return either an alias of a working LIB_SYMBOL copy, or alias of the original symbol if there is no working copy.

Definition at line 605 of file symbol_library_manager.cpp.

607{
608 // Try the library buffers first
609 auto libIt = m_libs.find( aLibrary );
610
611 if( libIt != m_libs.end() )
612 {
613 LIB_SYMBOL* symbol = libIt->second.GetSymbol( aAlias );
614
615 if( symbol )
616 return symbol;
617 }
618
619 // Get the original symbol
620 LIB_SYMBOL* alias = nullptr;
621
622 try
623 {
624 alias = symTable()->LoadSymbol( aLibrary, aAlias );
625 }
626 catch( const IO_ERROR& e )
627 {
628 wxLogMessage( _( "Cannot load symbol '%s' from library '%s'." ) + e.What(),
629 aAlias,
630 aLibrary );
631 }
632
633 return alias;
634}
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
Define a library symbol object.
Definition: lib_symbol.h:99
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
#define _(s)

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

Referenced by SYMBOL_EDIT_FRAME::CreateNewSymbol(), SYMBOL_EDIT_FRAME::getTargetSymbol(), and DIALOG_LIB_SYMBOL_PROPERTIES::TransferDataFromWindow().

◆ GetAliases()

std::list< LIB_SYMBOL * > SYMBOL_LIBRARY_MANAGER::GetAliases ( const wxString &  aLibrary) const
inherited

Definition at line 359 of file symbol_library_manager.cpp.

360{
361 std::list<LIB_SYMBOL*> ret;
362 wxCHECK( LibraryExists( aLibrary ), ret );
363
364 auto libIt = m_libs.find( aLibrary );
365
366 if( libIt != m_libs.end() )
367 {
368 for( auto& symbolBuf : libIt->second.GetBuffers() )
369 {
370 ret.push_back( symbolBuf->GetSymbol() );
371 }
372 }
373 else
374 {
375 std::vector<LIB_SYMBOL*> aliases;
376
377 try
378 {
379 symTable()->LoadSymbolLib( aliases, aLibrary );
380 }
381 catch( const IO_ERROR& e )
382 {
383 wxLogWarning( e.Problem() );
384 }
385
386 std::copy( aliases.begin(), aliases.end(), std::back_inserter( ret ) );
387 }
388
389 return ret;
390}
virtual const wxString Problem() const
what was the problem?
Definition: exceptions.cpp:46
void LoadSymbolLib(std::vector< LIB_SYMBOL * > &aAliasList, const wxString &aNickname, bool aPowerSymbolsOnly=false)

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

Referenced by SYMBOL_TREE_SYNCHRONIZING_ADAPTER::updateLibrary().

◆ GetBufferedSymbol()

LIB_SYMBOL * SYMBOL_LIBRARY_MANAGER::GetBufferedSymbol ( const wxString &  aAlias,
const wxString &  aLibrary 
)
inherited

Return the symbol copy from the buffer.

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

Definition at line 393 of file symbol_library_manager.cpp.

395{
396 wxCHECK( LibraryExists( aLibrary ), nullptr );
397
398 // try the library buffers first
399 LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary );
400 LIB_SYMBOL* bufferedSymbol = libBuf.GetSymbol( aAlias );
401
402 if( !bufferedSymbol ) // no buffer symbol found
403 {
404 // create a copy of the symbol
405 try
406 {
407 LIB_SYMBOL* symbol = symTable()->LoadSymbol( aLibrary, aAlias );
408
409 if( symbol == nullptr )
410 THROW_IO_ERROR( _( "Symbol not found." ) );
411
412 LIB_SYMBOL* bufferedParent = nullptr;
413
414 // Create parent symbols on demand so parent symbol can be set.
415 if( symbol->IsAlias() )
416 {
417 std::shared_ptr< LIB_SYMBOL > parent = symbol->GetParent().lock();
418 wxCHECK_MSG( parent, nullptr,
419 wxString::Format( "Derived symbol '%s' found with undefined parent.",
420 symbol->GetName() ) );
421
422 // Check if the parent symbol buffer has already be created.
423 bufferedParent = libBuf.GetSymbol( parent->GetName() );
424
425 if( !bufferedParent )
426 {
427 bufferedParent = new LIB_SYMBOL( *parent.get() );
428 libBuf.CreateBuffer( bufferedParent, new SCH_SCREEN );
429 }
430 }
431
432 bufferedSymbol = new LIB_SYMBOL( *symbol );
433
434 if( bufferedParent )
435 bufferedSymbol->SetParent( bufferedParent );
436
437 libBuf.CreateBuffer( bufferedSymbol, new SCH_SCREEN );
438 }
439 catch( const IO_ERROR& e )
440 {
441 wxLogMessage( _( "Error loading symbol %s from library '%s'. (%s)" ),
442 aAlias, aLibrary, e.What() );
443 bufferedSymbol = nullptr;
444 }
445 }
446
447 return bufferedSymbol;
448}
bool IsAlias() const
Definition: lib_symbol.h:188
void SetParent(LIB_SYMBOL *aParent=nullptr)
Definition: lib_symbol.cpp:447
wxString GetName() const override
Definition: lib_symbol.h:138
LIB_SYMBOL_REF & GetParent()
Definition: lib_symbol.h:127
LIB_BUFFER & getLibraryBuffer(const wxString &aLibrary)
Return an existing library buffer or creates one to using Symbol Library Table to get the original da...
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References _, SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::CreateBuffer(), Format(), SYMBOL_LIBRARY_MANAGER::getLibraryBuffer(), LIB_SYMBOL::GetName(), LIB_SYMBOL::GetParent(), SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetSymbol(), LIB_SYMBOL::IsAlias(), SYMBOL_LIBRARY_MANAGER::LibraryExists(), SYMBOL_LIB_TABLE::LoadSymbol(), LIB_SYMBOL::SetParent(), SYMBOL_LIBRARY_MANAGER::symTable(), THROW_IO_ERROR, and IO_ERROR::What().

Referenced by SYMBOL_EDIT_FRAME::CopySymbolToClipboard(), SYMBOL_EDIT_FRAME::DuplicateSymbol(), SYMBOL_EDIT_FRAME::IsCurrentSymbol(), SYMBOL_EDIT_FRAME::LoadOneLibrarySymbolAux(), SYMBOL_EDIT_FRAME::LoadSymbol(), and SYMBOL_EDITOR_CONTROL::RenameSymbol().

◆ GetHash()

int SYMBOL_LIBRARY_MANAGER::GetHash ( ) const
inherited

Definition at line 106 of file symbol_library_manager.cpp.

107{
108 int hash = symTable()->GetModifyHash();
109
110 for( const std::pair<const wxString, LIB_BUFFER>& lib : m_libs )
111 hash += lib.second.GetHash();
112
113 return hash;
114}

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

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

◆ GetLibrary()

SYMBOL_LIB_TABLE_ROW * SYMBOL_LIBRARY_MANAGER::GetLibrary ( const wxString &  aLibrary) const
inherited

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

Definition at line 149 of file symbol_library_manager.cpp.

150{
151 SYMBOL_LIB_TABLE_ROW* row = nullptr;
152
153 try
154 {
155 row = symTable()->FindRow( aLibrary, true );
156 }
157 catch( const IO_ERROR& e )
158 {
159 wxLogMessage( _( "Library '%s' not found in the Symbol Library Table." ) + e.What(),
160 aLibrary );
161 }
162
163 return row;
164}
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...

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

Referenced by SCH_EDITOR_CONTROL::ExportSymbolsToLibrary(), SYMBOL_LIBRARY_MANAGER::GetLibraryHash(), SYMBOL_LIBRARY_MANAGER::GetLibraryNames(), SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetValue(), SYMBOL_EDIT_FRAME::IsSymbolFromLegacyLibrary(), SYMBOL_EDIT_FRAME::LoadSymbol(), SYMBOL_LIBRARY_MANAGER::SaveLibrary(), and SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync().

◆ getLibraryBuffer()

SYMBOL_LIBRARY_MANAGER::LIB_BUFFER & SYMBOL_LIBRARY_MANAGER::getLibraryBuffer ( const wxString &  aLibrary)
protectedinherited

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

The library buffers

Definition at line 788 of file symbol_library_manager.cpp.

790{
791 auto it = m_libs.find( aLibrary );
792
793 if( it != m_libs.end() )
794 return it->second;
795
796 // The requested buffer does not exist yet, so create one
797 auto ret = m_libs.emplace( aLibrary, LIB_BUFFER( aLibrary ) );
798 LIB_BUFFER& buf = ret.first->second;
799
800 for( auto symbol : getOriginalSymbols( aLibrary ) )
801 {
802 LIB_SYMBOL* newSymbol;
803
804 if( symbol->IsAlias() )
805 {
806 std::shared_ptr< LIB_SYMBOL > oldParent = symbol->GetParent().lock();
807
808 wxCHECK_MSG( oldParent, buf,
809 wxString::Format( "Derived symbol '%s' found with undefined parent.",
810 symbol->GetName() ) );
811
812 LIB_SYMBOL* libParent = buf.GetSymbol( oldParent->GetName() );
813
814 if( !libParent )
815 {
816 libParent = new LIB_SYMBOL( *oldParent.get() );
817 buf.CreateBuffer( libParent, new SCH_SCREEN );
818 }
819
820 newSymbol = new LIB_SYMBOL( *symbol );
821 newSymbol->SetParent( libParent );
822 buf.CreateBuffer( newSymbol, new SCH_SCREEN );
823 }
824 else if( !buf.GetSymbol( symbol->GetName() ) )
825 {
826 buf.CreateBuffer( new LIB_SYMBOL( *symbol ), new SCH_SCREEN );
827 }
828 }
829
830 return buf;
831}
std::set< LIB_SYMBOL * > getOriginalSymbols(const wxString &aLibrary)
Return a set of LIB_SYMBOL objects belonging to the original library.

References SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::CreateBuffer(), Format(), SYMBOL_LIBRARY_MANAGER::getOriginalSymbols(), LIB_SYMBOL::GetParent(), SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetSymbol(), SYMBOL_LIBRARY_MANAGER::m_libs, and LIB_SYMBOL::SetParent().

Referenced by SYMBOL_LIBRARY_MANAGER::GetBufferedSymbol(), SYMBOL_LIBRARY_MANAGER::GetRootSymbolNames(), SYMBOL_LIBRARY_MANAGER::HasDerivedSymbols(), SYMBOL_LIBRARY_MANAGER::RemoveSymbol(), SYMBOL_LIBRARY_MANAGER::UpdateSymbol(), and SYMBOL_LIBRARY_MANAGER::UpdateSymbolAfterRename().

◆ GetLibraryCount()

size_t SYMBOL_LIBRARY_MANAGER::GetLibraryCount ( ) const
inherited

Definition at line 708 of file symbol_library_manager.cpp.

709{
710 return symTable()->GetLogicalLibs().size();
711}
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.

References LIB_TABLE::GetLogicalLibs(), and SYMBOL_LIBRARY_MANAGER::symTable().

◆ GetLibraryHash()

int SYMBOL_LIBRARY_MANAGER::GetLibraryHash ( const wxString &  aLibrary) const
inherited

Return 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 117 of file symbol_library_manager.cpp.

118{
119 const auto libBufIt = m_libs.find( aLibrary );
120
121 if( libBufIt != m_libs.end() )
122 return libBufIt->second.GetHash();
123
124 SYMBOL_LIB_TABLE_ROW* row = GetLibrary( aLibrary );
125
126 // return -1 if library does not exist or 0 if not modified
127 return row ? std::hash<std::string>{}( aLibrary.ToStdString() +
128 row->GetFullURI( true ).ToStdString() ) : -1;
129}
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
SYMBOL_LIB_TABLE_ROW * GetLibrary(const wxString &aLibrary) const
Find a single library within the (aggregate) library table.

References LIB_TABLE_ROW::GetFullURI(), SYMBOL_LIBRARY_MANAGER::GetLibrary(), and SYMBOL_LIBRARY_MANAGER::m_libs.

Referenced by SYMBOL_TREE_SYNCHRONIZING_ADAPTER::updateLibrary().

◆ getLibraryName()

wxString SYMBOL_LIBRARY_MANAGER::getLibraryName ( const wxString &  aFilePath)
staticprotectedinherited

Helper function to add either existing or create new library.

Definition at line 714 of file symbol_library_manager.cpp.

715{
716 wxFileName fn( aFilePath );
717 return fn.GetName();
718}

Referenced by SYMBOL_LIBRARY_MANAGER::addLibrary().

◆ GetLibraryNames()

wxArrayString SYMBOL_LIBRARY_MANAGER::GetLibraryNames ( ) const
inherited

Return the array of library names.

Definition at line 132 of file symbol_library_manager.cpp.

133{
134 wxArrayString res;
135
136 for( const wxString& libName : symTable()->GetLogicalLibs() )
137 {
138 // Database libraries are hidden from the symbol editor at the moment
139 if( GetLibrary( libName )->SchLibType() == SCH_IO_MGR::SCH_DATABASE )
140 continue;
141
142 res.Add( libName );
143 }
144
145 return res;
146}
VECTOR3I res

References SYMBOL_LIBRARY_MANAGER::GetLibrary(), res, and SYMBOL_LIBRARY_MANAGER::symTable().

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

◆ getOriginalSymbols()

std::set< LIB_SYMBOL * > SYMBOL_LIBRARY_MANAGER::getOriginalSymbols ( const wxString &  aLibrary)
protectedinherited

Return a set of LIB_SYMBOL objects belonging to the original library.

Definition at line 763 of file symbol_library_manager.cpp.

764{
765 std::set<LIB_SYMBOL*> symbols;
766 wxCHECK( LibraryExists( aLibrary ), symbols );
767
768 try
769 {
770 wxArrayString aliases;
771 symTable()->EnumerateSymbolLib( aLibrary, aliases );
772
773 for( const auto& aliasName : aliases )
774 {
775 LIB_SYMBOL* alias = symTable()->LoadSymbol( aLibrary, aliasName );
776 symbols.insert( alias );
777 }
778 }
779 catch( const IO_ERROR& e )
780 {
781 wxLogMessage( _( "Cannot enumerate library '%s'." ) + e.What(), aLibrary );
782 }
783
784 return symbols;
785}
void EnumerateSymbolLib(const wxString &aNickname, wxArrayString &aAliasNames, bool aPowerSymbolsOnly=false)
Return a list of symbol alias names contained within the library given by aNickname.

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

Referenced by SYMBOL_LIBRARY_MANAGER::getLibraryBuffer(), and SYMBOL_LIBRARY_MANAGER::SaveLibrary().

◆ GetRootSymbolNames()

void SYMBOL_LIBRARY_MANAGER::GetRootSymbolNames ( const wxString &  aLibName,
wxArrayString &  aRootSymbolNames 
)
inherited

Definition at line 690 of file symbol_library_manager.cpp.

692{
693 LIB_BUFFER& libBuf = getLibraryBuffer( aLibraryName );
694
695 libBuf.GetRootSymbolNames( aRootSymbolNames );
696}

References SYMBOL_LIBRARY_MANAGER::getLibraryBuffer(), and SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetRootSymbolNames().

Referenced by SYMBOL_EDIT_FRAME::CreateNewSymbol(), and DIALOG_LIB_SYMBOL_PROPERTIES::TransferDataToWindow().

◆ GetScreen()

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

Return the screen used to edit a specific symbol.

SYMBOL_LIBRARY_MANAGER retains the ownership.

Definition at line 451 of file symbol_library_manager.cpp.

452{
453 wxCHECK( LibraryExists( aLibrary ), nullptr );
454 wxCHECK( !aAlias.IsEmpty(), nullptr );
455 auto it = m_libs.find( aLibrary );
456 wxCHECK( it != m_libs.end(), nullptr );
457
458 LIB_BUFFER& buf = it->second;
459 auto symbolBuf = buf.GetBuffer( aAlias );
460 return symbolBuf ? symbolBuf->GetScreen() : nullptr;
461}

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

Referenced by SYMBOL_EDIT_FRAME::LoadOneLibrarySymbolAux().

◆ GetUniqueLibraryName()

wxString SYMBOL_LIBRARY_MANAGER::GetUniqueLibraryName ( ) const
inherited

Return a library name that is not currently in use.

Used for generating names for new libraries.

Definition at line 670 of file symbol_library_manager.cpp.

671{
672 wxString name = "New_Library";
673
674 if( !LibraryExists( name ) )
675 return name;
676
677 name += "_";
678
679 for( unsigned int i = 0; i < std::numeric_limits<unsigned int>::max(); ++i )
680 {
681 if( !LibraryExists( name + wxString::Format( "%u", i ) ) )
682 return name + wxString::Format( "%u", i );
683 }
684
685 wxFAIL;
686 return wxEmptyString;
687}
const char * name
Definition: DXF_plotter.cpp:56

References Format(), SYMBOL_LIBRARY_MANAGER::LibraryExists(), and name.

Referenced by SYMBOL_EDIT_FRAME::AddLibraryFile().

◆ HasDerivedSymbols()

bool SYMBOL_LIBRARY_MANAGER::HasDerivedSymbols ( const wxString &  aSymbolName,
const wxString &  aLibraryName 
)
inherited

Check if symbol aSymbolName in library aLibraryName is a root symbol that has derived symbols.

Returns
true if \aSymbolName in aLibraryName has derived symbols.

Definition at line 699 of file symbol_library_manager.cpp.

701{
702 LIB_BUFFER& libBuf = getLibraryBuffer( aLibraryName );
703
704 return libBuf.HasDerivedSymbols( aSymbolName );
705}

References SYMBOL_LIBRARY_MANAGER::getLibraryBuffer(), and SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::HasDerivedSymbols().

Referenced by SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::DeleteBuffer(), and SYMBOL_EDIT_FRAME::DeleteSymbolFromLibrary().

◆ HasModifications()

bool SYMBOL_LIBRARY_MANAGER::HasModifications ( ) const
inherited

Definition at line 94 of file symbol_library_manager.cpp.

95{
96 for( const std::pair<const wxString, LIB_BUFFER>& lib : m_libs )
97 {
98 if( lib.second.IsModified() )
99 return true;
100 }
101
102 return false;
103}

References SYMBOL_LIBRARY_MANAGER::m_libs.

Referenced by SYMBOL_EDIT_FRAME::HasLibModifications().

◆ IsLibraryLoaded()

bool SYMBOL_LIBRARY_MANAGER::IsLibraryLoaded ( const wxString &  aLibrary) const
inherited

Return true if the library was successfully loaded.

Definition at line 351 of file symbol_library_manager.cpp.

352{
353 wxCHECK( LibraryExists( aLibrary ), false );
354
355 return symTable()->IsSymbolLibLoaded( aLibrary );
356}
bool IsSymbolLibLoaded(const wxString &aNickname)
Return true if the library given by aNickname was successfully loaded.

References SYMBOL_LIB_TABLE::IsSymbolLibLoaded(), SYMBOL_LIBRARY_MANAGER::LibraryExists(), and SYMBOL_LIBRARY_MANAGER::symTable().

Referenced by SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr(), and SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetValue().

◆ IsLibraryModified()

bool SYMBOL_LIBRARY_MANAGER::IsLibraryModified ( const wxString &  aLibrary) const
inherited

Return true if library has unsaved modifications.

Definition at line 270 of file symbol_library_manager.cpp.

271{
272 auto it = m_libs.find( aLibrary );
273 return it != m_libs.end() ? it->second.IsModified() : false;
274}

References SYMBOL_LIBRARY_MANAGER::m_libs.

Referenced by SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr(), SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetValue(), SYMBOL_EDIT_FRAME::IsContentModified(), and SYMBOL_EDIT_FRAME::saveAllLibraries().

◆ IsLibraryReadOnly()

bool SYMBOL_LIBRARY_MANAGER::IsLibraryReadOnly ( const wxString &  aLibrary) const
inherited

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

Returns
True on success, false otherwise.

Definition at line 343 of file symbol_library_manager.cpp.

344{
345 wxCHECK( LibraryExists( aLibrary ), true );
346
347 return !symTable()->IsSymbolLibWritable( aLibrary );
348}
bool IsSymbolLibWritable(const wxString &aNickname)
Return true if the library given by aNickname is writable.

References SYMBOL_LIB_TABLE::IsSymbolLibWritable(), SYMBOL_LIBRARY_MANAGER::LibraryExists(), and SYMBOL_LIBRARY_MANAGER::symTable().

Referenced by SYMBOL_EDITOR_CONTROL::AddSymbol(), SYMBOL_EDITOR_CONTROL::CutCopyDelete(), SYMBOL_EDITOR_CONTROL::DuplicateSymbol(), SYMBOL_EDIT_FRAME::IsContentModified(), SYMBOL_EDIT_FRAME::Save(), SYMBOL_EDIT_FRAME::saveAllLibraries(), SYMBOL_EDIT_FRAME::saveLibrary(), and SYMBOL_EDIT_FRAME::updateTitle().

◆ IsSymbolModified()

bool SYMBOL_LIBRARY_MANAGER::IsSymbolModified ( const wxString &  aAlias,
const wxString &  aLibrary 
) const
inherited

Return true if symbol has unsaved modifications.

Definition at line 277 of file symbol_library_manager.cpp.

279{
280 auto libIt = m_libs.find( aLibrary );
281
282 if( libIt == m_libs.end() )
283 return false;
284
285 const LIB_BUFFER& buf = libIt->second;
286 const std::shared_ptr<SYMBOL_LIBRARY_MANAGER::SYMBOL_BUFFER> symbolBuf = buf.GetBuffer( aAlias );
287 return symbolBuf ? symbolBuf->IsModified() : false;
288}

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

Referenced by SYMBOL_EDIT_FRAME::DeleteSymbolFromLibrary(), SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr(), SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetValue(), and SYMBOL_EDIT_FRAME::setupUIConditions().

◆ LibraryExists()

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

◆ OnDataChanged()

void LIB_SYMBOL_LIBRARY_MANAGER::OnDataChanged ( ) const
overrideprotectedvirtual

Extract library name basing on the file name.

Reimplemented from SYMBOL_LIBRARY_MANAGER.

Definition at line 47 of file lib_symbol_library_manager.cpp.

48{
49 static_cast<SYMBOL_EDIT_FRAME&>( m_frame ).SyncLibraries( false );
50}
The symbol library editor main window.

References SYMBOL_LIBRARY_MANAGER::m_frame.

◆ Preload()

void SYMBOL_LIBRARY_MANAGER::Preload ( PROGRESS_REPORTER aReporter)
inherited

Preloads all symbol libraries in the symbol library table using SYMBOL_ASYNC_LOADER.

Call before the first call to Sync() to get better performance.

Parameters
aReporteris used to report progress of the load

Definition at line 60 of file symbol_library_manager.cpp.

61{
62 SYMBOL_ASYNC_LOADER loader( symTable()->GetLogicalLibs(), symTable(), false, nullptr,
63 &aReporter );
64
65 LOCALE_IO toggle;
66
67 loader.Start();
68
69 while( !loader.Done() )
70 {
71 if( !aReporter.KeepRefreshing() )
72 break;
73
74 wxMilliSleep( 33 /* 30 FPS refresh rate */ );
75 }
76
77 loader.Join();
78
79 if( !loader.GetErrors().IsEmpty() )
80 {
81 HTML_MESSAGE_BOX dlg( &m_frame, _( "Load Error" ) );
82
83 dlg.MessageSet( _( "Errors loading symbols:" ) );
84
85 wxString msg = loader.GetErrors();
86 msg.Replace( "\n", "<BR>" );
87
88 dlg.AddHTML_Text( msg );
89 dlg.ShowModal();
90 }
91}
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:41
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).

References _, HTML_MESSAGE_BOX::AddHTML_Text(), SYMBOL_ASYNC_LOADER::Done(), SYMBOL_ASYNC_LOADER::GetErrors(), SYMBOL_ASYNC_LOADER::Join(), PROGRESS_REPORTER::KeepRefreshing(), SYMBOL_LIBRARY_MANAGER::m_frame, HTML_MESSAGE_BOX::MessageSet(), SYMBOL_ASYNC_LOADER::Start(), and SYMBOL_LIBRARY_MANAGER::symTable().

◆ RemoveSymbol()

bool SYMBOL_LIBRARY_MANAGER::RemoveSymbol ( const wxString &  aName,
const wxString &  aLibrary 
)
inherited

Remove the symbol from the symbol buffer.

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

Definition at line 590 of file symbol_library_manager.cpp.

591{
592 LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary );
593 auto symbolBuf = libBuf.GetBuffer( aAlias );
594 wxCHECK( symbolBuf, false );
595
596 bool retv = true;
597
598 retv &= libBuf.DeleteBuffer( symbolBuf );
600
601 return retv;
602}

References SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::DeleteBuffer(), SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetBuffer(), SYMBOL_LIBRARY_MANAGER::getLibraryBuffer(), and SYMBOL_LIBRARY_MANAGER::OnDataChanged().

Referenced by SYMBOL_EDIT_FRAME::DeleteSymbolFromLibrary().

◆ RevertAll()

bool SYMBOL_LIBRARY_MANAGER::RevertAll ( )
inherited

Revert all pending changes.

Returns
True if all changes successfully reverted.

Definition at line 564 of file symbol_library_manager.cpp.

565{
566 bool retv = true;
567
568 // Nothing to revert.
569 if( GetHash() == 0 )
570 return true;
571
572 for( const auto& lib : m_libs )
573 {
574 if( !lib.second.IsModified() )
575 continue;
576
577 for( const auto& buffer : lib.second.GetBuffers() )
578 {
579 if( !buffer->IsModified() )
580 continue;
581
582 RevertSymbol( lib.first, buffer->GetOriginal()->GetName() );
583 }
584 }
585
586 return retv;
587}
LIB_ID RevertSymbol(const wxString &aAlias, const wxString &aLibrary)
Revert unsaved changes for a symbolicular symbol.

References SYMBOL_LIBRARY_MANAGER::GetHash(), SYMBOL_LIBRARY_MANAGER::m_libs, and SYMBOL_LIBRARY_MANAGER::RevertSymbol().

Referenced by SYMBOL_EDIT_FRAME::RevertAll().

◆ RevertLibrary()

bool SYMBOL_LIBRARY_MANAGER::RevertLibrary ( const wxString &  aLibrary)
inherited

Revert unsaved changes for a symbolicular library.

Returns
True on success, false otherwise.

Definition at line 550 of file symbol_library_manager.cpp.

551{
552 auto it = m_libs.find( aLibrary );
553
554 if( it == m_libs.end() ) // nothing to reverse
555 return false;
556
557 m_libs.erase( it );
559
560 return true;
561}

References SYMBOL_LIBRARY_MANAGER::m_libs, and SYMBOL_LIBRARY_MANAGER::OnDataChanged().

Referenced by SYMBOL_EDIT_FRAME::Revert().

◆ RevertSymbol()

LIB_ID SYMBOL_LIBRARY_MANAGER::RevertSymbol ( const wxString &  aAlias,
const wxString &  aLibrary 
)
inherited

Revert unsaved changes for a symbolicular symbol.

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

Definition at line 524 of file symbol_library_manager.cpp.

525{
526 auto it = m_libs.find( aLibrary );
527
528 if( it == m_libs.end() ) // no items to flush
529 return LIB_ID( aLibrary, aAlias );
530
531 auto symbolBuf = it->second.GetBuffer( aAlias );
532 wxCHECK( symbolBuf, LIB_ID( aLibrary, aAlias ) );
533 LIB_SYMBOL original( *symbolBuf->GetOriginal() );
534
535 if( original.GetName() != aAlias )
536 {
537 UpdateSymbolAfterRename( &original, aAlias, aLibrary );
538 }
539 else
540 {
541 // copy the initial data to the current symbol to restore
542 *symbolBuf->GetSymbol() = original;
544 }
545
546 return LIB_ID( aLibrary, original.GetName() );
547}
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
bool UpdateSymbolAfterRename(LIB_SYMBOL *aSymbol, const wxString &oldAlias, const wxString &aLibrary)
Update the symbol buffer with a new version of the symbol when the name has changed.

References LIB_SYMBOL::GetName(), SYMBOL_LIBRARY_MANAGER::m_libs, SYMBOL_LIBRARY_MANAGER::OnDataChanged(), and SYMBOL_LIBRARY_MANAGER::UpdateSymbolAfterRename().

Referenced by SYMBOL_EDIT_FRAME::Revert(), and SYMBOL_LIBRARY_MANAGER::RevertAll().

◆ SaveLibrary()

bool SYMBOL_LIBRARY_MANAGER::SaveLibrary ( const wxString &  aLibrary,
const wxString &  aFileName,
SCH_IO_MGR::SCH_FILE_T  aFileType = SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY 
)
inherited

Save 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 167 of file symbol_library_manager.cpp.

169{
170 wxCHECK( aFileType != SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY && LibraryExists( aLibrary ), false );
171 wxFileName fn( aFileName );
172 wxCHECK( !fn.FileExists() || fn.IsFileWritable(), false );
173 SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( aFileType ) );
174 bool res = true; // assume all libraries are successfully saved
175
176 STRING_UTF8_MAP properties;
177 properties.emplace( SCH_LEGACY_PLUGIN::PropBuffering, "" );
178
179 auto it = m_libs.find( aLibrary );
180
181 if( it != m_libs.end() )
182 {
183 // Handle buffered library
184 LIB_BUFFER& libBuf = it->second;
185
186 const auto& symbolBuffers = libBuf.GetBuffers();
187
188 for( const auto& symbolBuf : symbolBuffers )
189 {
190 if( !libBuf.SaveBuffer( symbolBuf, aFileName, &*pi, true ) )
191 {
192 // Something went wrong, but try to save other libraries
193 res = false;
194 }
195 }
196
197 // clear the deleted symbols buffer only if data is saved to the original file
198 wxFileName original, destination( aFileName );
199 SYMBOL_LIB_TABLE_ROW* row = GetLibrary( aLibrary );
200
201 if( row )
202 {
203 original = row->GetFullURI();
204 original.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
205 }
206
207 destination.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
208
209 if( res && original == destination )
210 libBuf.ClearDeletedBuffer();
211 }
212 else
213 {
214 // Handle original library
215 for( LIB_SYMBOL* symbol : getOriginalSymbols( aLibrary ) )
216 {
217 LIB_SYMBOL* newSymbol;
218
219 try
220 {
221 if( symbol->IsAlias() )
222 {
223 std::shared_ptr< LIB_SYMBOL > oldParent = symbol->GetParent().lock();
224
225 wxCHECK_MSG( oldParent, false,
226 wxString::Format( wxT( "Derived symbol '%s' found with undefined parent." ),
227 symbol->GetName() ) );
228
229 LIB_SYMBOL* libParent = pi->LoadSymbol( aLibrary, oldParent->GetName(),
230 &properties );
231
232 if( !libParent )
233 {
234 libParent = new LIB_SYMBOL( *oldParent.get() );
235 pi->SaveSymbol( aLibrary, libParent, &properties );
236 }
237
238 newSymbol = new LIB_SYMBOL( *symbol );
239 newSymbol->SetParent( libParent );
240 pi->SaveSymbol( aLibrary, newSymbol, &properties );
241 }
242 else if( !pi->LoadSymbol( aLibrary, symbol->GetName(), &properties ) )
243 {
244 pi->SaveSymbol( aLibrary, new LIB_SYMBOL( *symbol ), &properties );
245 }
246 }
247 catch( ... )
248 {
249 res = false;
250 break;
251 }
252 }
253 }
254
255 try
256 {
257 pi->SaveLibrary( aFileName );
258 }
259 catch( ... )
260 {
261 // return false because something happens.
262 // The library is not successfully saved
263 res = false;
264 }
265
266 return res;
267}
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:535
A name/value tuple with unique names and optional values.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().
Definition: wx_filename.h:38

References SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::ClearDeletedBuffer(), FN_NORMALIZE_FLAGS, Format(), SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetBuffers(), LIB_TABLE_ROW::GetFullURI(), SYMBOL_LIBRARY_MANAGER::GetLibrary(), SYMBOL_LIBRARY_MANAGER::getOriginalSymbols(), LIB_SYMBOL::GetParent(), SYMBOL_LIBRARY_MANAGER::LibraryExists(), SCH_PLUGIN::LoadSymbol(), SYMBOL_LIBRARY_MANAGER::m_libs, SCH_LEGACY_PLUGIN::PropBuffering, res, SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer(), SCH_PLUGIN::SaveLibrary(), SCH_PLUGIN::SaveSymbol(), and LIB_SYMBOL::SetParent().

Referenced by SYMBOL_EDIT_FRAME::saveLibrary().

◆ SetSymbolModified()

void SYMBOL_LIBRARY_MANAGER::SetSymbolModified ( const wxString &  aAlias,
const wxString &  aLibrary 
)
inherited

Definition at line 291 of file symbol_library_manager.cpp.

293{
294 auto libIt = m_libs.find( aLibrary );
295
296 if( libIt == m_libs.end() )
297 return;
298
299 const LIB_BUFFER& buf = libIt->second;
300 std::shared_ptr<SYMBOL_LIBRARY_MANAGER::SYMBOL_BUFFER> symbolBuf = buf.GetBuffer( aAlias );
301
302 wxCHECK( symbolBuf, /* void */ );
303
304 symbolBuf->GetScreen()->SetContentModified();
305}

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

Referenced by SYMBOL_EDITOR_CONTROL::RenameSymbol().

◆ SymbolExists()

bool SYMBOL_LIBRARY_MANAGER::SymbolExists ( const wxString &  aAlias,
const wxString &  aLibrary 
) const
inherited

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

Definition at line 637 of file symbol_library_manager.cpp.

638{
639 auto libBufIt = m_libs.find( aLibrary );
640 LIB_SYMBOL* alias = nullptr;
641
642 if( libBufIt != m_libs.end() )
643 return !!libBufIt->second.GetBuffer( aAlias );
644
645 try
646 {
647 alias = symTable()->LoadSymbol( aLibrary, aAlias );
648 }
649 catch( IO_ERROR& )
650 {
651 // checking if certain symbol exists, so its absence is perfectly fine
652 }
653
654 return alias != nullptr;
655}

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

Referenced by SYMBOL_EDIT_FRAME::CreateNewSymbol(), SYMBOL_EDIT_FRAME::ensureUniqueName(), SYMBOL_EDIT_FRAME::ImportSymbol(), SYMBOL_EDITOR_CONTROL::RenameSymbol(), SYMBOL_EDIT_FRAME::Revert(), SYMBOL_EDIT_FRAME::saveSymbolAs(), DIALOG_LIB_SYMBOL_PROPERTIES::TransferDataFromWindow(), and SYMBOL_EDIT_FRAME::UpdateAfterSymbolProperties().

◆ symTable()

◆ Sync()

void LIB_SYMBOL_LIBRARY_MANAGER::Sync ( const wxString &  aForceRefresh,
std::function< void(int, int, const wxString &)>  aProgressCallback 
)

Updates the SYMBOL_LIBRARY_MANAGER data to synchronize with Symbol Library Table.

Definition at line 34 of file lib_symbol_library_manager.cpp.

37{
39 {
40 getAdapter()->Sync( aForceRefresh, aProgressCallback );
42 }
44}
void Deactivate()
Definition: lib_logger.cpp:49
void Activate()
Definition: lib_logger.cpp:39
SYMBOL_TREE_SYNCHRONIZING_ADAPTER * getAdapter()
void Sync(const wxString &aForceRefresh, std::function< void(int, int, const wxString &)> aProgressCallback)

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

Referenced by SYMBOL_EDIT_FRAME::SyncLibraries().

◆ UpdateSymbol()

bool SYMBOL_LIBRARY_MANAGER::UpdateSymbol ( LIB_SYMBOL aSymbol,
const wxString &  aLibrary 
)
inherited

Update the symbol buffer with a new version of the symbol.

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

Definition at line 464 of file symbol_library_manager.cpp.

465{
466 wxCHECK( LibraryExists( aLibrary ), false );
467 wxCHECK( aSymbol, false );
468 LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary );
469 auto symbolBuf = libBuf.GetBuffer( aSymbol->GetName() );
470
471 if( symbolBuf ) // Existing symbol.
472 {
473 LIB_SYMBOL* bufferedSymbol = const_cast< LIB_SYMBOL* >( symbolBuf->GetSymbol() );
474
475 wxCHECK( bufferedSymbol, false );
476
477 *bufferedSymbol = *aSymbol;
478 symbolBuf->GetScreen()->SetContentModified();
479 }
480 else // New symbol
481 {
482 LIB_SYMBOL* symbolCopy = new LIB_SYMBOL( *aSymbol, nullptr );
483
484 symbolCopy->SetLibId( LIB_ID( aLibrary, aSymbol->GetLibId().GetLibItemName() ) );
485
486 SCH_SCREEN* screen = new SCH_SCREEN;
487 libBuf.CreateBuffer( symbolCopy, screen );
488 screen->SetContentModified();
489 }
490
491 return true;
492}
const UTF8 & GetLibItemName() const
Definition: lib_id.h:102
LIB_ID GetLibId() const override
Definition: lib_symbol.h:141
void SetLibId(const LIB_ID &aLibId)
Definition: lib_symbol.h:142

References SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::CreateBuffer(), SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetBuffer(), LIB_SYMBOL::GetLibId(), LIB_ID::GetLibItemName(), SYMBOL_LIBRARY_MANAGER::getLibraryBuffer(), LIB_SYMBOL::GetName(), SYMBOL_LIBRARY_MANAGER::LibraryExists(), BASE_SCREEN::SetContentModified(), and LIB_SYMBOL::SetLibId().

Referenced by SYMBOL_EDIT_FRAME::CreateNewSymbol(), SYMBOL_EDIT_FRAME::DuplicateSymbol(), SYMBOL_EDIT_FRAME::ImportSymbol(), SYMBOL_EDIT_FRAME::saveSymbolAs(), and SYMBOL_EDIT_FRAME::storeCurrentSymbol().

◆ UpdateSymbolAfterRename()

bool SYMBOL_LIBRARY_MANAGER::UpdateSymbolAfterRename ( LIB_SYMBOL aSymbol,
const wxString &  oldAlias,
const wxString &  aLibrary 
)
inherited

Update the symbol buffer with a new version of the symbol when the name has changed.

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

Definition at line 495 of file symbol_library_manager.cpp.

497{
498 LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary );
499 auto symbolBuf = libBuf.GetBuffer( aOldName );
500
501 wxCHECK( symbolBuf, false );
502
503 libBuf.UpdateBuffer( symbolBuf, aSymbol );
505
506 return true;
507}

References SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetBuffer(), SYMBOL_LIBRARY_MANAGER::getLibraryBuffer(), SYMBOL_LIBRARY_MANAGER::OnDataChanged(), and SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::UpdateBuffer().

Referenced by SYMBOL_EDIT_FRAME::GetSymbolFromRedoList(), SYMBOL_EDIT_FRAME::GetSymbolFromUndoList(), SYMBOL_EDITOR_CONTROL::RenameSymbol(), SYMBOL_LIBRARY_MANAGER::RevertSymbol(), and SYMBOL_EDIT_FRAME::UpdateAfterSymbolProperties().

Member Data Documentation

◆ m_adapter

wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> LIB_SYMBOL_LIBRARY_MANAGER::m_adapter
private

Definition at line 57 of file lib_symbol_library_manager.h.

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

◆ m_frame

SCH_BASE_FRAME& SYMBOL_LIBRARY_MANAGER::m_frame
protectedinherited

◆ m_libs

◆ m_logger

LIB_LOGGER* SYMBOL_LIBRARY_MANAGER::m_logger
protectedinherited

◆ m_syncHash

int LIB_SYMBOL_LIBRARY_MANAGER::m_syncHash
private

Symbol lib table hash value from last synchronization.

Definition at line 59 of file lib_symbol_library_manager.h.

Referenced by Sync().


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