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

331  : RESCUE_CANDIDATE()
332 {
333  m_requested_id = aRequestedId;
334  m_requested_name = aRequestedId.Format();
335  m_new_id = aNewId;
336  m_lib_candidate = aLibCandidate;
337  m_cache_candidate = aCacheCandidate;
338 }
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 341 of file project_rescue.cpp.

342 {
345 }
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 348 of file project_rescue.cpp.

351 {
352  typedef std::map<LIB_ID, RESCUE_SYMBOL_LIB_TABLE_CANDIDATE> candidate_map_t;
353 
354  candidate_map_t candidate_map;
355 
356  // Remember the list of components is sorted by LIB_ID.
357  // So a search in libraries is made only once by group
358  LIB_PART* cache_match = nullptr;
359  LIB_PART* lib_match = nullptr;
360  LIB_ID old_part_id;
361 
362  for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) )
363  {
364  const LIB_ID& part_id = each_component->GetLibId();
365 
366  if( old_part_id != part_id )
367  {
368  // A new part name is found (a new group starts here).
369  // Search the symbol names candidates only once for this group:
370  old_part_id = part_id;
371 
372  // Get the library symbol from the cache library. It will be a flattened
373  // symbol by default (no inheritance).
374  cache_match = find_component( part_id.Format().wx_str(), aRescuer.GetPrj()->SchLibs(),
375  true );
376 
377  // Get the library symbol from the symbol library table.
378  lib_match = SchGetLibPart( part_id, aRescuer.GetPrj()->SchSymbolLibTable() );
379 
380  if( !cache_match && !lib_match )
381  continue;
382 
383  PART_SPTR lib_match_parent;
384 
385  // If it's a derive symbol, use the parent symbol to perform the pin test.
386  if( lib_match && lib_match->IsAlias() )
387  {
388  lib_match_parent = lib_match->GetParent().lock();
389 
390  if( !lib_match_parent )
391  {
392  lib_match = nullptr;
393  }
394  else
395  {
396  lib_match = lib_match_parent.get();
397  }
398  }
399 
400  // Test whether there is a conflict or if the symbol can only be found in the cache.
401  if( LIB_ID::HasIllegalChars( part_id.GetLibItemName(), LIB_ID::ID_SCH ) == -1 )
402  {
403  if( cache_match && lib_match &&
404  !cache_match->PinsConflictWith( *lib_match, true, true, true, true, false ) )
405  continue;
406 
407  if( !cache_match && lib_match )
408  continue;
409  }
410 
411  // Fix illegal LIB_ID name characters.
412  wxString new_name = LIB_ID::FixIllegalChars( part_id.GetLibItemName(), LIB_ID::ID_SCH );
413 
414  // Differentiate symbol name in the rescue library by appending the symbol library
415  // table nickname to the symbol name to prevent name clashes in the rescue library.
416  wxString libNickname = GetRescueLibraryFileName().GetName();
417 
418  // Spaces in the file name will break the symbol name because they are not
419  // quoted in the symbol library file format.
420  libNickname.Replace( " ", "-" );
421  LIB_ID new_id( libNickname, new_name + "-" + part_id.GetLibNickname().wx_str() );
422 
423  RESCUE_SYMBOL_LIB_TABLE_CANDIDATE candidate( part_id, new_id, cache_match, lib_match );
424 
425  candidate_map[part_id] = candidate;
426  }
427  }
428 
429  // Now, dump the map into aCandidates
430  for( const candidate_map_t::value_type& each_pair : candidate_map )
431  {
432  aCandidates.push_back( new RESCUE_SYMBOL_LIB_TABLE_CANDIDATE( each_pair.second ) );
433  }
434 }
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
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
static wxFileName GetRescueLibraryFileName()
wxString wx_str() const
Definition: utf8.cpp:51
SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:89
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(), 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 437 of file project_rescue.cpp.

438 {
439  wxString action;
440 
442  action.Printf( _( "Cannot rescue symbol %s which is not available in any library or "
443  "the cache." ), m_requested_id.GetLibItemName().wx_str() );
444  else if( m_cache_candidate && !m_lib_candidate )
445  action.Printf( _( "Rescue symbol %s found only in cache library to %s." ),
447  else
448  action.Printf( _( "Rescue modified symbol %s to %s" ),
450 
451  return action;
452 }
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:31
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 455 of file project_rescue.cpp.

456 {
458 
459  wxCHECK_MSG( tmp, false, "Both cache and library symbols undefined." );
460 
461  LIB_PART new_part( *tmp );
462  new_part.SetLibId( m_new_id );
463  new_part.SetName( m_new_id.GetLibItemName() );
464  aRescuer->AddPart( &new_part );
465 
466  for( SCH_COMPONENT* each_component : *aRescuer->GetComponents() )
467  {
468  if( each_component->GetLibId() != m_requested_id )
469  continue;
470 
471  each_component->SetLibId( m_new_id );
472  each_component->ClearFlags();
473  aRescuer->LogRescue( each_component, m_requested_id.Format(), m_new_id.Format() );
474  }
475 
476  return true;
477 }
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
SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:89
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::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: