-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbaseState.h
295 lines (259 loc) · 7.19 KB
/
baseState.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
class BaseState;
#ifndef BaseState_H
#define BaseState_H
#include <QGraphicsPixmapItem>
#include <QList>
QT_BEGIN_NAMESPACE
class QPixmap;
class QGraphicsItem;
class QGraphicsScene;
class QTextEdit;
class QGraphicsSceneMouseEvent;
class QMenu;
class QGraphicsSceneContextMenuEvent;
class QPainter;
class QStyleOptionGraphicsItem;
class QWidget;
class QPolygonF;
class QXmlStreamWriter;
class QXmlStreamReader;
QT_END_NAMESPACE
#include "RobotSet.h"
#include "Coordinates.h"
#include <fstream>
class TreeItem;
class Transition;
/**
* Class being a Base to all the state classes, having only the base attributes of the states.
*/
class BaseState : public QGraphicsPolygonItem
{
public:
/**
* Sets selected and updates graphics view of this object.
*/
void setSelected(bool selected)
{
QGraphicsPolygonItem::setSelected(selected);
this->update();
}
enum { Type = UserType + 15 };
/**
* Getter function to stateType.
*/
StateType getType() {return stateType;}
/**
* Setter function for stateType.
*/
void setType(StateType newType){stateType=newType;}
/**
* Getter function to stateName.
*/
QString getName() {return stateName;}
/**
* Settes function for stateName.
*/
void setName(QString newName);
/**
* Getter function to argument.
*/
QString getArgument() {return argument;}
/**
* Setter function for argument.
*/
void setArgument(QString newArg){argument = newArg;}
/**
* Getter function to parameters.
*/
QString getParameters() {return parameters;}
/**
* Setter function for parameters.
*/
void setParameters(QString newParams){parameters = newParams;}
/**
* Getter function for nameTextItem.
*/
QGraphicsTextItem * getNameTextItem(){return nameTextItem;}
//void setNameTextItem(QGraphicsTextItem * newItem){nameTextItem=newItem;}
/**
* Getter function for subtaskTransitions.
*/
QList<Transition*> getSubtaskTransitions(){return subtaskTransitions;}
/**
* Resizes the text in nameTextItem to fit the boundingRect of the state.
*/
void updateSize();
/**
* Moves the text to fit the left top corner with the state corner.
*/
void updateTextPositions()
{
nameTextItem->setPos(this->pos().x()-50,this->pos().y()-50);
}
/**
* Loads from XML Stream the data and passes it to the subclasses(if any).
* @param reader Stream from which the data is read
* @returns List of errors, which occured while loading
*/
virtual QStringList LoadFromXML(QXmlStreamReader * reader){return QStringList();}
/**
* Counts how many children does the object have in the TreeView.
* @returns Number of children which will be visible in the TreeView
*/
virtual int itemCount(){return 0;}
/**
* Creates and returns the child of this state located at the index i.
* @returns Child of this state at index i.
*/
virtual TreeItem * getChild(int i, TreeItem * parent){return 0;}
/**
* Function comparing 2 states. Checks only the basic elements of the state(name, type, arguments, parameters).
* @returns true if states are equal.
*/
virtual bool equals(BaseState* other)
{
if(getName()==other->getName())
if(this->stateType==other->stateType)
if(this->parameters==other->parameters)
if(this->argument==other->argument)
return true;
return false;
}
/**
* Copy operator for BaseState.
*/
BaseState & operator=(const BaseState &);
/**
* Creates a state with empty nameTextItem and with no stateType.
*/
BaseState();
/**
* Creates a state, which is a copy of state 'old'.
*/
BaseState(BaseState& old);
/**
* Deletes nameTextItem, and removes this state from all transitions, which pointed to it as to a subtask.
*/
virtual ~BaseState();
/**
* Removes the tr Transition from the subtaskTransitions list.
*/
void removeSubtaskTrans(Transition * tr);
/**
* Adds the Transition tr to the subtaskTransitions list.
*/
void addSubtaskTrans(Transition * tr);
/**
* Sets context menu for the state.
*/
void setMenu( QMenu *contextMenu);
/**
* Removes given transition.
* @param transition Transition to be removed
*/
void removeTransition(Transition *transition);
/**
* Removes from both states and deletes all transitions of the given state.
*/
void removeTransitions();
/**
* Retruns the polygon representing the state.
*/
QPolygonF polygon() const
{ return myPolygon; }
/**
* Adds transition to the state.
*/
void addTransition(Transition *transition);
/**
* Returns the image representing the state.
*/
QPixmap image() const;
/**
* Getter function for Type.
*/
int type() const
{ return Type;}
/**
* Getter function for Transitions.
*/
QList<Transition *> getTransitions (){return Transitions;}
/**
* Writes the data of the state to the XML stream.
* @param writer Stream to which the data is written
*/
virtual void Print(QXmlStreamWriter* writer){}
/**
* Creates a string describing the state attributes.
* @returns String with the description of the State
*/
virtual std::string Print()
{
std::string x;
x+="Name ";
x+=this->stateName.toStdString();
if(this->getType()<STATE_TYPES_NUMBER)
{
x+="\nStateType: ";
x+=STATE_TYPE_TABLE[this->getType()];
}
if(parameters.size()>0)
{
x+="\nParameters ";
x+=this->parameters.toStdString();
}
return x;
}
/**
* Counts the number of transitions which are going out from this state.
* @returns Number of transitions starting at this state
*/
int outTransitionsCount();
protected:
/**
* Opens the context menu for the state.
*/
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
/**
* If the change is change of position then updateposition() function is called for allt he transitions of this state.
*/
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
/**
* Name of the state.
*/
QString stateName;
/**
* Type of the State.
*/
StateType stateType;
/**
* Argument(optional) of the state.
*/
QString argument;
/**
* Parameters(optional) of the state.
*/
QString parameters;
/**
* TextItem showing name and type of the state.
*/
QGraphicsTextItem * nameTextItem;
/**
* List of transitions of this state.
*/
QList<Transition *> Transitions;
/**
* List of transitions, which point to this item as to a subtask.
*/
QList<Transition *> subtaskTransitions;
private:
/**
* Polygon representing the state.
*/
QPolygonF myPolygon;
/**
* ContextMenu which is called when right click action has occured.
*/
QMenu *myContextMenu;
};
#endif