198 g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + idx, obj); |
198 g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + idx, obj); |
199 } |
199 } |
200 |
200 |
201 g_ForgeWindow->refresh (); |
201 g_ForgeWindow->refresh (); |
202 } |
202 } |
|
203 |
|
204 // ============================================================================= |
|
205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
206 // ============================================================================= |
|
207 QuadSplitHistory::~QuadSplitHistory () { |
|
208 for (LDQuad* pQuad : paQuads) |
|
209 delete pQuad; |
|
210 } |
|
211 |
|
212 void QuadSplitHistory::undo () { |
|
213 for (ulong i = 0; i < paQuads.size(); ++i) { |
|
214 // The quad was replaced by the first triangle and a second one was |
|
215 // added after it. Thus, we remove the second one here and replace |
|
216 // the first with a copy of the quad. |
|
217 ulong idx = ulaIndices[i]; |
|
218 printf ("%lu (%lu)\n", i, idx); |
|
219 |
|
220 LDTriangle* tri1 = static_cast<LDTriangle*> (g_CurrentFile->objects[idx]), |
|
221 *tri2 = static_cast<LDTriangle*> (g_CurrentFile->objects[idx + 1]); |
|
222 LDQuad* pCopy = paQuads[i]->clone (); |
|
223 |
|
224 tri1->replace (pCopy); |
|
225 g_CurrentFile->forgetObject (tri2); |
|
226 delete tri2; |
|
227 } |
|
228 |
|
229 g_ForgeWindow->refresh (); |
|
230 } |
|
231 |
|
232 void QuadSplitHistory::redo () { |
|
233 for (long i = paQuads.size() - 1; i >= 0; --i) { |
|
234 ulong idx = ulaIndices[i]; |
|
235 |
|
236 printf ("redo: %ld (%lu)\n", i, idx); |
|
237 |
|
238 LDQuad* pQuad = static_cast<LDQuad*> (g_CurrentFile->objects[idx]); |
|
239 std::vector<LDTriangle*> paTriangles = pQuad->splitToTriangles (); |
|
240 |
|
241 g_CurrentFile->objects[idx] = paTriangles[0]; |
|
242 g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + idx + 1, paTriangles[1]); |
|
243 delete pQuad; |
|
244 } |
|
245 |
|
246 g_ForgeWindow->refresh (); |
|
247 } |