forked from twiniars/RESpecTa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Model.h
275 lines (250 loc) · 8.21 KB
/
Model.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
class Model;
#ifndef MODEL_H
#define MODEL_H
#include "globals.h"
#include "Graph.h"
#include "respecta.h"
/**
* Class responsible for keeping the data and allowing operation on the data.
*/
class Model
{
public:
Model();
Transition * getTransition(BaseState *st, int i);
//************* COUNT ***********//
/**
* Returns Number of Vertices in the subtask defined by the SubtaskName.
*/
int vertNum(QString SubtaskName);
//************* DELETE ***********//
void CleanTask(QString name);
/**
* Clears the model leaving only empty main state.
*/
void deleteAll();
/**
* Removes the given transition from the model.
*/
void deleteTransition(Transition * transition);
/**
* Removes the given state from the model.
*/
void deleteState(BaseState * state);
/**
* Deletes all states and transitions of the task from model,
* if it's not the main task erases the given Subtask from the model.
*/
void DeleteTask(QString SubtaskName);
//************* ADD ***********//
/**
* Adds a subtask to the model.
* @param name Name of subtask which will be created.
*/
void addSubtask(QString name);
/**
* Adds a state to a subtask.
* @param item State, which will be inserted.
* @param subtas
Q_OBJECTkName Name of subtask, to which the state will be inserted.
* @returns True if operation successful.
*/
bool addState(BaseState * item, QString subtaskName);
/**
* Adds a subtask to the model.
* @param trans Transition which will be inserted.
* @returns True if operation successful.
*/
bool tryInsertTransition(Transition * trans);
//************* CHANGE ***********//
/*void changeSourceStateofTrans(Transition * tr, QString newstatename);
void changeDestStateofTrans(Transition * tr, QString newstatename);*/
/**
* Changes the name of subtask from oldName to NewName.
*/
void changeSubtaskName(QString oldName, QString NewName);
/**
* Changes the oldState to newState in the model.
* @returns True if operation successful.
*/
bool ReplaceState(BaseState * oldState, BaseState * newState);
/**
* Moves the transition at index _index one position Up in the Transition List in the graph representing task.
*/
void MoveTransitionUp(BaseState * st, int _index);
/**
* Moves the transition at index _index one position Down in the Transition List in the graph representing task.
*/
void MoveTransitionDown(BaseState * st, int _index);
//************* GET ***********//
QStringList getAllStartStateNames(QString sub)
{
QStringList list = getAllStateNames(sub);
list.removeOne("_END_");
list.removeOne("_STOP_");
return list;
}
QStringList getAllEndStateNames(QString sub)
{
QStringList list = getStateNames((*((*subtasks)[sub])));
list.removeOne("INIT");
return list;
}
/**
* Returns the State with given name. Not for use for _END_ or _STOP_ states.
*/
BaseState * getState(QString name);
/**
* Returns the State with given name from the subtask with given subtaskName.
*/
BaseState * getState(QString name, QString subtaskName);
/**
* Returns the State at index i in Graph graph.
*/
BaseState * getState(MyGraphType * graph, int i);
/**
* Returns all transitions of a state from the model.
*/
std::vector<Transition *> getTransitions(BaseState * state);
/**
* Returns Graph with given Name.
*/
MyGraphType * getGraph(QString Name);
/**
* Returns Name of subtask containing a state with given StateName.
*/
QString getSubtaskName(QString StateName);
/**
* Returns Name of subtask containing a state State.
*/
QString getSubtaskName(BaseState * State );
/**
* Returns Name of the main task.
*/
QString getMainName(){return mainName;}
/**
* Returns Name of subtask containing given transition.
*/
QString getSubNameOfTrans(Transition * transition);
/**
* Returns List with names of all states from the graph G.
*/
QStringList getStateNames(MyGraphType G);
/**
* Returns List with names of all tasks from the model.
*/
QStringList getTasksNameLists();
/**
* Returns List with names of all tasks from the model without the main task..
*/
QStringList getTasksNameListsWithoutMain();
/**
* Returns List with names of all states from the subtask with name sub.
*/
QStringList getAllStateNames(QString sub);
/**
* Returns edge_iterator of the Edge containing transition toFind in the graph.
*/
boost::graph_traits<MyGraphType>::edge_iterator findEdge ( MyGraphType * graph, Transition * toFind);
/**
* Returns vertex_iterator of the Vertex containing state toFind in the graph.
*/
boost::graph_traits<MyGraphType>::vertex_iterator findVertex ( MyGraphType * graph, BaseState * toFind);
//************* SET ***********//
/**
* Changes name of the main task to newName.
*/
void setMainName(QString newName);
/**
* Sets main window to newres.
*/
void setView(RESpecTa * newres){res=newres;}
/**
* Sets save folder to newSaveFolder.
*/
void setSaveFolder(QString newSaveFolder){SaveFolder=newSaveFolder;}
//************* CHECK ***********//
/**
* Checks if condition cond is available for the state source.
* @returns True if the condition cond hasn't been used as a out-condition from the state source.
*/
bool checkTransCondAvailabe(BaseState * source,ConditionType condType, QString cond);
/**
* Checks if subtask with name Name exists.
* @returns True if subtask with name Name exists.
*/
bool checkSubtaskExists(QString Name);
/**
* Checks if name Name is available for graph G.
* @returns True if no state with name Name exists in graph G.
*/
bool checkNameAvailable(QString Name, MyGraphType * G);
/**
* Checks if state with name Name is present in the model.
* @returns True if subtask containing state with name Name exists.
*/
bool checkNameAvailable(QString Name);
/**
* Checks if Trnsition trans is present in the model.
* @returns True if subtask containing Transition trans exists.
*/
bool checkTransitonExists(Transition * trans);
/**
* Checks if condition of transition tr can be changed to cond.
* @returns True if no transition from the source state of tr has condition cond.
*/
bool checkTransCondAvailabe(Transition * tr,ConditionType condType, QString cond);
//************* SAVE ***********//
/**
* Saves the Model to the file filename.
*/
void save(QString filename);
/**
* Saves the Task G to file FileName, if ifmain==1 saves the paths to other files.
*/
void printStates(MyGraphType *G, std::string FileName, bool ifMain);
/**
* Checks for errors in the Model.
* @returns List of errors.
*/
QStringList checkIfOK();
//************* OTHER ***********//
/**
* Sets changed parameter and refreshes the TreeView in the main window.
*/
void setChanged(bool newChanged);
bool wasChanged(){return changed;}
void setBlock(bool block){changeBlocked=block;}
signals:
/**
* Reports error to the main window.
*/
void reportError(QString);
void reportMsg(QString);
private:
/**
* pointer to the main window class.
*/
RESpecTa * res;
/**
* Name of the main task in the model.
*/
QString mainName;
/**
* Map of all the subtasks.
*/
std::map<QString, MyGraphType *> * subtasks;
/**
* Folder, to which all the files are saved.
*/
QString SaveFolder;
/**
* Variable which is checked before load/exit to determine, whether the user should be asked to save his work.
*/
bool changed;
/**
* Variable which is set to block refreshing the TreeView all the time while loading from file.
*/
bool changeBlocked;
};
#endif // MODEL_H