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  for( SCH_SYMBOL* eachSymbol : *( aRescuer.GetSymbols() ) )
382  {
383  const LIB_ID& symbol_id = eachSymbol->GetLibId();
384 
385  if( old_symbol_id != symbol_id )
386  {
387  // A new symbol name is found (a new group starts here).
388  // Search the symbol names candidates only once for this group:
389  old_symbol_id = symbol_id;
390 
391  // Get the library symbol from the cache library. It will be a flattened
392  // symbol by default (no inheritance).
393  cache_match = findSymbol( symbol_id.Format().wx_str(), aRescuer.GetPrj()->SchLibs(),
394  true );
395 
396  // Get the library symbol from the symbol library table.
397  lib_match = SchGetLibSymbol( symbol_id, aRescuer.GetPrj()->SchSymbolLibTable() );
398 
399  if( !cache_match && !lib_match )
400  continue;
401 
402  LIB_SYMBOL_SPTR lib_match_parent;
403 
404  // If it's a derive symbol, use the parent symbol to perform the pin test.
405  if( lib_match && lib_match->IsAlias() )
406  {
407  lib_match_parent = lib_match->GetParent().lock();
408 
409  if( !lib_match_parent )
410  lib_match = nullptr;
411  else
412  lib_match = lib_match_parent.get();
413  }
414 
415  // Test whether there is a conflict or if the symbol can only be found in the cache.
416  if( LIB_ID::HasIllegalChars( symbol_id.GetLibItemName() ) == -1 )
417  {
418  if( cache_match && lib_match &&
419  !cache_match->PinsConflictWith( *lib_match, true, true, true, true, false ) )
420  {
421  continue;
422  }
423 
424  if( !cache_match && lib_match )
425  continue;
426  }
427 
428  // Fix illegal LIB_ID name characters.
429  wxString new_name = LIB_ID::FixIllegalChars( symbol_id.GetLibItemName(), false );
430 
431  // Differentiate symbol name in the rescue library by appending the symbol library
432  // table nickname to the symbol name to prevent name clashes in the rescue library.
433  wxString libNickname = GetRescueLibraryFileName( aRescuer.Schematic() ).GetName();
434 
435  // Spaces in the file name will break the symbol name because they are not
436  // quoted in the symbol library file format.
437  libNickname.Replace( " ", "-" );
438  LIB_ID new_id( libNickname, new_name + "-" + symbol_id.GetLibNickname().wx_str() );
439 
440  RESCUE_SYMBOL_LIB_TABLE_CANDIDATE candidate( symbol_id, new_id, cache_match, lib_match,
441  eachSymbol->GetUnit(),
442  eachSymbol->GetConvert() );
443 
444  candidate_map[symbol_id] = candidate;
445  }
446  }
447 
448  // Now, dump the map into aCandidates
449  for( const candidate_map_t::value_type& each_pair : candidate_map )
450  {
451  aCandidates.push_back( new RESCUE_SYMBOL_LIB_TABLE_CANDIDATE( each_pair.second ) );
452  }
453 }
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)
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.
bool PinsConflictWith(const LIB_SYMBOL &aOtherSymbol, bool aTestNums, bool aTestNames, bool aTestType, bool aTestOrientation, bool aTestLength) const
Return true if this symbol's pins do not match another symbol's pins.
Definition: lib_symbol.cpp:738
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

References 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::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 456 of file project_rescue.cpp.

457 {
458  wxString action;
459 
461  {
462  action.Printf( _( "Cannot rescue symbol %s which is not available in any library or "
463  "the cache." ),
465  }
466  else if( m_cache_candidate && !m_lib_candidate )
467  {
468  action.Printf( _( "Rescue symbol %s found only in cache library to %s." ),
470  m_new_id.Format().wx_str() );
471  }
472  else
473  {
474  action.Printf( _( "Rescue modified symbol %s to %s" ),
476  m_new_id.Format().wx_str() );
477  }
478 
479  return action;
480 }
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 483 of file project_rescue.cpp.

484 {
486 
487  wxCHECK_MSG( tmp, false, "Both cache and library symbols undefined." );
488 
489  std::unique_ptr<LIB_SYMBOL> new_symbol = tmp->Flatten();
490  new_symbol->SetLibId( m_new_id );
491  new_symbol->SetName( m_new_id.GetLibItemName() );
492  aRescuer->AddSymbol( new_symbol.get() );
493 
494  for( SCH_SYMBOL* eachSymbol : *aRescuer->GetSymbols() )
495  {
496  if( eachSymbol->GetLibId() != m_requested_id )
497  continue;
498 
499  eachSymbol->SetLibId( m_new_id );
500  eachSymbol->ClearFlags();
501  aRescuer->LogRescue( eachSymbol, m_requested_id.Format(), m_new_id.Format() );
502  }
503 
504  return true;
505 }
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:332
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: