summaryrefslogtreecommitdiff
path: root/tikzit/src/common/GraphChange.h
blob: 0e71a90497772960ffdbf19d352144dd17c30a3a (plain)
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
//
//  GraphChange.h
//  TikZiT
//  
//  Copyright 2010 Aleks Kissinger. All rights reserved.
//  
//  
//  This file is part of TikZiT.
//  
//  TikZiT 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.
//  
//  TikZiT 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 TikZiT.  If not, see <http://www.gnu.org/licenses/>.
//  

#import "Node.h"
#import "Edge.h"

typedef enum {
	GraphAddition,
	GraphDeletion,
	NodePropertyChange,
	EdgePropertyChange,
	NodesPropertyChange,
	EdgesPropertyChange,
	NodesShift,
	NodesFlip,
	EdgesReverse,
	BoundingBoxChange,
	GraphPropertyChange,
	NodeOrderChange,
	EdgeOrderChange
} ChangeType;

/*!
 @class      GraphChange 
 @brief      Store the data associated with a graph change.
 @details    All of the methods that change a graph return an object of type GraphChange.
             Graph changes can be re-done by calling [graph applyGraphChange:]. They can be undone
             by calling applyGraphChange on [change inverse]. This class has no public initializer,
             so everything should be constructed by factory methods.
 */
@interface GraphChange : NSObject {
	ChangeType changeType;
	
	// for addition, deletion, and shifts
	NSSet *affectedNodes;
	NSSet *affectedEdges;
	NSPoint shiftPoint;
	
	// for flip
	BOOL horizontal;
	
	// for property changes
	Node *nodeRef;
	Edge *edgeRef;

	Node *oldNode, *nwNode;
	Edge *oldEdge, *nwEdge;
	NSMapTable *oldNodeTable, *nwNodeTable;
	NSMapTable *oldEdgeTable, *nwEdgeTable;
	NSRect oldBoundingBox, nwBoundingBox;
	GraphElementData *oldGraphData, *nwGraphData;

	NSArray *oldNodeOrder, *nwNodeOrder;
	NSArray *oldEdgeOrder, *nwEdgeOrder;
}

/*!
 @property   changeType
 @brief      Type of GraphChange.
 */
@property (assign) ChangeType changeType;

/*!
 @property   shiftPoint
 @brief      A point storing a shifted distance.
 */
@property (assign) NSPoint shiftPoint;

/*!
 @property   horizontal
 @brief      Flags whether nodes were flipped horizontally
 */
@property (assign) BOOL horizontal;

/*!
 @property   affectedNodes
 @brief      A set of nodes affected by this change, may be undefined.
 */
@property (copy) NSSet *affectedNodes;

/*!
 @property   affectedEdges
 @brief      A set of edges affected by this change, may be undefined.
 */
@property (copy) NSSet *affectedEdges;

/*!
 @property   nodeRef
 @brief      A reference to a single node affected by this change, may be undefined.
 */
@property (retain) Node *nodeRef;

/*!
 @property   oldNode
 @brief      A copy of the node pre-change.
 */
@property (copy) Node *oldNode;

/*!
 @property   nwNode
 @brief      A copy of the node post-change.
 */
@property (copy) Node *nwNode;

/*!
 @property   edgeRef
 @brief      A reference to a single edge affected by this change, may be undefined.
 */
@property (retain) Edge *edgeRef;

/*!
 @property   oldEdge
 @brief      A copy of the edge pre-change.
 */
@property (copy) Edge *oldEdge;

/*!
 @property   nwEdge
 @brief      A copy of the edge post-change.
 */
@property (copy) Edge *nwEdge;

/*!
 @property   oldNodeTable
 @brief      A a table containing copies of a set of nodes pre-change.
 */
@property (retain) NSMapTable *oldNodeTable;

/*!
 @property   nwNodeTable
 @brief      A a table containing copies of a set of nodes post-change.
 */
@property (retain) NSMapTable *nwNodeTable;

/*!
 @property   oldEdgeTable
 @brief      A a table containing copies of a set of edges pre-change.
 */
@property (retain) NSMapTable *oldEdgeTable;

/*!
 @property   nwEdgeTable
 @brief      A a table containing copies of a set of edges post-change.
 */
@property (retain) NSMapTable *nwEdgeTable;

/*!
 @property   oldBoundingBox
 @brief      The old bounding box.
 */
@property (assign) NSRect oldBoundingBox;

/*!
 @property   nwBoundingBox
 @brief      The new bounding box.
 */
@property (assign) NSRect nwBoundingBox;

/*!
 @property   oldGraphData
 @brief      The old graph data.
 */
@property (copy) GraphElementData *oldGraphData;

/*!
 @property   nwGraphData
 @brief      The new graph data.
 */
@property (copy) GraphElementData *nwGraphData;

/*!
 @property   oldNodeOrder
 @brief      The old node list.
 */
@property (copy) NSArray *oldNodeOrder;

/*!
 @property   nwNodeOrder
 @brief      The new node list.
 */
@property (copy) NSArray *nwNodeOrder;

