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 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

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.

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

59  :
60  // start @ != 0 so each additional library added
61  // is immediately detectable, zero would not be.
63  m_pluginType( aPluginType )
64 {
65  type = aType;
66  isModified = false;
67  timeStamp = 0;
68  timeStamp = wxDateTime::Now();
69  versionMajor = 0; // Will be updated after reading the lib file
70  versionMinor = 0; // Will be updated after reading the lib file
71 
72  fileName = aFileName;
73 
74  if( !fileName.IsOk() )
75  fileName = "unnamed.lib";
76 
77  m_plugin.reset( SCH_IO_MGR::FindPlugin( m_pluginType ) );
78  m_properties = std::make_unique<PROPERTIES>();
79 }
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 82 of file class_library.cpp.

83 {
84 }

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

189 {
190  // add a clone, not the caller's copy, the plugin take ownership of the new symbol.
191  m_plugin->SaveSymbol( fileName.GetFullPath(), new LIB_PART( *aPart->SharedPtr().get(), this ),
192  m_properties.get() );
193 
194  // If we are not buffering, the library file is updated immediately when the plugin
195  // SaveSymbol() function is called.
196  if( IsBuffering() )
197  isModified = true;
198 
199  ++m_mod_hash;
200 }
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 102 of file class_library.cpp.

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

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

169 {
170  LIB_PART* symbol = m_plugin->LoadSymbol( fileName.GetFullPath(), aName, m_properties.get() );
171 
172  // Set the library to this even though technically the legacy cache plugin owns the
173  // symbols. This allows the symbol library table conversion tool to determine the
174  // correct library where the symbol was found.
175  if( symbol && !symbol->GetLib() )
176  symbol->SetLib( const_cast<PART_LIB*>( this ) );
177 
178  return symbol;
179 }
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 182 of file class_library.cpp.

183 {
184  return FindPart( aLibId.Format().wx_str() );
185 }
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 425 of file class_library.h.

425 { 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 432 of file class_library.h.

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

326 { 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 418 of file class_library.h.

418 { 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 150 of file class_library.cpp.

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

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

◆ GetPluginType()

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

Definition at line 328 of file class_library.h.

328 { return m_pluginType; }
SCH_IO_MGR::SCH_FILE_T m_pluginType

References m_pluginType.

◆ IsBuffering()

bool PART_LIB::IsBuffering ( ) const

Definition at line 135 of file class_library.cpp.

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

124 {
126 }
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 336 of file class_library.h.

337  {
338  return isModified;
339  }
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 354 of file class_library.h.

354 { 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 240 of file class_library.cpp.

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

204 {
205  wxCHECK_MSG( aEntry != NULL, NULL, "NULL pointer cannot be removed from library." );
206 
207  m_plugin->DeleteSymbol( fileName.GetFullPath(), aEntry->GetName(), 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  return NULL;
216 }
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 219 of file class_library.cpp.

220 {
221  wxASSERT( aOldPart != NULL );
222  wxASSERT( aNewPart != NULL );
223 
224  m_plugin->DeleteSymbol( fileName.GetFullPath(), aOldPart->GetName(), m_properties.get() );
225 
226  LIB_PART* my_part = new LIB_PART( *aNewPart, this );
227 
228  m_plugin->SaveSymbol( fileName.GetFullPath(), my_part, m_properties.get() );
229 
230  // If we are not buffering, the library file is updated immediately when the plugin
231  // SaveSymbol() function is called.
232  if( IsBuffering() )
233  isModified = true;
234 
235  ++m_mod_hash;
236  return my_part;
237 }
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 87 of file class_library.cpp.

88 {
89  wxCHECK_RET( m_plugin != NULL, wxString::Format( "no plugin defined for library `%s`.",
90  fileName.GetFullPath() ) );
91 
92  PROPERTIES props;
93 
94  if( !aSaveDocFile )
96 
97  m_plugin->SaveLibrary( fileName.GetFullPath(), &props );
98  isModified = false;
99 }
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:205

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

◆ SetCache()

void PART_LIB::SetCache ( )

Definition at line 129 of file class_library.cpp.

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

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

References fileName.

◆ SetPluginType()

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

Definition at line 113 of file class_library.cpp.

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

◆ isModified

bool PART_LIB::isModified
private

Library modification status.

Definition at line 311 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 312 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 314 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 307 of file class_library.h.

Referenced by PART_LIB().

◆ type

int PART_LIB::type
private

Library type indicator.

Definition at line 305 of file class_library.h.

Referenced by PART_LIB().

◆ versionMajor

int PART_LIB::versionMajor
private

Library major version number.

Definition at line 308 of file class_library.h.

Referenced by PART_LIB().

◆ versionMinor

int PART_LIB::versionMinor
private

Library minor version number.

Definition at line 309 of file class_library.h.

Referenced by PART_LIB().


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