KiCad PCB EDA Suite
RESCUE_CACHE_CANDIDATE Class Reference
Inheritance diagram for RESCUE_CACHE_CANDIDATE:
RESCUE_CANDIDATE

Public Member Functions

 RESCUE_CACHE_CANDIDATE (const wxString &aRequestedName, const wxString &aNewName, LIB_PART *aCacheCandidate, LIB_PART *aLibCandidate)
 Constructor RESCUE_CACHE_CANDIDATE. More...
 
 RESCUE_CACHE_CANDIDATE ()
 
virtual wxString GetRequestedName () const override
 Function GetRequestedName Get the name that was originally requested in the schematic. More...
 
virtual wxString GetNewName () const override
 Function GetNewName Get the name we're proposing changing it to. More...
 
virtual LIB_PARTGetCacheCandidate () const override
 Function GetCacheCandidate Get the part that can be loaded from the project cache, if possible, or else NULL. More...
 
virtual LIB_PARTGetLibCandidate () const override
 Function GetLibCandidate Get the part the would be loaded from the libraries, if possible, or else NULL. More...
 
virtual wxString GetActionDescription () const override
 Function GetActionDescription Get a description of the action proposed, for displaying in the UI. More...
 
virtual bool PerformAction (RESCUER *aRescuer) override
 Function PerformAction Perform the actual rescue action. More...
 

Static Public Member Functions

static void FindRescues (RESCUER &aRescuer, boost::ptr_vector< RESCUE_CANDIDATE > &aCandidates)
 Function FindRescues Grab all possible RESCUE_CACHE_CANDIDATEs into a vector. More...
 
static void OpenRescueLibrary ()
 Function OpenRescueLibrary Creates the new rescue library. More...
 
static bool WriteRescueLibrary (SCH_EDIT_FRAME *aEditFrame, PROJECT *aProject)
 Function WriteRescueLibrary Writes out the rescue library. More...
 

Private Attributes

wxString m_requested_name
 
wxString m_new_name
 
LIB_PARTm_cache_candidate
 
LIB_PARTm_lib_candidate
 

Static Private Attributes

static std::unique_ptr< PART_LIBm_rescue_lib
 

Detailed Description

Definition at line 345 of file project_rescue.cpp.

Constructor & Destructor Documentation

RESCUE_CACHE_CANDIDATE::RESCUE_CACHE_CANDIDATE ( const wxString &  aRequestedName,
const wxString &  aNewName,
LIB_PART aCacheCandidate,
LIB_PART aLibCandidate 
)
inline

Constructor RESCUE_CACHE_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 418 of file project_rescue.cpp.

420  : m_requested_name( aRequestedName ),
421  m_new_name( aNewName ),
422  m_cache_candidate( aCacheCandidate ),
423  m_lib_candidate( aLibCandidate ) { }
RESCUE_CACHE_CANDIDATE::RESCUE_CACHE_CANDIDATE ( )
inline

Definition at line 425 of file project_rescue.cpp.

Referenced by FindRescues().

426  : m_cache_candidate( NULL ), m_lib_candidate( NULL ) {}

Member Function Documentation

static void RESCUE_CACHE_CANDIDATE::FindRescues ( RESCUER aRescuer,
boost::ptr_vector< RESCUE_CANDIDATE > &  aCandidates 
)
inlinestatic

Function FindRescues Grab all possible RESCUE_CACHE_CANDIDATEs into a vector.

Parameters
aRescuer- the working RESCUER instance.
aCandidates- the vector the will hold the candidates.

Definition at line 361 of file project_rescue.cpp.

References find_component(), PART_LIBS::FindLibPart(), RESCUER::GetComponents(), RESCUER::GetLibs(), RESCUER::GetPartNameSuffix(), LIB_PART::PinsConflictWith(), and RESCUE_CACHE_CANDIDATE().

Referenced by RESCUER::FindCandidates().

