KiCad PCB EDA Suite
RESCUER Class Reference

#include <project_rescue.h>

Public Member Functions

 RESCUER (SCH_EDIT_FRAME &aEditFrame, PROJECT &aProject)
 
void FindCandidates ()
 Function FindCandidates Populate the RESCUER with all possible candidates. More...
 
void RemoveDuplicates ()
 Function RemoveDuplicates Filter out duplicately named rescue candidates. More...
 
size_t GetCandidateCount ()
 Function GetCandidateCount. More...
 
size_t GetChosenCandidateCount ()
 Function GetChosenCandidateCount. More...
 
std::vector< SCH_COMPONENT * > * GetComponents ()
 Function GetComponents. More...
 
PART_LIBSGetLibs ()
 Function GetLibs. More...
 
PROJECTGetPrj ()
 Function GetPrj. More...
 
wxString GetPartNameSuffix ()
 Function GetPartNameSuffix Return the suffix to add to rescued parts. More...
 
void InvokeDialog (bool aAskShowAgain)
 Function InvokeDialog Display a dialog to allow the user to select rescues. More...
 
void LogRescue (SCH_COMPONENT *aComponent, const wxString &aOldName, const wxString &aNewName)
 Function LogRescue Used by individual RESCUE_CANDIDATEs to log a rescue for undoing. More...
 
bool DoRescues ()
 Function DoRescues Perform all chosen rescue actions, logging them to be undone if necessary. More...
 
void UndoRescues ()
 Function UndoRescues Reverse the effects of all rescues on the project. More...
 

Private Attributes

std::vector< SCH_COMPONENT * > m_components
 
PART_LIBSm_libs
 
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 110 of file project_rescue.h.

Constructor & Destructor Documentation

RESCUER::RESCUER ( SCH_EDIT_FRAME aEditFrame,
PROJECT aProject 
)

Definition at line 496 of file project_rescue.cpp.

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

497 {
499  m_prj = &aProject;
500  m_libs = m_prj->SchLibs();
501  m_edit_frame = &aEditFrame;
502 }
static void get_components(std::vector< SCH_COMPONENT * > &aComponents)
Function get_components Fills a vector with all of the project's components, to ease iterating over t...
PART_LIBS * m_libs
PROJECT * m_prj
std::vector< SCH_COMPONENT * > m_components
SCH_EDIT_FRAME * m_edit_frame

Member Function Documentation

bool RESCUER::DoRescues ( )

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

Returns
True on success

Definition at line 529 of file project_rescue.cpp.

References m_chosen_candidates.

Referenced by SCH_EDIT_FRAME::RescueProject().

530 {
531  for( RESCUE_CANDIDATE* each_candidate : m_chosen_candidates )
532  {
533  if( ! each_candidate->PerformAction( this ) )
534  return false;
535  }
536  return true;
537 }
std::vector< RESCUE_CANDIDATE * > m_chosen_candidates
void RESCUER::FindCandidates ( )

Function FindCandidates Populate the RESCUER with all possible candidates.

Definition at line 505 of file project_rescue.cpp.

References RESCUE_CASE_CANDIDATE::FindRescues(), RESCUE_CACHE_CANDIDATE::FindRescues(), and m_all_candidates.

Referenced by SCH_EDIT_FRAME::RescueProject().

506 {
509 }
static void FindRescues(RESCUER &aRescuer, boost::ptr_vector< RESCUE_CANDIDATE > &aCandidates)
Function FindRescues Grab all possible RESCUE_CASE_CANDIDATES into a vector.
static void FindRescues(RESCUER &aRescuer, boost::ptr_vector< RESCUE_CANDIDATE > &aCandidates)
Function FindRescues Grab all possible RESCUE_CACHE_CANDIDATEs into a vector.
boost::ptr_vector< RESCUE_CANDIDATE > m_all_candidates
size_t RESCUER::GetCandidateCount ( )
inline

Function GetCandidateCount.

Definition at line 142 of file project_rescue.h.

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

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

Function GetChosenCandidateCount.

Definition at line 147 of file project_rescue.h.

Referenced by SCH_EDIT_FRAME::RescueProject().

147 { return m_chosen_candidates.size(); }
std::vector< RESCUE_CANDIDATE * > m_chosen_candidates
std::vector<SCH_COMPONENT*>* RESCUER::GetComponents ( )
inline
PART_LIBS* RESCUER::GetLibs ( )
inline

Function GetLibs.

Definition at line 157 of file project_rescue.h.

References m_libs.

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

157 { return m_libs; }
PART_LIBS * m_libs
wxString RESCUER::GetPartNameSuffix ( )

Function GetPartNameSuffix Return the suffix to add to rescued parts.

Definition at line 553 of file project_rescue.cpp.

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

Referenced by RESCUE_CACHE_CANDIDATE::FindRescues().

