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 (C) 2015-2023 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 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
57{
60};
61
62
64{
65public:
66 virtual ~RESCUE_CANDIDATE() {}
67
71 virtual wxString GetRequestedName() const { return m_requested_name; }
72
76 virtual wxString GetNewName() const { return m_new_name; }
77
82 virtual LIB_SYMBOL* GetCacheCandidate() const { return nullptr; }
83
88 virtual LIB_SYMBOL* GetLibCandidate() const { return m_lib_candidate; }
89
90 int GetUnit() const { return m_unit; }
91
92 int GetConvert() const { return m_convert; }
93
97 virtual wxString GetActionDescription() const = 0;
98
104 virtual bool PerformAction( RESCUER* aRescuer ) = 0;
105
106protected:
108 wxString m_new_name;
112};
113
114
116{
117public:
124 static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
125
135 RESCUE_CASE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName,
136 LIB_SYMBOL* aLibCandidate, int aUnit = 0, int aConvert = 0 );
137
139
140 virtual wxString GetActionDescription() const override;
141
142 virtual bool PerformAction( RESCUER* aRescuer ) override;
143};
144
145
147{
149
150public:
157 static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
158
169 RESCUE_CACHE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName,
170 LIB_SYMBOL* aCacheCandidate, LIB_SYMBOL* aLibCandidate,
171 int aUnit = 0, int aConvert = 0 );
172
174
175 virtual LIB_SYMBOL* GetCacheCandidate() const override { return m_cache_candidate; }
176
177 virtual wxString GetActionDescription() const override;
178
179 virtual bool PerformAction( RESCUER* aRescuer ) override;
180};
181
182
184{
185public:
192 static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
193
204 RESCUE_SYMBOL_LIB_TABLE_CANDIDATE( const LIB_ID& aRequestedId, const LIB_ID& aNewId,
205 LIB_SYMBOL* aCacheCandidate, LIB_SYMBOL* aLibCandidate,
206 int aUnit = 0, int aConvert = 0 );
207
209
210 virtual LIB_SYMBOL* GetCacheCandidate() const override { return m_cache_candidate; }
211
212 virtual wxString GetActionDescription() const override;
213
214 virtual bool PerformAction( RESCUER* aRescuer ) override;
215
216private:
220};
221
222
224{
225public:
227 wxString old_name;
228 wxString new_name;
229};
230
231
233{
234public:
235 RESCUER( PROJECT& aProject, SCHEMATIC* aSchematic, SCH_SHEET_PATH* aCurrentSheet,
236 EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType );
237
238 virtual ~RESCUER()
239 {
240 }
241
249 virtual bool WriteRescueLibrary( wxWindow *aParent ) = 0;
250
251 virtual void OpenRescueLibrary() = 0;
252
256 virtual void FindCandidates() = 0;
257
258 virtual void AddSymbol( LIB_SYMBOL* aNewSymbol ) = 0;
259
265 virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) = 0;
266
270 void RemoveDuplicates();
271
275 size_t GetCandidateCount() { return m_all_candidates.size(); }
276
281
285 std::vector<SCH_SYMBOL*>* GetSymbols() { return &m_symbols; }
286
290 PROJECT* GetPrj() { return m_prj; }
291
293
297 void LogRescue( SCH_SYMBOL *aSymbol, const wxString& aOldName, const wxString& aNewName );
298
304 bool DoRescues();
305
309 void UndoRescues();
310
311 static bool RescueProject( wxWindow* aParent, RESCUER& aRescuer, bool aRunningOnDemand );
312
313protected:
314 friend class DIALOG_RESCUE_EACH;
315
316 std::vector<SCH_SYMBOL*> m_symbols;
321
322 boost::ptr_vector<RESCUE_CANDIDATE> m_all_candidates;
323 std::vector<RESCUE_CANDIDATE*> m_chosen_candidates;
324
325 std::vector<RESCUE_LOG> m_rescue_log;
326};
327
328
330{
331public:
332 LEGACY_RESCUER( PROJECT& aProject, SCHEMATIC* aSchematic, SCH_SHEET_PATH* aCurrentSheet,
333 EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType ) :
334 RESCUER( aProject, aSchematic, aCurrentSheet, aGalBackEndType )
335 {
336 }
337
339 {
340 }
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 AddSymbol( LIB_SYMBOL* aNewSymbol ) override;
351
352private:
353 std::unique_ptr<SYMBOL_LIB> m_rescue_lib;
354};
355
356
358{
359public:
360 SYMBOL_LIB_TABLE_RESCUER( PROJECT& aProject, SCHEMATIC* aSchematic,
361 SCH_SHEET_PATH* aCurrentSheet,
362 EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType );
363
365 {
366 }
367
368 virtual void FindCandidates() override;
369
370 virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) override;
371
372 virtual void OpenRescueLibrary() override;
373
374 virtual bool WriteRescueLibrary( wxWindow* aParent ) override;
375
376 virtual void AddSymbol( LIB_SYMBOL* aNewSymbol ) override;
377
378private:
379 std::vector<std::unique_ptr<LIB_SYMBOL>> m_rescueLibSymbols;
380
381 std::unique_ptr<std::map<std::string, UTF8>> m_properties;
382};
383
384#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 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 ~LEGACY_RESCUER()
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:78
Container for project specific data.
Definition: project.h:64
virtual void AddSymbol(LIB_SYMBOL *aNewSymbol)=0
virtual bool WriteRescueLibrary(wxWindow *aParent)=0
Write the rescue library.
std::vector< RESCUE_LOG > m_rescue_log
SCHEMATIC * m_schematic
PROJECT * m_prj
virtual ~RESCUER()
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
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.
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.
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()
int GetConvert() const
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.
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.
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.
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:77
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:104
virtual void OpenRescueLibrary() override
virtual bool WriteRescueLibrary(wxWindow *aParent) override
Write the rescue library.
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 void AddSymbol(LIB_SYMBOL *aNewSymbol) override
std::vector< std::unique_ptr< LIB_SYMBOL > > m_rescueLibSymbols
RESCUE_TYPE
@ RESCUE_CASE
@ RESCUE_CONFLICT