KiCad PCB EDA Suite
class_undoredo_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)
75 };
77 
78 
80 {
81 private:
82  STATUS_FLAGS m_pickerFlags; /* a copy of m_Flags member. useful in mode/drag
83  * undo/redo commands */
84  UNDO_REDO_T m_undoRedoStatus; /* type of operation to undo/redo for this item */
85  EDA_ITEM* m_pickedItem; /* Pointer on the schematic or board item that is concerned
86  * (picked), or in undo redo commands, the copy of an
87  * edited item. */
88  KICAD_T m_pickedItemType; /* type of schematic or board item that is concerned */
89 
90  EDA_ITEM* m_link; /* Pointer on an other item. Used in undo redo command
91  * used when a duplicate exists i.e. when an item is
92  * modified, and the copy of initial item exists (the
93  * duplicate) m_Item points the duplicate (i.e the old
94  * copy of an active item) and m_Link points the active
95  * item in schematic */
96 
97 public:
98  ITEM_PICKER( EDA_ITEM* aItem = NULL, UNDO_REDO_T aUndoRedoStatus = UR_UNSPECIFIED );
99 
100  EDA_ITEM* GetItem() const { return m_pickedItem; }
101 
102  void SetItem( EDA_ITEM* aItem )
103  {
104  m_pickedItem = aItem;
105  m_pickedItemType = aItem ? aItem->Type() : TYPE_NOT_INIT;
106  }
107 
109 
110  void SetStatus( UNDO_REDO_T aStatus ) { m_undoRedoStatus = aStatus; }
111 
113 
114  void SetFlags( STATUS_FLAGS aFlags ) { m_pickerFlags = aFlags; }
115 
116  STATUS_FLAGS GetFlags() const { return m_pickerFlags; }
117 
118  void SetLink( EDA_ITEM* aItem ) { m_link = aItem; }
119 
120  EDA_ITEM* GetLink() const { return m_link; }
121 };
122 
123 
130 {
131 public:
132  UNDO_REDO_T m_Status; /* info about operation to undo/redo for this item. can be
133  * UR_UNSPECIFIED */
134  wxPoint m_TransformPoint; /* used to undo redo command by the same command: usually
135  * need to know the rotate point or the move vector */
136 
137 private:
138  std::vector <ITEM_PICKER> m_ItemsList;
139 
140 public:
143 
149  void PushItem( const ITEM_PICKER& aItem );
150 
156 
161  bool ContainsItem( const EDA_ITEM* aItem ) const;
162 
168  int FindItem( const EDA_ITEM* aItem ) const;
169 
174  void ClearItemsList();
175 
182 
187  unsigned GetCount() const
188  {
189  return m_ItemsList.size();
190  }
191 
201 
209  ITEM_PICKER GetItemWrapper( unsigned int aIdx ) const;
210 
216  EDA_ITEM* GetPickedItem( unsigned int aIdx ) const;
217 
223  EDA_ITEM* GetPickedItemLink( unsigned int aIdx ) const;
224 
231  UNDO_REDO_T GetPickedItemStatus( unsigned int aIdx ) const;
232 
239  STATUS_FLAGS GetPickerFlags( unsigned aIdx ) const;
240 
247  bool SetPickedItem( EDA_ITEM* aItem, unsigned aIdx );
248 
256  bool SetPickedItem( EDA_ITEM* aItem, UNDO_REDO_T aStatus, unsigned aIdx );
257 
265  bool SetPickedItemLink( EDA_ITEM* aLink, unsigned aIdx );
266 
274  bool SetPickedItemStatus( UNDO_REDO_T aStatus, unsigned aIdx );
275 
283  bool SetPickerFlags( STATUS_FLAGS aFlags, unsigned aIdx );
284 
291  bool RemovePicker( unsigned aIdx );
292 
299  void CopyList( const PICKED_ITEMS_LIST& aSource );
300 };
301 
302 
309 {
310 public:
311  std::vector <PICKED_ITEMS_LIST*> m_CommandsList; // the list of possible undo/redo commands
312 
313 public:
314 
317 
318  void PushCommand( PICKED_ITEMS_LIST* aCommand );
319 
321 
322  void ClearCommandList();
323 };
324 
325 
326 #endif // _CLASS_UNDOREDO_CONTAINER_H
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
std::vector< ITEM_PICKER > m_ItemsList
Use for changing the schematic text type where swapping data structure is insufficient to restor the ...
ITEM_PICKER(EDA_ITEM *aItem=NULL, UNDO_REDO_T aUndoRedoStatus=UR_UNSPECIFIED)
void ReversePickersListOrder()
Function ReversePickersListOrder reverses the order of pickers stored in this list.
void SetStatus(UNDO_REDO_T aStatus)
STATUS_FLAGS GetFlags() const
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
void SetLink(EDA_ITEM *aItem)
UNDO_REDO_T GetPickedItemStatus(unsigned int aIdx) const
Function GetPickedItemStatus.
PICKED_ITEMS_LIST * PopCommand()
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:90
EDA_ITEM * GetPickedItemLink(unsigned int aIdx) const
Function GetPickedItemLink.
UNDO_REDO_T GetStatus() const
void PushCommand(PICKED_ITEMS_LIST *aCommand)
UNDO_REDO_T
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
Class UNDO_REDO_CONTAINER is a holder to handle alist of undo (or redo) command.
bool ContainsItem(const EDA_ITEM *aItem) const
Function IsItemInList.
void CopyList(const PICKED_ITEMS_LIST &aSource)
Function CopyList copies all data from aSource to the list.
EDA_ITEM * GetItem() const
std::vector< PICKED_ITEMS_LIST * > m_CommandsList
bool SetPickedItem(EDA_ITEM *aItem, unsigned aIdx)
Function SetPickedItem.
unsigned STATUS_FLAGS
Definition: base_struct.h:158
void SetFlags(STATUS_FLAGS aFlags)
bool RemovePicker(unsigned aIdx)
Function RemovePicker removes one entry (one picker) from the list of picked items.
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
bool SetPickerFlags(STATUS_FLAGS aFlags, unsigned aIdx)
Function SetPickerFlags set the flags of the picker (usually to the picked item m_Flags value) ...
void SetItem(EDA_ITEM *aItem)
STATUS_FLAGS m_pickerFlags
unsigned GetCount() const
Function GetCount.
STATUS_FLAGS GetPickerFlags(unsigned aIdx) const
Function GetPickerFlags returns the value of the picker flag.
bool SetPickedItemStatus(UNDO_REDO_T aStatus, unsigned aIdx)
Function SetPickedItemStatus sets the type of undo/redo operation for a given picked item...
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
Function GetPickedItem.
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:165
ITEM_PICKER PopItem()
Function PopItem.
void ClearItemsList()
Function ClearItemsList deletes only the list of pickers, NOT the picked data itself.
bool SetPickedItemLink(EDA_ITEM *aLink, unsigned aIdx)
Function SetPickedItemLink set the link associated to a given picked item.
UNDO_REDO_T m_undoRedoStatus
Basic classes for most KiCad items.
int FindItem(const EDA_ITEM *aItem) const
Function FindItem.
ITEM_PICKER GetItemWrapper(unsigned int aIdx) const
Function GetItemWrapper.
EDA_ITEM * GetLink() const
void ClearListAndDeleteItems()
Function ClearListAndDeleteItems deletes the list of pickers, AND the data pointed by m_PickedItem or...