history.h

Wed, 10 Apr 2013 02:40:52 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Wed, 10 Apr 2013 02:40:52 +0300
changeset 89
5e6c08e98dbf
parent 85
b1541b547c8c
child 90
03f718ed5b33
permissions
-rw-r--r--

Allow undo of set color

85
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2013 Santeri `arezey` Piippo
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #ifndef HISTORY_H
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #define HISTORY_H
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include "common.h"
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #define IMPLEMENT_HISTORY_TYPE(N) \
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 virtual HistoryType_e getType () const { \
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 return HISTORY_##N; \
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 } \
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 enum HistoryType_e {
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 HISTORY_Delete,
89
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
31 HISTORY_SetColor,
85
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 };
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33
89
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
34 // =============================================================================
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
36 // =============================================================================
85
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 class HistoryEntry {
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 public:
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 virtual void undo () {}
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 virtual void redo () {}
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 virtual ~HistoryEntry () {}
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 virtual HistoryType_e getType () const {
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 return (HistoryType_e)(0);
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 };
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 };
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47
89
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
48 // =============================================================================
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
50 // =============================================================================
85
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 class DeleteHistory : public HistoryEntry {
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 public:
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 IMPLEMENT_HISTORY_TYPE (Delete)
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 vector<ulong> indices;
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 vector<LDObject*> cache;
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 DeleteHistory (vector<ulong> indices, vector<LDObject*> cache) :
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 indices (indices), cache (cache) {}
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 virtual ~DeleteHistory ();
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 virtual void undo ();
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 virtual void redo ();
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 };
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64
89
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
65 // =============================================================================
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
67 // =============================================================================
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
68 class SetColorHistory : public HistoryEntry {
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
69 public:
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
70 IMPLEMENT_HISTORY_TYPE (SetColor)
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
71
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
72 vector<ulong> ulaIndices;
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
73 vector<short> daColors;
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
74 short dNewColor;
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
75
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
76 SetColorHistory (vector<ulong> ulaIndices, vector<short> daColors, short dNewColor) :
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
77 ulaIndices (ulaIndices), daColors (daColors), dNewColor (dNewColor) {}
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
78 virtual ~SetColorHistory () {}
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
79 virtual void undo ();
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
80 virtual void redo ();
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
81 };
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
82
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
83 // =============================================================================
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
84 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
5e6c08e98dbf Allow undo of set color
Santeri Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
85 // =============================================================================
85
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 namespace History {
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 extern std::vector<HistoryEntry*> entries;
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 void addEntry (HistoryEntry* entry);
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 void undo ();
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 void redo ();
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 };
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93
b1541b547c8c Added undo/redo foundations. Capable of undoing and redoing delete operations
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 #endif // HISTORY_H

mercurial