KiCad PCB EDA Suite
PART_LIB Class Reference

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

#include <class_library.h>

Public Member Functions

 PART_LIB (int aType, const wxString &aFileName, SCH_IO_MGR::SCH_FILE_T aPluginType=SCH_IO_MGR::SCH_LEGACY)
 
 ~PART_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 GetAliasNames (wxArrayString &aNames) const
 Load a string array with the names of all the entries in this library. More...
 
void GetAliases (std::vector< LIB_ALIAS * > &aAliases) const
 Load a vector with all the entries in this library. More...
 
LIB_ALIASFindAlias (const wxString &aName) const
 Find LIB_ALIAS by aName. More...
 
LIB_ALIASFindAlias (const LIB_ID &aLibId) const
 
LIB_PARTFindPart (const wxString &aName) const
 Find part by aName. More...
 
LIB_PARTFindPart (const LIB_ID &aLibId) const
 
void AddPart (LIB_PART *aPart)
 Add aPart entry to library. More...
 
LIB_ALIASRemoveAlias (LIB_ALIAS *aEntry)
 Safely remove aEntry from the library and return the next entry. More...
 
LIB_PARTReplacePart (LIB_PART *aOldPart, LIB_PART *aNewPart)
 Replace an existing part 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 PART_LIBLoadLibrary (const wxString &aFileName)
 Allocate and load a symbol library file. More...
 

Private Attributes

int 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< PROPERTIESm_properties
 Library properties. More...
 

Detailed Description

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

Definition at line 314 of file class_library.h.

Constructor & Destructor Documentation

◆ PART_LIB()

PART_LIB::PART_LIB ( int  aType,
const wxString &  aFileName,
SCH_IO_MGR::SCH_FILE_T  aPluginType = SCH_IO_MGR::SCH_LEGACY 
)

Definition at line 58 of file class_library.cpp.

58  :
59  // start @ != 0 so each additional library added
60  // is immediately detectable, zero would not be.
62  m_pluginType( aPluginType )
63 {
64  type = aType;
65  isModified = false;
66  timeStamp = 0;
67  timeStamp = wxDateTime::Now();
68  versionMajor = 0; // Will be updated after reading the lib file
69  versionMinor = 0; // Will be updated after reading the lib file
70 
71  fileName = aFileName;
72 
73  if( !fileName.IsOk() )
74  fileName = "unnamed.lib";
75 
76  m_plugin.reset( SCH_IO_MGR::FindPlugin( m_pluginType ) );
77  m_properties = std::make_unique<PROPERTIES>();
78 }
int m_mod_hash
incremented each time library is changed.
std::unique_ptr< SCH_PLUGIN > m_plugin
static int s_modify_generation
helper for GetModifyHash()
bool isModified
Library modification status.
int type
Library type indicator.
wxDateTime timeStamp
Library save time and date.
std::unique_ptr< PROPERTIES > m_properties
Library properties.
SCH_IO_MGR::SCH_FILE_T m_pluginType
wxFileName fileName
Library file name.
int versionMinor
Library minor version number.
int versionMajor
Library major version number.

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

Referenced by LoadLibrary().

◆ ~PART_LIB()

PART_LIB::~PART_LIB ( )

Definition at line 81 of file class_library.cpp.

82 {
83 }

Member Function Documentation

◆ AddPart()

void PART_LIB::AddPart ( LIB_PART aPart)

Add aPart entry to library.

Note
A LIB_PART 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
aPart- Part to add, caller retains ownership, a clone is added.

Definition at line 204 of file class_library.cpp.

205 {
206  // add a clone, not the caller's copy, the plugin take ownership of the new symbol.
207  m_plugin->SaveSymbol( fileName.GetFullPath(), new LIB_PART( *aPart, this ), m_properties.get() );
208 
209  // If we are not buffering, the library file is updated immediately when the plugin
210  // SaveSymbol() function is called.
211  if( IsBuffering() )
212  isModified = true;
213 
214  ++m_mod_hash;
215 }
int m_mod_hash
incremented each time library is changed.
std::unique_ptr< SCH_PLUGIN > m_plugin
bool isModified
Library modification status.
bool IsBuffering() const
Define a library symbol object.
std::unique_ptr< PROPERTIES > m_properties
Library properties.
wxFileName fileName
Library file name.

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

