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@verizon.net>
6  * Copyright (C) 2009 KiCad Developers, see change_log.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 <base_struct.h>
31 
32 
33 class PICKED_ITEMS_LIST;
34 
35 
56 /* Type of undo/redo operations
57  * each type must be redo/undone by a specific operation
58  */
60  UR_UNSPECIFIED = 0, // illegal
61  UR_CHANGED, // params of items have a value changed: undo is made by exchange
62  // values with a copy of these values
63  UR_NEW, // new item, undo by changing in deleted
64  UR_DELETED, // deleted item, undo by changing in deleted
65  UR_MOVED, // moved item, undo by move it
66  UR_MIRRORED_X, // mirrored item, undo by mirror X
67  UR_MIRRORED_Y, // mirrored item, undo by mirror Y
68  UR_ROTATED, // Rotated item (counterclockwise), undo by rotating it
69  UR_ROTATED_CLOCKWISE, // Rotated item (clockwise), undo by rotating it
70  UR_FLIPPED, // flipped (board items only), undo by flipping it
71  UR_WIRE_IMAGE, // Specific to Eeschema for handling wires changes.
72  UR_LIBEDIT, // Specific to the component editor (libedit creates a full copy
73  // of the current component when changed)
74  UR_LIB_RENAME, // As UR_LIBEDIT, but old copy should be removed from library
76  UR_DRILLORIGIN, // origin changed (like UR_CHANGED, contains the origin and a copy)
78  UR_GRIDORIGIN // origin changed (like UR_CHANGED, contains the origin and a copy)
79 };
80 
81 
83 {
84 private:
85  STATUS_FLAGS m_pickerFlags; /* a copy of m_Flags member. useful in mode/drag
86  * undo/redo commands */
87  UNDO_REDO_T m_undoRedoStatus; /* type of operation to undo/redo for this item */
88  EDA_ITEM* m_pickedItem; /* Pointer on the schematic or board item that is concerned
89  * (picked), or in undo redo commands, the copy of an
90  * edited item. */
91  KICAD_T m_pickedItemType; /* type of schematic or board item that is concerned */
92 
93  EDA_ITEM* m_link; /* Pointer on another item. Used in undo redo command
94  * used when a duplicate exists i.e. when an item is
95  * modified, and the copy of initial item exists (the
96  * duplicate) m_Item points the duplicate (i.e the old
97  * copy of an active item) and m_Link points the active
98  * item in schematic */
99 
100 public:
101  ITEM_PICKER( EDA_ITEM* aItem = NULL, UNDO_REDO_T aUndoRedoStatus = UR_UNSPECIFIED );
102 
103  EDA_ITEM* GetItem() const { return m_pickedItem; }
104 
105  void SetItem( EDA_ITEM* aItem )
106  {
107  m_pickedItem = aItem;
108  m_pickedItemType = aItem ? aItem->Type() : TYPE_NOT_INIT;
109  }
110 
112 
113  void SetStatus( UNDO_REDO_T aStatus ) { m_undoRedoStatus = aStatus; }
114 
116 
117  void SetFlags( STATUS_FLAGS aFlags ) { m_pickerFlags = aFlags; }
118 
119  STATUS_FLAGS GetFlags() const { return m_pickerFlags; }
120 
121  void SetLink( EDA_ITEM* aItem ) { m_link = aItem; }
122 
123  EDA_ITEM* GetLink() const { return m_link; }
124 };
125 
126 
133 {
134 public:
135  UNDO_REDO_T m_Status; /* info about operation to undo/redo for this item. can be
136  * UR_UNSPECIFIED */
137  wxPoint m_TransformPoint; /* used to undo redo command by the same command: usually
138  * need to know the rotate point or the move vector */
139 
140 private:
141  std::vector <ITEM_PICKER> m_ItemsList;
142 
143 public:
146 
152  void PushItem( const ITEM_PICKER& aItem );
153 
158  ITEM_PICKER PopItem();
159 
164  bool ContainsItem( const EDA_ITEM* aItem ) const;
165 
171  int FindItem( const EDA_ITEM* aItem ) const;
172 
177  void ClearItemsList();
178 
184  void ClearListAndDeleteItems();
185 
190  unsigned GetCount() const
191  {
192  return m_ItemsList.size();
193  }
194 
203  void ReversePickersListOrder();
204 
212  ITEM_PICKER GetItemWrapper( unsigned int aIdx ) const;
213 
219  EDA_ITEM* GetPickedItem( unsigned int aIdx ) const;
220 
226  EDA_ITEM* GetPickedItemLink( unsigned int aIdx ) const;
227 
234  UNDO_REDO_T GetPickedItemStatus( unsigned int aIdx ) const;
235 
242  STATUS_FLAGS GetPickerFlags( unsigned aIdx ) const;
243 
250  bool SetPickedItem( EDA_ITEM* aItem, unsigned aIdx );
251 
259  bool SetPickedItem( EDA_ITEM* aItem, UNDO_REDO_T aStatus, unsigned aIdx );
260 
268  bool SetPickedItemLink( EDA_ITEM* aLink, unsigned aIdx );
269 
277  bool SetPickedItemStatus( UNDO_REDO_T aStatus, unsigned aIdx );
278 
286  bool SetPickerFlags( STATUS_FLAGS aFlags, unsigned aIdx );
287 
294  bool RemovePicker( unsigned aIdx );
295 
302  void CopyList( const PICKED_ITEMS_LIST& aSource );
303 };
304 
305 
312 {
313 public:
314  std::vector <PICKED_ITEMS_LIST*> m_CommandsList; // the list of possible undo/redo commands
315 
316 public:
317 
320 
321  void PushCommand( PICKED_ITEMS_LIST* aCommand );
322 
323  PICKED_ITEMS_LIST* PopCommand();
324 
325  void ClearCommandList();
326 };
327 
328 
329 #endif // _CLASS_UNDOREDO_CONTAINER_H
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
std::vector< ITEM_PICKER > m_ItemsList
ITEM_PICKER(EDA_ITEM *aItem=NULL, UNDO_REDO_T aUndoRedoStatus=UR_UNSPECIFIED)
void SetStatus(UNDO_REDO_T aStatus)
UNDO_REDO_T
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
STATUS_FLAGS GetFlags() const
void SetLink(EDA_ITEM *aItem)
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
UNDO_REDO_T GetStatus() const
EDA_ITEM * m_link
KICAD_T m_pickedItemType
Class UNDO_REDO_CONTAINER is a holder to handle alist of undo (or redo) command.
EDA_ITEM * GetItem() const
std::vector< PICKED_ITEMS_LIST * > m_CommandsList
unsigned STATUS_FLAGS
Definition: base_struct.h:147
void SetFlags(STATUS_FLAGS aFlags)
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
Use for changing the schematic text type where swapping data structure is insufficient to restore the...
void SetItem(EDA_ITEM *aItem)
STATUS_FLAGS m_pickerFlags
unsigned GetCount() const
Function GetCount.
EDA_ITEM * m_pickedItem
KICAD_T GetItemType() const
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
UNDO_REDO_T m_undoRedoStatus
Basic classes for most KiCad items.
EDA_ITEM * GetLink() const