KiCad PCB EDA Suite
LEGACY_RESCUER Class Reference

#include <project_rescue.h>

Inheritance diagram for LEGACY_RESCUER:
RESCUER

Public Member Functions

 LEGACY_RESCUER (SCH_EDIT_FRAME &aEditFrame, PROJECT &aProject)
 
virtual void FindCandidates () override
 Populate the RESCUER with all possible candidates. More...
 
virtual void InvokeDialog (bool aAskShowAgain) override
 Display a dialog to allow the user to select rescues. More...
 
virtual void OpenRescueLibrary () override
 
virtual bool WriteRescueLibrary (SCH_EDIT_FRAME *aEditFrame) override
 Writes out the rescue library. More...
 
virtual void AddPart (LIB_PART *aNewPart) override
 
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...
 
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
 

Private Attributes

std::unique_ptr< PART_LIBm_rescue_lib
 

Detailed Description

Definition at line 303 of file project_rescue.h.

Constructor & Destructor Documentation

LEGACY_RESCUER::LEGACY_RESCUER ( SCH_EDIT_FRAME aEditFrame,
PROJECT aProject 
)
inline

Definition at line 309 of file project_rescue.h.

309  :
310  RESCUER( aEditFrame, aProject )
311  {
312  }
RESCUER(SCH_EDIT_FRAME &aEditFrame, PROJECT &aProject)

Member Function Documentation

void LEGACY_RESCUER::AddPart ( LIB_PART aNewPart)
overridevirtual

Implements RESCUER.

Definition at line 744 of file project_rescue.cpp.

References LIB_PART::SetLib().

745 {
746  wxCHECK_RET( aNewPart, "Invalid LIB_PART pointer." );
747 
748  aNewPart->SetLib( m_rescue_lib.get() );
749  m_rescue_lib->AddPart( aNewPart );
750 }
void SetLib(PART_LIB *aLibrary)
std::unique_ptr< PART_LIB > m_rescue_lib
bool RESCUER::DoRescues ( )
inherited

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

Returns
True on success

Definition at line 486 of file project_rescue.cpp.

Referenced by SCH_EDIT_FRAME::rescueProject().

487 {
488  for( RESCUE_CANDIDATE* each_candidate : m_chosen_candidates )
489  {
490  if( ! each_candidate->PerformAction( this ) )
491  return false;
492  }
493 
494  return true;
495 }
std::vector< RESCUE_CANDIDATE * > m_chosen_candidates
void LEGACY_RESCUER::FindCandidates ( )
overridevirtual

Populate the RESCUER with all possible candidates.

Implements RESCUER.

Definition at line 616 of file project_rescue.cpp.

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

617 {
620 }
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.
size_t RESCUER::GetCandidateCount ( )
inlineinherited

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

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

Definition at line 256 of file project_rescue.h.

Referenced by RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues().

256 { return m_edit_frame; }
SCH_EDIT_FRAME * m_edit_frame
PROJECT* RESCUER::GetPrj ( )
inlineinherited

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

Definition at line 281 of file project_rescue.h.

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

