32#include <unordered_map>
66 if( buffer.IsModified() )
83 if(
const auto libBufIt =
m_libs.find( aLibrary ); libBufIt !=
m_libs.end() )
84 return libBufIt->second.GetHash();
92 wxFileName fn( *uri );
104 else if( fn.IsFileReadable() )
106 mtime = fn.GetModificationTime().GetValue().GetValue();
109 size_t base = std::hash<std::string>{}( aLibrary.ToStdString() + uri->ToStdString() );
110 return static_cast<int>( base ^
static_cast<size_t>( mtime ) );
129 res.Add( row->Nickname() );
132 res.Sort( [](
const wxString& lhs,
const wxString& rhs ) ->
int
142 SCH_IO_MGR::SCH_FILE_T aFileType )
144 wxCHECK( aFileType != SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY,
false );
146 wxFileName fn( aFileName );
148 if( fn.FileExists() && !fn.IsFileWritable() )
153 std::map<std::string, UTF8> properties;
157 auto it =
m_libs.find( aLibrary );
164 const std::deque<std::shared_ptr<SYMBOL_BUFFER>>& symbolBuffers = libBuf.
GetBuffers();
166 wxFileName original, destination( aFileName );
177 bool toOriginal = original == destination;
185 for(
const std::shared_ptr<SYMBOL_BUFFER>& symbolBuf : symbolBuffers )
187 wxCHECK2( symbolBuf,
continue );
189 if( !libBuf.
SaveBuffer( *symbolBuf, aFileName, &*pi,
true ) )
198 if(
res && toOriginal )
201 for(
const std::shared_ptr<SYMBOL_BUFFER>& deletedBuf : libBuf.
GetDeletedBuffers() )
203 wxCHECK2( deletedBuf,
continue );
205 const wxString& originalName = deletedBuf->GetOriginal().GetName();
209 if( pi->LoadSymbol( aFileName, originalName ) )
210 pi->DeleteSymbol( aFileName, originalName, &properties );
214 wxLogError(
_(
"Error deleting symbol %s from library '%s'." ) + wxS(
"\n%s" ),
232 if( symbol->IsDerived() )
234 std::shared_ptr< LIB_SYMBOL > oldParent = symbol->GetParent().lock();
236 wxCHECK_MSG( oldParent,
false,
237 wxString::Format( wxT(
"Derived symbol '%s' found with undefined parent." ),
238 symbol->GetName() ) );
240 LIB_SYMBOL* libParent = pi->LoadSymbol( aFileName, oldParent->
GetName(), &properties );
244 std::unique_ptr<LIB_SYMBOL> newParent = std::make_unique<LIB_SYMBOL>( *oldParent );
245 pi->SaveSymbol( aFileName, std::move( newParent ), &properties );
249 libParent = pi->LoadSymbol( aFileName, oldParent->
GetName(), &properties );
269 std::unique_ptr<LIB_SYMBOL> newSymbol = std::make_unique<LIB_SYMBOL>( *symbol );
270 newSymbol->SetParent( libParent );
271 pi->SaveSymbol( aFileName, std::move( newSymbol ), &properties );
273 else if( !pi->LoadSymbol( aFileName, symbol->GetName(), &properties ) )
275 pi->SaveSymbol( aFileName, std::make_unique<LIB_SYMBOL>( *symbol ), &properties );
288 pi->SaveLibrary( aFileName );
303 auto it =
m_libs.find( aLibrary );
304 return it !=
m_libs.end() ? it->second.IsModified() :
false;
310 auto libIt =
m_libs.find( aLibrary );
312 if( libIt ==
m_libs.end() )
316 const std::shared_ptr<SYMBOL_BUFFER> symbolBuf = buf.
GetBuffer( aSymbolName );
318 return symbolBuf ? symbolBuf->IsModified() :
false;
324 auto libIt =
m_libs.find( aLibrary );
326 if( libIt ==
m_libs.end() )
330 std::shared_ptr<SYMBOL_BUFFER> symbolBuf = buf.
GetBuffer( aSymbolName );
332 wxCHECK( symbolBuf, );
334 symbolBuf->GetScreen()->SetContentModified();
340 auto libIt =
m_libs.find( aLibrary );
342 if( libIt ==
m_libs.end() )
345 for(
const std::shared_ptr<SYMBOL_BUFFER>& symbolBuf : libIt->second.GetBuffers() )
373 std::list<LIB_SYMBOL*> ret;
374 auto libIt =
m_libs.find( aLibrary );
376 if( libIt !=
m_libs.end() )
378 for(
const std::shared_ptr<SYMBOL_BUFFER>& symbolBuf : libIt->second.GetBuffers() )
379 ret.push_back( &symbolBuf->GetSymbol() );
384 std::vector<LIB_SYMBOL*> symbols = adapter->
GetSymbols( aLibrary );
386 std::copy( symbols.begin(), symbols.end(), std::back_inserter( ret ) );
399 if( !bufferedSymbol )
408 if( symbol ==
nullptr )
416 std::shared_ptr<LIB_SYMBOL> parent = symbol->
GetParent().lock();
417 wxCHECK_MSG( parent,
nullptr, wxString::Format(
"Derived symbol '%s' found with undefined parent.",
421 bufferedParent = libBuf.
GetSymbol( parent->GetName() );
423 if( !bufferedParent )
425 std::unique_ptr<LIB_SYMBOL> newParent = std::make_unique<LIB_SYMBOL>( *parent );
426 bufferedParent = newParent.get();
427 libBuf.
CreateBuffer( std::move( newParent ), std::make_unique<SCH_SCREEN>() );
431 std::unique_ptr<LIB_SYMBOL> newSymbol = std::make_unique<LIB_SYMBOL>( *symbol );
432 bufferedSymbol = newSymbol.get();
435 newSymbol->SetParent( bufferedParent );
437 libBuf.
CreateBuffer( std::move( newSymbol ), std::make_unique<SCH_SCREEN>() );
443 msg.Printf(
_(
"Error loading symbol %s from library '%s'." ),
447 bufferedSymbol =
nullptr;
451 return bufferedSymbol;
457 auto it =
m_libs.find( aLibrary );
458 wxCHECK( it !=
m_libs.end(),
nullptr );
461 std::shared_ptr<SYMBOL_BUFFER> symbolBuf = buf.
GetBuffer( aSymbolName );
463 return symbolBuf ? symbolBuf->GetScreen() :
nullptr;
475 return libBuf.
GetBuffer( aSymbolName ).get();
482 std::shared_ptr<SYMBOL_BUFFER> symbolBuf = libBuf.
GetBuffer( aSymbol->
GetName() );
486 LIB_SYMBOL& bufferedSymbol = symbolBuf->GetSymbol();
490 bufferedSymbol = *aSymbol;
493 symbolBuf->GetScreen()->SetContentModified();
497 std::unique_ptr<LIB_SYMBOL> symbolCopy = std::make_unique<LIB_SYMBOL>( *aSymbol,
nullptr );
501 std::unique_ptr<SCH_SCREEN> newScreen = std::make_unique<SCH_SCREEN>();
502 newScreen->SetContentModified();
504 libBuf.
CreateBuffer( std::move( symbolCopy ), std::move( newScreen ),
true );
512 const wxString& aLibrary )
515 std::shared_ptr<SYMBOL_BUFFER> symbolBuf = libBuf.
GetBuffer( aOldName );
517 wxCHECK( symbolBuf && aSymbol,
false );
533 std::shared_ptr<SYMBOL_BUFFER> symbolBuf = it->second.GetBuffer( aIdToRevert.
GetLibItemName() );
534 wxCHECK( symbolBuf, aIdToRevert );
535 LIB_SYMBOL original( symbolBuf->GetOriginal() );
544 symbolBuf->GetSymbol() = original;
548 symbolBuf->GetScreen()->SetContentModified(
false );
556 auto it =
m_libs.find( aLibrary );
576 for(
auto& [libName, libBuffer] :
m_libs )
578 if( !libBuffer.IsModified() )
583 libBuffer.RevertDeletedBuffers();
585 for(
const std::shared_ptr<SYMBOL_BUFFER>& buffer : libBuffer.GetBuffers() )
587 if( !buffer->IsModified() )
591 libBuffer.UpdateBuffer( *buffer, buffer->GetOriginal() );
592 buffer->GetScreen()->SetContentModified(
false );
595 libBuffer.RevertAddedBuffers();
606 std::shared_ptr<SYMBOL_BUFFER> symbolBuf = libBuf.
GetBuffer( aSymbolName );
607 wxCHECK( symbolBuf,
false );
621 auto libIt =
m_libs.find( aLibrary );
623 if( libIt !=
m_libs.end() )
625 LIB_SYMBOL* symbol = libIt->second.GetSymbol( aSymbolName );
637 symbol = adapter->
LoadSymbol( aLibrary, aSymbolName );
643 msg.Printf(
_(
"Cannot load symbol '%s' from library '%s'." ),
655 auto libBufIt =
m_libs.find( aLibrary );
658 if( libBufIt !=
m_libs.end() )
659 return libBufIt->second.GetBuffer( aSymbolName ) !=
nullptr;
665 symbol = adapter->
LoadSymbol( aLibrary, aSymbolName );
672 return symbol !=
nullptr;
678 wxArrayString existing;
685 for( wxString& candidate : existing )
687 if( candidate.CmpNoCase( unescapedName ) == 0 )
697 if( aLibrary.IsEmpty() )
700 if(
m_libs.count( aLibrary ) > 0 )
705 return adapter->
HasLibrary( aLibrary, aCheckEnabled );
711 wxString
name =
"New_Library";
718 for(
unsigned int i = 0; i < std::numeric_limits<unsigned int>::max(); ++i )
721 return name + wxString::Format(
"%u", i );
725 return wxEmptyString;
739 wxArrayString& aList )
764 wxFileName fn( aFilePath );
780 if( schFileType == SCH_IO_MGR::SCH_FILE_UNKNOWN )
781 schFileType = SCH_IO_MGR::SCH_LEGACY;
787 wxCHECK( optTable,
false );
799 table->Save().map_error(
802 wxMessageBox(
_(
"Error saving library table:\n\n" ) + aError.
message,
803 _(
"File Save Error" ), wxOK | wxICON_ERROR );
812 wxCHECK( schFileType != SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY,
false );
816 table->Rows().erase(
table->Rows().end() - 1 );
818 table->Save().map_error(
821 wxMessageBox(
_(
"Error saving library table:\n\n" ) + aError.
message,
822 _(
"File Save Error" ), wxOK | wxICON_ERROR );
844 std::set<LIB_SYMBOL*> symbols;
850 symbols.insert( symbol );
858 auto it =
m_libs.find( aLibrary );
869 if( symbol->IsDerived() )
871 std::shared_ptr<LIB_SYMBOL> oldParent = symbol->GetParent().lock();
873 wxCHECK_MSG( oldParent, buf, wxString::Format(
"Derived symbol '%s' found with undefined parent.",
874 symbol->GetName() ) );
880 std::unique_ptr<LIB_SYMBOL> newParent = std::make_unique<LIB_SYMBOL>( *oldParent.get() );
881 libParent = newParent.get();
882 buf.
CreateBuffer( std::move( newParent ), std::make_unique<SCH_SCREEN>() );
885 std::unique_ptr<LIB_SYMBOL> newSymbol = std::make_unique<LIB_SYMBOL>( *symbol );
886 newSymbol->SetParent( libParent );
887 buf.
CreateBuffer( std::move( newSymbol ), std::make_unique<SCH_SCREEN>() );
889 else if( !buf.
GetSymbol( symbol->GetName() ) )
891 buf.
CreateBuffer( std::make_unique<LIB_SYMBOL>( *symbol ), std::make_unique<SCH_SCREEN>() );
906 catch(
const std::exception& e )
908 wxLogError(
_(
"Error updating library buffer: %s" ), e.what() );
913 wxLogError(
_(
"Error updating library buffer." ) );
925 std::vector<wxString> dropped;
929 if( it->second.IsModified() || aKeep.contains( it->first ) )
935 dropped.push_back( it->first );
965 if(
m_original->GetLibId().GetLibNickname() !=
m_symbol->GetLibId().GetLibNickname() )
980 if(
m_original->GetLibId().GetLibNickname() !=
m_symbol->GetLibId().GetLibNickname() )
996 std::shared_ptr<SYMBOL_BUFFER> buf =
GetBuffer( aAlias );
1001 return &buf->GetSymbol();
1008 wxASSERT( aCopy->GetLib() ==
nullptr );
1012 LIB_ID libId = aCopy->GetLibId();
1014 aCopy->SetLibId( libId );
1016 std::shared_ptr<SYMBOL_BUFFER> symbolBuf = std::make_shared<SYMBOL_BUFFER>( std::move( aCopy ),
1017 std::move( aScreen ) );
1018 m_symbols.push_back( std::move( symbolBuf ) );
1033 bufferedSymbol = aCopy;
1042 const auto sameBufferPredicate =
1043 [&](
const std::shared_ptr<SYMBOL_BUFFER>& aBuf )
1045 return aBuf.get() == &aSymbolBuf;
1048 wxCHECK( std::any_of(
m_symbols.begin(),
m_symbols.end(), sameBufferPredicate ),
false );
1060 auto symbolBufIt = std::find_if(
m_symbols.begin(),
m_symbols.end(), sameBufferPredicate );
1061 wxCHECK( symbolBufIt !=
m_symbols.end(),
false );
1073 for( std::shared_ptr<SYMBOL_BUFFER>& buffer :
m_deleted )
1084 [&](
const std::shared_ptr<SYMBOL_BUFFER>& item )
1086 for(
const std::shared_ptr<SYMBOL_BUFFER>& added :
m_added )
1088 if( added.get() == item.get() )
1105 return parent ? parent->GetName() : wxString();
1112 if( wxFileName::FileExists( aFileName ) || wxFileName::DirExists( aFileName ) )
1114 wxArrayString names;
1122 wxLogError(
_(
"Error loading library '%s'." ) + wxS(
"\n%s" ), aFileName, ioe.
What() );
1129 for(
const std::shared_ptr<SYMBOL_BUFFER>& symbolBuf :
m_symbols )
1131 wxCHECK2( symbolBuf,
continue );
1133 if( symbolBuf->IsModified() && !
SaveBuffer( *symbolBuf, aFileName, aPlugin,
true ) )
1144 wxCHECK( !aFileName.IsEmpty(),
false );
1146 wxString errorMsg =
_(
"Error saving symbol %s to library '%s'." ) + wxS(
"\n%s" );
1149 std::map<std::string, UTF8> properties;
1155 wxArrayString derivedSymbols;
1157 for(
const std::shared_ptr<SYMBOL_BUFFER>& buf :
m_symbols )
1160 derivedSymbols.push_back( buf->GetSymbol().GetName() );
1165 const wxString originalName = originalSymbol.
GetName();
1171 [&](
const std::shared_ptr<SYMBOL_BUFFER>& aBuf )
1173 return aBuf->GetSymbol().GetName() == originalName;
1178 if( !nameTaken && aPlugin->
LoadSymbol( aFileName, originalName ) )
1179 aPlugin->
DeleteSymbol( aFileName, originalName, &properties );
1191 std::unique_ptr<LIB_SYMBOL> newCachedSymbol = std::make_unique<LIB_SYMBOL>( libSymbol );
1192 std::shared_ptr<LIB_SYMBOL> bufferedParent = libSymbol.
GetParent().lock();
1194 wxCHECK( bufferedParent,
false );
1201 cachedParent = aPlugin->
LoadSymbol( aFileName, bufferedParent->GetName() );
1212 std::unique_ptr<LIB_SYMBOL> newParent = std::make_unique<LIB_SYMBOL>( *bufferedParent );
1213 newCachedSymbol->SetParent( newParent.get() );
1215 const wxString cachedParentName = newParent->GetName();
1219 aPlugin->
SaveSymbol( aFileName, std::move( newParent ), aBuffer ? &properties :
nullptr );
1227 const wxString newCachedSymbolName = newCachedSymbol->GetName();
1231 aPlugin->
SaveSymbol( aFileName, std::move( newCachedSymbol ), aBuffer ? &properties :
nullptr );
1235 wxLogError( errorMsg,
UnescapeString( newCachedSymbolName ), aFileName, ioe.
What() );
1239 std::unique_ptr<LIB_SYMBOL> originalParent = std::make_unique<LIB_SYMBOL>( *bufferedParent );
1241 aSymbolBuf.
SetOriginal( std::move( originalParent ) );
1243 std::unique_ptr<LIB_SYMBOL> newSymbol = std::make_unique<LIB_SYMBOL>( libSymbol );
1244 newSymbol->SetParent( &parentRef );
1258 for(
const auto& [
name, file] : bufferedParent->EmbeddedFileMap() )
1264 newCachedSymbol->SetParent( cachedParent );
1266 const wxString newCachedSymbolName = newCachedSymbol->GetName();
1270 aPlugin->
SaveSymbol( aFileName, std::move( newCachedSymbol ), aBuffer ? &properties :
nullptr );
1274 wxLogError( errorMsg,
UnescapeString( newCachedSymbolName ), aFileName, ioe.
What() );
1278 std::shared_ptr<SYMBOL_BUFFER> originalBufferedParent =
GetBuffer( bufferedParent->GetName() );
1279 wxCHECK( originalBufferedParent,
false );
1281 std::unique_ptr<LIB_SYMBOL> newSymbol = std::make_unique<LIB_SYMBOL>( libSymbol );
1282 newSymbol->SetParent( &originalBufferedParent->GetSymbol() );
1288 std::unique_ptr<LIB_SYMBOL> newSymbol = std::make_unique<LIB_SYMBOL>( libSymbol );
1292 aPlugin->
SaveSymbol( aFileName, std::move( newSymbol ), aBuffer ? &properties :
nullptr );
1300 aSymbolBuf.
SetOriginal( std::make_unique<LIB_SYMBOL>( libSymbol ) );
1306 if( !derivedSymbols.IsEmpty() )
1313 wxCHECK_MSG( parentSymbol,
false, wxS(
"Failed to borrow the saved symbol back from the plugin cache." ) );
1316 for(
const wxString& entry : derivedSymbols )
1318 std::shared_ptr<SYMBOL_BUFFER> symbol =
GetBuffer( entry );
1320 wxCHECK2( symbol,
continue );
1322 std::unique_ptr<LIB_SYMBOL> derivedSymbol = std::make_unique<LIB_SYMBOL>( symbol->GetSymbol() );
1324 derivedSymbol->SetParent( parentSymbol );
1326 const wxString derivedSymbolName = derivedSymbol->GetName();
1330 aPlugin->
SaveSymbol( aFileName, std::move( derivedSymbol ), aBuffer ? &properties :
nullptr );
1349 for( std::shared_ptr<SYMBOL_BUFFER> entry :
m_symbols )
1351 if( entry->GetSymbol().GetName() == aSymbolName )
1355 return std::shared_ptr<SYMBOL_BUFFER>(
nullptr );
1361 wxCHECK( !aParentName.IsEmpty(),
false );
1363 for(
const std::shared_ptr<SYMBOL_BUFFER>& entry :
m_symbols )
1375 for( std::shared_ptr<SYMBOL_BUFFER>& entry :
m_symbols )
1377 const LIB_SYMBOL& symbol = entry->GetSymbol();
1392 wxCHECK( !aSymbolName.IsEmpty(), 0 );
1396 std::unordered_map<wxString, std::vector<wxString>> derivedMap;
1399 for(
const std::shared_ptr<SYMBOL_BUFFER>& entry :
m_symbols )
1403 if( !parentName.IsEmpty() )
1404 derivedMap[parentName].emplace_back( entry->GetSymbol().GetName() );
1409 std::set<wxString> visited{ aSymbolName };
1412 const std::function<void(
const wxString& )> getDerived =
1413 [&](
const wxString& aParentName )
1415 auto it = derivedMap.find( aParentName );
1417 if( it != derivedMap.end() )
1419 for(
const wxString& derivedName : it->second )
1421 if( !visited.insert( derivedName ).second )
1424 aList.Add( derivedName );
1427 getDerived( derivedName );
1433 getDerived( aSymbolName );
1435 return aList.GetCount();
1442 wxArrayString derivedSymbolNames;
1443 std::deque<std::shared_ptr<SYMBOL_BUFFER>>::iterator it;
1447 for(
const wxString& symbolName : derivedSymbolNames )
1450 [symbolName]( std::shared_ptr<SYMBOL_BUFFER>& buf )
1452 return buf->GetSymbol().GetName() == symbolName;
1455 wxCHECK2( it !=
m_symbols.end(),
continue );
void SetContentModified(bool aModified=true)
void SetFileAddedCallback(FILE_ADDED_CALLBACK callback)
void ClearEmbeddedFiles(bool aDeleteFiles=true)
EMBEDDED_FILE * AddFile(const wxFileName &aName, bool aOverwrite)
Load a file from disk and adds it to the collection.
const std::map< wxString, std::shared_ptr< EMBEDDED_FILE > > & EmbeddedFileMap() const
Provide an iterable view of the file collection.
void SetAreFontsEmbedded(bool aEmbedFonts)
FILE_ADDED_CALLBACK GetFileAddedCallback() const
bool GetAreFontsEmbedded() const
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()
bool IsLibraryLoaded(const wxString &aNickname)
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library tables.
std::vector< wxString > GetLibraryNames() const
Returns a list of library nicknames that are available (skips any that failed to load)
bool CreateLibrary(const wxString &aNickname)
Creates the library (i.e. saves to disk) for the given row if it exists.
std::optional< LIBRARY_TABLE * > Table(LIBRARY_TABLE_TYPE aType, LIBRARY_TABLE_SCOPE aScope)
Retrieves a given table; creating a new empty project table if a valid project is loaded and the give...
std::optional< wxString > GetFullURI(LIBRARY_TABLE_TYPE aType, const wxString &aNickname, bool aSubstituted=false)
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
std::vector< LIBRARY_TABLE_ROW * > Rows(LIBRARY_TABLE_TYPE aType, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH, bool aIncludeInvalid=false) const
Returns a flattened list of libraries of the given type.
void SetNickname(const wxString &aNickname)
void SetType(const wxString &aType)
void SetURI(const wxString &aUri)
Store a working copy of a library.
void ClearAddedAndDeletedBufferLists()
void RevertDeletedBuffers()
Move symbol buffers on the library's deleted list back to its main list.
bool CreateBuffer(std::unique_ptr< LIB_SYMBOL > aCopy, std::unique_ptr< SCH_SCREEN > aScreen, bool aNew=false)
Create a new buffer to store a symbol. LIB_BUFFER takes ownership of aCopy.
void RevertAddedBuffers()
std::deque< std::shared_ptr< SYMBOL_BUFFER > > m_added
Buffer for added synbols until lib is saved.
bool DeleteBuffer(const SYMBOL_BUFFER &aSymbolBuf)
Delete the given symbol buffer from the library buffer.
bool SaveModifiedBuffers(const wxString &aFileName, SCH_IO *aPlugin)
Save the modified symbols back to the library's own file aFileName.
void GetSymbolNames(wxArrayString &aSymbolNames, SYMBOL_NAME_FILTER aFilter=SYMBOL_NAME_FILTER::ALL)
Fetch a list of root symbols names from the library buffer.
const std::deque< std::shared_ptr< SYMBOL_BUFFER > > & GetDeletedBuffers() const
Return the deleted symbol buffers that need to be removed from the library file.
size_t GetDerivedSymbolNames(const wxString &aSymbolName, wxArrayString &aList) const
Fetch all of the symbols derived from a aSymbolName into aList.
std::deque< std::shared_ptr< SYMBOL_BUFFER > > m_symbols
std::deque< std::shared_ptr< SYMBOL_BUFFER > > m_deleted
Buffer for deleted symbols until lib is saved.
bool SaveBuffer(SYMBOL_BUFFER &aSymbolBuf, const wxString &aFileName, SCH_IO *aPlugin, bool aBuffer)
Save stored modifications using a plugin.
const std::deque< std::shared_ptr< SYMBOL_BUFFER > > & GetBuffers() const
Return all buffered symbols.
std::shared_ptr< SYMBOL_BUFFER > GetBuffer(const wxString &aAlias) const
Return a symbol buffer with LIB_SYMBOL holding a symbolic alias.
LIB_SYMBOL * GetSymbol(const wxString &aAlias) const
Return the working copy of a LIB_SYMBOL root object with specified alias.
int removeChildSymbols(const SYMBOL_BUFFER &aSymbolBuf)
Remove all symbols derived from aSymbolBuf from the library buffer.
bool HasDerivedSymbols(const wxString &aParentName) const
Check to see any symbols in the buffer are derived from a parent named aParentName.
bool UpdateBuffer(SYMBOL_BUFFER &aSymbolBuf, const LIB_SYMBOL &aCopy)
Update the buffered symbol with the contents of aCopy.
const wxString m_libName
Buffered library name.
A logical library item identifier and consists of various portions much like a URI.
int SetLibNickname(const UTF8 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
const UTF8 & GetLibItemName() const
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Define a library symbol object.
const LIB_ID & GetLibId() const override
std::weak_ptr< LIB_SYMBOL > & GetParent()
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
wxString GetName() const override
void SetLibId(const LIB_ID &aLibId)
virtual LIBRARY_MANAGER & GetLibraryManager() const
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
static SCH_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath, int aCtl=0)
Return a plugin type given a symbol library using the file extension of aLibPath.
Base class that schematic file and library loading and saving plugins should derive from.
virtual void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr)
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
virtual void DeleteSymbol(const wxString &aLibraryPath, const wxString &aSymbolName, const std::map< std::string, UTF8 > *aProperties=nullptr)
Delete the entire LIB_SYMBOL associated with aAliasName from the library aLibraryPath.
virtual LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aPartName, const std::map< std::string, UTF8 > *aProperties=nullptr)
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
virtual void SaveSymbol(const wxString &aLibraryPath, std::unique_ptr< LIB_SYMBOL > aSymbol, const std::map< std::string, UTF8 > *aProperties=nullptr)
Write aSymbol to an existing library located at aLibraryPath.
std::unique_ptr< LIB_SYMBOL > m_symbol
std::unique_ptr< SCH_SCREEN > m_screen
void SetSymbol(std::unique_ptr< LIB_SYMBOL > aSymbol)
LIB_SYMBOL & GetSymbol() const
SYMBOL_BUFFER(std::unique_ptr< LIB_SYMBOL > aSymbol=nullptr, std::unique_ptr< SCH_SCREEN > aScreen=nullptr)
std::unique_ptr< LIB_SYMBOL > m_original
LIB_SYMBOL & GetOriginal() const
void SetOriginal(std::unique_ptr< LIB_SYMBOL > aSymbol)
An interface to the global shared library manager that is schematic-specific and linked to one projec...
std::optional< LIB_STATUS > LoadOne(LIB_DATA *aLib) override
Loads or reloads the given library, if it exists.
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
int GetModifyHash() const
std::vector< LIB_SYMBOL * > GetSymbols(const wxString &aNickname, SYMBOL_TYPE aType=SYMBOL_TYPE::ALL_SYMBOLS)
bool IsSymbolLibWritable(const wxString &aNickname)
Return true if the library given by aNickname is writable.
bool IsLibraryReadOnly(const wxString &aLibrary) const
Return true if the library is stored in a read-only file.
SYMBOL_BUFFER * GetBuffer(const wxString &aSymbolName, const wxString &aLibrary)
Return the working buffer holding the symbol/screen pair, or nullptr when none exists.
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Return true if library exists.
size_t GetLibraryCount() const
bool ClearLibraryModified(const wxString &aLibrary) const
Clear the modified flag for all symbols in a library.
LIB_SYMBOL * GetBufferedSymbol(const wxString &aSymbolName, const wxString &aLibrary)
Return the symbol copy from the buffer.
bool addLibrary(const wxString &aFilePath, bool aCreate, LIBRARY_TABLE_SCOPE aScope)
Helper function to add either existing or create new library.
SCH_SCREEN * GetScreen(const wxString &aSymbolName, const wxString &aLibrary)
Return the screen used to edit a specific symbol.
bool SymbolNameInUse(const wxString &aName, const wxString &aLibrary)
Return true if the symbol name is already in use in the specified library.
bool IsLibraryModified(const wxString &aLibrary) const
Return true if library has unsaved modifications.
LIB_SYMBOL * GetSymbol(const wxString &aSymbolName, const wxString &aLibrary) const
Return either an alias of a working LIB_SYMBOL copy, or alias of the original symbol if there is no w...
bool RemoveSymbol(const wxString &aSymbolName, const wxString &aLibrary)
Remove the symbol from the symbol buffer.
wxArrayString GetLibraryNames() const
Return the array of library names.
LIB_BUFFER & getLibraryBuffer(const wxString &aLibrary)
Return an existing library buffer or creates one to using symbol library table to get the original da...
std::vector< wxString > DropUnmodifiedBuffers(const std::set< wxString > &aKeep={})
Forget the buffers of libraries with no unsaved changes, except those in aKeep, so they are read agai...
wxString GetUniqueLibraryName() const
Return a library name that is not currently in use.
bool HasModifications() const
static wxString getLibraryName(const wxString &aFilePath)
Extract library name basing on the file name.
bool UpdateSymbolAfterRename(LIB_SYMBOL *aSymbol, const wxString &aOldSymbolName, const wxString &aLibrary)
Update the symbol buffer with a new version of the symbol when the name has changed.
bool IsSymbolModified(const wxString &aSymbolName, const wxString &aLibrary) const
Return true if symbol has unsaved modifications.
virtual void OnDataChanged() const
bool IsLibraryLoaded(const wxString &aLibrary) const
Return true if the library was successfully loaded.
void SetSymbolModified(const wxString &aSymbolName, const wxString &aLibrary)
virtual ~SYMBOL_LIBRARY_MANAGER()
bool RevertLibrary(const wxString &aLibrary)
Revert unsaved changes for a symbol library.
void GetSymbolNames(const wxString &aLibName, wxArrayString &aSymbolNames, SYMBOL_NAME_FILTER aFilter=SYMBOL_NAME_FILTER::ALL)
std::set< LIB_SYMBOL * > getOriginalSymbols(const wxString &aLibrary)
Return a set of LIB_SYMBOL objects belonging to the original library.
int GetLibraryHash(const wxString &aLibrary) const
Return a library hash value to determine if it has changed.
LIB_ID RevertSymbol(const LIB_ID &aIdToRevert)
Revert unsaved changes for a symbol and clear its modified flag.
size_t GetDerivedSymbolNames(const wxString &aSymbolName, const wxString &aLibraryName, wxArrayString &aList)
Fetch all of the symbols derived from a aSymbolName into aList.
bool RevertAll()
Revert all pending changes.
SYMBOL_LIBRARY_MANAGER(SCH_BASE_FRAME &aFrame)
bool SymbolExists(const wxString &aSymbolName, const wxString &aLibrary) const
Return true if symbol with a specific alias exists in library (either original one or buffered).
SCH_BASE_FRAME & m_frame
Parent frame.
std::list< LIB_SYMBOL * > EnumerateSymbols(const wxString &aLibrary) const
bool UpdateSymbol(LIB_SYMBOL *aSymbol, const wxString &aLibrary)
Update the symbol buffer with a new version of the symbol.
bool SaveLibrary(const wxString &aLibrary, const wxString &aFileName, SCH_IO_MGR::SCH_FILE_T aFileType=SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY)
Save library to a file, including unsaved changes.
bool HasDerivedSymbols(const wxString &aSymbolName, const wxString &aLibraryName)
Check whether any symbol inherits from aSymbolName, without building the list of names.
std::map< wxString, LIB_BUFFER > m_libs
The library buffers.
bool UpdateLibraryBuffer(const wxString &aLibrary)
Update the library buffer with a new version of the library.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
This file is part of the common library.
wxString NormalizePath(const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath)
Normalize a file path to an environmental variable, if possible.
Helper functions to substitute paths with environmental variables.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
static const std::string KiCadSymbolLibFileExtension
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
#define KICTL_CREATE
caller thinks requested project files may not exist.
PGM_BASE & Pgm()
The global program "get" accessor.
int StrNumCmp(const wxString &aString1, const wxString &aString2, CMP_T aCaseSensitivity)
Compare two strings with alphanumerical content.
wxString UnescapeString(const wxString &aSource)
static wxString getParentName(const SYMBOL_BUFFER &aSymbolBuf)
Name of the parent a buffered symbol inherits from, or empty if it is a root symbol.
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().