43#include <wx/progdlg.h>
44#include <wx/tokenzr.h>
48 SCH_IO_MGR::SCH_FILE_T aPluginType ) :
49 m_pluginType( 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();
170 SIM_MODEL::MigrateSimModel<LIB_SYMBOL>( *symbol,
nullptr );
201 wxCHECK_MSG( aEntry !=
nullptr,
nullptr,
"NULL pointer cannot be removed from library." );
217 wxASSERT( aOldSymbol !=
nullptr );
218 wxASSERT( aNewSymbol !=
nullptr );
238 std::unique_ptr<SYMBOL_LIB> lib = std::make_unique<SYMBOL_LIB>( SCH_LIB_TYPE::LT_EESCHEMA,
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( SYMBOL_LIBS::iterator it = begin(); it!=end(); ++it )
359 if( it->GetName() == aName )
369 for( SYMBOL_LIBS::iterator it = begin(); it!=end(); ++it )
381 for( 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
name = aFullProjectFilename;
489 name.SetName(
name.GetName() +
"-cache" );
492 if(
name.FileExists() )
493 return name.GetFullPath();
495 return wxEmptyString;
502 wxString libs_not_found;
505#if defined(DEBUG) && 0
506 lib_search->Show( __func__ );
509 wxArrayString lib_names;
514 if( !lib_names.empty() )
518 lib_names.GetCount(),
528 for(
unsigned i = 0; i < lib_names.GetCount(); ++i )
532 lib_dialog.
Update( i, wxString::Format(
_(
"Loading %s..." ), lib_names[i] ) );
540 wxFileName fn( fullname );
546 if( !fn.FileExists() )
548 filename = lib_search->FindValidPath( fn.GetFullPath() );
552 libs_not_found += fn.GetFullPath();
553 libs_not_found +=
'\n';
562 if( !fn.IsAbsolute() )
565 filename = fn.GetFullPath();
575 msg.Printf(
_(
"Symbol library '%s' failed to load." ), filename );
577 wxLogError( msg + wxS(
"\n" ) + ioe.
What() );
597 wxString msg = wxString::Format(
_(
"Error loading symbol library '%s'." )
607 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()
A logical library item identifier and consists of various portions much like a URI.
const UTF8 & GetLibItemName() const
Define a library symbol object.
wxString GetName() const override
void SetLib(SYMBOL_LIB *aLibrary)
LIB_SYMBOL_SPTR SharedPtr() const
SYMBOL_LIB * GetLib() const
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.
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.
static void SetLibNamesAndPaths(PROJECT *aProject, const wxString &aPaths, const wxArrayString &aNames)
SYMBOL_LIB * FindLibrary(const wxString &aName)
Find a symbol library by aName.
SYMBOL_LIB * FindLibraryByFullFileName(const wxString &aFullFileName)
wxArrayString GetLibraryNames(bool aSorted=true)
Return the list of symbol library file names without path and extension.
void LoadAllLibraries(PROJECT *aProject, bool aShowProgress=true)
Load all of the project's libraries into this container, which should be cleared before calling it.
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.
LIB_SYMBOL * FindLibSymbol(const LIB_ID &aLibId, const wxString &aLibraryName=wxEmptyString)
Search all libraries in the list for a symbol.
SYMBOL_LIB * AddLibrary(const wxString &aFileName)
Allocate and adds a symbol library to the library list.
static void GetLibNamesAndPaths(PROJECT *aProject, wxString *aPaths, wxArrayString *aNames=nullptr)
SYMBOL_LIB * GetCacheLibrary()
Object used to load, save, search, and otherwise manipulate symbol library files.
std::unique_ptr< SCH_IO > m_plugin
SCH_IO_MGR::SCH_FILE_T m_pluginType
void Create(const wxString &aFileName=wxEmptyString)
void GetSymbols(std::vector< LIB_SYMBOL * > &aSymbols) const
Load a vector with all the entries in this library.
std::unique_ptr< std::map< std::string, UTF8 > > m_properties
Library properties.
void SetPluginType(SCH_IO_MGR::SCH_FILE_T aPluginType)
SCH_LIB_TYPE type
Library type indicator.
SYMBOL_LIB(SCH_LIB_TYPE aType, const wxString &aFileName, SCH_IO_MGR::SCH_FILE_T aPluginType=SCH_IO_MGR::SCH_LEGACY)
void EnableBuffering(bool aEnable=true)
void Save(bool aSaveDocFile=true)
LIB_SYMBOL * FindSymbol(const wxString &aName) const
Find LIB_SYMBOL by aName.
void AddSymbol(LIB_SYMBOL *aSymbol)
Add aSymbol entry to library.
static SYMBOL_LIB * LoadSymbolLibrary(const wxString &aFileName)
Allocate and load a symbol library file.
bool isModified
Library modification status.
void GetSymbolNames(wxArrayString &aNames) const
Load a string array with the names of all the entries in this library.
wxDateTime timeStamp
Library save time and date.
int versionMinor
Library minor version number.
int m_mod_hash
incremented each time library is changed.
LIB_SYMBOL * ReplaceSymbol(LIB_SYMBOL *aOldSymbol, LIB_SYMBOL *aNewSymbol)
Replace an existing symbol entry in the library.
wxFileName fileName
Library file name.
int versionMajor
Library major version number.
const wxString GetName() const
Return the file name without path or extension.
LIB_SYMBOL * RemoveSymbol(LIB_SYMBOL *aEntry)
Safely remove aEntry from the library and return the next entry.
Base window classes and related definitions.
static const std::string LegacySymbolLibFileExtension
#define THROW_IO_ERROR(msg)
#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 for symbol library class.
Definition of file extensions used in Kicad.