history.h

Tue, 16 Apr 2013 14:36:56 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Tue, 16 Apr 2013 14:36:56 +0300
changeset 113
bbaa40226ec9
parent 104
6e29bb0e83c5
child 117
7eb7a43a511b
permissions
-rw-r--r--

Radial saving and reading from files

/*
 *  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 <http://www.gnu.org/licenses/>.
 */

#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_SetContents,
	HISTORY_ListMove,
	HISTORY_Add,
	HISTORY_QuadSplit,
	HISTORY_Inline,
	HISTORY_Move,
};

// =============================================================================
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// =============================================================================
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<ulong> indices;
	vector<LDObject*> cache;
	const Type eType;
	
	DelHistory (vector<ulong> indices, vector<LDObject*> cache, const Type eType = Other) :
		indices (indices), cache (cache), eType (eType) {}
};

// =============================================================================
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// =============================================================================
class SetColorHistory : public HistoryEntry {
public:
	IMPLEMENT_HISTORY_TYPE (SetColor)
	
	vector<ulong> ulaIndices;
	vector<short> daColors;
	short dNewColor;
	
	SetColorHistory (vector<ulong> ulaIndices, vector<short> daColors, short dNewColor) :
		ulaIndices (ulaIndices), daColors (daColors), dNewColor (dNewColor) {}
};

// =============================================================================
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// =============================================================================
class SetContentsHistory : public HistoryEntry {
public:
	IMPLEMENT_HISTORY_TYPE (SetContents)
	
	ulong ulIndex;
	LDObject* oldObj, *newObj;
	
	SetContentsHistory (ulong ulIndex, LDObject* oldObj, LDObject* newObj) :
		ulIndex (ulIndex), oldObj (oldObj), newObj (newObj) {}
};

// =============================================================================
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// =============================================================================
class ListMoveHistory : public HistoryEntry {
public:
	IMPLEMENT_HISTORY_TYPE (ListMove)
	
	std::vector<ulong> ulaIndices;
	bool bUp;
	
	std::vector<LDObject*> getObjects (short ofs);
	ListMoveHistory (vector<ulong> 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<ulong> ulaIndices;
	std::vector<LDObject*> paObjs;
	const Type eType;
	
	AddHistory (std::vector<ulong> ulaIndices, std::vector<LDObject*> paObjs,
		const Type eType = Other) :
		ulaIndices (ulaIndices), paObjs (paObjs), eType (eType) {}
};

// =============================================================================
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// =============================================================================
class QuadSplitHistory : public HistoryEntry {
public:
	IMPLEMENT_HISTORY_TYPE (QuadSplit)
	
	std::vector<ulong> ulaIndices;
	std::vector<LDQuad*> paQuads;
	
	QuadSplitHistory (std::vector<ulong> ulaIndices, std::vector<LDQuad*> paQuads) :
		ulaIndices (ulaIndices), paQuads (paQuads) {}
};

// =============================================================================
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// =============================================================================
class InlineHistory : public HistoryEntry {
public:
	IMPLEMENT_HISTORY_TYPE (Inline)
	
	const std::vector<ulong> ulaBitIndices, ulaRefIndices;
	const std::vector<LDSubfile*> paRefs;
	const bool bDeep;
	
	InlineHistory (const std::vector<ulong> ulaBitIndices, const std::vector<ulong> ulaRefIndices,
		const std::vector<LDSubfile*> paRefs, const bool bDeep) :
		ulaBitIndices (ulaBitIndices), ulaRefIndices (ulaRefIndices), paRefs (paRefs), bDeep (bDeep) {}
};

// =============================================================================
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// =============================================================================
class MoveHistory : public HistoryEntry {
public:
	IMPLEMENT_HISTORY_TYPE (Move)
	
	const std::vector<ulong> ulaIndices;
	const vertex vVector;
	
	MoveHistory (const std::vector<ulong> ulaIndices, const vertex vVector) :
		ulaIndices (ulaIndices), vVector (vVector) {}
};

// =============================================================================
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// =============================================================================
namespace History {
	extern std::vector<HistoryEntry*> entries;
	
	void addEntry (HistoryEntry* entry);
	void undo ();
	void redo ();
	void clear ();
	void updateActions ();
	long pos ();
};

#endif // HISTORY_H

mercurial