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 (PROJECT &aProject, SCH_SHEET_PATH *aCurrentSheet, EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType)
 
virtual bool WriteRescueLibrary (wxWindow *aParent)=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 (wxWindow *aParent, bool aAskShowAgain)=0
 Display a dialog to allow the user to select rescues. More...
 
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...
 

Static Public Member Functions

static bool RescueProject (wxWindow *aParent, RESCUER &aRescuer, bool aRunningOnDemand)
 

Protected Attributes

std::vector< SCH_COMPONENT * > m_components
 
PROJECTm_prj
 
EDA_DRAW_PANEL_GAL::GAL_TYPE m_galBackEndType
 
SCH_SHEET_PATHm_currentSheet
 
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 217 of file project_rescue.h.

Constructor & Destructor Documentation

◆ RESCUER()

RESCUER::RESCUER ( PROJECT aProject,
SCH_SHEET_PATH aCurrentSheet,
EDA_DRAW_PANEL_GAL::GAL_TYPE  aGalBackeEndType 
)

Definition at line 486 of file project_rescue.cpp.

488 {
490  m_prj = &aProject;
491  m_currentSheet = aCurrentSheet;
492  m_galBackEndType = aGalBackEndType;
493 }
EDA_DRAW_PANEL_GAL::GAL_TYPE m_galBackEndType
static void get_components(std::vector< SCH_COMPONENT * > &aComponents)
Fill a vector with all of the project's symbols, to ease iterating over them.
SCH_SHEET_PATH * m_currentSheet
PROJECT * m_prj
std::vector< SCH_COMPONENT * > m_components

References get_components(), m_components, m_currentSheet, m_galBackEndType, and m_prj.

Member Function Documentation

◆ AddPart()

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

◆ DoRescues()

bool RESCUER::DoRescues ( )

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

Returns
True on success

Definition at line 507 of file project_rescue.cpp.

508 {
509  for( RESCUE_CANDIDATE* each_candidate : m_chosen_candidates )
510  {
511  if( ! each_candidate->PerformAction( this ) )
512  return false;
513  }
514 
515  return true;
516 }
std::vector< RESCUE_CANDIDATE * > m_chosen_candidates

References m_chosen_candidates.

Referenced by RescueProject().

◆ FindCandidates()

virtual void RESCUER::FindCandidates ( )
pure virtual

Populate the RESCUER with all possible candidates.

Implemented in SYMBOL_LIB_TABLE_RESCUER, and LEGACY_RESCUER.

Referenced by RescueProject().

◆ GetCandidateCount()

size_t RESCUER::GetCandidateCount ( )
inline

Returen the number of rescue candidates found.

Definition at line 268 of file project_rescue.h.

268 { return m_all_candidates.size(); }
boost::ptr_vector< RESCUE_CANDIDATE > m_all_candidates

References m_all_candidates.

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

◆ GetChosenCandidateCount()

size_t RESCUER::GetChosenCandidateCount ( )
inline

Get the number of resuce candidates chosen by the user.

Definition at line 273 of file project_rescue.h.

273 { return m_chosen_candidates.size(); }
std::vector< RESCUE_CANDIDATE * > m_chosen_candidates

References m_chosen_candidates.

Referenced by RescueProject().

◆ GetComponents()

◆ GetPrj()

PROJECT* RESCUER::GetPrj ( )
inline

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

Definition at line 283 of file project_rescue.h.

283 { return m_prj; }
PROJECT * m_prj

References m_prj.

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

◆ InvokeDialog()