◆ Create()

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

Definition at line 101 of file class_library.cpp.

102 {
103  wxString tmpFileName = fileName.GetFullPath();
104 
105  if( !aFileName.IsEmpty() )
106  tmpFileName = aFileName;
107 
108  m_plugin->CreateSymbolLib( tmpFileName, m_properties.get() );
109 }
std::unique_ptr< SCH_PLUGIN > m_plugin
std::unique_ptr< PROPERTIES > m_properties
Library properties.
wxFileName fileName
Library file name.

References fileName, m_plugin, and m_properties.

◆ EnableBuffering()

void PART_LIB::EnableBuffering ( bool  aEnable = true)

Definition at line 140 of file class_library.cpp.

141 {
142  if( aEnable )
143  (*m_properties)[ SCH_LEGACY_PLUGIN::PropBuffering ] = "";
144  else
146 }
std::unique_ptr< PROPERTIES > m_properties
Library properties.
static const char * PropBuffering
const char* PropBuffering

References m_properties, and SCH_LEGACY_PLUGIN::PropBuffering.

◆ FindAlias() [1/2]

LIB_ALIAS * PART_LIB::FindAlias ( const wxString &  aName) const

Find LIB_ALIAS by aName.

Parameters
aName- Name of entry, case sensitive.
Returns
LIB_ALIAS* if found. NULL if not found.

Definition at line 167 of file class_library.cpp.

168 {
169  LIB_ALIAS* alias = m_plugin->LoadSymbol( fileName.GetFullPath(), aName, m_properties.get() );
170 
171  // Set the library to this even though technically the legacy cache plugin owns the
172  // symbols. This allows the symbol library table conversion tool to determine the
173  // correct library where the symbol was found.
174  if( alias && alias->GetPart() && !alias->GetPart()->GetLib() )
175  alias->GetPart()->SetLib( const_cast<PART_LIB*>( this ) );
176 
177  return alias;
178 }
PART_LIB * GetLib()
void SetLib(PART_LIB *aLibrary)
Part library alias object definition.
std::unique_ptr< SCH_PLUGIN > m_plugin
std::unique_ptr< PROPERTIES > m_properties
Library properties.
LIB_PART * GetPart() const
Get the shared LIB_PART.
wxFileName fileName
Library file name.

References fileName, LIB_PART::GetLib(), LIB_ALIAS::GetPart(), m_plugin, m_properties, and LIB_PART::SetLib().

Referenced by FindAlias(), PART_LIBS::FindLibraryAlias(), PART_LIBS::FindLibraryNearEntries(), FindPart(), SCH_COMPONENT::Resolve(), SchGetLibAlias(), and SCH_COMPONENT::SetLibId().

◆ FindAlias() [2/2]

LIB_ALIAS * PART_LIB::FindAlias ( const LIB_ID aLibId) const

Definition at line 181 of file class_library.cpp.

182 {
183  return FindAlias( aLibId.Format().wx_str() );
184 }
LIB_ALIAS * FindAlias(const wxString &aName) const
Find LIB_ALIAS by aName.
UTF8 Format() const
Definition: lib_id.cpp:237
wxString wx_str() const
Definition: utf8.cpp:51

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

◆ FindPart() [1/2]

LIB_PART * PART_LIB::FindPart ( const wxString &  aName) const

Find part by aName.

This is a helper for FindEntry so casting a LIB_ALIAS pointer to a LIB_PART pointer is not required.

Parameters
aName- Name of part, case sensitive.
Returns
LIB_PART* - part if found, else NULL.

Definition at line 187 of file class_library.cpp.

188 {
189  LIB_ALIAS* alias = FindAlias( aName );
190 
191  if( alias != NULL )
192  return alias->GetPart();
193 
194  return NULL;
195 }
Part library alias object definition.
LIB_ALIAS * FindAlias(const wxString &aName) const
Find LIB_ALIAS by aName.
LIB_PART * GetPart() const
Get the shared LIB_PART.

References FindAlias(), and LIB_ALIAS::GetPart().

Referenced by PART_LIBS::FindLibPart(), and FindPart().

◆ FindPart() [2/2]

LIB_PART * PART_LIB::FindPart ( const LIB_ID aLibId) const

Definition at line 198 of file class_library.cpp.

199 {
200  return FindPart( aLibId.Format().wx_str() );
201 }
LIB_PART * FindPart(const wxString &aName) const
Find part by aName.
UTF8 Format() const
Definition: lib_id.cpp:237
wxString wx_str() const
Definition: utf8.cpp:51

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

◆ GetAliases()

void PART_LIB::GetAliases ( std::vector< LIB_ALIAS * > &  aAliases) const

Load a vector with all the entries in this library.

Parameters
aAliases- vector to receive the aliases.

Definition at line 157 of file class_library.cpp.

158 {
159  m_plugin->EnumerateSymbolLib( aAliases, fileName.GetFullPath(), m_properties.get() );
160 
161  std::sort( aAliases.begin(), aAliases.end(),
162  [](LIB_ALIAS *lhs, LIB_ALIAS *rhs) -> bool
163  { return lhs->GetName() < rhs->GetName(); });
164 }
Part library alias object definition.
std::unique_ptr< SCH_PLUGIN > m_plugin
std::unique_ptr< PROPERTIES > m_properties
Library properties.
YYCODETYPE lhs
wxFileName fileName
Library file name.

References fileName, numEval::lhs, m_plugin, and m_properties.

Referenced by LEGACY_RESCUER::OpenRescueLibrary().

◆ GetAliasNames()

void PART_LIB::GetAliasNames ( wxArrayString &  aNames) const

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

Parameters
aNames- String array to place entry names into.

Definition at line 149 of file class_library.cpp.

150 {
151  m_plugin->EnumerateSymbolLib( aNames, fileName.GetFullPath(), m_properties.get() );
152 
153  aNames.Sort();
154 }
std::unique_ptr< SCH_PLUGIN > m_plugin
std::unique_ptr< PROPERTIES > m_properties
Library properties.
wxFileName fileName
Library file name.

References fileName, m_plugin, and m_properties.

Referenced by PART_LIBS::FindLibraryNearEntries().

◆ GetFullFileName()

wxString PART_LIB::GetFullFileName ( ) const
inline

Return the full file library name with path and extension.

Returns
wxString - Full library file name with path and extension.

Definition at line 448 of file class_library.h.

448 { return fileName.GetFullPath(); }
wxFileName fileName
Library file name.

References fileName.

◆ GetLogicalName()

const wxString PART_LIB::GetLogicalName ( ) const
inline

Return the logical name of the library.

Returns
wxString - The logical name of this library.

Definition at line 455 of file class_library.h.

456  {
457  /* for now is the filename without path or extension.
458 
459  Technically the library should not know its logical name!
460  This will eventually come out of a pair of lookup tables using a
461  reverse lookup using the full name or library pointer as a key.
462  Search will be by project lookup table and then user lookup table if
463  not found.
464  */
465  return fileName.GetName();
466  }
wxFileName fileName
Library file name.

References fileName.

◆ GetModHash()

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

Definition at line 337 of file class_library.h.

337 { return m_mod_hash; }
int m_mod_hash
incremented each time library is changed.

References m_mod_hash.

◆ GetName()

const wxString PART_LIB::GetName ( ) const
inline

Return the file name without path or extension.

Returns
Name of library file.

Definition at line 441 of file class_library.h.

441 { return fileName.GetName(); }
wxFileName fileName
Library file name.

References fileName.

Referenced by PART_LIBS::FindLibPart(), PART_LIBS::FindLibraryAlias(), PART_LIBS::FindLibraryNearEntries(), LIB_PART::GetLibraryName(), and PART_LIBS::GetLibraryNames().

◆ GetPluginType()

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

Definition at line 339 of file class_library.h.

339 { return m_pluginType; }
SCH_IO_MGR::SCH_FILE_T m_pluginType

References m_pluginType.

◆ IsBuffering()

bool PART_LIB::IsBuffering ( ) const

Definition at line 134 of file class_library.cpp.

135 {
137 }
std::unique_ptr< PROPERTIES > m_properties
Library properties.
static const char * PropBuffering
const char* PropBuffering

References m_properties, and SCH_LEGACY_PLUGIN::PropBuffering.

Referenced by AddPart(), RemoveAlias(), and ReplacePart().

