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 
49 /* Type of undo/redo operations
50  * each type must be redo/undone by a specific operation
51  */
53  UR_UNSPECIFIED = 0, // illegal
54  UR_CHANGED, // params of items have a value changed: undo is made by exchange
55  // values with a copy of these values
56  UR_NEW, // new item, undo by changing in deleted
57  UR_DELETED, // deleted item, undo by changing in deleted
58  UR_MOVED, // moved item, undo by move it
59  UR_MIRRORED_X, // mirrored item, undo by mirror X
60  UR_MIRRORED_Y, // mirrored item, undo by mirror Y
61  UR_ROTATED, // Rotated item (counterclockwise), undo by rotating it
62  UR_ROTATED_CLOCKWISE, // Rotated item (clockwise), undo by rotating it
63  UR_FLIPPED, // flipped (board items only), undo by flipping it
64  UR_LIBEDIT, // Specific to the component editor (libedit creates a full copy
65  // of the current component when changed)
66  UR_LIB_RENAME, // As UR_LIBEDIT, but old copy should be removed from library
67  UR_EXCHANGE_T, // Use for changing the schematic text type where swapping
68  // data structure is insufficient to restore the change.
69  UR_DRILLORIGIN, // origin changed (like UR_CHANGED, contains the origin and a copy)
70  UR_GRIDORIGIN, // origin changed (like UR_CHANGED, contains the origin and a copy)
71  UR_PAGESETTINGS // page settings or title block changes
72 };
73 
74 
76 {
77 private:
78  STATUS_FLAGS m_pickerFlags; /* a copy of m_Flags member. useful in mode/drag
79  * undo/redo commands */
80  UNDO_REDO_T m_undoRedoStatus; /* type of operation to undo/redo for this item */
81  EDA_ITEM* m_pickedItem; /* Pointer on the schematic or board item that is concerned
82  * (picked), or in undo redo commands, the copy of an
83  * edited item. */
84  KICAD_T m_pickedItemType; /* type of schematic or board item that is concerned */
85 
86  EDA_ITEM* m_link; /* Pointer on another item. Used in undo redo command
87  * used when a duplicate exists i.e. when an item is
88  * modified, and the copy of initial item exists (the
89  * duplicate) m_Item points the duplicate (i.e the old
90  * copy of an active item) and m_Link points the active
91  * item in schematic */
92 
93 public:
94  ITEM_PICKER( EDA_ITEM* aItem = NULL, UNDO_REDO_T aUndoRedoStatus = UR_UNSPECIFIED );
95 
96  EDA_ITEM* GetItem() const { return m_pickedItem; }
97 
98  void SetItem( EDA_ITEM* aItem )
99  {
100  m_pickedItem = aItem;
101  m_pickedItemType = aItem ? aItem->Type() : TYPE_NOT_INIT;
102  }
103 
105 
106  void SetStatus( UNDO_REDO_T aStatus ) { m_undoRedoStatus = aStatus; }
107 
109 
110  void SetFlags( STATUS_FLAGS aFlags ) { m_pickerFlags = aFlags; }
111 
112  STATUS_FLAGS GetFlags() const { return m_pickerFlags; }
113 
114  void SetLink( EDA_ITEM* aItem ) { m_link = aItem; }
115 
116  EDA_ITEM* GetLink() const { return m_link; }
117 };
118 
119 
126 {
127 public:
128  UNDO_REDO_T m_Status; /* info about operation to undo/redo for this item. can be
129  * UR_UNSPECIFIED */
130  wxPoint m_TransformPoint; /* used to undo redo command by the same command: usually
131  * need to know the rotate point or the move vector */
132 
133 private:
134  std::vector <ITEM_PICKER> m_ItemsList;
135 
136 public:
139 
145  void PushItem( const ITEM_PICKER& aItem );
146 
152 
157  bool ContainsItem( const EDA_ITEM* aItem ) const;
158 
164  int FindItem( const EDA_ITEM* aItem ) const;
165 
170  void ClearItemsList();
171 
178 
183  unsigned GetCount() const
184  {
185  return m_ItemsList.size();
186  }
187 
197 
205  ITEM_PICKER GetItemWrapper( unsigned int aIdx ) const;
206 
212  EDA_ITEM* GetPickedItem( unsigned int aIdx ) const;
213 
219  EDA_ITEM* GetPickedItemLink( unsigned int aIdx ) const;
220 
227  UNDO_REDO_T GetPickedItemStatus( unsigned int aIdx ) const;
228 
235  STATUS_FLAGS GetPickerFlags( unsigned aIdx ) const;
236 
243  bool SetPickedItem( EDA_ITEM* aItem, unsigned aIdx );
244 
252  bool SetPickedItem( EDA_ITEM* aItem, UNDO_REDO_T aStatus, unsigned aIdx );
253 
261  bool SetPickedItemLink( EDA_ITEM* aLink, unsigned aIdx );
262 
270  bool SetPickedItemStatus( UNDO_REDO_T aStatus, unsigned aIdx );
271 
279  bool SetPickerFlags( STATUS_FLAGS aFlags, unsigned aIdx );
280 
287  bool RemovePicker( unsigned aIdx );
288 
295  void CopyList( const PICKED_ITEMS_LIST& aSource );
296 };
297 
298 
305 {
306 public:
307  std::vector <PICKED_ITEMS_LIST*> m_CommandsList; // the list of possible undo/redo commands
308 
309 public:
310 
313 
314  void PushCommand( PICKED_ITEMS_LIST* aCommand );
315 
317 
318  void ClearCommandList();
319 };
320 
321 
322 #endif // _CLASS_UNDOREDO_CONTAINER_H
EDA_ITEM * GetPickedItemLink(unsigned int aIdx) const
Function GetPickedItemLink.
std::vector< ITEM_PICKER > m_ItemsList
int FindItem(const EDA_ITEM *aItem) const
Function FindItem.
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)
UNDO_REDO_T GetStatus() const
UNDO_REDO_T
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
EDA_ITEM * GetItem() const
STATUS_FLAGS GetPickerFlags(unsigned aIdx) const
Function GetPickerFlags returns the value of the picker flag.
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
void SetLink(EDA_ITEM *aItem)
KICAD_T GetItemType() const
PICKED_ITEMS_LIST * PopCommand()
unsigned GetCount() const
Function GetCount.
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
EDA_ITEM * GetLink() const
void PushCommand(PICKED_ITEMS_LIST *aCommand)
EDA_ITEM * m_link
KICAD_T m_pickedItemType
UNDO_REDO_CONTAINER is a holder to handle alist of undo (or redo) command.
void CopyList(const PICKED_ITEMS_LIST &aSource)
Function CopyList copies all data from aSource to the list.
#define NULL
std::vector< PICKED_ITEMS_LIST * > m_CommandsList
bool SetPickedItem(EDA_ITEM *aItem, unsigned aIdx)
Function SetPickedItem.
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
Function GetPickedItem.
STATUS_FLAGS GetFlags() const
unsigned STATUS_FLAGS
Definition: base_struct.h:156
void SetFlags(STATUS_FLAGS aFlags)
bool RemovePicker(unsigned aIdx)
Function RemovePicker removes one entry (one picker) from the list of picked items.
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
ITEM_PICKER GetItemWrapper(unsigned int aIdx) const
Function GetItemWrapper.
bool SetPickedItemStatus(UNDO_REDO_T aStatus, unsigned aIdx)
Function SetPickedItemStatus sets the type of undo/redo operation for a given picked item.
UNDO_REDO_T GetPickedItemStatus(unsigned int aIdx) const
Function GetPickedItemStatus.
EDA_ITEM * m_pickedItem
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:163
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
bool ContainsItem(const EDA_ITEM *aItem) const
Function IsItemInList.
void ClearListAndDeleteItems()
Function ClearListAndDeleteItems deletes the list of pickers, AND the data pointed by m_PickedItem or...
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207