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_PART *aCacheCandidate, LIB_PART *aLibCandidate, int aUnit=0, int aConvert=0)
 Constructor RESCUE_CANDIDATE. More...
 
 RESCUE_SYMBOL_LIB_TABLE_CANDIDATE ()
 
virtual LIB_PARTGetCacheCandidate () 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_PARTGetLibCandidate () 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_PARTm_lib_candidate
 
int m_unit
 
int m_convert
 

Private Attributes

LIB_ID m_requested_id
 
LIB_ID m_new_id
 
LIB_PARTm_cache_candidate
 

Detailed Description

Definition at line 184 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_PART aCacheCandidate,
LIB_PART aLibCandidate,
int  aUnit = 0,
int  aConvert = 0 
)

Constructor RESCUE_CANDIDATE.

Parameters
aRequestedName- the name the schematic asks for
aNewName- the name we want to change it to
aCacheCandidate- the part from the cache
aLibCandidate- the part that would be loaded from the library
aUnitThe unit of the rescued symbol.
aConvertThe body style of the rescued symbol.

Definition at line 340 of file project_rescue.cpp.

346  : RESCUE_CANDIDATE()
347 {
348  m_requested_id = aRequestedId;
349  m_requested_name = aRequestedId.Format();
350  m_new_id = aNewId;
351  m_lib_candidate = aLibCandidate;
352  m_cache_candidate = aCacheCandidate;
353  m_unit = aUnit;
354  m_convert = aConvert;
355 }
LIB_PART * m_lib_candidate
UTF8 Format() const
Definition: lib_id.cpp:237
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 358 of file project_rescue.cpp.

359 {
362 }
LIB_PART * m_lib_candidate
#define NULL

References m_cache_candidate, RESCUE_CANDIDATE::m_lib_candidate, and NULL.

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
aRescuer- the working RESCUER instance.
aCandidates- the vector the will hold the candidates.

Definition at line 365 of file project_rescue.cpp.