◆ IsCache()

bool PART_LIB::IsCache ( ) const

Definition at line 122 of file class_library.cpp.

123 {
125 }
std::unique_ptr< PROPERTIES > m_properties
Library properties.
static const char * PropNoDocFile
const char* PropBuffering

References m_properties, and SCH_LEGACY_PLUGIN::PropNoDocFile.

Referenced by PART_LIBS::GetLibraryNames().

◆ IsModified()

bool PART_LIB::IsModified ( ) const
inline

Definition at line 347 of file class_library.h.

348  {
349  return isModified;
350  }
bool isModified
Library modification status.

References isModified.

◆ IsReadOnly()

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

Definition at line 365 of file class_library.h.

365 { return !fileName.IsFileWritable(); }
wxFileName fileName
Library file name.

References fileName.

◆ LoadLibrary()

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

Allocate and load a symbol library file.

Parameters
aFileName- File name of the part library to load.
Returns
PART_LIB* - the allocated and loaded PART_LIB, which is owned by the caller.
Exceptions
IO_ERRORif there's any problem loading the library.

Definition at line 255 of file class_library.cpp.

256 {
257  std::unique_ptr<PART_LIB> lib( new PART_LIB( LIBRARY_TYPE_EESCHEMA, aFileName ) );
258 
259  std::vector<LIB_ALIAS*> aliases;
260  // This loads the library.
261  lib->GetAliases( aliases );
262 
263  // Now, set the LIB_PART m_library member but it will only be used
264  // when loading legacy libraries in the future. Once the symbols in the
265  // schematic have a full #LIB_ID, this will not get called.
266  for( size_t ii = 0; ii < aliases.size(); ii++ )
267  {
268  LIB_ALIAS* alias = aliases[ii];
269 
270  if( alias->GetPart() )
271  alias->GetPart()->SetLib( lib.get() );
272  }
273 
274  PART_LIB* ret = lib.release();
275  return ret;
276 }
void SetLib(PART_LIB *aLibrary)
Part library alias object definition.
LIB_PART * GetPart() const
Get the shared LIB_PART.
PART_LIB(int aType, const wxString &aFileName, SCH_IO_MGR::SCH_FILE_T aPluginType=SCH_IO_MGR::SCH_LEGACY)
Object used to load, save, search, and otherwise manipulate symbol library files.

References LIB_ALIAS::GetPart(), LIBRARY_TYPE_EESCHEMA, PART_LIB(), and LIB_PART::SetLib().

Referenced by PART_LIBS::AddLibrary().

◆ RemoveAlias()

