KiCad PCB EDA Suite
SYMBOL_LIBRARY_MANAGER Class Reference

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

#include <symbol_library_manager.h>

Inheritance diagram for SYMBOL_LIBRARY_MANAGER:
LIB_SYMBOL_LIBRARY_MANAGER

Classes

class  LIB_BUFFER
 
class  SYMBOL_BUFFER
 Store a working copy of a library. More...
 

Public Member Functions

 SYMBOL_LIBRARY_MANAGER (SCH_BASE_FRAME &aFrame)
 
virtual ~SYMBOL_LIBRARY_MANAGER ()
 
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

virtual void OnDataChanged () const
 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
 

Detailed Description

Class to handle modifications to the symbol libraries.

Definition at line 52 of file symbol_library_manager.h.

Constructor & Destructor Documentation

◆ SYMBOL_LIBRARY_MANAGER()

SYMBOL_LIBRARY_MANAGER::SYMBOL_LIBRARY_MANAGER ( SCH_BASE_FRAME aFrame)

Definition at line 47 of file symbol_library_manager.cpp.

47 :
48 m_frame( aFrame )
49{
50 m_logger = new LIB_LOGGER();
51}
SCH_BASE_FRAME & m_frame
Parent frame.

References m_logger.

◆ ~SYMBOL_LIBRARY_MANAGER()

SYMBOL_LIBRARY_MANAGER::~SYMBOL_LIBRARY_MANAGER ( )
virtual

Definition at line 54 of file symbol_library_manager.cpp.

55{
56 delete m_logger;
57}

References m_logger.

Member Function Documentation

◆ addLibrary()

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

Return the current Symbol Library Table.

Definition at line 715 of file symbol_library_manager.cpp.

717{
718 wxCHECK( aTable, false );
719 wxString libName = getLibraryName( aFilePath );
720 wxCHECK( !LibraryExists( libName ), false ); // either create or add an existing one
721
722 // try to use path normalized to an environmental variable or project path
723 wxString relPath = NormalizePath( aFilePath, &Pgm().GetLocalEnvVariables(), &m_frame.Prj() );
724
725 SCH_IO_MGR::SCH_FILE_T schFileType = SCH_IO_MGR::GuessPluginTypeFromLibPath( aFilePath );
726 wxString typeName = SCH_IO_MGR::ShowType( schFileType );
727 SYMBOL_LIB_TABLE_ROW* libRow = new SYMBOL_LIB_TABLE_ROW( libName, relPath, typeName );
728 aTable->InsertRow( libRow );
729
730 if( aCreate )
731 {
732 wxCHECK( schFileType != SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY, false );
733
734 try
735 {
736 aTable->CreateSymbolLib( libName );
737 }
738 catch( const IO_ERROR& )
739 {
740 aTable->RemoveRow( libRow );
741 return false;
742 }
743 }
744
746
747 return true;
748}
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.
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(), getLibraryName(), SCH_IO_MGR::GuessPluginTypeFromLibPath(), LIB_TABLE::InsertRow(), LibraryExists(), m_frame, NormalizePath(), OnDataChanged(), Pgm(), KIWAY_HOLDER::Prj(), LIB_TABLE::RemoveRow(), and SCH_IO_MGR::ShowType().

Referenced by AddLibrary(), and CreateLibrary().

◆ AddLibrary()

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

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

Clear the modified flag for all symbols in a library.

Definition at line 302 of file symbol_library_manager.cpp.

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

References 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

Clear the modified flag for a symbol.

Definition at line 321 of file symbol_library_manager.cpp.

323{
324 auto libI = m_libs.find( aLibrary );
325
326 if( libI == m_libs.end() )
327 return false;
328
329 auto symbolBuf = libI->second.GetBuffer( aAlias );
330 wxCHECK( symbolBuf, false );
331
332 symbolBuf->GetScreen()->SetContentModified( false );
333 return true;
334}

References 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 
)
inline

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 addLibrary().

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

◆ FlushSymbol()

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

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

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

References m_libs, and symTable().

Referenced by SYMBOL_EDIT_FRAME::saveCurrentSymbol().

◆ GetAlias()

