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 <string_utf8_map.h>
43#include <lib_symbol.h>
46
47
48class LIB_SYMBOL;
49class SCH_SYMBOL;
50class RESCUER;
51class SCH_EDIT_FRAME;
53class SCH_SHEET_PATH;
54class SCHEMATIC;
55
56
58{
61};
62
63
65{
66public:
67 virtual ~RESCUE_CANDIDATE() {}
68
72 virtual wxString GetRequestedName() const { return m_requested_name; }
73
77 virtual wxString GetNewName() const { return m_new_name; }
78
83 virtual LIB_SYMBOL* GetCacheCandidate() const { return nullptr; }
84
89 virtual LIB_SYMBOL* GetLibCandidate() const { return m_lib_candidate; }
90
91 int GetUnit() const { return m_unit; }
92
93 int GetConvert() const { return m_convert; }
94
98 virtual wxString GetActionDescription() const = 0;
99
105 virtual bool PerformAction( RESCUER* aRescuer ) = 0;
106
107protected:
109 wxString m_new_name;
113};
114
115
117{
118public:
125 static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
126
136 RESCUE_CASE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName,
137 LIB_SYMBOL* aLibCandidate, int aUnit = 0, int aConvert = 0 );
138
140
141 virtual wxString GetActionDescription() const override;
142
143 virtual bool PerformAction( RESCUER* aRescuer ) override;
144};
145
146
148{
150
151public:
158 static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
159
170 RESCUE_CACHE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName,
171 LIB_SYMBOL* aCacheCandidate, LIB_SYMBOL* aLibCandidate,
172 int aUnit = 0, int aConvert = 0 );
173
175
176 virtual LIB_SYMBOL* GetCacheCandidate() const override { return m_cache_candidate; }
177
178 virtual wxString GetActionDescription() const override;
179
180 virtual bool PerformAction( RESCUER* aRescuer ) override;
181};
182
183
185{
186public:
193 static void FindRescues( RESCUER& aRescuer, boost::ptr_vector<RESCUE_CANDIDATE>& aCandidates );
194
205 RESCUE_SYMBOL_LIB_TABLE_CANDIDATE( const LIB_ID& aRequestedId, const LIB_ID& aNewId,
206 LIB_SYMBOL* aCacheCandidate, LIB_SYMBOL* aLibCandidate,
207 int aUnit = 0, int aConvert = 0 );
208
210
211 virtual LIB_SYMBOL* GetCacheCandidate() const override { return m_cache_candidate; }
212
213 virtual wxString GetActionDescription() const override;
214
215 virtual bool PerformAction( RESCUER* aRescuer ) override;
216
217private:
221};
222
223
225{
226public:
228 wxString old_name;
229 wxString new_name;
230};
231
232
234{
235public:
236 RESCUER( PROJECT& aProject, SCHEMATIC* aSchematic, SCH_SHEET_PATH* aCurrentSheet,
237 EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType );
238
239 virtual ~RESCUER()
240 {
241 }
242
250 virtual bool WriteRescueLibrary( wxWindow *aParent ) = 0;
251
252 virtual void OpenRescueLibrary() = 0;
253
257 virtual void FindCandidates() = 0;
258
259 virtual void AddSymbol( LIB_SYMBOL* aNewSymbol ) = 0;
260
266 virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) = 0;
267
271 void RemoveDuplicates();
272
276 size_t GetCandidateCount() { return m_all_candidates.size(); }
277
282
286 std::vector<SCH_SYMBOL*>* GetSymbols() { return &m_symbols; }
287
291 PROJECT* GetPrj() { return m_prj; }
292
294
298 void LogRescue( SCH_SYMBOL *aSymbol, const wxString& aOldName, const wxString& aNewName );
299
305 bool DoRescues();
306
310 void UndoRescues();
311
312 static bool RescueProject( wxWindow* aParent, RESCUER& aRescuer, bool aRunningOnDemand );
313
314protected:
315 friend class DIALOG_RESCUE_EACH;
316
317 std::vector<SCH_SYMBOL*> m_symbols;
322
323 boost::ptr_vector<RESCUE_CANDIDATE> m_all_candidates;
324 std::vector<RESCUE_CANDIDATE*> m_chosen_candidates;
325
326 std::vector<RESCUE_LOG> m_rescue_log;
327};
328
329
331{
332public:
333 LEGACY_RESCUER( PROJECT& aProject, SCHEMATIC* aSchematic, SCH_SHEET_PATH* aCurrentSheet,
334 EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType ) :
335 RESCUER( aProject, aSchematic, aCurrentSheet, aGalBackEndType )
336 {
337 }
338
340 {
341 }
342
343 virtual void FindCandidates() override;
344
345 virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) override;
346
347 virtual void OpenRescueLibrary() override;
348
349 virtual bool WriteRescueLibrary( wxWindow *aParent ) override;
350
351 virtual void AddSymbol( LIB_SYMBOL* aNewSymbol ) override;
352
353private:
354 std::unique_ptr<SYMBOL_LIB> m_rescue_lib;
355};
356
357
359{
360public:
361 SYMBOL_LIB_TABLE_RESCUER( PROJECT& aProject, SCHEMATIC* aSchematic,
362 SCH_SHEET_PATH* aCurrentSheet,
363 EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackeEndType );
364
366 {
367 }
368
369 virtual void FindCandidates() override;
370
371 virtual void InvokeDialog( wxWindow* aParent, bool aAskShowAgain ) override;
372
373 virtual void OpenRescueLibrary() override;
374
375 virtual bool WriteRescueLibrary( wxWindow* aParent ) override;
376
377 virtual void AddSymbol( LIB_SYMBOL* aNewSymbol ) override;
378
379private:
380 std::vector<std::unique_ptr<LIB_SYMBOL>> m_rescueLibSymbols;
381
382 std::unique_ptr<STRING_UTF8_MAP> m_properties;
383};
384
385#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:77
Container for project specific data.
Definition: project.h:62
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:75
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:108
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.
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