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, SCHEMATIC *aSchematic, SCH_SHEET_PATH *aCurrentSheet, EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType)
 
virtual ~RESCUER ()
 
virtual bool WriteRescueLibrary (wxWindow *aParent)=0
 Write the rescue library. More...
 
virtual void OpenRescueLibrary ()=0
 
virtual void FindCandidates ()=0
 Populate the RESCUER with all possible candidates. More...
 
virtual void AddSymbol (LIB_SYMBOL *aNewSymbol)=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 ()
 Return the number of rescue candidates found. More...
 
size_t GetChosenCandidateCount ()
 Get the number of rescue candidates chosen by the user. More...
 
std::vector< SCH_SYMBOL * > * GetSymbols ()
 Get the list of symbols that need rescued. More...
 
PROJECTGetPrj ()
 Return the #SCH_PROJECT object for access to the symbol libraries. More...
 
SCHEMATICSchematic ()
 
void LogRescue (SCH_SYMBOL *aSymbol, 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_SYMBOL * > m_symbols
 
PROJECTm_prj
 
SCHEMATICm_schematic
 
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 235 of file project_rescue.h.

Constructor & Destructor Documentation

◆ RESCUER()

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

Definition at line 535 of file project_rescue.cpp.

537{
538 m_schematic = aSchematic ? aSchematic : aCurrentSheet->LastScreen()->Schematic();
539
540 wxASSERT( m_schematic );
541
542 if( m_schematic )
544
545 m_prj = &aProject;
546 m_currentSheet = aCurrentSheet;
547 m_galBackEndType = aGalBackEndType;
548}
SCHEMATIC * m_schematic
PROJECT * m_prj
std::vector< SCH_SYMBOL * > m_symbols
SCH_SHEET_PATH * m_currentSheet
EDA_DRAW_PANEL_GAL::GAL_TYPE m_galBackEndType
SCHEMATIC * Schematic() const
Definition: sch_screen.cpp:92
SCH_SCREEN * LastScreen()
static void getSymbols(SCHEMATIC *aSchematic, std::vector< SCH_SYMBOL * > &aSymbols)
Fill a vector with all of the project's symbols, to ease iterating over them.

References getSymbols(), SCH_SHEET_PATH::LastScreen(), m_currentSheet, m_galBackEndType, m_prj, m_schematic, m_symbols, and SCH_SCREEN::Schematic().

◆ ~RESCUER()

virtual RESCUER::~RESCUER ( )
inlinevirtual

Definition at line 241 of file project_rescue.h.

242 {
243 }

Member Function Documentation

◆ AddSymbol()

◆ DoRescues()

bool RESCUER::DoRescues ( )

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

Returns
True on success

Definition at line 562 of file project_rescue.cpp.

563{
564 for( RESCUE_CANDIDATE* each_candidate : m_chosen_candidates )
565 {
566 if( ! each_candidate->PerformAction( this ) )
567 return false;
568 }
569
570 return true;
571}
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 LEGACY_RESCUER, and SYMBOL_LIB_TABLE_RESCUER.

Referenced by RescueProject().

◆ GetCandidateCount()

size_t RESCUER::GetCandidateCount ( )
inline

Return the number of rescue candidates found.

Definition at line 278 of file project_rescue.h.

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

References m_all_candidates.

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

◆ GetChosenCandidateCount()

size_t RESCUER::GetChosenCandidateCount ( )
inline

Get the number of rescue candidates chosen by the user.

Definition at line 283 of file project_rescue.h.

283{ return m_chosen_candidates.size(); }

References m_chosen_candidates.

Referenced by RescueProject().

◆ GetPrj()

PROJECT * RESCUER::GetPrj ( )
inline

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

Definition at line 293 of file project_rescue.h.

293{ return m_prj; }

References m_prj.

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

◆ GetSymbols()

◆ 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 LEGACY_RESCUER, and SYMBOL_LIB_TABLE_RESCUER.

Referenced by RescueProject().

◆ LogRescue()

void RESCUER::LogRescue ( SCH_SYMBOL aSymbol,
const wxString &  aOldName,
const wxString &  aNewName 
)

Used by individual RESCUE_CANDIDATE objects to log a rescue for undoing.

Definition at line 551 of file project_rescue.cpp.

553{
554 RESCUE_LOG logitem;
555 logitem.symbol = aSymbol;
556 logitem.old_name = aOldName;
557 logitem.new_name = aNewName;
558 m_rescue_log.push_back( logitem );
559}
std::vector< RESCUE_LOG > m_rescue_log
wxString old_name
wxString new_name
SCH_SYMBOL * symbol

References m_rescue_log, RESCUE_LOG::new_name, RESCUE_LOG::old_name, and RESCUE_LOG::symbol.

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 LEGACY_RESCUER, and SYMBOL_LIB_TABLE_RESCUER.

Referenced by RescueProject().

◆ RemoveDuplicates()

void RESCUER::RemoveDuplicates ( )

Filter out duplicately named rescue candidates.

Definition at line 633 of file project_rescue.cpp.

634{
635 std::vector<wxString> names_seen;
636
637 for( boost::ptr_vector<RESCUE_CANDIDATE>::iterator it = m_all_candidates.begin();
638 it != m_all_candidates.end(); )
639 {
640 bool seen_already = false;
641
642 for( wxString& name_seen : names_seen )
643 {
644 if( name_seen == it->GetRequestedName() )
645 {
646 seen_already = true;
647 break;
648 }
649 }
650
651 if( seen_already )
652 {
653 it = m_all_candidates.erase( it );
654 }
655 else
656 {
657 names_seen.push_back( it->GetRequestedName() );
658 ++it;
659 }
660 }
661}

References m_all_candidates.

Referenced by RescueProject().

◆ RescueProject()

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

Definition at line 587 of file project_rescue.cpp.

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

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

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

◆ Schematic()

SCHEMATIC * RESCUER::Schematic ( )
inline

Definition at line 295 of file project_rescue.h.

295{ return m_schematic; }

References m_schematic.

Referenced by RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues().

◆ UndoRescues()

void RESCUER::UndoRescues ( )

Reverse the effects of all rescues on the project.

Definition at line 574 of file project_rescue.cpp.

575{
576 for( RESCUE_LOG& each_logitem : m_rescue_log )
577 {
578 LIB_ID libId;
579
580 libId.SetLibItemName( each_logitem.old_name );
581 each_logitem.symbol->SetLibId( libId );
582 each_logitem.symbol->ClearFlags();
583 }
584}
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:109

References m_rescue_log, and LIB_ID::SetLibItemName().

Referenced by RescueProject().

◆ WriteRescueLibrary()

virtual bool RESCUER::WriteRescueLibrary ( wxWindow *  aParent)
pure virtual

Write the rescue library.

Called after successful PerformAction()s. If this fails, undo the actions.

Returns
True on success.

Implemented in LEGACY_RESCUER, and SYMBOL_LIB_TABLE_RESCUER.

Referenced by RescueProject().

Friends And Related Function Documentation

◆ DIALOG_RESCUE_EACH

friend class DIALOG_RESCUE_EACH
friend

Definition at line 317 of file project_rescue.h.

Member Data Documentation

◆ m_all_candidates

◆ m_chosen_candidates

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

Referenced by LogRescue(), and UndoRescues().

◆ m_schematic

◆ m_symbols

std::vector<SCH_SYMBOL*> RESCUER::m_symbols
protected

Definition at line 319 of file project_rescue.h.

Referenced by GetSymbols(), and RESCUER().


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