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 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 <schframe.h>
41 
42 #include <vector>
43 #include <wx/string.h>
44 #include <boost/ptr_container/ptr_vector.hpp>
45 
46 class LIB_PART;
47 class SCH_COMPONENT;
48 class RESCUER;
49 
51 {
54 };
55 
57 {
58 public:
59  virtual ~RESCUE_CANDIDATE() {}
60 
65  virtual wxString GetRequestedName() const = 0;
66 
71  virtual wxString GetNewName() const = 0;
72 
78  virtual LIB_PART* GetCacheCandidate() const { return NULL; }
79 
85  virtual LIB_PART* GetLibCandidate() const { return NULL; }
86 
91  virtual wxString GetActionDescription() const = 0;
92 
99  virtual bool PerformAction( RESCUER* aRescuer ) = 0;
100 };
101 
103 {
104 public:
106  wxString old_name;
107  wxString new_name;
108 };
109 
110 class RESCUER
111 {
112  friend class DIALOG_RESCUE_EACH;
113 
114  std::vector<SCH_COMPONENT*> m_components;
118 
119  boost::ptr_vector<RESCUE_CANDIDATE> m_all_candidates;
120  std::vector<RESCUE_CANDIDATE*> m_chosen_candidates;
121 
122  std::vector<RESCUE_LOG> m_rescue_log;
123 
124 public:
125  RESCUER( SCH_EDIT_FRAME& aEditFrame, PROJECT& aProject );
126 
131  void FindCandidates();
132 
137  void RemoveDuplicates();
138 
142  size_t GetCandidateCount() { return m_all_candidates.size(); }
143 
147  size_t GetChosenCandidateCount() { return m_chosen_candidates.size(); }
148 
152  std::vector<SCH_COMPONENT*>* GetComponents() { return &m_components; }
153 
157  PART_LIBS* GetLibs() { return m_libs; }
158 
162  PROJECT* GetPrj() { return m_prj; }
163 
168  wxString GetPartNameSuffix();
169 
175  void InvokeDialog( bool aAskShowAgain );
176 
181  void LogRescue( SCH_COMPONENT *aComponent, const wxString& aOldName,
182  const wxString& aNewName );
183 
189  bool DoRescues();
190 
195  void UndoRescues();
196 };
197 
198 #endif // _LIB_CACHE_RESCUE_H_
RESCUER(SCH_EDIT_FRAME &aEditFrame, PROJECT &aProject)
virtual LIB_PART * GetLibCandidate() const
Function GetLibCandidate Get the part the would be loaded from the libraries, if possible, or else NULL.
size_t GetChosenCandidateCount()
Function GetChosenCandidateCount.
virtual LIB_PART * GetCacheCandidate() const
Function GetCacheCandidate 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:56
void InvokeDialog(bool aAskShowAgain)
Function InvokeDialog Display a dialog to allow the user to select rescues.
PROJECT * GetPrj()
Function GetPrj.
virtual wxString GetActionDescription() const =0
Function GetActionDescription Get a description of the action proposed, for displaying in the UI...
Schematic editor (Eeschema) main window.
Definition: schframe.h:117
PART_LIBS * m_libs
virtual ~RESCUE_CANDIDATE()
SCH_COMPONENT * component
boost::ptr_vector< RESCUE_CANDIDATE > m_all_candidates
void RemoveDuplicates()
Function RemoveDuplicates Filter out duplicately named rescue candidates.
size_t GetCandidateCount()
Function GetCandidateCount.
RESCUE_TYPE
Class LIB_PART defines a library part object.
PROJECT * m_prj
virtual wxString GetRequestedName() const =0
Function GetRequestedName Get the name that was originally requested in the schematic.
std::vector< SCH_COMPONENT * > m_components
Class PART_LIBS is a collection of PART_LIBs.
wxString GetPartNameSuffix()
Function GetPartNameSuffix Return the suffix to add to rescued parts.
std::vector< RESCUE_CANDIDATE * > m_chosen_candidates
bool DoRescues()
Function DoRescues Perform all chosen rescue actions, logging them to be undone if necessary...
void FindCandidates()
Function FindCandidates Populate the RESCUER with all possible candidates.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
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.
wxString old_name
virtual bool PerformAction(RESCUER *aRescuer)=0
Function PerformAction Perform the actual rescue action.
PART_LIBS * GetLibs()
Function GetLibs.
void UndoRescues()
Function UndoRescues Reverse the effects of all rescues on the project.
virtual wxString GetNewName() const =0
Function GetNewName Get the name we're proposing changing it to.
wxString new_name