KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.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 symbols 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 <wx/string.h>
41
42#include <lib_symbol.h>
45
46
47class LIB_SYMBOL;
48class SCH_SYMBOL;
49class RESCUER;
50class SCH_EDIT_FRAME;
52class SCH_SHEET_PATH;
53class SCHEMATIC;
54
55
61
62
64{
65public:
66 RESCUE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName,
67 LIB_SYMBOL* aLibCandidate, int aUnit, int aBodyStyle ) :
68 m_requested_name( aRequestedName ),
69 m_new_name( aNewName ),
70 m_lib_candidate( aLibCandidate ),
71 m_unit( aUnit ),
72 m_bodyStyle( aBodyStyle )
73 {}
74
75 virtual ~RESCUE_CANDIDATE() {}
76
80 virtual wxString GetRequestedName() const { return m_requested_name; }
81
85 virtual wxString GetNewName() const { return m_new_name; }
86
91 virtual LIB_SYMBOL* GetCacheCandidate() const { return nullptr; }
92
97 virtual LIB_SYMBOL* GetLibCandidate() const { return m_lib_candidate; }
98
99 int GetUnit() const { return m_unit; }
100 int GetBodyStyle() const { return m_bodyStyle; }
101
105 virtual wxString GetActionDescription() const = 0;
106
112 virtual bool PerformAction( RESCUER* aRescuer ) = 0;
113
114protected:
116 wxString m_new_name;
120};
121
122
124{
125public:
132 static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
133
143 RESCUE_CASE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName,
144 LIB_SYMBOL* aLibCandidate, int aUnit = 0, int aBodyStyle = 0 );
145
147 RESCUE_CANDIDATE( wxEmptyString, wxEmptyString, nullptr, 0, 0 )
148 {}
149
150 virtual wxString GetActionDescription() const override;
151
152 virtual bool PerformAction( RESCUER* aRescuer ) override;
153};
154
155
157{
159
160public:
167 static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
168
179 RESCUE_CACHE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName,
180 LIB_SYMBOL* aCacheCandidate, LIB_SYMBOL* aLibCandidate,
181 int aUnit = 0, int aBodyStyle = 0 ) :
182 RESCUE_CANDIDATE( aRequestedName, aNewName, aLibCandidate, aUnit, aBodyStyle ),
183 m_cache_candidate( aCacheCandidate )
184 {}
185
187 RESCUE_CANDIDATE( wxEmptyString, wxEmptyString, nullptr, 0, 0 ),
188 m_cache_candidate( nullptr )
189 {}
190
191 virtual LIB_SYMBOL* GetCacheCandidate() const override { return m_cache_candidate; }
192
193 virtual wxString GetActionDescription() const override;
194
195 virtual bool PerformAction( RESCUER* aRescuer ) override;
196};
197
198
200{
201public:
208 static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
209
220 RESCUE_SYMBOL_LIB_TABLE_CANDIDATE( const LIB_ID& aRequestedId, const LIB_ID& aNewId,
221 LIB_SYMBOL* aCacheCandidate, LIB_SYMBOL* aLibCandidate,
222 int aUnit = 0, int aBodyStyle = 0 );
223
225
226 virtual LIB_SYMBOL* GetCacheCandidate() const override { return m_cache_candidate; }
227
228 virtual wxString GetActionDescription() const override;
229
230 virtual bool PerformAction( RESCUER* aRescuer ) override;
231
232private:
236};
237
238
240{
241public:
243 wxString old_name;
244 wxString new_name;
245};
246
247
249{
250public:
251 RESCUER( PROJECT& aProject, SCHEMATIC* aSchematic, SCH_SHEET_PATH* aCurrentSheet,
252 EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType );
253
254 virtual ~RESCUER() = default;
255
263 virtual bool WriteRescueLibrary( wxWindow *aParent ) = 0;
264
265 virtual void OpenRescueLibrary() = 0;
266
270 virtual void FindCandidates() = 0;
271
272 virtual void AddSymbol( LIB_SYMBOL* aNewSymbol ) = 0;
273
279 virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) = 0;
280
284 void RemoveDuplicates();
285
289 size_t GetCandidateCount() { return m_all_candidates.size(); }
290
295
299 std::vector<SCH_SYMBOL*>* GetSymbols() { return &m_symbols; }
300
304 PROJECT* GetPrj() { return m_prj; }
305
307
311 void LogRescue( SCH_SYMBOL *aSymbol, const wxString& aOldName, const wxString& aNewName );
312
318 bool DoRescues();
319
323 void UndoRescues();
324
325 static bool RescueProject( wxWindow* aParent, RESCUER& aRescuer, bool aRunningOnDemand );
326
327protected:
328 friend class DIALOG_RESCUE_EACH;
329
330 std::vector<SCH_SYMBOL*> m_symbols;
335
336 boost::ptr_vector<RESCUE_CANDIDATE> m_all_candidates;
337 std::vector<RESCUE_CANDIDATE*> m_chosen_candidates;
338
339 std::vector<RESCUE_LOG> m_rescue_log;
340};
341
342
344{
345public:
346 LEGACY_RESCUER( PROJECT& aProject, SCHEMATIC* aSchematic, SCH_SHEET_PATH* aCurrentSheet,
347 EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType ) :
348 RESCUER( aProject, aSchematic, aCurrentSheet, aGalBackEndType )
349 {
350 }
351
352 virtual ~LEGACY_RESCUER() = default;
353
354 virtual void FindCandidates() override;
355
356 virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) override;
357
358 virtual void OpenRescueLibrary() override;
359
360 virtual bool WriteRescueLibrary( wxWindow *aParent ) override;
361
362 virtual void AddSymbol( LIB_SYMBOL* aNewSymbol ) override;
363
364private:
365 std::unique_ptr<SYMBOL_LIB> m_rescue_lib;
366};
367
368
370{
371public:
372 SYMBOL_LIB_TABLE_RESCUER( PROJECT& aProject, SCHEMATIC* aSchematic,
373 SCH_SHEET_PATH* aCurrentSheet,
374 EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType );
375
376 virtual ~SYMBOL_LIB_TABLE_RESCUER() = default;
377
378 virtual void FindCandidates() override;
379
380 virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) override;
381
382 virtual void OpenRescueLibrary() override;
383
384 virtual bool WriteRescueLibrary( wxWindow* aParent ) override;
385
386 virtual void AddSymbol( LIB_SYMBOL* aNewSymbol ) override;
387
388private:
389 std::vector<std::unique_ptr<LIB_SYMBOL>> m_rescueLibSymbols;
390 std::unique_ptr<std::map<std::string, UTF8>> m_properties;
391};
392
393#endif // _LIB_CACHE_RESCUE_H_
virtual void FindCandidates() override
Populate the RESCUER with all possible candidates.
virtual bool WriteRescueLibrary(wxWindow *aParent) override
Write the rescue library.
virtual ~LEGACY_RESCUER()=default
virtual void InvokeDialog(wxWindow *aParent, bool aAskShowAgain) override
Display a dialog to allow the user to select rescues.
LEGACY_RESCUER(PROJECT &aProject, SCHEMATIC *aSchematic, SCH_SHEET_PATH *aCurrentSheet, EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType)
virtual void AddSymbol(LIB_SYMBOL *aNewSymbol) override
std::unique_ptr< SYMBOL_LIB > m_rescue_lib
virtual void OpenRescueLibrary() override
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:49
Define a library symbol object.
Definition lib_symbol.h:85
Container for project specific data.
Definition project.h:65
virtual void AddSymbol(LIB_SYMBOL *aNewSymbol)=0
friend class DIALOG_RESCUE_EACH
virtual bool WriteRescueLibrary(wxWindow *aParent)=0
Write the rescue library.
std::vector< RESCUE_LOG > m_rescue_log
SCHEMATIC * m_schematic
virtual ~RESCUER()=default
PROJECT * m_prj
void UndoRescues()
Reverse the effects of all rescues on the project.
bool DoRescues()
Perform all chosen rescue actions, logging them to be undone if necessary.
std::vector< SCH_SYMBOL * > m_symbols
static bool RescueProject(wxWindow *aParent, RESCUER &aRescuer, bool aRunningOnDemand)
void LogRescue(SCH_SYMBOL *aSymbol, const wxString &aOldName, const wxString &aNewName)
Used by individual RESCUE_CANDIDATE objects to log a rescue for undoing.
SCH_SHEET_PATH * m_currentSheet
std::vector< RESCUE_CANDIDATE * > m_chosen_candidates
std::vector< SCH_SYMBOL * > * GetSymbols()
Get the list of symbols that need rescued.
size_t GetCandidateCount()
Return the number of rescue candidates found.
PROJECT * GetPrj()
Return the #SCH_PROJECT object for access to the symbol libraries.
virtual void InvokeDialog(wxWindow *aParent, bool aAskShowAgain)=0
Display a dialog to allow the user to select rescues.
SCHEMATIC * Schematic()
EDA_DRAW_PANEL_GAL::GAL_TYPE m_galBackEndType
RESCUER(PROJECT &aProject, SCHEMATIC *aSchematic, SCH_SHEET_PATH *aCurrentSheet, EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType)
virtual void OpenRescueLibrary()=0
size_t GetChosenCandidateCount()
Get the number of rescue candidates chosen by the user.
boost::ptr_vector< RESCUE_CANDIDATE > m_all_candidates
virtual void FindCandidates()=0
Populate the RESCUER with all possible candidates.
void RemoveDuplicates()
Filter out duplicately named rescue candidates.
LIB_SYMBOL * m_cache_candidate
virtual LIB_SYMBOL * GetCacheCandidate() const override
Get the part that can be loaded from the project cache, if possible, or else NULL.
RESCUE_CACHE_CANDIDATE(const wxString &aRequestedName, const wxString &aNewName, LIB_SYMBOL *aCacheCandidate, LIB_SYMBOL *aLibCandidate, int aUnit=0, int aBodyStyle=0)
Create a RESCUE_CACHE_CANDIDATE.
static void FindRescues(RESCUER &aRescuer, boost::ptr_vector< RESCUE_CANDIDATE > &aCandidates)
Grab all possible RESCUE_CACHE_CANDIDATE objects into a vector.
virtual wxString GetActionDescription() const override
Get a description of the action proposed, for displaying in the UI.
virtual bool PerformAction(RESCUER *aRescuer) override
Perform the actual rescue action.
RESCUE_CANDIDATE(const wxString &aRequestedName, const wxString &aNewName, LIB_SYMBOL *aLibCandidate, int aUnit, int aBodyStyle)
virtual wxString GetActionDescription() const =0
Get a description of the action proposed, for displaying in the UI.
int GetUnit() const
virtual LIB_SYMBOL * GetCacheCandidate() const
Get the part that can be loaded from the project cache, if possible, or else NULL.
virtual bool PerformAction(RESCUER *aRescuer)=0
Perform the actual rescue action.
wxString m_requested_name
virtual wxString GetRequestedName() const
Get the name that was originally requested in the schematic.
virtual ~RESCUE_CANDIDATE()
virtual LIB_SYMBOL * GetLibCandidate() const
Get the part the would be loaded from the libraries, if possible, or else NULL.
LIB_SYMBOL * m_lib_candidate
virtual wxString GetNewName() const
Get the name we're proposing changing it to.
int GetBodyStyle() const
static void FindRescues(RESCUER &aRescuer, boost::ptr_vector< RESCUE_CANDIDATE > &aCandidates)
Grab all possible RESCUE_CASE_CANDIDATE objects into a vector.
virtual wxString GetActionDescription() const override
Get a description of the action proposed, for displaying in the UI.
RESCUE_CASE_CANDIDATE(const wxString &aRequestedName, const wxString &aNewName, LIB_SYMBOL *aLibCandidate, int aUnit=0, int aBodyStyle=0)
Create a RESCUE_CANDIDATE.
virtual bool PerformAction(RESCUER *aRescuer) override
Perform the actual rescue action.
wxString old_name
wxString new_name
SCH_SYMBOL * symbol
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.
RESCUE_SYMBOL_LIB_TABLE_CANDIDATE(const LIB_ID &aRequestedId, const LIB_ID &aNewId, LIB_SYMBOL *aCacheCandidate, LIB_SYMBOL *aLibCandidate, int aUnit=0, int aBodyStyle=0)
Create RESCUE_CANDIDATE.
static void FindRescues(RESCUER &aRescuer, boost::ptr_vector< RESCUE_CANDIDATE > &aCandidates)
Grab all possible RESCUE_SYMBOL_LIB_TABLE_CANDIDATE objects into a vector.
virtual LIB_SYMBOL * GetCacheCandidate() const override
Get the part that can be loaded from the project cache, if possible, or else NULL.
Holds all the data relating to one schematic.
Definition schematic.h:88
Schematic editor (Eeschema) main window.
A SCH_IO derivation for loading schematic files created before the new s-expression file format.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition sch_symbol.h:75
virtual void OpenRescueLibrary() override
virtual bool WriteRescueLibrary(wxWindow *aParent) override
Write the rescue library.
SYMBOL_LIB_TABLE_RESCUER(PROJECT &aProject, SCHEMATIC *aSchematic, SCH_SHEET_PATH *aCurrentSheet, EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType)
virtual void InvokeDialog(wxWindow *aParent, bool aAskShowAgain) override
Display a dialog to allow the user to select rescues.
std::unique_ptr< std::map< std::string, UTF8 > > m_properties
Library plugin properties.
virtual void FindCandidates() override
Populate the RESCUER with all possible candidates.
virtual ~SYMBOL_LIB_TABLE_RESCUER()=default
virtual void AddSymbol(LIB_SYMBOL *aNewSymbol) override
std::vector< std::unique_ptr< LIB_SYMBOL > > m_rescueLibSymbols
RESCUE_TYPE
@ RESCUE_CASE
@ RESCUE_CONFLICT