This repository has been archived by the owner on Jun 27, 2022. It is now read-only.
/
mainwindow.cpp
231 lines (174 loc) · 5.59 KB
/
mainwindow.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
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QtScript/qscriptengine.h"
#include "qdebug.h"
#include "ibex.h"
#include "sivia.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow),
xmin(-10), xmax(10), ymin(-10), ymax(10)
{
ui->setupUi(this);
Init();
}
void MainWindow::Init() {
this->show();
R = ui->graphicsView;
R->setDrawingArea(xmin,xmax,ymin,ymax);
R->Scene->setSceneRect(0,0,R->geometry().width()-3,R->geometry().height()-3);
ui->graphicsView->setMouseTracking(true);
connect(R,SIGNAL(repaint_all()),this,SLOT(drawAll()));
//Scenario
senario = new Scenario();
QString sf,sg;
senario->load(sf,sg);
ui->textf->setPlainText(sf);
ui->textg->setPlainText(sg);
Simu = new simulation();
sivia = NULL;
on_push_run_clicked();
}
MainWindow::~MainWindow() {
delete sivia;
delete senario;
delete Simu;
// delete R;
delete ui;
}
//Gestion redimensionnement
void MainWindow::resizeEvent(QResizeEvent* event){
QMainWindow::resizeEvent(event);
if(R!=NULL && this->isVisible()){
R->Scene->setSceneRect(0,0,R->geometry().width()-3,R->geometry().height()-3);
drawAll();
}
}
//Table d'evenements
void MainWindow::on_buttonField_stateChanged(int state)
{
drawAll();
}
void MainWindow::on_buttonPaving_stateChanged(int state)
{
drawAll();
}
void MainWindow::on_buttonSimu_stateChanged(int state)
{
drawAll();
}
void MainWindow::on_timeBar_valueChanged(int position)
{
drawAll();
}
void MainWindow::on_pushSave_clicked()
{
senario->save(ui->textf->toPlainText(),
ui->textg->toPlainText());
ui->push_run->setEnabled(true);
}
double MainWindow::str2double(QString s){
QScriptEngine e;
s.replace(QRegExp("PI"),"Math.PI");
QScriptValue v = e.evaluate(s);
return v.toNumber();
}
QString interval2String(Interval &i){
QString s;
s+= "[" + QString::number(i.lb()) + "," + QString::number(i.ub()) + "]";
return s;
}
void MainWindow::on_push_run_clicked()
{
ui->push_run->setEnabled(true);
//Run MonteCarlo Simulation
ui->timeBar->setMaximum(ui->t_max->text().toDouble()/Simu->dt);
Simu->simuMonteCarlo(ui->t_max->text().toDouble()/Simu->dt+1);
//Rune SIVIA
//Loading parameters
QScriptEngine e;
double _box[4][2];
_box[0][0] = (ui->x_min->text()).toDouble();
_box[0][1] = (ui->x_max->text()).toDouble();
_box[1][0] = (ui->y_min->text()).toDouble();
_box[1][1] = (ui->y_max->text()).toDouble();
_box[2][0] = str2double(ui->th_min->text());
_box[2][1] = str2double(ui->th_max->text());
_box[3][0] = (ui->t_min->text()).toDouble();
_box[3][1] = (ui->t_max->text()).toDouble();
if(sivia!=NULL) delete sivia;
IntervalVector box(4, _box);
//cout << box;
QTime t;
QString info;
t.start();
sivia = new Sivia(*R,ui->epsilonBox->value(), box);
double tsiv = t.elapsed()/1000.0;
info += "Elapsed time: " + QString::number(tsiv) + " s\n";
info += "\nInitial box:\n\tx:\t[" + QString::number(_box[0][0]) + "," + QString::number(_box[0][1]) + "]\n";
info += "\ty:\t[" + QString::number(_box[1][0]) + "," + QString::number(_box[1][1]) + "]\n";
info += "\ttheta:\t[" + QString::number(_box[2][0]) + "," + QString::number(_box[2][1]) + "]\n";
info += "\tt:\t[" + QString::number(_box[3][0]) + "," + QString::number(_box[3][1]) + "]\n";
info += "\tepsilon: " + QString::number(ui->epsilonBox->value()) + "\n";
info += "\nNumber of boxes: " + QString::number(sivia->Sout.size()+sivia->Sp.size());
info += "\nUnsafe boxes: " + QString::number(sivia->Sp.size());
QMessageBox::information(this,"Sivia report",info);
drawAll();
}
void MainWindow::on_loadfFromFile_clicked()
{
QString fileName1 = QFileDialog::getOpenFileName(this,tr("Open Text File For Function f"), "", tr("Text Files (*.txt)"));
QFile file1(fileName1);
if(!file1.open(QIODevice::ReadOnly | QIODevice::Text))
return;
ui->textf->setPlainText(file1.readAll());
file1.close();
//ui->push_run->setDisabled(true);
}
void MainWindow::on_loadgFromFile_clicked()
{
QString fileName1 = QFileDialog::getOpenFileName(this,tr("Open Text File For Function g"), "", tr("Text Files (*.txt)"));
QFile file1(fileName1);
if(!file1.open(QIODevice::ReadOnly | QIODevice::Text))
return;
ui->textg->setPlainText(file1.readAll());
file1.close();
//ui->push_run->setDisabled(true);
}
void MainWindow::on_textf_textChanged()
{
ui->push_run->setDisabled(true);
}
void MainWindow::on_textg_textChanged()
{
ui->push_run->setDisabled(true);
}
void MainWindow::on_pushZoomPlus_clicked()
{
R->zoomPlus();
}
void MainWindow::on_pushZoomMinus_clicked()
{
R->zoomMinus();
}
void MainWindow::on_pushZoomRaz_clicked()
{
R->zoomReset();
}
///Fonction d'affichage
void MainWindow::drawAll(){
double t = ui->timeBar->value();
ui->curTime->setText(QString::number(t*Simu->dt));
R->Clean();
//Drawing Paving if box checked
if(ui->buttonPaving->isChecked()){
drawPaving(sivia->Sout,sivia->Sp,t*Simu->dt,*R);
}
//Drawing Field if box checked
if(ui->buttonField->isChecked()){
Drawf(sivia->Sp,t*Simu->dt,*R);
}
//Drawing Simulation if box checked
if(ui->buttonSimu->isChecked()){
Simu->drawtraj(R);
Simu->drawrob(R,t);
}
}