KiCad PCB EDA Suite
SYMBOL_LIBRARY_MANAGER::LIB_BUFFER Class Reference

#include <symbol_library_manager.h>

Public Member Functions

 LIB_BUFFER (const wxString &aLibrary)
 
bool IsModified () const
 
int GetHash () const
 Return the working copy of a LIB_SYMBOL root object with specified alias. More...
 
LIB_SYMBOLGetSymbol (const wxString &aAlias) const
 Create a new buffer to store a symbol. LIB_BUFFER takes ownership of aCopy. More...
 
bool CreateBuffer (LIB_SYMBOL *aCopy, SCH_SCREEN *aScreen)
 Update the buffered symbol with the contents of aCopy. More...
 
bool UpdateBuffer (std::shared_ptr< SYMBOL_BUFFER > aSymbolBuf, LIB_SYMBOL *aCopy)
 
bool DeleteBuffer (std::shared_ptr< SYMBOL_BUFFER > aSymbolBuf)
 
void ClearDeletedBuffer ()
 Save stored modifications to Symbol Lib Table. More...
 
bool SaveBuffer (std::shared_ptr< SYMBOL_BUFFER > aSymbolBuf, SYMBOL_LIB_TABLE *aLibTable)
 Save stored modifications using a plugin. More...
 
bool SaveBuffer (std::shared_ptr< SYMBOL_BUFFER > aSymbolBuf, const wxString &aFileName, SCH_PLUGIN *aPlugin, bool aBuffer)
 Return a symbol buffer with LIB_SYMBOL holding a symbolicular alias. More...
 
std::shared_ptr< SYMBOL_BUFFERGetBuffer (const wxString &aAlias) const
 Return all buffered symbols. More...
 
const std::deque< std::shared_ptr< SYMBOL_BUFFER > > & GetBuffers () const
 
bool HasDerivedSymbols (const wxString &aParentName) const
 Check to see any symbols in the buffer are derived from a parent named aParentName. More...
 
void GetRootSymbolNames (wxArrayString &aRootSymbolNames)
 Fetch a list of root symbols names from the library buffer. More...
 
size_t GetDerivedSymbolNames (const wxString &aSymbolName, wxArrayString &aList)
 Fetch all of the symbols derived from a aSymbolName into aList. More...
 

Private Member Functions

int removeChildSymbols (std::shared_ptr< SYMBOL_BUFFER > aSymbolBuf)
 Remove all symbols derived from aParent from the library buffer. More...
 

Private Attributes

std::deque< std::shared_ptr< SYMBOL_BUFFER > > m_symbols
 Buffer for deleted symbols until library is saved. More...
 
std::deque< std::shared_ptr< SYMBOL_BUFFER > > m_deleted
 
const wxString m_libName
 
int m_hash
 

Detailed Description

Definition at line 300 of file symbol_library_manager.h.

Constructor & Destructor Documentation

◆ LIB_BUFFER()

SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::LIB_BUFFER ( const wxString &  aLibrary)
inline

Definition at line 303 of file symbol_library_manager.h.

Member Function Documentation

◆ ClearDeletedBuffer()

void SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::ClearDeletedBuffer ( )
inline

Save stored modifications to Symbol Lib Table.

It may result in saving the symbol to disk as well, depending on the row properties.

Definition at line 335 of file symbol_library_manager.h.

References m_deleted.

Referenced by SYMBOL_LIBRARY_MANAGER::SaveLibrary().

◆ CreateBuffer()

bool SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::CreateBuffer ( LIB_SYMBOL aCopy,
SCH_SCREEN aScreen 
)

Update the buffered symbol with the contents of aCopy.

Definition at line 897 of file symbol_library_manager.cpp.

898{
899 wxASSERT( aCopy );
900 wxASSERT( aCopy->GetLib() == nullptr );
901 std::unique_ptr<SCH_SCREEN> screen( aScreen );
902 auto symbolBuf = std::make_shared<SYMBOL_BUFFER>( aCopy, std::move( screen ) );
903 m_symbols.push_back( symbolBuf );
904
905 // Set the parent library name,
906 // otherwise it is empty as no library has been given as the owner during object construction
907 LIB_ID libId = aCopy->GetLibId();
908 libId.SetLibNickname( m_libName );
909 aCopy->SetLibId( libId );
910 ++m_hash;
911
912 return true;
913}
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:98
LIB_ID GetLibId() const override
Definition: lib_symbol.h:139
SYMBOL_LIB * GetLib() const
Definition: lib_symbol.h:187
void SetLibId(const LIB_ID &aLibId)
Definition: lib_symbol.h:140
std::deque< std::shared_ptr< SYMBOL_BUFFER > > m_symbols
Buffer for deleted symbols until library is saved.

