48 #include <wx/progdlg.h> 49 #include <wx/tokenzr.h> 52 #define DUPLICATE_NAME_MSG \ 53 _( "Library \"%s\" has duplicate entry name \"%s\".\n" \ 54 "This may cause some unexpected behavior when loading components into a schematic." ) 60 m_mod_hash(
PART_LIBS::s_modify_generation ),
61 m_pluginType( aPluginType )
102 wxString tmpFileName =
fileName.GetFullPath();
104 if( !aFileName.IsEmpty() )
105 tmpFileName = aFileName;
160 std::sort( aSymbols.begin(), aSymbols.end(),
162 {
return lhs->
GetName() < rhs->GetName(); });
173 if( symbol && !symbol->
GetLib() )
174 symbol->
SetLib( const_cast<PART_LIB*>(
this ) );
203 wxCHECK_MSG( aEntry !=
NULL,
NULL,
"NULL pointer cannot be removed from library." );
219 wxASSERT( aOldPart !=
NULL );
220 wxASSERT( aNewPart !=
NULL );
242 std::vector<LIB_PART*> parts;
244 lib->GetParts( parts );
249 for(
size_t ii = 0; ii < parts.size(); ii++ )
253 part->
SetLib( lib.get() );
265 wxFileName fn = aFileName;
289 wxFileName fn( aFileName );
299 if( aIterator >= begin() && aIterator < end() )
300 insert( aIterator, lib );
315 for( PART_LIBS::iterator it = begin(); it!=end(); ++it )
317 if( it->GetName() == aName )
327 for( PART_LIBS::iterator it = begin(); it!=end(); ++it )
339 for( PART_LIBS::iterator it = begin(); it!=end(); ++it )
341 if( it->GetFullFileName() == aFullFileName )
351 wxArrayString cacheNames;
357 cacheNames.Add( lib.
GetName() );
366 for(
unsigned int i = 0; i<cacheNames.Count(); i++ )
367 names.Add( cacheNames.Item( i ) );
379 if( !aLibraryName.IsEmpty() && lib.
GetName() != aLibraryName )
393 const wxString& aEntryName,
394 const wxString& aLibraryName )
398 if( !aLibraryName.IsEmpty() && lib.
GetName() != aLibraryName )
401 wxArrayString partNames;
405 if( partNames.IsEmpty() )
408 for(
size_t i = 0; i < partNames.size(); i++ )
410 if( partNames[i].CmpNoCase( aEntryName ) == 0 )
411 aCandidates.push_back( lib.
FindPart( partNames[i] ) );
424 for( PART_LIBS::const_iterator it = begin(); it != end(); ++it )
426 hash += it->GetModHash();
439 wxString* aPaths, wxArrayString* aNames )
441 wxCHECK_RET( aProject,
"Null PROJECT in LibNamesAndPaths" );
466 wxFileName
name = aFullProjectFilename;
468 name.SetName(
name.GetName() +
"-cache" );
471 if(
name.FileExists() )
472 return name.GetFullPath();
474 return wxEmptyString;
481 wxString libs_not_found;
484 #if defined(DEBUG) && 0 485 lib_search->Show( __func__ );
488 wxArrayString lib_names;
493 if( !lib_names.empty() )
497 lib_names.GetCount(),
507 wxString progress_message;
509 for(
unsigned i = 0; i < lib_names.GetCount(); ++i )
513 lib_dialog.
Update( i,
_(
"Loading " + lib_names[i] ) );
521 wxFileName fn( fullname );
527 if( !fn.FileExists() )
533 libs_not_found += fn.GetFullPath();
534 libs_not_found +=
'\n';
543 if( !fn.IsAbsolute() )
546 filename = fn.GetFullPath();
556 msg.Printf(
_(
"Symbol library \"%s\" failed to load. Error:\n %s" ),
557 filename, ioe.
What() );
568 if( !cache_name.IsEmpty() )
575 cache_lib->SetCache();
581 cache_name, ioe.
What() );
588 if( !libs_not_found.IsEmpty() )
const wxString GetName() const
Return the file name without path or extension.
int m_mod_hash
incremented each time library is changed.
void SetLib(PART_LIB *aLibrary)
wxString FindValidPath(const wxString &aFileName) const
const UTF8 & GetLibItemName() const
LIB_PART * ReplacePart(LIB_PART *aOldPart, LIB_PART *aNewPart)
Replace an existing part entry in the library.
SCH_LIB_TYPE type
Library type indicator.
std::unique_ptr< SCH_PLUGIN > m_plugin
static void LibNamesAndPaths(PROJECT *aProject, bool doSave, wxString *aPaths, wxArrayString *aNames=NULL)
Save or load the names of the currently configured part libraries (without paths).
Container for project specific data.
This file is part of the common library TODO brief description.
void LoadAllLibraries(PROJECT *aProject, bool aShowProgress=true)
Load all of the project's libraries into this container, which should be cleared before calling it.
wxString GetName() const override
static int s_modify_generation
helper for GetModifyHash()
void Save(bool aSaveDocFile=true)
bool isModified
Library modification status.
const std::string LegacySymbolLibFileExtension
wxArrayString m_LegacyLibNames
This file is part of the common library.
virtual PROJECT_FILE & GetProjectFile() const
PART_LIB * GetCacheLibrary()
wxArrayString GetLibraryNames(bool aSorted=true)
Return the list of part library file names without path and extension.
int GetModifyHash()
Return the modification hash for all libraries.
void FindLibraryNearEntries(std::vector< LIB_PART * > &aCandidates, const wxString &aEntryName, const wxString &aLibraryName=wxEmptyString)
Search all libraries in the list for a LIB_PART using a case insensitive comparison.
LIB_PART * RemovePart(LIB_PART *aEntry)
Safely remove aEntry from the library and return the next entry.
Look for files in a number of paths.
A logical library item identifier and consists of various portions much like a URI.
PART_LIB * FindLibrary(const wxString &aName)
Find a part library by aName.
static const wxString CacheName(const wxString &aFullProjectFilename)
Return the name of the cache library after potentially fixing it from an older naming scheme.
A name/value tuple with unique names and optional values.
PROJECT_FILE is the backing store for a PROJECT, in JSON format.
void GetPartNames(wxArrayString &aNames) const
Load a string array with the names of all the entries in this library.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
void EnableBuffering(bool aEnable=true)
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
virtual const wxString What() const
A composite of Problem() and Where()
wxDateTime timeStamp
Library save time and date.
PART_LIB * AddLibrary(const wxString &aFileName)
Allocate and adds a part library to the library list.
static PART_LIB * LoadLibrary(const wxString &aFileName)
Allocate and load a symbol library file.
Define a library symbol object.
Definition of file extensions used in Kicad.
Base window classes and related definitions.
virtual bool Update(int aValue, const wxString &aNewMsg=wxEmptyString, bool *aSkip=NULL) override
std::unique_ptr< PROPERTIES > m_properties
Library properties.
LIB_PART * FindLibPart(const LIB_ID &aLibId, const wxString &aLibraryName=wxEmptyString)
Search all libraries in the list for a part.
static const char * PropNoDocFile
The property used internally by the plugin to disable writing the library documentation (....
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
SCH_IO_MGR::SCH_FILE_T m_pluginType
LIB_PART * FindPart(const wxString &aName) const
Find LIB_PART by aName.
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.
void GetParts(std::vector< LIB_PART * > &aPart) const
Load a vector with all the entries in this library.
A collection of PART_LIB objects.
void AddPart(LIB_PART *aPart)
Add aPart entry to library.
PART_LIB(SCH_LIB_TYPE aType, const wxString &aFileName, SCH_IO_MGR::SCH_FILE_T aPluginType=SCH_IO_MGR::SCH_LEGACY)
int versionMinor
Library minor version number.
wxProgressDialog with the option to also update the application progress on the taskbar
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
PART_LIB * FindLibraryByFullFileName(const wxString &aFullFileName)
void SetPluginType(SCH_IO_MGR::SCH_FILE_T aPluginType)
Definition for part library class.
void Create(const wxString &aFileName=wxEmptyString)
Object used to load, save, search, and otherwise manipulate symbol library files.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
#define THROW_IO_ERROR(msg)
int versionMajor
Library major version number.