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

Constructor & Destructor Documentation

RESCUER::RESCUER ( SCH_EDIT_FRAME aEditFrame,
PROJECT aProject 
)

Definition at line 495 of file project_rescue.cpp.

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

496 {
498  m_prj = &aProject;
499  m_libs = m_prj->SchLibs();
500  m_edit_frame = &aEditFrame;
501 }
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 528 of file project_rescue.cpp.

References m_chosen_candidates.

Referenced by SCH_EDIT_FRAME::RescueProject().

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

Function FindCandidates Populate the RESCUER with all possible candidates.

Definition at line 504 of file project_rescue.cpp.

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

Referenced by SCH_EDIT_FRAME::RescueProject().

505 {
508 }
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 141 of file project_rescue.h.

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

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

Function GetChosenCandidateCount.

Definition at line 146 of file project_rescue.h.

Referenced by SCH_EDIT_FRAME::RescueProject().

146 { 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 156 of file project_rescue.h.

References m_libs.

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

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

Function GetPartNameSuffix Return the suffix to add to rescued parts.

Definition at line 552 of file project_rescue.cpp.

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

Referenced by RESCUE_CACHE_CANDIDATE::FindRescues().

553 {
554  wxString suffix = wxT( "-RESCUE-" );
555  wxString pname = GetPrj()->GetProjectName();
556  for( size_t i = 0; i < pname.Len(); ++i )
557  {
558  if( isspace( pname[i].GetValue() ) )
559  suffix.Append( '_' );
560  else
561  suffix.Append( pname[i] );
562  }
563 
564  return suffix;
565 }
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 161 of file project_rescue.h.

References m_prj.

Referenced by GetPartNameSuffix().

161 { 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 511 of file project_rescue.cpp.

References InvokeDialogRescueEach(), and m_edit_frame.

Referenced by SCH_EDIT_FRAME::RescueProject().

512 {
513  InvokeDialogRescueEach( m_edit_frame, *this, aAskShowAgain );
514 }
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 517 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().

519 {
520  RESCUE_LOG logitem;
521  logitem.component = aComponent;
522  logitem.old_name = aOldName;
523  logitem.new_name = aNewName;
524  m_rescue_log.push_back( logitem );
525 }
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 209 of file project_rescue.cpp.

References m_all_candidates.

Referenced by SCH_EDIT_FRAME::RescueProject().

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

References m_rescue_log, LIB_ID::SetLibItemName(), and TO_UTF8.

Referenced by SCH_EDIT_FRAME::RescueProject().

540 {
541  for( RESCUE_LOG& each_logitem : m_rescue_log )
542  {
543  LIB_ID libId;
544 
545  libId.SetLibItemName( TO_UTF8( each_logitem.old_name ), false );
546  each_logitem.component->SetLibId( libId );
547  each_logitem.component->ClearFlags();
548  }
549 }
Class LIB_ID.
Definition: lib_id.h:56
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
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 111 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 113 of file project_rescue.h.

Referenced by GetComponents(), and RESCUER().

SCH_EDIT_FRAME* RESCUER::m_edit_frame
private

Definition at line 116 of file project_rescue.h.

Referenced by InvokeDialog(), and RESCUER().

PART_LIBS* RESCUER::m_libs
private

Definition at line 114 of file project_rescue.h.

Referenced by GetLibs(), and RESCUER().

PROJECT* RESCUER::m_prj
private

Definition at line 115 of file project_rescue.h.

Referenced by GetPrj(), and RESCUER().

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

Definition at line 121 of file project_rescue.h.

Referenced by LogRescue(), and UndoRescues().


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