LIB_SYMBOL * SYMBOL_LIBRARY_MANAGER::GetAlias ( 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.

Definition at line 599 of file symbol_library_manager.cpp.

601{
602 // Try the library buffers first
603 auto libIt = m_libs.find( aLibrary );
604
605 if( libIt != m_libs.end() )
606 {
607 LIB_SYMBOL* symbol = libIt->second.GetSymbol( aAlias );
608
609 if( symbol )
610 return symbol;
611 }
612
613 // Get the original symbol
614 LIB_SYMBOL* alias = nullptr;
615
616 try
617 {
618 alias = symTable()->LoadSymbol( aLibrary, aAlias );
619 }
620 catch( const IO_ERROR& e )
621 {
622 wxLogMessage( _( "Cannot load symbol '%s' from library '%s'." ) + e.What(),
623 aAlias,
624 aLibrary );
625 }
626
627 return alias;
628}
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
Define a library symbol object.
Definition: lib_symbol.h:98
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(), m_libs, 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

Definition at line 353 of file symbol_library_manager.cpp.

354{
355 std::list<LIB_SYMBOL*> ret;
356 wxCHECK( LibraryExists( aLibrary ), ret );
357
358 auto libIt = m_libs.find( aLibrary );
359
360 if( libIt != m_libs.end() )
361 {
362 for( auto& symbolBuf : libIt->second.GetBuffers() )
363 {
364 ret.push_back( symbolBuf->GetSymbol() );
365 }
366 }
367 else
368 {
369 std::vector<LIB_SYMBOL*> aliases;
370
371 try
372 {
373 symTable()->LoadSymbolLib( aliases, aLibrary );
374 }
375 catch( const IO_ERROR& e )
376 {
377 wxLogWarning( e.Problem() );
378 }
379
380 std::copy( aliases.begin(), aliases.end(), std::back_inserter( ret ) );
381 }
382
383 return ret;
384}
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 LibraryExists(), SYMBOL_LIB_TABLE::LoadSymbolLib(), m_libs, IO_ERROR::Problem(), and symTable().

Referenced by SYMBOL_TREE_SYNCHRONIZING_ADAPTER::updateLibrary().

◆ GetBufferedSymbol()

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

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

389{
390 wxCHECK( LibraryExists( aLibrary ), nullptr );
391
392 // try the library buffers first
393 LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary );
394 LIB_SYMBOL* bufferedSymbol = libBuf.GetSymbol( aAlias );
395
396 if( !bufferedSymbol ) // no buffer symbol found
397 {
398 // create a copy of the symbol
399 try
400 {
401 LIB_SYMBOL* symbol = symTable()->LoadSymbol( aLibrary, aAlias );
402
403 if( symbol == nullptr )
404 THROW_IO_ERROR( _( "Symbol not found." ) );
405
406 LIB_SYMBOL* bufferedParent = nullptr;
407
408 // Create parent symbols on demand so parent symbol can be set.
409 if( symbol->IsAlias() )
410 {
411 std::shared_ptr< LIB_SYMBOL > parent = symbol->GetParent().lock();
412 wxCHECK_MSG( parent, nullptr,
413 wxString::Format( "Derived symbol '%s' found with undefined parent.",
414 symbol->GetName() ) );
415
416 // Check if the parent symbol buffer has already be created.
417 bufferedParent = libBuf.GetSymbol( parent->GetName() );
418
419 if( !bufferedParent )
420 {
421 bufferedParent = new LIB_SYMBOL( *parent.get() );
422 libBuf.CreateBuffer( bufferedParent, new SCH_SCREEN );
423 }
424 }
425
426 bufferedSymbol = new LIB_SYMBOL( *symbol );
427
428 if( bufferedParent )
429 bufferedSymbol->SetParent( bufferedParent );
430
431 libBuf.CreateBuffer( bufferedSymbol, new SCH_SCREEN );
432 }
433 catch( const IO_ERROR& e )
434 {
435 wxLogMessage( _( "Error loading symbol %s from library '%s'. (%s)" ),
436 aAlias, aLibrary, e.What() );
437 bufferedSymbol = nullptr;
438 }
439 }
440
441 return bufferedSymbol;
442}
bool IsAlias() const
Definition: lib_symbol.h:183
void SetParent(LIB_SYMBOL *aParent=nullptr)
Definition: lib_symbol.cpp:451
wxString GetName() const override
Definition: lib_symbol.h:136
LIB_SYMBOL_REF & GetParent()
Definition: lib_symbol.h:125
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(), getLibraryBuffer(), LIB_SYMBOL::GetName(), LIB_SYMBOL::GetParent(), SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetSymbol(), LIB_SYMBOL::IsAlias(), LibraryExists(), SYMBOL_LIB_TABLE::LoadSymbol(), LIB_SYMBOL::SetParent(), 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

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(), m_libs, and symTable().

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

