43#include <wx/progdlg.h>
44#include <wx/tokenzr.h>
48 SCH_IO_MGR::SCH_FILE_T aPluginType ) :
64 m_properties = std::make_unique<std::map<std::string, UTF8>>();
77 wxString::Format( wxT(
"no plugin defined for library `%s`." ),
80 std::map<std::string, UTF8> props;
92 wxString tmpFileName =
fileName.GetFullPath();
94 if( !aFileName.IsEmpty() )
95 tmpFileName = aFileName;
150 std::sort( aSymbols.begin(), aSymbols.end(),
153 return lhs->GetName() < rhs->GetName();
201 wxCHECK_MSG( aEntry !=
nullptr,
nullptr,
"NULL pointer cannot be removed from library." );
217 wxASSERT( aOldSymbol !=
nullptr );
218 wxASSERT( aNewSymbol !=
nullptr );
241 std::vector<LIB_SYMBOL*> parts;
243 lib->GetSymbols( parts );
248 for(
size_t ii = 0; ii < parts.size(); ii++ )
252 part->
SetLib( lib.get() );
264 wxFileName fn = aFileName;
288 wxFileName fn( aFileName );
298 if( aIterator >= begin() && aIterator <
end() )
299 insert( aIterator, lib );
314 wxFileName fn = aFileName;
325 for(
auto it = begin(); it !=
end(); ++it )
327 if( it->GetName() == fn.GetName() )
349 push_back( cloneLib );
357 for( LEGACY_SYMBOL_LIBS::iterator it = begin(); it!=
end(); ++it )
359 if( it->GetName() == aName )
369 for( LEGACY_SYMBOL_LIBS::iterator it = begin(); it!=
end(); ++it )
381 for( LEGACY_SYMBOL_LIBS::iterator it = begin(); it!=
end(); ++it )
383 if( it->GetFullFileName() == aFullFileName )
393 wxArrayString cacheNames;
399 cacheNames.Add( lib.
GetName() );
408 for(
unsigned int i = 0; i<cacheNames.Count(); i++ )
409 names.Add( cacheNames.Item( i ) );
421 if( !aLibraryName.IsEmpty() && lib.
GetName() != aLibraryName )
435 const wxString& aEntryName,
436 const wxString& aLibraryName )
440 if( !aLibraryName.IsEmpty() && lib.
GetName() != aLibraryName )
443 wxArrayString partNames;
447 if( partNames.IsEmpty() )
450 for(
size_t i = 0; i < partNames.size(); i++ )
452 if( partNames[i].CmpNoCase( aEntryName ) == 0 )
453 aCandidates.push_back( lib.
FindSymbol( partNames[i] ) );
461 wxCHECK_RET( aProject,
"Null PROJECT in GetLibNamesAndPaths" );
466 *aPaths =
project.m_LegacyLibDir;
469 *aNames =
project.m_LegacyLibNames;
474 const wxArrayString& aNames )
476 wxCHECK_RET( aProject,
"Null PROJECT in SetLibNamesAndPaths" );
480 project.m_LegacyLibDir = aPaths;
481 project.m_LegacyLibNames = aNames;
487 wxFileName filename( aFullProjectFilename );
488 wxString
name = filename.GetName();
490 filename.SetName(
name +
"-cache" );
493 if( filename.FileExists() )
494 return filename.GetFullPath();
497 filename.SetName(
name +
".cache" );
499 if( filename.FileExists() )
500 return filename.GetFullPath();
502 return wxEmptyString;
509 wxString libs_not_found;
512#if defined(DEBUG) && 0
513 lib_search->Show( __func__ );
516 wxArrayString lib_names;
521 if( !lib_names.empty() )
525 lib_names.GetCount(),
535 for(
unsigned i = 0; i < lib_names.GetCount(); ++i )
539 lib_dialog.
Update( i, wxString::Format(
_(
"Loading %s..." ), lib_names[i] ) );
548 wxFileName fn( fullname );
554 if( !fn.FileExists() )
556 filename = lib_search->FindValidPath( fn.GetFullPath() );
560 libs_not_found += fn.GetFullPath();
561 libs_not_found +=
'\n';
570 if( !fn.IsAbsolute() )
573 filename = fn.GetFullPath();
583 msg.Printf(
_(
"Symbol library '%s' failed to load." ), filename );
585 wxLogError( msg + wxS(
"\n" ) + ioe.
What() );
605 wxString msg = wxString::Format(
_(
"Error loading symbol library '%s'." )
615 if( !libs_not_found.IsEmpty() )
wxProgressDialog with the option to also update the application progress on the taskbar
virtual bool Update(int aValue, const wxString &aNewMsg=wxEmptyString, bool *aSkip=nullptr) override
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
LEGACY_SYMBOL_LIB * GetCacheLibrary()
wxArrayString GetLibraryNames(bool aSorted=true)
Return the list of symbol library file names without path and extension.
void FindLibraryNearEntries(std::vector< LIB_SYMBOL * > &aCandidates, const wxString &aEntryName, const wxString &aLibraryName=wxEmptyString)
Search all libraries in the list for a LIB_SYMBOL using a case insensitive comparison.
LEGACY_SYMBOL_LIB * FindLibraryByFullFileName(const wxString &aFullFileName)
static void GetLibNamesAndPaths(PROJECT *aProject, wxString *aPaths, wxArrayString *aNames=nullptr)
void LoadAllLibraries(PROJECT *aProject, bool aShowProgress=true)
Load all of the project's libraries into this container, which should be cleared before calling it.
static void SetLibNamesAndPaths(PROJECT *aProject, const wxString &aPaths, const wxArrayString &aNames)
LEGACY_SYMBOL_LIB * FindLibrary(const wxString &aName)
Find a symbol library by aName.
LIB_SYMBOL * FindLibSymbol(const LIB_ID &aLibId, const wxString &aLibraryName=wxEmptyString)
Search all libraries in the list for a symbol.
LEGACY_SYMBOL_LIB * AddLibrary(const wxString &aFileName)
Allocate and adds a symbol library to the library list.
bool ReloadLibrary(const wxString &aFileName)
Refreshes the library from the (possibly updated) contents on disk.
static const wxString CacheName(const wxString &aFullProjectFilename)
Return the name of the cache library after potentially fixing it from an older naming scheme.
Object used to load, save, search, and otherwise manipulate symbol library files.
static LEGACY_SYMBOL_LIB * LoadSymbolLibrary(const wxString &aFileName)
Allocate and load a symbol library file.
wxFileName fileName
Library file name.
int versionMajor
Library major version number.
std::unique_ptr< std::map< std::string, UTF8 > > m_properties
Library properties.
void EnableBuffering(bool aEnable=true)
LIB_SYMBOL * ReplaceSymbol(LIB_SYMBOL *aOldSymbol, LIB_SYMBOL *aNewSymbol)
Replace an existing symbol entry in the library.
wxDateTime timeStamp
Library save time and date.
std::unique_ptr< SCH_IO > m_plugin
SCH_IO_MGR::SCH_FILE_T m_pluginType
LIB_SYMBOL * FindSymbol(const wxString &aName) const
Find LIB_SYMBOL by aName.
LIB_SYMBOL * RemoveSymbol(LIB_SYMBOL *aEntry)
Safely remove aEntry from the library and return the next entry.
void Create(const wxString &aFileName=wxEmptyString)
int m_mod_hash
incremented each time library is changed.
LEGACY_SYMBOL_LIB(SCH_LIB_TYPE aType, const wxString &aFileName, SCH_IO_MGR::SCH_FILE_T aPluginType=SCH_IO_MGR::SCH_LEGACY)
void GetSymbolNames(wxArrayString &aNames) const
Load a string array with the names of all the entries in this library.
void AddSymbol(LIB_SYMBOL *aSymbol)
Add aSymbol entry to library.
const wxString GetName() const
Return the file name without path or extension.
void Save(bool aSaveDocFile=true)
bool isModified
Library modification status.
void GetSymbols(std::vector< LIB_SYMBOL * > &aSymbols) const
Load a vector with all the entries in this library.
int versionMinor
Library minor version number.
void SetPluginType(SCH_IO_MGR::SCH_FILE_T aPluginType)
SCH_LIB_TYPE type
Library type indicator.
A logical library item identifier and consists of various portions much like a URI.
const UTF8 & GetLibItemName() const
Define a library symbol object.
void SetLib(LEGACY_SYMBOL_LIB *aLibrary)
LEGACY_SYMBOL_LIB * GetLib() const
wxString GetName() const override
LIB_SYMBOL_SPTR SharedPtr() const
http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared.
The backing store for a PROJECT, in JSON format.
static SEARCH_STACK * SchSearchS(PROJECT *aProject)
Accessor for Eeschema search stack.
Container for project specific data.
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
virtual PROJECT_FILE & GetProjectFile() const
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
static const char * PropNoDocFile
The property used internally by the plugin to disable writing the library documentation (....
Look for files in a number of paths.
static void MigrateSimModel(T &aSymbol, const PROJECT *aProject)
Base window classes and related definitions.
static const std::string LegacySymbolLibFileExtension
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
This file contains miscellaneous commonly used macros and functions.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition of file extensions used in Kicad.