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 <[email protected]>
5 * Copyright (C) 2015-2022 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 <vector>
41#include <wx/string.h>
42#include <boost/ptr_container/ptr_vector.hpp>
43
44#include <string_utf8_map.h>
45#include <lib_symbol.h>
48
49
50class LIB_SYMBOL;
51class SCH_SYMBOL;
52class RESCUER;
53class SCH_EDIT_FRAME;
55class SCH_SHEET_PATH;
56class SCHEMATIC;
57
58
60{
63};
64
65
67{
68public:
69 virtual ~RESCUE_CANDIDATE() {}
70
74 virtual wxString GetRequestedName() const { return m_requested_name; }
75
79 virtual wxString GetNewName() const { return m_new_name; }
80
85 virtual LIB_SYMBOL* GetCacheCandidate() const { return nullptr; }
86
91 virtual LIB_SYMBOL* GetLibCandidate() const { return m_lib_candidate; }
92
93 int GetUnit() const { return m_unit; }
94
95 int GetConvert() const { return m_convert; }
96
100 virtual wxString GetActionDescription() const = 0;
101
107 virtual bool PerformAction( RESCUER* aRescuer ) = 0;
108
109protected:
111 wxString m_new_name;
115};
116
117
119{
120public:
127 static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
128
138 RESCUE_CASE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName,
139 LIB_SYMBOL* aLibCandidate, int aUnit = 0, int aConvert = 0 );
140
142
143 virtual wxString GetActionDescription() const override;
144
145 virtual bool PerformAction( RESCUER* aRescuer ) override;
146};
147
148
150{
152
153public:
160 static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
161
172 RESCUE_CACHE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName,
173 LIB_SYMBOL* aCacheCandidate, LIB_SYMBOL* aLibCandidate,
174 int aUnit = 0, int aConvert = 0 );
175
177
178 virtual LIB_SYMBOL* GetCacheCandidate() const override { return m_cache_candidate; }
179
180 virtual wxString GetActionDescription() const override;
181
182 virtual bool PerformAction( RESCUER* aRescuer ) override;
183};
184
185
187{
188public:
195 static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
196
207 RESCUE_SYMBOL_LIB_TABLE_CANDIDATE( const LIB_ID& aRequestedId, const LIB_ID& aNewId,
208 LIB_SYMBOL* aCacheCandidate, LIB_SYMBOL* aLibCandidate,
209 int aUnit = 0, int aConvert = 0 );
210
212
213 virtual LIB_SYMBOL* GetCacheCandidate() const override { return m_cache_candidate; }
214
215 virtual wxString GetActionDescription() const override;
216
217 virtual bool PerformAction( RESCUER* aRescuer ) override;
218
219private:
223};
224
225
227{
228public:
230 wxString old_name;
231 wxString new_name;
232};
233
234
236{
237public:
238 RESCUER( PROJECT& aProject, SCHEMATIC* aSchematic, SCH_SHEET_PATH* aCurrentSheet,
239 EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType );
240
241 virtual ~RESCUER()
242 {
243 }
244
252 virtual bool WriteRescueLibrary( wxWindow *aParent ) = 0;
253
254 virtual void OpenRescueLibrary() = 0;
255
259 virtual void FindCandidates() = 0;
260
261 virtual void AddSymbol( LIB_SYMBOL* aNewSymbol ) = 0;
262
268 virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) = 0;
269
273 void RemoveDuplicates();
274
278 size_t GetCandidateCount() { return m_all_candidates.size(); }
279
284
288 std::vector<SCH_SYMBOL*>* GetSymbols() { return &m_symbols; }
289
293 PROJECT* GetPrj() { return m_prj; }
294
296
300 void LogRescue( SCH_SYMBOL *aSymbol, const wxString& aOldName, const wxString& aNewName );
301
307 bool DoRescues();
308
312 void UndoRescues();
313
314 static bool RescueProject( wxWindow* aParent, RESCUER& aRescuer, bool aRunningOnDemand );
315
316protected:
317 friend class DIALOG_RESCUE_EACH;
318
319 std::vector<SCH_SYMBOL*> m_symbols;
324
325 boost::ptr_vector<RESCUE_CANDIDATE> m_all_candidates;
326 std::vector<RESCUE_CANDIDATE*> m_chosen_candidates;
327
328 std::vector<RESCUE_LOG> m_rescue_log;
329};
330
331
333{
334public:
335 LEGACY_RESCUER( PROJECT& aProject, SCHEMATIC* aSchematic, SCH_SHEET_PATH* aCurrentSheet,
336 EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType ) :
337 RESCUER( aProject, aSchematic, aCurrentSheet, aGalBackEndType )
338 {
339 }
340
342 {
343 }
344
345 virtual void FindCandidates() override;
346
347 virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) override;
348
349 virtual void OpenRescueLibrary() override;
350
351 virtual bool WriteRescueLibrary( wxWindow *aParent ) override;
352
353 virtual void AddSymbol( LIB_SYMBOL* aNewSymbol ) override;
354
355private:
356 std::unique_ptr<SYMBOL_LIB> m_rescue_lib;
357};
358
359
361{
362public:
363 SYMBOL_LIB_TABLE_RESCUER( PROJECT& aProject, SCHEMATIC* aSchematic,
364 SCH_SHEET_PATH* aCurrentSheet,
365 EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType );
366
368 {
369 }
370
371 virtual void FindCandidates() override;
372
373 virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) override;
374
375 virtual void OpenRescueLibrary() override;
376
377 virtual bool WriteRescueLibrary( wxWindow* aParent ) override;
378
379 virtual void AddSymbol( LIB_SYMBOL* aNewSymbol ) override;
380
381private:
382 std::vector<std::unique_ptr<LIB_SYMBOL>> m_rescueLibSymbols;
383
384 std::unique_ptr<STRING_UTF8_MAP> m_properties;
385};
386
387#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:99
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
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.
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:61
Schematic editor (Eeschema) main window.
A SCH_PLUGIN 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:81
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.
virtual void FindCandidates() override
Populate the RESCUER with all possible candidates.
virtual void AddSymbol(LIB_SYMBOL *aNewSymbol) override
std::unique_ptr< STRING_UTF8_MAP > m_properties
Library plugin properties.
std::vector< std::unique_ptr< LIB_SYMBOL > > m_rescueLibSymbols
RESCUE_TYPE
@ RESCUE_CASE
@ RESCUE_CONFLICT