KiCad PCB EDA Suite
SYMBOL_LIBRARY_MANAGER::LIB_BUFFER Class Reference

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 312 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 315 of file symbol_library_manager.h.

315  :
316  m_libName( aLibrary ),
317  m_hash( 1 )
318  { }

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 347 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 894 of file symbol_library_manager.cpp.

895 {
896  wxASSERT( aCopy );
897  wxASSERT( aCopy->GetLib() == nullptr );
898  std::unique_ptr<SCH_SCREEN> screen( aScreen );
899  auto symbolBuf = std::make_shared<SYMBOL_BUFFER>( aCopy, std::move( screen ) );
900  m_symbols.push_back( symbolBuf );
901 
902  // Set the parent library name,
903  // otherwise it is empty as no library has been given as the owner during object construction
904  LIB_ID libId = aCopy->GetLibId();
905  libId.SetLibNickname( m_libName );
906  aCopy->SetLibId( libId );
907  ++m_hash;
908 
909  return true;
910 }
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
SYMBOL_LIB * GetLib() const
Definition: lib_symbol.h:176
LIB_ID GetLibId() const override
Definition: lib_symbol.h:135
void SetLibId(const LIB_ID &aLibId)
Definition: lib_symbol.h:136
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:97
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 929 of file symbol_library_manager.cpp.

930 {
931  auto symbolBufIt = std::find( m_symbols.begin(), m_symbols.end(), aSymbolBuf );
932  wxCHECK( symbolBufIt != m_symbols.end(), false );
933 
934  bool retv = true;
935 
936  // Remove all derived symbols to prevent broken inheritance.
937  if( aSymbolBuf->GetSymbol()->IsRoot() && HasDerivedSymbols( aSymbolBuf->GetSymbol()->GetName() )
938  && removeChildSymbols( aSymbolBuf ) == 0 )
939  {
940  retv = false;
941  }
942 
943  m_deleted.emplace_back( *symbolBufIt );
944  m_symbols.erase( symbolBufIt );
945  ++m_hash;
946 
947  return retv;
948 }
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.
std::deque< std::shared_ptr< SYMBOL_BUFFER > > m_symbols
Buffer for deleted symbols until library is saved.
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 1200 of file symbol_library_manager.cpp.

1201 {
1202  for( auto entry : m_symbols )
1203  {
1204  if( entry->GetSymbol()->GetName() == aAlias )
1205  return entry;
1206  }
1207 
1208  return std::shared_ptr<SYMBOL_BUFFER>( nullptr );
1209 }
std::deque< std::shared_ptr< SYMBOL_BUFFER > > m_symbols
Buffer for deleted symbols until library is saved.

Referenced by SYMBOL_LIBRARY_MANAGER::GetScreen(), SYMBOL_LIBRARY_MANAGER::IsSymbolModified(), SYMBOL_LIBRARY_MANAGER::RemoveSymbol(), 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 365 of file symbol_library_manager.h.

365 { return m_symbols; }
std::deque< std::shared_ptr< SYMBOL_BUFFER > > m_symbols
Buffer for deleted symbols until library is saved.

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 1244 of file symbol_library_manager.cpp.

1246 {
1247  wxCHECK( !aSymbolName.IsEmpty(), 0 );
1248 
1249  for( auto entry : m_symbols )
1250  {
1251  if( entry->GetSymbol()->IsAlias() )
1252  {
1253  LIB_SYMBOL_SPTR parent = entry->GetSymbol()->GetParent().lock();
1254 
1255  // Check for inherited symbol without a valid parent.
1256  wxCHECK( parent, false );
1257 
1258  if( parent->GetName() == aSymbolName )
1259  aList.Add( entry->GetSymbol()->GetName() );
1260  }
1261  }
1262 
1263  return aList.GetCount();
1264 }
std::shared_ptr< LIB_SYMBOL > LIB_SYMBOL_SPTR
shared pointer to LIB_SYMBOL
Definition: lib_symbol.h:42
std::deque< std::shared_ptr< SYMBOL_BUFFER > > m_symbols
Buffer for deleted symbols until library is saved.

◆ 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 334 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 1232 of file symbol_library_manager.cpp.

1233 {
1234  for( auto entry : m_symbols )
1235  {
1236  if( entry->GetSymbol()->IsAlias() )
1237  continue;
1238 
1239  aRootSymbolNames.Add( UnescapeString( entry->GetSymbol()->GetName() ) );
1240  }
1241 }
wxString UnescapeString(const wxString &aSource)
std::deque< std::shared_ptr< SYMBOL_BUFFER > > m_symbols
Buffer for deleted symbols until library is saved.

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 879 of file symbol_library_manager.cpp.

