KiCad PCB EDA Suite
Loading...
Searching...
No Matches
undo_redo_container.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) 2009 [email protected]
5 * Copyright (C) 2011 Wayne Stambaugh <[email protected]>
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#ifndef _CLASS_UNDOREDO_CONTAINER_H
23#define _CLASS_UNDOREDO_CONTAINER_H
24
25#include <core/typeinfo.h>
26#include <eda_item_flags.h>
27#include <functional>
28#include <kiid.h>
29#include <unordered_set>
30#include <vector>
31#include <wx/string.h>
32
33class EDA_ITEM;
35class BASE_SCREEN;
36
37
49
50
56enum class UNDO_REDO {
57 UNSPECIFIED = 0, // illegal
58 CHANGED, // params of items have a value changed: undo is made by exchange
59 // values with a copy of these values
60 NEWITEM, // new item, undo by changing in deleted
61 DELETED, // deleted item, undo by changing in deleted
62 LIBEDIT, // Specific to the component editor (symbol_editor creates a full copy
63 // of the current component when changed)
64 LIB_RENAME, // As LIBEDIT, but old copy should be removed from library
65 DRILLORIGIN, // origin changed (like CHANGED, contains the origin and a copy)
66 GRIDORIGIN, // origin changed (like CHANGED, contains the origin and a copy)
67 PAGESETTINGS, // page settings or title block changes
68 REPEAT_ITEM, // storage entry for the editor's global repeatItems list
69 VARIANTS // one or more variants were added, deleted, or changed
70};
71
72
74{
75public:
77 ITEM_PICKER( BASE_SCREEN* aScreen, EDA_ITEM* aItem,
79
80 EDA_ITEM* GetItem() const { return m_pickedItem; }
81 void SetItem( EDA_ITEM* aItem );
82
83 void SetStatus( UNDO_REDO aStatus ) { m_undoRedoStatus = aStatus; }
85
86 void SetFlags( EDA_ITEM_FLAGS aFlags ) { m_pickerFlags = aFlags; }
88
89 void SetLink( EDA_ITEM* aItem );
90 EDA_ITEM* GetLink() const { return m_link; }
91
92 KIID GetGroupId() const { return m_groupId; }
93 std::vector<KIID> GetGroupMembers() const { return m_groupMembers; }
94
95 BASE_SCREEN* GetScreen() const { return m_screen; }
96
97private:
98 EDA_ITEM_FLAGS m_pickerFlags; /* A copy of m_flags member. Currently used only to flag
99 * transient items. */
100 UNDO_REDO m_undoRedoStatus; /* type of operation to undo/redo for this item */
101 EDA_ITEM* m_pickedItem; /* Pointer on the schematic or board item that is concerned
102 * (picked), or in undo redo commands, the copy of an
103 * edited item. */
104 KICAD_T m_pickedItemType; /* type of schematic or board item that is concerned */
105
106 EDA_ITEM* m_link; /* Pointer on another item. Used in undo redo command
107 * used when a duplicate exists i.e. when an item is
108 * modified, and the copy of initial item exists (the
109 * duplicate) m_Item points the duplicate (i.e the old
110 * copy of an active item) and m_Link points the active
111 * item in schematic */
112 KIID m_groupId; /* Id of the parent group */
113 std::vector<KIID> m_groupMembers; /* Ids of the members of a group */
114
115 BASE_SCREEN* m_screen; /* For new and deleted items the screen the item should
116 * be added to/removed from. */
117
118};
119
120
127{
128public:
131
137 void PushItem( const ITEM_PICKER& aItem );
138
143
147 bool ContainsItem( const EDA_ITEM* aItem ) const;
148
153 int FindItem( const EDA_ITEM* aItem ) const;
154
158 void ClearItemsList();
159
164 void ClearListAndDeleteItems( std::function<void(EDA_ITEM*)> aItemDeleter );
165
169 unsigned GetCount() const
170 {
171 return m_ItemsList.size();
172 }
173
182
188 const ITEM_PICKER& GetItemWrapper( unsigned int aIdx ) const;
189 ITEM_PICKER& GetItemWrapper( unsigned int aIdx );
190
195 EDA_ITEM* GetPickedItem( unsigned int aIdx ) const;
196
201 BASE_SCREEN* GetScreenForItem( unsigned int aIdx ) const;
202
207 EDA_ITEM* GetPickedItemLink( unsigned int aIdx ) const;
208
214 UNDO_REDO GetPickedItemStatus( unsigned int aIdx ) const;
215
222 EDA_ITEM_FLAGS GetPickerFlags( unsigned aIdx ) const;
223
229 bool SetPickedItem( EDA_ITEM* aItem, unsigned aIdx );
230
238 bool SetPickedItemLink( EDA_ITEM* aLink, unsigned aIdx );
239
247 bool SetPickedItemStatus( UNDO_REDO aStatus, unsigned aIdx );
248
256 bool SetPickerFlags( EDA_ITEM_FLAGS aFlags, unsigned aIdx );
257
264 bool RemovePicker( unsigned aIdx );
265
273 void CopyList( const PICKED_ITEMS_LIST& aSource );
274
275 wxString GetDescription() const { return m_description; }
276 void SetDescription( const wxString& aDescription ) { m_description = aDescription; }
277
278private:
280 std::vector<ITEM_PICKER> m_ItemsList;
281};
282
283
288{
289public:
292
293 // We own at least one list of raw pointers. Don't let the compiler fill in copy c'tors that
294 // will only land us in trouble.
297
298 void PushCommand( PICKED_ITEMS_LIST* aCommand );
299
301
302 void ClearCommandList();
303
308 void ForgetItems( const std::unordered_set<const EDA_ITEM*>& aItems );
309
310 std::vector <PICKED_ITEMS_LIST*> m_CommandsList; // the list of possible undo/redo commands
311};
312
313
314#endif // _CLASS_UNDOREDO_CONTAINER_H
Handles how to draw a screen (a board, a schematic ...)
Definition base_screen.h:37
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
std::vector< KIID > m_groupMembers
void SetItem(EDA_ITEM *aItem)
void SetLink(EDA_ITEM *aItem)
BASE_SCREEN * m_screen
EDA_ITEM * GetItem() const
void SetStatus(UNDO_REDO aStatus)
BASE_SCREEN * GetScreen() const
EDA_ITEM * GetLink() const
EDA_ITEM_FLAGS GetFlags() const
EDA_ITEM_FLAGS m_pickerFlags
EDA_ITEM * m_pickedItem
KIID GetGroupId() const
UNDO_REDO m_undoRedoStatus
UNDO_REDO GetStatus() const
void SetFlags(EDA_ITEM_FLAGS aFlags)
std::vector< KIID > GetGroupMembers() const
Definition kiid.h:46
A holder to handle information on schematic or board items.
bool SetPickedItemStatus(UNDO_REDO aStatus, unsigned aIdx)
Set the type of undo/redo operation for a given picked item.
EDA_ITEM_FLAGS GetPickerFlags(unsigned aIdx) const
Return the value of the picker flag.
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
void SetDescription(const wxString &aDescription)
int FindItem(const EDA_ITEM *aItem) const
UNDO_REDO GetPickedItemStatus(unsigned int aIdx) const
EDA_ITEM * GetPickedItemLink(unsigned int aIdx) const
wxString GetDescription() const
std::vector< ITEM_PICKER > m_ItemsList
bool RemovePicker(unsigned aIdx)
Remove one entry (one picker) from the list of picked items.
const ITEM_PICKER & GetItemWrapper(unsigned int aIdx) const
bool ContainsItem(const EDA_ITEM *aItem) const
unsigned GetCount() const
bool SetPickedItem(EDA_ITEM *aItem, unsigned aIdx)
void CopyList(const PICKED_ITEMS_LIST &aSource)
Copy all data from aSource to the list.
void ReversePickersListOrder()
Reverse the order of pickers stored in this list.
void ClearItemsList()
Delete only the list of pickers NOT the picked data itself.
bool SetPickedItemLink(EDA_ITEM *aLink, unsigned aIdx)
Set the link associated to a given picked item.
void ClearListAndDeleteItems(std::function< void(EDA_ITEM *)> aItemDeleter)
Delete the list of pickers AND the data pointed by ITEM_PICKER::m_pickedItem or ITEM_PICKER::m_link.
BASE_SCREEN * GetScreenForItem(unsigned int aIdx) const
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
bool SetPickerFlags(EDA_ITEM_FLAGS aFlags, unsigned aIdx)
Set the flags of the picker (usually to the picked item m_flags value).
UNDO_REDO_CONTAINER(const UNDO_REDO_CONTAINER &)=delete
UNDO_REDO_CONTAINER & operator=(const UNDO_REDO_CONTAINER &)=delete
void PushCommand(PICKED_ITEMS_LIST *aCommand)
PICKED_ITEMS_LIST * PopCommand()
void ForgetItems(const std::unordered_set< const EDA_ITEM * > &aItems)
Drop every picker that refers to one of aItems, before they are freed outside the undo system.
std::vector< PICKED_ITEMS_LIST * > m_CommandsList
#define UNSPECIFIED
std::uint32_t EDA_ITEM_FLAGS
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:70
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...