KiCad PCB EDA Suite
RESCUE_SYMBOL_LIB_TABLE_CANDIDATE Class Reference

#include <project_rescue.h>

Inheritance diagram for RESCUE_SYMBOL_LIB_TABLE_CANDIDATE:
RESCUE_CANDIDATE

Public Member Functions

 RESCUE_SYMBOL_LIB_TABLE_CANDIDATE (const LIB_ID &aRequestedId, const LIB_ID &aNewId, LIB_SYMBOL *aCacheCandidate, LIB_SYMBOL *aLibCandidate, int aUnit=0, int aConvert=0)
 Create RESCUE_CANDIDATE. More...
 
 RESCUE_SYMBOL_LIB_TABLE_CANDIDATE ()
 
virtual LIB_SYMBOLGetCacheCandidate () const override
 Get the part that can be loaded from the project cache, if possible, or else NULL. More...
 
virtual wxString GetActionDescription () const override
 Get a description of the action proposed, for displaying in the UI. More...
 
virtual bool PerformAction (RESCUER *aRescuer) override
 Perform the actual rescue action. More...
 
virtual wxString GetRequestedName () const
 Get the name that was originally requested in the schematic. More...
 
virtual wxString GetNewName () const
 Get the name we're proposing changing it to. More...
 
virtual LIB_SYMBOLGetLibCandidate () const
 Get the part the would be loaded from the libraries, if possible, or else NULL. More...
 
int GetUnit () const
 
int GetConvert () const
 

Static Public Member Functions

static void FindRescues (RESCUER &aRescuer, boost::ptr_vector< RESCUE_CANDIDATE > &aCandidates)
 Grab all possible RESCUE_SYMBOL_LIB_TABLE_CANDIDATE objects into a vector. More...
 

Protected Attributes

wxString m_requested_name
 
wxString m_new_name
 
LIB_SYMBOLm_lib_candidate
 
int m_unit
 
int m_convert
 

Private Attributes

LIB_ID m_requested_id
 
LIB_ID m_new_id
 
LIB_SYMBOLm_cache_candidate
 

Detailed Description

Definition at line 186 of file project_rescue.h.

Constructor & Destructor Documentation

◆ RESCUE_SYMBOL_LIB_TABLE_CANDIDATE() [1/2]

RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::RESCUE_SYMBOL_LIB_TABLE_CANDIDATE ( const LIB_ID aRequestedId,
const LIB_ID aNewId,
LIB_SYMBOL aCacheCandidate,
LIB_SYMBOL aLibCandidate,
int  aUnit = 0,
int  aConvert = 0 
)

Create RESCUE_CANDIDATE.

Parameters
aRequestedNameis the name the schematic asks for.
aNewNameis the name we want to change it to.
aCacheCandidateis the part from the cache.
aLibCandidateis the part that would be loaded from the library.
aUnitis the unit of the rescued symbol.
aConvertis the body style of the rescued symbol.

Definition at line 342 of file project_rescue.cpp.

348  : RESCUE_CANDIDATE()
349 {
350  m_requested_id = aRequestedId;
351  m_requested_name = aRequestedId.Format();
352  m_new_id = aNewId;
353  m_lib_candidate = aLibCandidate;
354  m_cache_candidate = aCacheCandidate;
355  m_unit = aUnit;
356  m_convert = aConvert;
357 }
LIB_SYMBOL * m_lib_candidate
UTF8 Format() const
Definition: lib_id.cpp:116
wxString m_requested_name

References LIB_ID::Format(), m_cache_candidate, RESCUE_CANDIDATE::m_convert, RESCUE_CANDIDATE::m_lib_candidate, m_new_id, m_requested_id, RESCUE_CANDIDATE::m_requested_name, and RESCUE_CANDIDATE::m_unit.

◆ RESCUE_SYMBOL_LIB_TABLE_CANDIDATE() [2/2]

RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::RESCUE_SYMBOL_LIB_TABLE_CANDIDATE ( )

Definition at line 360 of file project_rescue.cpp.

361 {
362  m_cache_candidate = nullptr;
363  m_lib_candidate = nullptr;
364 }
LIB_SYMBOL * m_lib_candidate

References m_cache_candidate, and RESCUE_CANDIDATE::m_lib_candidate.

Referenced by FindRescues().

Member Function Documentation

◆ FindRescues()

void RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues ( RESCUER aRescuer,
boost::ptr_vector< RESCUE_CANDIDATE > &  aCandidates 
)
static

Grab all possible RESCUE_SYMBOL_LIB_TABLE_CANDIDATE objects into a vector.

Parameters
aRescueris the working RESCUER instance.
aCandidatesis the vector the will hold the candidates.

Definition at line 367 of file project_rescue.cpp.

370 {
371  typedef std::map<LIB_ID, RESCUE_SYMBOL_LIB_TABLE_CANDIDATE> candidate_map_t;
372 
373  candidate_map_t candidate_map;
374 
375  // Remember the list of symbols is sorted by LIB_ID.
376  // So a search in libraries is made only once by group
377  LIB_SYMBOL* cache_match = nullptr;
378  LIB_SYMBOL* lib_match = nullptr;
379  LIB_ID old_symbol_id;
380 
381  wxString escapedSymbolName;
382 
383  for( SCH_SYMBOL* eachSymbol : *( aRescuer.GetSymbols() ) )
384  {
385  const LIB_ID& symbol_id = eachSymbol->GetLibId();
386 
387  if( old_symbol_id != symbol_id )
388  {
389  // A new symbol name is found (a new group starts here).
390  // Search the symbol names candidates only once for this group:
391  old_symbol_id = symbol_id;
392 
393  escapedSymbolName = EscapeString( symbol_id.Format().wx_str(), CTX_LIBID );
394 
395  // Get the library symbol from the cache library. It will be a flattened
396  // symbol by default (no inheritance).
397  cache_match = findSymbol( escapedSymbolName, aRescuer.GetPrj()->SchLibs(),
398  true );
399 
400  // At some point during V5 development, the LIB_ID delimiter character ':' was
401  // replaced by '_' when writing the symbol cache library so we have to test for
402  // the LIB_NICKNAME_LIB_SYMBOL_NAME case.
403  if( !cache_match )
404  {
405  escapedSymbolName = EscapeString( symbol_id.GetLibNickname().wx_str() +
406  wxT( "_" ) + symbol_id.GetLibItemName().wx_str(),
407  CTX_LIBID );
408  cache_match = findSymbol( escapedSymbolName, aRescuer.GetPrj()->SchLibs(),
409  true );
410  }
411 
412  // Get the library symbol from the symbol library table.
413  lib_match = SchGetLibSymbol( symbol_id, aRescuer.GetPrj()->SchSymbolLibTable() );
414 
415  if( !cache_match && !lib_match )
416  continue;
417 
418  LIB_SYMBOL_SPTR lib_match_parent;
419 
420  // If it's a derive symbol, use the parent symbol to perform the pin test.
421  if( lib_match && lib_match->IsAlias() )
422  {
423  lib_match_parent = lib_match->GetParent().lock();
424 
425  if( !lib_match_parent )
426  lib_match = nullptr;
427  else
428  lib_match = lib_match_parent.get();
429  }
430 
431  // Test whether there is a conflict or if the symbol can only be found in the cache.
432  if( LIB_ID::HasIllegalChars( symbol_id.GetLibItemName() ) == -1 )
433  {
434  if( cache_match && lib_match &&
435  !cache_match->PinsConflictWith( *lib_match, true, true, true, true, false ) )
436  {
437  continue;
438  }
439 
440  if( !cache_match && lib_match )
441  continue;
442  }
443 
444  // Fix illegal LIB_ID name characters.
445  wxString new_name = LIB_ID::FixIllegalChars( symbol_id.GetLibItemName(), false );
446 
447  // Differentiate symbol name in the rescue library by appending the symbol library
448  // table nickname to the symbol name to prevent name clashes in the rescue library.
449  wxString libNickname = GetRescueLibraryFileName( aRescuer.Schematic() ).GetName();
450 
451  // Spaces in the file name will break the symbol name because they are not
452  // quoted in the symbol library file format.
453  libNickname.Replace( wxT( " " ), wxT( "-" ) );
454  LIB_ID new_id( libNickname, new_name + wxT( "-" ) + symbol_id.GetLibNickname().wx_str() );
455 
456  RESCUE_SYMBOL_LIB_TABLE_CANDIDATE candidate( symbol_id, new_id, cache_match, lib_match,
457  eachSymbol->GetUnit(),
458  eachSymbol->GetConvert() );
459 
460  candidate_map[symbol_id] = candidate;
461  }
462  }
463 
464  // Now, dump the map into aCandidates
465  for( const candidate_map_t::value_type& each_pair : candidate_map )
466  {
467  aCandidates.push_back( new RESCUE_SYMBOL_LIB_TABLE_CANDIDATE( each_pair.second ) );
468  }
469 }
LIB_SYMBOL_REF & GetParent()
Definition: lib_symbol.h:124
SCHEMATIC * Schematic()
const UTF8 & GetLibItemName() const
Definition: lib_id.h:104
PROJECT * GetPrj()
Return the #SCH_PROJECT object for access to the symbol libraries.
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:189
static wxFileName GetRescueLibraryFileName(SCHEMATIC *aSchematic)
bool IsAlias() const
Definition: lib_symbol.h:172
std::shared_ptr< LIB_SYMBOL > LIB_SYMBOL_SPTR
shared pointer to LIB_SYMBOL
Definition: lib_symbol.h:42
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
LIB_SYMBOL * SchGetLibSymbol(const LIB_ID &aLibId, SYMBOL_LIB_TABLE *aLibTable, SYMBOL_LIB *aCacheLib, wxWindow *aParent, bool aShowErrorMsg)
Load symbol from symbol library table.
Define a library symbol object.
Definition: lib_symbol.h:96
static LIB_SYMBOL * findSymbol(const wxString &aName, SYMBOL_LIBS *aLibs, bool aCached)
Search the libraries for the first symbol with a given name.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:90
UTF8 Format() const
Definition: lib_id.cpp:116
static int HasIllegalChars(const UTF8 &aLibItemName)
Examine aLibItemName for invalid LIB_ID item name characters.
Definition: lib_id.cpp:173
Schematic symbol object.
Definition: sch_symbol.h:78
std::vector< SCH_SYMBOL * > * GetSymbols()
Get the list of symbols that need rescued.
wxString wx_str() const
Definition: utf8.cpp:46
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...

