-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStates.h
766 lines (730 loc) · 18.9 KB
/
States.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
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
class StopState;
class StopGenState;
class EmptyGenState;
class EmptyGenForStateState;
class sysInitState;
class RunGenState;
class WaitState;
class GetSensorState;
class InitiateSensorState;
#ifndef STATES_H
#define STATES_H
#include "globals.h"
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include "RobotSet.h"
#include "Coordinates.h"
#include <stdio.h>
#include <stdlib.h>
#include "robotInit.h"
#include "baseState.h"
class QXmlStreamWriter;
class QXmlStreamReader;
#include <QtGui>
class BaseState;
////////////////////////// Stop State //////////////////////////////////////////////////////
/**
* State representing end of a task/subtask.
*/
class StopState:public BaseState
{
public:
/**
* Empty constructor setting stateType.
*/
StopState():BaseState(){stateType=STATE_TYPES_NUMBER;}
/**
* Copy constructor copying all date from state old.
*/
StopState(StopState& old):BaseState(old){}
/**
* Empty destructor.
*/
~StopState(){}
/**
* Function checking if the other object is equal to this.
* @returns true if objects data is the same.
*/
bool equals(BaseState* other){return BaseState::equals(other);}
/**
* Function printing the state to XML writer stream.
*/
void Print(QXmlStreamWriter* writer);
/**
* Function printing the attributes of the state into a String.
*/
std::string Print();
/**
* Function loading a State from XML reader Stream.
*/
QStringList LoadFromXML(QXmlStreamReader * reader);
/**
* Function used to count how many children should there be for state's TreeView item.
*/
int itemCount()
{
return 0;//Type selfexplainable
}
/**
* Returns the i'th children of this state.
* @returns NULL, because no children are present.
*/
TreeItem * getChild(int i, TreeItem * parent)
{
return 0;
}
};
////////////////////////// Empty Gen for Set State /////////////////////////////////////////////////
/**
* State representing sets of robots, of which the first one waits for the second.
*/
class EmptyGenForSetState:public BaseState
{
public:
/**
* Empty constructor setting stateType.
*/
EmptyGenForSetState():BaseState(){stateType=EMPTY_GEN_FOR_SET;}
/**
* Copy constructor copying all date from state old.
*/
EmptyGenForSetState(EmptyGenForSetState& old):BaseState(old)
{
this->set = old.set;
}
/**
* Empty destructor.
*/
~EmptyGenForSetState(){}
/**
* Function checking if the other object is equal to this.
* @returns true if objects data is the same.
*/
bool equals(BaseState* other);
/**
* Getter function for set.
*/
RobotSet getSet() {return set;}
/**
* Setter function for set.
*/
void setSet(RobotSet newSet) {set=newSet;}
/**
* Function printing the state to XML writer stream.
*/
void Print(QXmlStreamWriter * writer);
/**
* Function printing the attributes of the state into a String.
*/
std::string Print();
/**
* Function loading a State from XML reader Stream.
*/
QStringList LoadFromXML(QXmlStreamReader * reader);
/**
* Function used to count how many children should there be for state's TreeView item.
*/
int itemCount()
{
int i=0;//Type
i++;//set
if(parameters.size()>0)i++;
i+= this->outTransitionsCount();
return i;
}
/**
* Returns the i'th children of this state.
*/
TreeItem * getChild(int i, TreeItem * parent);
private:
/**
* Set of robots.
*/
RobotSet set;
};
////////////////////////// Empty Gen State ///////////////////////////////////////////////////
/**
* State representing empty generator for one robot.
*/
class EmptyGenState:public BaseState
{
public:
/**
* Empty constructor setting stateType.
*/
EmptyGenState():BaseState(){robot = (Robot)0;stateType=EMPTY_GEN;}
/**
* Copy constructor copying all date from state old.
*/
EmptyGenState(EmptyGenState& old):BaseState(old)
{
this->robot=old.robot;
}
/**
* Empty destructor.
*/
~EmptyGenState(){}
/**
* Function checking if the other object is equal to this.
* @returns true if objects data is the same.
*/
bool equals(BaseState* other);
/**
* Getter function for robot.
*/
Robot getRobot() {return robot;}
/**
* Setter function for robot.
*/
void setRobot(Robot newRobot) {robot=newRobot;}
/**
* Getter function for argument.
*/
QString getArgument() {return argument;}
/**
* Setter function for argument.
*/
void setArgument(QString newArg) {argument=newArg;}
/**
* Function printing the state to XML writer stream.
*/
void Print(QXmlStreamWriter * writer);
/**
* Function printing the attributes of the state into a String.
*/
std::string Print();
/**
* Function loading a State from XML reader Stream.
*/
QStringList LoadFromXML(QXmlStreamReader * reader);
/**
* Function used to count how many children should there be for state's TreeView item.
*/
int itemCount()
{
int i=0;//Type
i++;//robot
if(argument.size()>0)i++;
if(parameters.size()>0)i++;
i+= this->outTransitionsCount();
return i;
}
/**
* Returns the i'th children of this state.
*/
TreeItem * getChild(int i, TreeItem * parent);
private:
/**
* Robot, for which the empty generator is called.
*/
Robot robot;
//QString argument;
};
////////////////////////// Get Sensor State ///////////////////////////////////////////////////
/**
* State representing downloading data from a sensor.
*/
class GetSensorState:public BaseState
{
public:
/**
* Empty constructor setting stateType.
*/
GetSensorState():BaseState(){stateType=GET_SENSOR_READING;}
/**
* Copy constructor copying all date from state old.
*/
GetSensorState(GetSensorState& old):BaseState(old)
{
this->sensor=old.sensor;
}
/**
* Empty destructor.
*/
~GetSensorState(){}
/**
* Function checking if the other object is equal to this.
* @returns true if objects data is the same.
*/
bool equals(BaseState* other);
/**
* Getter function for sensor.
*/
Sensor getSensor() {return sensor;}
/**
* Setter function for sensor.
*/
void setSensor(Sensor newSensor) {sensor=newSensor;}
/**
* Function printing the state to XML writer stream.
*/
void Print(QXmlStreamWriter * writer);
/**
* Function printing the attributes of the state into a String.
*/
std::string Print();
/**
* Function loading a State from XML reader Stream.
*/
QStringList LoadFromXML(QXmlStreamReader * reader);
/**
* Function used to count how many children should there be for state's TreeView item.
*/
int itemCount()
{
int i=0;//Type
i++;//sensor
if(parameters.size()>0)i++;
i+= this->outTransitionsCount();
return i;
}
/**
* Returns the i'th children of this state.
*/
TreeItem * getChild(int i, TreeItem * parent);
private:
/**
* Sensor, from which the information which be received.
*/
Sensor sensor;
};
////////////////////////// Init Sensor State ///////////////////////////////////////////////////
/**
* State representing initiating sensor.
*/
class InitiateSensorState:public BaseState
{
public:
/**
* Empty constructor setting stateType.
*/
InitiateSensorState():BaseState(){stateType=INITIATE_SENSOR_READING;}
/**
* Copy constructor copying all date from state old.
*/
InitiateSensorState(InitiateSensorState& old):BaseState(old)
{
this->sensor=old.sensor;
}
/**
* Empty destructor.
*/
~InitiateSensorState(){}
/**
* Function checking if the other object is equal to this.
* @returns true if objects data is the same.
*/
bool equals(BaseState* other);
/**
* Getter function for sensor.
*/
Sensor getSensor() {return sensor;}
/**
* Setter function for sensor.
*/
void setSensor(Sensor newSensor) {sensor=newSensor;}
/**
* Function printing the state to XML writer stream.
*/
void Print(QXmlStreamWriter * writer);
/**
* Function printing the attributes of the state into a String.
*/
std::string Print();
/**
* Function loading a State from XML reader Stream.
*/
QStringList LoadFromXML(QXmlStreamReader * reader);
/**
* Function used to count how many children should there be for state's TreeView item.
*/
int itemCount()
{
int i=0;//Type
i++;//sensor
if(parameters.size()>0)i++;
i+= this->outTransitionsCount();
return i;
}
/**
* Returns the i'th children of this state.
*/
TreeItem * getChild(int i, TreeItem * parent);
private:
/**
* Sensor to be initialized.
*/
Sensor sensor;
};
////////////////////////// Run Gen State ///////////////////////////////////////////////////
/**
* State representing movement of one robot.
*/
class RunGenState:public BaseState
{
public:
/**
* Empty constructor setting stateType.
*/
RunGenState():BaseState(){coords = new Coordinates();stateType==RUN_GENERATOR;}
/**
* Copy constructor copying all date from state old.
*/
RunGenState(RunGenState& old):BaseState(old)
{
this->robot=old.robot;
this->genType=old.genType;
this->filePath=old.filePath;
this->genArgs=old.genArgs;
this->coords=new Coordinates(*(old.coords));
this->speech=old.speech;
}
/**
* Destructor, which deletes coords.
*/
~RunGenState(){if(coords)delete coords;}
/**
* Function checking if the other object is equal to this.
* @returns true if objects data is the same.
*/
bool equals(BaseState* other);
/**
* Getter function for robot.
*/
Robot getRobot() {return robot;}
/**
* Setter function for robot.
*/
void setRobot(Robot newRobot) {robot=newRobot;}
/**
* Getter function for genType.
*/
GeneratorType getGenType() {return genType;}
/**
* Setter function for genType.
*/
void setGenType(GeneratorType newGenType) {genType=newGenType;}
/**
* Getter function for coords.
*/
Coordinates* getCoords() {return coords;}
/**
* Setter function for coords.
*/
void setCoords (Coordinates * newCoords) {coords = newCoords;}
/**
* Getter function for speech.
*/
QString getSpeech() {return speech;}
/**
* Setter function for speech.
*/
void setSpeech(QString newSpeech) {speech = newSpeech;}
/**
* Getter function for genArgs.
*/
QString getArgs(){return genArgs;}
/**
* Setter function for genArgs.
*/
void setArgs(QString newGenArgs){genArgs=newGenArgs;}
/**
* Getter function for filePath.
*/
QString getFilePath() {return filePath;}
/**
* Setter function for filePath.
*/
void setFilePath(QString newPath) {filePath=newPath;}
/**
* Function printing the state to XML writer stream.
*/
void Print(QXmlStreamWriter * writer);
/**
* Function printing the attributes of the state into a String.
*/
std::string Print();
/**
* Function loading a State from XML reader Stream.
*/
QStringList LoadFromXML(QXmlStreamReader * reader);
/**
* Function used to count how many children should there be for state's TreeView item.
*/
int itemCount()
{
int i=0;//Type
i++;//robot
i++;//genType
if(genArgs.size()>0)i++;
if(filePath.size()>0)i++;
if(speech.size()>0)i++;
if(coords->getPoses().size()>0)i++;//to oznacza ze coords ma sens
if(parameters.size()>0)i++;
i+= this->outTransitionsCount();
return i;
}
/**
* Returns the i'th children of this state.
*/
TreeItem * getChild(int i, TreeItem * parent);
private:
/**
* Path to the trajectory file.
*/
QString filePath;
/**
* Robot which executes the generator.
*/
Robot robot;
/**
* Generator, which is executed.
*/
GeneratorType genType;
/**
* Coordinates holding poses and pose specification.
*/
Coordinates * coords;
/**
* Additional argument for generator execution.
*/
QString genArgs;
/**
* Speech which will be used by a speech generator.
*/
QString speech;
};
////////////////////////// Stop Gen State ///////////////////////////////////////////////////
/**
* State representing stopping movement of a set of robots.
*/
class StopGenState:public BaseState
{
public:
/**
* Empty constructor setting stateType.
*/
StopGenState():BaseState(){stateType==STOP_GEN;}
/**
* Copy constructor copying all date from state old.
*/
StopGenState(StopGenState& old):BaseState(old)
{
this->set=old.set;
}
/**
* Empty destructor.
*/
~StopGenState(){}
/**
* Function checking if the other object is equal to this.
* @returns true if objects data is the same.
*/
bool equals(BaseState* other);
/**
* Getter function for set.
*/
RobotSet getSet() {return set;}
/**
* Setter function for set.
*/
void setSet(RobotSet newSet) {set=newSet;}
/**
* Function printing the state to XML writer stream.
*/
void Print(QXmlStreamWriter * writer);
/**
* Function printing the attributes of the state into a String.
*/
std::string Print();
/**
* Function loading a State from XML reader Stream.
*/
QStringList LoadFromXML(QXmlStreamReader * reader);
/**
* Function used to count how many children should there be for state's TreeView item.
*/
int itemCount()
{
int i=0;//Type
i++;//set
if(parameters.size()>0)i++;
i+= this->outTransitionsCount();
return i;
}
/**
* Returns the i'th children of this state.
*/
TreeItem * getChild(int i, TreeItem * parent);
private:
/**
* Set of robots.
*/
RobotSet set;
};
///////////////////////// Sys Ini State ///////////////////////////////////////////////////
/**
* State representing system initialization.
*/
class sysInitState:public BaseState
{
public:
/**
* Empty constructor setting stateType.
*/
sysInitState():BaseState(){transmitter=(Transmitter)-1;stateType==SYSTEM_INITIALIZATION;}
/**
* Copy constructor copying all date from state old.
*/
sysInitState(sysInitState& old):BaseState(old)
{
this->inits=old.inits;
this->transmitter=old.transmitter;
this->sensors=old.sensors;
}
/**
* Empty destructor.
*/
~sysInitState(){}
/**
* Function checking if the other object is equal to this.
* @returns true if objects data is the same.
*/
bool equals(BaseState* other);
/**
* Getter function for inits.
*/
std::vector<robotInit> getInits() {return inits;}
/**
* Setter function for inits.
*/
void setInits (std::vector<robotInit> newInits) {inits=newInits;}
/**
* Getter function for transmitter.
*/
Transmitter getTransmitter() {return transmitter;}
/**
* Setter function for transmitter.
*/
void setTransmitter(Transmitter newTrans) {transmitter=newTrans;}
/**
* Getter function for sensors.
*/
std::vector<Sensor> getSensors() {return sensors;}
/**
* Setter function for sensors.
*/
void setSensors(std::vector<Sensor> newSensors) {sensors=newSensors;}
/**
* Function printing the state to XML writer stream.
*/
void Print(QXmlStreamWriter * writer);
/**
* Function printing the attributes of the state into a String.
*/
std::string Print();
/**
* Function loading a State from XML reader Stream.
*/
QStringList LoadFromXML(QXmlStreamReader * reader);
/**
* Function used to count how many children should there be for state's TreeView item.
*/
int itemCount()
{
int i=0;//Type
if(isProper(transmitter))i++;
i+=sensors.size();
i+=inits.size();
if(parameters.size()>0)i++;
i+= this->outTransitionsCount();
return i;
}
/**
* Returns the i'th children of this state.
*/
TreeItem * getChild(int i, TreeItem * parent);
private:
/**
* Vector of robotInits, representing initializations of generators for robots (1 robot only in each element).
*/
std::vector<robotInit> inits;
/**
* Object representing transmitter to be initialized.
*/
Transmitter transmitter;
/**
* Vector of Sensors to be initialized.
*/
std::vector<Sensor> sensors;
};
///////////////////////// Wait State ///////////////////////////////////////////////////
/**
* State representing a time delay in the system.
*/
class WaitState:public BaseState
{
public:
/**
* Empty constructor setting stateType.
*/
WaitState():BaseState(){Timespan=0;stateType==WAIT;}
/**
* Copy constructor copying all date from state old.
*/
WaitState(WaitState& old):BaseState(old)
{
this->Timespan=old.Timespan;
}
/**
* Empty destructor.
*/
~WaitState(){}
/**
* Function checking if the other object is equal to this.
* @returns true if objects data is the same.
*/
bool equals(BaseState* other);
/**
* Getter function for Timespan.
*/
long long int getTimespan() {return Timespan;}
/**
* Setter function for Timespan.
*/
void setTimespan(long long int newTimeSpan){Timespan = newTimeSpan;}
/**
* Function printing the state to XML writer stream.
*/
void Print(QXmlStreamWriter * writer);
/**
* Function printing the attributes of the state into a String.
*/
std::string Print();
/**
* Function loading a State from XML reader Stream.
*/
QStringList LoadFromXML(QXmlStreamReader * reader);
/**
* Function used to count how many children should there be for state's TreeView item.
*/
int itemCount()
{
int i=0;//Type
i++;//timespan
if(parameters.size()>0)i++;
i+= this->outTransitionsCount();
return i;
}
/**
* Returns the i'th children of this state.
*/
TreeItem * getChild(int i, TreeItem * parent);
private:
/**
* Time, for which the system will stop (in ms).
*/
unsigned long long int Timespan;
};
#endif