References LIB_SYMBOL::GetLib(), LIB_SYMBOL::GetLibId(), LIB_SYMBOL::SetLibId(), and LIB_ID::SetLibNickname().

Referenced by SYMBOL_LIBRARY_MANAGER::GetBufferedSymbol(), SYMBOL_LIBRARY_MANAGER::getLibraryBuffer(), and SYMBOL_LIBRARY_MANAGER::UpdateSymbol().

◆ DeleteBuffer()

bool SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::DeleteBuffer ( std::shared_ptr< SYMBOL_BUFFER aSymbolBuf)

Definition at line 932 of file symbol_library_manager.cpp.

933{
934 auto symbolBufIt = std::find( m_symbols.begin(), m_symbols.end(), aSymbolBuf );
935 wxCHECK( symbolBufIt != m_symbols.end(), false );
936
937 bool retv = true;
938
939 // Remove all derived symbols to prevent broken inheritance.
940 if( aSymbolBuf->GetSymbol()->IsRoot() && HasDerivedSymbols( aSymbolBuf->GetSymbol()->GetName() )
941 && removeChildSymbols( aSymbolBuf ) == 0 )
942 {
943 retv = false;
944 }
945
946 m_deleted.emplace_back( *symbolBufIt );
947 m_symbols.erase( symbolBufIt );
948 ++m_hash;
949
950 return retv;
951}
std::deque< std::shared_ptr< SYMBOL_BUFFER > > m_deleted
bool HasDerivedSymbols(const wxString &aParentName) const
Check to see any symbols in the buffer are derived from a parent named aParentName.
int removeChildSymbols(std::shared_ptr< SYMBOL_BUFFER > aSymbolBuf)
Remove all symbols derived from aParent from the library buffer.

References SYMBOL_LIBRARY_MANAGER::HasDerivedSymbols().

Referenced by SYMBOL_LIBRARY_MANAGER::RemoveSymbol().

◆ GetBuffer()

std::shared_ptr< SYMBOL_LIBRARY_MANAGER::SYMBOL_BUFFER > SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetBuffer ( const wxString &  aAlias) const

Return all buffered symbols.

Definition at line 1230 of file symbol_library_manager.cpp.

1231{
1232 for( std::shared_ptr<SYMBOL_LIBRARY_MANAGER::SYMBOL_BUFFER> entry : m_symbols )
1233 {
1234 if( entry->GetSymbol()->GetName() == aAlias )
1235 return entry;
1236 }
1237
1238 return std::shared_ptr<SYMBOL_BUFFER>( nullptr );
1239}

Referenced by SYMBOL_LIBRARY_MANAGER::GetScreen(), SYMBOL_LIBRARY_MANAGER::IsSymbolModified(), SYMBOL_LIBRARY_MANAGER::RemoveSymbol(), SYMBOL_LIBRARY_MANAGER::SetSymbolModified(), SYMBOL_LIBRARY_MANAGER::UpdateSymbol(), and SYMBOL_LIBRARY_MANAGER::UpdateSymbolAfterRename().

◆ GetBuffers()

const std::deque< std::shared_ptr< SYMBOL_BUFFER > > & SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetBuffers ( ) const
inline

Definition at line 353 of file symbol_library_manager.h.

353{ return m_symbols; }

References m_symbols.

Referenced by SYMBOL_LIBRARY_MANAGER::SaveLibrary().

◆ GetDerivedSymbolNames()

size_t SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetDerivedSymbolNames ( const wxString &  aSymbolName,
wxArrayString &  aList 
)

Fetch all of the symbols derived from a aSymbolName into aList.

Parameters
aSymbolNameis the name of the symbol to search for derived symbols in this buffer.
aListis the list of symbols names derived from aSymbolName.
Returns
a size_t count of the number of symbols derived from aSymbolName.

Definition at line 1274 of file symbol_library_manager.cpp.

1276{
1277 wxCHECK( !aSymbolName.IsEmpty(), 0 );
1278
1279 for( auto& entry : m_symbols )
1280 {
1281 if( entry->GetSymbol()->IsAlias() )
1282 {
1283 LIB_SYMBOL_SPTR parent = entry->GetSymbol()->GetParent().lock();
1284
1285 // Check for inherited symbol without a valid parent.
1286 wxCHECK( parent, false );
1287
1288 if( parent->GetName() == aSymbolName )
1289 aList.Add( entry->GetSymbol()->GetName() );
1290 }
1291 }
1292
1293 return aList.GetCount();
1294}
std::shared_ptr< LIB_SYMBOL > LIB_SYMBOL_SPTR
shared pointer to LIB_SYMBOL
Definition: lib_symbol.h:44

◆ GetHash()

int SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetHash ( ) const
inline

Return the working copy of a LIB_SYMBOL root object with specified alias.

Definition at line 322 of file symbol_library_manager.h.

References m_hash.

◆ GetRootSymbolNames()

void SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetRootSymbolNames ( wxArrayString &  aRootSymbolNames)

Fetch a list of root symbols names from the library buffer.

Parameters
aRootSymbolNamesis a reference to a list to populate with root symbol names.

Definition at line 1262 of file symbol_library_manager.cpp.

1263{
1264 for( auto& entry : m_symbols )
1265 {
1266 if( entry->GetSymbol()->IsAlias() )
1267 continue;
1268
1269 aRootSymbolNames.Add( UnescapeString( entry->GetSymbol()->GetName() ) );
1270 }
1271}
wxString UnescapeString(const wxString &aSource)

References UnescapeString().

Referenced by SYMBOL_LIBRARY_MANAGER::GetRootSymbolNames().

◆ GetSymbol()

LIB_SYMBOL * SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetSymbol ( const wxString &  aAlias) const

Create a new buffer to store a symbol. LIB_BUFFER takes ownership of aCopy.

Definition at line 882 of file symbol_library_manager.cpp.

883{
884 auto buf = GetBuffer( aAlias );
885
886 if( !buf )
887 return nullptr;
888
889 LIB_SYMBOL* symbol = buf->GetSymbol();
890
891 wxCHECK( symbol, nullptr );
892
893 return symbol;
894}
Define a library symbol object.
Definition: lib_symbol.h:98
std::shared_ptr< SYMBOL_BUFFER > GetBuffer(const wxString &aAlias) const
Return all buffered symbols.

Referenced by SYMBOL_LIBRARY_MANAGER::GetBufferedSymbol(), and SYMBOL_LIBRARY_MANAGER::getLibraryBuffer().

◆ HasDerivedSymbols()

bool SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::HasDerivedSymbols ( const wxString &  aParentName) const

Check to see any symbols in the buffer are derived from a parent named aParentName.

Parameters
aParentNameis the name of the parent to test.
Returns
true if any symbols are found derived from a symbol named aParent, otherwise false.

Definition at line 1242 of file symbol_library_manager.cpp.

1243{
1244 for( auto& entry : m_symbols )
1245 {
1246 if( entry->GetSymbol()->IsAlias() )
1247 {
1248 LIB_SYMBOL_SPTR parent = entry->GetSymbol()->GetParent().lock();
1249
1250 // Check for inherited symbol without a valid parent.
1251 wxCHECK( parent, false );
1252
1253 if( parent->GetName() == aParentName )
1254 return true;
1255 }
1256 }
1257
1258 return false;
1259}

Referenced by SYMBOL_LIBRARY_MANAGER::HasDerivedSymbols().

◆ IsModified()

bool SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::IsModified ( ) const
inline

Definition at line 308 of file symbol_library_manager.h.

309 {
310 if( !m_deleted.empty() )
311 return true;
312
313 for( const std::shared_ptr<SYMBOL_BUFFER>& symbolBuf : m_symbols )
314 {
315 if( symbolBuf->IsModified() )
316 return true;
317 }
318
319 return false;
320 }

References m_deleted, and m_symbols.

◆ removeChildSymbols()

int SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::removeChildSymbols ( std::shared_ptr< SYMBOL_BUFFER aSymbolBuf)
private

Remove all symbols derived from aParent from the library buffer.

Parameters
aParentis the #SYMBOL_BUFFER to check against.
Returns
the count of #SYMBOL_BUFFER objects removed from the library.

Definition at line 1297 of file symbol_library_manager.cpp.