368 {
369  typedef std::map<LIB_ID, RESCUE_SYMBOL_LIB_TABLE_CANDIDATE> candidate_map_t;
370 
371  candidate_map_t candidate_map;
372 
373  // Remember the list of components is sorted by LIB_ID.
374  // So a search in libraries is made only once by group
375  LIB_PART* cache_match = nullptr;
376  LIB_PART* lib_match = nullptr;
377  LIB_ID old_part_id;
378 
379  for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) )
380  {
381  const LIB_ID& part_id = each_component->GetLibId();
382 
383  if( old_part_id != part_id )
384  {
385  // A new part name is found (a new group starts here).
386  // Search the symbol names candidates only once for this group:
387  old_part_id = part_id;
388 
389  // Get the library symbol from the cache library. It will be a flattened
390  // symbol by default (no inheritance).
391  cache_match = find_component( part_id.Format().wx_str(), aRescuer.GetPrj()->SchLibs(),
392  true );
393 
394  // Get the library symbol from the symbol library table.
395  lib_match = SchGetLibPart( part_id, aRescuer.GetPrj()->SchSymbolLibTable() );
396 
397  if( !cache_match && !lib_match )
398  continue;
399 
400  PART_SPTR lib_match_parent;
401 
402  // If it's a derive symbol, use the parent symbol to perform the pin test.
403  if( lib_match && lib_match->IsAlias() )
404  {
405  lib_match_parent = lib_match->GetParent().lock();
406 
407  if( !lib_match_parent )
408  {
409  lib_match = nullptr;
410  }
411  else
412  {
413  lib_match = lib_match_parent.get();
414  }
415  }
416 
417  // Test whether there is a conflict or if the symbol can only be found in the cache.
418  if( LIB_ID::HasIllegalChars( part_id.GetLibItemName(), LIB_ID::ID_SCH ) == -1 )
419  {
420  if( cache_match && lib_match &&
421  !cache_match->PinsConflictWith( *lib_match, true, true, true, true, false ) )
422  continue;
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( part_id.GetLibItemName(), LIB_ID::ID_SCH );
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 + "-" + part_id.GetLibNickname().wx_str() );
439 
440  RESCUE_SYMBOL_LIB_TABLE_CANDIDATE candidate( part_id, new_id, cache_match, lib_match,
441  each_component->GetUnit(),
442  each_component->GetConvert() );
443 
444  candidate_map[part_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 }
bool PinsConflictWith(LIB_PART &aOtherPart, bool aTestNums, bool aTestNames, bool aTestType, bool aTestOrientation, bool aTestLength)
Return true if this part's pins do not match another part's pins.
SCHEMATIC * Schematic()
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
PROJECT * GetPrj()
Return the #SCH_PROJECT object for access to the symbol libraries.
static wxFileName GetRescueLibraryFileName(SCHEMATIC *aSchematic)
static int HasIllegalChars(const UTF8 &aLibItemName, LIB_ID_TYPE aType)
Examine aLibItemName for invalid LIB_ID item name characters.
Definition: lib_id.cpp:336
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
std::shared_ptr< LIB_PART > PART_SPTR
shared pointer to LIB_PART
PART_REF & GetParent()
Define a library symbol object.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
static LIB_PART * find_component(const wxString &aName, PART_LIBS *aLibs, bool aCached)
Search the libraries for the first component with a given name.
UTF8 Format() const
Definition: lib_id.cpp:237
wxString wx_str() const
Definition: utf8.cpp:51
Schematic symbol object.
Definition: sch_component.h:88
std::vector< SCH_COMPONENT * > * GetComponents()
Get the list of symbols that need rescued.
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, LIB_ID_TYPE aType, bool aLib=false)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:352
LIB_PART * SchGetLibPart(const LIB_ID &aLibId, SYMBOL_LIB_TABLE *aLibTable, PART_LIB *aCacheLib, wxWindow *aParent, bool aShowErrorMsg)
Load symbol from symbol library table.

References find_component(), LIB_ID::FixIllegalChars(), LIB_ID::Format(), RESCUER::GetComponents(), LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), LIB_PART::GetParent(), RESCUER::GetPrj(), GetRescueLibraryFileName(), LIB_ID::HasIllegalChars(), LIB_ID::ID_SCH, LIB_PART::PinsConflictWith(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE(), RESCUER::Schematic(), SchGetLibPart(), 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  action.Printf( _( "Cannot rescue symbol %s which is not available in any library or "
462  "the cache." ), m_requested_id.GetLibItemName().wx_str() );
463  else if( m_cache_candidate && !m_lib_candidate )
464  action.Printf( _( "Rescue symbol %s found only in cache library to %s." ),
466  else
467  action.Printf( _( "Rescue modified symbol %s to %s" ),
469 
470  return action;
471 }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
LIB_PART * m_lib_candidate
UTF8 Format() const
Definition: lib_id.cpp:237
#define _(s)
Definition: 3d_actions.cpp:33
wxString wx_str() const
Definition: utf8.cpp:51

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_PART* 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 214 of file project_rescue.h.

References m_cache_candidate.

◆ GetConvert()

int RESCUE_CANDIDATE::GetConvert ( ) const
inlineinherited

Definition at line 102 of file project_rescue.h.

102 { return m_convert; }

References RESCUE_CANDIDATE::m_convert.

Referenced by DIALOG_RESCUE_EACH::displayItemsInConflict().

◆ GetLibCandidate()

virtual LIB_PART* RESCUE_CANDIDATE::GetLibCandidate ( ) const
inlinevirtualinherited

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

Definition at line 98 of file project_rescue.h.

98 { return m_lib_candidate; }
LIB_PART * 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 86 of file project_rescue.h.

86 { 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 81 of file project_rescue.h.

81 { 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 100 of file project_rescue.h.

100 { 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 474 of file project_rescue.cpp.

475 {
477 
478  wxCHECK_MSG( tmp, false, "Both cache and library symbols undefined." );
479 
480  std::unique_ptr<LIB_PART> new_part = tmp->Flatten();
481  new_part->SetLibId( m_new_id );
482  new_part->SetName( m_new_id.GetLibItemName() );
483  aRescuer->AddPart( new_part.get() );
484 
485  for( SCH_COMPONENT* each_component : *aRescuer->GetComponents() )
486  {
487  if( each_component->GetLibId() != m_requested_id )
488  continue;
489 
490  each_component->SetLibId( m_new_id );
491  each_component->ClearFlags();
492  aRescuer->LogRescue( each_component, m_requested_id.Format(), m_new_id.Format() );
493  }
494 
495  return true;
496 }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
LIB_PART * m_lib_candidate
Define a library symbol object.
std::unique_ptr< LIB_PART > Flatten() const
Return a flattened symbol inheritance to the caller.
UTF8 Format() const
Definition: lib_id.cpp:237
Schematic symbol object.
Definition: sch_component.h:88
virtual void AddPart(LIB_PART *aNewPart)=0
std::vector< SCH_COMPONENT * > * GetComponents()
Get the list of symbols that need rescued.
void LogRescue(SCH_COMPONENT *aComponent, const wxString &aOldName, const wxString &aNewName)
Used by individual RESCUE_CANDIDATE objects to log a rescue for undoing.

References RESCUER::AddPart(), LIB_PART::Flatten(), LIB_ID::Format(), RESCUER::GetComponents(), LIB_ID::GetLibItemName(), RESCUER::LogRescue(), m_cache_candidate, RESCUE_CANDIDATE::m_lib_candidate, m_new_id, and m_requested_id.

Member Data Documentation

◆ m_cache_candidate

LIB_PART* 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: