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, SCH_SHEET_PATH *aCurrentSheet, EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType)
 
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
 Writes out the rescue library. More...
 
virtual void AddPart (LIB_PART *aNewPart) override
 
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
 

Private Attributes

std::unique_ptr< PART_LIBm_rescue_lib
 

Detailed Description

Definition at line 307 of file project_rescue.h.

Constructor & Destructor Documentation

◆ LEGACY_RESCUER()

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

Definition at line 313 of file project_rescue.h.

314  :
315  RESCUER( aProject, aCurrentSheet, aGalBackEndType )
316  {
317  }
RESCUER(PROJECT &aProject, SCH_SHEET_PATH *aCurrentSheet, EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType)

Member Function Documentation

◆ AddPart()

void LEGACY_RESCUER::AddPart ( LIB_PART aNewPart)
overridevirtual

Implements RESCUER.

Definition at line 757 of file project_rescue.cpp.

758 {
759  wxCHECK_RET( aNewPart, "Invalid LIB_PART pointer." );
760 
761  aNewPart->SetLib( m_rescue_lib.get() );
762  m_rescue_lib->AddPart( aNewPart );
763 }
void SetLib(PART_LIB *aLibrary)
std::unique_ptr< PART_LIB > m_rescue_lib

References m_rescue_lib, and LIB_PART::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 488 of file project_rescue.cpp.

489 {
490  for( RESCUE_CANDIDATE* each_candidate : m_chosen_candidates )
491  {
492  if( ! each_candidate->PerformAction( this ) )
493  return false;
494  }
495 
496  return true;
497 }
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 628 of file project_rescue.cpp.

629 {
632 }
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 objectss 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

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

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

◆ GetChosenCandidateCount()

size_t RESCUER::GetChosenCandidateCount ( )
inlineinherited

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

Referenced by RESCUER::RescueProject().

◆ GetComponents()

◆ GetPrj()

PROJECT* RESCUER::GetPrj ( )
inlineinherited

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

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

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

636 {
637  InvokeDialogRescueEach( aParent, static_cast< RESCUER& >( *this ), m_currentSheet,
638  m_galBackEndType, aAskShowAgain );
639 }
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.
SCH_SHEET_PATH * m_currentSheet

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

◆ LogRescue()

void RESCUER::LogRescue ( SCH_COMPONENT aComponent,
const wxString &  aOldName,
const wxString &  aNewName 
)
inherited

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

Definition at line 477 of file project_rescue.cpp.

479 {
480  RESCUE_LOG logitem;
481  logitem.component = aComponent;
482  logitem.old_name = aOldName;
483  logitem.new_name = aNewName;
484  m_rescue_log.push_back( logitem );
485 }
SCH_COMPONENT * component
std::vector< RESCUE_LOG > m_rescue_log
wxString old_name
wxString new_name

References RESCUE_LOG::component, RESCUER::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()

void LEGACY_RESCUER::OpenRescueLibrary ( )
overridevirtual

Implements RESCUER.

Definition at line 642 of file project_rescue.cpp.

643 {
644  wxFileName fn = GetRescueLibraryFileName();
645 
646  std::unique_ptr<PART_LIB> rescue_lib( new PART_LIB( LIBRARY_TYPE_EESCHEMA, fn.GetFullPath() ) );
647 
648  m_rescue_lib = std::move( rescue_lib );
649  m_rescue_lib->EnableBuffering();
650 
651  // If a rescue library already exists copy the contents of that library so we do not
652  // lose an previous rescues.
653  PART_LIB* rescueLib = m_prj->SchLibs()->FindLibrary( fn.GetName() );
654 
655  if( rescueLib )
656  {
657  // For items in the rescue library, aliases are the root symbol.
658  std::vector< LIB_ALIAS* > aliases;
659 
660  rescueLib->GetAliases( aliases );
661 
662  for( auto alias : aliases )
663  {
664  LIB_PART* part = alias->GetPart();
665 
666  wxCHECK2( part, continue );
667 
668  m_rescue_lib->AddPart( new LIB_PART( *part, m_rescue_lib.get() ) );
669  }
670  }
671 }
Define a library symbol object.
PROJECT * m_prj
static wxFileName GetRescueLibraryFileName()
std::unique_ptr< PART_LIB > m_rescue_lib
void GetAliases(std::vector< LIB_ALIAS * > &aAliases) const
Load a vector with all the entries in this library.
Object used to load, save, search, and otherwise manipulate symbol library files.

References PART_LIB::GetAliases(), GetRescueLibraryFileName(), LIBRARY_TYPE_EESCHEMA, RESCUER::m_prj, and m_rescue_lib.

◆ RemoveDuplicates()

void RESCUER::RemoveDuplicates ( )
inherited

Filter out duplicately named rescue candidates.

Definition at line 597 of file project_rescue.cpp.

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

References RESCUER::m_all_candidates.

Referenced by RESCUER::RescueProject().

◆ RescueProject()

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

Definition at line 551 of file project_rescue.cpp.

