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_PART root object with specified alias. More...
 
LIB_PARTGetPart (const wxString &aAlias) const
 Create a new buffer to store a part. LIB_BUFFER takes ownership of aCopy. More...
 
bool CreateBuffer (LIB_PART *aCopy, SCH_SCREEN *aScreen)
 Update the buffered part with the contents of aCopy. More...
 
bool UpdateBuffer (PART_BUFFER::PTR aPartBuf, LIB_PART *aCopy)
 
bool DeleteBuffer (PART_BUFFER::PTR aPartBuf)
 
void ClearDeletedBuffer ()
 Save stored modifications to Symbol Lib Table. More...
 
bool SaveBuffer (PART_BUFFER::PTR aPartBuf, SYMBOL_LIB_TABLE *aLibTable)
 Save stored modifications using a plugin. More...
 
bool SaveBuffer (PART_BUFFER::PTR aPartBuf, const wxString &aFileName, SCH_PLUGIN *aPlugin, bool aBuffer)
 Return a part buffer with LIB_PART holding a particular alias. More...
 
PART_BUFFER::PTR GetBuffer (const wxString &aAlias) const
 Return all buffered parts. More...
 
const std::deque< PART_BUFFER::PTR > & GetBuffers () const
 
bool HasDerivedSymbols (const wxString &aParentName) const
 Check to see any parts 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 (PART_BUFFER::PTR aPartBuf)
 Remove all symbols derived from aParent from the library buffer. More...
 

Private Attributes

std::deque< PART_BUFFER::PTRm_parts
 
std::deque< PART_BUFFER::PTRm_deleted
 
const wxString m_libName
 
int m_hash
 

Detailed Description

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

364  :
365  m_libName( aLibrary ),
366  m_hash( 1 )
367  { }

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

References m_deleted.

Referenced by SYMBOL_LIBRARY_MANAGER::SaveLibrary().

◆ CreateBuffer()

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

Update the buffered part with the contents of aCopy.

Definition at line 885 of file symbol_library_manager.cpp.

886 {
887  wxASSERT( aCopy );
888  wxASSERT( aCopy->GetLib() == nullptr );
889  std::unique_ptr<SCH_SCREEN> screen( aScreen );
890  auto partBuf = std::make_shared<PART_BUFFER>( aCopy, std::move( screen ) );
891  m_parts.push_back( partBuf );
892 
893  // Set the parent library name,
894  // otherwise it is empty as no library has been given as the owner during object construction
895  LIB_ID libId = aCopy->GetLibId();
896  libId.SetLibNickname( m_libName );
897  aCopy->SetLibId( libId );
898  ++m_hash;
899 
900  return true;
901 }
LIB_ID GetLibId() const override
Definition: lib_symbol.h:131
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
std::deque< PART_BUFFER::PTR > m_parts
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:193
PART_LIB * GetLib() const
Definition: lib_symbol.h:172
void SetLibId(const LIB_ID &aLibId)
Definition: lib_symbol.h:132

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

Referenced by SYMBOL_LIBRARY_MANAGER::GetBufferedPart(), SYMBOL_LIBRARY_MANAGER::getLibraryBuffer(), and SYMBOL_LIBRARY_MANAGER::UpdatePart().

◆ DeleteBuffer()

bool SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::DeleteBuffer ( PART_BUFFER::PTR  aPartBuf)

Definition at line 920 of file symbol_library_manager.cpp.

922 {
923  auto partBufIt = std::find( m_parts.begin(), m_parts.end(), aPartBuf );
924  wxCHECK( partBufIt != m_parts.end(), false );
925 
926  bool retv = true;
927 
928  // Remove all derived symbols to prevent broken inheritance.
929  if( aPartBuf->GetPart()->IsRoot() && HasDerivedSymbols( aPartBuf->GetPart()->GetName() )
930  && removeChildSymbols( aPartBuf ) == 0 )
931  {
932  retv = false;
933  }
934 
935  m_deleted.emplace_back( *partBufIt );
936  m_parts.erase( partBufIt );
937  ++m_hash;
938 
939  return retv;
940 }
std::deque< PART_BUFFER::PTR > m_parts
std::deque< PART_BUFFER::PTR > m_deleted
int removeChildSymbols(PART_BUFFER::PTR aPartBuf)
Remove all symbols derived from aParent from the library buffer.
bool HasDerivedSymbols(const wxString &aParentName) const
Check to see any parts in the buffer are derived from a parent named aParentName.

