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 308 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 57 of file class_library.cpp.

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

81 {
82 }

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

187 {
188  // add a clone, not the caller's copy, the plugin take ownership of the new symbol.
189  m_plugin->SaveSymbol( fileName.GetFullPath(), new LIB_PART( *aPart->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 }
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
PART_SPTR SharedPtr()
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, m_properties, and LIB_PART::SharedPtr().

◆ Create()

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

Definition at line 100 of file class_library.cpp.

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

140 {
141  if( aEnable )
142  (*m_properties)[ SCH_LEGACY_PLUGIN::PropBuffering ] = "";
143  else
145 }
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 166 of file class_library.cpp.

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

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

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

◆ FindPart() [2/2]

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

Definition at line 180 of file class_library.cpp.

181 {
182  return FindPart( aLibId.Format().wx_str() );
183 }
LIB_PART * FindPart(const wxString &aName) const
Find LIB_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().

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

430 { 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 437 of file class_library.h.

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

331 { 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 423 of file class_library.h.

423 { 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 148 of file class_library.cpp.

149 {
150  m_plugin->EnumerateSymbolLib( aNames, fileName.GetFullPath(), m_properties.get() );
151 
152  aNames.Sort();
153 }
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 156 of file class_library.cpp.

157 {
158  m_plugin->EnumerateSymbolLib( aSymbols, fileName.GetFullPath(), m_properties.get() );
159 
160  std::sort( aSymbols.begin(), aSymbols.end(),
161  [](LIB_PART *lhs, LIB_PART *rhs) -> bool
162  { return lhs->GetName() < rhs->GetName(); });
163 }
std::unique_ptr< SCH_PLUGIN > m_plugin
wxString GetName() const override
Define a library symbol object.
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 333 of file class_library.h.

333 { return m_pluginType; }
SCH_IO_MGR::SCH_FILE_T m_pluginType

References m_pluginType.

◆ IsBuffering()

bool PART_LIB::IsBuffering ( ) const

Definition at line 133 of file class_library.cpp.

134 {
136 }
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 121 of file class_library.cpp.

122 {
124 }
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(), and SchGetLibPart().

◆ IsModified()

bool PART_LIB::IsModified ( ) const
inline

Definition at line 341 of file class_library.h.

342  {
343  return isModified;
344  }
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 359 of file class_library.h.

359 { 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 238 of file class_library.cpp.

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

202 {
203  wxCHECK_MSG( aEntry != NULL, NULL, "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 NULL;
214 }
int m_mod_hash
incremented each time library is changed.
std::unique_ptr< SCH_PLUGIN > m_plugin
wxString GetName() const override
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 217 of file class_library.cpp.

218 {
219  wxASSERT( aOldPart != NULL );
220  wxASSERT( aNewPart != NULL );
221 
222  m_plugin->DeleteSymbol( fileName.GetFullPath(), aOldPart->GetName(), m_properties.get() );
223 
224  LIB_PART* my_part = new LIB_PART( *aNewPart, 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 }
int m_mod_hash
incremented each time library is changed.
std::unique_ptr< SCH_PLUGIN > m_plugin
wxString GetName() const override
bool isModified
Library modification status.
bool IsBuffering() const
#define NULL
Define a library symbol object.
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 85 of file class_library.cpp.

86 {
87  wxCHECK_RET( m_plugin != NULL, wxString::Format( "no plugin defined for library `%s`.",
88  fileName.GetFullPath() ) );
89 
90  PROPERTIES props;
91 
92  if( !aSaveDocFile )
94 
95  m_plugin->SaveLibrary( fileName.GetFullPath(), &props );
96  isModified = false;
97 }
std::unique_ptr< SCH_PLUGIN > m_plugin
bool isModified
Library modification status.
PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
#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, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201

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

◆ SetCache()

void PART_LIB::SetCache ( )

Definition at line 127 of file class_library.cpp.

128 {
129  (*m_properties)[ SCH_LEGACY_PLUGIN::PropNoDocFile ] = "";
130 }
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 339 of file class_library.h.

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

References fileName.

◆ SetPluginType()

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

Definition at line 111 of file class_library.cpp.

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

◆ isModified

bool PART_LIB::isModified
private

Library modification status.

Definition at line 316 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 317 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 319 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 312 of file class_library.h.

Referenced by PART_LIB().

◆ type

SCH_LIB_TYPE PART_LIB::type
private

Library type indicator.

Definition at line 310 of file class_library.h.

Referenced by PART_LIB().

◆ versionMajor

int PART_LIB::versionMajor
private

Library major version number.

Definition at line 313 of file class_library.h.

Referenced by PART_LIB().

◆ versionMinor

int PART_LIB::versionMinor
private

Library minor version number.

Definition at line 314 of file class_library.h.

Referenced by PART_LIB().


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