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_LIBLoadSymbolLibrary (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 49 of file symbol_library.cpp.

50 :
51 m_pluginType( aPluginType )
52{
53 type = aType;
54 isModified = false;
55 timeStamp = 0;
56 timeStamp = wxDateTime::Now();
57 versionMajor = 0; // Will be updated after reading the lib file
58 versionMinor = 0; // Will be updated after reading the lib file
59
60 fileName = aFileName;
61
62 if( !fileName.IsOk() )
63 fileName = "unnamed.lib";
64
65 m_plugin.reset( SCH_IO_MGR::FindPlugin( m_pluginType ) );
66 m_properties = std::make_unique<STRING_UTF8_MAP>();
67 m_mod_hash = 0;
68}
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 71 of file symbol_library.cpp.

72{
73}

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 185 of file symbol_library.cpp.

186{
187 // add a clone, not the caller's copy, the plugin take ownership of the new symbol.
188 m_plugin->SaveSymbol( fileName.GetFullPath(),
189 new LIB_SYMBOL( *aSymbol->SharedPtr().get(), this ),
190 m_properties.get() );
191
192 // If we are not buffering, the library file is updated immediately when the plugin
193 // SaveSymbol() function is called.
194 if( IsBuffering() )
195 isModified = true;
196
197 ++m_mod_hash;
198}
Define a library symbol object.
Definition: lib_symbol.h:99
LIB_SYMBOL_SPTR SharedPtr() const
Definition: lib_symbol.h:110
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 92 of file symbol_library.cpp.

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

References fileName, m_plugin, and m_properties.

◆ EnableBuffering()

void SYMBOL_LIB::EnableBuffering ( bool  aEnable = true)

Definition at line 131 of file symbol_library.cpp.

132{
133 if( aEnable )
134 (*m_properties)[ SCH_LEGACY_PLUGIN::PropBuffering ] = "";
135 else
137}
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 179 of file symbol_library.cpp.

180{
181 return FindSymbol( aLibId.Format().wx_str() );
182}
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 160 of file symbol_library.cpp.

161{
162 LIB_SYMBOL* symbol = m_plugin->LoadSymbol( fileName.GetFullPath(), aName, m_properties.get() );
163
164 if( symbol )
165 {
166 // Set the library to this even though technically the legacy cache plugin owns the
167 // symbols. This allows the symbol library table conversion tool to determine the
168 // correct library where the symbol was found.
169 if( !symbol->GetLib() )
170 symbol->SetLib( const_cast<SYMBOL_LIB*>( this ) );
171
172 SIM_MODEL::MigrateSimModel<LIB_SYMBOL, LIB_FIELD>( *symbol, nullptr );
173 }
174
175 return symbol;
176}
void SetLib(SYMBOL_LIB *aLibrary)
Definition: lib_symbol.h:193
SYMBOL_LIB * GetLib() const
Definition: lib_symbol.h:192
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 140 of file symbol_library.cpp.

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

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 148 of file symbol_library.cpp.

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

References fileName, m_plugin, and m_properties.

Referenced by LEGACY_RESCUER::OpenRescueLibrary().

◆ IsBuffering()

bool SYMBOL_LIB::IsBuffering ( ) const

Definition at line 125 of file symbol_library.cpp.

126{
128}

References m_properties, and SCH_LEGACY_PLUGIN::PropBuffering.

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

◆ IsCache()

bool SYMBOL_LIB::IsCache ( ) const

Definition at line 113 of file symbol_library.cpp.

114{
116}
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.

◆ LoadSymbolLibrary()

SYMBOL_LIB * SYMBOL_LIB::LoadSymbolLibrary ( 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 238 of file symbol_library.cpp.

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

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 201 of file symbol_library.cpp.

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

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 217 of file symbol_library.cpp.

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

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 76 of file symbol_library.cpp.

77{
78 wxCHECK_RET( m_plugin != nullptr,
79 wxString::Format( wxT( "no plugin defined for library `%s`." ),
80 fileName.GetFullPath() ) );
81
82 STRING_UTF8_MAP props;
83
84 if( !aSaveDocFile )
86
87 m_plugin->SaveLibrary( fileName.GetFullPath(), &props );
88 isModified = false;
89}
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 119 of file symbol_library.cpp.

120{
121 (*m_properties)[ SCH_LEGACY_PLUGIN::PropNoDocFile ] = "";
122}

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 103 of file symbol_library.cpp.

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

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: