KiCad PCB EDA Suite
project_rescue.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015-2017 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #include <class_drawpanel.h>
25 #include <class_library.h>
26 #include <confirm.h>
27 #include <invoke_sch_dialog.h>
28 #include <kicad_device_context.h>
29 #include <project_rescue.h>
30 #include <sch_component.h>
31 #include <sch_sheet.h>
32 #include <schframe.h>
34 
35 #include <cctype>
36 #include <map>
37 
38 
39 typedef std::pair<SCH_COMPONENT*, wxString> COMPONENT_NAME_PAIR;
40 
41 
49 static bool save_library( PART_LIB* aLibrary, SCH_EDIT_FRAME* aEditFrame )
50 {
51  try
52  {
53  aLibrary->Save( false );
54  }
55  catch( ... /* IO_ERROR ioe */ )
56  {
57  wxString msg = wxString::Format( _( "Failed to create component library file '%s'" ),
58  GetChars( aLibrary->GetFullFileName() )
59  );
60  DisplayError( aEditFrame, msg );
61  return false;
62  }
63 
64  return true;
65 }
66 
67 
78 static bool insert_library( PROJECT *aProject, PART_LIB *aLibrary, size_t aIndex ) throw( boost::bad_pointer )
79 {
80  wxArrayString libNames;
81  wxString libPaths;
82 
83  wxString libName = aLibrary->GetName();
84  PART_LIBS *libs = dynamic_cast<PART_LIBS*>( aProject->GetElem( PROJECT::ELEM_SCH_PART_LIBS ) );
85  if( !libs )
86  {
87  libs = new PART_LIBS();
88  aProject->SetElem( PROJECT::ELEM_SCH_PART_LIBS, libs );
89  }
90 
91  try
92  {
93  PART_LIBS::LibNamesAndPaths( aProject, false, &libPaths, &libNames );
94 
95  // Make sure the library is not already in the list
96  while( libNames.Index( libName ) != wxNOT_FOUND )
97  libNames.Remove( libName );
98 
99  // Add the library to the list and save
100  libNames.Insert( libName, aIndex );
101  PART_LIBS::LibNamesAndPaths( aProject, true, &libPaths, &libNames );
102  }
103  catch( const IO_ERROR& )
104  {
105  // Could not get or save the current libraries.
106  return false;
107  }
108 
109  // Save the old libraries in case there is a problem after clear(). We'll
110  // put them back in.
111  boost::ptr_vector<PART_LIB> libsSave;
112  libsSave.transfer( libsSave.end(), libs->begin(), libs->end(), *libs );
113 
114  aProject->SetElem( PROJECT::ELEM_SCH_PART_LIBS, NULL );
115 
116  libs = new PART_LIBS();
117  try
118  {
119  libs->LoadAllLibraries( aProject );
120  }
121  catch( const PARSE_ERROR& )
122  {
123  // Some libraries were not found. There's no point in showing the error,
124  // because it was already shown. Just don't do anything.
125  }
126  catch( const IO_ERROR& )
127  {
128  // Restore the old list
129  libs->clear();
130  libs->transfer( libs->end(), libsSave.begin(), libsSave.end(), libsSave );
131  return false;
132  }
133  aProject->SetElem( PROJECT::ELEM_SCH_PART_LIBS, libs );
134 
135  // Update the schematic symbol library links since the library list has changed.
136  SCH_SCREENS schematic;
137 
138  schematic.UpdateSymbolLinks();
139 
140  return true;
141 }
142 
143 
153 // Helper sort function, used in get_components, to sort a component list by lib_id
154 static bool sort_by_libid( const SCH_COMPONENT* ref, SCH_COMPONENT* cmp )
155 {
156  return ref->GetLibId() < cmp->GetLibId();
157 }
158 
159 static void get_components( std::vector<SCH_COMPONENT*>& aComponents )
160 {
161  SCH_SCREENS screens;
162 
163  // Get the full list
164  for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
165  {
166  for( SCH_ITEM* item = screen->GetDrawItems(); item; item = item->Next() )
167  {
168  if( item->Type() != SCH_COMPONENT_T )
169  continue;
170  SCH_COMPONENT* component = static_cast<SCH_COMPONENT*>( item );
171  aComponents.push_back( component );
172  }
173  }
174 
175  // sort aComponents by lib part. Components will be grouped by same lib part.
176  std::sort( aComponents.begin(), aComponents.end(), sort_by_libid );
177 }
178 
179 
188 static LIB_PART* find_component( wxString aName, PART_LIBS* aLibs, bool aCached )
189 {
190  LIB_PART *part = NULL;
191 
192  for( PART_LIB& each_lib : *aLibs )
193  {
194  if( aCached && !each_lib.IsCache() )
195  continue;
196 
197  if( !aCached && each_lib.IsCache() )
198  continue;
199 
200  part = each_lib.FindPart( aName );
201  if( part )
202  break;
203  }
204 
205  return part;
206 }
207 
208 
210 {
211  std::vector<wxString> names_seen;
212 
213  for( boost::ptr_vector<RESCUE_CANDIDATE>::iterator it = m_all_candidates.begin();
214  it != m_all_candidates.end(); )
215  {
216  bool seen_already = false;
217  for( wxString& name_seen : names_seen )
218  {
219  if( name_seen == it->GetRequestedName() )
220  {
221  seen_already = true;
222  break;
223  }
224  }
225 
226  if( seen_already )
227  {
228  it = m_all_candidates.erase( it );
229  }
230  else
231  {
232  names_seen.push_back( it->GetRequestedName() );
233  ++it;
234  }
235  }
236 }
237 
238 
240 {
242  wxString m_new_name;
244 
245 public:
252  static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates )
253  {
254  typedef std::map<wxString, RESCUE_CASE_CANDIDATE> candidate_map_t;
255  candidate_map_t candidate_map;
256 
257  // Remember the list of components is sorted by part name.
258  // So a search in libraries is made only once by group
259  LIB_ALIAS* case_sensitive_match = nullptr;
260  std::vector<LIB_ALIAS*> case_insensitive_matches;
261 
262  wxString last_part_name;
263 
264  for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) )
265  {
266  wxString part_name( FROM_UTF8( each_component->GetLibId().GetLibItemName() ) );
267 
268  if( last_part_name != part_name )
269  {
270  // A new part name is found (a new group starts here).
271  // Search the symbol names candidates only once for this group:
272  last_part_name = part_name;
273  case_insensitive_matches.clear();
274 
275  LIB_ID id( wxEmptyString, part_name );
276 
277  case_sensitive_match = aRescuer.GetLibs()->FindLibraryAlias( id );
278 
279  if( !case_sensitive_match )
280  // the case sensitive match failed. Try a case insensitive match
281  aRescuer.GetLibs()->FindLibraryNearEntries( case_insensitive_matches, part_name );
282  }
283 
284  if( case_sensitive_match || !( case_insensitive_matches.size() ) )
285  continue;
286 
287  RESCUE_CASE_CANDIDATE candidate(
288  part_name, case_insensitive_matches[0]->GetName(),
289  case_insensitive_matches[0]->GetPart() );
290 
291  candidate_map[part_name] = candidate;
292  }
293 
294  // Now, dump the map into aCandidates
295  for( const candidate_map_t::value_type& each_pair : candidate_map )
296  {
297  aCandidates.push_back( new RESCUE_CASE_CANDIDATE( each_pair.second ) );
298  }
299  }
300 
307  RESCUE_CASE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName,
308  LIB_PART* aLibCandidate )
309  : m_requested_name( aRequestedName ),
310  m_new_name( aNewName ),
311  m_lib_candidate( aLibCandidate ) { }
312 
313  RESCUE_CASE_CANDIDATE() { m_lib_candidate = NULL; }
314 
315  virtual wxString GetRequestedName() const override { return m_requested_name; }
316  virtual wxString GetNewName() const override { return m_new_name; }
317  virtual LIB_PART* GetLibCandidate() const override { return m_lib_candidate; }
318  virtual wxString GetActionDescription() const override
319  {
320  wxString action;
321  action.Printf( _( "Rename to %s" ), m_new_name );
322  return action;
323  }
324 
325  virtual bool PerformAction( RESCUER* aRescuer ) override
326  {
327  for( SCH_COMPONENT* each_component : *aRescuer->GetComponents() )
328  {
329  if( each_component->GetLibId().GetLibItemName() != TO_UTF8( m_requested_name ) )
330  continue;
331 
332  LIB_ID libId;
333 
334  libId.SetLibItemName( TO_UTF8( m_new_name ), false );
335  each_component->SetLibId( libId );
336  each_component->ClearFlags();
337  aRescuer->LogRescue( each_component, m_requested_name, m_new_name );
338  }
339  return true;
340  }
341 };
342 
343 
345 {
347  wxString m_new_name;
350 
351  static std::unique_ptr<PART_LIB> m_rescue_lib;
352 
353 public:
360  static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates )
361  {
362  typedef std::map<wxString, RESCUE_CACHE_CANDIDATE> candidate_map_t;
363  candidate_map_t candidate_map;
364 
365  // Remember the list of components is sorted by part name.
366  // So a search in libraries is made only once by group
367  LIB_PART* cache_match = nullptr;
368  LIB_PART* lib_match = nullptr;
369  wxString old_part_name;
370 
371  wxString part_name_suffix = aRescuer.GetPartNameSuffix();
372 
373  for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) )
374  {
375  wxString part_name( FROM_UTF8( each_component->GetLibId().GetLibItemName() ) );
376 
377  if( old_part_name != part_name )
378  {
379  // A new part name is found (a new group starts here).
380  // Search the symbol names candidates only once for this group:
381  old_part_name = part_name;
382  cache_match = find_component( part_name, aRescuer.GetLibs(), /* aCached */ true );
383  LIB_ID id( wxEmptyString, part_name );
384  lib_match = aRescuer.GetLibs()->FindLibPart( id );
385 
386  // Test whether there is a conflict
387  if( !cache_match || !lib_match )
388  continue;
389 
390  if( !cache_match->PinsConflictWith( *lib_match, /* aTestNums */ true,
391  /* aTestNames */ true, /* aTestType */ true, /* aTestOrientation */ true,
392  /* aTestLength */ false ))
393  continue;
394 
395  RESCUE_CACHE_CANDIDATE candidate(
396  part_name, part_name + part_name_suffix,
397  cache_match, lib_match );
398 
399  candidate_map[part_name] = candidate;
400  }
401  }
402 
403  // Now, dump the map into aCandidates
404  for( const candidate_map_t::value_type& each_pair : candidate_map )
405  {
406  aCandidates.push_back( new RESCUE_CACHE_CANDIDATE( each_pair.second ) );
407  }
408  }
409 
417  RESCUE_CACHE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName,
418  LIB_PART* aCacheCandidate, LIB_PART* aLibCandidate )
419  : m_requested_name( aRequestedName ),
420  m_new_name( aNewName ),
421  m_cache_candidate( aCacheCandidate ),
422  m_lib_candidate( aLibCandidate ) { }
423 
425  : m_cache_candidate( NULL ), m_lib_candidate( NULL ) {}
426 
427  virtual wxString GetRequestedName() const override { return m_requested_name; }
428  virtual wxString GetNewName() const override { return m_new_name; }
429  virtual LIB_PART* GetCacheCandidate() const override { return m_cache_candidate; }
430  virtual LIB_PART* GetLibCandidate() const override { return m_lib_candidate; }
431  virtual wxString GetActionDescription() const override
432  {
433  wxString action;
434  action.Printf( _( "Rescue %s as %s" ), m_requested_name, m_new_name );
435  return action;
436  }
437 
442  static void OpenRescueLibrary()
443  {
444  wxFileName fn( g_RootSheet->GetScreen()->GetFileName() );
445  fn.SetName( fn.GetName() + wxT( "-rescue" ) );
446  fn.SetExt( SchematicLibraryFileExtension );
447 
448  std::unique_ptr<PART_LIB> rescue_lib( new PART_LIB( LIBRARY_TYPE_EESCHEMA,
449  fn.GetFullPath() ) );
450 
451  m_rescue_lib = std::move( rescue_lib );
452  m_rescue_lib->EnableBuffering();
453  }
454 
455  virtual bool PerformAction( RESCUER* aRescuer ) override
456  {
457  LIB_PART new_part( *m_cache_candidate, m_rescue_lib.get() );
458  new_part.SetName( m_new_name );
459  new_part.RemoveAllAliases();
460  RESCUE_CACHE_CANDIDATE::m_rescue_lib.get()->AddPart( &new_part );
461 
462  for( SCH_COMPONENT* each_component : *aRescuer->GetComponents() )
463  {
464  if( each_component->GetLibId().GetLibItemName() != TO_UTF8( m_requested_name ) )
465  continue;
466 
467  LIB_ID libId;
468 
469  libId.SetLibItemName( TO_UTF8( m_new_name ), false );
470  each_component->SetLibId( libId );
471  each_component->ClearFlags();
472  aRescuer->LogRescue( each_component, m_requested_name, m_new_name );
473  }
474  return true;
475  }
476 
483  static bool WriteRescueLibrary( SCH_EDIT_FRAME *aEditFrame, PROJECT* aProject )
484  {
485  if( !save_library( m_rescue_lib.get(), aEditFrame ) )
486  return false;
487  return insert_library( aProject, m_rescue_lib.get(), 0 );
488  }
489 };
490 
491 
492 std::unique_ptr<PART_LIB> RESCUE_CACHE_CANDIDATE::m_rescue_lib;
493 
494 
495 RESCUER::RESCUER( SCH_EDIT_FRAME& aEditFrame, PROJECT& aProject )
496 {
498  m_prj = &aProject;
499  m_libs = m_prj->SchLibs();
500  m_edit_frame = &aEditFrame;
501 }
502 
503 
505 {
508 }
509 
510 
511 void RESCUER::InvokeDialog( bool aAskShowAgain )
512 {
513  InvokeDialogRescueEach( m_edit_frame, *this, aAskShowAgain );
514 }
515 
516 
517 void RESCUER::LogRescue( SCH_COMPONENT *aComponent, const wxString &aOldName,
518  const wxString &aNewName )
519 {
520  RESCUE_LOG logitem;
521  logitem.component = aComponent;
522  logitem.old_name = aOldName;
523  logitem.new_name = aNewName;
524  m_rescue_log.push_back( logitem );
525 }
526 
527 
529 {
530  for( RESCUE_CANDIDATE* each_candidate : m_chosen_candidates )
531  {
532  if( ! each_candidate->PerformAction( this ) )
533  return false;
534  }
535  return true;
536 }
537 
538 
540 {
541  for( RESCUE_LOG& each_logitem : m_rescue_log )
542  {
543  LIB_ID libId;
544 
545  libId.SetLibItemName( TO_UTF8( each_logitem.old_name ), false );
546  each_logitem.component->SetLibId( libId );
547  each_logitem.component->ClearFlags();
548  }
549 }
550 
551 
553 {
554  wxString suffix = wxT( "-RESCUE-" );
555  wxString pname = GetPrj()->GetProjectName();
556  for( size_t i = 0; i < pname.Len(); ++i )
557  {
558  if( isspace( pname[i].GetValue() ) )
559  suffix.Append( '_' );
560  else
561  suffix.Append( pname[i] );
562  }
563 
564  return suffix;
565 }
566 
567 
568 bool SCH_EDIT_FRAME::RescueProject( bool aRunningOnDemand )
569 {
570  RESCUER rescuer( *this, Prj() );
571 
572  rescuer.FindCandidates();
573 
574  if( ! rescuer.GetCandidateCount() )
575  {
576  if( aRunningOnDemand )
577  {
578  wxMessageDialog dlg( this, _( "This project has nothing to rescue." ),
579  _( "Project Rescue Helper" ) );
580  dlg.ShowModal();
581  }
582  return true;
583  }
584 
585  rescuer.RemoveDuplicates();
586 
587  rescuer.InvokeDialog( !aRunningOnDemand );
588 
589  // If no components were rescued, let the user know what's going on. He might
590  // have clicked cancel by mistake, and should have some indication of that.
591  if( !rescuer.GetChosenCandidateCount() )
592  {
593  wxMessageDialog dlg( this, _( "No symbols were rescued." ),
594  _( "Project Rescue Helper" ) );
595  dlg.ShowModal();
596 
597  // Set the modified flag even on Cancel. Many users seem to instinctively want to Save at
598  // this point, due to the reloading of the symbols, so we'll make the save button active.
599  OnModify();
600  return true;
601  }
602 
604 
605  if( !rescuer.DoRescues() )
606  {
607  rescuer.UndoRescues();
608  return false;
609  }
610 
612 
614 
615  // Clean up wire ends
617  m_canvas->Refresh( true );
618  OnModify();
619 
620  return true;
621 }
Definition of the SCH_SHEET class for Eeschema.
RESCUER(SCH_EDIT_FRAME &aEditFrame, PROJECT &aProject)
bool PinsConflictWith(LIB_PART &aOtherPart, bool aTestNums, bool aTestNames, bool aTestType, bool aTestOrientation, bool aTestLength)
Function PinsConflictWith returns true if this part's pins do not match another part's pins...
virtual LIB_PART * GetLibCandidate() const override
Function GetLibCandidate Get the part the would be loaded from the libraries, if possible, or else NULL.
Part library alias object definition.
virtual wxString GetRequestedName() const override
Function GetRequestedName Get the name that was originally requested in the schematic.
SCH_SCREEN * GetNext()
size_t GetChosenCandidateCount()
Function GetChosenCandidateCount.
virtual wxString GetActionDescription() const override
Function GetActionDescription Get a description of the action proposed, for displaying in the UI...
static void LibNamesAndPaths(PROJECT *aProject, bool doSave, wxString *aPaths, wxArrayString *aNames=NULL)
Function LibNamesAndPaths either saves or loads the names of the currently configured part libraries ...
Class PROJECT holds project specific data.
Definition: project.h:52
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
void InvokeDialog(bool aAskShowAgain)
Function InvokeDialog Display a dialog to allow the user to select rescues.
PROJECT * GetPrj()
Function GetPrj.
bool RescueProject(bool aRunningOnDemand)
Function RescueProject performs rescue operations to recover old projects from before certain changes...
virtual wxString GetNewName() const override
Function GetNewName Get the name we're proposing changing it to.
void LoadAllLibraries(PROJECT *aProject, bool aShowProgress=true)
Function LoadAllLibraries loads all of the project's libraries into this container, which should be cleared before calling it.
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Definition: draw_panel.cpp:326
void Save(bool aSaveDocFile=true)
This file is part of the common library.
virtual wxString GetRequestedName() const override
Function GetRequestedName Get the name that was originally requested in the schematic.
void OnModify()
Function OnModify Must be called after a schematic change in order to set the "modify" flag of the cu...
Definition: schframe.cpp:762
wxString GetFullFileName()
Function GetFullFileName returns the full file library name with path and extension.
const wxString & GetFileName() const
static bool sort_by_libid(const SCH_COMPONENT *ref, SCH_COMPONENT *cmp)
Function get_components Fills a vector with all of the project's components, to ease iterating over t...
static void FindRescues(RESCUER &aRescuer, boost::ptr_vector< RESCUE_CANDIDATE > &aCandidates)
Function FindRescues Grab all possible RESCUE_CASE_CANDIDATES into a vector.
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...
static void get_components(std::vector< SCH_COMPONENT * > &aComponents)
Schematic editor (Eeschema) main window.
Definition: schframe.h:117
PART_LIBS * m_libs
Class LIB_ID.
Definition: lib_id.h:56
static LIB_PART * find_component(wxString aName, PART_LIBS *aLibs, bool aCached)
Function find_component Search the libraries for the first component with a given name...
virtual bool PerformAction(RESCUER *aRescuer) override
Function PerformAction Perform the actual rescue action.
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:286
LIB_ALIAS * FindLibraryAlias(const LIB_ID &aLibId, const wxString &aLibraryName=wxEmptyString)
Function FindLibraryEntry searches all libraries in the list for an entry.
SCH_ITEM * Next() const
SCH_COMPONENT * component
static void FindRescues(RESCUER &aRescuer, boost::ptr_vector< RESCUE_CANDIDATE > &aCandidates)
Function FindRescues Grab all possible RESCUE_CACHE_CANDIDATEs into a vector.
VTBL_ENTRY void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:208
boost::ptr_vector< RESCUE_CANDIDATE > m_all_candidates
static bool WriteRescueLibrary(SCH_EDIT_FRAME *aEditFrame, PROJECT *aProject)
Function WriteRescueLibrary Writes out the rescue library.
void RemoveDuplicates()
Function RemoveDuplicates Filter out duplicately named rescue candidates.
SCH_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Definition: schframe.cpp:521
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
virtual wxString GetActionDescription() const override
Function GetActionDescription Get a description of the action proposed, for displaying in the UI...
a helper to handle the real device context used in KiCad
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:54
bool SchematicCleanUp()
Function SchematicCleanUp performs routine schematic cleaning including breaking wire and buses and d...
Definition: sch_screen.cpp:426
void UpdateSymbolLinks()
size_t GetCandidateCount()
Function GetCandidateCount.
Class LIB_PART defines a library part object.
The common library.
PROJECT * m_prj
std::pair< SCH_COMPONENT *, wxString > COMPONENT_NAME_PAIR
LIB_PART * FindLibPart(const LIB_ID &aLibId, const wxString &aLibraryName=wxEmptyString)
Function FindLibPart searches all libraries in the list for a part.
std::vector< SCH_COMPONENT * > m_components
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Function SetLibItemName.
Definition: lib_id.cpp:232
const wxString SchematicLibraryFileExtension
Class PART_LIBS is a collection of PART_LIBs.
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:92
wxString GetPartNameSuffix()
Function GetPartNameSuffix Return the suffix to add to rescued parts.
virtual LIB_PART * GetCacheCandidate() const override
Function GetCacheCandidate Get the part that can be loaded from the project cache, if possible, or else NULL.
Definition the SCH_COMPONENT class for Eeschema.
std::vector< RESCUE_CANDIDATE * > m_chosen_candidates
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's report and his call site information: CPP source file, function, and line number.
Definition: ki_exception.h:94
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
virtual wxString GetNewName() const override
Function GetNewName Get the name we're proposing changing it to.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
bool DoRescues()
Function DoRescues Perform all chosen rescue actions, logging them to be undone if necessary...
RESCUE_CACHE_CANDIDATE(const wxString &aRequestedName, const wxString &aNewName, LIB_PART *aCacheCandidate, LIB_PART *aLibCandidate)
Constructor RESCUE_CACHE_CANDIDATE.
static std::unique_ptr< PART_LIB > m_rescue_lib
void FindCandidates()
Function FindCandidates Populate the RESCUER with all possible candidates.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
const LIB_ID & GetLibId() const
std::vector< SCH_COMPONENT * > * GetComponents()
Function GetComponents.
std::vector< RESCUE_LOG > m_rescue_log
SCH_EDIT_FRAME * m_edit_frame
void LogRescue(SCH_COMPONENT *aComponent, const wxString &aOldName, const wxString &aNewName)
Function LogRescue Used by individual RESCUE_CANDIDATEs to log a rescue for undoing.
virtual void SetName(const wxString &aName)
wxString old_name
virtual LIB_PART * GetLibCandidate() const override
Function GetLibCandidate Get the part the would be loaded from the libraries, if possible, or else NULL.
SCH_SCREEN * GetFirst()
PART_LIBS * GetLibs()
Function GetLibs.
Definition for part library class.
virtual bool PerformAction(RESCUER *aRescuer) override
Function PerformAction Perform the actual rescue action.
void UndoRescues()
Function UndoRescues Reverse the effects of all rescues on the project.
static bool insert_library(PROJECT *aProject, PART_LIB *aLibrary, size_t aIndex)
Function insert_library inserts a library into the project and refreshes libraries.
static void OpenRescueLibrary()
Function OpenRescueLibrary Creates the new rescue library.
static bool save_library(PART_LIB *aLibrary, SCH_EDIT_FRAME *aEditFrame)
Function save_library writes the library out to disk.
Class PART_LIB is used to load, save, search, and otherwise manipulate part library files...
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:69
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
wxString new_name
void FindLibraryNearEntries(std::vector< LIB_ALIAS * > &aCandidates, const wxString &aEntryName, const wxString &aLibraryName=wxEmptyString)
Function FindLibraryNearEntries Searches all libraries in the list for an entry, using a case insensi...
Class SCH_SCREENS is a container class that holds multiple SCH_SCREENs in a hierarchy.
VTBL_ENTRY const wxString GetProjectName() const
Function GetProjectName returns the short name of the project.
Definition: project.cpp:108
RESCUE_CASE_CANDIDATE(const wxString &aRequestedName, const wxString &aNewName, LIB_PART *aLibCandidate)
Constructor RESCUE_CANDIDATE.