552 {
553  aRescuer.FindCandidates();
554 
555  if( !aRescuer.GetCandidateCount() )
556  {
557  if( aRunningOnDemand )
558  {
559  wxMessageDialog dlg( aParent, _( "This project has nothing to rescue." ),
560  _( "Project Rescue Helper" ) );
561  dlg.ShowModal();
562  }
563 
564  return true;
565  }
566 
567  aRescuer.RemoveDuplicates();
568  aRescuer.InvokeDialog( aParent, !aRunningOnDemand );
569 
570  // If no symbols were rescued, let the user know what's going on. He might
571  // have clicked cancel by mistake, and should have some indication of that.
572  if( !aRescuer.GetChosenCandidateCount() )
573  {
574  wxMessageDialog dlg( aParent, _( "No symbols were rescued." ),
575  _( "Project Rescue Helper" ) );
576  dlg.ShowModal();
577 
578  // Set the modified flag even on Cancel. Many users seem to instinctively want to Save at
579  // this point, due to the reloading of the symbols, so we'll make the save button active.
580  return true;
581  }
582 
583  aRescuer.OpenRescueLibrary();
584 
585  if( !aRescuer.DoRescues() )
586  {
587  aRescuer.UndoRescues();
588  return false;
589  }
590 
591  aRescuer.WriteRescueLibrary( aParent );
592 
593  return true;
594 }
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.
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 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_EDIT_FRAME::rescueProject().

◆ UndoRescues()

void RESCUER::UndoRescues ( )
inherited

Reverse the effects of all rescues on the project.

Definition at line 500 of file project_rescue.cpp.

501 {
502  for( RESCUE_LOG& each_logitem : m_rescue_log )
503  {
504  LIB_ID libId;
505 
506  libId.SetLibItemName( each_logitem.old_name, false );
507  each_logitem.component->SetLibId( libId );
508  each_logitem.component->ClearFlags();
509  }
510 }
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 RESCUER::m_rescue_log, and LIB_ID::SetLibItemName().

Referenced by RESCUER::RescueProject().

◆ WriteRescueLibrary()

bool LEGACY_RESCUER::WriteRescueLibrary ( wxWindow *  aParent)
overridevirtual

Writes out the rescue library.

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

Returns
True on success.

Implements RESCUER.

Definition at line 674 of file project_rescue.cpp.

675 {
676  try
677  {
678  m_rescue_lib->Save( false );
679  }
680  catch( ... /* IO_ERROR ioe */ )
681  {
682  wxString msg;
683 
684  msg.Printf( _( "Failed to create symbol library file \"%s\"" ),
685  m_rescue_lib->GetFullFileName() );
686  DisplayError( aParent, msg );
687  return false;
688  }
689 
690  wxArrayString libNames;
691  wxString libPaths;
692 
693  wxString libName = m_rescue_lib->GetName();
694  PART_LIBS *libs = dynamic_cast<PART_LIBS*>( m_prj->GetElem( PROJECT::ELEM_SCH_PART_LIBS ) );
695 
696  if( !libs )
697  {
698  libs = new PART_LIBS();
700  }
701 
702  try
703  {
704  PART_LIBS::LibNamesAndPaths( m_prj, false, &libPaths, &libNames );
705 
706  // Make sure the library is not already in the list
707  while( libNames.Index( libName ) != wxNOT_FOUND )
708  libNames.Remove( libName );
709 
710  // Add the library to the top of the list and save.
711  libNames.Insert( libName, 0 );
712  PART_LIBS::LibNamesAndPaths( m_prj, true, &libPaths, &libNames );
713  }
714  catch( const IO_ERROR& )
715  {
716  // Could not get or save the current libraries.
717  return false;
718  }
719 
720  // Save the old libraries in case there is a problem after clear(). We'll
721  // put them back in.
722  boost::ptr_vector<PART_LIB> libsSave;
723  libsSave.transfer( libsSave.end(), libs->begin(), libs->end(), *libs );
724 
726 
727  libs = new PART_LIBS();
728 
729  try
730  {
731  libs->LoadAllLibraries( m_prj );
732  }
733  catch( const PARSE_ERROR& )
734  {
735  // Some libraries were not found. There's no point in showing the error,
736  // because it was already shown. Just don't do anything.
737  }
738  catch( const IO_ERROR& )
739  {
740  // Restore the old list
741  libs->clear();
742  libs->transfer( libs->end(), libsSave.begin(), libsSave.end(), libsSave );
743  return false;
744  }
745 
747 
748  // Update the schematic symbol library links since the library list has changed.
749  SCH_SCREENS schematic;
750 
751  schematic.UpdateSymbolLinks();
752 
753  return true;
754 }
static void LibNamesAndPaths(PROJECT *aProject, bool doSave, wxString *aPaths, wxArrayString *aNames=NULL)
Save or load the names of the currently configured part libraries (without paths).
void LoadAllLibraries(PROJECT *aProject, bool aShowProgress=true)
Load all of the project's libraries into this container, which should be cleared before calling it.
VTBL_ENTRY _ELEM * GetElem(ELEM_T aIndex)
Typically wrapped somewhere else in a more meaningful function wrapper.
Definition: project.cpp:205
VTBL_ENTRY void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:217
PROJECT * m_prj
A collection of PART_LIB objects.
Struct PARSE_ERROR contains a filename or source description, a problem input line,...
Definition: ki_exception.h:123
std::unique_ptr< PART_LIB > m_rescue_lib
void UpdateSymbolLinks(bool aForce=false)
Initialize or reinitialize the weak reference to the LIB_PART for each SCH_COMPONENT found in the ful...
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:244
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:493

References DisplayError(), PROJECT::ELEM_SCH_PART_LIBS, PROJECT::GetElem(), PART_LIBS::LibNamesAndPaths(), PART_LIBS::LoadAllLibraries(), RESCUER::m_prj, m_rescue_lib, PROJECT::SetElem(), and SCH_SCREENS::UpdateSymbolLinks().

Member Data Documentation

◆ m_all_candidates

◆ m_chosen_candidates

◆ m_components

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

Definition at line 222 of file project_rescue.h.

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

◆ 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<PART_LIB> LEGACY_RESCUER::m_rescue_lib
private

Definition at line 310 of file project_rescue.h.

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

◆ m_rescue_log

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

Definition at line 230 of file project_rescue.h.

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


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