/*!
 @property   oldEdgeOrder
 @brief      The old edge list.
 */
@property (copy) NSArray *oldEdgeOrder;

/*!
 @property   nwEdgeOrder
 @brief      The new edge list.
 */
@property (copy) NSArray *nwEdgeOrder;

/*!
 @brief      Invert a GraphChange.
 @details    Invert a GraphChange. Calling [graph applyGraphChange:[[graph msg:...] invert]]
             should leave the graph unchanged for any method of Graph that returns a
             GraphChange.
 @result     The inverse of the current Graph Change.
 */
- (GraphChange*)invert;

/*!
 @brief      Construct a graph addition. affectedNodes are the added nodes,
             affectedEdges are the added edges.
 @param      ns a set of nodes.
 @param      es a set of edges.
 @result     A graph addition.
 */
+ (GraphChange*)graphAdditionWithNodes:(NSSet*)ns edges:(NSSet*)es;

/*!
 @brief      Construct a graph deletion. affectedNodes are the deleted nodes,
             affectedEdges are the deleted edges.
 @param      ns a set of nodes.
 @param      es a set of edges.
 @result     A graph deletion.
 */
+ (GraphChange*)graphDeletionWithNodes:(NSSet*)ns edges:(NSSet*)es;

/*!
 @brief      Construct a property change of a single node.
 @param      nd the affected node.
 @param      old a copy of the node pre-change
 @param      nw a copy of the node post-change
 @result     A property change of a single node.
 */
+ (GraphChange*)propertyChangeOfNode:(Node*)nd fromOld:(Node*)old toNew:(Node*)nw;

/*!
 @brief      Construct a property change of a single edge.
 @param      e the affected edge.
 @param      old a copy of the edge pre-change
 @param      nw a copy of the edge post-change
 @result     A property change of a single node.
 */
+ (GraphChange*)propertyChangeOfEdge:(Edge*)e fromOld:(Edge *)old toNew:(Edge *)nw;

/*!
 @brief      Construct a property change of set of nodes.
 @details    Construct a property change of set of nodes. oldC and newC should be
             constructed using the class method [Graph nodeTableForNodes:] before
             and after the property change, respectively. The affected nodes are
             keys(oldC) = keys(newC).
 @param      oldC a table of copies of nodes pre-change
 @param      newC a table of copies of nodes post-change
 @result     A property change of a set of nodes.
 */
+ (GraphChange*)propertyChangeOfNodesFromOldCopies:(NSMapTable*)oldC
									   toNewCopies:(NSMapTable*)newC;

/*!
 @brief      Construct a property change of set of edges.
 @details    Construct a property change of set of edges. oldC and newC should be
             constructed using the class method [Graph edgeTableForEdges:] before
             and after the property change, respectively. The affected edges are
             keys(oldC) = keys(newC).
 @param      oldC a table of copies of edges pre-change
 @param      newC a table of copies of edges post-change
 @result     A property change of a set of edges.
 */
+ (GraphChange*)propertyChangeOfEdgesFromOldCopies:(NSMapTable*)oldC
									   toNewCopies:(NSMapTable*)newC;


/*!
 @brief      Construct a shift of a set of nodes by a given point.
 @param      ns the affected nodes.
 @param      p a point storing (dx,dy)
 @result     A shift of a set of nodes.
 */
+ (GraphChange*)shiftNodes:(NSSet*)ns byPoint:(NSPoint)p;

/*!
 @brief      Construct a horizontal or vertical flip of a set of nodes.
 @param      ns the affected nodes.
 @param      b flag for whether to flip horizontally
 @result     A flip of a set of nodes.
 */
+ (GraphChange*)flipNodes:(NSSet*)ns horizontal:(BOOL)b;

/*!
 @brief      Construct a reversal of a set of edges.
 @param      es the affected edges.
 @result     A reverse of a set of edges.
 */
+ (GraphChange*)reverseEdges:(NSSet*)es;

/*!
 @brief      Construct a bounding box change
 @param      oldBB the old bounding box
 @param      newBB the new bounding box
 @result     A bounding box change.
 */
+ (GraphChange*)changeBoundingBoxFrom:(NSRect)oldBB to:(NSRect)newBB;

/*!
 @brief      Construct a graph property change
 @param      oldData the old graph data
 @param      newData the new graph data
 @result     A graph property change.
 */
+ (GraphChange*)propertyChangeOfGraphFrom:(GraphElementData*)oldData to:(GraphElementData*)newData;

/*!
 @brief      Construct a node order change
 @param old  The old ordering
 @param new  The new ordering
 @result     A node order change
 */
+ (GraphChange*)nodeOrderChangeFrom:(NSArray*)old to:(NSArray*)new moved:(NSSet*)affected;

/*!
 @brief      Construct an edge order change
 @param old  The old ordering
 @param new  The new ordering
 @result     A edge order change
 */
+ (GraphChange*)edgeOrderChangeFrom:(NSArray*)old to:(NSArray*)new moved:(NSSet*)affected;

@end

// vi:ft=objc:noet:ts=4:sts=4:sw=4