-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
148 lines (126 loc) · 4.81 KB
/
mainwindow.cpp
File metadata and controls
148 lines (126 loc) · 4.81 KB
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
#include "mainwindow.h"
#include "ui_mainwindow_v2.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
model(new Model),
ltView(new LTView)
{
ui->setupUi(this);
ui->bStop->setEnabled(false);
/* Установка фонового изображения */
QPixmap pmap ("background.png");
ui->lBackground->setPixmap(pmap);
ui->ltViewLayout->addWidget(ltView);
connect(ui->bStart, SIGNAL(released()), this, SLOT(bStartHandler()));
connect(ui->bStop, SIGNAL(released()), this, SLOT(bStopHandler()));
connect(this, SIGNAL(startSimulation()), model, SLOT(start()));
connect(this, SIGNAL(stopSimulation()), model, SLOT(stop()));
connect(model, SIGNAL(update()), this, SLOT(updateDataOnUI()));
connect(ui->cbManualU, SIGNAL(clicked(bool)), this, SLOT(cbManualU(bool)));
}
MainWindow::~MainWindow()
{
delete ui;
}
/* Обработчик нажатия кнопки Start */
void MainWindow::bStartHandler(){
ui->bStart->setEnabled(false);
ui->bStop->setEnabled(true);
uploadDataToModel();
emit startSimulation();
}
/* Обработчик нажатия кнопки Stop */
void MainWindow::bStopHandler(){
ui->bStart->setEnabled(true);
ui->bStop->setEnabled(false);
emit stopSimulation();
}
/* Обработчик для кнопки ручного управления насосами */
void MainWindow::cbManualU(bool state){
if (state){
model->setManualU(state);
connect(ui->cbPump1, SIGNAL(clicked(bool)), this, SLOT(cbU1(bool)));
connect(ui->cbPump2, SIGNAL(clicked(bool)), this, SLOT(cbU2(bool)));
} else {
model->setManualU(state);
disconnect(ui->cbPump1, SIGNAL(clicked(bool)), this, NULL);
disconnect(ui->cbPump2, SIGNAL(clicked(bool)), this, NULL);
}
}
void MainWindow::cbU1(bool state){
model->setU1(state);
}
void MainWindow::cbU2(bool state){
model->setU2(state);
}
/* Инициализация модели */
void MainWindow::uploadDataToModel(){
double temp;
QMap<QString, double> params;
temp = ui->tableWidget->item(0,0)->text().toDouble();
params.insert("LH", temp);
temp = ui->tableWidget->item(1,0)->text().toDouble();
params.insert("LL", temp);
temp = ui->tableWidget->item(2,0)->text().toDouble();
params.insert("Level", temp);
temp = ui->tableWidget->item(3,0)->text().toDouble();
params.insert("TH", temp);
temp = ui->tableWidget->item(4,0)->text().toDouble();
params.insert("TL", temp);
temp = ui->tableWidget->item(5,0)->text().toDouble();
params.insert("Tin", temp);
temp = ui->tableWidget->item(6,0)->text().toDouble();
params.insert("Tout", temp);
temp = ui->tableWidget->item(7,0)->text().toDouble();
params.insert("Temp", temp);
temp = ui->tableWidget->item(8,0)->text().toDouble();
params.insert("S", temp);
temp = ui->tableWidget->item(9,0)->text().toDouble();
params.insert("C", temp);
temp = ui->tableWidget->item(10,0)->text().toDouble();
params.insert("R", temp);
temp = ui->tableWidget->item(11,0)->text().toDouble();
params.insert("K", temp);
temp = ui->tableWidget->item(12,0)->text().toDouble();
params.insert("Q", temp);
temp = ui->tableWidget->item(13,0)->text().toDouble();
params.insert("sT", temp);
temp = ui->tableWidget->item(14,0)->text().toDouble();
params.insert("dT", temp);
temp = ui->tableWidget->item(15,0)->text().toDouble();
params.insert("dTgist", temp);
temp = ui->tableWidget->item(16,0)->text().toDouble();
params.insert("sL", temp);
temp = ui->tableWidget->item(17,0)->text().toDouble();
params.insert("dL", temp);
temp = ui->tableWidget->item(18,0)->text().toDouble();
params.insert("dLgist", temp);
temp = ui->tableWidget->item(19,0)->text().toDouble();
params.insert("tMod", temp);
temp = ui->tableWidget->item(20,0)->text().toDouble();
params.insert("tReg", temp);
model->applySettings(params);
ltView->applySettings(params);
}
/* Отображение данных модели на экране */
void MainWindow::updateDataOnUI(){
double temp, level, slevel, stemp, lh;
bool state;
level = model->getLevel();
temp = model->getTemp();
slevel = model->getLevelFromSensor();
stemp = model->getTempFromSensor();
lh = ui->tableWidget->item(0,0)->text().toDouble();
ui->tableWidget->item(2,0)->setText(QString::number(level));
ui->tableWidget->item(7,0)->setText(QString::number(temp));
ui->pbPool->setValue(level / lh * 100);
// Установка точки на графике
ltView->setCursor(stemp, slevel);
// Перерисовка
ltView->updateView();
state = model->getU1();
ui->cbPump1->setChecked(state);
state = model->getU2();
ui->cbPump2->setChecked(state);
}