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 (SCH_LIB_TYPE 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 GetPartNames (wxArrayString &aNames) const
 Load a string array with the names of all the entries in this library. More...
 
void GetParts (std::vector< LIB_PART * > &aPart) const
 Load a vector with all the entries in this library. More...
 
LIB_PARTFindPart (const wxString &aName) const
 Find LIB_PART by aName. More...
 
LIB_PARTFindPart (const LIB_ID &aLibId) const
 
void AddPart (LIB_PART *aPart)
 Add aPart entry to library. More...
 
LIB_PARTRemovePart (LIB_PART *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

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< PROPERTIESm_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 324 of file class_library.h.

Constructor & Destructor Documentation

◆ PART_LIB()

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

Definition at line 56 of file class_library.cpp.

56  :
57  // start @ != 0 so each additional library added
58  // is immediately detectable, zero would not be.
60  m_pluginType( aPluginType )
61 {
62  type = aType;
63  isModified = false;
64  timeStamp = 0;
65  timeStamp = wxDateTime::Now();
66  versionMajor = 0; // Will be updated after reading the lib file
67  versionMinor = 0; // Will be updated after reading the lib file
68 
69  fileName = aFileName;
70 
71  if( !fileName.IsOk() )
72  fileName = "unnamed.lib";
73 
74  m_plugin.reset( SCH_IO_MGR::FindPlugin( m_pluginType ) );
75  m_properties = std::make_unique<PROPERTIES>();
76 }
int m_mod_hash
incremented each time library is changed.
SCH_LIB_TYPE type
Library type indicator.
std::unique_ptr< SCH_PLUGIN > m_plugin
bool isModified
Library modification status.
static int GetModifyGeneration()
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.

◆ ~PART_LIB()

PART_LIB::~PART_LIB ( )

Definition at line 79 of file class_library.cpp.

80 {
81 }

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 185 of file class_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(), new LIB_PART( *aPart->SharedPtr().get(), this ),
189  m_properties.get() );
190 
191  // If we are not buffering, the library file is updated immediately when the plugin
192  // SaveSymbol() function is called.
193  if( IsBuffering() )
194  isModified = true;
195 
196  ++m_mod_hash;
197 }
int m_mod_hash
incremented each time library is changed.
std::unique_ptr< SCH_PLUGIN > m_plugin
bool isModified
Library modification status.
PART_SPTR SharedPtr() const
Definition: lib_symbol.h:103
bool IsBuffering() const
Define a library symbol object.
Definition: lib_symbol.h:93
std::unique_ptr< PROPERTIES > m_properties
Library properties.
wxFileName fileName
Library file name.

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

◆ Create()

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

Definition at line 99 of file class_library.cpp.

100 {
101  wxString tmpFileName = fileName.GetFullPath();
102 
103  if( !aFileName.IsEmpty() )
104  tmpFileName = aFileName;
105 
106  m_plugin->CreateSymbolLib( tmpFileName, m_properties.get() );
107 }
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 138 of file class_library.cpp.

139 {
140  if( aEnable )
141  (*m_properties)[ SCH_LEGACY_PLUGIN::PropBuffering ] = "";
142  else
144 }
std::unique_ptr< PROPERTIES > m_properties
Library properties.
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.

◆ FindPart() [1/2]

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

Find LIB_PART by aName.

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

Definition at line 165 of file class_library.cpp.

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

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

Referenced by PART_LIBS::FindLibPart(), PART_LIBS::FindLibraryNearEntries(), FindPart(), SchGetLibPart(), and SCH_SCREEN::UpdateSymbolLinks().

◆ FindPart() [2/2]

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

Definition at line 179 of file class_library.cpp.

180 {
181  return FindPart( aLibId.Format().wx_str() );
182 }
LIB_PART * FindPart(const wxString &aName) const
Find LIB_PART by aName.
UTF8 Format() const
Definition: lib_id.cpp:233
wxString wx_str() const
Definition: utf8.cpp:51

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

◆ 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 433 of file class_library.h.

