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

Constructor & Destructor Documentation

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

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

338  : RESCUE_CANDIDATE()
339 {
340  m_requested_id = aRequestedId;
341  m_requested_name = aRequestedId.Format();
342  m_new_id = aNewId;
343  m_lib_candidate = aLibCandidate;
344  m_cache_candidate = aCacheCandidate;
345 }
LIB_PART * m_lib_candidate
UTF8 Format() const
Definition: lib_id.cpp:237
wxString m_requested_name
RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::RESCUE_SYMBOL_LIB_TABLE_CANDIDATE ( )

Definition at line 348 of file project_rescue.cpp.

References m_cache_candidate, and RESCUE_CANDIDATE::m_lib_candidate.

Referenced by FindRescues().

349 {
350  m_cache_candidate = NULL;
351  m_lib_candidate = NULL;
352 }
LIB_PART * m_lib_candidate

Member Function Documentation

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

References find_component(), LIB_ID::FixIllegalChars(), LIB_ID::Format(), RESCUER::GetComponents(), RESCUER::GetFrame(), LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), SCH_BASE_FRAME::GetLibPart(), RESCUER::GetPrj(), GetRescueLibraryFileName(), LIB_ID::HasIllegalChars(), LIB_ID::ID_SCH, LIB_PART::PinsConflictWith(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE(), and UTF8::wx_str().

Referenced by SYMBOL_LIB_TABLE_RESCUER::FindCandidates().

358 {
359  typedef std::map<LIB_ID, RESCUE_SYMBOL_LIB_TABLE_CANDIDATE> candidate_map_t;
360 
361  candidate_map_t candidate_map;
362 
363  // Remember the list of components is sorted by LIB_ID.
364  // So a search in libraries is made only once by group
365  LIB_PART* cache_match = nullptr;
366  LIB_PART* lib_match = nullptr;
367  LIB_ID old_part_id;
368 
369  for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) )
370  {
371  LIB_ID part_id = each_component->GetLibId();
372 
373  if( old_part_id != part_id )
374  {
375  // A new part name is found (a new group starts here).
376  // Search the symbol names candidates only once for this group:
377  old_part_id = part_id;
378  cache_match = find_component( part_id.Format().wx_str(), aRescuer.GetPrj()->SchLibs(),
379  true );
380 
381  lib_match = aRescuer.GetFrame()->GetLibPart( part_id );
382 
383  if( !cache_match && !lib_match )
384  continue;
385 
386  // Test whether there is a conflict or if the symbol can only be found in the cache.
387  if( LIB_ID::HasIllegalChars( part_id.GetLibItemName(), LIB_ID::ID_SCH ) == -1 )
388  {
389  if( cache_match && lib_match &&
390  !cache_match->PinsConflictWith( *lib_match, true, true, true, true, false ) )
391  continue;
392 
393  if( !cache_match && lib_match )
394  continue;
395  }
396 
397  // Fix illegal LIB_ID name characters.
398  wxString new_name = LIB_ID::FixIllegalChars( part_id.GetLibItemName(), LIB_ID::ID_SCH );
399 
400  // Differentiate symbol name in the rescue library by appending the symbol library
401  // table nickname to the symbol name to prevent name clashes in the rescue library.
402  wxString libNickname = GetRescueLibraryFileName().GetName();
403 
404  // Spaces in the file name will break the symbol name because they are not
405  // quoted in the symbol library file format.
406  libNickname.Replace( " ", "-" );
407  LIB_ID new_id( libNickname, new_name + "-" + part_id.GetLibNickname().wx_str() );
408 
409  RESCUE_SYMBOL_LIB_TABLE_CANDIDATE candidate( part_id, new_id, cache_match, lib_match );
410 
411  candidate_map[part_id] = candidate;
412  }
413  }
414 
415  // Now, dump the map into aCandidates
416  for( const candidate_map_t::value_type& each_pair : candidate_map )
417  {
418  aCandidates.push_back( new RESCUE_SYMBOL_LIB_TABLE_CANDIDATE( each_pair.second ) );
419  }
420 }
bool PinsConflictWith(LIB_PART &aOtherPart, bool aTestNums, bool aTestNames, bool aTestType, bool aTestOrientation, bool aTestLength)
Return true if this part&#39;s pins do not match another part&#39;s pins.
PROJECT * GetPrj()
Return the #SCH_PROJECT object for access to the symbol libraries.
SCH_EDIT_FRAME * GetFrame()
static int HasIllegalChars(const UTF8 &aLibItemName, LIB_ID_TYPE aType)
Examine aLibItemName for invalid LIB_ID item name characters.
Definition: lib_id.cpp:336
LIB_PART * GetLibPart(const LIB_ID &aLibId, bool aUseCacheLib=false, bool aShowErrorMsg=false)
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
wxString wx_str() const
Definition: utf8.cpp:51
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
Define a library symbol object.
static LIB_PART * find_component(const wxString &aName, PART_LIBS *aLibs, bool aCached)
Search the libraries for the first component with a given name.
static wxFileName GetRescueLibraryFileName()
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
std::vector< SCH_COMPONENT * > * GetComponents()
Get the list of symbols that need rescued.
UTF8 Format() const
Definition: lib_id.cpp:237
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, LIB_ID_TYPE aType, bool aLib=false)
Replace illegal LIB_ID item name characters with underscores &#39;_&#39;.
Definition: lib_id.cpp:352
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
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 423 of file project_rescue.cpp.

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

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

