KiCad PCB EDA Suite
LEGACY_RESCUER Class Reference

#include <project_rescue.h>

Inheritance diagram for LEGACY_RESCUER:
RESCUER

Public Member Functions

 LEGACY_RESCUER (PROJECT &aProject, SCHEMATIC *aSchematic, SCH_SHEET_PATH *aCurrentSheet, EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType)
 
virtual ~LEGACY_RESCUER ()
 
virtual void FindCandidates () override
 Populate the RESCUER with all possible candidates. More...
 
virtual void InvokeDialog (wxWindow *aParent, bool aAskShowAgain) override
 Display a dialog to allow the user to select rescues. More...
 
virtual void OpenRescueLibrary () override
 
virtual bool WriteRescueLibrary (wxWindow *aParent) override
 Write the rescue library. More...
 
virtual void AddSymbol (LIB_SYMBOL *aNewSymbol) override
 
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
 

Private Attributes

std::unique_ptr< SYMBOL_LIBm_rescue_lib
 

Detailed Description

Definition at line 332 of file project_rescue.h.

Constructor & Destructor Documentation

◆ LEGACY_RESCUER()

LEGACY_RESCUER::LEGACY_RESCUER ( PROJECT aProject,
SCHEMATIC aSchematic,
SCH_SHEET_PATH aCurrentSheet,
EDA_DRAW_PANEL_GAL::GAL_TYPE  aGalBackEndType 
)
inline

Definition at line 335 of file project_rescue.h.

336 :
337 RESCUER( aProject, aSchematic, aCurrentSheet, aGalBackEndType )
338 {
339 }
RESCUER(PROJECT &aProject, SCHEMATIC *aSchematic, SCH_SHEET_PATH *aCurrentSheet, EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType)

◆ ~LEGACY_RESCUER()

virtual LEGACY_RESCUER::~LEGACY_RESCUER ( )
inlinevirtual

Definition at line 341 of file project_rescue.h.

342 {
343 }

Member Function Documentation

◆ AddSymbol()

void LEGACY_RESCUER::AddSymbol ( LIB_SYMBOL aNewSymbol)
overridevirtual

Implements RESCUER.

Definition at line 789 of file project_rescue.cpp.

790{
791 wxCHECK_RET( aNewSymbol, wxS( "Invalid LIB_SYMBOL pointer." ) );
792
793 aNewSymbol->SetLib( m_rescue_lib.get() );
794 m_rescue_lib->AddSymbol( aNewSymbol );
795}
std::unique_ptr< SYMBOL_LIB > m_rescue_lib
void SetLib(SYMBOL_LIB *aLibrary)
Definition: lib_symbol.h:193

References m_rescue_lib, and LIB_SYMBOL::SetLib().

◆ DoRescues()

bool RESCUER::DoRescues ( )
inherited

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 RESCUER::m_chosen_candidates.

Referenced by RESCUER::RescueProject().

◆ FindCandidates()

void LEGACY_RESCUER::FindCandidates ( )
overridevirtual

Populate the RESCUER with all possible candidates.

Implements RESCUER.

Definition at line 664 of file project_rescue.cpp.

665{
668}
boost::ptr_vector< RESCUE_CANDIDATE > m_all_candidates
static void FindRescues(RESCUER &aRescuer, boost::ptr_vector< RESCUE_CANDIDATE > &aCandidates)
Grab all possible RESCUE_CACHE_CANDIDATE objects into a vector.
static void FindRescues(RESCUER &aRescuer, boost::ptr_vector< RESCUE_CANDIDATE > &aCandidates)
Grab all possible RESCUE_CASE_CANDIDATE objects into a vector.

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

◆ GetCandidateCount()

size_t RESCUER::GetCandidateCount ( )
inlineinherited

Return the number of rescue candidates found.

Definition at line 278 of file project_rescue.h.

278{ return m_all_candidates.size(); }

References RESCUER::m_all_candidates.

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

◆ GetChosenCandidateCount()

size_t RESCUER::GetChosenCandidateCount ( )
inlineinherited

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 RESCUER::m_chosen_candidates.

Referenced by RESCUER::RescueProject().

◆ GetPrj()

PROJECT * RESCUER::GetPrj ( )
inlineinherited

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

Definition at line 293 of file project_rescue.h.

293{ return m_prj; }
PROJECT * m_prj

References RESCUER::m_prj.

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

◆ GetSymbols()

◆ InvokeDialog()

