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 Chris Pavlina <pavlina.chris@gmail.com>
5  * Copyright (C) 2015-2017 KiCad Developers, see change_log.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <class_drawpanel.h>
26 #include <class_library.h>
27 #include <confirm.h>
28 #include <invoke_sch_dialog.h>
29 #include <kicad_device_context.h>
30 #include <project_rescue.h>
31 #include <sch_component.h>
32 #include <sch_sheet.h>
33 #include <schframe.h>
35 
36 #include <cctype>
37 #include <map>
38 
39 
40 typedef std::pair<SCH_COMPONENT*, wxString> COMPONENT_NAME_PAIR;
41 
42 
50 static bool save_library( PART_LIB* aLibrary, SCH_EDIT_FRAME* aEditFrame )
51 {
52  try
53  {
54  aLibrary->Save( false );
55  }
56  catch( ... /* IO_ERROR ioe */ )
57  {
58  wxString msg = wxString::Format( _( "Failed to create component library file '%s'" ),
59  GetChars( aLibrary->GetFullFileName() )
60  );
61  DisplayError( aEditFrame, msg );
62  return false;
63  }
64 
65  return true;
66 }
67 
68 
79 static bool insert_library( PROJECT *aProject, PART_LIB *aLibrary, size_t aIndex )
80 {
81  wxArrayString libNames;
82  wxString libPaths;
83 
84  wxString libName = aLibrary->GetName();
85  PART_LIBS *libs = dynamic_cast<PART_LIBS*>( aProject->GetElem( PROJECT::ELEM_SCH_PART_LIBS ) );
86  if( !libs )
87  {
88  libs = new PART_LIBS();
89  aProject->SetElem( PROJECT::ELEM_SCH_PART_LIBS, libs );
90  }
91 
92  try
93  {
94  PART_LIBS::LibNamesAndPaths( aProject, false, &libPaths, &libNames );
95 
96  // Make sure the library is not already in the list
97  while( libNames.Index( libName ) != wxNOT_FOUND )
98  libNames.Remove( libName );
99 
100  // Add the library to the list and save
101  libNames.Insert( libName, aIndex );
102  PART_LIBS::LibNamesAndPaths( aProject, true, &libPaths, &libNames );
103  }
104  catch( const IO_ERROR& )
105  {
106  // Could not get or save the current libraries.
107  return false;
108  }
109 
110  // Save the old libraries in case there is a problem after clear(). We'll
111  // put them back in.
112  boost::ptr_vector<PART_LIB> libsSave;
113  libsSave.transfer( libsSave.end(), libs->begin(), libs->end(), *libs );
114 
115  aProject->SetElem( PROJECT::ELEM_SCH_PART_LIBS, NULL );
116 
117  libs = new PART_LIBS();
118  try
119  {
120  libs->LoadAllLibraries( aProject );
121  }
122  catch( const PARSE_ERROR& )
123  {
124  // Some libraries were not found. There's no point in showing the error,
125  // because it was already shown. Just don't do anything.
126  }
127  catch( const IO_ERROR& )
128  {
129  // Restore the old list
130  libs->clear();
131  libs->transfer( libs->end(), libsSave.begin(), libsSave.end(), libsSave );
132  return false;
133  }
134  aProject->SetElem( PROJECT::ELEM_SCH_PART_LIBS, libs );
135 
136  // Update the schematic symbol library links since the library list has changed.
137  SCH_SCREENS schematic;
138 
139  schematic.UpdateSymbolLinks();
140 
141  return true;
142 }
143 
144 
145 // Helper sort function, used in get_components, to sort a component list by lib_id
146 static bool sort_by_libid( const SCH_COMPONENT* ref, SCH_COMPONENT* cmp )
147 {
148  return ref->GetLibId() < cmp->GetLibId();
149 }
150 
160 static void get_components( std::vector<SCH_COMPONENT*>& aComponents )
161 {
162  SCH_SCREENS screens;
163 
164  // Get the full list
165  for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
166  {
167  for( SCH_ITEM* item = screen->GetDrawItems(); item; item = item->Next() )
168  {
169  if( item->Type() != SCH_COMPONENT_T )
170  continue;
171  SCH_COMPONENT* component = static_cast<SCH_COMPONENT*>( item );
172  aComponents.push_back( component );
173  }
174  }
175 
176  // sort aComponents by lib part. Components will be grouped by same lib part.
177  std::sort( aComponents.begin(), aComponents.end(), sort_by_libid );
178 }
179 
180 
189 static LIB_PART* find_component( wxString aName, PART_LIBS* aLibs, bool aCached )
190 {
191  LIB_PART *part = NULL;
192 
193  for( PART_LIB& each_lib : *aLibs )
194  {
195  if( aCached && !each_lib.IsCache() )
196  continue;
197 
198  if( !aCached && each_lib.IsCache() )
199  continue;
200 
201  part = each_lib.FindPart( aName );
202  if( part )
203  break;
204  }
205 
206  return part;
207 }
208 
209 
211 {
212  std::vector<wxString> names_seen;
213 
214  for( boost::ptr_vector<RESCUE_CANDIDATE>::iterator it = m_all_candidates.begin();
215  it != m_all_candidates.end(); )
216  {
217  bool seen_already = false;
218  for( wxString& name_seen : names_seen )
219  {
220  if( name_seen == it->GetRequestedName() )
221  {
222  seen_already = true;
223  break;
224  }
225  }
226 
227  if( seen_already )
228  {
229  it = m_all_candidates.erase( it );
230  }
231  else
232  {
233  names_seen.push_back( it->GetRequestedName() );
234  ++it;
235  }
236  }
237 }
238 
239 
241 {
243  wxString m_new_name;
245 
246 public:
253  static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates )
254  {
255  typedef std::map<wxString, RESCUE_CASE_CANDIDATE> candidate_map_t;
256  candidate_map_t candidate_map;
257 
258  // Remember the list of components is sorted by part name.
259  // So a search in libraries is made only once by group
260  LIB_ALIAS* case_sensitive_match = nullptr;
261  std::vector<LIB_ALIAS*> case_insensitive_matches;
262 
263  wxString last_part_name;
264 
265  for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) )
266  {
267  wxString part_name = each_component->GetLibId().GetLibItemName();
268 
269  if( last_part_name != part_name )
270  {
271  // A new part name is found (a new group starts here).
272  // Search the symbol names candidates only once for this group:
273  last_part_name = part_name;
274  case_insensitive_matches.clear();
275 
276  LIB_ID id( wxEmptyString, part_name );
277 
278  case_sensitive_match = aRescuer.GetLibs()->FindLibraryAlias( id );
279 
280  if( !case_sensitive_match )
281  // the case sensitive match failed. Try a case insensitive match
282  aRescuer.GetLibs()->FindLibraryNearEntries( case_insensitive_matches, part_name );
283  }
284 
285  if( case_sensitive_match || !( case_insensitive_matches.size() ) )
286  continue;
287 
288  RESCUE_CASE_CANDIDATE candidate(
289  part_name, case_insensitive_matches[0]->GetName(),
290  case_insensitive_matches[0]->GetPart() );
291 
292  candidate_map[part_name] = candidate;
293  }
294 
295  // Now, dump the map into aCandidates
296  for( const candidate_map_t::value_type& each_pair : candidate_map )
297  {
298  aCandidates.push_back( new RESCUE_CASE_CANDIDATE( each_pair.second ) );
299  }
300  }
301 
308  RESCUE_CASE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName,
309  LIB_PART* aLibCandidate )
310  : m_requested_name( aRequestedName ),
311  m_new_name( aNewName ),
312  m_lib_candidate( aLibCandidate ) { }
313 
314  RESCUE_CASE_CANDIDATE() { m_lib_candidate = NULL; }
315 
316  virtual wxString GetRequestedName() const override { return m_requested_name; }
317  virtual wxString GetNewName() const override { return m_new_name; }
318  virtual LIB_PART* GetLibCandidate() const override { return m_lib_candidate; }
319  virtual wxString GetActionDescription() const override
320  {
321  wxString action;
322  action.Printf( _( "Rename to %s" ), m_new_name );
323  return action;
324  }
325 
326  virtual bool PerformAction( RESCUER* aRescuer ) override
327  {
328  for( SCH_COMPONENT* each_component : *aRescuer->GetComponents() )
329  {
330  if( each_component->GetLibId().GetLibItemName() != UTF8( m_requested_name ) )
331  continue;
332 
333  LIB_ID libId;
334 
335  libId.SetLibItemName( m_new_name, false );
336  each_component->SetLibId( libId );
337  each_component->ClearFlags();
338  aRescuer->LogRescue( each_component, m_requested_name, m_new_name );
339  }
340  return true;
341  }
342 };
343 
344 
346 {
348  wxString m_new_name;
351 
352  static std::unique_ptr<PART_LIB> m_rescue_lib;
353 
354 public:
361  static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates )
362  {
363  typedef std::map<wxString, RESCUE_CACHE_CANDIDATE> candidate_map_t;
364  candidate_map_t candidate_map;
365 
366  // Remember the list of components is sorted by part name.
367  // So a search in libraries is made only once by group
368  LIB_PART* cache_match = nullptr;
369  LIB_PART* lib_match = nullptr;
370  wxString old_part_name;
371 
372  wxString part_name_suffix = aRescuer.GetPartNameSuffix();
373 
374  for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) )
375  {
376  wxString part_name = each_component->GetLibId().GetLibItemName();
377 
378  if( old_part_name != part_name )
379  {
380  // A new part name is found (a new group starts here).
381  // Search the symbol names candidates only once for this group:
382  old_part_name = part_name;
383  cache_match = find_component( part_name, aRescuer.GetLibs(), /* aCached */ true );
384  LIB_ID id( wxEmptyString, part_name );
385  lib_match = aRescuer.GetLibs()->FindLibPart( id );
386 
387  // Test whether there is a conflict
388  if( !cache_match || !lib_match )
389  continue;
390 
391  if( !cache_match->PinsConflictWith( *lib_match, /* aTestNums */ true,
392  /* aTestNames */ true, /* aTestType */ true, /* aTestOrientation */ true,
393  /* aTestLength */ false ))
394  continue;
395 
396  RESCUE_CACHE_CANDIDATE candidate(
397  part_name, part_name + part_name_suffix,
398  cache_match, lib_match );
399 
400  candidate_map[part_name] = candidate;
401  }
402  }
403 
404  // Now, dump the map into aCandidates
405  for( const candidate_map_t::value_type& each_pair : candidate_map )
406  {
407  aCandidates.push_back( new RESCUE_CACHE_CANDIDATE( each_pair.second ) );
408  }
409  }
410 
418  RESCUE_CACHE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName,
419  LIB_PART* aCacheCandidate, LIB_PART* aLibCandidate )
420  : m_requested_name( aRequestedName ),
421  m_new_name( aNewName ),
422  m_cache_candidate( aCacheCandidate ),
423  m_lib_candidate( aLibCandidate ) { }
424 
426  : m_cache_candidate( NULL ), m_lib_candidate( NULL ) {}
427 
428  virtual wxString GetRequestedName() const override { return m_requested_name; }
429  virtual wxString GetNewName() const override { return m_new_name; }
430  virtual LIB_PART* GetCacheCandidate() const override { return m_cache_candidate; }
431  virtual LIB_PART* GetLibCandidate() const override { return m_lib_candidate; }
432  virtual wxString GetActionDescription() const override
433  {
434  wxString action;
435  action.Printf( _( "Rescue %s as %s" ), m_requested_name, m_new_name );
436  return action;
437  }
438 
443  static void OpenRescueLibrary()
444  {
445  wxFileName fn( g_RootSheet->GetScreen()->GetFileName() );
446  fn.SetName( fn.GetName() + wxT( "-rescue" ) );
447  fn.SetExt( SchematicLibraryFileExtension );
448 
449  std::unique_ptr<PART_LIB> rescue_lib( new PART_LIB( LIBRARY_TYPE_EESCHEMA,
450  fn.GetFullPath() ) );
451 
452  m_rescue_lib = std::move( rescue_lib );
453  m_rescue_lib->EnableBuffering();
454  }
455 
456  virtual bool PerformAction( RESCUER* aRescuer ) override
457  {
458  LIB_PART new_part( *m_cache_candidate, m_rescue_lib.get() );
459  new_part.SetName( m_new_name );
460  new_part.RemoveAllAliases();
461  RESCUE_CACHE_CANDIDATE::m_rescue_lib.get()->AddPart( &new_part );
462 
463  for( SCH_COMPONENT* each_component : *aRescuer->GetComponents() )
464  {
465  if( each_component->GetLibId().GetLibItemName() != UTF8( m_requested_name ) )
466  continue;
467 
468  LIB_ID libId;
469 
470  libId.SetLibItemName( m_new_name, false );
471  each_component->SetLibId( libId );
472  each_component->ClearFlags();
473  aRescuer->LogRescue( each_component, m_requested_name, m_new_name );
474  }
475  return true;
476  }
477 
484  static bool WriteRescueLibrary( SCH_EDIT_FRAME *aEditFrame, PROJECT* aProject )
485  {
486  if( !save_library( m_rescue_lib.get(), aEditFrame ) )
487  return false;
488  return insert_library( aProject, m_rescue_lib.get(), 0 );
489  }
490 };
491 
492 
493 std::unique_ptr<PART_LIB> RESCUE_CACHE_CANDIDATE::m_rescue_lib;
494 
495 
496 RESCUER::RESCUER( SCH_EDIT_FRAME& aEditFrame, PROJECT& aProject )
497 {
499  m_prj = &aProject;
500  m_libs = m_prj->SchLibs();
501  m_edit_frame = &aEditFrame;
502 }
503 
504 
506 {
509 }
510 
511 
512 void RESCUER::InvokeDialog( bool aAskShowAgain )
513 {
514  InvokeDialogRescueEach( m_edit_frame, *this, aAskShowAgain );
515 }
516 
517 
518 void RESCUER::LogRescue( SCH_COMPONENT *aComponent, const wxString &aOldName,
519  const wxString &aNewName )
520 {
521  RESCUE_LOG logitem;
522  logitem.component = aComponent;
523  logitem.old_name = aOldName;
524  logitem.new_name = aNewName;
525  m_rescue_log.push_back( logitem );
526 }
527 
528 
530 {
531  for( RESCUE_CANDIDATE* each_candidate : m_chosen_candidates )
532  {
533  if( ! each_candidate->PerformAction( this ) )
534  return false;
535  }
536  return true;
537 }
538 
539 
541 {
542  for( RESCUE_LOG& each_logitem : m_rescue_log )
543  {
544  LIB_ID libId;
545 
546  libId.SetLibItemName( each_logitem.old_name, false );
547  each_logitem.component->SetLibId( libId );
548  each_logitem.component->ClearFlags();
549  }
550 }
551 
552 
554 {
555  wxString suffix = wxT( "-RESCUE-" );
556  wxString pname = GetPrj()->GetProjectName();
557  for( size_t i = 0; i < pname.Len(); ++i )
558  {
559  if( isspace( pname[i].GetValue() ) )
560  suffix.Append( '_' );
561  else
562  suffix.Append( pname[i] );
563  }
564 
565  return suffix;
566 }
567 
568 
569 bool SCH_EDIT_FRAME::RescueProject( bool aRunningOnDemand )
570 {
571  RESCUER rescuer( *this, Prj() );
572 
573  rescuer.FindCandidates();
574 
575  if( ! rescuer.GetCandidateCount() )
576  {
577  if( aRunningOnDemand )
578  {
579  wxMessageDialog dlg( this, _( "This project has nothing to rescue." ),
580  _( "Project Rescue Helper" ) );
581  dlg.ShowModal();
582  }
583  return true;
584  }
585 
586  rescuer.RemoveDuplicates();
587 
588  rescuer.InvokeDialog( !aRunningOnDemand );
589 
590  // If no components were rescued, let the user know what's going on. He might
591  // have clicked cancel by mistake, and should have some indication of that.
592  if( !rescuer.GetChosenCandidateCount() )
593  {
594  wxMessageDialog dlg( this, _( "No symbols were rescued." ),
595  _( "Project Rescue Helper" ) );
596  dlg.ShowModal();
597 
598  // Set the modified flag even on Cancel. Many users seem to instinctively want to Save at
599  // this point, due to the reloading of the symbols, so we'll make the save button active.
600  OnModify();
601  return true;
602  }
603 
605 
606  if( !rescuer.DoRescues() )
607  {
608  rescuer.UndoRescues();
609  return false;
610  }
611 
613 
615 
616  // Clean up wire ends
618  m_canvas->Refresh( true );
619  OnModify();
620 
621  return true;
622 }
Definition of the SCH_SHEET class for Eeschema.
RESCUER(SCH_EDIT_FRAME &aEditFrame, PROJECT &aProject)
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
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:56
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
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:325
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:770
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)
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)
Function get_components Fills a vector with all of the project's components, to ease iterating over t...
Schematic editor (Eeschema) main window.
Definition: schframe.h:117
PART_LIBS * m_libs
VTBL_ENTRY _ELEM * GetElem(ELEM_T aIndex)
Typically wrapped somewhere else in a more meaningful function wrapper.
Definition: project.cpp:196
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:529
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:55
bool SchematicCleanUp()
Function SchematicCleanUp performs routine schematic cleaning including breaking wire and buses and d...
Definition: sch_screen.cpp:426
void UpdateSymbolLinks()
initializes or reinitializes the weak reference to the LIB_PART for each SCH_COMPONENT found in the f...
size_t GetCandidateCount()
Function GetCandidateCount.
const wxString GetName() const
Return the file name without path or extension.
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:93
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:71
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.