References RESCUE_CANDIDATE::GetActionDescription(), and RESCUE_CANDIDATE::PerformAction().

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

References RESCUE_CANDIDATE::GetActionDescription(), RESCUE_CANDIDATE::m_lib_candidate, and RESCUE_CANDIDATE::PerformAction().

Referenced by DIALOG_RESCUE_EACH::displayItemsInConflict().

94 { return m_lib_candidate; }
LIB_PART * m_lib_candidate
virtual wxString RESCUE_CANDIDATE::GetNewName ( ) const
inlinevirtualinherited

Get the name we're proposing changing it to.

Definition at line 82 of file project_rescue.h.

References RESCUE_CANDIDATE::m_new_name.

82 { return m_new_name; }
virtual wxString RESCUE_CANDIDATE::GetRequestedName ( ) const
inlinevirtualinherited

Get the name that was originally requested in the schematic.

Definition at line 77 of file project_rescue.h.

References RESCUE_CANDIDATE::m_requested_name.

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

77 { return m_requested_name; }
wxString m_requested_name
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 441 of file project_rescue.cpp.

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

442 {
444 
445  wxCHECK_MSG( tmp, false, "Both cache and library symbols undefined." );
446 
447  LIB_PART new_part( *tmp );
448  new_part.SetLibId( m_new_id );
449  new_part.SetName( m_new_id.GetLibItemName() );
450  new_part.RemoveAllAliases();
451  aRescuer->AddPart( &new_part );
452 
453  for( SCH_COMPONENT* each_component : *aRescuer->GetComponents() )
454  {
455  if( each_component->GetLibId() != m_requested_id )
456  continue;
457 
458  each_component->SetLibId( m_new_id );
459  each_component->ClearFlags();
460  aRescuer->LogRescue( each_component, m_requested_id.Format(), m_new_id.Format() );
461  }
462 
463  return true;
464 }
LIB_PART * m_lib_candidate
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
Define a library symbol object.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
virtual void AddPart(LIB_PART *aNewPart)=0
std::vector< SCH_COMPONENT * > * GetComponents()
Get the list of symbols that need rescued.
UTF8 Format() const
Definition: lib_id.cpp:237
void LogRescue(SCH_COMPONENT *aComponent, const wxString &aOldName, const wxString &aNewName)
Used by individual RESCUE_CANDIDATE objects to log a rescue for undoing.

Member Data Documentation

LIB_PART* RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::m_cache_candidate
private
LIB_ID RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::m_new_id
private
LIB_ID RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::m_requested_id
private

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