KiCad PCB EDA Suite
RESCUER Class Referenceabstract

#include <project_rescue.h>

Inheritance diagram for RESCUER:
LEGACY_RESCUER SYMBOL_LIB_TABLE_RESCUER

Public Member Functions

 RESCUER (SCH_EDIT_FRAME &aEditFrame, PROJECT &aProject)
 
virtual bool WriteRescueLibrary (SCH_EDIT_FRAME *aEditFrame)=0
 Writes out the rescue library. More...
 
virtual void OpenRescueLibrary ()=0
 
virtual void FindCandidates ()=0
 Populate the RESCUER with all possible candidates. More...
 
virtual void AddPart (LIB_PART *aNewPart)=0
 
virtual void InvokeDialog (bool aAskShowAgain)=0
 Display a dialog to allow the user to select rescues. More...
 
SCH_EDIT_FRAMEGetFrame ()
 
void RemoveDuplicates ()
 Filter out duplicately named rescue candidates. More...
 
size_t GetCandidateCount ()
 Returen the number of rescue candidates found. More...
 
size_t GetChosenCandidateCount ()
 Get the number of resuce candidates chosen by the user. More...
 
std::vector< SCH_COMPONENT * > * GetComponents ()
 Get the list of symbols that need rescued. More...
 
PROJECTGetPrj ()
 Return the #SCH_PROJECT object for access to the symbol libraries. More...
 
void LogRescue (SCH_COMPONENT *aComponent, const wxString &aOldName, const wxString &aNewName)
 Used by individual RESCUE_CANDIDATE objects to log a rescue for undoing. More...
 
bool DoRescues ()
 Perform all chosen rescue actions, logging them to be undone if necessary. More...
 
void UndoRescues ()
 Reverse the effects of all rescues on the project. More...
 

Protected Attributes

std::vector< SCH_COMPONENT * > m_components
 
PROJECTm_prj
 
SCH_EDIT_FRAMEm_edit_frame
 
boost::ptr_vector< RESCUE_CANDIDATEm_all_candidates
 
std::vector< RESCUE_CANDIDATE * > m_chosen_candidates
 
std::vector< RESCUE_LOGm_rescue_log
 

Friends

class DIALOG_RESCUE_EACH
 

Detailed Description

Definition at line 215 of file project_rescue.h.

Constructor & Destructor Documentation

RESCUER::RESCUER ( SCH_EDIT_FRAME aEditFrame,
PROJECT aProject 
)

Definition at line 459 of file project_rescue.cpp.

References get_components().

460 {
462  m_prj = &aProject;
463  m_edit_frame = &aEditFrame;
464 }
static void get_components(std::vector< SCH_COMPONENT * > &aComponents)
Fill a vector with all of the project&#39;s symbols, to ease iterating over them.
PROJECT * m_prj
std::vector< SCH_COMPONENT * > m_components
SCH_EDIT_FRAME * m_edit_frame

Member Function Documentation

virtual void RESCUER::AddPart ( LIB_PART aNewPart)
pure virtual
bool RESCUER::DoRescues ( )

Perform all chosen rescue actions, logging them to be undone if necessary.

Returns
True on success

Definition at line 478 of file project_rescue.cpp.

Referenced by SCH_EDIT_FRAME::rescueProject().

479 {
480  for( RESCUE_CANDIDATE* each_candidate : m_chosen_candidates )
481  {
482  if( ! each_candidate->PerformAction( this ) )
483  return false;
484  }
485 
486  return true;
487 }
std::vector< RESCUE_CANDIDATE * > m_chosen_candidates
virtual void RESCUER::FindCandidates ( )
pure virtual

Populate the RESCUER with all possible candidates.

Implemented in SYMBOL_LIB_TABLE_RESCUER, and LEGACY_RESCUER.

Referenced by SCH_EDIT_FRAME::rescueProject().

size_t RESCUER::GetCandidateCount ( )
inline

Returen the number of rescue candidates found.

Definition at line 266 of file project_rescue.h.

Referenced by SCH_EDIT_FRAME::rescueProject(), and DIALOG_RESCUE_EACH::TransferDataFromWindow().

266 { return m_all_candidates.size(); }
boost::ptr_vector< RESCUE_CANDIDATE > m_all_candidates
size_t RESCUER::GetChosenCandidateCount ( )
inline

Get the number of resuce candidates chosen by the user.

Definition at line 271 of file project_rescue.h.

Referenced by SCH_EDIT_FRAME::rescueProject().

271 { return m_chosen_candidates.size(); }
std::vector< RESCUE_CANDIDATE * > m_chosen_candidates
SCH_EDIT_FRAME* RESCUER::GetFrame ( )
inline

