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
|
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QDebug"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
/*TODO fix crash after changing Voltage!!!! */
ui->setupUi(this);
initializeGraphics();
connect(&m_wire,&Wire::calculation, [&]() {
ui->lineEditWireGauge->setText(m_wire.gauge());
ui->lineEditWireWeight->setText(QString::number(m_wire.weight()));
});
connect(&m_battery,&Battery::calculation, [&]() {
ui->lineEditCellCount->setText(QString::number(m_battery.seriesCells())+"S");
ui->lineEditVoltageRange->setText(QString::number(m_battery.minimumPackVoltage())+" - "+QString::number(m_battery.maximumPackVoltage()));
ui->lineEditPeakCurrent->setText(QString::number(m_battery.peakCurrent()));
});
connect(&m_generator,&Generator::calculation, [&]() {
ui->lineEditGeneratorKV->setText(QString::number(m_generator.generatorKV()));
});
connect(&m_precharge,&Precharge::calculation, [&]() {
ui->lineEditMaximumPrechargeResistance->setText(QString::number(m_precharge.maximumResistance()));
ui->lineEditActualPreChargeTime->setText(QString::number(m_precharge.actualPreChargeTime()));
ui->lineEditPeakInRushCurrent->setText(QString::number(m_precharge.peakInRushCurrent()));
ui->lineEditAveragePreChargePower->setText(QString::number(m_precharge.averagePower()));
});
connect(ui->doubleSpinBoxPreChargePercentageDesired,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), [=]() {
ui->lineEditActualPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->lineEditAveragePreChargePower->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->lineEditMaximumPrechargeResistance->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->lineEditPeakInRushCurrent->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->labelActualPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelAveragePreChargePower->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelMaxResistance->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelPeakInRushCurrent->setStyleSheet("color: rgb(0, 0, 0);");
ui->doubleSpinBoxChosenResistance->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->doubleSpinBoxPreChargePercentageDesired->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->doubleSpinBoxPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->doubleSpinBoxSystemCapacitance->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->labelChosenResistance->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelPreChargePercentageDesired->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelDesiredPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelSystemCapacitance->setStyleSheet("color: rgb(0, 0, 0);");
ui->doubleSpinBoxChosenResistance->setEnabled(true);
// disconnect(ui->doubleSpinBoxPreChargeTime,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),0,0);
// disconnect(ui->doubleSpinBoxPreChargePercentageDesired,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),0,0);
// disconnect(ui->doubleSpinBoxChosenResistance,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),0,0);
// disconnect(ui->doubleSpinBoxSystemCapacitance,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),0,0);
});
connect(ui->doubleSpinBoxSystemCapacitance,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), [=]() {
ui->lineEditActualPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->lineEditAveragePreChargePower->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->lineEditMaximumPrechargeResistance->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->lineEditPeakInRushCurrent->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->labelActualPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelAveragePreChargePower->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelMaxResistance->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelPeakInRushCurrent->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelActualPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelAveragePreChargePower->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelMaxResistance->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelPeakInRushCurrent->setStyleSheet("color: rgb(0, 0, 0);");
ui->doubleSpinBoxChosenResistance->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->doubleSpinBoxPreChargePercentageDesired->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->doubleSpinBoxPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->doubleSpinBoxSystemCapacitance->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->labelChosenResistance->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelPreChargePercentageDesired->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelDesiredPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelSystemCapacitance->setStyleSheet("color: rgb(0, 0, 0);");
ui->doubleSpinBoxChosenResistance->setEnabled(true);
// disconnect(ui->doubleSpinBoxPreChargeTime,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),0,0);
// disconnect(ui->doubleSpinBoxPreChargePercentageDesired,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),0,0);
// disconnect(ui->doubleSpinBoxChosenResistance,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),0,0);
// disconnect(ui->doubleSpinBoxSystemCapacitance,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),0,0);
});
connect(ui->doubleSpinBoxPreChargeTime,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), [=]() {
ui->lineEditActualPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->lineEditAveragePreChargePower->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->lineEditMaximumPrechargeResistance->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->lineEditPeakInRushCurrent->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->labelActualPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelAveragePreChargePower->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelMaxResistance->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelPeakInRushCurrent->setStyleSheet("color: rgb(0, 0, 0);");
ui->doubleSpinBoxChosenResistance->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->doubleSpinBoxPreChargePercentageDesired->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->doubleSpinBoxPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->doubleSpinBoxSystemCapacitance->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->labelChosenResistance->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelPreChargePercentageDesired->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelDesiredPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelSystemCapacitance->setStyleSheet("color: rgb(0, 0, 0);");
ui->doubleSpinBoxChosenResistance->setEnabled(true);
// disconnect(ui->doubleSpinBoxPreChargeTime,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),0,0);
// disconnect(ui->doubleSpinBoxPreChargePercentageDesired,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),0,0);
// disconnect(ui->doubleSpinBoxChosenResistance,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),0,0);
// disconnect(ui->doubleSpinBoxSystemCapacitance,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),0,0);
});
connect(ui->doubleSpinBoxChosenResistance,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), [=]() {
ui->lineEditActualPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->lineEditAveragePreChargePower->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->lineEditMaximumPrechargeResistance->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->lineEditPeakInRushCurrent->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->labelActualPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelAveragePreChargePower->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelMaxResistance->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelPeakInRushCurrent->setStyleSheet("color: rgb(0, 0, 0);");
ui->doubleSpinBoxChosenResistance->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->doubleSpinBoxPreChargePercentageDesired->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->doubleSpinBoxPreChargeTime->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->doubleSpinBoxSystemCapacitance->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->labelChosenResistance->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelPreChargePercentageDesired->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelDesiredPreChargeTime->setStyleSheet("color: rgb(0, 0, 0);");
ui->labelSystemCapacitance->setStyleSheet("color: rgb(0, 0, 0);");
ui->doubleSpinBoxChosenResistance->setEnabled(true);
// disconnect(ui->doubleSpinBoxPreChargeTime,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),0,0);
// disconnect(ui->doubleSpinBoxPreChargePercentageDesired,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),0,0);
// disconnect(ui->doubleSpinBoxChosenResistance,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),0,0);
// disconnect(ui->doubleSpinBoxSystemCapacitance,static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),0,0);
});
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_spinBoxPeakSystemPower_valueChanged(double arg1)
{
m_wire.setPeakSystemPower(arg1);
m_wire.calculate();
m_battery.setPeakSystemPower(arg1);
m_battery.calculate();
}
void MainWindow :: initializeGraphics()
{
for(auto entry : batteries)ui->comboBoxBatteryChemistry->addItem(entry.name);
for(auto entry : wireMaterials)ui->comboBoxWireMaterial->addItem(entry);
}
void MainWindow::on_comboBoxBatteryChemistry_currentIndexChanged(int index)
{
m_battery.changeBatteryChemistry(index);
m_battery.calculate();
}
void MainWindow::on_actionactionSettings_triggered()
{
}
void MainWindow::on_comboBoxWireMaterial_currentIndexChanged(int index)
{
m_wire.setActiveWireType(index);
m_wire.calculate();
}
void MainWindow::on_doubleSpinBoxSystemVoltage_valueChanged(double arg1)
{
//m_wire.setSystemVoltage(arg1);
//m_wire.calculate();
m_battery.setSystemVoltage(arg1);
m_battery.calculate();
m_generator.setSystemVoltage(arg1);
m_generator.calculate();
}
void MainWindow::on_doubleSpinBoxEstimatedWireLength_valueChanged(double arg1)
{
m_wire.setWireLength(arg1);
m_wire.calculate();
}
void MainWindow::on_lineEditVoltageRange_textChanged(const QString &arg1)
{
double min = arg1.split(" - ")[0].toDouble();
double max = arg1.split(" - ")[1].toDouble();
m_wire.setSystemVoltage(min);
m_wire.calculate();
m_precharge.setMaximumVoltage(max);
if(ui->doubleSpinBoxChosenResistance->isEnabled())m_precharge.calculate();
}
void MainWindow::on_doubleSpinBoxMinimumAllowableSOC_valueChanged(double arg1)
{
m_battery.setMinimumSOC(arg1);
m_battery.calculate();
if (arg1 > 0)
{
ui->doubleSpinBoxMinimumAllowableSOC->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->labelMinimumAllowableSOC->setStyleSheet("color: rgb(0, 0, 0);");
}
else
{
ui->doubleSpinBoxMinimumAllowableSOC->setStyleSheet("background-color: rgba(255, 255, 255, 80);"
"color: rgba(0, 0, 0, 80);");
ui->labelMinimumAllowableSOC->setStyleSheet("color: rgba(0, 0, 0, 120);");
}
}
void MainWindow::on_doubleSpinBoxGeneratorRPM_valueChanged(double arg1)
{
m_generator.setRPM(arg1);
m_generator.calculate();
if (arg1 > 0)
{
ui->doubleSpinBoxGeneratorRPM->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->labelGeneratorRPM->setStyleSheet("color: rgb(0, 0, 0);");
ui->lineEditGeneratorKV->setStyleSheet("background-color: rgb(255, 255, 255);"
"color: rgb(0, 0, 0);");
ui->labelGeneratorKV->setStyleSheet("color: rgb(0, 0, 0);");
}
else
{
ui->doubleSpinBoxGeneratorRPM->setStyleSheet("background-color: rgba(255, 255, 255, 80);"
"color: rgba(0, 0, 0, 80);");
ui->labelGeneratorRPM->setStyleSheet("color: rgba(0, 0, 0, 120);");
ui->lineEditGeneratorKV->setStyleSheet("background-color: rgba(255, 255, 255, 80);"
"color: rgba(0, 0, 0, 80);");
ui->labelGeneratorKV->setStyleSheet("color: rgba(0, 0, 0, 120);");
ui->lineEditGeneratorKV->setText("--");
}
}
void MainWindow::on_doubleSpinBoxPreChargeTime_valueChanged(double arg1)
{
m_precharge.setPreChargeTime(arg1);
m_precharge.calculate();
}
void MainWindow::on_doubleSpinBoxSystemCapacitance_valueChanged(double arg1)
{
m_precharge.setSystemCapacitance(arg1);
m_precharge.calculate();
}
void MainWindow::on_doubleSpinBoxPreChargePercentageDesired_valueChanged(double arg1)
{
m_precharge.setPreChargePercentage(arg1);
m_precharge.calculate();
}
void MainWindow::on_doubleSpinBoxChosenResistance_valueChanged(double arg1)
{
m_precharge.setChosenResistance(arg1);
m_precharge.calculate();
}
void MainWindow::on_lineEditMaximumPrechargeResistance_textChanged(const QString &arg1)
{
ui->doubleSpinBoxChosenResistance->setMaximum(arg1.toDouble());
if(ui->doubleSpinBoxChosenResistance->value() > arg1.toDouble()) ui->doubleSpinBoxChosenResistance->setValue(arg1.toDouble());
}
|