-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTreeItem.h
492 lines (456 loc) · 12 KB
/
TreeItem.h
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
class TreeItem;
class TreeStateItem;
class TreeTransItem;
class TreeCoordItem;
class TreePoseItem;
class TreeInitItem;
class TreeRobotSetItem;
class TreeTextItem;
class TreeGraphItem;
#ifndef TREEITEM_H
#define TREEITEM_H
#include "TreeModel.h"
#include <QHash>
#include "Transition.h"
#include "Coordinates.h"
#include "Pose.h"
#include "robotInit.h"
#include "RobotSet.h"
/**
* Base class of item of the TreeView.
*/
class TreeItem
{
public:
/**
* Creates an item with given parent, and saves the row value.
*/
TreeItem( int row, TreeItem *parent = 0);
/**
* Destructor for base item.
*/
~TreeItem();
/**
* Returns parent of this element.
*/
TreeItem *parent();
/**
* Returns number of the row in that level (considering only children of parent of this element) on which this element is.
*/
int row();
/**
* Getter function for Type.
*/
int getType(){return Type;}
/**
* Returns number of children, which this item has.
*/
virtual int childNodesCount(){return 0;}
/**
* Returns name (1st column value) for this element.
*/
virtual QString Name(){return QString();}
/**
* Returns Value (2nd column value) for this element.
*/
virtual QString Attr(){return QString();}
/**
* Returns the i-th child of this element.
*/
virtual TreeItem *child(int i){return NULL;}
/**
* Returns the first met graphicsItem while going up the item tree.
*/
virtual QGraphicsItem * getGraphicsItem(){return NULL;}
protected:
/**
* Type of the item.
*/
int Type;
/**
* Table of items, used to store items, not to create them with every use of child(i).
*/
QHash<int,TreeItem*> childItems;
/**
* Parentitem of this element.
*/
TreeItem *parentItem;
/**
* Number of the row, in which this item is in the list of the children of parentelement.
*/
int rowNumber;
};
/**
* Item of the treeview, which represents a State (uses it's name and StateType).
*/
class TreeStateItem : public TreeItem
{
public:
/**
* Creates an item with given parent, and saves the row value.
*/
TreeStateItem( int row, TreeItem *parent = 0):TreeItem(row, parent){}
/**
* Destructor of the item.
*/
~TreeStateItem(){}
/**
* Sets State which is represented by this item.
*/
void setState(BaseState * st){Type = 0; state = st;}
/**
* Returns the first met graphicsItem while going up the item tree.
*/
QGraphicsItem * getGraphicsItem(){return state;}
/**
* Returns number of children, which this item has.
*/
int childNodesCount(){return state->itemCount();}
/**
* Returns the i-th child of this element.
*/
TreeItem *child(int i);
/**
* Returns name (1st column value) for this element.
*/
QString Name(){return state->getName();}
/**
* Returns Value (2nd column value) for this element.
*/
QString Attr(){return QString().fromStdString(STATE_TYPE_TABLE[state->getType()]);}
private:
/**
* State represented by this item.
*/
BaseState * state;//0
};
/**
* Item of the treeview, which represents a Transition.
*/
class TreeTransItem : public TreeItem
{
public:
/**
* Creates an item with given parent, and saves the row value.
*/
TreeTransItem( int row, TreeItem *parent = 0):TreeItem(row, parent){}
/**
* Destructor of the item.
*/
~TreeTransItem(){}
/**
* Sets Transition, which is represented by this item.
*/
void setTrans(Transition * _tr){Type = 1; tr = _tr;}
/**
* Returns the first met graphicsItem while going up the item tree.
*/
QGraphicsItem * getGraphicsItem(){return tr;}
/**
* Returns number of children, which this item has.
*/
int childNodesCount(){if(tr->getSubtask()!=NULL)return 1; else return 0;}
/**
* Returns the i-th child of this element.
*/
TreeItem *child(int i);
/**
* Returns name (1st column value) for this element.
*/
QString Name(){return QString("->")+=QString().fromStdString(CONDITION_TABLE[tr->getCondType()]).append(tr->getCondition());}
/**
* Returns Value (2nd column value) for this element.
*/
QString Attr(){return tr->endItem()->getName();}
private:
/**
* Transition represented by this item.
*/
Transition * tr;//1
};
/**
* Item of the treeview, which represents Coordinates.
*/
class TreeCoordItem : public TreeItem
{
public:
/**
* Creates an item with given parent, and saves the row value.
*/
TreeCoordItem( int row, TreeItem *parent = 0):TreeItem(row, parent){}
/**
* Destructor of the item.
*/
~TreeCoordItem(){}
/**
* Sets coordinates, which are represented by this item.
*/
void setCoords(Coordinates * _coords){Type = 2; coords = _coords;}
/**
* Returns the first met graphicsItem while going up the item tree.
*/
QGraphicsItem * getGraphicsItem(){return parentItem->getGraphicsItem();}
/**
* Returns number of children, which this item has.
*/
int childNodesCount()
{
int i=0;
if(isProper(coords->getMotionType()))
i++;
if(isProper(coords->getCoordType()))
i++;
i+=coords->getPoses().size();
return i;
}
/**
* Returns the i-th child of this element.
*/
TreeItem *child(int i);
/**
* Returns name (1st column value) for this element.
*/
QString Name(){return QString("Coordinates");}
/**
* Returns Value (2nd column value) for this element.
*/
QString Attr(){return QString();}
private:
/**
* Coordinates, which are represented byy this item.
*/
Coordinates * coords;//2
};
/**
* Item of the treeview, which represents a RobotSet.
*/
class TreeRobotSetItem : public TreeItem
{
public:
/**
* Creates an item with given parent, and saves the row value.
*/
TreeRobotSetItem( int row, TreeItem *parent = 0):TreeItem(row, parent){}
/**
* Destructor of the item.
*/
~TreeRobotSetItem(){}
/**
* Sets set, which is represented by this item, also defines if it's first or second set.
*/
void setSet(std::vector<Robot> _set){Type = 3; set = _set;}
/**
* Returns number of children, which this item has.
*/
int childNodesCount(){return set.size();}
/**
* Returns the i-th child of this element.
*/
TreeItem *child(int i);
/**
* Returns the first met graphicsItem while going up the item tree.
*/
QGraphicsItem * getGraphicsItem(){return parentItem->getGraphicsItem();}
/**
* Returns name (1st column value) for this element.
*/
QString Name(){return "FirstSet";}
/**
* Returns Value (2nd column value) for this element.
*/
QString Attr(){return QString();}
private:
/**
* Set, which is represented by this item.
*/
std::vector<Robot> set;//3
};
/**
* Item of the treeview, which represents a robotInit.
*/
class TreeInitItem : public TreeItem
{
public:
/**
* Creates an item with given parent, and saves the row value.
*/
TreeInitItem( int row, TreeItem *parent = 0):TreeItem(row, parent){}
/**
* Destructor of the item.
*/
~TreeInitItem(){}
/**
* Sets robotInit which is represented by this item.
*/
void setInit(robotInit _init){Type = 4; init = _init;}
/**
* Returns number of children, which this item has.
*/
int childNodesCount(){return init.init_values.size();}
/**
* Returns the i-th child of this element.
*/
TreeItem *child(int i);
/**
* Returns the first met graphicsItem while going up the item tree.
*/
QGraphicsItem * getGraphicsItem(){return parentItem->getGraphicsItem();}
/**
* Returns name (1st column value) for this element.
*/
QString Name(){return QString("Init");}
/**
* Returns Value (2nd column value) for this element.
*/
QString Attr(){return QString().fromStdString(ROBOT_TABLE[init.robot]);}
private:
/**
* RobotInit, which is represented by this state.
*/
robotInit init;//4
};
/**
* Item of the treeview, which represents a Pose.
*/
class TreePoseItem : public TreeItem
{
public:
/**
* Creates an item with given parent, and saves the row value.
*/
TreePoseItem( int row, TreeItem *parent = 0):TreeItem(row, parent){}
/**
* Destructor of the item.
*/
~TreePoseItem(){}
/**
* Sets pose, which is represented by this item.
*/
void setPos(Pose * _pos){Type = 5; pos = _pos;}
/**
* Returns number of children, which this item has.
*/
int childNodesCount(){return 3;}
/**
* Returns the i-th child of this element.
*/
TreeItem *child(int i);
/**
* Returns the first met graphicsItem while going up the item tree.
*/
QGraphicsItem * getGraphicsItem(){return parentItem->getGraphicsItem();}
/**
* Returns name (1st column value) for this element.
*/
QString Name(){return QString("Pose");}
/**
* Returns Value (2nd column value) for this element.
*/
QString Attr()
{
return QString();
}
private:
/**
* Pose, which is represented by this item.
*/
Pose * pos;//5
};
/**
* Item of the treeview, which represents various items without children.
*/
class TreeTextItem : public TreeItem
{
public:
/**
* Creates an item with given parent, and saves the row value.
*/
TreeTextItem( int row, TreeItem *parent = 0):TreeItem(row, parent){}
/**
* Destructor of the item.
*/
~TreeTextItem(){}
/**
* Sets name and value, which are represented by this value.
*/
void setNameAttr(QString _name, QString _attr){Type = 100; name=_name; attr=_attr;}
/**
* Returns number of children, which this item has.
*/
int childNodesCount(){return 0;}
/**
* Returns the i-th child of this element.
*/
TreeItem *child(int i)
{return 0;}
/**
* Returns the first met graphicsItem while going up the item tree.
*/
QGraphicsItem * getGraphicsItem(){return parentItem->getGraphicsItem();}
/**
* Returns name (1st column value) for this element.
*/
QString Name(){return name;}
/**
* Returns Value (2nd column value) for this element.
*/
QString Attr(){return attr;}
private:
/**
* Name (1st column value) for this item.
*/
QString name;
/**
* Attribute (2nd column value) for this item.
*/
QString attr;
};
/**
* Item of the treeview, which represents a Graph; it's a parent to all other items of the TreeView.
*/
class TreeGraphItem : public TreeItem
{
public:
/**
* Creates an item with given parent, and saves the row value.
*/
TreeGraphItem( int row, TreeItem *parent = 0):TreeItem(row, parent){}
/**
* Destructor of the item.
*/
~TreeGraphItem(){}
/**
* Sets Graph, which is represented by this item and sets TreeModel, which is used to get list of states of this Graph.
*/
void setGraph(MyGraphType * _gr, TreeModel * mod){Type=101;gr=_gr;Model=mod;}
/**
* Returns number of children, which this item has.
*/
int childNodesCount(){return boost::num_vertices(*gr);}
/**
* Returns the i-th child of this element.
*/
TreeItem *child(int i);
/**
* Returns the first met graphicsItem while going up the item tree.
*/
QGraphicsItem * getGraphicsItem(){return NULL;}
/**
* Returns name (1st column value) for this element.
*/
QString Name(){return QString();}
/**
* Returns Value (2nd column value) for this element.
*/
QString Attr(){return QString();}
private:
/**
* Graph, which is represented by this item;
*/
MyGraphType * gr;//101
/**
* Model of the tree, which is used to get list of state names form the project model.
*/
TreeModel * Model;
};
#endif // TREEITEM_H