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 (C) 2009-2024 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, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#ifndef _CLASS_UNDOREDO_CONTAINER_H
27#define _CLASS_UNDOREDO_CONTAINER_H
28
29#include <core/typeinfo.h>
30#include <eda_item_flags.h>
31#include <functional>
32#include <kiid.h>
33#include <vector>
34#include <wx/string.h>
35
36class EDA_ITEM;
38class BASE_SCREEN;
39
40
59enum class UNDO_REDO {
60 UNSPECIFIED = 0, // illegal
61 CHANGED, // params of items have a value changed: undo is made by exchange
62 // values with a copy of these values
63 NEWITEM, // new item, undo by changing in deleted
64 DELETED, // deleted item, undo by changing in deleted
65 LIBEDIT, // Specific to the component editor (symbol_editor creates a full copy
66 // of the current component when changed)
67 LIB_RENAME, // As LIBEDIT, but old copy should be removed from library
68 DRILLORIGIN, // origin changed (like CHANGED, contains the origin and a copy)
69 GRIDORIGIN, // origin changed (like CHANGED, contains the origin and a copy)
70 PAGESETTINGS, // page settings or title block changes
71 REGROUP, // new group of items created (NB: can't use GROUP because of collision
72 // with a header on msys2)
73 UNGROUP, // existing group destroyed (items not destroyed)
74 REPEAT_ITEM // storage entry for the editor's global repeatItems list
75};
76
77
79{
80public:
81// ITEM_PICKER( EDA_ITEM* aItem = NULL, UNDO_REDO aStatus = UNSPECIFIED );
83 ITEM_PICKER( BASE_SCREEN* aScreen, EDA_ITEM* aItem,
84 UNDO_REDO aStatus = UNDO_REDO::UNSPECIFIED );
85
86 EDA_ITEM* GetItem() const { return m_pickedItem; }
87
88 void SetItem( EDA_ITEM* aItem );
89
91
92 void SetStatus( UNDO_REDO aStatus ) { m_undoRedoStatus = aStatus; }
93
95
96 void SetFlags( EDA_ITEM_FLAGS aFlags ) { m_pickerFlags = aFlags; }
97
99
100 void SetLink( EDA_ITEM* aItem ) { m_link = aItem; }
101
102 EDA_ITEM* GetLink() const { return m_link; }
103
104 KIID GetGroupId() const { return m_groupId; }
105
106 void SetGroupId( KIID aId ) { m_groupId = aId; }
107
108 BASE_SCREEN* GetScreen() const { return m_screen; }
109
110private:
111 EDA_ITEM_FLAGS m_pickerFlags; /* A copy of m_flags member. Currently used only to flag
112 * transient items. */
113 UNDO_REDO m_undoRedoStatus; /* type of operation to undo/redo for this item */
114 EDA_ITEM* m_pickedItem; /* Pointer on the schematic or board item that is concerned
115 * (picked), or in undo redo commands, the copy of an
116 * edited item. */
117 KICAD_T m_pickedItemType; /* type of schematic or board item that is concerned */
118
119 EDA_ITEM* m_link; /* Pointer on another item. Used in undo redo command
120 * used when a duplicate exists i.e. when an item is
121 * modified, and the copy of initial item exists (the
122 * duplicate) m_Item points the duplicate (i.e the old
123 * copy of an active item) and m_Link points the active
124 * item in schematic */
125 KIID m_groupId; /* Id of the group of items in case this is a group/ungroup command */
126
127 BASE_SCREEN* m_screen; /* For new and deleted items the screen the item should
128 * be added to/removed from. */
129
130};
131
132
139{
140public:
143
149 void PushItem( const ITEM_PICKER& aItem );
150
155
159 bool ContainsItem( const EDA_ITEM* aItem ) const;
160
167 bool ContainsItemType( KICAD_T aItemType ) const;
168
173 int FindItem( const EDA_ITEM* aItem ) const;
174
178 void ClearItemsList();
179
184 void ClearListAndDeleteItems( std::function<void(EDA_ITEM*)> aItemDeleter );
185
189 unsigned GetCount() const
190 {
191 return m_ItemsList.size();
192 }
193
202
208 ITEM_PICKER GetItemWrapper( unsigned int aIdx ) const;
209
214 EDA_ITEM* GetPickedItem( unsigned int aIdx ) const;
215
220 BASE_SCREEN* GetScreenForItem( unsigned int aIdx ) const;
221
226 EDA_ITEM* GetPickedItemLink( unsigned int aIdx ) const;
227
233 UNDO_REDO GetPickedItemStatus( unsigned int aIdx ) const;
234
239 KIID GetPickedItemGroupId( unsigned int aIdx ) const;
240
247 EDA_ITEM_FLAGS GetPickerFlags( unsigned aIdx ) const;
248
254 bool SetPickedItem( EDA_ITEM* aItem, unsigned aIdx );
255
262 bool SetPickedItem( EDA_ITEM* aItem, UNDO_REDO aStatus, unsigned aIdx );
263
271 bool SetPickedItemLink( EDA_ITEM* aLink, unsigned aIdx );
272
280 bool SetPickedItemGroupId( KIID aId, unsigned aIdx );
281
289 bool SetPickedItemStatus( UNDO_REDO aStatus, unsigned aIdx );
290
298 bool SetPickerFlags( EDA_ITEM_FLAGS aFlags, unsigned aIdx );
299
306 bool RemovePicker( unsigned aIdx );
307
315 void CopyList( const PICKED_ITEMS_LIST& aSource );
316
317 wxString GetDescription() const { return m_description; }
318 void SetDescription( const wxString& aDescription ) { m_description = aDescription; }
319
320private:
322 std::vector<ITEM_PICKER> m_ItemsList;
323};
324
325
330{
331public:
334
335 void PushCommand( PICKED_ITEMS_LIST* aCommand );
336
338
339 void ClearCommandList();
340
341 std::vector <PICKED_ITEMS_LIST*> m_CommandsList; // the list of possible undo/redo commands
342};
343
344
345#endif // _CLASS_UNDOREDO_CONTAINER_H
Handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:41
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
void SetItem(EDA_ITEM *aItem)
void SetGroupId(KIID aId)
void SetLink(EDA_ITEM *aItem)
BASE_SCREEN * m_screen
EDA_ITEM * GetItem() const
KICAD_T m_pickedItemType
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)
KICAD_T GetItemType() const
Definition: kiid.h:49
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
ITEM_PICKER GetItemWrapper(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.
bool ContainsItem(const EDA_ITEM *aItem) const
KIID GetPickedItemGroupId(unsigned int aIdx) const
unsigned GetCount() const
bool ContainsItemType(KICAD_T aItemType) const
Check the undo/redo list for any EDA_ITEM of type aItemType.
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 #m_PickedItem or #m_PickedItemLink according to th...
bool SetPickedItemGroupId(KIID aId, unsigned aIdx)
Set the group id associated to a given picked item.
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).
A holder to handle a list of undo (or redo) commands.
void PushCommand(PICKED_ITEMS_LIST *aCommand)
PICKED_ITEMS_LIST * PopCommand()
std::vector< PICKED_ITEMS_LIST * > m_CommandsList
std::uint32_t EDA_ITEM_FLAGS
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...