◆ GetLibrary()

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

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

Definition at line 143 of file symbol_library_manager.cpp.

144{
145 SYMBOL_LIB_TABLE_ROW* row = nullptr;
146
147 try
148 {
149 row = symTable()->FindRow( aLibrary, true );
150 }
151 catch( const IO_ERROR& e )
152 {
153 wxLogMessage( _( "Library '%s' not found in the Symbol Library Table." ) + e.What(),
154 aLibrary );
155 }
156
157 return row;
158}
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(), symTable(), and IO_ERROR::What().

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

◆ getLibraryBuffer()

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

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

The library buffers

Definition at line 782 of file symbol_library_manager.cpp.

784{
785 auto it = m_libs.find( aLibrary );
786
787 if( it != m_libs.end() )
788 return it->second;
789
790 // The requested buffer does not exist yet, so create one
791 auto ret = m_libs.emplace( aLibrary, LIB_BUFFER( aLibrary ) );
792 LIB_BUFFER& buf = ret.first->second;
793
794 for( auto symbol : getOriginalSymbols( aLibrary ) )
795 {
796 LIB_SYMBOL* newSymbol;
797
798 if( symbol->IsAlias() )
799 {
800 std::shared_ptr< LIB_SYMBOL > oldParent = symbol->GetParent().lock();
801
802 wxCHECK_MSG( oldParent, buf,
803 wxString::Format( "Derived symbol '%s' found with undefined parent.",
804 symbol->GetName() ) );
805
806 LIB_SYMBOL* libParent = buf.GetSymbol( oldParent->GetName() );
807
808 if( !libParent )
809 {
810 libParent = new LIB_SYMBOL( *oldParent.get() );
811 buf.CreateBuffer( libParent, new SCH_SCREEN );
812 }
813
814 newSymbol = new LIB_SYMBOL( *symbol );
815 newSymbol->SetParent( libParent );
816 buf.CreateBuffer( newSymbol, new SCH_SCREEN );
817 }
818 else if( !buf.GetSymbol( symbol->GetName() ) )
819 {
820 buf.CreateBuffer( new LIB_SYMBOL( *symbol ), new SCH_SCREEN );
821 }
822 }
823
824 return buf;
825}
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(), getOriginalSymbols(), LIB_SYMBOL::GetParent(), SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetSymbol(), m_libs, and LIB_SYMBOL::SetParent().

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

◆ GetLibraryCount()

size_t SYMBOL_LIBRARY_MANAGER::GetLibraryCount ( ) const

Definition at line 702 of file symbol_library_manager.cpp.

703{
704 return symTable()->GetLogicalLibs().size();
705}
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 symTable().

◆ GetLibraryHash()

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

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(), GetLibrary(), and m_libs.

Referenced by SYMBOL_TREE_SYNCHRONIZING_ADAPTER::updateLibrary().

◆ getLibraryName()

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

Helper function to add either existing or create new library.

Definition at line 708 of file symbol_library_manager.cpp.

709{
710 wxFileName fn( aFilePath );
711 return fn.GetName();
712}

Referenced by addLibrary().

◆ GetLibraryNames()

wxArrayString SYMBOL_LIBRARY_MANAGER::GetLibraryNames ( ) const

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 res.Add( libName );
138
139 return res;
140}

References 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)
protected

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

Definition at line 757 of file symbol_library_manager.cpp.

758{
759 std::set<LIB_SYMBOL*> symbols;
760 wxCHECK( LibraryExists( aLibrary ), symbols );
761
762 try
763 {
764 wxArrayString aliases;
765 symTable()->EnumerateSymbolLib( aLibrary, aliases );
766
767 for( const auto& aliasName : aliases )
768 {
769 LIB_SYMBOL* alias = symTable()->LoadSymbol( aLibrary, aliasName );
770 symbols.insert( alias );
771 }
772 }
773 catch( const IO_ERROR& e )
774 {
775 wxLogMessage( _( "Cannot enumerate library '%s'." ) + e.What(), aLibrary );
776 }
777
778 return symbols;
779}
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(), LibraryExists(), SYMBOL_LIB_TABLE::LoadSymbol(), symTable(), and IO_ERROR::What().

