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-2017 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #ifndef _LIB_CACHE_RESCUE_H_
25 #define _LIB_CACHE_RESCUE_H_
26 
27 /* This code handles the case where an old schematic was made before
28  * various changes were made, either to KiCad or to the libraries, and
29  * the project needs to be recovered. The function of note is a member
30  * of SCH_EDIT_FRAME, defined thus:
31  *
32  * bool SCH_EDIT_FRAME::RescueProject( bool aSilentIfNone );
33  *
34  * When this is called, a list of problematic components is compiled. If
35  * this list is empty, then the function displays a notification and returns
36  * (if aSilentIfNone is true, the notification is silenced).
37  */
38 
39 #include <schframe.h>
40 
41 #include <vector>
42 #include <wx/string.h>
43 #include <boost/ptr_container/ptr_vector.hpp>
44 
45 class LIB_PART;
46 class SCH_COMPONENT;
47 class RESCUER;
48 
50 {
53 };
54 
56 {
57 public:
58  virtual ~RESCUE_CANDIDATE() {}
59 
64  virtual wxString GetRequestedName() const = 0;
65 
70  virtual wxString GetNewName() const = 0;
71 
77  virtual LIB_PART* GetCacheCandidate() const { return NULL; }
78 
84  virtual LIB_PART* GetLibCandidate() const { return NULL; }
85 
90  virtual wxString GetActionDescription() const = 0;
91 
98  virtual bool PerformAction( RESCUER* aRescuer ) = 0;
99 };
100 
102 {
103 public:
105  wxString old_name;
106  wxString new_name;
107 };
108 
109 class RESCUER
110 {
111  friend class DIALOG_RESCUE_EACH;
112 
113  std::vector<SCH_COMPONENT*> m_components;
117 
118  boost::ptr_vector<RESCUE_CANDIDATE> m_all_candidates;
119  std::vector<RESCUE_CANDIDATE*> m_chosen_candidates;
120 
121  std::vector<RESCUE_LOG> m_rescue_log;
122 
123 public:
124  RESCUER( SCH_EDIT_FRAME& aEditFrame, PROJECT& aProject );
125 
130  void FindCandidates();
131 
136  void RemoveDuplicates();
137 
141  size_t GetCandidateCount() { return m_all_candidates.size(); }
142 
146  size_t GetChosenCandidateCount() { return m_chosen_candidates.size(); }
147 
151  std::vector<SCH_COMPONENT*>* GetComponents() { return &m_components; }
152 
156  PART_LIBS* GetLibs() { return m_libs; }
157 
161  PROJECT* GetPrj() { return m_prj; }
162 
167  wxString GetPartNameSuffix();
168 
174  void InvokeDialog( bool aAskShowAgain );
175 
180  void LogRescue( SCH_COMPONENT *aComponent, const wxString& aOldName,
181  const wxString& aNewName );
182 
188  bool DoRescues();
189 
194  void UndoRescues();
195 };
196 
197 #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:52
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