Definition at line 256 of file project_rescue.h.

Referenced by RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues().

256 { return m_edit_frame; }
SCH_EDIT_FRAME * m_edit_frame
PROJECT* RESCUER::GetPrj ( )
inline

Return the #SCH_PROJECT object for access to the symbol libraries.

Definition at line 281 of file project_rescue.h.

Referenced by RESCUE_CASE_CANDIDATE::FindRescues(), RESCUE_CACHE_CANDIDATE::FindRescues(), and RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues().

281 { return m_prj; }
PROJECT * m_prj
virtual void RESCUER::InvokeDialog ( bool  aAskShowAgain)
pure virtual

Display a dialog to allow the user to select rescues.

Parameters
aAskShowAgain- whether the "Never Show Again" button should be visible

Implemented in SYMBOL_LIB_TABLE_RESCUER, and LEGACY_RESCUER.

Referenced by SCH_EDIT_FRAME::rescueProject().

void RESCUER::LogRescue ( SCH_COMPONENT aComponent,
const wxString &  aOldName,
const wxString &  aNewName 
)

Used by individual RESCUE_CANDIDATE objects to log a rescue for undoing.

Definition at line 467 of file project_rescue.cpp.

References RESCUE_LOG::component, RESCUE_LOG::new_name, and RESCUE_LOG::old_name.

Referenced by RESCUE_CASE_CANDIDATE::PerformAction(), RESCUE_CACHE_CANDIDATE::PerformAction(), and RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::PerformAction().

469 {
470  RESCUE_LOG logitem;
471  logitem.component = aComponent;
472  logitem.old_name = aOldName;
473  logitem.new_name = aNewName;
474  m_rescue_log.push_back( logitem );
475 }
SCH_COMPONENT * component
std::vector< RESCUE_LOG > m_rescue_log
wxString old_name
wxString new_name
virtual void RESCUER::OpenRescueLibrary ( )
pure virtual
void RESCUER::RemoveDuplicates ( )

Filter out duplicately named rescue candidates.

Definition at line 576 of file project_rescue.cpp.

Referenced by SCH_EDIT_FRAME::rescueProject().

577 {
578  std::vector<wxString> names_seen;
579 
580  for( boost::ptr_vector<RESCUE_CANDIDATE>::iterator it = m_all_candidates.begin();
581  it != m_all_candidates.end(); )
582  {
583  bool seen_already = false;
584 
585  for( wxString& name_seen : names_seen )
586  {
587  if( name_seen == it->GetRequestedName() )
588  {
589  seen_already = true;
590  break;
591  }
592  }
593 
594  if( seen_already )
595  {
596  it = m_all_candidates.erase( it );
597  }
598  else
599  {
600  names_seen.push_back( it->GetRequestedName() );
601  ++it;
602  }
603  }
604 }
boost::ptr_vector< RESCUE_CANDIDATE > m_all_candidates
void RESCUER::UndoRescues ( )

Reverse the effects of all rescues on the project.

Definition at line 490 of file project_rescue.cpp.

References LIB_ID::SetLibItemName().

Referenced by SCH_EDIT_FRAME::rescueProject().

491 {
492  for( RESCUE_LOG& each_logitem : m_rescue_log )
493  {
494  LIB_ID libId;
495 
496  libId.SetLibItemName( each_logitem.old_name, false );
497  each_logitem.component->SetLibId( libId );
498  each_logitem.component->ClearFlags();
499  }
500 }
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:232
std::vector< RESCUE_LOG > m_rescue_log
virtual bool RESCUER::WriteRescueLibrary ( SCH_EDIT_FRAME aEditFrame)
pure virtual

Writes out the rescue library.

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

Returns
True on success.

Implemented in SYMBOL_LIB_TABLE_RESCUER, and LEGACY_RESCUER.

Referenced by SCH_EDIT_FRAME::rescueProject().

Friends And Related Function Documentation

friend class DIALOG_RESCUE_EACH
friend

Definition at line 218 of file project_rescue.h.

Member Data Documentation

std::vector<RESCUE_CANDIDATE*> RESCUER::m_chosen_candidates
protected
std::vector<SCH_COMPONENT*> RESCUER::m_components
protected

Definition at line 220 of file project_rescue.h.

SCH_EDIT_FRAME* RESCUER::m_edit_frame
protected

Definition at line 222 of file project_rescue.h.

Referenced by SYMBOL_LIB_TABLE_RESCUER::InvokeDialog().

PROJECT* RESCUER::m_prj
protected
std::vector<RESCUE_LOG> RESCUER::m_rescue_log
protected

Definition at line 227 of file project_rescue.h.


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