KiCad PCB EDA Suite
SYMBOL_LIB Class Reference

Object used to load, save, search, and otherwise manipulate symbol library files. More...

#include <symbol_library.h>

Public Member Functions

 SYMBOL_LIB (SCH_LIB_TYPE aType, const wxString &aFileName, SCH_IO_MGR::SCH_FILE_T aPluginType=SCH_IO_MGR::SCH_LEGACY)
 
 ~SYMBOL_LIB ()
 
int GetModHash () const
 
SCH_IO_MGR::SCH_FILE_T GetPluginType () const
 
void SetPluginType (SCH_IO_MGR::SCH_FILE_T aPluginType)
 
void Create (const wxString &aFileName=wxEmptyString)
 
void SetFileName (const wxString &aFileName)
 
bool IsModified () const
 
bool IsCache () const
 
void SetCache ()
 
bool IsBuffering () const
 
void EnableBuffering (bool aEnable=true)
 
void Save (bool aSaveDocFile=true)
 
bool IsReadOnly () const
 
void GetSymbolNames (wxArrayString &aNames) const
 Load a string array with the names of all the entries in this library. More...
 
void GetSymbols (std::vector< LIB_SYMBOL * > &aSymbols) const
 Load a vector with all the entries in this library. More...
 
LIB_SYMBOLFindSymbol (const wxString &aName) const
 Find LIB_SYMBOL by aName. More...
 
LIB_SYMBOLFindSymbol (const LIB_ID &aLibId) const
 
void AddSymbol (LIB_SYMBOL *aSymbol)
 Add aSymbol entry to library. More...
 
LIB_SYMBOLRemoveSymbol (LIB_SYMBOL *aEntry)
 Safely remove aEntry from the library and return the next entry. More...
 
LIB_SYMBOLReplaceSymbol (LIB_SYMBOL *aOldSymbol, LIB_SYMBOL *aNewSymbol)
 Replace an existing symbol entry in the library. More...
 
const wxString GetName () const
 Return the file name without path or extension. More...
 
wxString GetFullFileName () const
 Return the full file library name with path and extension. More...
 
const wxString GetLogicalName () const
 Return the logical name of the library. More...
 

Static Public Member Functions

static SYMBOL_LIBLoadLibrary (const wxString &aFileName)
 Allocate and load a symbol library file. More...
 

Private Attributes

SCH_LIB_TYPE type
 Library type indicator. More...
 
wxFileName fileName
 Library file name. More...
 
wxDateTime timeStamp
 Library save time and date. More...
 
int versionMajor
 Library major version number. More...
 
int versionMinor
 Library minor version number. More...
 
wxString header
 first line of loaded library. More...
 
bool isModified
 Library modification status. More...
 
int m_mod_hash
 incremented each time library is changed. More...
 
SCH_IO_MGR::SCH_FILE_T m_pluginType
 
std::unique_ptr< SCH_PLUGINm_plugin
 
std::unique_ptr< STRING_UTF8_MAPm_properties
 Library properties. More...
 

Detailed Description

Object used to load, save, search, and otherwise manipulate symbol library files.

Warning
This code is obsolete with the exception of the cache library. All other symbol library I/O is managed by the SCH_IO_MGR object.

Definition at line 168 of file symbol_library.h.

Constructor & Destructor Documentation

◆ SYMBOL_LIB()

SYMBOL_LIB::SYMBOL_LIB ( SCH_LIB_TYPE  aType,
const wxString &  aFileName,
SCH_IO_MGR::SCH_FILE_T  aPluginType = SCH_IO_MGR::SCH_LEGACY 
)

Definition at line 47 of file symbol_library.cpp.

48 :
49 m_pluginType( aPluginType )
50{
51 type = aType;
52 isModified = false;
53 timeStamp = 0;
54 timeStamp = wxDateTime::Now();
55 versionMajor = 0; // Will be updated after reading the lib file
56 versionMinor = 0; // Will be updated after reading the lib file
57
58 fileName = aFileName;
59
60 if( !fileName.IsOk() )
61 fileName = "unnamed.lib";
62
63 m_plugin.reset( SCH_IO_MGR::FindPlugin( m_pluginType ) );
64 m_properties = std::make_unique<STRING_UTF8_MAP>();
65 m_mod_hash = 0;
66}
SCH_IO_MGR::SCH_FILE_T m_pluginType
std::unique_ptr< SCH_PLUGIN > m_plugin
SCH_LIB_TYPE type
Library type indicator.
bool isModified
Library modification status.
wxDateTime timeStamp
Library save time and date.
int versionMinor
Library minor version number.
int m_mod_hash
incremented each time library is changed.
wxFileName fileName
Library file name.
int versionMajor
Library major version number.
std::unique_ptr< STRING_UTF8_MAP > m_properties
Library properties.

