1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Defines the interface to the Undo system.
//
//=============================================================================//
#ifndef HISTORY_H
#define HISTORY_H
#ifdef _WIN32
#pragma once
#endif
#include "MapClass.h" // For CMapObjectList
class CMapClass;
class CMapDoc;
class CHistory;
//
// Holds undo information for a single object, due to a single operation. Held by a CHistoryTrack.
//
class CTrackEntry
{
public:
enum TrackType_t
{
ttNone = -1,
ttCopy,
ttDelete,
ttCreate,
};
CTrackEntry();
CTrackEntry(TrackType_t eType, ...);
~CTrackEntry();
void Undo(CHistory *Opposite);
void DispatchUndoNotify(void);
void SetKeptChildren(bool bSet);
inline int GetSize(void) { return(m_nDataSize); }
void OnRemoveVisGroup(CVisGroup *pGroup);
bool m_bAutoDestruct;
protected:
size_t m_nDataSize;
TrackType_t m_eType; // What type of event this entry can undo.
//
// Based on the event type, one of these structs will be filled out:
//
union
{
struct
{
CMapClass *pCurrent; // Pointer to the object as it currently exists in the world.
CMapClass *pKeptObject; // Pointer to a copy of the object at the time it was kept.
} m_Copy;
struct
{
CMapClass *pDeleted; // Pointer to the object that was deleted from the world.
CMapClass *pKeptParent; // Pointer to the object's parent at the time of deletion.
} m_Delete;
struct
{
CMapClass *pCreated; // Pointer to the object that was created and added to the world.
} m_Create;
};
bool m_bKeptChildren;
bool m_bUndone; // Set to true after this entry is undone.
};
//
// Tracks all the objects changed by a single operation, such as "Nudge Objects" or "Delete". Each
// track contains one track entry per object affected by the operation.
//
class CHistoryTrack
{
public:
CHistoryTrack(CHistory *pParent, const CMapObjectList *pSelection);
~CHistoryTrack();
void Keep(CMapClass *pObject, bool bKeepChildren);
void KeepForDestruction(CMapClass *pObject);
void KeepNew(CMapClass *pObject);
void Undo();
void SetName(LPCTSTR pszName) { if(pszName) strcpy(szName, pszName); }
void OnRemoveVisGroup(CVisGroup *pGroup);
private:
BOOL CheckObjectFlag(CMapClass *pObject, int iFlag);
CUtlVector<CTrackEntry> Data;
CHistory *Parent;
DWORD dwID; // id of this tracker..
char szName[128];
CMapObjectList Selected;
bool m_bAutoDestruct;
size_t uDataSize; // approx
friend class CHistory;
};
class CHistory
{
public:
CHistory();
~CHistory();
static void SetHistory(CHistory *pHistory);
void SetOpposite(BOOL bUndo, CHistory*);
inline void SetDocument(CMapDoc *pDoc);
inline CMapDoc *GetDocument(void);
// mark undo position:
void MarkUndoPosition(const CMapObjectList* pSelection = NULL, LPCTSTR pszName = NULL, BOOL = FALSE);
//
// Keep this object so we can undo changes to it:
//
void Keep(CMapClass *pObject);
void KeepNoChildren(CMapClass *pObject);
void Keep(const CMapObjectList *pList);
//
// Store this pointer for destruction if it cycles off the undo stack:
//
void KeepForDestruction(CMapClass *pObject);
//
// Store this object for destruction if 'undone':
//
void KeepNew(CMapClass *pObject, bool bKeepChildren = true);
void KeepNew(const CMapObjectList *pList, bool bKeepChildren = true);
void Undo(CMapObjectList *pNewSelection);
BOOL IsUndoable(); // anything to undo?
void OnRemoveVisGroup(CVisGroup *pVisGroup);
// returns current name
LPCTSTR GetCurTrackName() { return CurTrack ? CurTrack->szName : ""; }
// total override:
void SetActive(BOOL bActive);
BOOL IsActive() { return m_bActive; }
// temporary shutdown/resume:
inline void Pause() { bPaused = TRUE; }
inline void Resume() { if(bPaused == TRUE) bPaused = FALSE; }
inline BOOL IsPaused() { return bPaused || !IsActive(); }
private:
CHistoryTrack *CurTrack;
CUtlVector<CHistoryTrack*> Tracks;
CMapDoc *m_pDoc; // Associated document.
// opposite tracker:
CHistory *Opposite;
BOOL bUndo; // is this the undo tracker?
BOOL bPaused;
size_t uDataSize;
BOOL m_bActive; // veto control
friend class CHistoryTrack;
};
//-----------------------------------------------------------------------------
// Purpose: Sets the document that this undo history belongs to.
//-----------------------------------------------------------------------------
void CHistory::SetDocument(CMapDoc *pDoc)
{
m_pDoc = pDoc;
}
//-----------------------------------------------------------------------------
// Purpose: Returns the document that this undo history belongs to.
//-----------------------------------------------------------------------------
CMapDoc *CHistory::GetDocument(void)
{
return(m_pDoc);
}
CHistory *GetHistory();
#endif // HISTORY_H
|