362  {
363  typedef std::map<wxString, RESCUE_CACHE_CANDIDATE> candidate_map_t;
364  candidate_map_t candidate_map;
365 
366  // Remember the list of components is sorted by part name.
367  // So a search in libraries is made only once by group
368  LIB_PART* cache_match = nullptr;
369  LIB_PART* lib_match = nullptr;
370  wxString old_part_name;
371 
372  wxString part_name_suffix = aRescuer.GetPartNameSuffix();
373 
374  for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) )
375  {
376  wxString part_name = each_component->GetLibId().GetLibItemName();
377 
378  if( old_part_name != part_name )
379  {
380  // A new part name is found (a new group starts here).
381  // Search the symbol names candidates only once for this group:
382  old_part_name = part_name;
383  cache_match = find_component( part_name, aRescuer.GetLibs(), /* aCached */ true );
384  LIB_ID id( wxEmptyString, part_name );
385  lib_match = aRescuer.GetLibs()->FindLibPart( id );
386 
387  // Test whether there is a conflict
388  if( !cache_match || !lib_match )
389  continue;
390 
391  if( !cache_match->PinsConflictWith( *lib_match, /* aTestNums */ true,
392  /* aTestNames */ true, /* aTestType */ true, /* aTestOrientation */ true,
393  /* aTestLength */ false ))
394  continue;
395 
396  RESCUE_CACHE_CANDIDATE candidate(
397  part_name, part_name + part_name_suffix,
398  cache_match, lib_match );
399 
400  candidate_map[part_name] = candidate;
401  }
402  }
403 
404  // Now, dump the map into aCandidates
405  for( const candidate_map_t::value_type& each_pair : candidate_map )
406  {
407  aCandidates.push_back( new RESCUE_CACHE_CANDIDATE( each_pair.second ) );
408  }
409  }
bool PinsConflictWith(LIB_PART &aOtherPart, bool aTestNums, bool aTestNames, bool aTestType, bool aTestOrientation, bool aTestLength)
Function PinsConflictWith returns true if this part's pins do not match another part's pins...
Class LIB_ID.
Definition: lib_id.h:56
static LIB_PART * find_component(wxString aName, PART_LIBS *aLibs, bool aCached)
Function find_component Search the libraries for the first component with a given name...
Class LIB_PART defines a library part object.
LIB_PART * FindLibPart(const LIB_ID &aLibId, const wxString &aLibraryName=wxEmptyString)
Function FindLibPart searches all libraries in the list for a part.
wxString GetPartNameSuffix()
Function GetPartNameSuffix Return the suffix to add to rescued parts.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
std::vector< SCH_COMPONENT * > * GetComponents()
Function GetComponents.
PART_LIBS * GetLibs()
Function GetLibs.
virtual wxString RESCUE_CACHE_CANDIDATE::GetActionDescription ( ) const
inlineoverridevirtual

Function GetActionDescription Get a description of the action proposed, for displaying in the UI.

Implements RESCUE_CANDIDATE.

Definition at line 432 of file project_rescue.cpp.

433  {
434  wxString action;
435  action.Printf( _( "Rescue %s as %s" ), m_requested_name, m_new_name );
436  return action;
437  }
virtual LIB_PART* RESCUE_CACHE_CANDIDATE::GetCacheCandidate ( ) const
inlineoverridevirtual

Function GetCacheCandidate Get the part that can be loaded from the project cache, if possible, or else NULL.

Reimplemented from RESCUE_CANDIDATE.

Definition at line 430 of file project_rescue.cpp.

References m_cache_candidate.

430 { return m_cache_candidate; }
virtual LIB_PART* RESCUE_CACHE_CANDIDATE::GetLibCandidate ( ) const
inlineoverridevirtual

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

Reimplemented from RESCUE_CANDIDATE.

Definition at line 431 of file project_rescue.cpp.

References m_lib_candidate.

431 { return m_lib_candidate; }
virtual wxString RESCUE_CACHE_CANDIDATE::GetNewName ( ) const
inlineoverridevirtual

Function GetNewName Get the name we're proposing changing it to.

Implements RESCUE_CANDIDATE.

Definition at line 429 of file project_rescue.cpp.

References m_new_name.

429 { return m_new_name; }
virtual wxString RESCUE_CACHE_CANDIDATE::GetRequestedName ( ) const
inlineoverridevirtual

Function GetRequestedName Get the name that was originally requested in the schematic.

Implements RESCUE_CANDIDATE.

Definition at line 428 of file project_rescue.cpp.

References m_requested_name.

428 { return m_requested_name; }
static void RESCUE_CACHE_CANDIDATE::OpenRescueLibrary ( )
inlinestatic

Function OpenRescueLibrary Creates the new rescue library.

Must be called before calling any PerformAction()s.

Definition at line 443 of file project_rescue.cpp.

References g_RootSheet, SCH_SCREEN::GetFileName(), SCH_SHEET::GetScreen(), LIBRARY_TYPE_EESCHEMA, and SchematicLibraryFileExtension.

Referenced by SCH_EDIT_FRAME::RescueProject().