1298{
1299 wxCHECK( aSymbolBuf && aSymbolBuf->GetSymbol()->IsRoot(), 0 );
1300
1301 int cnt = 0;
1302 std::deque< std::shared_ptr<SYMBOL_BUFFER> >::iterator it = m_symbols.begin();
1303
1304 while( it != m_symbols.end() )
1305 {
1306
1307 if( (*it)->GetSymbol()->IsRoot() )
1308 {
1309 ++it;
1310 }
1311 else
1312 {
1313 LIB_SYMBOL_SPTR parent = (*it)->GetSymbol()->GetParent().lock();
1314
1315 wxCHECK2( parent, ++it; continue );
1316
1317 if( parent->GetName() == aSymbolBuf->GetSymbol()->GetName() )
1318 {
1319 wxCHECK2( parent == aSymbolBuf->GetSymbol()->SharedPtr(), ++it; continue );
1320
1321 m_deleted.emplace_back( *it );
1322 it = m_symbols.erase( it );
1323 cnt++;
1324 }
1325 else
1326 {
1327 ++it;
1328 }
1329 }
1330 }
1331
1332 return cnt;
1333}

◆ SaveBuffer() [1/2]

bool SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer ( std::shared_ptr< SYMBOL_BUFFER aSymbolBuf,
const wxString &  aFileName,
SCH_PLUGIN aPlugin,
bool  aBuffer 
)

Return a symbol buffer with LIB_SYMBOL holding a symbolicular alias.

Definition at line 1056 of file symbol_library_manager.cpp.