Referenced by getLibraryBuffer(), and SaveLibrary().

◆ GetRootSymbolNames()

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

Definition at line 684 of file symbol_library_manager.cpp.

686{
687 LIB_BUFFER& libBuf = getLibraryBuffer( aLibraryName );
688
689 libBuf.GetRootSymbolNames( aRootSymbolNames );
690}

References 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 
)

Return the screen used to edit a specific symbol.

SYMBOL_LIBRARY_MANAGER retains the ownership.

Definition at line 445 of file symbol_library_manager.cpp.

446{
447 wxCHECK( LibraryExists( aLibrary ), nullptr );
448 wxCHECK( !aAlias.IsEmpty(), nullptr );
449 auto it = m_libs.find( aLibrary );
450 wxCHECK( it != m_libs.end(), nullptr );
451
452 LIB_BUFFER& buf = it->second;
453 auto symbolBuf = buf.GetBuffer( aAlias );
454 return symbolBuf ? symbolBuf->GetScreen() : nullptr;
455}

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

Referenced by SYMBOL_EDIT_FRAME::LoadOneLibrarySymbolAux().

◆ GetUniqueLibraryName()

wxString SYMBOL_LIBRARY_MANAGER::GetUniqueLibraryName ( ) const

Return a library name that is not currently in use.

Used for generating names for new libraries.

Definition at line 664 of file symbol_library_manager.cpp.

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

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

Referenced by SYMBOL_EDIT_FRAME::AddLibraryFile().

◆ HasDerivedSymbols()

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

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

695{
696 LIB_BUFFER& libBuf = getLibraryBuffer( aLibraryName );
697
698 return libBuf.HasDerivedSymbols( aSymbolName );
699}

References 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

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

Referenced by SYMBOL_EDIT_FRAME::HasLibModifications().

◆ IsLibraryLoaded()

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

Return true if the library was successfully loaded.

Definition at line 345 of file symbol_library_manager.cpp.

346{
347 wxCHECK( LibraryExists( aLibrary ), false );
348
349 return symTable()->IsSymbolLibLoaded( aLibrary );
350}
bool IsSymbolLibLoaded(const wxString &aNickname)
Return true if the library given by aNickname was successfully loaded.

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

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

◆ IsLibraryModified()

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

Return true if library has unsaved modifications.

Definition at line 264 of file symbol_library_manager.cpp.

265{
266 auto it = m_libs.find( aLibrary );
267 return it != m_libs.end() ? it->second.IsModified() : false;
268}

References 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

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

Returns
True on success, false otherwise.

Definition at line 337 of file symbol_library_manager.cpp.

338{
339 wxCHECK( LibraryExists( aLibrary ), true );
340
341 return !symTable()->IsSymbolLibWritable( aLibrary );
342}
bool IsSymbolLibWritable(const wxString &aNickname)
Return true if the library given by aNickname is writable.

References SYMBOL_LIB_TABLE::IsSymbolLibWritable(), LibraryExists(), and 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

Return true if symbol has unsaved modifications.

Definition at line 271 of file symbol_library_manager.cpp.

273{
274 auto libIt = m_libs.find( aLibrary );
275
276 if( libIt == m_libs.end() )
277 return false;
278
279 const LIB_BUFFER& buf = libIt->second;
280 const std::shared_ptr<SYMBOL_LIBRARY_MANAGER::SYMBOL_BUFFER> symbolBuf = buf.GetBuffer( aAlias );
281 return symbolBuf ? symbolBuf->IsModified() : false;
282}

References SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetBuffer(), and 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

Return true if library exists.

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

Definition at line 652 of file symbol_library_manager.cpp.

653{
654 if( aLibrary.IsEmpty() )
655 return false;
656
657 if( m_libs.count( aLibrary ) > 0 )
658 return true;
659
660 return symTable()->HasLibrary( aLibrary, aCheckEnabled );
661}
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.

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

Referenced by addLibrary(), SYMBOL_EDIT_FRAME::AddLibraryFile(), SYMBOL_EDIT_FRAME::CreateNewSymbol(), SYMBOL_EDIT_FRAME::DdAddLibrary(), SYMBOL_EDIT_FRAME::DuplicateSymbol(), GetAliases(), GetBufferedSymbol(), getOriginalSymbols(), GetScreen(), GetUniqueLibraryName(), SYMBOL_EDIT_FRAME::ImportSymbol(), IsLibraryLoaded(), IsLibraryReadOnly(), SYMBOL_EDITOR_CONTROL::RenameSymbol(), SaveLibrary(), SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync(), and UpdateSymbol().

