#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(&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);"); }); connect(ui->doubleSpinBoxSystemCapacitance,static_cast(&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);"); }); connect(ui->doubleSpinBoxPreChargeTime,static_cast(&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);"); }); connect(ui->doubleSpinBoxChosenResistance,static_cast(&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);"); }); } 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); 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()); }