281 { return m_prj; }
PROJECT * m_prj
void LEGACY_RESCUER::InvokeDialog ( 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 623 of file project_rescue.cpp.

References InvokeDialogRescueEach().

624 {
625  InvokeDialogRescueEach( m_edit_frame, static_cast< RESCUER& >( *this ), aAskShowAgain );
626 }
int InvokeDialogRescueEach(SCH_EDIT_FRAME *aCaller, RESCUER &aRescuer, bool aAskShowAgain)
Function InvokeDialogRescueEach This dialog asks the user which rescuable, cached parts he wants to r...
SCH_EDIT_FRAME * m_edit_frame
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 475 of file project_rescue.cpp.

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

477 {
478  RESCUE_LOG logitem;
479  logitem.component = aComponent;
480  logitem.old_name = aOldName;
481  logitem.new_name = aNewName;
482  m_rescue_log.push_back( logitem );
483 }
SCH_COMPONENT * component
std::vector< RESCUE_LOG > m_rescue_log
wxString old_name
wxString new_name
void LEGACY_RESCUER::OpenRescueLibrary ( )
overridevirtual

Implements RESCUER.

Definition at line 629 of file project_rescue.cpp.

References PART_LIB::GetAliases(), GetRescueLibraryFileName(), and LIBRARY_TYPE_EESCHEMA.

630 {
631  wxFileName fn = GetRescueLibraryFileName();
632 
633  std::unique_ptr<PART_LIB> rescue_lib( new PART_LIB( LIBRARY_TYPE_EESCHEMA, fn.GetFullPath() ) );
634 
635  m_rescue_lib = std::move( rescue_lib );
636  m_rescue_lib->EnableBuffering();
637 
638  // If a rescue library already exists copy the contents of that library so we do not
639  // lose an previous rescues.
640  PART_LIB* rescueLib = m_prj->SchLibs()->FindLibrary( fn.GetName() );
641 
642  if( rescueLib )
643  {
644  // For items in the rescue library, aliases are the root symbol.
645  std::vector< LIB_ALIAS* > aliases;
646 
647  rescueLib->GetAliases( aliases );
648 
649  for( auto alias : aliases )
650  {
651  LIB_PART* part = alias->GetPart();
652 
653  wxCHECK2( part, continue );
654 
655  m_rescue_lib->AddPart( new LIB_PART( *part, m_rescue_lib.get() ) );
656  }
657  }
658 }
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. ...
void RESCUER::RemoveDuplicates ( )
inherited

Filter out duplicately named rescue candidates.

Definition at line 585 of file project_rescue.cpp.

Referenced by SCH_EDIT_FRAME::rescueProject().

586 {
587  std::vector<wxString> names_seen;
588 
589  for( boost::ptr_vector<RESCUE_CANDIDATE>::iterator it = m_all_candidates.begin();
590  it != m_all_candidates.end(); )
591  {
592  bool seen_already = false;
593 
594  for( wxString& name_seen : names_seen )
595  {
596  if( name_seen == it->GetRequestedName() )
597  {
598  seen_already = true;
599  break;
600  }
601  }
602 
603  if( seen_already )
604  {
605  it = m_all_candidates.erase( it );
606  }
607  else
608  {
609  names_seen.push_back( it->GetRequestedName() );
610  ++it;
611  }
612  }
613 }
boost::ptr_vector< RESCUE_CANDIDATE > m_all_candidates
void RESCUER::UndoRescues ( )
inherited

Reverse the effects of all rescues on the project.

Definition at line 498 of file project_rescue.cpp.

References LIB_ID::SetLibItemName().

Referenced by SCH_EDIT_FRAME::rescueProject().

499 {
500  for( RESCUE_LOG& each_logitem : m_rescue_log )
501  {
502  LIB_ID libId;
503 
504  libId.SetLibItemName( each_logitem.old_name, false );
505  each_logitem.component->SetLibId( libId );
506  each_logitem.component->ClearFlags();
507  }
508 }
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
bool LEGACY_RESCUER::WriteRescueLibrary ( SCH_EDIT_FRAME aEditFrame)
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 661 of file project_rescue.cpp.

References DisplayError(), PROJECT::ELEM_SCH_PART_LIBS, PART_LIBS::LibNamesAndPaths(), PART_LIBS::LoadAllLibraries(), and SCH_SCREENS::UpdateSymbolLinks().

662 {
663  try
664  {
665  m_rescue_lib->Save( false );
666  }
667  catch( ... /* IO_ERROR ioe */ )
668  {
669  wxString msg;
670 
671  msg.Printf( _( "Failed to create symbol library file \"%s\"" ),
672  m_rescue_lib->GetFullFileName() );
673  DisplayError( aEditFrame, msg );
674  return false;
675  }
676 
677  wxArrayString libNames;
678  wxString libPaths;
679 
680  wxString libName = m_rescue_lib->GetName();
681  PART_LIBS *libs = dynamic_cast<PART_LIBS*>( m_prj->GetElem( PROJECT::ELEM_SCH_PART_LIBS ) );
682 
683  if( !libs )
684  {
685  libs = new PART_LIBS();
687  }
688 
689  try
690  {
691  PART_LIBS::LibNamesAndPaths( m_prj, false, &libPaths, &libNames );
692 
693  // Make sure the library is not already in the list
694  while( libNames.Index( libName ) != wxNOT_FOUND )
695  libNames.Remove( libName );
696 
697  // Add the library to the top of the list and save.
698  libNames.Insert( libName, 0 );
699  PART_LIBS::LibNamesAndPaths( m_prj, true, &libPaths, &libNames );
700  }
701  catch( const IO_ERROR& )
702  {
703  // Could not get or save the current libraries.
704  return false;
705  }
706 
707  // Save the old libraries in case there is a problem after clear(). We'll
708  // put them back in.
709  boost::ptr_vector<PART_LIB> libsSave;
710  libsSave.transfer( libsSave.end(), libs->begin(), libs->end(), *libs );
711 
713 
714  libs = new PART_LIBS();
715 
716  try
717  {
718  libs->LoadAllLibraries( m_prj );
719  }
720  catch( const PARSE_ERROR& )
721  {
722  // Some libraries were not found. There's no point in showing the error,
723  // because it was already shown. Just don't do anything.
724  }
725  catch( const IO_ERROR& )
726  {
727  // Restore the old list
728  libs->clear();
729  libs->transfer( libs->end(), libsSave.begin(), libsSave.end(), libsSave );
730  return false;
731  }
732 
734 
735  // Update the schematic symbol library links since the library list has changed.
736  SCH_SCREENS schematic;
737 
738  schematic.UpdateSymbolLinks();
739 
740  return true;
741 }
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&#39;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, a line number, a byte offset, and an error message which contains the the caller&#39;s report and his call site information: CPP source file, function, and line number.
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:245
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:523

Member Data Documentation

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

Definition at line 220 of file project_rescue.h.

SCH_EDIT_FRAME* RESCUER::m_edit_frame
protectedinherited

Definition at line 222 of file project_rescue.h.

Referenced by SYMBOL_LIB_TABLE_RESCUER::InvokeDialog().

PROJECT* RESCUER::m_prj
protectedinherited
std::unique_ptr<PART_LIB> LEGACY_RESCUER::m_rescue_lib
private

Definition at line 306 of file project_rescue.h.

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

Definition at line 227 of file project_rescue.h.


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