433 { 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 440 of file class_library.h.

441  {
442  /* for now is the filename without path or extension.
443 
444  Technically the library should not know its logical name!
445  This will eventually come out of a pair of lookup tables using a
446  reverse lookup using the full name or library pointer as a key.
447  Search will be by project lookup table and then user lookup table if
448  not found.
449  */
450  return fileName.GetName();
451  }
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 334 of file class_library.h.

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

References m_mod_hash.

◆ GetName()

const wxString PART_LIB::GetName ( void  ) const
inline

Return the file name without path or extension.

Returns
Name of library file.

Definition at line 426 of file class_library.h.

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

References fileName.

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

◆ GetPartNames()

void PART_LIB::GetPartNames ( 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 147 of file class_library.cpp.

148 {
149  m_plugin->EnumerateSymbolLib( aNames, fileName.GetFullPath(), m_properties.get() );
150 
151  aNames.Sort();
152 }
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().

◆ GetParts()

void PART_LIB::GetParts ( std::vector< LIB_PART * > &  aPart) const

Load a vector with all the entries in this library.

Parameters
aParts- vector to receive the aliases.

Definition at line 155 of file class_library.cpp.

156 {
157  m_plugin->EnumerateSymbolLib( aSymbols, fileName.GetFullPath(), m_properties.get() );
158 
159  std::sort( aSymbols.begin(), aSymbols.end(),
160  [](LIB_PART *lhs, LIB_PART *rhs) -> bool
161  { return lhs->GetName() < rhs->GetName(); });
162 }
std::unique_ptr< SCH_PLUGIN > m_plugin
wxString GetName() const override
Definition: lib_symbol.h:129
Define a library symbol object.
Definition: lib_symbol.h:93
std::unique_ptr< PROPERTIES > m_properties
Library properties.
wxFileName fileName
Library file name.

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

Referenced by LEGACY_RESCUER::OpenRescueLibrary().

◆ GetPluginType()

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

Definition at line 336 of file class_library.h.

336 { return m_pluginType; }
SCH_IO_MGR::SCH_FILE_T m_pluginType

References m_pluginType.

◆ IsBuffering()

bool PART_LIB::IsBuffering ( ) const

Definition at line 132 of file class_library.cpp.

133 {
135 }
std::unique_ptr< PROPERTIES > m_properties
Library properties.
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.

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

◆ IsCache()

bool PART_LIB::IsCache ( ) const

Definition at line 120 of file class_library.cpp.

121 {
123 }
std::unique_ptr< PROPERTIES > m_properties
Library properties.
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 PART_LIBS::GetLibraryNames(), SchGetLibPart(), and SCH_SCREEN::UpdateSymbolLinks().

◆ IsModified()

bool PART_LIB::IsModified ( ) const
inline

Definition at line 344 of file class_library.h.

345  {
346  return isModified;
347  }
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 362 of file class_library.h.

362 { 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 237 of file class_library.cpp.

238 {
239  std::unique_ptr<PART_LIB> lib = std::make_unique<PART_LIB>( SCH_LIB_TYPE::LT_EESCHEMA, aFileName );
240 
241  std::vector<LIB_PART*> parts;
242  // This loads the library.
243  lib->GetParts( parts );
244 
245  // Now, set the LIB_PART m_library member but it will only be used
246  // when loading legacy libraries in the future. Once the symbols in the
247  // schematic have a full #LIB_ID, this will not get called.
248  for( size_t ii = 0; ii < parts.size(); ii++ )
249  {
250  LIB_PART* part = parts[ii];
251 
252  part->SetLib( lib.get() );
253  }
254 
255  PART_LIB* ret = lib.release();
256  return ret;
257 }
void SetLib(PART_LIB *aLibrary)
Definition: lib_symbol.h:173
Define a library symbol object.
Definition: lib_symbol.h:93
Object used to load, save, search, and otherwise manipulate symbol library files.

References LT_EESCHEMA, and LIB_PART::SetLib().

Referenced by PART_LIBS::AddLibrary().

◆ RemovePart()

LIB_PART * PART_LIB::RemovePart ( LIB_PART 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 200 of file class_library.cpp.

201 {
202  wxCHECK_MSG( aEntry != NULL, NULL, "NULL pointer cannot be removed from library." );
203 
204  m_plugin->DeleteSymbol( fileName.GetFullPath(), aEntry->GetName(), m_properties.get() );
205 
206  // If we are not buffering, the library file is updated immediately when the plugin
207  // SaveSymbol() function is called.
208  if( IsBuffering() )
209  isModified = true;
210 
211  ++m_mod_hash;
212  return NULL;
213 }
int m_mod_hash
incremented each time library is changed.
std::unique_ptr< SCH_PLUGIN > m_plugin
wxString GetName() const override
Definition: lib_symbol.h:129
bool isModified
Library modification status.
bool IsBuffering() const
#define NULL
std::unique_ptr< PROPERTIES > m_properties
Library properties.
wxFileName fileName
Library file name.

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

◆ 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 216 of file class_library.cpp.

217 {
218  wxASSERT( aOldPart != NULL );
219  wxASSERT( aNewPart != NULL );
220 
221  m_plugin->DeleteSymbol( fileName.GetFullPath(), aOldPart->GetName(), m_properties.get() );
222 
223  LIB_PART* my_part = new LIB_PART( *aNewPart, this );
224 
225  m_plugin->SaveSymbol( fileName.GetFullPath(), my_part, m_properties.get() );
226 
227  // If we are not buffering, the library file is updated immediately when the plugin
228  // SaveSymbol() function is called.
229  if( IsBuffering() )
230  isModified = true;
231 
232  ++m_mod_hash;
233  return my_part;
234 }
int m_mod_hash
incremented each time library is changed.
std::unique_ptr< SCH_PLUGIN > m_plugin
wxString GetName() const override
Definition: lib_symbol.h:129
bool isModified
Library modification status.
bool IsBuffering() const
#define NULL
Define a library symbol object.
Definition: lib_symbol.h:93
std::unique_ptr< PROPERTIES > m_properties
Library properties.
wxFileName fileName
Library file name.

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

◆ Save()

void PART_LIB::Save ( bool  aSaveDocFile = true)

Definition at line 84 of file class_library.cpp.

85 {
86  wxCHECK_RET( m_plugin != NULL, wxString::Format( "no plugin defined for library `%s`.",
87  fileName.GetFullPath() ) );
88 
89  PROPERTIES props;
90 
91  if( !aSaveDocFile )
93 
94  m_plugin->SaveLibrary( fileName.GetFullPath(), &props );
95  isModified = false;
96 }
std::unique_ptr< SCH_PLUGIN > m_plugin
bool isModified
Library modification status.
A name/value tuple with unique names and optional values.
Definition: properties.h:33
#define NULL
static const char * PropNoDocFile
The property used internally by the plugin to disable writing the library documentation (....
wxFileName fileName
Library file name.
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, NULL, and SCH_LEGACY_PLUGIN::PropNoDocFile.

◆ SetCache()

void PART_LIB::SetCache ( )

Definition at line 126 of file class_library.cpp.

127 {
128  (*m_properties)[ SCH_LEGACY_PLUGIN::PropNoDocFile ] = "";
129 }
static const char * PropNoDocFile
The property used internally by the plugin to disable writing the library documentation (....

References SCH_LEGACY_PLUGIN::PropNoDocFile.

◆ SetFileName()

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

Definition at line 342 of file class_library.h.

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

References fileName.

◆ SetPluginType()

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

Definition at line 110 of file class_library.cpp.

111 {
112  if( m_pluginType != aPluginType )
113  {
114  m_pluginType = aPluginType;
115  m_plugin.reset( SCH_IO_MGR::FindPlugin( m_pluginType ) );
116  }
117 }
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 469 of file class_library.h.

◆ isModified

bool PART_LIB::isModified
private

Library modification status.

Definition at line 470 of file class_library.h.

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

◆ m_mod_hash

int PART_LIB::m_mod_hash
private

incremented each time library is changed.

Definition at line 471 of file class_library.h.

Referenced by AddPart(), GetModHash(), RemovePart(), 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 473 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 466 of file class_library.h.

Referenced by PART_LIB().

◆ type

SCH_LIB_TYPE PART_LIB::type
private

Library type indicator.

Definition at line 464 of file class_library.h.

Referenced by PART_LIB().

◆ versionMajor

int PART_LIB::versionMajor
private

Library major version number.

Definition at line 467 of file class_library.h.

Referenced by PART_LIB().

◆ versionMinor

int PART_LIB::versionMinor
private

Library minor version number.

Definition at line 468 of file class_library.h.

Referenced by PART_LIB().


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