LIB_ALIAS * PART_LIB::RemoveAlias ( LIB_ALIAS 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 part, then the next entry from the list is returned. If the entry being used only removes an alias from a part, then the next alias of the part is returned.

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

Definition at line 218 of file class_library.cpp.

219 {
220  wxCHECK_MSG( aEntry != NULL, NULL, "NULL pointer cannot be removed from library." );
221 
222  m_plugin->DeleteAlias( fileName.GetFullPath(), aEntry->GetName(), m_properties.get() );
223 
224  // If we are not buffering, the library file is updated immediately when the plugin
225  // SaveSymbol() function is called.
226  if( IsBuffering() )
227  isModified = true;
228 
229  ++m_mod_hash;
230  return NULL;
231 }
int m_mod_hash
incremented each time library is changed.
std::unique_ptr< SCH_PLUGIN > m_plugin
bool isModified
Library modification status.
bool IsBuffering() const
std::unique_ptr< PROPERTIES > m_properties
Library properties.
wxFileName fileName
Library file name.
const wxString & GetName() const override

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

◆ ReplacePart()

LIB_PART * PART_LIB::ReplacePart ( LIB_PART aOldPart,
LIB_PART aNewPart 
)

Replace an existing part entry in the library.

Note a part can have an alias list, so these alias will be added in library (and previously existing alias removed)

Parameters
aOldPart- The part to replace.
aNewPart- The new part.

Definition at line 234 of file class_library.cpp.

235 {
236  wxASSERT( aOldPart != NULL );
237  wxASSERT( aNewPart != NULL );
238 
239  m_plugin->DeleteSymbol( fileName.GetFullPath(), aOldPart->GetName(), m_properties.get() );
240 
241  LIB_PART* my_part = new LIB_PART( *aNewPart, this );
242 
243  m_plugin->SaveSymbol( fileName.GetFullPath(), my_part, m_properties.get() );
244 
245  // If we are not buffering, the library file is updated immediately when the plugin
246  // SaveSymbol() function is called.
247  if( IsBuffering() )
248  isModified = true;
249 
250  ++m_mod_hash;
251  return my_part;
252 }
int m_mod_hash
incremented each time library is changed.
std::unique_ptr< SCH_PLUGIN > m_plugin
bool isModified
Library modification status.
bool IsBuffering() const
Define a library symbol object.
std::unique_ptr< PROPERTIES > m_properties
Library properties.
wxFileName fileName
Library file name.
const wxString & GetName() const

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

◆ Save()

void PART_LIB::Save ( bool  aSaveDocFile = true)

Definition at line 86 of file class_library.cpp.

87 {
88  wxCHECK_RET( m_plugin != NULL, wxString::Format( "no plugin defined for library `%s`.",
89  fileName.GetFullPath() ) );
90 
91  PROPERTIES props;
92 
93  if( !aSaveDocFile )
95 
96  m_plugin->SaveLibrary( fileName.GetFullPath(), &props );
97  isModified = false;
98 }
std::unique_ptr< SCH_PLUGIN > m_plugin
bool isModified
Library modification status.
Class PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
static const char * PropNoDocFile
const char* PropBuffering
wxFileName fileName
Library file name.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205

References fileName, Format(), isModified, m_plugin, and SCH_LEGACY_PLUGIN::PropNoDocFile.

◆ SetCache()

void PART_LIB::SetCache ( )

Definition at line 128 of file class_library.cpp.

129 {
130  (*m_properties)[ SCH_LEGACY_PLUGIN::PropNoDocFile ] = "";
131 }
static const char * PropNoDocFile
const char* PropBuffering

References SCH_LEGACY_PLUGIN::PropNoDocFile.

◆ SetFileName()

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

Definition at line 345 of file class_library.h.

345 { fileName = aFileName; }
wxFileName fileName
Library file name.

References fileName.

◆ SetPluginType()

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

Definition at line 112 of file class_library.cpp.

113 {
114  if( m_pluginType != aPluginType )
115  {
116  m_pluginType = aPluginType;
117  m_plugin.reset( SCH_IO_MGR::FindPlugin( m_pluginType ) );
118  }
119 }
std::unique_ptr< SCH_PLUGIN > m_plugin
SCH_IO_MGR::SCH_FILE_T m_pluginType

References m_plugin, and m_pluginType.

Member Data Documentation

◆ fileName

wxFileName PART_LIB::fileName
private

◆ header

wxString PART_LIB::header
private

first line of loaded library.

Definition at line 321 of file class_library.h.

◆ isModified

bool PART_LIB::isModified
private

Library modification status.

Definition at line 322 of file class_library.h.

Referenced by AddPart(), IsModified(), PART_LIB(), RemoveAlias(), ReplacePart(), and Save().

◆ m_mod_hash

int PART_LIB::m_mod_hash
private

incremented each time library is changed.

Definition at line 323 of file class_library.h.

Referenced by AddPart(), GetModHash(), RemoveAlias(), and ReplacePart().

◆ m_plugin

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

◆ m_pluginType

SCH_IO_MGR::SCH_FILE_T PART_LIB::m_pluginType
private

Definition at line 325 of file class_library.h.

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

◆ m_properties

std::unique_ptr< PROPERTIES > PART_LIB::m_properties
private

◆ timeStamp

wxDateTime PART_LIB::timeStamp
private

Library save time and date.

Definition at line 318 of file class_library.h.

Referenced by PART_LIB().

◆ type

int PART_LIB::type
private

Library type indicator.

Definition at line 316 of file class_library.h.

Referenced by PART_LIB().

◆ versionMajor

int PART_LIB::versionMajor
private

Library major version number.

Definition at line 319 of file class_library.h.

Referenced by PART_LIB().

◆ versionMinor

int PART_LIB::versionMinor
private

Library minor version number.

Definition at line 320 of file class_library.h.

Referenced by PART_LIB().


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