880 {
881  auto buf = GetBuffer( aAlias );
882 
883  if( !buf )
884  return nullptr;
885 
886  LIB_SYMBOL* symbol = buf->GetSymbol();
887 
888  wxCHECK( symbol, nullptr );
889 
890  return symbol;
891 }
Define a library symbol object.
Definition: lib_symbol.h:96
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 1212 of file symbol_library_manager.cpp.

1213 {
1214  for( auto entry : m_symbols )
1215  {
1216  if( entry->GetSymbol()->IsAlias() )
1217  {
1218  LIB_SYMBOL_SPTR parent = entry->GetSymbol()->GetParent().lock();
1219 
1220  // Check for inherited symbol without a valid parent.
1221  wxCHECK( parent, false );
1222 
1223  if( parent->GetName() == aParentName )
1224  return true;
1225  }
1226  }
1227 
1228  return false;
1229 }
std::shared_ptr< LIB_SYMBOL > LIB_SYMBOL_SPTR
shared pointer to LIB_SYMBOL
Definition: lib_symbol.h:42
std::deque< std::shared_ptr< SYMBOL_BUFFER > > m_symbols
Buffer for deleted symbols until library is saved.

Referenced by SYMBOL_LIBRARY_MANAGER::HasDerivedSymbols().

◆ IsModified()

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

Definition at line 320 of file symbol_library_manager.h.

321  {
322  if( !m_deleted.empty() )
323  return true;
324 
325  for( const std::shared_ptr<SYMBOL_BUFFER>& symbolBuf : m_symbols )
326  {
327  if( symbolBuf->IsModified() )
328  return true;
329  }
330 
331  return false;
332  }
std::deque< std::shared_ptr< SYMBOL_BUFFER > > m_deleted
std::deque< std::shared_ptr< SYMBOL_BUFFER > > m_symbols
Buffer for deleted symbols until library is saved.

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 1267 of file symbol_library_manager.cpp.

1268 {
1269  wxCHECK( aSymbolBuf && aSymbolBuf->GetSymbol()->IsRoot(), 0 );
1270 
1271  int cnt = 0;
1272  std::deque< std::shared_ptr<SYMBOL_BUFFER> >::iterator it = m_symbols.begin();
1273 
1274  while( it != m_symbols.end() )
1275  {
1276 
1277  if( (*it)->GetSymbol()->IsRoot() )
1278  {
1279  ++it;
1280  }
1281  else
1282  {
1283  LIB_SYMBOL_SPTR parent = (*it)->GetSymbol()->GetParent().lock();
1284 
1285  wxCHECK2( parent, ++it; continue );
1286 
1287  if( parent->GetName() == aSymbolBuf->GetSymbol()->GetName() )
1288  {
1289  wxCHECK2( parent == aSymbolBuf->GetSymbol()->SharedPtr(), ++it; continue );
1290 
1291  m_deleted.emplace_back( *it );
1292  it = m_symbols.erase( it );
1293  cnt++;
1294  }
1295  else
1296  {
1297  ++it;
1298  }
1299  }
1300  }
1301 
1302  return cnt;
1303 }
std::deque< std::shared_ptr< SYMBOL_BUFFER > > m_deleted
std::shared_ptr< LIB_SYMBOL > LIB_SYMBOL_SPTR
shared pointer to LIB_SYMBOL
Definition: lib_symbol.h:42
std::deque< std::shared_ptr< SYMBOL_BUFFER > > m_symbols
Buffer for deleted symbols until library is saved.