References SYMBOL_LIBRARY_MANAGER::HasDerivedSymbols().

Referenced by SYMBOL_LIBRARY_MANAGER::RemovePart().

◆ GetBuffer()

SYMBOL_LIBRARY_MANAGER::PART_BUFFER::PTR SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetBuffer ( const wxString &  aAlias) const

Return all buffered parts.

Definition at line 1188 of file symbol_library_manager.cpp.

1189 {
1190  for( auto entry : m_parts )
1191  {
1192  if( entry->GetPart()->GetName() == aAlias )
1193  return entry;
1194  }
1195 
1196  return PART_BUFFER::PTR( nullptr );
1197 }
std::deque< PART_BUFFER::PTR > m_parts
std::shared_ptr< PART_BUFFER > PTR

Referenced by SYMBOL_LIBRARY_MANAGER::GetScreen(), SYMBOL_LIBRARY_MANAGER::IsPartModified(), SYMBOL_LIBRARY_MANAGER::RemovePart(), SYMBOL_LIBRARY_MANAGER::UpdatePart(), and SYMBOL_LIBRARY_MANAGER::UpdatePartAfterRename().

◆ GetBuffers()

const std::deque<PART_BUFFER::PTR>& SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetBuffers ( ) const
inline

Definition at line 414 of file symbol_library_manager.h.

414 { return m_parts; }
std::deque< PART_BUFFER::PTR > m_parts

References m_parts.

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

1234 {
1235  wxCHECK( !aSymbolName.IsEmpty(), 0 );
1236 
1237  for( auto entry : m_parts )
1238  {
1239  if( entry->GetPart()->IsAlias() )
1240  {
1241  PART_SPTR parent = entry->GetPart()->GetParent().lock();
1242 
1243  // Check for inherited part without a valid parent.
1244  wxCHECK( parent, false );
1245 
1246  if( parent->GetName() == aSymbolName )
1247  aList.Add( entry->GetPart()->GetName() );
1248  }
1249  }
1250 
1251  return aList.GetCount();
1252 }
std::shared_ptr< LIB_PART > PART_SPTR
shared pointer to LIB_PART
Definition: lib_symbol.h:42
std::deque< PART_BUFFER::PTR > m_parts

◆ GetHash()

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

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

Definition at line 383 of file symbol_library_manager.h.

References m_hash.

◆ GetPart()

LIB_PART * SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::GetPart ( const wxString &  aAlias) const

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

Definition at line 870 of file symbol_library_manager.cpp.

871 {
872  auto buf = GetBuffer( aAlias );
873 
874  if( !buf )
875  return nullptr;
876 
877  LIB_PART* part = buf->GetPart();
878 
879  wxCHECK( part, nullptr );
880 
881  return part;
882 }
Define a library symbol object.
Definition: lib_symbol.h:93
PART_BUFFER::PTR GetBuffer(const wxString &aAlias) const
Return all buffered parts.

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

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

1221 {
1222  for( auto entry : m_parts )
1223  {
1224  if( entry->GetPart()->IsAlias() )
1225  continue;
1226 
1227  aRootSymbolNames.Add( entry->GetPart()->GetName() );
1228  }
1229 }
std::deque< PART_BUFFER::PTR > m_parts

Referenced by SYMBOL_LIBRARY_MANAGER::GetRootSymbolNames().

◆ HasDerivedSymbols()

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

Check to see any parts 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 1200 of file symbol_library_manager.cpp.

1201 {
1202  for( auto entry : m_parts )
1203  {
1204  if( entry->GetPart()->IsAlias() )
1205  {
1206  PART_SPTR parent = entry->GetPart()->GetParent().lock();
1207 
1208  // Check for inherited part without a valid parent.
1209  wxCHECK( parent, false );
1210 
1211  if( parent->GetName() == aParentName )
1212  return true;
1213  }
1214  }
1215 
1216  return false;
1217 }
std::shared_ptr< LIB_PART > PART_SPTR
shared pointer to LIB_PART
Definition: lib_symbol.h:42
std::deque< PART_BUFFER::PTR > m_parts

