diff -r 9374fea8f77f -r f1b8cb53d2a2 src/history.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/history.h Wed May 08 15:19:06 2013 +0300
@@ -0,0 +1,215 @@
+/*
+ * LDForge: LDraw parts authoring CAD
+ * Copyright (C) 2013 Santeri Piippo
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef HISTORY_H
+#define HISTORY_H
+
+#include "common.h"
+#include "ldtypes.h"
+
+#define IMPLEMENT_HISTORY_TYPE(N) \
+ virtual ~N##History (); \
+ virtual void undo (); \
+ virtual void redo (); \
+ virtual HistoryType type () { return HISTORY_##N; }
+
+// =============================================================================
+enum HistoryType {
+ HISTORY_Del,
+ HISTORY_SetColor,
+ HISTORY_Edit,
+ HISTORY_ListMove,
+ HISTORY_Add,
+ HISTORY_QuadSplit,
+ HISTORY_Inline,
+ HISTORY_Move,
+ HISTORY_Combo,
+};
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+class HistoryEntry {
+public:
+ virtual void undo () {}
+ virtual void redo () {}
+ virtual ~HistoryEntry () {}
+ virtual HistoryType type () { return (HistoryType)(0); }
+};
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+class DelHistory : public HistoryEntry {
+public:
+ enum Type {
+ Cut, // were deleted with a cut operation
+ Other, // were deleted witout specific reason
+ };
+
+ IMPLEMENT_HISTORY_TYPE (Del)
+
+ vector indices;
+ vector cache;
+ const Type eType;
+
+ DelHistory (vector indices, vector cache, const Type eType = Other) :
+ indices (indices), cache (cache), eType (eType) {}
+};
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+class SetColorHistory : public HistoryEntry {
+public:
+ IMPLEMENT_HISTORY_TYPE (SetColor)
+
+ vector ulaIndices;
+ vector daColors;
+ short dNewColor;
+
+ SetColorHistory (vector ulaIndices, vector daColors, short dNewColor) :
+ ulaIndices (ulaIndices), daColors (daColors), dNewColor (dNewColor) {}
+};
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+class EditHistory : public HistoryEntry {
+public:
+ IMPLEMENT_HISTORY_TYPE (Edit)
+
+ const std::vector ulaIndices;
+ const std::vector paOldObjs, paNewObjs;
+
+ EditHistory (std::vector ulaIndices, std::vector paOldObjs,
+ std::vector paNewObjs) :
+ ulaIndices (ulaIndices), paOldObjs (paOldObjs), paNewObjs (paNewObjs) {}
+};
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+class ListMoveHistory : public HistoryEntry {
+public:
+ IMPLEMENT_HISTORY_TYPE (ListMove)
+
+ std::vector ulaIndices;
+ bool bUp;
+
+ std::vector getObjects (short ofs);
+ ListMoveHistory (vector ulaIndices, const bool bUp) :
+ ulaIndices (ulaIndices), bUp (bUp) {}
+};
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+class AddHistory : public HistoryEntry {
+public:
+ enum Type {
+ Other, // was "just added"
+ Paste, // was added through a paste operation
+ };
+
+ IMPLEMENT_HISTORY_TYPE (Add)
+
+ std::vector ulaIndices;
+ std::vector paObjs;
+ const Type eType;
+
+ AddHistory (std::vector ulaIndices, std::vector paObjs,
+ const Type eType = Other) :
+ ulaIndices (ulaIndices), paObjs (paObjs), eType (eType) {}
+};
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+class QuadSplitHistory : public HistoryEntry {
+public:
+ IMPLEMENT_HISTORY_TYPE (QuadSplit)
+
+ std::vector ulaIndices;
+ std::vector paQuads;
+
+ QuadSplitHistory (std::vector ulaIndices, std::vector paQuads) :
+ ulaIndices (ulaIndices), paQuads (paQuads) {}
+};
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+class InlineHistory : public HistoryEntry {
+public:
+ IMPLEMENT_HISTORY_TYPE (Inline)
+
+ const std::vector ulaBitIndices, ulaRefIndices;
+ const std::vector paRefs;
+ const bool bDeep;
+
+ InlineHistory (const std::vector ulaBitIndices, const std::vector ulaRefIndices,
+ const std::vector paRefs, const bool bDeep) :
+ ulaBitIndices (ulaBitIndices), ulaRefIndices (ulaRefIndices), paRefs (paRefs), bDeep (bDeep) {}
+};
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+class MoveHistory : public HistoryEntry {
+public:
+ IMPLEMENT_HISTORY_TYPE (Move)
+
+ const std::vector ulaIndices;
+ const vertex vVector;
+
+ MoveHistory (const std::vector ulaIndices, const vertex vVector) :
+ ulaIndices (ulaIndices), vVector (vVector) {}
+};
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+class ComboHistory : public HistoryEntry {
+public:
+ IMPLEMENT_HISTORY_TYPE (Combo)
+
+ std::vector paEntries;
+
+ ComboHistory (std::vector paEntries) : paEntries (paEntries) {}
+
+ ComboHistory& operator<< (HistoryEntry* entry) {
+ paEntries.push_back (entry);
+ return *this;
+ }
+};
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+namespace History {
+ void addEntry (HistoryEntry* entry);
+ void undo ();
+ void redo ();
+ void clear ();
+ void updateActions ();
+ long pos ();
+ std::vector& entries ();
+};
+
+#endif // HISTORY_H
\ No newline at end of file