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...
 
wxString GetPartNameSuffix ()
 Return the suffix to add to rescued parts. 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 431 of file project_rescue.cpp.

References get_components(), m_components, m_edit_frame, and m_prj.

432 {
434  m_prj = &aProject;
435  m_edit_frame = &aEditFrame;
436 }
static void get_components(std::vector< SCH_COMPONENT * > &aComponents)
Fill a vector with all of the project'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 450 of file project_rescue.cpp.

References m_chosen_candidates.

Referenced by SCH_EDIT_FRAME::rescueProject().

451 {
452  for( RESCUE_CANDIDATE* each_candidate : m_chosen_candidates )
453  {
454  if( ! each_candidate->PerformAction( this ) )
455  return false;
456  }
457 
458  return true;
459 }
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.

References m_edit_frame.

Referenced by RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues().

256 { return m_edit_frame; }
SCH_EDIT_FRAME * m_edit_frame
wxString RESCUER::GetPartNameSuffix ( )

Return the suffix to add to rescued parts.

Definition at line 475 of file project_rescue.cpp.

References GetPrj(), and PROJECT::GetProjectName().

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

476 {
477  wxString suffix = wxT( "-RESCUE-" );
478  wxString pname = GetPrj()->GetProjectName();
479 
480  for( size_t i = 0; i < pname.Len(); ++i )
481  {
482  if( isspace( pname[i].GetValue() ) )
483  suffix.Append( '_' );
484  else
485  suffix.Append( pname[i] );
486  }
487 
488  return suffix;
489 }
PROJECT * GetPrj()
Return the #SCH_PROJECT object for access to the symbol libraries.
VTBL_ENTRY const wxString GetProjectName() const
Function GetProjectName returns the short name of the project.
Definition: project.cpp:108
PROJECT* RESCUER::GetPrj ( )
inline

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

Definition at line 281 of file project_rescue.h.

References m_prj.

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

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

References RESCUE_LOG::component, m_rescue_log, 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().

441 {
442  RESCUE_LOG logitem;
443  logitem.component = aComponent;
444  logitem.old_name = aOldName;
445  logitem.new_name = aNewName;
446  m_rescue_log.push_back( logitem );
447 }
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 566 of file project_rescue.cpp.

References m_all_candidates.

Referenced by SCH_EDIT_FRAME::rescueProject().

567 {
568  std::vector<wxString> names_seen;
569 
570  for( boost::ptr_vector<RESCUE_CANDIDATE>::iterator it = m_all_candidates.begin();
571  it != m_all_candidates.end(); )
572  {
573  bool seen_already = false;
574 
575  for( wxString& name_seen : names_seen )
576  {
577  if( name_seen == it->GetRequestedName() )
578  {
579  seen_already = true;
580  break;
581  }
582  }
583 
584  if( seen_already )
585  {
586  it = m_all_candidates.erase( it );
587  }
588  else
589  {
590  names_seen.push_back( it->GetRequestedName() );
591  ++it;
592  }
593  }
594 }
boost::ptr_vector< RESCUE_CANDIDATE > m_all_candidates
void RESCUER::UndoRescues ( )

Reverse the effects of all rescues on the project.

Definition at line 462 of file project_rescue.cpp.

References m_rescue_log, and LIB_ID::SetLibItemName().

Referenced by SCH_EDIT_FRAME::rescueProject().

463 {
464  for( RESCUE_LOG& each_logitem : m_rescue_log )
465  {
466  LIB_ID libId;
467 
468  libId.SetLibItemName( each_logitem.old_name, false );
469  each_logitem.component->SetLibId( libId );
470  each_logitem.component->ClearFlags();
471  }
472 }
Class LIB_ID.
Definition: lib_id.h:56
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Function SetLibItemName.
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.

Referenced by GetComponents(), and RESCUER().

SCH_EDIT_FRAME* RESCUER::m_edit_frame
protected
std::vector<RESCUE_LOG> RESCUER::m_rescue_log
protected

Definition at line 227 of file project_rescue.h.

Referenced by LogRescue(), and UndoRescues().


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