Wed, 10 Apr 2013 14:10:58 +0300
Added history management for cut and paste, copy doesn't alter the object list by itself so it doesn't touch history
| 
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 | #include "history.h" | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
20 | #include "ldtypes.h" | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
21 | #include "file.h" | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
22 | #include "misc.h" | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
23 | #include "gui.h" | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
24 | |
| 
92
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
25 | EXTERN_ACTION (undo) | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
26 | EXTERN_ACTION (redo) | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
27 | |
| 
85
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
28 | // ============================================================================= | 
| 
89
 
5e6c08e98dbf
Allow undo of set color
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
85 
diff
changeset
 | 
29 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | 
| 
 
5e6c08e98dbf
Allow undo of set color
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
85 
diff
changeset
 | 
30 | // ============================================================================= | 
| 
91
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
31 | namespace History { | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
32 | std::vector<HistoryEntry*> entries; | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
33 | |
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
34 | static long lPos = -1; | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
35 | |
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
36 | // ========================================================================= | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
37 | void addEntry (HistoryEntry* entry) { | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
38 | // If there's any entries after our current position, we need to remove them now | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
39 | for (ulong i = lPos + 1; i < entries.size(); ++i) { | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
40 | |
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
41 | delete entries[i]; | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
42 | entries.erase (entries.begin() + i); | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
43 | } | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
44 | |
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
45 | entries.push_back (entry); | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
46 | lPos++; | 
| 
92
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
47 | |
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
48 | updateActions (); | 
| 
91
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
49 | } | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
50 | |
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
51 | // ========================================================================= | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
52 | void undo () { | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
53 | if (lPos == -1) | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
54 | return; // nothing to undo | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
55 | |
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
56 | entries[lPos--]->undo (); | 
| 
92
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
57 | updateActions (); | 
| 
91
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
58 | } | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
59 | |
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
60 | // ========================================================================= | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
61 | void redo () { | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
62 | if (lPos == (long) entries.size () - 1) | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
63 | return; // nothing to redo; | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
64 | |
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
65 | entries[++lPos]->redo (); | 
| 
92
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
66 | updateActions (); | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
67 | } | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
68 | |
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
69 | // ========================================================================= | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
70 | void updateActions () { | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
71 | ACTION_NAME (undo)->setEnabled (lPos > -1); | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
72 | ACTION_NAME (redo)->setEnabled (lPos < (long) entries.size () - 1); | 
| 
91
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
73 | } | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
74 | } | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
75 | |
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
76 | // ============================================================================= | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
77 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
78 | // ============================================================================= | 
| 
85
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
79 | void DeleteHistory::undo () { | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
80 | for (ulong i = 0; i < cache.size(); ++i) { | 
| 
94
 
a9e67f6e610e
Added history management for cut and paste, copy doesn't alter the object list by itself so it doesn't touch history
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
93 
diff
changeset
 | 
81 | ulong idx = cache.size() - i - 1; | 
| 
 
a9e67f6e610e
Added history management for cut and paste, copy doesn't alter the object list by itself so it doesn't touch history
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
93 
diff
changeset
 | 
82 | LDObject* obj = cache[idx]->clone (); | 
| 
 
a9e67f6e610e
Added history management for cut and paste, copy doesn't alter the object list by itself so it doesn't touch history
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
93 
diff
changeset
 | 
83 | g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + indices[idx], obj); | 
| 
85
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
84 | } | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
85 | |
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
86 | g_ForgeWindow->refresh (); | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
87 | } | 
| 
 
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 | // ============================================================================= | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
90 | void DeleteHistory::redo () { | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
91 | for (ulong i = 0; i < cache.size(); ++i) { | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
92 | LDObject* obj = g_CurrentFile->objects[indices[i]]; | 
| 
 
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 | g_CurrentFile->forgetObject (obj); | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
95 | delete obj; | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
96 | } | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
97 | |
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
98 | g_ForgeWindow->refresh (); | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
99 | } | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
100 | |
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
101 | // ============================================================================= | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
102 | DeleteHistory::~DeleteHistory () { | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
103 | for (LDObject* obj : cache) | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
104 | delete obj; | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
105 | } | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
106 | |
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
107 | // ============================================================================= | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
108 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | 
| 
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
109 | // ============================================================================= | 
| 
89
 
5e6c08e98dbf
Allow undo of set color
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
85 
diff
changeset
 | 
110 | void SetColorHistory::undo () { | 
| 
 
5e6c08e98dbf
Allow undo of set color
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
85 
diff
changeset
 | 
111 | // Restore colors | 
| 
 
5e6c08e98dbf
Allow undo of set color
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
85 
diff
changeset
 | 
112 | for (ulong i = 0; i < ulaIndices.size (); ++i) | 
| 
 
5e6c08e98dbf
Allow undo of set color
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
85 
diff
changeset
 | 
113 | g_CurrentFile->objects[ulaIndices[i]]->dColor = daColors[i]; | 
| 
 
5e6c08e98dbf
Allow undo of set color
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
85 
diff
changeset
 | 
114 | |
| 
 
5e6c08e98dbf
Allow undo of set color
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
85 
diff
changeset
 | 
115 | g_ForgeWindow->refresh (); | 
| 
 
5e6c08e98dbf
Allow undo of set color
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
85 
diff
changeset
 | 
116 | } | 
| 
 
5e6c08e98dbf
Allow undo of set color
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
85 
diff
changeset
 | 
117 | |
| 
 
5e6c08e98dbf
Allow undo of set color
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
85 
diff
changeset
 | 
118 | void SetColorHistory::redo () { | 
| 
 
5e6c08e98dbf
Allow undo of set color
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
85 
diff
changeset
 | 
119 | // Re-set post color | 
| 
 
5e6c08e98dbf
Allow undo of set color
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
85 
diff
changeset
 | 
120 | for (ulong i = 0; i < ulaIndices.size (); ++i) | 
| 
 
5e6c08e98dbf
Allow undo of set color
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
85 
diff
changeset
 | 
121 | g_CurrentFile->objects[ulaIndices[i]]->dColor = dNewColor; | 
| 
 
5e6c08e98dbf
Allow undo of set color
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
85 
diff
changeset
 | 
122 | |
| 
 
5e6c08e98dbf
Allow undo of set color
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
85 
diff
changeset
 | 
123 | g_ForgeWindow->refresh (); | 
| 
 
5e6c08e98dbf
Allow undo of set color
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
85 
diff
changeset
 | 
124 | } | 
| 
 
5e6c08e98dbf
Allow undo of set color
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
85 
diff
changeset
 | 
125 | |
| 
90
 
03f718ed5b33
Added history handling for set contents
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
89 
diff
changeset
 | 
126 | SetColorHistory::~SetColorHistory () {} | 
| 
 
03f718ed5b33
Added history handling for set contents
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
89 
diff
changeset
 | 
127 | |
| 
 
03f718ed5b33
Added history handling for set contents
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
89 
diff
changeset
 | 
128 | // ============================================================================= | 
| 
 
03f718ed5b33
Added history handling for set contents
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
89 
diff
changeset
 | 
129 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | 
| 
 
03f718ed5b33
Added history handling for set contents
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
89 
diff
changeset
 | 
130 | // ============================================================================= | 
| 
 
03f718ed5b33
Added history handling for set contents
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
89 
diff
changeset
 | 
131 | void SetContentsHistory::undo () { | 
| 
 
03f718ed5b33
Added history handling for set contents
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
89 
diff
changeset
 | 
132 | LDObject* obj = g_CurrentFile->objects[ulIndex]; | 
| 
 
03f718ed5b33
Added history handling for set contents
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
89 
diff
changeset
 | 
133 | obj->replace (oldObj->clone ()); | 
| 
 
03f718ed5b33
Added history handling for set contents
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
89 
diff
changeset
 | 
134 | g_ForgeWindow->refresh (); | 
| 
 
03f718ed5b33
Added history handling for set contents
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
89 
diff
changeset
 | 
135 | } | 
| 
 
03f718ed5b33
Added history handling for set contents
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
89 
diff
changeset
 | 
136 | |
| 
 
03f718ed5b33
Added history handling for set contents
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
89 
diff
changeset
 | 
137 | void SetContentsHistory::redo () { | 
| 
 
03f718ed5b33
Added history handling for set contents
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
89 
diff
changeset
 | 
138 | LDObject* obj = g_CurrentFile->objects[ulIndex]; | 
| 
 
03f718ed5b33
Added history handling for set contents
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
89 
diff
changeset
 | 
139 | obj->replace (newObj->clone ()); | 
| 
 
03f718ed5b33
Added history handling for set contents
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
89 
diff
changeset
 | 
140 | g_ForgeWindow->refresh (); | 
| 
 
03f718ed5b33
Added history handling for set contents
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
89 
diff
changeset
 | 
141 | } | 
| 
 
03f718ed5b33
Added history handling for set contents
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
89 
diff
changeset
 | 
142 | |
| 
 
03f718ed5b33
Added history handling for set contents
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
89 
diff
changeset
 | 
143 | SetContentsHistory::~SetContentsHistory () { | 
| 
 
03f718ed5b33
Added history handling for set contents
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
89 
diff
changeset
 | 
144 | delete oldObj; | 
| 
 
03f718ed5b33
Added history handling for set contents
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
89 
diff
changeset
 | 
145 | delete newObj; | 
| 
 
03f718ed5b33
Added history handling for set contents
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
89 
diff
changeset
 | 
146 | } | 
| 
 
03f718ed5b33
Added history handling for set contents
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
89 
diff
changeset
 | 
147 | |
| 
89
 
5e6c08e98dbf
Allow undo of set color
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
85 
diff
changeset
 | 
148 | // ============================================================================= | 
| 
 
5e6c08e98dbf
Allow undo of set color
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
85 
diff
changeset
 | 
149 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | 
| 
 
5e6c08e98dbf
Allow undo of set color
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
85 
diff
changeset
 | 
