KiCad PCB EDA Suite
project_rescue.h
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-2019 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 #ifndef _LIB_CACHE_RESCUE_H_
26 #define _LIB_CACHE_RESCUE_H_
27 
28 /* This code handles the case where an old schematic was made before
29  * various changes were made, either to KiCad or to the libraries, and
30  * the project needs to be recovered. The function of note is a member
31  * of SCH_EDIT_FRAME, defined thus:
32  *
33  * bool SCH_EDIT_FRAME::RescueProject( bool aSilentIfNone );
34  *
35  * When this is called, a list of problematic components is compiled. If
36  * this list is empty, then the function displays a notification and returns
37  * (if aSilentIfNone is true, the notification is silenced).
38  */
39 
40 #include <vector>
41 #include <wx/string.h>
42 #include <boost/ptr_container/ptr_vector.hpp>
43 
44 #include <properties.h>
45 #include <class_libentry.h>
46 #include <sch_legacy_plugin.h>
47 #include <class_draw_panel_gal.h>
48 
49 
50 class LIB_PART;
51 class SCH_COMPONENT;
52 class RESCUER;
53 class SCH_EDIT_FRAME;
54 class SCH_LEGACY_PLUGIN;
55 class SCH_SHEET_PATH;
56 
57 
59 {
62 };
63 
64 
66 {
67 protected:
68  wxString m_requested_name;
69  wxString m_new_name;
71 
72 public:
73  virtual ~RESCUE_CANDIDATE() {}
74 
78  virtual wxString GetRequestedName() const { return m_requested_name; }
79 
83  virtual wxString GetNewName() const { return m_new_name; }
84 
89  virtual LIB_PART* GetCacheCandidate() const { return NULL; }
90 
95  virtual LIB_PART* GetLibCandidate() const { return m_lib_candidate; }
96 
100  virtual wxString GetActionDescription() const = 0;
101 
107  virtual bool PerformAction( RESCUER* aRescuer ) = 0;
108 };
109 
110 
112 {
113 public:
120  static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
121 
128  RESCUE_CASE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName,
129  LIB_PART* aLibCandidate );
130 
132 
133  virtual wxString GetActionDescription() const override;
134 
135  virtual bool PerformAction( RESCUER* aRescuer ) override;
136 };
137 
138 
140 {
142 
143 public:
150  static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
151 
159  RESCUE_CACHE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName,
160  LIB_PART* aCacheCandidate, LIB_PART* aLibCandidate );
161 
163 
164  virtual LIB_PART* GetCacheCandidate() const override { return m_cache_candidate; }
165 
166  virtual wxString GetActionDescription() const override;
167 
168  virtual bool PerformAction( RESCUER* aRescuer ) override;
169 };
170 
171 
173 {
177 
178 public:
185  static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
186 
194  RESCUE_SYMBOL_LIB_TABLE_CANDIDATE( const LIB_ID& aRequestedId, const LIB_ID& aNewId,
195  LIB_PART* aCacheCandidate, LIB_PART* aLibCandidate);
196 
198 
199  virtual LIB_PART* GetCacheCandidate() const override { return m_cache_candidate; }
200 
201  virtual wxString GetActionDescription() const override;
202 
203  virtual bool PerformAction( RESCUER* aRescuer ) override;
204 };
205 
206 
208 {
209 public:
211  wxString old_name;
212  wxString new_name;
213 };
214 
215 
216 class RESCUER
217 {
218 protected:
219  friend class DIALOG_RESCUE_EACH;
220 
221  std::vector<SCH_COMPONENT*> m_components;
225 
226  boost::ptr_vector<RESCUE_CANDIDATE> m_all_candidates;
227  std::vector<RESCUE_CANDIDATE*> m_chosen_candidates;
228 
229  std::vector<RESCUE_LOG> m_rescue_log;
230 
231 public:
232  RESCUER( PROJECT& aProject, SCH_SHEET_PATH* aCurrentSheet,
233  EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType );
234 
235  virtual ~RESCUER()
236  {
237  }
238 
245  virtual bool WriteRescueLibrary( wxWindow *aParent ) = 0;
246 
247  virtual void OpenRescueLibrary() = 0;
248 
252  virtual void FindCandidates() = 0;
253 
254  virtual void AddPart( LIB_PART* aNewPart ) = 0;
255 
261  virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) = 0;
262 
266  void RemoveDuplicates();
267 
271  size_t GetCandidateCount() { return m_all_candidates.size(); }
272 
276  size_t GetChosenCandidateCount() { return m_chosen_candidates.size(); }
277 
281  std::vector<SCH_COMPONENT*>* GetComponents() { return &m_components; }
282 
286  PROJECT* GetPrj() { return m_prj; }
287 
291  void LogRescue( SCH_COMPONENT *aComponent, const wxString& aOldName,
292  const wxString& aNewName );
293 
299  bool DoRescues();
300 
304  void UndoRescues();
305 
306  static bool RescueProject( wxWindow* aParent, RESCUER& aRescuer, bool aRunningOnDemand );
307 };
308 
309 
310 class LEGACY_RESCUER : public RESCUER
311 {
312 private:
313  std::unique_ptr<PART_LIB> m_rescue_lib;
314 
315 public:
316  LEGACY_RESCUER( PROJECT& aProject, SCH_SHEET_PATH* aCurrentSheet,
317  EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType ) :
318  RESCUER( aProject, aCurrentSheet, aGalBackEndType )
319  {
320  }
321 
322  virtual ~LEGACY_RESCUER()
323  {
324  }
325 
326  virtual void FindCandidates() override;
327 
328  virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) override;
329 
330  virtual void OpenRescueLibrary() override;
331 
332  virtual bool WriteRescueLibrary( wxWindow *aParent ) override;
333 
334  virtual void AddPart( LIB_PART* aNewPart ) override;
335 };
336 
337 
339 {
340 private:
342 
343  std::unique_ptr< PROPERTIES > m_properties;
344 
345 public:
346  SYMBOL_LIB_TABLE_RESCUER( PROJECT& aProject, SCH_SHEET_PATH* aCurrentSheet,
347  EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType );
348 
350  {
351  }
352 
353  virtual void FindCandidates() override;
354 
355  virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) override;
356 
357  virtual void OpenRescueLibrary() override;
358 
359  virtual bool WriteRescueLibrary( wxWindow* aParent ) override;
360 
361  virtual void AddPart( LIB_PART* aNewPart ) override;
362 };
363 
364 #endif // _LIB_CACHE_RESCUE_H_
virtual void InvokeDialog(wxWindow *aParent, bool aAskShowAgain) override
Display a dialog to allow the user to select rescues.
EDA_DRAW_PANEL_GAL::GAL_TYPE m_galBackEndType
virtual void FindCandidates() override
Populate the RESCUER with all possible candidates.
virtual bool WriteRescueLibrary(wxWindow *aParent)=0
Writes out the rescue library.
virtual ~RESCUER()
virtual wxString GetActionDescription() const override
Get a description of the action proposed, for displaying in the UI.
virtual void FindCandidates()=0
Populate the RESCUER with all possible candidates.
RESCUER(PROJECT &aProject, SCH_SHEET_PATH *aCurrentSheet, EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType)
size_t GetChosenCandidateCount()
Get the number of resuce candidates chosen by the user.
virtual LIB_PART * GetLibCandidate() const
Get the part the would be loaded from the libraries, if possible, or else NULL.
PROJECT holds project specific data.
Definition: project.h:59
PROJECT * GetPrj()
Return the #SCH_PROJECT object for access to the symbol libraries.
virtual wxString GetNewName() const
Get the name we're proposing changing it to.
virtual wxString GetActionDescription() const =0
Get a description of the action proposed, for displaying in the UI.
virtual wxString GetRequestedName() const
Get the name that was originally requested in the schematic.
virtual void OpenRescueLibrary() override
virtual void InvokeDialog(wxWindow *aParent, bool aAskShowAgain)=0
Display a dialog to allow the user to select rescues.
Schematic editor (Eeschema) main window.
virtual ~RESCUE_CANDIDATE()
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
LIB_PART * m_lib_candidate
SCH_COMPONENT * component
boost::ptr_vector< RESCUE_CANDIDATE > m_all_candidates
void RemoveDuplicates()
Filter out duplicately named rescue candidates.
static bool RescueProject(wxWindow *aParent, RESCUER &aRescuer, bool aRunningOnDemand)
SCH_SHEET_PATH * m_currentSheet
#define NULL
static void FindRescues(RESCUER &aRescuer, boost::ptr_vector< RESCUE_CANDIDATE > &aCandidates)
Grab all possible RESCUE_CACHE_CANDIDATE objectss into a vector.
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi
Class LIB_PIN definition.
virtual bool PerformAction(RESCUER *aRescuer) override
Perform the actual rescue action.
virtual wxString GetActionDescription() const override
Get a description of the action proposed, for displaying in the UI.
size_t GetCandidateCount()
Returen the number of rescue candidates found.
static void FindRescues(RESCUER &aRescuer, boost::ptr_vector< RESCUE_CANDIDATE > &aCandidates)
Grab all possible RESCUE_SYMBOL_LIB_TABLE_CANDIDATE objects into a vector.
virtual wxString GetActionDescription() const override
Get a description of the action proposed, for displaying in the UI.
std::unique_ptr< PROPERTIES > m_properties
Library plugin properties.
virtual LIB_PART * GetCacheCandidate() const
Get the part that can be loaded from the project cache, if possible, or else NULL.
RESCUE_TYPE
Define a library symbol object.
PROJECT * m_prj
std::vector< SCH_COMPONENT * > m_components
SCH_SHEET_PATH.
virtual void OpenRescueLibrary()=0
A SCH_PLUGIN derivation for loading schematic files created before the new s-expression file format.
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:516
virtual LIB_PART * GetCacheCandidate() const override
Get the part that can be loaded from the project cache, if possible, or else NULL.
std::vector< RESCUE_CANDIDATE * > m_chosen_candidates
virtual bool WriteRescueLibrary(wxWindow *aParent) override
Writes out the rescue library.
std::unique_ptr< PART_LIB > m_rescue_lib
virtual void OpenRescueLibrary() override
virtual LIB_PART * GetCacheCandidate() const override
Get the part that can be loaded from the project cache, if possible, or else NULL.
bool DoRescues()
Perform all chosen rescue actions, logging them to be undone if necessary.
virtual ~LEGACY_RESCUER()
SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:99
virtual void AddPart(LIB_PART *aNewPart)=0
virtual bool WriteRescueLibrary(wxWindow *aParent) override
Writes out the rescue library.
std::vector< SCH_COMPONENT * > * GetComponents()
Get the list of symbols that need rescued.
std::vector< RESCUE_LOG > m_rescue_log
void LogRescue(SCH_COMPONENT *aComponent, const wxString &aOldName, const wxString &aNewName)
Used by individual RESCUE_CANDIDATE objects to log a rescue for undoing.
wxString m_requested_name
virtual void InvokeDialog(wxWindow *aParent, bool aAskShowAgain) override
Display a dialog to allow the user to select rescues.
virtual bool PerformAction(RESCUER *aRescuer) override
Perform the actual rescue action.
virtual void AddPart(LIB_PART *aNewPart) override
wxString old_name
virtual bool PerformAction(RESCUER *aRescuer)=0
Perform the actual rescue action.
virtual bool PerformAction(RESCUER *aRescuer) override
Perform the actual rescue action.
static void FindRescues(RESCUER &aRescuer, boost::ptr_vector< RESCUE_CANDIDATE > &aCandidates)
Grab all possible RESCUE_CASE_CANDIDATE objects into a vector.
virtual void AddPart(LIB_PART *aNewPart) override
void UndoRescues()
Reverse the effects of all rescues on the project.
LEGACY_RESCUER(PROJECT &aProject, SCH_SHEET_PATH *aCurrentSheet, EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType)
SYMBOL_LIB_TABLE_RESCUER(PROJECT &aProject, SCH_SHEET_PATH *aCurrentSheet, EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType)
wxString new_name
virtual void FindCandidates() override
Populate the RESCUER with all possible candidates.