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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef _LIB_CACHE_RESCUE_H_
22#define _LIB_CACHE_RESCUE_H_
23
24/* This code handles the case where an old schematic was made before
25 * various changes were made, either to KiCad or to the libraries, and
26 * the project needs to be recovered. The function of note is a member
27 * of SCH_EDIT_FRAME, defined thus:
28 *
29 * bool SCH_EDIT_FRAME::RescueProject( bool aSilentIfNone );
30 *
31 * When this is called, a list of problematic symbols is compiled. If
32 * this list is empty, then the function displays a notification and returns
33 * (if aSilentIfNone is true, the notification is silenced).
34 */
35
36#include <wx/string.h>
37
38#include <lib_symbol.h>
42
43
44class LIB_SYMBOL;
45class SCH_SYMBOL;
46class RESCUER;
47class SCH_EDIT_FRAME;
49class SCH_SHEET_PATH;
50class SCHEMATIC;
51
52
58
59
61{
62public:
63 RESCUE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName,
64 LIB_SYMBOL* aLibCandidate, int aUnit, int aBodyStyle ) :
65 m_requested_name( aRequestedName ),
66 m_new_name( aNewName ),
67 m_lib_candidate( aLibCandidate ),
68 m_unit( aUnit ),
69 m_bodyStyle( aBodyStyle )
70 {}
71
72 virtual ~RESCUE_CANDIDATE() {}
73
77 virtual wxString GetRequestedName() const { return m_requested_name; }
78
82 virtual wxString GetNewName() const { return m_new_name; }
83
88 virtual LIB_SYMBOL* GetCacheCandidate() const { return nullptr; }
89
94 virtual LIB_SYMBOL* GetLibCandidate() const { return m_lib_candidate; }
95
96 int GetUnit() const { return m_unit; }
97 int GetBodyStyle() const { return m_bodyStyle; }
98
102 virtual wxString GetActionDescription() const = 0;
103
109 virtual bool PerformAction( RESCUER* aRescuer ) = 0;
110
111protected:
113 wxString m_new_name;
117};
118
119
121{
122public:
129 static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
130
140 RESCUE_CASE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName,
141 LIB_SYMBOL* aLibCandidate, int aUnit = 0, int aBodyStyle = 0 );
142
144 RESCUE_CANDIDATE( wxEmptyString, wxEmptyString, nullptr, 0, 0 )
145 {}
146
147 virtual wxString GetActionDescription() const override;
148
149 virtual bool PerformAction( RESCUER* aRescuer ) override;
150};
151
152
154{
156
157public:
164 static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
165
176 RESCUE_CACHE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName,
177 LIB_SYMBOL* aCacheCandidate, LIB_SYMBOL* aLibCandidate,
178 int aUnit = 0, int aBodyStyle = 0 ) :
179 RESCUE_CANDIDATE( aRequestedName, aNewName, aLibCandidate, aUnit, aBodyStyle ),
180 m_cache_candidate( aCacheCandidate )
181 {}
182
184 RESCUE_CANDIDATE( wxEmptyString, wxEmptyString, nullptr, 0, 0 ),
185 m_cache_candidate( nullptr )
186 {}
187
188 virtual LIB_SYMBOL* GetCacheCandidate() const override { return m_cache_candidate; }
189
190 virtual wxString GetActionDescription() const override;
191
192 virtual bool PerformAction( RESCUER* aRescuer ) override;
193};
194
195
197{
198public:
205 static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
206
217 RESCUE_SYMBOL_LIB_TABLE_CANDIDATE( const LIB_ID& aRequestedId, const LIB_ID& aNewId,
218 LIB_SYMBOL* aCacheCandidate, LIB_SYMBOL* aLibCandidate,
219 int aUnit = 0, int aBodyStyle = 0 );
220
222
223 virtual LIB_SYMBOL* GetCacheCandidate() const override { return m_cache_candidate; }
224
225 virtual wxString GetActionDescription() const override;
226
227 virtual bool PerformAction( RESCUER* aRescuer ) override;
228
229private:
233};
234
235
237{
238public:
240 wxString old_name;
241 wxString new_name;
242};
243
244
246{
247public:
248 RESCUER( PROJECT& aProject, SCHEMATIC* aSchematic, SCH_SHEET_PATH* aCurrentSheet,
249 EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType );
250
251 virtual ~RESCUER() = default;
252
260 virtual bool WriteRescueLibrary( wxWindow *aParent ) = 0;
261
262 virtual void OpenRescueLibrary() = 0;
263
267 virtual void FindCandidates() = 0;
268
269 virtual void AddSymbol( LIB_SYMBOL* aNewSymbol ) = 0;
270
276 virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) = 0;
277
281 void RemoveDuplicates();
282
286 size_t GetCandidateCount() { return m_all_candidates.size(); }
287
292
296 std::vector<SCH_SYMBOL*>* GetSymbols() { return &m_symbols; }
297
301 PROJECT* GetPrj() { return m_prj; }
302
304
308 void LogRescue( SCH_SYMBOL *aSymbol, const wxString& aOldName, const wxString& aNewName );
309
315 bool DoRescues();
316
320 void UndoRescues();
321
322 static bool RescueProject( wxWindow* aParent, RESCUER& aRescuer, bool aRunningOnDemand );
323
324protected:
325 friend class DIALOG_RESCUE_EACH;
326
327 std::vector<SCH_SYMBOL*> m_symbols;
332
333 boost::ptr_vector<RESCUE_CANDIDATE> m_all_candidates;
334 std::vector<RESCUE_CANDIDATE*> m_chosen_candidates;
335
336 std::vector<RESCUE_LOG> m_rescue_log;
337};
338
339
341{
342public:
343 LEGACY_RESCUER( PROJECT& aProject, SCHEMATIC* aSchematic, SCH_SHEET_PATH* aCurrentSheet,
344 EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType ) :
345 RESCUER( aProject, aSchematic, aCurrentSheet, aGalBackEndType )
346 {
347 }
348
349 virtual ~LEGACY_RESCUER() = default;
350
351 virtual void FindCandidates() override;
352
353 virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) override;
354
355 virtual void OpenRescueLibrary() override;
356
357 virtual bool WriteRescueLibrary( wxWindow *aParent ) override;
358
359 virtual void AddSymbol( LIB_SYMBOL* aNewSymbol ) override;
360
361private:
362 std::unique_ptr<LEGACY_SYMBOL_LIB> m_rescue_lib;
363};
364
365
367{
368public:
369 SYMBOL_LIB_TABLE_RESCUER( PROJECT& aProject, SCHEMATIC* aSchematic,
370 SCH_SHEET_PATH* aCurrentSheet,
371 EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType );
372
373 virtual ~SYMBOL_LIB_TABLE_RESCUER() = default;
374
375 virtual void FindCandidates() override;
376
377 virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) override;
378
379 virtual void OpenRescueLibrary() override;
380
381 virtual bool WriteRescueLibrary( wxWindow* aParent ) override;
382
383 virtual void AddSymbol( LIB_SYMBOL* aNewSymbol ) override;
384
385private:
386 std::vector<std::unique_ptr<LIB_SYMBOL>> m_rescueLibSymbols;
387 std::unique_ptr<std::map<std::string, UTF8>> m_properties;
388};
389
390#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< LEGACY_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:45
Define a library symbol object.
Definition lib_symbol.h:79
Container for project specific data.
Definition project.h:62
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:90
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:69
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