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

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

464 {
466  m_prj = &aProject;
467  m_edit_frame = &aEditFrame;
468 }
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 482 of file project_rescue.cpp.

References m_chosen_candidates.

Referenced by SCH_EDIT_FRAME::rescueProject().

483 {
484  for( RESCUE_CANDIDATE* each_candidate : m_chosen_candidates )
485  {
486  if( ! each_candidate->PerformAction( this ) )
487  return false;
488  }
489 
490  return true;
491 }
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 507 of file project_rescue.cpp.

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

Referenced by RESCUE_CACHE_CANDIDATE::FindRescues().

508 {
509  wxString suffix = wxT( "-RESCUE-" );
510  wxString pname = GetPrj()->GetProjectName();
511 
512  for( size_t i = 0; i < pname.Len(); ++i )
513  {
514  if( isspace( pname[i].GetValue() ) )
515  suffix.Append( '_' );
516  else
517  suffix.Append( pname[i] );
518  }
519 
520  return suffix;
521 }
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:106
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 471 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().

473 {
474  RESCUE_LOG logitem;
475  logitem.component = aComponent;
476  logitem.old_name = aOldName;
477  logitem.new_name = aNewName;
478  m_rescue_log.push_back( logitem );
479 }
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 597 of file project_rescue.cpp.

References m_all_candidates.

Referenced by SCH_EDIT_FRAME::rescueProject().

598 {
599  std::vector<wxString> names_seen;
600 
601  for( boost::ptr_vector<RESCUE_CANDIDATE>::iterator it = m_all_candidates.begin();
602  it != m_all_candidates.end(); )
603  {
604  bool seen_already = false;
605 
606  for( wxString& name_seen : names_seen )
607  {
608  if( name_seen == it->GetRequestedName() )
609  {
610  seen_already = true;
611  break;
612  }
613  }
614 
615  if( seen_already )
616  {
617  it = m_all_candidates.erase( it );
618  }
619  else
620  {
621  names_seen.push_back( it->GetRequestedName() );
622  ++it;
623  }
624  }
625 }
boost::ptr_vector< RESCUE_CANDIDATE > m_all_candidates
void RESCUER::UndoRescues ( )

Reverse the effects of all rescues on the project.

Definition at line 494 of file project_rescue.cpp.

References m_rescue_log, and LIB_ID::SetLibItemName().

Referenced by SCH_EDIT_FRAME::rescueProject().

495 {
496  for( RESCUE_LOG& each_logitem : m_rescue_log )
497  {
498  LIB_ID libId;
499 
500  libId.SetLibItemName( each_logitem.old_name, false );
501  each_logitem.component->SetLibId( libId );
502  each_logitem.component->ClearFlags();
503  }
504 }
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.

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: