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 class BASE_SCREEN;
35 
36 
50 /* Type of undo/redo operations
51  * each type must be redo/undone by a specific operation
52  */
53 enum class UNDO_REDO {
54  UNSPECIFIED = 0, // illegal
55  CHANGED, // params of items have a value changed: undo is made by exchange
56  // values with a copy of these values
57  NEWITEM, // new item, undo by changing in deleted
58  DELETED, // deleted item, undo by changing in deleted
59  MOVED, // moved item, undo by move it
60  MIRRORED_X, // mirrored item, undo by mirror X
61  MIRRORED_Y, // mirrored item, undo by mirror Y
62  ROTATED, // Rotated item (counterclockwise), undo by rotating it
63  ROTATED_CLOCKWISE, // Rotated item (clockwise), undo by rotating it
64  FLIPPED, // flipped (board items only), undo by flipping it
65  LIBEDIT, // Specific to the component editor (libedit 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  EXCHANGE_T, // Use for changing the schematic text type where swapping
69  // data structure is insufficient to restore the change.
70  DRILLORIGIN, // origin changed (like CHANGED, contains the origin and a copy)
71  GRIDORIGIN, // origin changed (like CHANGED, contains the origin and a copy)
72  PAGESETTINGS // page settings or title block changes
73 };
74 
75 
77 {
78 private:
79  STATUS_FLAGS m_pickerFlags; /* a copy of m_Flags member. useful in mode/drag
80  * undo/redo commands */
81  UNDO_REDO m_undoRedoStatus; /* type of operation to undo/redo for this item */
82  EDA_ITEM* m_pickedItem; /* Pointer on the schematic or board item that is concerned
83  * (picked), or in undo redo commands, the copy of an
84  * edited item. */
85  KICAD_T m_pickedItemType; /* type of schematic or board item that is concerned */
86 
87  EDA_ITEM* m_link; /* Pointer on another item. Used in undo redo command
88  * used when a duplicate exists i.e. when an item is
89  * modified, and the copy of initial item exists (the
90  * duplicate) m_Item points the duplicate (i.e the old
91  * copy of an active item) and m_Link points the active
92  * item in schematic */
93 
94  BASE_SCREEN* m_screen; /* For new and deleted items the screen the item should
95  * be added to/removed from. */
96 
97 public:
98 // ITEM_PICKER( EDA_ITEM* aItem = NULL, UNDO_REDO aStatus = UNSPECIFIED );
99  ITEM_PICKER();
100  ITEM_PICKER( BASE_SCREEN* aScreen, EDA_ITEM* aItem, UNDO_REDO aStatus = UNDO_REDO::UNSPECIFIED );
101 
102  EDA_ITEM* GetItem() const { return m_pickedItem; }
103 
104  void SetItem( EDA_ITEM* aItem )
105  {
106  m_pickedItem = aItem;
107  m_pickedItemType = aItem ? aItem->Type() : TYPE_NOT_INIT;
108  }
109 
111 
112  void SetStatus( UNDO_REDO aStatus ) { m_undoRedoStatus = aStatus; }
113 
115 
116  void SetFlags( STATUS_FLAGS aFlags ) { m_pickerFlags = aFlags; }
117 
118  STATUS_FLAGS GetFlags() const { return m_pickerFlags; }
119 
120  void SetLink( EDA_ITEM* aItem ) { m_link = aItem; }
121 
122  EDA_ITEM* GetLink() const { return m_link; }
123 
124  BASE_SCREEN* GetScreen() const { return m_screen; }
125 };
126 
127 
134 {
135 public:
136  UNDO_REDO m_Status; /* info about operation to undo/redo for this item. can be
137  * UNSPECIFIED */
138  wxPoint m_TransformPoint; /* used to undo redo command by the same command: usually
139  * need to know the rotate point or the move vector */
140 
141 private:
142  std::vector <ITEM_PICKER> m_ItemsList;
143 
144 public:
147 
153  void PushItem( const ITEM_PICKER& aItem );
154 
160 
165  bool ContainsItem( const EDA_ITEM* aItem ) const;
166 
172  int FindItem( const EDA_ITEM* aItem ) const;
173 
178  void ClearItemsList();
179 
186 
191  unsigned GetCount() const
192  {
193  return m_ItemsList.size();
194  }
195 
205 
213  ITEM_PICKER GetItemWrapper( unsigned int aIdx ) const;
214 
220  EDA_ITEM* GetPickedItem( unsigned int aIdx ) const;
221 
227  BASE_SCREEN* GetScreenForItem( unsigned int aIdx ) const;
228 
234  EDA_ITEM* GetPickedItemLink( unsigned int aIdx ) const;
235 
242  UNDO_REDO GetPickedItemStatus( unsigned int aIdx ) const;
243 
250  STATUS_FLAGS GetPickerFlags( unsigned aIdx ) const;
251 
258  bool SetPickedItem( EDA_ITEM* aItem, unsigned aIdx );
259 
267  bool SetPickedItem( EDA_ITEM* aItem, UNDO_REDO aStatus, unsigned aIdx );
268 
276  bool SetPickedItemLink( EDA_ITEM* aLink, unsigned aIdx );
277 
285  bool SetPickedItemStatus( UNDO_REDO aStatus, unsigned aIdx );
286 
294  bool SetPickerFlags( STATUS_FLAGS aFlags, unsigned aIdx );
295 
302  bool RemovePicker( unsigned aIdx );
303 
310  void CopyList( const PICKED_ITEMS_LIST& aSource );
311 };
312 
313 
320 {
321 public:
322  std::vector <PICKED_ITEMS_LIST*> m_CommandsList; // the list of possible undo/redo commands
323 
324 public:
325 
328 
329  void PushCommand( PICKED_ITEMS_LIST* aCommand );
330 
332 
333  void ClearCommandList();
334 };
335 
336 
337 #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.
void ReversePickersListOrder()
Function ReversePickersListOrder reverses the order of pickers stored in this list.
EDA_ITEM * GetItem() const
BASE_SCREEN * GetScreenForItem(unsigned int aIdx) const
Function GetScreenForItem.
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)
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
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.
std::vector< PICKED_ITEMS_LIST * > m_CommandsList
bool SetPickedItem(EDA_ITEM *aItem, unsigned aIdx)
Function SetPickedItem.
BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:43
void SetStatus(UNDO_REDO aStatus)
UNDO_REDO m_undoRedoStatus
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
Function GetPickedItem.
STATUS_FLAGS GetFlags() const
unsigned STATUS_FLAGS
Definition: base_struct.h:152
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 aStatus, unsigned aIdx)
Function SetPickedItemStatus sets the type of undo/redo operation for a given picked item.
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:159
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.
BASE_SCREEN * GetScreen() const
UNDO_REDO GetPickedItemStatus(unsigned int aIdx) const
Function GetPickedItemStatus.
BASE_SCREEN * m_screen
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...
UNDO_REDO GetStatus() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193