1059{
1060 wxCHECK( aSymbolBuf, false );
1061 LIB_SYMBOL* libSymbol = aSymbolBuf->GetSymbol();
1062 LIB_SYMBOL* originalSymbol = aSymbolBuf->GetOriginal();
1063 wxCHECK( libSymbol && originalSymbol, false );
1064 wxCHECK( !aFileName.IsEmpty(), false );
1065
1066 wxString errorMsg = _( "Error saving symbol %s to library '%s'." ) + wxS( "\n%s" );
1067
1068 // set properties to prevent save file on every symbol save
1069 STRING_UTF8_MAP properties;
1070 properties.emplace( SCH_LEGACY_PLUGIN::PropBuffering, "" );
1071
1072 // Delete the original symbol if the symbol name has been changed.
1073 if( libSymbol->GetName() != originalSymbol->GetName() )
1074 {
1075 try
1076 {
1077 if( aPlugin->LoadSymbol( aFileName, originalSymbol->GetName() ) )
1078 aPlugin->DeleteSymbol( aFileName, originalSymbol->GetName(), &properties );
1079 }
1080 catch( const IO_ERROR& ioe )
1081 {
1082 wxLogError( errorMsg, UnescapeString( originalSymbol->GetName() ), aFileName,
1083 ioe.What() );
1084 return false;
1085 }
1086 }
1087
1088 if( libSymbol->IsAlias() )
1089 {
1090 LIB_SYMBOL* newCachedSymbol = new LIB_SYMBOL( *libSymbol );
1091 std::shared_ptr< LIB_SYMBOL > bufferedParent = libSymbol->GetParent().lock();
1092
1093 wxCHECK( bufferedParent, false );
1094
1095 LIB_SYMBOL* cachedParent = nullptr;
1096
1097 try
1098 {
1099 cachedParent = aPlugin->LoadSymbol( aFileName, bufferedParent->GetName() );
1100 }
1101 catch( const IO_ERROR& )
1102 {
1103 return false;
1104 }
1105
1106 if( !cachedParent )
1107 {
1108 cachedParent = new LIB_SYMBOL( *bufferedParent.get() );
1109 newCachedSymbol->SetParent( cachedParent );
1110
1111 try
1112 {
1113 aPlugin->SaveSymbol( aFileName, cachedParent, aBuffer ? &properties : nullptr );
1114 }
1115 catch( const IO_ERROR& ioe )
1116 {
1117 wxLogError( errorMsg, UnescapeString( cachedParent->GetName() ), aFileName,
1118 ioe.What() );
1119 return false;
1120 }
1121
1122 try
1123 {
1124 aPlugin->SaveSymbol( aFileName, newCachedSymbol, aBuffer ? &properties : nullptr );
1125 }
1126 catch( const IO_ERROR& ioe )
1127 {
1128 wxLogError( errorMsg, UnescapeString( newCachedSymbol->GetName() ), aFileName,
1129 ioe.What() );
1130 return false;
1131 }
1132
1133 LIB_SYMBOL* originalParent = new LIB_SYMBOL( *bufferedParent.get() );
1134 aSymbolBuf->SetOriginal( originalParent );
1135 originalSymbol = new LIB_SYMBOL( *libSymbol );
1136 originalSymbol->SetParent( originalParent );
1137 aSymbolBuf->SetOriginal( originalSymbol );
1138 }
1139 else
1140 {
1141 newCachedSymbol->SetParent( cachedParent );
1142
1143 try
1144 {
1145 aPlugin->SaveSymbol( aFileName, newCachedSymbol, aBuffer ? &properties : nullptr );
1146 }
1147 catch( const IO_ERROR& ioe )
1148 {
1149 wxLogError( errorMsg, UnescapeString( newCachedSymbol->GetName() ), aFileName,
1150 ioe.What() );
1151 return false;
1152 }
1153
1154 auto originalBufferedParent = GetBuffer( bufferedParent->GetName() );
1155 wxCHECK( originalBufferedParent, false );
1156 originalSymbol = new LIB_SYMBOL( *libSymbol );
1157 originalSymbol->SetParent( originalBufferedParent->GetSymbol() );
1158 aSymbolBuf->SetOriginal( originalSymbol );
1159 }
1160 }
1161 else
1162 {
1163 wxArrayString derivedSymbols;
1164
1165 if( GetDerivedSymbolNames( libSymbol->GetName(), derivedSymbols ) == 0 )
1166 {
1167 try
1168 {
1169 aPlugin->SaveSymbol( aFileName, new LIB_SYMBOL( *libSymbol ),
1170 aBuffer ? &properties : nullptr );
1171 }
1172 catch( const IO_ERROR& ioe )
1173 {
1174 wxLogError( errorMsg, UnescapeString( libSymbol->GetName() ), aFileName,
1175 ioe.What() );
1176 return false;
1177 }
1178
1179 aSymbolBuf->SetOriginal( new LIB_SYMBOL( *libSymbol ) );
1180 }
1181 else
1182 {
1183 LIB_SYMBOL* parentSymbol = new LIB_SYMBOL( *libSymbol );
1184
1185 // Save the modified root symbol.
1186 try
1187 {
1188 aPlugin->SaveSymbol( aFileName, parentSymbol, aBuffer ? &properties : nullptr );
1189 }
1190 catch( const IO_ERROR& ioe )
1191 {
1192 wxLogError( errorMsg, UnescapeString( libSymbol->GetName() ), aFileName,
1193 ioe.What() );
1194 return false;
1195 }
1196
1197 aSymbolBuf->SetOriginal( new LIB_SYMBOL( *libSymbol ) );
1198
1199 // Save the derived symbols.
1200 for( const wxString& entry : derivedSymbols )
1201 {
1202 std::shared_ptr<SYMBOL_BUFFER> symbol = GetBuffer( entry );
1203
1204 wxCHECK2( symbol, continue );
1205
1206 LIB_SYMBOL* derivedSymbol = new LIB_SYMBOL( *symbol->GetSymbol() );
1207 derivedSymbol->SetParent( parentSymbol );
1208
1209 try
1210 {
1211 aPlugin->SaveSymbol( aFileName, new LIB_SYMBOL( *derivedSymbol ),
1212 aBuffer ? &properties : nullptr );
1213 }
1214 catch( const IO_ERROR& ioe )
1215 {
1216 wxLogError( errorMsg, UnescapeString( derivedSymbol->GetName() ), aFileName,
1217 ioe.What() );
1218 return false;
1219 }
1220 }
1221 }
1222 }
1223
1224 ++m_hash;
1225 return true;
1226}
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
bool IsAlias() const
Definition: lib_symbol.h:183
void SetParent(LIB_SYMBOL *aParent=nullptr)
Definition: lib_symbol.cpp:451
wxString GetName() const override
Definition: lib_symbol.h:136
LIB_SYMBOL_REF & GetParent()
Definition: lib_symbol.h:125
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
virtual void SaveSymbol(const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const STRING_UTF8_MAP *aProperties=nullptr)
Write aSymbol to an existing library located at aLibraryPath.
Definition: sch_plugin.cpp:94
virtual void DeleteSymbol(const wxString &aLibraryPath, const wxString &aSymbolName, const STRING_UTF8_MAP *aProperties=nullptr)
Delete the entire LIB_SYMBOL associated with aAliasName from the library aLibraryPath.
Definition: sch_plugin.cpp:102
virtual LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aPartName, const STRING_UTF8_MAP *aProperties=nullptr)
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
Definition: sch_plugin.cpp:85
A name/value tuple with unique names and optional values.
size_t GetDerivedSymbolNames(const wxString &aSymbolName, wxArrayString &aList)
Fetch all of the symbols derived from a aSymbolName into aList.
#define _(s)

