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 
46 #include <class_libentry.h>
47 #include <sch_legacy_plugin.h>
48 #include <class_draw_panel_gal.h>
49 
50 
51 class LIB_PART;
52 class SCH_COMPONENT;
53 class RESCUER;
54 class SCH_EDIT_FRAME;
55 class SCH_LEGACY_PLUGIN;
56 class SCH_SHEET_PATH;
57 
58 
60 {
63 };
64 
65 
67 {
68 protected:
69  wxString m_requested_name;
70  wxString m_new_name;
72 
73 public:
74  virtual ~RESCUE_CANDIDATE() {}
75 
79  virtual wxString GetRequestedName() const { return m_requested_name; }
80 
84  virtual wxString GetNewName() const { return m_new_name; }
85 
90  virtual LIB_PART* GetCacheCandidate() const { return NULL; }
91 
96  virtual LIB_PART* GetLibCandidate() const { return m_lib_candidate; }
97 
101  virtual wxString GetActionDescription() const = 0;
102 
108  virtual bool PerformAction( RESCUER* aRescuer ) = 0;
109 };
110 
111 
113 {
114 public:
121  static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
122 
129  RESCUE_CASE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName,
130  LIB_PART* aLibCandidate );
131 
133 
134  virtual wxString GetActionDescription() const override;
135 
136  virtual bool PerformAction( RESCUER* aRescuer ) override;
137 };
138 
139 
141 {
143 
144 public:
151  static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
152 
160  RESCUE_CACHE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName,
161  LIB_PART* aCacheCandidate, LIB_PART* aLibCandidate );
162 
164 
165  virtual LIB_PART* GetCacheCandidate() const override { return m_cache_candidate; }
166 
167  virtual wxString GetActionDescription() const override;
168 
169  virtual bool PerformAction( RESCUER* aRescuer ) override;
170 };
171 
172 
174 {
178 
179 public:
186  static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
187 
195  RESCUE_SYMBOL_LIB_TABLE_CANDIDATE( const LIB_ID& aRequestedId, const LIB_ID& aNewId,
196  LIB_PART* aCacheCandidate, LIB_PART* aLibCandidate);
197 
199 
200  virtual LIB_PART* GetCacheCandidate() const override { return m_cache_candidate; }
201 
202  virtual wxString GetActionDescription() const override;
203 
204  virtual bool PerformAction( RESCUER* aRescuer ) override;
205 };
206 
207 
209 {
210 public:
212  wxString old_name;
213  wxString new_name;
214 };
215 
216 
217 class RESCUER
218 {
219 protected:
220  friend class DIALOG_RESCUE_EACH;
221 
222  std::vector<SCH_COMPONENT*> m_components;
226 
227  boost::ptr_vector<RESCUE_CANDIDATE> m_all_candidates;
228  std::vector<RESCUE_CANDIDATE*> m_chosen_candidates;
229 
230  std::vector<RESCUE_LOG> m_rescue_log;
231 
232 public:
233  RESCUER( PROJECT& aProject, SCH_SHEET_PATH* aCurrentSheet,
234  EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType );
235 
242  virtual bool WriteRescueLibrary( wxWindow *aParent ) = 0;
243 
244  virtual void OpenRescueLibrary() = 0;
245 
249  virtual void FindCandidates() = 0;
250 
251  virtual void AddPart( LIB_PART* aNewPart ) = 0;
252 
258  virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) = 0;
259 
263  void RemoveDuplicates();
264 
268  size_t GetCandidateCount() { return m_all_candidates.size(); }
269 
273  size_t GetChosenCandidateCount() { return m_chosen_candidates.size(); }
274 
278  std::vector<SCH_COMPONENT*>* GetComponents() { return &m_components; }
279 
283  PROJECT* GetPrj() { return m_prj; }
284 
288  void LogRescue( SCH_COMPONENT *aComponent, const wxString& aOldName,
289  const wxString& aNewName );
290 
296  bool DoRescues();
297 
301  void UndoRescues();
302 
303  static bool RescueProject( wxWindow* aParent, RESCUER& aRescuer, bool aRunningOnDemand );
304 };
305 
306 
307 class LEGACY_RESCUER : public RESCUER
308 {
309 private:
310  std::unique_ptr<PART_LIB> m_rescue_lib;
311 
312 public:
313  LEGACY_RESCUER( PROJECT& aProject, SCH_SHEET_PATH* aCurrentSheet,
314  EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType ) :
315  RESCUER( aProject, aCurrentSheet, aGalBackEndType )
316  {
317  }
318 
319  virtual void FindCandidates() override;
320 
321  virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) override;
322 
323  virtual void OpenRescueLibrary() override;
324 
325  virtual bool WriteRescueLibrary( wxWindow *aParent ) override;
326 
327  virtual void AddPart( LIB_PART* aNewPart ) override;
328 };
329 
330 
332 {
333 private:
335 
336  std::unique_ptr< PROPERTIES > m_properties;
337 
338 public:
339  SYMBOL_LIB_TABLE_RESCUER( PROJECT& aProject, SCH_SHEET_PATH* aCurrentSheet,
340  EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType );
341 
342  virtual void FindCandidates() override;
343 
344  virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) override;
345 
346  virtual void OpenRescueLibrary() override;
347 
348  virtual bool WriteRescueLibrary( wxWindow* aParent ) override;
349 
350  virtual void AddPart( LIB_PART* aNewPart ) override;
351 };
352 
353 #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 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.
Class PROJECT holds project specific data.
Definition: project.h:58
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
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
Class 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:497
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.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
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.