Referenced by SYMBOL_LIBRARY_MANAGER::HasDerivedSymbols().

◆ IsModified()

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

Definition at line 369 of file symbol_library_manager.h.

370  {
371  if( !m_deleted.empty() )
372  return true;
373 
374  for( const auto& partBuf : m_parts )
375  {
376  if( partBuf->IsModified() )
377  return true;
378  }
379 
380  return false;
381  }
std::deque< PART_BUFFER::PTR > m_parts
std::deque< PART_BUFFER::PTR > m_deleted

References m_deleted, and m_parts.

◆ removeChildSymbols()

int SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::removeChildSymbols ( PART_BUFFER::PTR  aPartBuf)
private

Remove all symbols derived from aParent from the library buffer.

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

Definition at line 1255 of file symbol_library_manager.cpp.

1257 {
1258  wxCHECK( aPartBuf && aPartBuf->GetPart()->IsRoot(), 0 );
1259 
1260  int cnt = 0;
1261  std::deque< SYMBOL_LIBRARY_MANAGER::PART_BUFFER::PTR >::iterator it = m_parts.begin();
1262 
1263  while( it != m_parts.end() )
1264  {
1265 
1266  if( (*it)->GetPart()->IsRoot() )
1267  {
1268  ++it;
1269  }
1270  else
1271  {
1272  PART_SPTR parent = (*it)->GetPart()->GetParent().lock();
1273 
1274  wxCHECK2( parent, ++it; continue );
1275 
1276  if( parent->GetName() == aPartBuf->GetPart()->GetName() )
1277  {
1278  wxCHECK2( parent == aPartBuf->GetPart()->SharedPtr(), ++it; continue );
1279 
1280  m_deleted.emplace_back( *it );
1281  it = m_parts.erase( it );
1282  cnt++;
1283  }
1284  else
1285  {
1286  ++it;
1287  }
1288  }
1289  }
1290 
1291  return cnt;
1292 }
std::shared_ptr< LIB_PART > PART_SPTR
shared pointer to LIB_PART
Definition: lib_symbol.h:42
std::deque< PART_BUFFER::PTR > m_parts
std::deque< PART_BUFFER::PTR > m_deleted

◆ SaveBuffer() [1/2]