References _, SCH_PLUGIN::DeleteSymbol(), LIB_SYMBOL::GetName(), LIB_SYMBOL::GetParent(), LIB_SYMBOL::IsAlias(), SCH_PLUGIN::LoadSymbol(), SCH_LEGACY_PLUGIN::PropBuffering, SCH_PLUGIN::SaveSymbol(), LIB_SYMBOL::SetParent(), UnescapeString(), and IO_ERROR::What().

◆ SaveBuffer() [2/2]

bool SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer ( std::shared_ptr< SYMBOL_BUFFER aSymbolBuf,
SYMBOL_LIB_TABLE aLibTable 
)

Save stored modifications using a plugin.

aBuffer decides whether the changes should be cached or stored directly to the disk (for SCH_LEGACY_PLUGIN).

Definition at line 954 of file symbol_library_manager.cpp.

956{
957 wxCHECK( aSymbolBuf, false );
958 LIB_SYMBOL* libSymbol = aSymbolBuf->GetSymbol();
959 LIB_SYMBOL* originalSymbol = aSymbolBuf->GetOriginal();
960 wxCHECK( libSymbol && originalSymbol, false );
962 STRING_UTF8_MAP properties;
963 properties.emplace( SCH_LEGACY_PLUGIN::PropBuffering, "" );
964
965 wxString errorMsg = _( "Error saving symbol %s to library '%s'." ) + wxS( "\n%s" );
966
967 // Delete the original symbol if the symbol name has been changed.
968 if( libSymbol->GetName() != originalSymbol->GetName() )
969 {
970 // DeleteSymbol may throw
971 try
972 {
973 if( aLibTable->LoadSymbol( m_libName, originalSymbol->GetName() ) )
974 aLibTable->DeleteSymbol( m_libName, originalSymbol->GetName() );
975 }
976 catch( const IO_ERROR& ioe )
977 {
978 wxLogError( errorMsg, UnescapeString( originalSymbol->GetName() ), m_libName,
979 ioe.What() );
980 return false;
981 }
982 }
983
984 if( libSymbol->IsAlias() )
985 {
986 LIB_SYMBOL* newCachedSymbol = new LIB_SYMBOL( *libSymbol );
987 std::shared_ptr< LIB_SYMBOL > bufferedParent = libSymbol->GetParent().lock();
988
989 wxCHECK( bufferedParent, false );
990
991 LIB_SYMBOL* cachedParent = aLibTable->LoadSymbol( m_libName, bufferedParent->GetName() );
992
993 if( !cachedParent )
994 {
995 cachedParent = new LIB_SYMBOL( *bufferedParent.get() );
996 newCachedSymbol->SetParent( cachedParent );
997 result = aLibTable->SaveSymbol( m_libName, cachedParent );
998 wxCHECK( result == SYMBOL_LIB_TABLE::SAVE_OK, false );
999 result = aLibTable->SaveSymbol( m_libName, newCachedSymbol );
1000 wxCHECK( result == SYMBOL_LIB_TABLE::SAVE_OK, false );
1001
1002 LIB_SYMBOL* originalParent = new LIB_SYMBOL( *bufferedParent.get() );
1003 aSymbolBuf->SetOriginal( originalParent );
1004 originalSymbol = new LIB_SYMBOL( *libSymbol );
1005 originalSymbol->SetParent( originalParent );
1006 aSymbolBuf->SetOriginal( originalSymbol );
1007 }
1008 else
1009 {
1010 newCachedSymbol->SetParent( cachedParent );
1011 result = aLibTable->SaveSymbol( m_libName, newCachedSymbol );
1012 wxCHECK( result == SYMBOL_LIB_TABLE::SAVE_OK, false );
1013
1014 auto originalBufferedParent = GetBuffer( bufferedParent->GetName() );
1015 wxCHECK( originalBufferedParent, false );
1016 originalSymbol = new LIB_SYMBOL( *libSymbol );
1017 originalSymbol->SetParent( originalBufferedParent->GetSymbol() );
1018 aSymbolBuf->SetOriginal( originalSymbol );
1019 }
1020 }
1021 else
1022 {
1023 wxArrayString derivedSymbols;
1024
1025 if( GetDerivedSymbolNames( libSymbol->GetName(), derivedSymbols ) == 0 )
1026 {
1027 result = aLibTable->SaveSymbol( m_libName, new LIB_SYMBOL( *libSymbol ) );
1028 wxCHECK( result == SYMBOL_LIB_TABLE::SAVE_OK, false );
1029 aSymbolBuf->SetOriginal( new LIB_SYMBOL( *libSymbol ) );
1030 }
1031 else
1032 {
1033 LIB_SYMBOL* parentSymbol = new LIB_SYMBOL( *libSymbol );
1034
1035 aLibTable->SaveSymbol( m_libName, parentSymbol );
1036
1037 for( auto& entry : derivedSymbols )
1038 {
1039 std::shared_ptr<SYMBOL_BUFFER> symbol = GetBuffer( entry );
1040
1041 wxCHECK2( symbol, continue );
1042
1043 LIB_SYMBOL* derivedSymbol = new LIB_SYMBOL( *symbol->GetSymbol() );
1044 derivedSymbol->SetParent( parentSymbol );
1045 result = aLibTable->SaveSymbol( m_libName, derivedSymbol );
1046 wxCHECK( result == SYMBOL_LIB_TABLE::SAVE_OK, false );
1047 }
1048 }
1049 }
1050
1051 ++m_hash;
1052 return true;
1053}
void DeleteSymbol(const wxString &aNickname, const wxString &aSymbolName)
Deletes the aSymbolName from the library given by aNickname.
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
SAVE_T SaveSymbol(const wxString &aNickname, const LIB_SYMBOL *aSymbol, bool aOverwrite=true)
Write aSymbol to an existing library given by aNickname.
SAVE_T
The set of return values from SaveSymbol() below.