◆ OnDataChanged()

virtual void SYMBOL_LIBRARY_MANAGER::OnDataChanged ( ) const
inlineprotectedvirtual

Extract library name basing on the file name.

Reimplemented in LIB_SYMBOL_LIBRARY_MANAGER.

Definition at line 249 of file symbol_library_manager.h.

Referenced by addLibrary(), RemoveSymbol(), RevertLibrary(), RevertSymbol(), and UpdateSymbolAfterRename().

◆ Preload()

void SYMBOL_LIBRARY_MANAGER::Preload ( PROGRESS_REPORTER aReporter)

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(), m_frame, HTML_MESSAGE_BOX::MessageSet(), SYMBOL_ASYNC_LOADER::Start(), and symTable().

◆ RemoveSymbol()

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

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

585{
586 LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary );
587 auto symbolBuf = libBuf.GetBuffer( aAlias );
588 wxCHECK( symbolBuf, false );
589
590 bool retv = true;
591
592 retv &= libBuf.DeleteBuffer( symbolBuf );
594
595 return retv;
596}

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

Referenced by SYMBOL_EDIT_FRAME::DeleteSymbolFromLibrary().

◆ RevertAll()

bool SYMBOL_LIBRARY_MANAGER::RevertAll ( )

Revert all pending changes.

Returns
True if all changes successfully reverted.

Definition at line 558 of file symbol_library_manager.cpp.

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

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

Referenced by SYMBOL_EDIT_FRAME::RevertAll().

◆ RevertLibrary()

bool SYMBOL_LIBRARY_MANAGER::RevertLibrary ( const wxString &  aLibrary)

Revert unsaved changes for a symbolicular library.

Returns
True on success, false otherwise.

Definition at line 544 of file symbol_library_manager.cpp.

545{
546 auto it = m_libs.find( aLibrary );
547
548 if( it == m_libs.end() ) // nothing to reverse
549 return false;
550
551 m_libs.erase( it );
553
554 return true;
555}

References m_libs, and OnDataChanged().

Referenced by SYMBOL_EDIT_FRAME::Revert().

◆ RevertSymbol()

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

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

519{
520 auto it = m_libs.find( aLibrary );
521
522 if( it == m_libs.end() ) // no items to flush
523 return LIB_ID( aLibrary, aAlias );
524
525 auto symbolBuf = it->second.GetBuffer( aAlias );
526 wxCHECK( symbolBuf, LIB_ID( aLibrary, aAlias ) );
527 LIB_SYMBOL original( *symbolBuf->GetOriginal() );
528
529 if( original.GetName() != aAlias )
530 {
531 UpdateSymbolAfterRename( &original, aAlias, aLibrary );
532 }
533 else
534 {
535 // copy the initial data to the current symbol to restore
536 *symbolBuf->GetSymbol() = original;
538 }
539
540 return LIB_ID( aLibrary, original.GetName() );
541}
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(), m_libs, OnDataChanged(), and UpdateSymbolAfterRename().

Referenced by SYMBOL_EDIT_FRAME::Revert(), and 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 
)

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

