src/history.h

changeset 183
f1b8cb53d2a2
child 185
6fea53f1ffc2
equal deleted inserted replaced
182:9374fea8f77f 183:f1b8cb53d2a2
1 /*
2 * LDForge: LDraw parts authoring CAD
3 * Copyright (C) 2013 Santeri Piippo
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifndef HISTORY_H
20 #define HISTORY_H
21
22 #include "common.h"
23 #include "ldtypes.h"
24
25 #define IMPLEMENT_HISTORY_TYPE(N) \
26 virtual ~N##History (); \
27 virtual void undo (); \
28 virtual void redo (); \
29 virtual HistoryType type () { return HISTORY_##N; }
30
31 // =============================================================================
32 enum HistoryType {
33 HISTORY_Del,
34 HISTORY_SetColor,
35 HISTORY_Edit,
36 HISTORY_ListMove,
37 HISTORY_Add,
38 HISTORY_QuadSplit,
39 HISTORY_Inline,
40 HISTORY_Move,
41 HISTORY_Combo,
42 };
43
44 // =============================================================================
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
46 // =============================================================================
47 class HistoryEntry {
48 public:
49 virtual void undo () {}
50 virtual void redo () {}
51 virtual ~HistoryEntry () {}
52 virtual HistoryType type () { return (HistoryType)(0); }
53 };
54
55 // =============================================================================
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
57 // =============================================================================
58 class DelHistory : public HistoryEntry {
59 public:
60 enum Type {
61 Cut, // were deleted with a cut operation
62 Other, // were deleted witout specific reason
63 };
64
65 IMPLEMENT_HISTORY_TYPE (Del)
66
67 vector<ulong> indices;
68 vector<LDObject*> cache;
69 const Type eType;
70
71 DelHistory (vector<ulong> indices, vector<LDObject*> cache, const Type eType = Other) :
72 indices (indices), cache (cache), eType (eType) {}
73 };
74
75 // =============================================================================
76 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
77 // =============================================================================
78 class SetColorHistory : public HistoryEntry {
79 public:
80 IMPLEMENT_HISTORY_TYPE (SetColor)
81
82 vector<ulong> ulaIndices;
83 vector<short> daColors;
84 short dNewColor;
85
86 SetColorHistory (vector<ulong> ulaIndices, vector<short> daColors, short dNewColor) :
87 ulaIndices (ulaIndices), daColors (daColors), dNewColor (dNewColor) {}
88 };
89
90 // =============================================================================
91 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
92 // =============================================================================
93 class EditHistory : public HistoryEntry {
94 public:
95 IMPLEMENT_HISTORY_TYPE (Edit)
96
97 const std::vector<ulong> ulaIndices;
98 const std::vector<LDObject*> paOldObjs, paNewObjs;
99
100 EditHistory (std::vector<ulong> ulaIndices, std::vector<LDObject*> paOldObjs,
101 std::vector<LDObject*> paNewObjs) :
102 ulaIndices (ulaIndices), paOldObjs (paOldObjs), paNewObjs (paNewObjs) {}
103 };
104
105 // =============================================================================
106 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
107 // =============================================================================
108 class ListMoveHistory : public HistoryEntry {
109 public:
110 IMPLEMENT_HISTORY_TYPE (ListMove)
111
112 std::vector<ulong> ulaIndices;
113 bool bUp;
114
115 std::vector<LDObject*> getObjects (short ofs);
116 ListMoveHistory (vector<ulong> ulaIndices, const bool bUp) :
117 ulaIndices (ulaIndices), bUp (bUp) {}
118 };
119
120 // =============================================================================
121 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
122 // =============================================================================
123 class AddHistory : public HistoryEntry {
124 public:
125 enum Type {
126 Other, // was "just added"
127 Paste, // was added through a paste operation
128 };
129
130 IMPLEMENT_HISTORY_TYPE (Add)
131
132 std::vector<ulong> ulaIndices;
133 std::vector<LDObject*> paObjs;
134 const Type eType;
135
136 AddHistory (std::vector<ulong> ulaIndices, std::vector<LDObject*> paObjs,
137 const Type eType = Other) :
138 ulaIndices (ulaIndices), paObjs (paObjs), eType (eType) {}
139 };
140
141 // =============================================================================
142 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
143 // =============================================================================
144 class QuadSplitHistory : public HistoryEntry {
145 public:
146 IMPLEMENT_HISTORY_TYPE (QuadSplit)
147
148 std::vector<ulong> ulaIndices;
149 std::vector<LDQuad*> paQuads;
150
151 QuadSplitHistory (std::vector<ulong> ulaIndices, std::vector<LDQuad*> paQuads) :
152 ulaIndices (ulaIndices), paQuads (paQuads) {}
153 };
154
155 // =============================================================================
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
157 // =============================================================================
158 class InlineHistory : public HistoryEntry {
159 public:
160 IMPLEMENT_HISTORY_TYPE (Inline)
161
162 const std::vector<ulong> ulaBitIndices, ulaRefIndices;
163 const std::vector<LDSubfile*> paRefs;
164 const bool bDeep;
165
166 InlineHistory (const std::vector<ulong> ulaBitIndices, const std::vector<ulong> ulaRefIndices,
167 const std::vector<LDSubfile*> paRefs, const bool bDeep) :
168 ulaBitIndices (ulaBitIndices), ulaRefIndices (ulaRefIndices), paRefs (paRefs), bDeep (bDeep) {}
169 };
170
171 // =============================================================================
172 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
173 // =============================================================================
174 class MoveHistory : public HistoryEntry {
175 public:
176 IMPLEMENT_HISTORY_TYPE (Move)
177
178 const std::vector<ulong> ulaIndices;
179 const vertex vVector;
180
181 MoveHistory (const std::vector<ulong> ulaIndices, const vertex vVector) :
182 ulaIndices (ulaIndices), vVector (vVector) {}
183 };
184
185 // =============================================================================
186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
187 // =============================================================================
188 class ComboHistory : public HistoryEntry {
189 public:
190 IMPLEMENT_HISTORY_TYPE (Combo)
191
192 std::vector<HistoryEntry*> paEntries;
193
194 ComboHistory (std::vector<HistoryEntry*> paEntries) : paEntries (paEntries) {}
195
196 ComboHistory& operator<< (HistoryEntry* entry) {
197 paEntries.push_back (entry);
198 return *this;
199 }
200 };
201
202 // =============================================================================
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
204 // =============================================================================
205 namespace History {
206 void addEntry (HistoryEntry* entry);
207 void undo ();
208 void redo ();
209 void clear ();
210 void updateActions ();
211 long pos ();
212 std::vector<HistoryEntry*>& entries ();
213 };
214
215 #endif // HISTORY_H

mercurial