References _, SYMBOL_LIB_TABLE::DeleteSymbol(), LIB_SYMBOL::GetName(), LIB_SYMBOL::GetParent(), LIB_SYMBOL::IsAlias(), SYMBOL_LIB_TABLE::LoadSymbol(), SCH_LEGACY_PLUGIN::PropBuffering, SYMBOL_LIB_TABLE::SAVE_OK, SYMBOL_LIB_TABLE::SaveSymbol(), LIB_SYMBOL::SetParent(), UnescapeString(), and IO_ERROR::What().

Referenced by SYMBOL_LIBRARY_MANAGER::SaveLibrary().

◆ UpdateBuffer()

bool SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::UpdateBuffer ( std::shared_ptr< SYMBOL_BUFFER aSymbolBuf,
LIB_SYMBOL aCopy 
)

Definition at line 916 of file symbol_library_manager.cpp.

918{
919 wxCHECK( aCopy && aSymbolBuf, false );
920
921 LIB_SYMBOL* bufferedSymbol = aSymbolBuf->GetSymbol();
922
923 wxCHECK( bufferedSymbol, false );
924
925 *bufferedSymbol = *aCopy;
926 ++m_hash;
927
928 return true;
929}

Referenced by SYMBOL_LIBRARY_MANAGER::UpdateSymbolAfterRename().

Member Data Documentation

◆ m_deleted

std::deque< std::shared_ptr<SYMBOL_BUFFER> > SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::m_deleted
private

Definition at line 393 of file symbol_library_manager.h.

Referenced by ClearDeletedBuffer(), and IsModified().

◆ m_hash

int SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::m_hash
private

Definition at line 395 of file symbol_library_manager.h.

Referenced by GetHash().

◆ m_libName

const wxString SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::m_libName
private

Definition at line 394 of file symbol_library_manager.h.

◆ m_symbols

std::deque< std::shared_ptr<SYMBOL_BUFFER> > SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::m_symbols
private

Buffer for deleted symbols until library is saved.

Definition at line 390 of file symbol_library_manager.h.

Referenced by GetBuffers(), and IsModified().


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