163{
164 wxCHECK( aFileType != SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY && LibraryExists( aLibrary ), false );
165 wxFileName fn( aFileName );
166 wxCHECK( !fn.FileExists() || fn.IsFileWritable(), false );
167 SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( aFileType ) );
168 bool res = true; // assume all libraries are successfully saved
169
170 STRING_UTF8_MAP properties;
171 properties.emplace( SCH_LEGACY_PLUGIN::PropBuffering, "" );
172
173 auto it = m_libs.find( aLibrary );
174
175 if( it != m_libs.end() )
176 {
177 // Handle buffered library
178 LIB_BUFFER& libBuf = it->second;
179
180 const auto& symbolBuffers = libBuf.GetBuffers();
181
182 for( const auto& symbolBuf : symbolBuffers )
183 {
184 if( !libBuf.SaveBuffer( symbolBuf, aFileName, &*pi, true ) )
185 {
186 // Something went wrong, but try to save other libraries
187 res = false;
188 }
189 }
190
191 // clear the deleted symbols buffer only if data is saved to the original file
192 wxFileName original, destination( aFileName );
193 SYMBOL_LIB_TABLE_ROW* row = GetLibrary( aLibrary );
194
195 if( row )
196 {
197 original = row->GetFullURI();
198 original.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
199 }
200
201 destination.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
202
203 if( res && original == destination )
204 libBuf.ClearDeletedBuffer();
205 }
206 else
207 {
208 // Handle original library
209 for( LIB_SYMBOL* symbol : getOriginalSymbols( aLibrary ) )
210 {
211 LIB_SYMBOL* newSymbol;
212
213 try
214 {
215 if( symbol->IsAlias() )
216 {
217 std::shared_ptr< LIB_SYMBOL > oldParent = symbol->GetParent().lock();
218
219 wxCHECK_MSG( oldParent, false,
220 wxString::Format( wxT( "Derived symbol '%s' found with undefined parent." ),
221 symbol->GetName() ) );
222
223 LIB_SYMBOL* libParent = pi->LoadSymbol( aLibrary, oldParent->GetName(),
224 &properties );
225
226 if( !libParent )
227 {
228 libParent = new LIB_SYMBOL( *oldParent.get() );
229 pi->SaveSymbol( aLibrary, libParent, &properties );
230 }
231
232 newSymbol = new LIB_SYMBOL( *symbol );
233 newSymbol->SetParent( libParent );
234 pi->SaveSymbol( aLibrary, newSymbol, &properties );
235 }
236 else if( !pi->LoadSymbol( aLibrary, symbol->GetName(), &properties ) )
237 {
238 pi->SaveSymbol( aLibrary, new LIB_SYMBOL( *symbol ), &properties );
239 }
240 }
241 catch( ... )
242 {
243 res = false;
244 break;
245 }
246 }
247 }
248
249 try
250 {
251 pi->SaveLibrary( aFileName );
252 }
253 catch( ... )
254 {
255 // return false because something happens.
256 // The library is not successfully saved
257 res = false;
258 }
259
260 return res;
261}
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(), GetLibrary(), getOriginalSymbols(), LIB_SYMBOL::GetParent(), LibraryExists(), SCH_PLUGIN::LoadSymbol(), m_libs, SCH_LEGACY_PLUGIN::PropBuffering, 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 
)

Definition at line 285 of file symbol_library_manager.cpp.

287{
288 auto libIt = m_libs.find( aLibrary );
289
290 if( libIt == m_libs.end() )
291 return;
292
293 const LIB_BUFFER& buf = libIt->second;
294 std::shared_ptr<SYMBOL_LIBRARY_MANAGER::SYMBOL_BUFFER> symbolBuf = buf.GetBuffer( aAlias );
295
296 wxCHECK( symbolBuf, /* void */ );
297
298 symbolBuf->GetScreen()->SetContentModified();
299}

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

Referenced by SYMBOL_EDITOR_CONTROL::RenameSymbol().

◆ SymbolExists()

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

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

Definition at line 631 of file symbol_library_manager.cpp.

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

References SYMBOL_LIB_TABLE::LoadSymbol(), m_libs, and 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()

SYMBOL_LIB_TABLE * SYMBOL_LIBRARY_MANAGER::symTable ( ) const
protected

◆ UpdateSymbol()

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

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

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

References SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::CreateBuffer(), SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetBuffer(), LIB_SYMBOL::GetLibId(), LIB_ID::GetLibItemName(), getLibraryBuffer(), LIB_SYMBOL::GetName(), 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 
)

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

491{
492 LIB_BUFFER& libBuf = getLibraryBuffer( aLibrary );
493 auto symbolBuf = libBuf.GetBuffer( aOldName );
494
495 wxCHECK( symbolBuf, false );
496
497 libBuf.UpdateBuffer( symbolBuf, aSymbol );
499
500 return true;
501}

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

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

Member Data Documentation

◆ m_frame

SCH_BASE_FRAME& SYMBOL_LIBRARY_MANAGER::m_frame
protected

Parent frame.

Definition at line 412 of file symbol_library_manager.h.

Referenced by addLibrary(), LIB_SYMBOL_LIBRARY_MANAGER::OnDataChanged(), Preload(), and symTable().

◆ m_libs

◆ m_logger

LIB_LOGGER* SYMBOL_LIBRARY_MANAGER::m_logger
protected

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