KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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

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 UpdateLibraryBuffer (const wxString &aLibrary)
 Update the library buffer with a new version of the library. 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 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 GetSymbolNames (const wxString &aLibName, wxArrayString &aSymbolNames, SYMBOL_NAME_FILTER aFilter=SYMBOL_NAME_FILTER::ALL)
 
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 175 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 48 of file symbol_library_manager.cpp.

References m_logger.

◆ ~SYMBOL_LIBRARY_MANAGER()

SYMBOL_LIBRARY_MANAGER::~SYMBOL_LIBRARY_MANAGER ( )
virtual

Definition at line 55 of file symbol_library_manager.cpp.

References m_logger.

Member Function Documentation

◆ addLibrary()

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

◆ 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 224 of file symbol_library_manager.h.

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

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

References m_libs.

Referenced by SYMBOL_EDIT_FRAME::Revert().

◆ 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 216 of file symbol_library_manager.h.

References addLibrary().

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

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

References _, DisplayErrorMessage(), SYMBOL_LIB_TABLE::LoadSymbol(), m_frame, 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

◆ GetBufferedSymbol()

◆ GetHash()

int SYMBOL_LIBRARY_MANAGER::GetHash ( ) const

◆ GetLibrary()

◆ getLibraryBuffer()

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

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

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

◆ GetLibraryCount()

size_t SYMBOL_LIBRARY_MANAGER::GetLibraryCount ( ) const

Definition at line 702 of file symbol_library_manager.cpp.

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

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.

Referenced by addLibrary().

◆ GetLibraryNames()

wxArrayString SYMBOL_LIBRARY_MANAGER::GetLibraryNames ( ) const

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

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

Referenced by getLibraryBuffer(), and SaveLibrary().

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

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

Referenced by SYMBOL_EDIT_FRAME::KiwayMailIn(), and SYMBOL_EDIT_FRAME::LoadOneLibrarySymbolAux().

◆ GetSymbolNames()

void SYMBOL_LIBRARY_MANAGER::GetSymbolNames ( const wxString &  aLibName,
wxArrayString &  aSymbolNames,
SYMBOL_NAME_FILTER  aFilter = SYMBOL_NAME_FILTER::ALL 
)

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

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

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

Referenced by SYMBOL_EDIT_FRAME::DeleteSymbolFromLibrary().

◆ HasModifications()

bool SYMBOL_LIBRARY_MANAGER::HasModifications ( ) const

Definition at line 95 of file symbol_library_manager.cpp.

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

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

◆ IsLibraryReadOnly()

◆ IsSymbolModified()

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

◆ LibraryExists()

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

◆ 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 370 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 61 of file symbol_library_manager.cpp.

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

References LIB_BUFFER::DeleteBuffer(), 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 556 of file symbol_library_manager.cpp.

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

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

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

References LIB_BUFFER::ClearDeletedBuffer(), FN_NORMALIZE_FLAGS, LIB_BUFFER::GetBuffers(), LIB_TABLE_ROW::GetFullURI(), GetLibrary(), getOriginalSymbols(), LIB_SYMBOL::GetParent(), LibraryExists(), m_libs, SCH_IO_KICAD_LEGACY::PropBuffering, res, LIB_BUFFER::SaveBuffer(), 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 296 of file symbol_library_manager.cpp.

References 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

◆ symTable()

◆ UpdateLibraryBuffer()

bool SYMBOL_LIBRARY_MANAGER::UpdateLibraryBuffer ( const wxString &  aLibrary)

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

Definition at line 834 of file symbol_library_manager.cpp.

References _, getLibraryBuffer(), and m_libs.

Referenced by SYMBOL_EDIT_FRAME::KiwayMailIn().

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

References LIB_BUFFER::CreateBuffer(), 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::saveSymbolCopyAs(), 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 501 of file symbol_library_manager.cpp.

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

◆ m_libs

◆ m_logger

LIB_LOGGER* SYMBOL_LIBRARY_MANAGER::m_logger
protected

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