void LEGACY_RESCUER::InvokeDialog ( wxWindow *  aParent,
bool  aAskShowAgain 
)
overridevirtual

Display a dialog to allow the user to select rescues.

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

Implements RESCUER.

Definition at line 671 of file project_rescue.cpp.

672{
673 InvokeDialogRescueEach( aParent, static_cast< RESCUER& >( *this ), m_currentSheet,
674 m_galBackEndType, aAskShowAgain );
675}
SCH_SHEET_PATH * m_currentSheet
EDA_DRAW_PANEL_GAL::GAL_TYPE m_galBackEndType
int InvokeDialogRescueEach(wxWindow *aParent, RESCUER &aRescuer, SCH_SHEET_PATH *aCurrentSheet, EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType, bool aAskShowAgain)
This dialog asks the user which rescuable, cached parts he wants to rescue.

References InvokeDialogRescueEach(), RESCUER::m_currentSheet, and RESCUER::m_galBackEndType.

◆ LogRescue()

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

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 RESCUER::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()

void LEGACY_RESCUER::OpenRescueLibrary ( )
overridevirtual

Implements RESCUER.

Definition at line 678 of file project_rescue.cpp.

679{
680 wxFileName fn = GetRescueLibraryFileName( m_schematic );
681
682 std::unique_ptr<SYMBOL_LIB> rescue_lib = std::make_unique<SYMBOL_LIB>( SCH_LIB_TYPE::LT_EESCHEMA,
683 fn.GetFullPath() );
684
685 m_rescue_lib = std::move( rescue_lib );
686 m_rescue_lib->EnableBuffering();
687
688 // If a rescue library already exists copy the contents of that library so we do not
689 // lose any previous rescues.
690 SYMBOL_LIB* rescueLib = m_prj->SchLibs()->FindLibrary( fn.GetName() );
691
692 if( rescueLib )
693 {
694 // For items in the rescue library, aliases are the root symbol.
695 std::vector< LIB_SYMBOL* > symbols;
696
697 rescueLib->GetSymbols( symbols );
698
699 for( LIB_SYMBOL* symbol : symbols )
700 {
701 // The LIB_SYMBOL copy constructor flattens derived symbols (formerly known as aliases).
702 m_rescue_lib->AddSymbol( new LIB_SYMBOL( *symbol, m_rescue_lib.get() ) );
703 }
704 }
705}
Define a library symbol object.
Definition: lib_symbol.h:99
SCHEMATIC * m_schematic
Object used to load, save, search, and otherwise manipulate symbol library files.
void GetSymbols(std::vector< LIB_SYMBOL * > &aSymbols) const
Load a vector with all the entries in this library.
static wxFileName GetRescueLibraryFileName(SCHEMATIC *aSchematic)

References GetRescueLibraryFileName(), SYMBOL_LIB::GetSymbols(), LT_EESCHEMA, RESCUER::m_prj, m_rescue_lib, and RESCUER::m_schematic.

◆ RemoveDuplicates()

void RESCUER::RemoveDuplicates ( )
inherited

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 RESCUER::m_all_candidates.

Referenced by RESCUER::RescueProject().

◆ RescueProject()

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

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 _, RESCUER::DoRescues(), RESCUER::FindCandidates(), RESCUER::GetCandidateCount(), RESCUER::GetChosenCandidateCount(), RESCUER::InvokeDialog(), RESCUER::OpenRescueLibrary(), RESCUER::RemoveDuplicates(), RESCUER::UndoRescues(), and RESCUER::WriteRescueLibrary().

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

◆ Schematic()

SCHEMATIC * RESCUER::Schematic ( )
inlineinherited

Definition at line 295 of file project_rescue.h.

295{ return m_schematic; }

References RESCUER::m_schematic.

Referenced by RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues().

◆ UndoRescues()

void RESCUER::UndoRescues ( )
inherited

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 RESCUER::m_rescue_log, and LIB_ID::SetLibItemName().

Referenced by RESCUER::RescueProject().

◆ WriteRescueLibrary()

bool LEGACY_RESCUER::WriteRescueLibrary ( wxWindow *  aParent)
overridevirtual

Write the rescue library.

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

Returns
True on success.

Implements RESCUER.

Definition at line 708 of file project_rescue.cpp.