444  {
445  wxFileName fn( g_RootSheet->GetScreen()->GetFileName() );
446  fn.SetName( fn.GetName() + wxT( "-rescue" ) );
447  fn.SetExt( SchematicLibraryFileExtension );
448 
449  std::unique_ptr<PART_LIB> rescue_lib( new PART_LIB( LIBRARY_TYPE_EESCHEMA,
450  fn.GetFullPath() ) );
451 
452  m_rescue_lib = std::move( rescue_lib );
453  m_rescue_lib->EnableBuffering();
454  }
const wxString & GetFileName() const
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:286
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:54
const wxString SchematicLibraryFileExtension
static std::unique_ptr< PART_LIB > m_rescue_lib
Class PART_LIB is used to load, save, search, and otherwise manipulate part library files...
virtual bool RESCUE_CACHE_CANDIDATE::PerformAction ( RESCUER aRescuer)
inlineoverridevirtual

Function PerformAction 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 456 of file project_rescue.cpp.

References RESCUER::GetComponents(), RESCUER::LogRescue(), m_rescue_lib, LIB_ID::SetLibItemName(), and LIB_PART::SetName().

457  {
458  LIB_PART new_part( *m_cache_candidate, m_rescue_lib.get() );
459  new_part.SetName( m_new_name );
460  new_part.RemoveAllAliases();
461  RESCUE_CACHE_CANDIDATE::m_rescue_lib.get()->AddPart( &new_part );
462 
463  for( SCH_COMPONENT* each_component : *aRescuer->GetComponents() )
464  {
465  if( each_component->GetLibId().GetLibItemName() != UTF8( m_requested_name ) )
466  continue;
467 
468  LIB_ID libId;
469 
470  libId.SetLibItemName( m_new_name, false );
471  each_component->SetLibId( libId );
472  each_component->ClearFlags();
473  aRescuer->LogRescue( each_component, m_requested_name, m_new_name );
474  }
475  return true;
476  }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
Class LIB_ID.
Definition: lib_id.h:56
Class LIB_PART defines a library part object.
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Function SetLibItemName.
Definition: lib_id.cpp:232
static std::unique_ptr< PART_LIB > m_rescue_lib
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
std::vector< SCH_COMPONENT * > * GetComponents()
Function GetComponents.
void LogRescue(SCH_COMPONENT *aComponent, const wxString &aOldName, const wxString &aNewName)
Function LogRescue Used by individual RESCUE_CANDIDATEs to log a rescue for undoing.
virtual void SetName(const wxString &aName)
static bool RESCUE_CACHE_CANDIDATE::WriteRescueLibrary ( SCH_EDIT_FRAME aEditFrame,
PROJECT aProject 
)
inlinestatic

Function WriteRescueLibrary Writes out the rescue library.

Called after successful PerformAction()s. If this fails, undo the actions.

Returns
True on success.

Definition at line 484 of file project_rescue.cpp.

References insert_library(), and save_library().

Referenced by SCH_EDIT_FRAME::RescueProject().

485  {
486  if( !save_library( m_rescue_lib.get(), aEditFrame ) )
487  return false;
488  return insert_library( aProject, m_rescue_lib.get(), 0 );
489  }
static std::unique_ptr< PART_LIB > m_rescue_lib
static bool insert_library(PROJECT *aProject, PART_LIB *aLibrary, size_t aIndex)
Function insert_library inserts a library into the project and refreshes libraries.
static bool save_library(PART_LIB *aLibrary, SCH_EDIT_FRAME *aEditFrame)
Function save_library writes the library out to disk.

Member Data Documentation

LIB_PART* RESCUE_CACHE_CANDIDATE::m_cache_candidate
private

Definition at line 349 of file project_rescue.cpp.

Referenced by GetCacheCandidate().

LIB_PART* RESCUE_CACHE_CANDIDATE::m_lib_candidate
private

Definition at line 350 of file project_rescue.cpp.

Referenced by GetLibCandidate().

wxString RESCUE_CACHE_CANDIDATE::m_new_name
private

Definition at line 348 of file project_rescue.cpp.

Referenced by GetNewName().

wxString RESCUE_CACHE_CANDIDATE::m_requested_name
private

Definition at line 347 of file project_rescue.cpp.

Referenced by GetRequestedName().

std::unique_ptr< PART_LIB > RESCUE_CACHE_CANDIDATE::m_rescue_lib
staticprivate

Definition at line 352 of file project_rescue.cpp.

Referenced by PerformAction().


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