References fileName, isModified, m_mod_hash, m_plugin, m_pluginType, m_properties, timeStamp, type, versionMajor, and versionMinor.

◆ ~SYMBOL_LIB()

SYMBOL_LIB::~SYMBOL_LIB ( )

Definition at line 69 of file symbol_library.cpp.

70{
71}

Member Function Documentation

◆ AddSymbol()

void SYMBOL_LIB::AddSymbol ( LIB_SYMBOL aSymbol)

Add aSymbol entry to library.

Note
A LIB_SYMBOL can have an alias list so these alias will be added in library. and the any existing duplicate aliases will be removed from the library.
Parameters
aSymbolis the symbol to add, caller retains ownership, a clone is added.

Definition at line 178 of file symbol_library.cpp.

179{
180 // add a clone, not the caller's copy, the plugin take ownership of the new symbol.
181 m_plugin->SaveSymbol( fileName.GetFullPath(),
182 new LIB_SYMBOL( *aSymbol->SharedPtr().get(), this ),
183 m_properties.get() );
184
185 // If we are not buffering, the library file is updated immediately when the plugin
186 // SaveSymbol() function is called.
187 if( IsBuffering() )
188 isModified = true;
189
190 ++m_mod_hash;
191}
Define a library symbol object.
Definition: lib_symbol.h:98
LIB_SYMBOL_SPTR SharedPtr() const
Definition: lib_symbol.h:108
bool IsBuffering() const

References fileName, IsBuffering(), isModified, m_mod_hash, m_plugin, m_properties, and LIB_SYMBOL::SharedPtr().

◆ Create()

void SYMBOL_LIB::Create ( const wxString &  aFileName = wxEmptyString)

Definition at line 90 of file symbol_library.cpp.

91{
92 wxString tmpFileName = fileName.GetFullPath();
93
94 if( !aFileName.IsEmpty() )
95 tmpFileName = aFileName;
96
97 m_plugin->CreateSymbolLib( tmpFileName, m_properties.get() );
98}

References fileName, m_plugin, and m_properties.

◆ EnableBuffering()

void SYMBOL_LIB::EnableBuffering ( bool  aEnable = true)

Definition at line 129 of file symbol_library.cpp.

130{
131 if( aEnable )
132 (*m_properties)[ SCH_LEGACY_PLUGIN::PropBuffering ] = "";
133 else
135}
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...

References m_properties, and SCH_LEGACY_PLUGIN::PropBuffering.

◆ FindSymbol() [1/2]

LIB_SYMBOL * SYMBOL_LIB::FindSymbol ( const LIB_ID aLibId) const

Definition at line 172 of file symbol_library.cpp.

173{
174 return FindSymbol( aLibId.Format().wx_str() );
175}
UTF8 Format() const
Definition: lib_id.cpp:117
LIB_SYMBOL * FindSymbol(const wxString &aName) const
Find LIB_SYMBOL by aName.
wxString wx_str() const
Definition: utf8.cpp:46

References FindSymbol(), LIB_ID::Format(), and UTF8::wx_str().

◆ FindSymbol() [2/2]

LIB_SYMBOL * SYMBOL_LIB::FindSymbol ( const wxString &  aName) const

Find LIB_SYMBOL by aName.

Parameters
aNameis the name of the symbol, case sensitive.
Returns
LIB_SYMBOL pointer symbol if found, else NULL.

Definition at line 158 of file symbol_library.cpp.

159{
160 LIB_SYMBOL* symbol = m_plugin->LoadSymbol( fileName.GetFullPath(), aName, m_properties.get() );
161
162 // Set the library to this even though technically the legacy cache plugin owns the
163 // symbols. This allows the symbol library table conversion tool to determine the
164 // correct library where the symbol was found.
165 if( symbol && !symbol->GetLib() )
166 symbol->SetLib( const_cast<SYMBOL_LIB*>( this ) );
167
168 return symbol;
169}
void SetLib(SYMBOL_LIB *aLibrary)
Definition: lib_symbol.h:188
SYMBOL_LIB * GetLib() const
Definition: lib_symbol.h:187
Object used to load, save, search, and otherwise manipulate symbol library files.

References fileName, LIB_SYMBOL::GetLib(), m_plugin, m_properties, and LIB_SYMBOL::SetLib().

Referenced by SYMBOL_LIBS::FindLibraryNearEntries(), SYMBOL_LIBS::FindLibSymbol(), FindSymbol(), SchGetLibSymbol(), and SCH_SCREEN::UpdateSymbolLinks().

◆ GetFullFileName()

wxString SYMBOL_LIB::GetFullFileName ( ) const
inline

Return the full file library name with path and extension.

Returns
the full library file name with path and extension.

Definition at line 278 of file symbol_library.h.

278{ return fileName.GetFullPath(); }

References fileName.

◆ GetLogicalName()

const wxString SYMBOL_LIB::GetLogicalName ( ) const
inline

Return the logical name of the library.

Returns
The logical name of this library.

Definition at line 285 of file symbol_library.h.

286 {
287 /* for now is the filename without path or extension.
288
289 Technically the library should not know its logical name!
290 This will eventually come out of a pair of lookup tables using a
291 reverse lookup using the full name or library pointer as a key.
292 Search will be by project lookup table and then user lookup table if
293 not found.
294 */
295 return fileName.GetName();
296 }

References fileName.

◆ GetModHash()

int SYMBOL_LIB::GetModHash ( ) const
inline
Returns
a magic number that changes if the library has changed

Definition at line 178 of file symbol_library.h.

178{ return m_mod_hash; }

References m_mod_hash.

◆ GetName()

const wxString SYMBOL_LIB::GetName ( void  ) const
inline

Return the file name without path or extension.

Returns
the name of library file.

Definition at line 271 of file symbol_library.h.

271{ return fileName.GetName(); }

References fileName.

Referenced by SYMBOL_LIBS::FindLibraryNearEntries(), SYMBOL_LIBS::FindLibSymbol(), LIB_SYMBOL::GetLibraryName(), and SYMBOL_LIBS::GetLibraryNames().

◆ GetPluginType()

SCH_IO_MGR::SCH_FILE_T SYMBOL_LIB::GetPluginType ( ) const
inline

Definition at line 180 of file symbol_library.h.

180{ return m_pluginType; }

References m_pluginType.

◆ GetSymbolNames()

void SYMBOL_LIB::GetSymbolNames ( wxArrayString &  aNames) const

Load a string array with the names of all the entries in this library.

Parameters
aNamesis the array to place entry names into.

Definition at line 138 of file symbol_library.cpp.

139{
140 m_plugin->EnumerateSymbolLib( aNames, fileName.GetFullPath(), m_properties.get() );
141
142 aNames.Sort();
143}

References fileName, m_plugin, and m_properties.

Referenced by SYMBOL_LIBS::FindLibraryNearEntries().

◆ GetSymbols()

void SYMBOL_LIB::GetSymbols ( std::vector< LIB_SYMBOL * > &  aSymbols) const

Load a vector with all the entries in this library.

Parameters
aSymbolsis a vector to receive the aliases.

Definition at line 146 of file symbol_library.cpp.

147{
148 m_plugin->EnumerateSymbolLib( aSymbols, fileName.GetFullPath(), m_properties.get() );
149
150 std::sort( aSymbols.begin(), aSymbols.end(),
151 [](LIB_SYMBOL *lhs, LIB_SYMBOL *rhs) -> bool
152 {
153 return lhs->GetName() < rhs->GetName();
154 } );
155}

References fileName, m_plugin, and m_properties.

Referenced by LEGACY_RESCUER::OpenRescueLibrary().

◆ IsBuffering()

bool SYMBOL_LIB::IsBuffering ( ) const

Definition at line 123 of file symbol_library.cpp.

124{
126}

References m_properties, and SCH_LEGACY_PLUGIN::PropBuffering.

Referenced by AddSymbol(), RemoveSymbol(), and ReplaceSymbol().

◆ IsCache()

bool SYMBOL_LIB::IsCache ( ) const

Definition at line 111 of file symbol_library.cpp.

112{
114}
static const char * PropNoDocFile
The property used internally by the plugin to disable writing the library documentation (....

References m_properties, and SCH_LEGACY_PLUGIN::PropNoDocFile.

Referenced by SYMBOL_LIBS::GetLibraryNames(), SchGetLibSymbol(), and SCH_SCREEN::UpdateSymbolLinks().

◆ IsModified()

bool SYMBOL_LIB::IsModified ( ) const
inline

Definition at line 188 of file symbol_library.h.

189 {
190 return isModified;
191 }

References isModified.

◆ IsReadOnly()

bool SYMBOL_LIB::IsReadOnly ( ) const
inline
Returns
true if current user does not have write access to the library file.

Definition at line 206 of file symbol_library.h.

206{ return !fileName.IsFileWritable(); }

References fileName.

◆ LoadLibrary()

SYMBOL_LIB * SYMBOL_LIB::LoadLibrary ( const wxString &  aFileName)
static

Allocate and load a symbol library file.

Parameters
aFileNameis the file name of the symbol library to load.
Returns
SYMBOL_LIB* is the allocated and loaded SYMBOL_LIB, which is owned by the caller.
Exceptions
IO_ERRORif there's any problem loading the library.

Definition at line 231 of file symbol_library.cpp.

232{
233 std::unique_ptr<SYMBOL_LIB> lib = std::make_unique<SYMBOL_LIB>( SCH_LIB_TYPE::LT_EESCHEMA,
234 aFileName );
235
236 std::vector<LIB_SYMBOL*> parts;
237 // This loads the library.
238 lib->GetSymbols( parts );
239
240 // Now, set the LIB_SYMBOL m_library member but it will only be used
241 // when loading legacy libraries in the future. Once the symbols in the
242 // schematic have a full #LIB_ID, this will not get called.
243 for( size_t ii = 0; ii < parts.size(); ii++ )
244 {
245 LIB_SYMBOL* part = parts[ii];
246
247 part->SetLib( lib.get() );
248 }
249
250 SYMBOL_LIB* ret = lib.release();
251 return ret;
252}

References LT_EESCHEMA, and LIB_SYMBOL::SetLib().

Referenced by SYMBOL_LIBS::AddLibrary().

◆ RemoveSymbol()

LIB_SYMBOL * SYMBOL_LIB::RemoveSymbol ( LIB_SYMBOL aEntry)

Safely remove aEntry from the library and return the next entry.

The next entry returned depends on the entry being removed. If the entry being remove also removes the symbol, then the next entry from the list is returned. If the entry being used only removes an alias from a symbol, then the next alias of the symbol is returned.

Parameters
aEntryis the entry to remove from library.
Returns
The next entry in the library or NULL if the library is empty.

Definition at line 194 of file symbol_library.cpp.

195{
196 wxCHECK_MSG( aEntry != nullptr, nullptr, "NULL pointer cannot be removed from library." );
197
198 m_plugin->DeleteSymbol( fileName.GetFullPath(), aEntry->GetName(), m_properties.get() );
199
200 // If we are not buffering, the library file is updated immediately when the plugin
201 // SaveSymbol() function is called.
202 if( IsBuffering() )
203 isModified = true;
204
205 ++m_mod_hash;
206 return nullptr;
207}
wxString GetName() const override
Definition: lib_symbol.h:136

References fileName, LIB_SYMBOL::GetName(), IsBuffering(), isModified, m_mod_hash, m_plugin, and m_properties.

◆ ReplaceSymbol()

LIB_SYMBOL * SYMBOL_LIB::ReplaceSymbol ( LIB_SYMBOL aOldSymbol,
LIB_SYMBOL aNewSymbol 
)

Replace an existing symbol entry in the library.

Note
A symbol can have an alias list so these aliases will be added in library and previously existing alias removed.
Parameters
aOldSymbolis the symbol to replace.
aNewSymbolis the new symbol.

Definition at line 210 of file symbol_library.cpp.

211{
212 wxASSERT( aOldSymbol != nullptr );
213 wxASSERT( aNewSymbol != nullptr );
214
215 m_plugin->DeleteSymbol( fileName.GetFullPath(), aOldSymbol->GetName(), m_properties.get() );
216
217 LIB_SYMBOL* my_part = new LIB_SYMBOL( *aNewSymbol, this );
218
219 m_plugin->SaveSymbol( fileName.GetFullPath(), my_part, m_properties.get() );
220
221 // If we are not buffering, the library file is updated immediately when the plugin
222 // SaveSymbol() function is called.
223 if( IsBuffering() )
224 isModified = true;
225
226 ++m_mod_hash;
227 return my_part;
228}

References fileName, LIB_SYMBOL::GetName(), IsBuffering(), isModified, m_mod_hash, m_plugin, and m_properties.

◆ Save()

void SYMBOL_LIB::Save ( bool  aSaveDocFile = true)

Definition at line 74 of file symbol_library.cpp.

75{
76 wxCHECK_RET( m_plugin != nullptr,
77 wxString::Format( wxT( "no plugin defined for library `%s`." ),
78 fileName.GetFullPath() ) );
79
80 STRING_UTF8_MAP props;
81
82 if( !aSaveDocFile )
84
85 m_plugin->SaveLibrary( fileName.GetFullPath(), &props );
86 isModified = false;
87}
A name/value tuple with unique names and optional values.
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 fileName, Format(), isModified, m_plugin, and SCH_LEGACY_PLUGIN::PropNoDocFile.

◆ SetCache()

void SYMBOL_LIB::SetCache ( )

Definition at line 117 of file symbol_library.cpp.

118{
119 (*m_properties)[ SCH_LEGACY_PLUGIN::PropNoDocFile ] = "";
120}

References SCH_LEGACY_PLUGIN::PropNoDocFile.

Referenced by SYMBOL_LIBS::LoadAllLibraries().

◆ SetFileName()

void SYMBOL_LIB::SetFileName ( const wxString &  aFileName)
inline

Definition at line 186 of file symbol_library.h.

186{ fileName = aFileName; }

References fileName.

◆ SetPluginType()

void SYMBOL_LIB::SetPluginType ( SCH_IO_MGR::SCH_FILE_T  aPluginType)

Definition at line 101 of file symbol_library.cpp.

102{
103 if( m_pluginType != aPluginType )
104 {
105 m_pluginType = aPluginType;
106 m_plugin.reset( SCH_IO_MGR::FindPlugin( m_pluginType ) );
107 }
108}

References m_plugin, and m_pluginType.

Member Data Documentation

◆ fileName

wxFileName SYMBOL_LIB::fileName
private

◆ header

wxString SYMBOL_LIB::header
private

first line of loaded library.

Definition at line 313 of file symbol_library.h.

◆ isModified

bool SYMBOL_LIB::isModified
private

Library modification status.

Definition at line 314 of file symbol_library.h.

Referenced by AddSymbol(), IsModified(), RemoveSymbol(), ReplaceSymbol(), Save(), and SYMBOL_LIB().

◆ m_mod_hash

int SYMBOL_LIB::m_mod_hash
private

incremented each time library is changed.

Definition at line 315 of file symbol_library.h.

Referenced by AddSymbol(), GetModHash(), RemoveSymbol(), ReplaceSymbol(), and SYMBOL_LIB().

◆ m_plugin

std::unique_ptr< SCH_PLUGIN > SYMBOL_LIB::m_plugin
private

◆ m_pluginType

SCH_IO_MGR::SCH_FILE_T SYMBOL_LIB::m_pluginType
private

Definition at line 317 of file symbol_library.h.

Referenced by GetPluginType(), SetPluginType(), and SYMBOL_LIB().

◆ m_properties

std::unique_ptr<STRING_UTF8_MAP> SYMBOL_LIB::m_properties
private

◆ timeStamp

wxDateTime SYMBOL_LIB::timeStamp
private

Library save time and date.

Definition at line 310 of file symbol_library.h.

Referenced by SYMBOL_LIB().

◆ type

SCH_LIB_TYPE SYMBOL_LIB::type
private

Library type indicator.

Definition at line 308 of file symbol_library.h.

Referenced by SYMBOL_LIB().

◆ versionMajor

int SYMBOL_LIB::versionMajor
private

Library major version number.

Definition at line 311 of file symbol_library.h.

Referenced by SYMBOL_LIB().

◆ versionMinor

int SYMBOL_LIB::versionMinor
private

Library minor version number.

Definition at line 312 of file symbol_library.h.

Referenced by SYMBOL_LIB().


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