References CTX_LIBID, EscapeString(), findSymbol(), LIB_ID::FixIllegalChars(), LIB_ID::Format(), LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), LIB_SYMBOL::GetParent(), RESCUER::GetPrj(), GetRescueLibraryFileName(), RESCUER::GetSymbols(), LIB_ID::HasIllegalChars(), LIB_SYMBOL::IsAlias(), LIB_SYMBOL::PinsConflictWith(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE(), RESCUER::Schematic(), SchGetLibSymbol(), and UTF8::wx_str().

Referenced by SYMBOL_LIB_TABLE_RESCUER::FindCandidates().

◆ GetActionDescription()

wxString RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::GetActionDescription ( ) const
overridevirtual

Get a description of the action proposed, for displaying in the UI.

Implements RESCUE_CANDIDATE.

Definition at line 472 of file project_rescue.cpp.

473 {
474  wxString action;
475 
477  {
478  action.Printf( _( "Cannot rescue symbol %s which is not available in any library or "
479  "the cache." ),
481  }
482  else if( m_cache_candidate && !m_lib_candidate )
483  {
484  action.Printf( _( "Rescue symbol %s found only in cache library to %s." ),
486  m_new_id.Format().wx_str() );
487  }
488  else
489  {
490  action.Printf( _( "Rescue modified symbol %s to %s" ),
492  m_new_id.Format().wx_str() );
493  }
494 
495  return action;
496 }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:104
#define _(s)
LIB_SYMBOL * m_lib_candidate
UTF8 Format() const
Definition: lib_id.cpp:116
wxString wx_str() const
Definition: utf8.cpp:46

References _, LIB_ID::Format(), LIB_ID::GetLibItemName(), m_cache_candidate, RESCUE_CANDIDATE::m_lib_candidate, m_new_id, m_requested_id, and UTF8::wx_str().

◆ GetCacheCandidate()

virtual LIB_SYMBOL* RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::GetCacheCandidate ( ) const
inlineoverridevirtual

Get the part that can be loaded from the project cache, if possible, or else NULL.

Reimplemented from RESCUE_CANDIDATE.

Definition at line 213 of file project_rescue.h.

213 { return m_cache_candidate; }

References m_cache_candidate.

◆ GetConvert()

int RESCUE_CANDIDATE::GetConvert ( ) const
inlineinherited

Definition at line 95 of file project_rescue.h.

95 { return m_convert; }

References RESCUE_CANDIDATE::m_convert.

Referenced by DIALOG_RESCUE_EACH::displayItemsInConflict().

◆ GetLibCandidate()

virtual LIB_SYMBOL* RESCUE_CANDIDATE::GetLibCandidate ( ) const
inlinevirtualinherited

Get the part the would be loaded from the libraries, if possible, or else NULL.

Definition at line 91 of file project_rescue.h.

91 { return m_lib_candidate; }
LIB_SYMBOL * m_lib_candidate

References RESCUE_CANDIDATE::m_lib_candidate.

Referenced by DIALOG_RESCUE_EACH::displayItemsInConflict().

◆ GetNewName()

virtual wxString RESCUE_CANDIDATE::GetNewName ( ) const
inlinevirtualinherited

Get the name we're proposing changing it to.

Definition at line 79 of file project_rescue.h.

79 { return m_new_name; }

References RESCUE_CANDIDATE::m_new_name.

◆ GetRequestedName()

virtual wxString RESCUE_CANDIDATE::GetRequestedName ( ) const
inlinevirtualinherited

Get the name that was originally requested in the schematic.

Definition at line 74 of file project_rescue.h.

74 { return m_requested_name; }
wxString m_requested_name

References RESCUE_CANDIDATE::m_requested_name.

Referenced by DIALOG_RESCUE_EACH::PopulateConflictList(), and DIALOG_RESCUE_EACH::PopulateInstanceList().

◆ GetUnit()

int RESCUE_CANDIDATE::GetUnit ( ) const
inlineinherited

Definition at line 93 of file project_rescue.h.

93 { return m_unit; }

References RESCUE_CANDIDATE::m_unit.

Referenced by DIALOG_RESCUE_EACH::displayItemsInConflict().

◆ PerformAction()

bool RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::PerformAction ( RESCUER aRescuer)
overridevirtual

Perform the actual rescue action.

If successful, this must log the rescue using RESCUER::LogRescue to allow it to be reversed.

Returns
True on success.

Implements RESCUE_CANDIDATE.

Definition at line 499 of file project_rescue.cpp.

500 {
502 
503  wxCHECK_MSG( tmp, false, wxT( "Both cache and library symbols undefined." ) );
504 
505  std::unique_ptr<LIB_SYMBOL> new_symbol = tmp->Flatten();
506  new_symbol->SetLibId( m_new_id );
507  new_symbol->SetName( m_new_id.GetLibItemName() );
508  aRescuer->AddSymbol( new_symbol.get() );
509 
510  for( SCH_SYMBOL* eachSymbol : *aRescuer->GetSymbols() )
511  {
512  if( eachSymbol->GetLibId() != m_requested_id )
513  continue;
514 
515  eachSymbol->SetLibId( m_new_id );
516  eachSymbol->ClearFlags();
517  aRescuer->LogRescue( eachSymbol, m_requested_id.Format(), m_new_id.Format() );
518  }
519 
520  return true;
521 }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:104
Define a library symbol object.
Definition: lib_symbol.h:96
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Definition: lib_symbol.cpp:380
LIB_SYMBOL * m_lib_candidate
UTF8 Format() const
Definition: lib_id.cpp:116
Schematic symbol object.
Definition: sch_symbol.h:78
std::vector< SCH_SYMBOL * > * GetSymbols()
Get the list of symbols that need rescued.
void LogRescue(SCH_SYMBOL *aSymbol, const wxString &aOldName, const wxString &aNewName)
Used by individual RESCUE_CANDIDATE objects to log a rescue for undoing.
virtual void AddSymbol(LIB_SYMBOL *aNewSymbol)=0

References RESCUER::AddSymbol(), LIB_SYMBOL::Flatten(), LIB_ID::Format(), LIB_ID::GetLibItemName(), RESCUER::GetSymbols(), RESCUER::LogRescue(), m_cache_candidate, RESCUE_CANDIDATE::m_lib_candidate, m_new_id, and m_requested_id.

Member Data Documentation

◆ m_cache_candidate

LIB_SYMBOL* RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::m_cache_candidate
private

◆ m_convert

◆ m_lib_candidate

◆ m_new_id

LIB_ID RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::m_new_id
private

◆ m_new_name

◆ m_requested_id

LIB_ID RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::m_requested_id
private

◆ m_requested_name

◆ m_unit


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