150 | // ============================================================================= | 
| 
91
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
151 | std::vector<LDObject*> ListMoveHistory::getObjects (short ofs) { | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
152 | std::vector<LDObject*> objs; | 
| 
85
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
153 | |
| 
91
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
154 | for (ulong idx : ulaIndices) | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
155 | objs.push_back (g_CurrentFile->objects[idx + ofs]); | 
| 
85
 
b1541b547c8c
Added undo/redo foundations. Capable of undoing and redoing delete operations
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents:  
diff
changeset
 | 
156 | |
| 
91
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
157 | return objs; | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
158 | } | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
159 | |
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
160 | void ListMoveHistory::undo () { | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
161 | std::vector<LDObject*> objs = getObjects (bUp ? -1 : 1); | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
162 | LDObject::moveObjects (objs, !bUp); | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
163 | g_ForgeWindow->buildObjList (); | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
164 | } | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
165 | |
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
166 | void ListMoveHistory::redo () { | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
167 | std::vector<LDObject*> objs = getObjects (0); | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
168 | LDObject::moveObjects (objs, bUp); | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
169 | g_ForgeWindow->buildObjList (); | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
170 | } | 
| 
 
b4dda6348e7e
History handling for list moving
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
90 
diff
changeset
 | 
171 | |
| 
92
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
172 | ListMoveHistory::~ListMoveHistory() {} | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
173 | |
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
174 | // ============================================================================= | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
175 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
176 | // ============================================================================= | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
177 | AdditionHistory::~AdditionHistory () { | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
178 | for (LDObject* pObj : paObjs) | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
179 | delete pObj; | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
180 | } | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
181 | |
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
182 | void AdditionHistory::undo () { | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
183 | for (ulong i = 0; i < paObjs.size(); ++i) { | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
184 | ulong idx = ulaIndices[ulaIndices.size() - i - 1]; | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
185 | LDObject* obj = g_CurrentFile->objects[idx]; | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
186 | |
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
187 | g_CurrentFile->forgetObject (obj); | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
188 | delete obj; | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
189 | } | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
190 | |
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
191 | g_ForgeWindow->refresh (); | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
192 | } | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
193 | |
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
194 | void AdditionHistory::redo () { | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
195 | for (ulong i = 0; i < paObjs.size(); ++i) { | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
196 | ulong idx = ulaIndices[i]; | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
197 | LDObject* obj = paObjs[i]->clone (); | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
198 | |
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
199 | g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + idx, obj); | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
200 | } | 
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
201 | |
| 
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
202 | g_ForgeWindow->refresh (); | 
| 
93
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
203 | } | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
204 | |
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
205 | // ============================================================================= | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
206 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
207 | // ============================================================================= | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
208 | QuadSplitHistory::~QuadSplitHistory () { | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
209 | for (LDQuad* pQuad : paQuads) | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
210 | delete pQuad; | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
211 | } | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
212 | |
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
213 | void QuadSplitHistory::undo () { | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
214 | for (ulong i = 0; i < paQuads.size(); ++i) { | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
215 | // The quad was replaced by the first triangle and a second one was | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
216 | // added after it. Thus, we remove the second one here and replace | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
217 | // the first with a copy of the quad. | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
218 | ulong idx = ulaIndices[i]; | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
219 | printf ("%lu (%lu)\n", i, idx); | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
220 | |
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
221 | LDTriangle* tri1 = static_cast<LDTriangle*> (g_CurrentFile->objects[idx]), | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
222 | *tri2 = static_cast<LDTriangle*> (g_CurrentFile->objects[idx + 1]); | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
223 | LDQuad* pCopy = paQuads[i]->clone (); | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
224 | |
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
225 | tri1->replace (pCopy); | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
226 | g_CurrentFile->forgetObject (tri2); | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
227 | delete tri2; | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
228 | } | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
229 | |
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
230 | g_ForgeWindow->refresh (); | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
231 | } | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
232 | |
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
233 | void QuadSplitHistory::redo () { | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
234 | for (long i = paQuads.size() - 1; i >= 0; --i) { | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
235 | ulong idx = ulaIndices[i]; | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
236 | |
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
237 | printf ("redo: %ld (%lu)\n", i, idx); | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
238 | |
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
239 | LDQuad* pQuad = static_cast<LDQuad*> (g_CurrentFile->objects[idx]); | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
240 | std::vector<LDTriangle*> paTriangles = pQuad->splitToTriangles (); | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
241 | |
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
242 | g_CurrentFile->objects[idx] = paTriangles[0]; | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
243 | g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + idx + 1, paTriangles[1]); | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
244 | delete pQuad; | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
245 | } | 
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
246 | |
| 
 
92682e6369e9
Added history handling for quad splitting.
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
92 
diff
changeset
 | 
247 | g_ForgeWindow->refresh (); | 
| 
92
 
586d294ca83f
Added history management for auto-bordering (and mass-addition in general)
 
Santeri Piippo <crimsondusk64@gmail.com> 
parents: 
91 
diff
changeset
 | 
248 | } |