554 {
555  wxString suffix = wxT( "-RESCUE-" );
556  wxString pname = GetPrj()->GetProjectName();
557  for( size_t i = 0; i < pname.Len(); ++i )
558  {
559  if( isspace( pname[i].GetValue() ) )
560  suffix.Append( '_' );
561  else
562  suffix.Append( pname[i] );
563  }
564 
565  return suffix;
566 }
PROJECT * GetPrj()
Function GetPrj.
VTBL_ENTRY const wxString GetProjectName() const
Function GetProjectName returns the short name of the project.
Definition: project.cpp:108
PROJECT* RESCUER::GetPrj ( )
inline

Function GetPrj.

Definition at line 162 of file project_rescue.h.

References m_prj.

Referenced by GetPartNameSuffix().

162 { return m_prj; }
PROJECT * m_prj
void RESCUER::InvokeDialog ( bool  aAskShowAgain)

Function InvokeDialog Display a dialog to allow the user to select rescues.

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

Definition at line 512 of file project_rescue.cpp.

References InvokeDialogRescueEach(), and m_edit_frame.

Referenced by SCH_EDIT_FRAME::RescueProject().

513 {
514  InvokeDialogRescueEach( m_edit_frame, *this, aAskShowAgain );
515 }
int InvokeDialogRescueEach(SCH_EDIT_FRAME *aCaller, RESCUER &aRescuer, bool aAskShowAgain)
Function InvokeDialogRescueEach This dialog asks the user which rescuable, cached parts he wants to r...
SCH_EDIT_FRAME * m_edit_frame
void RESCUER::LogRescue ( SCH_COMPONENT aComponent,
const wxString &  aOldName,
const wxString &  aNewName 
)

Function LogRescue Used by individual RESCUE_CANDIDATEs to log a rescue for undoing.

Definition at line 518 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(), and RESCUE_CACHE_CANDIDATE::PerformAction().

520 {
521  RESCUE_LOG logitem;
522  logitem.component = aComponent;
523  logitem.old_name = aOldName;
524  logitem.new_name = aNewName;
525  m_rescue_log.push_back( logitem );
526 }
SCH_COMPONENT * component
std::vector< RESCUE_LOG > m_rescue_log
wxString old_name
wxString new_name
void RESCUER::RemoveDuplicates ( )

Function RemoveDuplicates Filter out duplicately named rescue candidates.

Definition at line 210 of file project_rescue.cpp.

References m_all_candidates.

Referenced by SCH_EDIT_FRAME::RescueProject().

211 {
212  std::vector<wxString> names_seen;
213 
214  for( boost::ptr_vector<RESCUE_CANDIDATE>::iterator it = m_all_candidates.begin();
215  it != m_all_candidates.end(); )
216  {
217  bool seen_already = false;
218  for( wxString& name_seen : names_seen )
219  {
220  if( name_seen == it->GetRequestedName() )
221  {
222  seen_already = true;
223  break;
224  }
225  }
226 
227  if( seen_already )
228  {
229  it = m_all_candidates.erase( it );
230  }
231  else
232  {
233  names_seen.push_back( it->GetRequestedName() );
234  ++it;
235  }
236  }
237 }
boost::ptr_vector< RESCUE_CANDIDATE > m_all_candidates
void RESCUER::UndoRescues ( )

Function UndoRescues Reverse the effects of all rescues on the project.

Definition at line 540 of file project_rescue.cpp.

References m_rescue_log, and LIB_ID::SetLibItemName().

Referenced by SCH_EDIT_FRAME::RescueProject().

541 {
542  for( RESCUE_LOG& each_logitem : m_rescue_log )
543  {
544  LIB_ID libId;
545 
546  libId.SetLibItemName( each_logitem.old_name, false );
547  each_logitem.component->SetLibId( libId );
548  each_logitem.component->ClearFlags();
549  }
550 }
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

Friends And Related Function Documentation

friend class DIALOG_RESCUE_EACH
friend

Definition at line 112 of file project_rescue.h.

Member Data Documentation

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

Definition at line 114 of file project_rescue.h.

Referenced by GetComponents(), and RESCUER().

SCH_EDIT_FRAME* RESCUER::m_edit_frame
private

Definition at line 117 of file project_rescue.h.

Referenced by InvokeDialog(), and RESCUER().

PART_LIBS* RESCUER::m_libs
private

Definition at line 115 of file project_rescue.h.

Referenced by GetLibs(), and RESCUER().

PROJECT* RESCUER::m_prj
private

Definition at line 116 of file project_rescue.h.

Referenced by GetPrj(), and RESCUER().

std::vector<RESCUE_LOG> RESCUER::m_rescue_log
private

Definition at line 122 of file project_rescue.h.

Referenced by LogRescue(), and UndoRescues().


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