bool SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer ( PART_BUFFER::PTR  aPartBuf,
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 943 of file symbol_library_manager.cpp.

945 {
946  wxCHECK( aPartBuf, false );
947  LIB_PART* part = aPartBuf->GetPart();
948  LIB_PART* originalPart = aPartBuf->GetOriginal();
949  wxCHECK( part && originalPart, false );
951  PROPERTIES properties;
952  properties.emplace( SCH_LEGACY_PLUGIN::PropBuffering, "" );
953 
954  // Delete the original symbol if the symbol name has been changed.
955  if( part->GetName() != originalPart->GetName() )
956  {
957  if( aLibTable->LoadSymbol( m_libName, originalPart->GetName() ) )
958  aLibTable->DeleteSymbol( m_libName, originalPart->GetName() );
959  }
960 
961  if( part->IsAlias() )
962  {
963  LIB_PART* newCachedPart = new LIB_PART( *part );
964  std::shared_ptr< LIB_PART > bufferedParent = part->GetParent().lock();
965 
966  wxCHECK( bufferedParent, false );
967 
968  LIB_PART* cachedParent = aLibTable->LoadSymbol( m_libName, bufferedParent->GetName() );
969 
970  if( !cachedParent )
971  {
972  cachedParent = new LIB_PART( *bufferedParent.get() );
973  newCachedPart->SetParent( cachedParent );
974  result = aLibTable->SaveSymbol( m_libName, cachedParent );
975  wxCHECK( result == SYMBOL_LIB_TABLE::SAVE_OK, false );
976  result = aLibTable->SaveSymbol( m_libName, newCachedPart );
977  wxCHECK( result == SYMBOL_LIB_TABLE::SAVE_OK, false );
978 
979  LIB_PART* originalParent = new LIB_PART( *bufferedParent.get() );
980  aPartBuf->SetOriginal( originalParent );
981  originalPart = new LIB_PART( *part );
982  originalPart->SetParent( originalParent );
983  aPartBuf->SetOriginal( originalPart );
984  }
985  else
986  {
987  newCachedPart->SetParent( cachedParent );
988  result = aLibTable->SaveSymbol( m_libName, newCachedPart );
989  wxCHECK( result == SYMBOL_LIB_TABLE::SAVE_OK, false );
990 
991  SYMBOL_LIBRARY_MANAGER::PART_BUFFER::PTR originalBufferedParent =
992  GetBuffer( bufferedParent->GetName() );
993  wxCHECK( originalBufferedParent, false );
994  originalPart = new LIB_PART( *part );
995  originalPart->SetParent( originalBufferedParent->GetPart() );
996  aPartBuf->SetOriginal( originalPart );
997  }
998  }
999  else
1000  {
1001  wxArrayString derivedSymbols;
1002 
1003  if( GetDerivedSymbolNames( part->GetName(), derivedSymbols ) == 0 )
1004  {
1005  result = aLibTable->SaveSymbol( m_libName, new LIB_PART( *part ) );
1006  wxCHECK( result == SYMBOL_LIB_TABLE::SAVE_OK, false );
1007  aPartBuf->SetOriginal( new LIB_PART( *part ) );
1008  }
1009  else
1010  {
1011  LIB_PART* parentSymbol = new LIB_PART( *part );
1012 
1013  aLibTable->SaveSymbol( m_libName, parentSymbol );
1014 
1015  for( auto entry : derivedSymbols )
1016  {
1018  LIB_PART* derivedSymbol = new LIB_PART( *symbol->GetPart() );
1019  derivedSymbol->SetParent( parentSymbol );
1020  result = aLibTable->SaveSymbol( m_libName, derivedSymbol );
1021  wxCHECK( result == SYMBOL_LIB_TABLE::SAVE_OK, false );
1022  }
1023  }
1024  }
1025 
1026  ++m_hash;
1027  return true;
1028 }
SAVE_T SaveSymbol(const wxString &aNickname, const LIB_PART *aSymbol, bool aOverwrite=true)
Write aSymbol to an existing library given by aNickname.
wxString GetName() const override
Definition: lib_symbol.h:129
LIB_PART * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_PART having aName from the library given by aNickname.
A name/value tuple with unique names and optional values.
Definition: properties.h:33
void SetParent(LIB_PART *aParent=nullptr)
Definition: lib_symbol.cpp:325
PART_REF & GetParent()
Definition: lib_symbol.h:120
Define a library symbol object.
Definition: lib_symbol.h:93
void DeleteSymbol(const wxString &aNickname, const wxString &aSymbolName)
Deletes the aSymbolName from the library given by aNickname.
bool IsAlias() const
Definition: lib_symbol.h:168
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 ...
PART_BUFFER::PTR GetBuffer(const wxString &aAlias) const
Return all buffered parts.
SAVE_T
The set of return values from SaveSymbol() below.
std::shared_ptr< PART_BUFFER > PTR

References SYMBOL_LIB_TABLE::DeleteSymbol(), LIB_PART::GetName(), LIB_PART::GetParent(), LIB_PART::IsAlias(), SYMBOL_LIB_TABLE::LoadSymbol(), SCH_LEGACY_PLUGIN::PropBuffering, SYMBOL_LIB_TABLE::SAVE_OK, SYMBOL_LIB_TABLE::SaveSymbol(), and LIB_PART::SetParent().

Referenced by SYMBOL_LIBRARY_MANAGER::SaveLibrary().

◆ SaveBuffer() [2/2]

bool SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer ( PART_BUFFER::PTR  aPartBuf,
const wxString &  aFileName,
SCH_PLUGIN aPlugin,
bool  aBuffer 
)

Return a part buffer with LIB_PART holding a particular alias.

Definition at line 1031 of file symbol_library_manager.cpp.

1034 {
1035  wxCHECK( aPartBuf, false );
1036  LIB_PART* part = aPartBuf->GetPart();
1037  LIB_PART* originalPart = aPartBuf->GetOriginal();
1038  wxCHECK( part && originalPart, false );
1039  wxCHECK( !aFileName.IsEmpty(), false );
1040 
1041  wxString errorMsg = _( "An error \"%s\" occurred saving symbol \"%s\" to library \"%s\"" );
1042 
1043  // set properties to prevent save file on every symbol save
1044  PROPERTIES properties;
1045  properties.emplace( SCH_LEGACY_PLUGIN::PropBuffering, "" );
1046 
1047  // Delete the original symbol if the symbol name has been changed.
1048  if( part->GetName() != originalPart->GetName() )
1049  {
1050  if( aPlugin->LoadSymbol( aFileName, originalPart->GetName() ) )
1051  aPlugin->DeleteSymbol( aFileName, originalPart->GetName(), &properties );
1052  }
1053 
1054  if( part->IsAlias() )
1055  {
1056  LIB_PART* newCachedPart = new LIB_PART( *part );
1057  std::shared_ptr< LIB_PART > bufferedParent = part->GetParent().lock();
1058 
1059  wxCHECK( bufferedParent, false );
1060 
1061  LIB_PART* cachedParent = nullptr;
1062 
1063  try
1064  {
1065  cachedParent = aPlugin->LoadSymbol( aFileName, bufferedParent->GetName() );
1066  }
1067  catch( const IO_ERROR& )
1068  {
1069  return false;
1070  }
1071 
1072  if( !cachedParent )
1073  {
1074  cachedParent = new LIB_PART( *bufferedParent.get() );
1075  newCachedPart->SetParent( cachedParent );
1076 
1077  try
1078  {
1079  aPlugin->SaveSymbol( aFileName, cachedParent, aBuffer ? &properties : nullptr );
1080  }
1081  catch( const IO_ERROR& ioe )
1082  {
1083  wxLogError( errorMsg, ioe.What(), cachedParent->GetName() );
1084  return false;
1085  }
1086 
1087  try
1088  {
1089  aPlugin->SaveSymbol( aFileName, newCachedPart, aBuffer ? &properties : nullptr );
1090  }
1091  catch( const IO_ERROR& ioe )
1092  {
1093  wxLogError( errorMsg, ioe.What(), newCachedPart->GetName() );
1094  return false;
1095  }
1096 
1097  LIB_PART* originalParent = new LIB_PART( *bufferedParent.get() );
1098  aPartBuf->SetOriginal( originalParent );
1099  originalPart = new LIB_PART( *part );
1100  originalPart->SetParent( originalParent );
1101  aPartBuf->SetOriginal( originalPart );
1102  }
1103  else
1104  {
1105  newCachedPart->SetParent( cachedParent );
1106 
1107  try
1108  {
1109  aPlugin->SaveSymbol( aFileName, newCachedPart, aBuffer ? &properties : nullptr );
1110  }
1111  catch( const IO_ERROR& ioe )
1112  {
1113  wxLogError( errorMsg, ioe.What(), newCachedPart->GetName() );
1114  return false;
1115  }
1116 
1117  SYMBOL_LIBRARY_MANAGER::PART_BUFFER::PTR originalBufferedParent =
1118  GetBuffer( bufferedParent->GetName() );
1119  wxCHECK( originalBufferedParent, false );
1120  originalPart = new LIB_PART( *part );
1121  originalPart->SetParent( originalBufferedParent->GetPart() );
1122  aPartBuf->SetOriginal( originalPart );
1123  }
1124  }
1125  else
1126  {
1127  wxArrayString derivedSymbols;
1128 
1129  if( GetDerivedSymbolNames( part->GetName(), derivedSymbols ) == 0 )
1130  {
1131  try
1132  {
1133  aPlugin->SaveSymbol( aFileName, new LIB_PART( *part ),
1134  aBuffer ? &properties : nullptr );
1135  }
1136  catch( const IO_ERROR& ioe )
1137  {
1138  wxLogError( errorMsg, ioe.What(), part->GetName() );
1139  return false;
1140  }
1141 
1142  aPartBuf->SetOriginal( new LIB_PART( *part ) );
1143  }
1144  else
1145  {
1146  LIB_PART* parentSymbol = new LIB_PART( *part );
1147 
1148  // Save the modified root symbol.
1149  try
1150  {
1151  aPlugin->SaveSymbol( aFileName, parentSymbol, aBuffer ? &properties : nullptr );
1152  }
1153  catch( const IO_ERROR& ioe )
1154  {
1155  wxLogError( errorMsg, ioe.What(), part->GetName() );
1156  return false;
1157  }
1158 
1159  aPartBuf->SetOriginal( new LIB_PART( *part ) );
1160 
1161  // Save the derived symbols.
1162  for( auto entry : derivedSymbols )
1163  {
1165  LIB_PART* derivedSymbol = new LIB_PART( *symbol->GetPart() );
1166  derivedSymbol->SetParent( parentSymbol );
1167 
1168  try
1169  {
1170  aPlugin->SaveSymbol( aFileName, new LIB_PART( *derivedSymbol ),
1171  aBuffer ? &properties : nullptr );
1172  }
1173  catch( const IO_ERROR& ioe )
1174  {
1175  wxLogError( errorMsg, ioe.What(), derivedSymbol->GetName() );
1176  return false;
1177  }
1178  }
1179  }
1180  }
1181 
1182  ++m_hash;
1183  return true;
1184 }
virtual void DeleteSymbol(const wxString &aLibraryPath, const wxString &aSymbolName, const PROPERTIES *aProperties=nullptr)
Delete the entire LIB_PART associated with aAliasName from the library aLibraryPath.
Definition: sch_plugin.cpp:102
wxString GetName() const override
Definition: lib_symbol.h:129
A name/value tuple with unique names and optional values.
Definition: properties.h:33
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
void SetParent(LIB_PART *aParent=nullptr)
Definition: lib_symbol.cpp:325
PART_REF & GetParent()
Definition: lib_symbol.h:120
Define a library symbol object.
Definition: lib_symbol.h:93
virtual LIB_PART * LoadSymbol(const wxString &aLibraryPath, const wxString &aPartName, const PROPERTIES *aProperties=nullptr)
Load a LIB_PART object having aPartName from the aLibraryPath containing a library format that this S...
Definition: sch_plugin.cpp:85
virtual void SaveSymbol(const wxString &aLibraryPath, const LIB_PART *aSymbol, const PROPERTIES *aProperties=nullptr)
Write aSymbol to an existing library located at aLibraryPath.
Definition: sch_plugin.cpp:94
#define _(s)
Definition: 3d_actions.cpp:33
bool IsAlias() const
Definition: lib_symbol.h:168
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 ...
PART_BUFFER::PTR GetBuffer(const wxString &aAlias) const
Return all buffered parts.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75
std::shared_ptr< PART_BUFFER > PTR

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

◆ UpdateBuffer()

bool SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::UpdateBuffer ( PART_BUFFER::PTR  aPartBuf,
LIB_PART aCopy 
)

Definition at line 904 of file symbol_library_manager.cpp.

906 {
907  wxCHECK( aCopy && aPartBuf, false );
908 
909  LIB_PART* bufferedPart = aPartBuf->GetPart();
910 
911  wxCHECK( bufferedPart, false );
912 
913  *bufferedPart = *aCopy;
914  ++m_hash;
915 
916  return true;
917 }
Define a library symbol object.
Definition: lib_symbol.h:93

Referenced by SYMBOL_LIBRARY_MANAGER::UpdatePartAfterRename().

Member Data Documentation

◆ m_deleted

std::deque<PART_BUFFER::PTR> SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::m_deleted
private

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

Referenced by GetHash().

◆ m_libName

const wxString SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::m_libName
private

Definition at line 453 of file symbol_library_manager.h.

◆ m_parts

std::deque<PART_BUFFER::PTR> SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::m_parts
private

Definition at line 451 of file symbol_library_manager.h.

Referenced by GetBuffers(), and IsModified().


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