709{
710 try
711 {
712 m_rescue_lib->Save( false );
713 }
714 catch( ... /* IO_ERROR ioe */ )
715 {
716 wxString msg;
717
718 msg.Printf( _( "Failed to create symbol library file '%s'." ),
719 m_rescue_lib->GetFullFileName() );
720 DisplayError( aParent, msg );
721 return false;
722 }
723
724 wxArrayString libNames;
725 wxString libPaths;
726
727 wxString libName = m_rescue_lib->GetName();
729
730 if( !libs )
731 {
732 libs = new SYMBOL_LIBS();
734 }
735
736 try
737 {
738 SYMBOL_LIBS::GetLibNamesAndPaths( m_prj, &libPaths, &libNames );
739
740 // Make sure the library is not already in the list
741 while( libNames.Index( libName ) != wxNOT_FOUND )
742 libNames.Remove( libName );
743
744 // Add the library to the top of the list and save.
745 libNames.Insert( libName, 0 );
746 SYMBOL_LIBS::SetLibNamesAndPaths( m_prj, libPaths, libNames );
747 }
748 catch( const IO_ERROR& )
749 {
750 // Could not get or save the current libraries.
751 return false;
752 }
753
754 // Save the old libraries in case there is a problem after clear(). We'll
755 // put them back in.
756 boost::ptr_vector<SYMBOL_LIB> libsSave;
757 libsSave.transfer( libsSave.end(), libs->begin(), libs->end(), *libs );
758
760
761 libs = new SYMBOL_LIBS();
762
763 try
764 {
765 libs->LoadAllLibraries( m_prj );
766 }
767 catch( const PARSE_ERROR& )
768 {
769 // Some libraries were not found. There's no point in showing the error,
770 // because it was already shown. Just don't do anything.
771 }
772 catch( const IO_ERROR& )
773 {
774 // Restore the old list
775 libs->clear();
776 libs->transfer( libs->end(), libsSave.begin(), libsSave.end(), libsSave );
777 return false;
778 }
779
781
782 // Update the schematic symbol library links since the library list has changed.
783 SCH_SCREENS schematic( m_schematic->Root() );
784 schematic.UpdateSymbolLinks();
785 return true;
786}
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
virtual _ELEM * GetElem(ELEM_T aIndex)
Get and set the elements for this project.
Definition: project.cpp:284
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:294
@ ELEM_SCH_SYMBOL_LIBS
Definition: project.h:208
SCH_SHEET & Root() const
Definition: schematic.h:91
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:662
A collection of SYMBOL_LIB objects.
static void SetLibNamesAndPaths(PROJECT *aProject, const wxString &aPaths, const wxArrayString &aNames)
void LoadAllLibraries(PROJECT *aProject, bool aShowProgress=true)
Load all of the project's libraries into this container, which should be cleared before calling it.
static void GetLibNamesAndPaths(PROJECT *aProject, wxString *aPaths, wxArrayString *aNames=nullptr)
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:300
A filename or source description, a problem input line, a line number, a byte offset,...
Definition: ki_exception.h:119

References _, DisplayError(), PROJECT::ELEM_SCH_SYMBOL_LIBS, PROJECT::GetElem(), SYMBOL_LIBS::GetLibNamesAndPaths(), SYMBOL_LIBS::LoadAllLibraries(), RESCUER::m_prj, m_rescue_lib, RESCUER::m_schematic, SCHEMATIC::Root(), PROJECT::SetElem(), SYMBOL_LIBS::SetLibNamesAndPaths(), and SCH_SCREENS::UpdateSymbolLinks().

Member Data Documentation

◆ m_all_candidates

◆ m_chosen_candidates

◆ m_currentSheet

SCH_SHEET_PATH* RESCUER::m_currentSheet
protectedinherited

◆ m_galBackEndType

EDA_DRAW_PANEL_GAL::GAL_TYPE RESCUER::m_galBackEndType
protectedinherited

◆ m_prj

◆ m_rescue_lib

std::unique_ptr<SYMBOL_LIB> LEGACY_RESCUER::m_rescue_lib
private

Definition at line 356 of file project_rescue.h.

Referenced by AddSymbol(), OpenRescueLibrary(), and WriteRescueLibrary().

◆ m_rescue_log

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

Definition at line 328 of file project_rescue.h.

Referenced by RESCUER::LogRescue(), and RESCUER::UndoRescues().

◆ m_schematic

◆ m_symbols

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

Definition at line 319 of file project_rescue.h.

Referenced by RESCUER::GetSymbols(), and RESCUER::RESCUER().


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