virtual void RESCUER::InvokeDialog ( wxWindow *  aParent,
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 RescueProject().

◆ LogRescue()

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

498 {
499  RESCUE_LOG logitem;
500  logitem.component = aComponent;
501  logitem.old_name = aOldName;
502  logitem.new_name = aNewName;
503  m_rescue_log.push_back( logitem );
504 }
SCH_COMPONENT * component
std::vector< RESCUE_LOG > m_rescue_log
wxString old_name
wxString new_name

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().

◆ OpenRescueLibrary()

virtual void RESCUER::OpenRescueLibrary ( )
pure virtual

Implemented in SYMBOL_LIB_TABLE_RESCUER, and LEGACY_RESCUER.

Referenced by RescueProject().

◆ RemoveDuplicates()

void RESCUER::RemoveDuplicates ( )

Filter out duplicately named rescue candidates.

Definition at line 625 of file project_rescue.cpp.

626 {
627  std::vector<wxString> names_seen;
628 
629  for( boost::ptr_vector<RESCUE_CANDIDATE>::iterator it = m_all_candidates.begin();
630  it != m_all_candidates.end(); )
631  {
632  bool seen_already = false;
633 
634  for( wxString& name_seen : names_seen )
635  {
636  if( name_seen == it->GetRequestedName() )
637  {
638  seen_already = true;
639  break;
640  }
641  }
642 
643  if( seen_already )
644  {
645  it = m_all_candidates.erase( it );
646  }
647  else
648  {
649  names_seen.push_back( it->GetRequestedName() );
650  ++it;
651  }
652  }
653 }
boost::ptr_vector< RESCUE_CANDIDATE > m_all_candidates

References m_all_candidates.

Referenced by RescueProject().

◆ RescueProject()

bool RESCUER::RescueProject ( wxWindow *  aParent,
RESCUER aRescuer,
bool  aRunningOnDemand 
)
static

Definition at line 579 of file project_rescue.cpp.

580 {
581  aRescuer.FindCandidates();
582 
583  if( !aRescuer.GetCandidateCount() )
584  {
585  if( aRunningOnDemand )
586  {
587  wxMessageDialog dlg( aParent, _( "This project has nothing to rescue." ),
588  _( "Project Rescue Helper" ) );
589  dlg.ShowModal();
590  }
591 
592  return true;
593  }
594 
595  aRescuer.RemoveDuplicates();
596  aRescuer.InvokeDialog( aParent, !aRunningOnDemand );
597 
598  // If no symbols were rescued, let the user know what's going on. He might
599  // have clicked cancel by mistake, and should have some indication of that.
600  if( !aRescuer.GetChosenCandidateCount() )
601  {
602  wxMessageDialog dlg( aParent, _( "No symbols were rescued." ),
603  _( "Project Rescue Helper" ) );
604  dlg.ShowModal();
605 
606  // Set the modified flag even on Cancel. Many users seem to instinctively want to Save at
607  // this point, due to the reloading of the symbols, so we'll make the save button active.
608  return true;
609  }
610 
611  aRescuer.OpenRescueLibrary();
612 
613  if( !aRescuer.DoRescues() )
614  {
615  aRescuer.UndoRescues();
616  return false;
617  }
618 
619  aRescuer.WriteRescueLibrary( aParent );
620 
621  return true;
622 }
virtual bool WriteRescueLibrary(wxWindow *aParent)=0
Writes out the rescue library.
virtual void FindCandidates()=0
Populate the RESCUER with all possible candidates.
size_t GetChosenCandidateCount()
Get the number of resuce candidates chosen by the user.
virtual void InvokeDialog(wxWindow *aParent, bool aAskShowAgain)=0
Display a dialog to allow the user to select rescues.
void RemoveDuplicates()
Filter out duplicately named rescue candidates.
size_t GetCandidateCount()
Returen the number of rescue candidates found.
#define _(s)
virtual void OpenRescueLibrary()=0
bool DoRescues()
Perform all chosen rescue actions, logging them to be undone if necessary.
void UndoRescues()
Reverse the effects of all rescues on the project.

References _, DoRescues(), FindCandidates(), GetCandidateCount(), GetChosenCandidateCount(), InvokeDialog(), OpenRescueLibrary(), RemoveDuplicates(), UndoRescues(), and WriteRescueLibrary().

Referenced by DIALOG_SYMBOL_REMAP::OnRemapSymbols(), and SCH_EDIT_FRAME::rescueProject().

◆ UndoRescues()

void RESCUER::UndoRescues ( )

Reverse the effects of all rescues on the project.

Definition at line 519 of file project_rescue.cpp.

520 {
521  for( RESCUE_LOG& each_logitem : m_rescue_log )
522  {
523  LIB_ID libId;
524 
525  libId.SetLibItemName( each_logitem.old_name, false );
526  each_logitem.component->SetLibId( libId );
527  each_logitem.component->ClearFlags();
528  }
529 }
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:206
std::vector< RESCUE_LOG > m_rescue_log

References m_rescue_log, and LIB_ID::SetLibItemName().

Referenced by RescueProject().

◆ WriteRescueLibrary()

virtual bool RESCUER::WriteRescueLibrary ( wxWindow *  aParent)
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 RescueProject().

Friends And Related Function Documentation

◆ DIALOG_RESCUE_EACH

friend class DIALOG_RESCUE_EACH
friend

Definition at line 220 of file project_rescue.h.

Member Data Documentation

◆ m_all_candidates

◆ m_chosen_candidates

◆ m_components

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

Definition at line 222 of file project_rescue.h.

Referenced by GetComponents(), and RESCUER().

◆ m_currentSheet

SCH_SHEET_PATH* RESCUER::m_currentSheet
protected

◆ m_galBackEndType

EDA_DRAW_PANEL_GAL::GAL_TYPE RESCUER::m_galBackEndType
protected

◆ m_prj

◆ m_rescue_log

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

Definition at line 230 of file project_rescue.h.

Referenced by LogRescue(), and UndoRescues().


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