-
Notifications
You must be signed in to change notification settings - Fork 1
/
simulationthread.cpp
133 lines (110 loc) · 3.44 KB
/
simulationthread.cpp
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
/*!
* \file simulationthread.cpp
* \author Simon Coakley
* \date 2012
* \copyright Copyright (c) 2012 University of Sheffield
* \brief Implementation of simulation thread
*/
#include <QtGui>
#include "./simulationthread.h"
SimulationThread::SimulationThread(QObject *parent)
: QThread(parent) {
machine = 0;
}
SimulationThread::~SimulationThread() {
mutex.lock();
m_abort = -1;
mutex.unlock();
wait();
}
void SimulationThread::startSim() {
m_abort = 1;
/*if(machine->machineModel->getStartState() != 0)
{
item = machine->getStartState();
item->setSelected(true);
}
else item = 0;*/
currentState = 0; // machine->machineModel->getStartState();
currentTransition = 0;
start();
}
void SimulationThread::stopSim() {
mutex.lock();
m_abort = -1;
mutex.unlock();
}
void SimulationThread::pauseSim() {
mutex.lock();
if (m_abort == 1) m_abort = 0;
else if (m_abort == 0) m_abort = 1;
mutex.unlock();
}
void SimulationThread::run() {
// qDebug() << "SimulationThread machine: " << machine->text(0);
// int rc;
while (currentState != 0 || currentTransition != 0) {
if (m_abort == -1) return;
while (m_abort == 0) msleep(10);
msleep(100);
if (currentState != 0) {
// qDebug() << "current State: " << currentState->name();
emit(selectState(currentState->name()));
for (int i = 0; i < machine->machineModel->getTransitions().size();
i++) {
if (machine->machineModel->
getTransitions().at(i)->
currentState() == currentState &&
machine->machineModel->
getTransitions().at(i)->
passesCondition(machine->memoryModel))
currentTransition =
machine->machineModel->getTransitions().at(i);
}
currentState = 0;
} else {
// qDebug() << "current Transition: " << currentTransition->name();
emit(this->selectTransition(currentTransition->name()));
currentTransition->updateMemory(machine->memoryModel);
currentState = currentTransition->nextState();
currentTransition = 0;
}
}
/*QList<Arrow *> transitions = machine->getTransitions();
QGraphicsItem * newItem;
while(item != 0)
{
newItem = 0;
for(int i = 0; i < transitions.size() && newItem == 0; i++)
{
if (m_abort == -1) return;
while(m_abort == 0) msleep(10);
msleep(100);
Arrow * t = transitions.at(i);
if(t->startItem() == item && t->passesCondition(memory))
{
//qDebug() << "transition: " << t->getName();
newItem = t;
emit( selectTransition(t) );
t->updateMemory(memory);
}
else if(t == item)
{
//qDebug() << "state: " << t->endItem()->getName();
newItem = t->endItem();
}
}
if(newItem == 0) return;
item->setSelected(false);
item = newItem;
item->setSelected(true);
emit( updateScene() );
}*/
/*for(int i = 0; i < 1000; i ++)
{
qDebug() << "run() " << i;
if (m_abort == -1) return;
while(m_abort == 0) msleep(10);
msleep(10);
}*/
}