◆ SaveBuffer() [1/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 951 of file symbol_library_manager.cpp.

953 {
954  wxCHECK( aSymbolBuf, false );
955  LIB_SYMBOL* libSymbol = aSymbolBuf->GetSymbol();
956  LIB_SYMBOL* originalSymbol = aSymbolBuf->GetOriginal();
957  wxCHECK( libSymbol && originalSymbol, false );
959  PROPERTIES properties;
960  properties.emplace( SCH_LEGACY_PLUGIN::PropBuffering, "" );
961 
962  // Delete the original symbol if the symbol name has been changed.
963  if( libSymbol->GetName() != originalSymbol->GetName() )
964  {
965  if( aLibTable->LoadSymbol( m_libName, originalSymbol->GetName() ) )
966  aLibTable->DeleteSymbol( m_libName, originalSymbol->GetName() );
967  }
968 
969  if( libSymbol->IsAlias() )
970  {
971  LIB_SYMBOL* newCachedSymbol = new LIB_SYMBOL( *libSymbol );
972  std::shared_ptr< LIB_SYMBOL > bufferedParent = libSymbol->GetParent().lock();
973 
974  wxCHECK( bufferedParent, false );
975 
976  LIB_SYMBOL* cachedParent = aLibTable->LoadSymbol( m_libName, bufferedParent->GetName() );
977 
978  if( !cachedParent )
979  {
980  cachedParent = new LIB_SYMBOL( *bufferedParent.get() );
981  newCachedSymbol->SetParent( cachedParent );
982  result = aLibTable->SaveSymbol( m_libName, cachedParent );
983  wxCHECK( result == SYMBOL_LIB_TABLE::SAVE_OK, false );
984  result = aLibTable->SaveSymbol( m_libName, newCachedSymbol );
985  wxCHECK( result == SYMBOL_LIB_TABLE::SAVE_OK, false );
986 
987  LIB_SYMBOL* originalParent = new LIB_SYMBOL( *bufferedParent.get() );
988  aSymbolBuf->SetOriginal( originalParent );
989  originalSymbol = new LIB_SYMBOL( *libSymbol );
990  originalSymbol->SetParent( originalParent );
991  aSymbolBuf->SetOriginal( originalSymbol );
992  }
993  else
994  {
995  newCachedSymbol->SetParent( cachedParent );
996  result = aLibTable->SaveSymbol( m_libName, newCachedSymbol );
997  wxCHECK( result == SYMBOL_LIB_TABLE::SAVE_OK, false );
998 
999  auto originalBufferedParent = GetBuffer( bufferedParent->GetName() );
1000  wxCHECK( originalBufferedParent, false );
1001  originalSymbol = new LIB_SYMBOL( *libSymbol );
1002  originalSymbol->SetParent( originalBufferedParent->GetSymbol() );
1003  aSymbolBuf->SetOriginal( originalSymbol );
1004  }
1005  }
1006  else
1007  {
1008  wxArrayString derivedSymbols;
1009 
1010  if( GetDerivedSymbolNames( libSymbol->GetName(), derivedSymbols ) == 0 )
1011  {
1012  result = aLibTable->SaveSymbol( m_libName, new LIB_SYMBOL( *libSymbol ) );
1013  wxCHECK( result == SYMBOL_LIB_TABLE::SAVE_OK, false );
1014  aSymbolBuf->SetOriginal( new LIB_SYMBOL( *libSymbol ) );
1015  }
1016  else
1017  {
1018  LIB_SYMBOL* parentSymbol = new LIB_SYMBOL( *libSymbol );
1019 
1020  aLibTable->SaveSymbol( m_libName, parentSymbol );
1021 
1022  for( auto entry : derivedSymbols )
1023  {
1024  std::shared_ptr<SYMBOL_BUFFER> symbol = GetBuffer( entry );
1025  LIB_SYMBOL* derivedSymbol = new LIB_SYMBOL( *symbol->GetSymbol() );
1026  derivedSymbol->SetParent( parentSymbol );
1027  result = aLibTable->SaveSymbol( m_libName, derivedSymbol );
1028  wxCHECK( result == SYMBOL_LIB_TABLE::SAVE_OK, false );
1029  }
1030  }
1031  }
1032 
1033  ++m_hash;
1034  return true;
1035 }
LIB_SYMBOL_REF & GetParent()
Definition: lib_symbol.h:124
wxString GetName() const override
Definition: lib_symbol.h:133
SAVE_T SaveSymbol(const wxString &aNickname, const LIB_SYMBOL *aSymbol, bool aOverwrite=true)
Write aSymbol to an existing library given by aNickname.
bool IsAlias() const
Definition: lib_symbol.h:172
A name/value tuple with unique names and optional values.
Definition: properties.h:33
Define a library symbol object.
Definition: lib_symbol.h:96
void SetParent(LIB_SYMBOL *aParent=nullptr)
Definition: lib_symbol.cpp:322
std::shared_ptr< SYMBOL_BUFFER > GetBuffer(const wxString &aAlias) const
Return all buffered symbols.
void DeleteSymbol(const wxString &aNickname, const wxString &aSymbolName)
Deletes the aSymbolName from the library given by aNickname.
size_t GetDerivedSymbolNames(const wxString &aSymbolName, wxArrayString &aList)
Fetch all of the symbols derived from a aSymbolName into aList.
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the 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(), and LIB_SYMBOL::SetParent().

Referenced by SYMBOL_LIBRARY_MANAGER::SaveLibrary().

◆ SaveBuffer() [2/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 1038 of file symbol_library_manager.cpp.

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

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().

◆ UpdateBuffer()

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

Definition at line 913 of file symbol_library_manager.cpp.

915 {
916  wxCHECK( aCopy && aSymbolBuf, false );
917 
918  LIB_SYMBOL* bufferedSymbol = aSymbolBuf->GetSymbol();
919 
920  wxCHECK( bufferedSymbol, false );
921 
922  *bufferedSymbol = *aCopy;
923  ++m_hash;
924 
925  return true;
926 }
Define a library symbol object.
Definition: lib_symbol.h:96

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 405 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 407 of file symbol_library_manager.h.

Referenced by GetHash().

◆ m_libName

const wxString SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::m_libName
private

Definition at line 406 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 402 of file symbol_library_manager.h.

Referenced by GetBuffers(), and IsModified().


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