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-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 #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 
49 
50 class LIB_PART;
51 class SCH_COMPONENT;
52 class RESCUER;
53 class SCH_EDIT_FRAME;
54 class SCH_LEGACY_PLUGIN;
55 
56 
58 {
61 };
62 
63 
65 {
66 protected:
67  wxString m_requested_name;
68  wxString m_new_name;
70 
71 public:
72  virtual ~RESCUE_CANDIDATE() {}
73 
77  virtual wxString GetRequestedName() const { return m_requested_name; }
78 
82  virtual wxString GetNewName() const { return m_new_name; }
83 
88  virtual LIB_PART* GetCacheCandidate() const { return NULL; }
89 
94  virtual LIB_PART* GetLibCandidate() const { return m_lib_candidate; }
95 
99  virtual wxString GetActionDescription() const = 0;
100 
106  virtual bool PerformAction( RESCUER* aRescuer ) = 0;
107 };
108 
109 
111 {
112 public:
119  static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
120 
127  RESCUE_CASE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName,
128  LIB_PART* aLibCandidate );
129 
131 
132  virtual wxString GetActionDescription() const override;
133 
134  virtual bool PerformAction( RESCUER* aRescuer ) override;
135 };
136 
137 
139 {
141 
142 public:
149  static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
150 
158  RESCUE_CACHE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName,
159  LIB_PART* aCacheCandidate, LIB_PART* aLibCandidate );
160 
162 
163  virtual LIB_PART* GetCacheCandidate() const override { return m_cache_candidate; }
164 
165  virtual wxString GetActionDescription() const override;
166 
167  virtual bool PerformAction( RESCUER* aRescuer ) override;
168 };
169 
170 
172 {
176 
177 public:
184  static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
185 
193  RESCUE_SYMBOL_LIB_TABLE_CANDIDATE( const LIB_ID& aRequestedId, const LIB_ID& aNewId,
194  LIB_PART* aCacheCandidate, LIB_PART* aLibCandidate);
195 
197 
198  virtual LIB_PART* GetCacheCandidate() const override { return m_cache_candidate; }
199 
200  virtual wxString GetActionDescription() const override;
201 
202  virtual bool PerformAction( RESCUER* aRescuer ) override;
203 };
204 
205 
207 {
208 public:
210  wxString old_name;
211  wxString new_name;
212 };
213 
214 
215 class RESCUER
216 {
217 protected:
218  friend class DIALOG_RESCUE_EACH;
219 
220  std::vector<SCH_COMPONENT*> m_components;
223 
224  boost::ptr_vector<RESCUE_CANDIDATE> m_all_candidates;
225  std::vector<RESCUE_CANDIDATE*> m_chosen_candidates;
226 
227  std::vector<RESCUE_LOG> m_rescue_log;
228 
229 public:
230  RESCUER( SCH_EDIT_FRAME& aEditFrame, PROJECT& aProject );
231 
238  virtual bool WriteRescueLibrary( SCH_EDIT_FRAME *aEditFrame ) = 0;
239 
240  virtual void OpenRescueLibrary() = 0;
241 
245  virtual void FindCandidates() = 0;
246 
247  virtual void AddPart( LIB_PART* aNewPart ) = 0;
248 
254  virtual void InvokeDialog( bool aAskShowAgain ) = 0;
255 
256  SCH_EDIT_FRAME* GetFrame() { return m_edit_frame; }
257 
261  void RemoveDuplicates();
262 
266  size_t GetCandidateCount() { return m_all_candidates.size(); }
267 
271  size_t GetChosenCandidateCount() { return m_chosen_candidates.size(); }
272 
276  std::vector<SCH_COMPONENT*>* GetComponents() { return &m_components; }
277 
281  PROJECT* GetPrj() { return m_prj; }
282 
286  void LogRescue( SCH_COMPONENT *aComponent, const wxString& aOldName,
287  const wxString& aNewName );
288 
294  bool DoRescues();
295 
299  void UndoRescues();
300 };
301 
302 
303 class LEGACY_RESCUER : public RESCUER
304 {
305 private:
306  std::unique_ptr<PART_LIB> m_rescue_lib;
307 
308 public:
309  LEGACY_RESCUER( SCH_EDIT_FRAME& aEditFrame, PROJECT& aProject ) :
310  RESCUER( aEditFrame, aProject )
311  {
312  }
313 
314  virtual void FindCandidates() override;
315 
316  virtual void InvokeDialog( bool aAskShowAgain ) override;
317 
318  virtual void OpenRescueLibrary() override;
319 
320  virtual bool WriteRescueLibrary( SCH_EDIT_FRAME *aEditFrame ) override;
321 
322  virtual void AddPart( LIB_PART* aNewPart ) override;
323 };
324 
325 
327 {
328 private:
330 
331  std::unique_ptr< PROPERTIES > m_properties;
332 
333 public:
334  SYMBOL_LIB_TABLE_RESCUER( SCH_EDIT_FRAME& aEditFrame, PROJECT& aProject );
335 
336  virtual void FindCandidates() override;
337 
338  virtual void InvokeDialog( bool aAskShowAgain ) override;
339 
340  virtual void OpenRescueLibrary() override;
341 
342  virtual bool WriteRescueLibrary( SCH_EDIT_FRAME *aEditFrame ) override;
343 
344  virtual void AddPart( LIB_PART* aNewPart ) override;
345 };
346 
347 #endif // _LIB_CACHE_RESCUE_H_
virtual LIB_PART * GetLibCandidate() const
Get the part the would be loaded from the libraries, if possible, or else NULL.
size_t GetChosenCandidateCount()
Get the number of resuce candidates chosen by the user.
virtual LIB_PART * GetCacheCandidate() const
Get the part that can be loaded from the project cache, if possible, or else NULL.
Class PROJECT holds project specific data.
Definition: project.h:57
PROJECT * GetPrj()
Return the #SCH_PROJECT object for access to the symbol libraries.
virtual wxString GetActionDescription() const =0
Get a description of the action proposed, for displaying in the UI.
SCH_EDIT_FRAME * GetFrame()
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
LEGACY_RESCUER(SCH_EDIT_FRAME &aEditFrame, PROJECT &aProject)
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi
Class LIB_ITEM definition.
size_t GetCandidateCount()
Returen the number of rescue candidates found.
std::unique_ptr< PROPERTIES > m_properties
Library plugin properties.
RESCUE_TYPE
Define a library symbol object.
PROJECT * m_prj
std::vector< SCH_COMPONENT * > m_components
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:523
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
std::unique_ptr< PART_LIB > m_rescue_lib
virtual LIB_PART * GetCacheCandidate() const override
Get the part that can be loaded from the project cache, if possible, or else NULL.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
std::vector< SCH_COMPONENT * > * GetComponents()
Get the list of symbols that need rescued.
std::vector< RESCUE_LOG > m_rescue_log
SCH_EDIT_FRAME * m_edit_frame
wxString m_requested_name
wxString old_name
virtual bool PerformAction(RESCUER *aRescuer)=0
Perform the actual rescue action.
virtual wxString GetRequestedName() const
Get the name that was originally requested in the schematic.
virtual wxString GetNewName() const
Get the name we&#39;re proposing changing it to.
wxString new_name