KiCad PCB EDA Suite
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 jean-pierre.charras@gipsa-lab.inpg.fr
5  * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
6  * Copyright (C) 2009-2020 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 #include <vector>
29 
30 #include <eda_item.h>
31 
32 
33 class PICKED_ITEMS_LIST;
34 class BASE_SCREEN;
35 
36 
55 enum class UNDO_REDO {
56  UNSPECIFIED = 0, // illegal
57  NOP, // Undo/redo will ignore this entry. Only forces the start of a new stack
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  EXCHANGE_T, // Use for changing the schematic text type where swapping
66  // data structure is insufficient to restore the change.
67  DRILLORIGIN, // origin changed (like CHANGED, contains the origin and a copy)
68  GRIDORIGIN, // origin changed (like CHANGED, contains the origin and a copy)
69  PAGESETTINGS, // page settings or title block changes
70  GROUP,
71  UNGROUP
72 };
73 
74 
76 {
77 public:
78 // ITEM_PICKER( EDA_ITEM* aItem = NULL, UNDO_REDO aStatus = UNSPECIFIED );
79  ITEM_PICKER();
80  ITEM_PICKER( BASE_SCREEN* aScreen, EDA_ITEM* aItem,
82 
83  EDA_ITEM* GetItem() const { return m_pickedItem; }
84 
85  void SetItem( EDA_ITEM* aItem )
86  {
87  m_pickedItem = aItem;
88  m_pickedItemType = aItem ? aItem->Type() : TYPE_NOT_INIT;
89  }
90 
91  KICAD_T GetItemType() const { return m_pickedItemType; }
92 
93  void SetStatus( UNDO_REDO aStatus ) { m_undoRedoStatus = aStatus; }
94 
95  UNDO_REDO GetStatus() const { return m_undoRedoStatus; }
96 
97  void SetFlags( STATUS_FLAGS aFlags ) { m_pickerFlags = aFlags; }
98 
99  STATUS_FLAGS GetFlags() const { return m_pickerFlags; }
100 
101  void SetLink( EDA_ITEM* aItem ) { m_link = aItem; }
102 
103  EDA_ITEM* GetLink() const { return m_link; }
104 
105  BASE_SCREEN* GetScreen() const { return m_screen; }
106 
107 private:
108  STATUS_FLAGS m_pickerFlags; /* a copy of m_flags member. useful in mode/drag
109  * undo/redo commands */
110  UNDO_REDO m_undoRedoStatus; /* type of operation to undo/redo for this item */
111  EDA_ITEM* m_pickedItem; /* Pointer on the schematic or board item that is concerned
112  * (picked), or in undo redo commands, the copy of an
113  * edited item. */
114  KICAD_T m_pickedItemType; /* type of schematic or board item that is concerned */
115 
116  EDA_ITEM* m_link; /* Pointer on another item. Used in undo redo command
117  * used when a duplicate exists i.e. when an item is
118  * modified, and the copy of initial item exists (the
119  * duplicate) m_Item points the duplicate (i.e the old
120  * copy of an active item) and m_Link points the active
121  * item in schematic */
122 
123  BASE_SCREEN* m_screen; /* For new and deleted items the screen the item should
124  * be added to/removed from. */
125 
126 };
127 
128 
135 {
136 private:
137  std::vector <ITEM_PICKER> m_ItemsList;
138 
139 public:
142 
148  void PushItem( const ITEM_PICKER& aItem );
149 
154 
158  bool ContainsItem( const EDA_ITEM* aItem ) const;
159 
164  int FindItem( const EDA_ITEM* aItem ) const;
165 
169  void ClearItemsList();
170 
176 
180  unsigned GetCount() const
181  {
182  return m_ItemsList.size();
183  }
184 
193 
199  ITEM_PICKER GetItemWrapper( unsigned int aIdx ) const;
200 
205  EDA_ITEM* GetPickedItem( unsigned int aIdx ) const;
206 
211  BASE_SCREEN* GetScreenForItem( unsigned int aIdx ) const;
212 
217  EDA_ITEM* GetPickedItemLink( unsigned int aIdx ) const;
218 
224  UNDO_REDO GetPickedItemStatus( unsigned int aIdx ) const;
225 
232  STATUS_FLAGS GetPickerFlags( unsigned aIdx ) const;
233 
239  bool SetPickedItem( EDA_ITEM* aItem, unsigned aIdx );
240 
247  bool SetPickedItem( EDA_ITEM* aItem, UNDO_REDO aStatus, unsigned aIdx );
248 
256  bool SetPickedItemLink( EDA_ITEM* aLink, unsigned aIdx );
257 
265  bool SetPickedItemStatus( UNDO_REDO aStatus, unsigned aIdx );
266 
274  bool SetPickerFlags( STATUS_FLAGS aFlags, unsigned aIdx );
275 
282  bool RemovePicker( unsigned aIdx );
283 
291  void CopyList( const PICKED_ITEMS_LIST& aSource );
292 };
293 
294 
299 {
300 public:
303 
304  void PushCommand( PICKED_ITEMS_LIST* aCommand );
305 
307 
308  void ClearCommandList();
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
EDA_ITEM * GetPickedItemLink(unsigned int aIdx) const
std::vector< ITEM_PICKER > m_ItemsList
int FindItem(const EDA_ITEM *aItem) const
void ReversePickersListOrder()
Reverse the order of pickers stored in this list.
EDA_ITEM * GetItem() const
BASE_SCREEN * GetScreenForItem(unsigned int aIdx) const
STATUS_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 SetLink(EDA_ITEM *aItem)
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
KICAD_T GetItemType() const
PICKED_ITEMS_LIST * PopCommand()
unsigned GetCount() const
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
EDA_ITEM * GetLink() const
void PushCommand(PICKED_ITEMS_LIST *aCommand)
KICAD_T m_pickedItemType
A holder to handle a list of undo (or redo) commands.
void CopyList(const PICKED_ITEMS_LIST &aSource)
Copy all data from aSource to the list.
std::vector< PICKED_ITEMS_LIST * > m_CommandsList
bool SetPickedItem(EDA_ITEM *aItem, unsigned aIdx)
Handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:40
void SetStatus(UNDO_REDO aStatus)
UNDO_REDO m_undoRedoStatus
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
unsigned STATUS_FLAGS
Definition: eda_item.h:144
STATUS_FLAGS GetFlags() const
void SetFlags(STATUS_FLAGS aFlags)
bool RemovePicker(unsigned aIdx)
Remove one entry (one picker) from the list of picked items.
A holder to handle information on schematic or board items.
bool SetPickerFlags(STATUS_FLAGS aFlags, unsigned aIdx)
Set the flags of the picker (usually to the picked item m_flags value).
void SetItem(EDA_ITEM *aItem)
STATUS_FLAGS m_pickerFlags
ITEM_PICKER GetItemWrapper(unsigned int aIdx) const
bool SetPickedItemStatus(UNDO_REDO aStatus, unsigned aIdx)
Set the type of undo/redo operation for a given picked item.
EDA_ITEM * m_pickedItem
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:149
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.
BASE_SCREEN * GetScreen() const
UNDO_REDO GetPickedItemStatus(unsigned int aIdx) const
BASE_SCREEN * m_screen
bool ContainsItem(const EDA_ITEM *aItem) const
void ClearListAndDeleteItems()
Delete the list of pickers AND the data pointed by #m_PickedItem or #m_PickedItemLink according to th...
UNDO_REDO GetStatus() const
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:162