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

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
 

Private Attributes

LIB_ID m_requested_id
 
LIB_ID m_new_id
 
LIB_PARTm_cache_candidate
 

Detailed Description

Definition at line 173 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 
)

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

Definition at line 333 of file project_rescue.cpp.

337  : RESCUE_CANDIDATE()
338 {
339  m_requested_id = aRequestedId;
340  m_requested_name = aRequestedId.Format();
341  m_new_id = aNewId;
342  m_lib_candidate = aLibCandidate;
343  m_cache_candidate = aCacheCandidate;
344 }
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_lib_candidate, m_new_id, m_requested_id, and RESCUE_CANDIDATE::m_requested_name.

◆ RESCUE_SYMBOL_LIB_TABLE_CANDIDATE() [2/2]

RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::RESCUE_SYMBOL_LIB_TABLE_CANDIDATE ( )

Definition at line 347 of file project_rescue.cpp.

348 {
349  m_cache_candidate = NULL;
350  m_lib_candidate = NULL;
351 }
LIB_PART * 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
aRescuer- the working RESCUER instance.
aCandidates- the vector the will hold the candidates.

Definition at line 354 of file project_rescue.cpp.

357 {
358  typedef std::map<LIB_ID, RESCUE_SYMBOL_LIB_TABLE_CANDIDATE> candidate_map_t;
359 
360  candidate_map_t candidate_map;
361 
362  // Remember the list of components is sorted by LIB_ID.
363  // So a search in libraries is made only once by group
364  LIB_PART* cache_match = nullptr;
365  LIB_PART* lib_match = nullptr;
366  LIB_ID old_part_id;
367 
368  for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) )
369  {
370  LIB_ID part_id = each_component->GetLibId();
371 
372  if( old_part_id != part_id )
373  {
374  // A new part name is found (a new group starts here).
375  // Search the symbol names candidates only once for this group:
376  old_part_id = part_id;
377  cache_match = find_component( part_id.Format().wx_str(), aRescuer.GetPrj()->SchLibs(),
378  true );
379 
380  lib_match = SchGetLibPart( part_id, aRescuer.GetPrj()->SchSymbolLibTable() );
381 
382  if( !cache_match && !lib_match )
383  continue;
384 
385  // Test whether there is a conflict or if the symbol can only be found in the cache.
386  if( LIB_ID::HasIllegalChars( part_id.GetLibItemName(), LIB_ID::ID_SCH ) == -1 )
387  {
388  if( cache_match && lib_match &&
389  !cache_match->PinsConflictWith( *lib_match, true, true, true, true, false ) )
390  continue;
391 
392  if( !cache_match && lib_match )
393  continue;
394  }
395 
396  // Fix illegal LIB_ID name characters.
397  wxString new_name = LIB_ID::FixIllegalChars( part_id.GetLibItemName(), LIB_ID::ID_SCH );
398 
399  // Differentiate symbol name in the rescue library by appending the symbol library
400  // table nickname to the symbol name to prevent name clashes in the rescue library.
401  wxString libNickname = GetRescueLibraryFileName().GetName();
402 
403  // Spaces in the file name will break the symbol name because they are not
404  // quoted in the symbol library file format.
405  libNickname.Replace( " ", "-" );
406  LIB_ID new_id( libNickname, new_name + "-" + part_id.GetLibNickname().wx_str() );
407 
408  RESCUE_SYMBOL_LIB_TABLE_CANDIDATE candidate( part_id, new_id, cache_match, lib_match );
409 
410  candidate_map[part_id] = candidate;
411  }
412  }
413 
414  // Now, dump the map into aCandidates
415  for( const candidate_map_t::value_type& each_pair : candidate_map )
416  {
417  aCandidates.push_back( new RESCUE_SYMBOL_LIB_TABLE_CANDIDATE( each_pair.second ) );
418  }
419 }
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.
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
PROJECT * GetPrj()
Return the #SCH_PROJECT object for access to the symbol libraries.
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
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
static wxFileName GetRescueLibraryFileName()
wxString wx_str() const
Definition: utf8.cpp:51
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
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)

References find_component(), LIB_ID::FixIllegalChars(), LIB_ID::Format(), RESCUER::GetComponents(), LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), RESCUER::GetPrj(), GetRescueLibraryFileName(), LIB_ID::HasIllegalChars(), LIB_ID::ID_SCH, LIB_PART::PinsConflictWith(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE(), 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 422 of file project_rescue.cpp.

423 {
424  wxString action;
425 
427  action.Printf( _( "Cannot rescue symbol %s which is not available in any library or "
428  "the cache." ), m_requested_id.GetLibItemName().wx_str() );
429  else if( m_cache_candidate && !m_lib_candidate )
430  action.Printf( _( "Rescue symbol %s found only in cache library to %s." ),
432  else
433  action.Printf( _( "Rescue modified symbol %s to %s" ),
435 
436  return action;
437 }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
LIB_PART * m_lib_candidate
#define _(s)
UTF8 Format() const
Definition: lib_id.cpp:237
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 200 of file project_rescue.h.

References m_cache_candidate.

◆ 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 96 of file project_rescue.h.

96 { 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 84 of file project_rescue.h.

84 { 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 79 of file project_rescue.h.

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

◆ 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 440 of file project_rescue.cpp.

441 {
443 
444  wxCHECK_MSG( tmp, false, "Both cache and library symbols undefined." );
445 
446  LIB_PART new_part( *tmp );
447  new_part.SetLibId( m_new_id );
448  new_part.SetName( m_new_id.GetLibItemName() );
449  new_part.RemoveAllAliases();
450  aRescuer->AddPart( &new_part );
451 
452  for( SCH_COMPONENT* each_component : *aRescuer->GetComponents() )
453  {
454  if( each_component->GetLibId() != m_requested_id )
455  continue;
456 
457  each_component->SetLibId( m_new_id );
458  each_component->ClearFlags();
459  aRescuer->LogRescue( each_component, m_requested_id.Format(), m_new_id.Format() );
460  }
461 
462  return true;
463 }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
LIB_PART * m_lib_candidate
Define a library symbol object.
UTF8 Format() const
Definition: lib_id.cpp:237
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
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_ID::Format(), RESCUER::GetComponents(), LIB_ID::GetLibItemName(), RESCUER::LogRescue(), m_cache_candidate, RESCUE_CANDIDATE::m_lib_candidate, m_new_id, m_requested_id, LIB_PART::RemoveAllAliases(), LIB_PART::SetLibId(), and LIB_PART::SetName().

Member Data Documentation

◆ m_cache_candidate

LIB_PART* RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::m_cache_candidate
private

◆ 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


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