#include "visualizationpage.h" #include "ui_visualizationpage.h" #include #include VisualizationPage::VisualizationPage(QWidget *parent) : QFrame(parent), ui(new Ui::VisualizationPage), mDieBieMS(nullptr) { ui->setupUi(this); mIsThisPageActivated = false; ui->pbPlus->hide(); ui->rtText->hide(); ui->tempGraph->hide(); ui->lbTCurTemp->hide(); ui->lbVTime->hide(); ui->lbATime->hide(); ui->lbTTime->hide(); ui->lbCTime->hide(); //V ui->lbVMidLegendVal->hide(); ui->lbVMidLegendMeasure->hide(); ui->lbVSecondLegendColorLine->hide(); ui->lbVSecondLegendSubTitle->hide(); //V ui->lbVMinLegendVal->hide(); ui->lbVMinLegendMeasure->hide(); ui->lbVThirdLegendColorLine->hide(); ui->lbVThirdLegendSubTitle->hide(); //A ui->lbAMidLegendVal->hide(); ui->lbAMidLegendMeasure->hide(); ui->lbASecondLegendColorLine->hide(); ui->lbASecondLegendSubTitle->hide(); //A ui->lbAMinLegendVal->hide(); ui->lbAMinLegendMeasure->hide(); ui->lbAThirdLegendColorLine->hide(); ui->lbAThirdLegendSubTitle->hide(); ui->checkBox->hide(); /* ui->lbTMinLegendVal->hide(); ui->lbTMinLegendMeasure->hide(); ui->lbTThirdLegendColorLine->hide(); ui->lbTThirdLegendSubTitle->hide(); ui->lbTMinLegendValBms->hide(); ui->lbTMinLegendMeasureBms->hide(); ui->lbTThirdLegendColorLineBms->hide(); ui->lbTThirdLegendSubTitleBms->hide(); */ m_btnGroup = new QButtonGroup(this); m_btnGroup->addButton(ui->pbVisualizationMenuBarVoltage ); m_btnGroup->addButton(ui->pbVisualizationMenuBarAmperage ); m_btnGroup->addButton(ui->pbVisualizationMenuBarTemperatureBat ); m_btnGroup->addButton(ui->pbVisualizationMenuBarTemperatureBms ); m_btnGroup->addButton(ui->pbVisualizationMenuBarCells ); m_btnGroup->addButton(ui->pbVisualizationMenuBarCellsAll ); m_currentPageIndex = TabWidgetPage::TemperatureBat; onTabBarButtonClicked(); chartV = new VisualizationChart(ui->chartViewVoltage->geometry().width(), ui->chartViewVoltage->geometry().height()); chartV->setTitleForY("Напряжение, В"); chartV->addSeriesWithNumber(VoltageMax , tr("Максимальная"), Qt::red); //chartV->addSeriesWithNumber(VoltageMid , tr("Средняя"), Qt::green); //chartV->addSeriesWithNumber(VoltageMin , tr("Низкая"), Qt::yellow); chartA = new VisualizationChart(ui->chartViewAmperage->geometry().width(), ui->chartViewAmperage->geometry().height()); chartA->setTitleForY("Ток, А"); chartA->addSeriesWithNumber(AmperageMax , tr("Максимальная"), Qt::red); //chartA->addSeriesWithNumber(AmperageMid , tr("Средняя"), Qt::green); //chartA->addSeriesWithNumber(AmperageMin , tr("Низкая"), Qt::yellow); //ui->chartViewTemperature->geometry().width(), //ui->chartViewTemperature->geometry().height(), //-10, 50, false); /* chartT->addSeriesWithNumber(TemperatureMax , tr("Максимальная"), Qt::red); chartT->addSeriesWithNumber(TemperatureMid , tr("Средняя"), Qt::green); chartT->addSeriesWithNumber(TemperatureMin , tr("Низкая"), Qt::yellow); */ chartT = new VisualizationChart(ui->chartViewTemperature->geometry().width(), ui->chartViewTemperature->geometry().height()); chartT->setTitleForY("Температура, °C"); chartT->addSeriesWithNumber(TemperatureBatMax , tr("Максимальная"), Qt::red); chartT->addSeriesWithNumber(TemperatureBatMid , tr("Средняя"), Qt::green); chartT->addSeriesWithNumber(TemperatureBatMin , tr("Низкая"), Qt::yellow); chartTB = new VisualizationChart(ui->chartViewTemperatureBms->geometry().width(), ui->chartViewTemperatureBms->geometry().height()); chartTB->setTitleForY("Температура, °C"); chartTB->addSeriesWithNumber(TemperatureBmsMax , tr("Максимальная"), Qt::red); chartTB->addSeriesWithNumber(TemperatureBmsMid , tr("Средняя"), Qt::green); chartTB->addSeriesWithNumber(TemperatureBmsMin , tr("Низкая"), Qt::yellow); chartC = new VisualizationChart(ui->chartViewCells->geometry().width(), ui->chartViewCells->geometry().height()); chartC->setTitleForY("Напряжение, В"); chartC->addSeriesWithNumber(CellsMax , tr("Максимальная"), Qt::red); chartC->addSeriesWithNumber(CellsMid , tr("Средняя"), Qt::green); chartC->addSeriesWithNumber(CellsMin , tr("Низкая"), Qt::yellow); chartCA = new VisualizationChart(ui->chartViewCellsAll->geometry().width(), ui->chartViewCellsAll->geometry().height()); chartCA->setTitleForY("Напряжение, В"); initColorsForChartCellsAll(); //chartCA->legend(); /* chartC->addSeriesWithNumber(CellsMax , tr("Максимальная"), Qt::red); chartC->addSeriesWithNumber(CellsMid , tr("Средняя"), Qt::green); chartC->addSeriesWithNumber(CellsMin , tr("Низкая"), Qt::yellow); */ //chartV->setTitleForY(tr("Напряжение, В")); //chartA->setTitleForY(tr("Ток, А")); //chartT->setTitleForY(tr("Температура, °C")); //chartC->setTitleForY(tr("?????, ??")); ui->chartViewVoltage->setChart(chartV); ui->chartViewAmperage->setChart(chartA); ui->chartViewTemperature->setChart(chartT); ui->chartViewTemperatureBms->setChart(chartTB); ui->chartViewCells->setChart(chartC); ui->chartViewCellsAll->setChart(chartCA); ui->chartViewVoltage->setRenderHint(QPainter::Antialiasing); ui->chartViewAmperage->setRenderHint(QPainter::Antialiasing); ui->chartViewTemperature->setRenderHint(QPainter::Antialiasing); ui->chartViewTemperatureBms->setRenderHint(QPainter::Antialiasing); ui->chartViewCells->setRenderHint(QPainter::Antialiasing); ui->chartViewCellsAll->setRenderHint(QPainter::Antialiasing); connect(chartV, &VisualizationChart::sendSecs, this, &VisualizationPage::onSetSecsV); connect(chartA, &VisualizationChart::sendSecs, this, &VisualizationPage::onSetSecsA); connect(chartT, &VisualizationChart::sendSecs, this, &VisualizationPage::onSetSecsT); connect(chartTB, &VisualizationChart::sendSecs, this, &VisualizationPage::onSetSecsT); connect(chartC, &VisualizationChart::sendSecs, this, &VisualizationPage::onSetSecsC); //connect(chartCA, &VisualizationChart::sendSecs, this, &VisualizationPage::onSetSecsCA); connect(m_btnGroup, QOverload::of(&QButtonGroup::buttonClicked), this, &VisualizationPage::onTabBarButtonClicked); //initForPlot(); initForCharts(); #if TURN_ON_DUMMY_DATA_FLOW_TO_GRAPHS onVisualizationPageSelected(); initListWidgetOfCells(10); #endif } VisualizationPage::~VisualizationPage() { delete ui; } int VisualizationPage::mOldCellsNumber = 0; void VisualizationPage::initListWidgetOfCells(int cells) { bool doResetCellsList = (mOldCellsNumber != cells); mOldCellsNumber = cells; if(doResetCellsList) { ui->listwgtCells->clear(); for(int i = 0; i < cells; ++i) { QListWidgetItem *item = new QListWidgetItem; //item->setData(Qt::UserRole, i); item->setData(Qt::CheckStateRole, Qt::Checked); QString name; QColor color; chartCA->getSeriesWithNumberNameAndColor(i, name, color); QString cname = color.name(); QString cnumber = QString::number(i+1); //item->setData(Qt::DisplayRole, "["+ QString::number(i+1) + "] - " + name ); item->setData(Qt::DisplayRole, "["+ cnumber + "] - Ячейка " + cnumber ); item->setForeground(color); //(Qt::red); //connect (item, QListWidgetItem:: ); connect(ui->listwgtCells, &QListWidget::itemChanged, this, &VisualizationPage::onChecked); ui->listwgtCells->addItem(item); } } } void VisualizationPage::onChecked(QListWidgetItem *item) { int irow = ui->listwgtCells->row(item); // starts with ZERO QString text = item->text(); bool checked = (item->checkState() == Qt::CheckState::Checked); //int colorMapIndex = item->data(Qt::UserRole).toInt(); if(checked) //ui->checkBox->isChecked()) { chartCA->showSeriesWithNumber(irow); } else { chartCA->hideSeriesWithNumber(irow); } //connect(ui->listwgtCells, &QListWidget::itemChanged, } void VisualizationPage::initColorsForChartCellsAll() { //Qt::white //Qt::color0 //Qt::color1 //chartCA->addSeriesWithNumber( CellQtwhite ,tr("CellQtwhite "), QColor(Qt::white ) ); chartCA->addSeriesWithNumber( CellQtblack ,tr("CellQtblack "), QColor(Qt::black ) ); chartCA->addSeriesWithNumber( CellQtdarkGray ,tr("CellQtdarkGray "), QColor(Qt::darkGray ) ); chartCA->addSeriesWithNumber( CellQtgray ,tr("CellQtgray "), QColor(Qt::gray ) ); chartCA->addSeriesWithNumber( CellQtlightGray ,tr("CellQtlightGray "), QColor(Qt::lightGray ) ); chartCA->addSeriesWithNumber( CellQtred ,tr("CellQtred "), QColor(Qt::red ) ); chartCA->addSeriesWithNumber( CellQtgreen ,tr("CellQtgreen "), QColor(Qt::green ) ); chartCA->addSeriesWithNumber( CellQtblue ,tr("CellQtblue "), QColor(Qt::blue ) ); chartCA->addSeriesWithNumber( CellQtcyan ,tr("CellQtcyan "), QColor(Qt::cyan ) ); chartCA->addSeriesWithNumber( CellQtmagenta ,tr("CellQtmagenta "), QColor(Qt::magenta ) ); chartCA->addSeriesWithNumber( CellQtyellow ,tr("CellQtyellow "), QColor(Qt::yellow ) ); chartCA->addSeriesWithNumber( CellQtdarkRed ,tr("CellQtdarkRed "), QColor(Qt::darkRed ) ); chartCA->addSeriesWithNumber( CellQtdarkGreen ,tr("CellQtdarkGreen "), QColor(Qt::darkGreen ) ); chartCA->addSeriesWithNumber( CellQtdarkBlue ,tr("CellQtdarkBlue "), QColor(Qt::darkBlue ) ); chartCA->addSeriesWithNumber( CellQtdarkCyan ,tr("CellQtdarkCyan "), QColor(Qt::darkCyan ) ); chartCA->addSeriesWithNumber( CellQtdarkMagenta ,tr("CellQtdarkMagenta "), QColor(Qt::darkMagenta ) ); chartCA->addSeriesWithNumber( CellQtdarkYellow ,tr("CellQtdarkYellow "), QColor(Qt::darkYellow ) ); //chartCA->addSeriesWithNumber(CellsMax , tr("Максимальная"), Qt::red); chartCA->addSeriesWithNumber( CellAlmond ,tr("CellAlmond "), QColor("#EFDBC5") ); // 239,219,197 chartCA->addSeriesWithNumber( CellAntiqueBrass ,tr("CellAntiqueBrass "), QColor("#CD9575") ); // 205,149,117 chartCA->addSeriesWithNumber( CellApricot ,tr("CellApricot "), QColor("#FDD9B5") ); // 253,217,181 chartCA->addSeriesWithNumber( CellAquamarine ,tr("CellAquamarine "), QColor("#78DBE2") ); // 120,219,226 chartCA->addSeriesWithNumber( CellAsparagus ,tr("CellAsparagus "), QColor("#87A96B") ); // 135,169,107 chartCA->addSeriesWithNumber( CellAtomicTangerine ,tr("CellAtomicTangerine "), QColor("#FFA474") ); // 255,164,116 chartCA->addSeriesWithNumber( CellBananaMania ,tr("CellBananaMania "), QColor("#FAE7B5") ); // 250,231,181 chartCA->addSeriesWithNumber( CellBeaver ,tr("CellBeaver "), QColor("#9F8170") ); // 159,129,112 chartCA->addSeriesWithNumber( CellBittersweet ,tr("CellBittersweet "), QColor("#FD7C6E") ); // 253,124,110 chartCA->addSeriesWithNumber( CellBlack ,tr("CellBlack "), QColor("#232323") ); // 35,35,35 chartCA->addSeriesWithNumber( CellBlue ,tr("CellBlue "), QColor("#1F75FE") ); // 31,117,254 chartCA->addSeriesWithNumber( CellBlueBell ,tr("CellBlueBell "), QColor("#ADADD6") ); // 173,173,214 chartCA->addSeriesWithNumber( CellBlueGreen ,tr("CellBlueGreen "), QColor("#199EBD") ); // 25,158,189 chartCA->addSeriesWithNumber( CellBlueViolet ,tr("CellBlueViolet "), QColor("#2E5090") ); // 115,102,189 chartCA->addSeriesWithNumber( CellBluetiful ,tr("CellBluetiful "), QColor("#7366BD") ); // 46,80,144 chartCA->addSeriesWithNumber( CellBlush ,tr("CellBlush "), QColor("#DE5D83") ); // 222,93,131 chartCA->addSeriesWithNumber( CellBrickRed ,tr("CellBrickRed "), QColor("#CB4154") ); // 203,65,84 chartCA->addSeriesWithNumber( CellBrown ,tr("CellBrown "), QColor("#B5674D") ); // 180,103,77 chartCA->addSeriesWithNumber( CellBurntOrange ,tr("CellBurntOrange "), QColor("#FF7F49") ); // 255,127,73 chartCA->addSeriesWithNumber( CellBurntSienna ,tr("CellBurntSienna "), QColor("#EA7E5D") ); // 234,126,93 chartCA->addSeriesWithNumber( CellCadetBlue ,tr("CellCadetBlue "), QColor("#B0B7C6") ); // 176,183,198 chartCA->addSeriesWithNumber( CellCanary ,tr("CellCanary "), QColor("#FFFF99") ); // 255,255,159 chartCA->addSeriesWithNumber( CellCaribbeanGreen ,tr("CellCaribbeanGreen "), QColor("#1CD3A2") ); // 28,211,162 chartCA->addSeriesWithNumber( CellCarnationPink ,tr("CellCarnationPink "), QColor("#FFAACC") ); // 255,170,204 chartCA->addSeriesWithNumber( CellCerise ,tr("CellCerise "), QColor("#FF43A4") ); // 221,68,146 chartCA->addSeriesWithNumber( CellCerulean ,tr("CellCerulean "), QColor("#1DACD6") ); // 29,172,214 chartCA->addSeriesWithNumber( CellChestnut ,tr("CellChestnut "), QColor("#BC5D58") ); // 188,93,88 chartCA->addSeriesWithNumber( CellCopper ,tr("CellCopper "), QColor("#DD9475") ); // 221,148,117 chartCA->addSeriesWithNumber( CellCornflower ,tr("CellCornflower "), QColor("#9ACEEB") ); // 154,206,235 chartCA->addSeriesWithNumber( CellCottonCandy ,tr("CellCottonCandy "), QColor("#FFBCD9") ); // 255,188,217 chartCA->addSeriesWithNumber( CellDenim ,tr("CellDenim "), QColor("#2B6CC4") ); // 43,108,196 chartCA->addSeriesWithNumber( CellDesertSand ,tr("CellDesertSand "), QColor("#EFCDB8") ); // 239,205,184 chartCA->addSeriesWithNumber( CellEggplant ,tr("CellEggplant "), QColor("#DD4492") ); // 110,81,96 chartCA->addSeriesWithNumber( CellElectricLime ,tr("CellElectricLime "), QColor("#1DF914") ); // 29,249,20 chartCA->addSeriesWithNumber( CellFern ,tr("CellFern "), QColor("#71BC78") ); // 113,188,120 chartCA->addSeriesWithNumber( CellForestGreen ,tr("CellForestGreen "), QColor("#6DAE81") ); // 109,174,129 chartCA->addSeriesWithNumber( CellFuchsia ,tr("CellFuchsia "), QColor("#C364C5") ); // 195,100,197 chartCA->addSeriesWithNumber( CellFuzzyWuzzy ,tr("CellFuzzyWuzzy "), QColor("#CC6666") ); // 204,102,102 chartCA->addSeriesWithNumber( CellGold ,tr("CellGold "), QColor("#E7C697") ); // 231,198,151 chartCA->addSeriesWithNumber( CellGoldenrod ,tr("CellGoldenrod "), QColor("#FCD975") ); // 255,217,117 chartCA->addSeriesWithNumber( CellGrannySmithApple ,tr("CellGrannySmithApple "), QColor("#A8E4A0") ); // 168,228,160 chartCA->addSeriesWithNumber( CellGray ,tr("CellGray "), QColor("#95918C") ); // 149,145,140 chartCA->addSeriesWithNumber( CellGreen ,tr("CellGreen "), QColor("#1CAC78") ); // 28,172,120 chartCA->addSeriesWithNumber( CellGreenYellow ,tr("CellGreenYellow "), QColor("#F0E891") ); // 240,232,145 chartCA->addSeriesWithNumber( CellHotMagenta ,tr("CellHotMagenta "), QColor("#FF1DCE") ); // 255,29,206 chartCA->addSeriesWithNumber( CellInchworm ,tr("CellInchworm "), QColor("#B2EC5D") ); // 178,236,93 chartCA->addSeriesWithNumber( CellIndigo ,tr("CellIndigo "), QColor("#5D76CB") ); // 93,118,203 chartCA->addSeriesWithNumber( CellJazzberryJam ,tr("CellJazzberryJam "), QColor("#CA3767") ); // 202,55,103 chartCA->addSeriesWithNumber( CellJungleGreen ,tr("CellJungleGreen "), QColor("#3BB08F") ); // 59,176,143 chartCA->addSeriesWithNumber( CellLaserLemon ,tr("CellLaserLemon "), QColor("#FDFC74") ); // 253,252,116 chartCA->addSeriesWithNumber( CellLavender ,tr("CellLavender "), QColor("#FCB4D5") ); // 252,180,213 chartCA->addSeriesWithNumber( CellMacaroniAndCheese ,tr("CellMacaroniAndCheese "), QColor("#FFBD88") ); // 255,189,136 chartCA->addSeriesWithNumber( CellMagenta ,tr("CellMagenta "), QColor("#FCB4D5") ); // 246,100,175 chartCA->addSeriesWithNumber( CellMahogany ,tr("CellMahogany "), QColor("#CD4A4A") ); // 205,74,74 chartCA->addSeriesWithNumber( CellManatee ,tr("CellManatee "), QColor("#979AAA") ); // 151,154,170 chartCA->addSeriesWithNumber( CellMangoTango ,tr("CellMangoTango "), QColor("#FF8243") ); // 255,130,67 chartCA->addSeriesWithNumber( CellMaroon ,tr("CellMaroon "), QColor("#C8385A") ); // 200,56,90 chartCA->addSeriesWithNumber( CellMauvelous ,tr("CellMauvelous "), QColor("#EF98AA") ); // 239,152,170 chartCA->addSeriesWithNumber( CellMelon ,tr("CellMelon "), QColor("#FDBCB4") ); // 253,188,180 chartCA->addSeriesWithNumber( CellMidnightBlue ,tr("CellMidnightBlue "), QColor("#1A4876") ); // 26,72,118 chartCA->addSeriesWithNumber( CellMountainMeadow ,tr("CellMountainMeadow "), QColor("#30BA8F") ); // 48,186,143 chartCA->addSeriesWithNumber( CellNavyBlue ,tr("CellNavyBlue "), QColor("#1974D2") ); // 25,116,210 chartCA->addSeriesWithNumber( CellNeonCarrot ,tr("CellNeonCarrot "), QColor("#FFA343") ); // 255,163,67 chartCA->addSeriesWithNumber( CellOliveGreen ,tr("CellOliveGreen "), QColor("#BAB86C") ); // 186,184,108 chartCA->addSeriesWithNumber( CellOrange ,tr("CellOrange "), QColor("#FF7538") ); // 255,117,56 chartCA->addSeriesWithNumber( CellOrchid ,tr("CellOrchid "), QColor("#C0448F") ); // 230,168,215 chartCA->addSeriesWithNumber( CellOuterSpace ,tr("CellOuterSpace "), QColor("#414AAC") ); // 65,74,76 chartCA->addSeriesWithNumber( CellOutrageousOrange ,tr("CellOutrageousOrange "), QColor("#FF6E4A") ); // 255,110,74 chartCA->addSeriesWithNumber( CellPacificBlue ,tr("CellPacificBlue "), QColor("#1CA9C9") ); // 28,169,201 chartCA->addSeriesWithNumber( CellPeach ,tr("CellPeach "), QColor("#FFCFAB") ); // 255,207,171 chartCA->addSeriesWithNumber( CellPeriwinkle ,tr("CellPeriwinkle "), QColor("#C5D0E6") ); // 197,208,230 chartCA->addSeriesWithNumber( CellPiggyPink ,tr("CellPiggyPink "), QColor("#FDD7E4") ); // 253,215,228 chartCA->addSeriesWithNumber( CellPineGreen ,tr("CellPineGreen "), QColor("#158078") ); // 21,128,120 chartCA->addSeriesWithNumber( CellPinkFlamingo ,tr("CellPinkFlamingo "), QColor("#FC74FD") ); // 252,116,253 chartCA->addSeriesWithNumber( CellPinkSherbet ,tr("CellPinkSherbet "), QColor("#F780A1") ); // 247,128,161 chartCA->addSeriesWithNumber( CellPlum ,tr("CellPlum "), QColor("#8E4584") ); // 142,69,133 chartCA->addSeriesWithNumber( CellPurpleHeart ,tr("CellPurpleHeart "), QColor("#7442C8") ); // 116,66,200 chartCA->addSeriesWithNumber( CellPurpleMountainsMajesty ,tr("CellPurpleMountainsMajesty "), QColor("#9D81BA") ); // 157,129,186 chartCA->addSeriesWithNumber( CellPurplePizza ,tr("CellPurplePizza "), QColor("#FF1DCE") ); // 255,29,206 chartCA->addSeriesWithNumber( CellRadicalRed ,tr("CellRadicalRed "), QColor("#FF496C") ); // 255,73,107 chartCA->addSeriesWithNumber( CellRawSienna ,tr("CellRawSienna "), QColor("#D68A59") ); // 214,138,89 chartCA->addSeriesWithNumber( CellRazzleDazzleRose ,tr("CellRazzleDazzleRose "), QColor("#E6A8D7") ); // 255,72,208 chartCA->addSeriesWithNumber( CellRazzmatazz ,tr("CellRazzmatazz "), QColor("#E3256B") ); // 227,37,107 chartCA->addSeriesWithNumber( CellRed ,tr("CellRed "), QColor("#EE204D") ); // 238,32,77 chartCA->addSeriesWithNumber( CellRedOrange ,tr("CellRedOrange "), QColor("#FF5349") ); // 255,83,73 chartCA->addSeriesWithNumber( CellRedViolet ,tr("CellRedViolet "), QColor("#c0448f") ); // 192,68,143 chartCA->addSeriesWithNumber( CellRobinsEggBlue ,tr("CellRobinsEggBlue "), QColor("#1FCECB") ); // 31,206,203 chartCA->addSeriesWithNumber( CellRoyalPurple ,tr("CellRoyalPurple "), QColor("#7851A9") ); // 120,81,169 chartCA->addSeriesWithNumber( CellSalmon ,tr("CellSalmon "), QColor("#FF9BAA") ); // 255,155,170 chartCA->addSeriesWithNumber( CellScarlet ,tr("CellScarlet "), QColor("#FC2847") ); // 242,40,71 chartCA->addSeriesWithNumber( CellScreaminGreen ,tr("CellScreaminGreen "), QColor("#76FF7A") ); // 118,255,122 chartCA->addSeriesWithNumber( CellSeaGreen ,tr("CellSeaGreen "), QColor("#9FE2BF") ); // 159,226,191 chartCA->addSeriesWithNumber( CellSepia ,tr("CellSepia "), QColor("#A5694F") ); // 165,105,79 chartCA->addSeriesWithNumber( CellShadow ,tr("CellShadow "), QColor("#8A795D") ); // 138,121,93 chartCA->addSeriesWithNumber( CellShamrock ,tr("CellShamrock "), QColor("#45CEA2") ); // 69,206,162 chartCA->addSeriesWithNumber( CellShockingPink ,tr("CellShockingPink "), QColor("#FB7EFD") ); // 251,126,253 chartCA->addSeriesWithNumber( CellSilver ,tr("CellSilver "), QColor("#CDC5C2") ); // 205,197,194 chartCA->addSeriesWithNumber( CellSkyBlue ,tr("CellSkyBlue "), QColor("#80DAEB") ); // 128,218,235 chartCA->addSeriesWithNumber( CellSpringGreen ,tr("CellSpringGreen "), QColor("#ECEABE") ); // 236,234,190 chartCA->addSeriesWithNumber( CellSunglow ,tr("CellSunglow "), QColor("#FFCF48") ); // 255,207,72 chartCA->addSeriesWithNumber( CellSunsetOrange ,tr("CellSunsetOrange "), QColor("#FD5E53") ); // 253,94,83 chartCA->addSeriesWithNumber( CellTan ,tr("CellTan "), QColor("#FAA76C") ); // 250,167,108 chartCA->addSeriesWithNumber( CellTickleMePink ,tr("CellTickleMePink "), QColor("#FC89AC") ); // 252,137,172 chartCA->addSeriesWithNumber( CellTimberwolf ,tr("CellTimberwolf "), QColor("#DBD7D2") ); // 219,215,210 chartCA->addSeriesWithNumber( CellTropicalRainForest ,tr("CellTropicalRainForest "), QColor("#17806D") ); // 23,128,109 chartCA->addSeriesWithNumber( CellTumbleweed ,tr("CellTumbleweed "), QColor("#DEAA88") ); // 222,170,136 chartCA->addSeriesWithNumber( CellTurquoiseBlue ,tr("CellTurquoiseBlue "), QColor("#77DDE7") ); // 119,221,231 chartCA->addSeriesWithNumber( CellUnmellowYellow ,tr("CellUnmellowYellow "), QColor("#FDFC74") ); // 253,252,116 chartCA->addSeriesWithNumber( CellVioletPurple ,tr("CellVioletPurple "), QColor("#926EAE") ); // 146,110,174 chartCA->addSeriesWithNumber( CellVioletRed ,tr("CellVioletRed "), QColor("#F75394") ); // 247,83,148 chartCA->addSeriesWithNumber( CellVividTangerine ,tr("CellVividTangerine "), QColor("#FFA089") ); // 255,160,137 chartCA->addSeriesWithNumber( CellVividViolet ,tr("CellVividViolet "), QColor("#8F509D") ); // 143,80,157 chartCA->addSeriesWithNumber( CellWhite ,tr("CellWhite "), QColor("#EDEDED") ); // 237,237,237 chartCA->addSeriesWithNumber( CellWildBlueYonder ,tr("CellWildBlueYonder "), QColor("#A2ADD0") ); // 162,173,208 chartCA->addSeriesWithNumber( CellWildStrawberry ,tr("CellWildStrawberry "), QColor("#F664AF") ); // 255,67,164 chartCA->addSeriesWithNumber( CellWildWatermelon ,tr("CellWildWatermelon "), QColor("#FC6C85") ); // 252,108,133 chartCA->addSeriesWithNumber( CellWisteria ,tr("CellWisteria "), QColor("#CDA4DE") ); // 205,164,222 chartCA->addSeriesWithNumber( CellYellow ,tr("CellYellow "), QColor("#FCE883") ); // 252,232,131 chartCA->addSeriesWithNumber( CellYellowGreen ,tr("CellYellowGreen "), QColor("#C5E384") ); // 197,227,132 chartCA->addSeriesWithNumber( CellYellowOrange ,tr("CellYellowOrange "), QColor("#FB6530") ); // 255,182,83 } void VisualizationPage::setIsPageActivated(bool isActivated) { mIsThisPageActivated = isActivated; } bool VisualizationPage::isPageActivated() { return mIsThisPageActivated; } void VisualizationPage::onVisualizationPageSelected() { /* QTimer* timerV = new QTimer(this); connect(timerV, &QTimer::timeout, this, &VisualizationPage::onSetValV); timerV->setInterval(1000); timerV->start(); QTimer* timerA = new QTimer(this); connect(timerA, &QTimer::timeout, this, &VisualizationPage::onSetValA); timerA->setInterval(1000); timerA->start(); */ QTimer* timerT = new QTimer(this); connect(timerT, &QTimer::timeout, this, &VisualizationPage::onSetValT); timerT->setInterval(1000); timerT->start(); //*/ } BMSInterface *VisualizationPage::bms() const { return mDieBieMS; } void VisualizationPage::setDieBieMS(BMSInterface *dieBieMS) { mDieBieMS = dieBieMS; /*if (mDieBieMS) { connect(mDieBieMS->commands(), SIGNAL(valuesReceived(BMS_VALUES)),this, SLOT(valuesReceived(BMS_VALUES))); connect(mDieBieMS->commands(), SIGNAL(cellsReceived(int,QVector)),this, SLOT(cellsReceived(int,QVector))); } */ if (mDieBieMS) { connect(mDieBieMS->commands(), &Commands::valuesReceived, this, &VisualizationPage::valuesReceived); connect(mDieBieMS->commands(), &Commands::cellsReceived, this, &VisualizationPage::cellsReceived); connect(mDieBieMS->commands(), &Commands::auxReceived, this, &VisualizationPage::auxReceived); //(int,QVector))); connect(mDieBieMS->commands(), &Commands::expTempReceived, this, &VisualizationPage::expTempReceived); //(int,QVector))); //connect(mDieBieMS->commands(), SIGNAL(valuesReceived(BMS_VALUES)),this, SLOT(valuesReceived(BMS_VALUES))); //connect(mDieBieMS->commands(), SIGNAL(cellsReceived(int,QVector)),this, SLOT(cellsReceived(int,QVector))); } } void VisualizationPage::onSetValV() { int val = (QRandomGenerator::global()->generate() % 100); // + //10; /* if (val > 0) { //ui->lbV->setText(QString::number(val)); chartV->append(val); chartV->update(); ui->chartViewVoltage->repaint(); } */ mHCLoadVoltage.append(val); } void VisualizationPage::onSetValA() { int val = /*(QRandomGenerator::global()->generate() % 10) +*/ 10; if (val > 0) { //ui->lbA->setText(QString::number(val)); chartA->append(val); chartA->update(); ui->chartViewAmperage->repaint(); } } void VisualizationPage::onSetValT() { //int val = (QRandomGenerator::global()->generate(-10,10) % T_MODUS); //int val = QRandomGenerator::global()->bounded(-10, 50); int valMax = QRandomGenerator::global()->bounded(-10, 50) + 0; int valMid = QRandomGenerator::global()->bounded(-10, 50) + 0; int valMin = QRandomGenerator::global()->bounded(-10, 50) + 0; //if (val > 0) { //ui->lbT->setText(QString::number(val)); //chartT->append(val); // increas X chartT->appendNextX(); // then set all new Ys /* chartT->appendYToSeries(TemperatureMax, valMax); chartT->appendYToSeries(TemperatureMid, valMid); chartT->appendYToSeries(TemperatureMin, valMin); */ chartT->appendYToSeries(TemperatureBatMax, valMax); chartT->appendYToSeries(TemperatureBatMid, valMid); chartT->appendYToSeries(TemperatureBatMin, valMin); ui->lbTMaxLegendVal->setText(QString("%1").arg(valMax)); ui->lbTMidLegendVal->setText(QString("%1").arg(valMid)); ui->lbTMinLegendVal->setText(QString("%1").arg(valMin)); //chartT->refreshSeries(TemperatureMax); //chartT->refreshSeries(TemperatureMid); //chartT->refreshSeries(TemperatureMin); chartT->update(); ui->chartViewTemperature->repaint(); //} ///ui->lbTCurTemp->setText(QString::number(val)); ui->lbTCurTemp->setText(""); } void VisualizationPage::onSetSecsV(int secs) { if(secs <= 0) ui->lbVTime->setText(QString("")); else if(secs < 60) ui->lbVTime->setText(QString("%1 с").arg(secs)); else if(secs % 60 == 0) ui->lbVTime->setText(QString("%1 мин").arg(secs/60)); else if(secs > 60) ui->lbVTime->setText(QString("%1 мин %2 с").arg(secs/60).arg(secs%60)); } void VisualizationPage::onSetSecsA(int secs) { if(secs <= 0) ui->lbATime->setText(QString("")); else if(secs < 60) ui->lbATime->setText(QString("%1 с").arg(secs)); else if(secs % 60 == 0) ui->lbATime->setText(QString("%1 мин").arg(secs/60)); else if(secs > 60) ui->lbATime->setText(QString("%1 мин %2 с").arg(secs/60).arg(secs%60)); } void VisualizationPage::onSetSecsT(int secs) { if(secs <= 0) ui->lbTTime->setText(QString("")); else if(secs < 60) ui->lbTTime->setText(QString("%1 с").arg(secs)); else if(secs % 60 == 0) ui->lbTTime->setText(QString("%1 мин").arg(secs/60)); else if(secs > 60) ui->lbTTime->setText(QString("%1 мин %2 с").arg(secs/60).arg(secs%60)); } void VisualizationPage::onSetSecsC(int secs) { if(secs <= 0) ui->lbCTime->setText(QString("")); else if(secs < 60) ui->lbCTime->setText(QString("%1 с").arg(secs)); else if(secs % 60 == 0) ui->lbCTime->setText(QString("%1 мин").arg(secs/60)); else if(secs > 60) ui->lbCTime->setText(QString("%1 мин %2 с").arg(secs/60).arg(secs%60)); } /*void VisualizationPage::onSetSecsCA(int secs) { if(secs <= 0) ui->lbCATime->setText(QString("")); else if(secs < 60) ui->lbCATime->setText(QString("%1 с").arg(secs)); else if(secs % 60 == 0) ui->lbCATime->setText(QString("%1 мин").arg(secs/60)); else if(secs > 60) ui->lbCATime->setText(QString("%1 мин %2 с").arg(secs/60).arg(secs%60)); } */ void VisualizationPage::onTabBarButtonClicked() { for(auto btn: m_btnGroup->buttons()) { if(!btn->isChecked()) continue; if ( btn->objectName() == ui->pbVisualizationMenuBarVoltage ->objectName() ) m_currentPageIndex = Voltage ; else if( btn->objectName() == ui->pbVisualizationMenuBarAmperage ->objectName() ) m_currentPageIndex = Apmerage ; //else if( btn->objectName() == ui->pbVisualizationMenuBarTemperature->objectName() ) m_currentPageIndex = Temperature ; else if( btn->objectName() == ui->pbVisualizationMenuBarTemperatureBat->objectName() ) m_currentPageIndex = TemperatureBat ; else if( btn->objectName() == ui->pbVisualizationMenuBarTemperatureBms->objectName() ) m_currentPageIndex = TemperatureBms ; else if( btn->objectName() == ui->pbVisualizationMenuBarCells ->objectName() ) m_currentPageIndex = Cells ; else if( btn->objectName() == ui->pbVisualizationMenuBarCellsAll ->objectName() ) m_currentPageIndex = CellsAll ; ui->tabWidgetVisualizationContent->setCurrentIndex(m_currentPageIndex); } } void VisualizationPage::initForPlot() { ui->rtText->setVisible(false); mTimer = new QTimer(this); mTimer->start(20); mSecondCounter = 0.0; mLastUpdateTime = 0; mUpdateValPlot = false; /* ui->ivLCGraph->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); ui->ivHCGraph->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); ui->cellGraph->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); */ ui->tempGraph->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); // LC IVGraph int graphIndex = 0; /* ui->ivLCGraph->addGraph(); ui->ivLCGraph->graph(graphIndex)->setPen(QPen(Qt::red)); ui->ivLCGraph->graph(graphIndex)->setName("Pack"); graphIndex++; ui->ivLCGraph->addGraph(); ui->ivLCGraph->graph(graphIndex)->setPen(QPen(Qt::darkGreen)); ui->ivLCGraph->graph(graphIndex)->setName("LC Voltage"); graphIndex++; ui->ivLCGraph->addGraph(ui->ivLCGraph->xAxis, ui->ivLCGraph->yAxis2); ui->ivLCGraph->graph(graphIndex)->setPen(QPen(Qt::green)); ui->ivLCGraph->graph(graphIndex)->setName("LC Current"); graphIndex++; // HC IVGraph graphIndex = 0; ui->ivHCGraph->addGraph(); ui->ivHCGraph->graph(graphIndex)->setPen(QPen(Qt::blue)); ui->ivHCGraph->graph(graphIndex)->setName("HC Voltage"); graphIndex++; ui->ivHCGraph->addGraph(ui->ivHCGraph->xAxis, ui->ivHCGraph->yAxis2); ui->ivHCGraph->graph(graphIndex)->setPen(QPen(Qt::magenta)); ui->ivHCGraph->graph(graphIndex)->setName("HC Current"); graphIndex++; // Cell voltage graph graphIndex = 0; ui->cellGraph->addGraph(); ui->cellGraph->graph(graphIndex)->setPen(QPen(Qt::green)); ui->cellGraph->graph(graphIndex)->setName("Cell high"); graphIndex++; ui->cellGraph->addGraph(); ui->cellGraph->graph(graphIndex)->setPen(QPen(Qt::blue)); ui->cellGraph->graph(graphIndex)->setName("Cell average"); graphIndex++; ui->cellGraph->addGraph(); ui->cellGraph->graph(graphIndex)->setPen(QPen(Qt::red)); ui->cellGraph->graph(graphIndex)->setName("Cell low"); graphIndex++; // Temperature graph // LC IVGraph graphIndex = 0; */ ui->tempGraph->addGraph(); ui->tempGraph->graph(graphIndex)->setPen(QPen(Qt::red)); ui->tempGraph->graph(graphIndex)->setName("BMS High"); graphIndex++; ui->tempGraph->addGraph(); ui->tempGraph->graph(graphIndex)->setPen(QPen(Qt::green)); ui->tempGraph->graph(graphIndex)->setName("BMS Average"); graphIndex++; ui->tempGraph->addGraph(); ui->tempGraph->graph(graphIndex)->setPen(QPen(Qt::yellow)); ui->tempGraph->graph(graphIndex)->setName("BMS Low"); graphIndex++; ///ui->tempGraph->addGraph(); ///ui->tempGraph->graph(graphIndex)->setPen(QPen(Qt::green)); ///ui->tempGraph->graph(graphIndex)->setName("Battery high"); ///graphIndex++; ///ui->tempGraph->addGraph(); ///ui->tempGraph->graph(graphIndex)->setPen(QPen(Qt::darkGreen)); ///ui->tempGraph->graph(graphIndex)->setName("Battery Average"); ///graphIndex++; QFont legendFont = font(); legendFont.setPointSize(9); /* //LC Graph ui->ivLCGraph->legend->setVisible(true); ui->ivLCGraph->legend->setFont(legendFont); ui->ivLCGraph->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignRight|Qt::AlignBottom); ui->ivLCGraph->legend->setBrush(QBrush(QColor(255,255,255,230))); ui->ivLCGraph->xAxis->setLabel("Seconds (s)"); ui->ivLCGraph->yAxis->setLabel("Voltage (V)"); ui->ivLCGraph->yAxis2->setLabel("Current (A)"); ui->ivLCGraph->yAxis->setRange(0, 60); ui->ivLCGraph->yAxis2->setRange(-5, 5); ui->ivLCGraph->yAxis2->setVisible(true); //HC Graph ui->ivHCGraph->legend->setVisible(true); ui->ivHCGraph->legend->setFont(legendFont); ui->ivHCGraph->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignRight|Qt::AlignBottom); ui->ivHCGraph->legend->setBrush(QBrush(QColor(255,255,255,230))); ui->ivHCGraph->xAxis->setLabel("Seconds (s)"); ui->ivHCGraph->yAxis->setLabel("Voltage (V)"); ui->ivHCGraph->yAxis2->setLabel("Current (A)"); ui->ivHCGraph->yAxis->setRange(0, 60); ui->ivHCGraph->yAxis2->setRange(-5, 5); ui->ivHCGraph->yAxis2->setVisible(true); //Cell voltage Graph ui->cellGraph->legend->setVisible(true); ui->cellGraph->legend->setFont(legendFont); ui->cellGraph->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignRight|Qt::AlignBottom); ui->cellGraph->legend->setBrush(QBrush(QColor(255,255,255,230))); ui->cellGraph->xAxis->setLabel("Seconds (s)"); ui->cellGraph->yAxis->setLabel("Voltage (V)"); ui->cellGraph->yAxis->setRange(0, 4.2); */ //Temperature Graph ui->tempGraph->legend->setVisible(true); ui->tempGraph->legend->setFont(legendFont); ui->tempGraph->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignRight|Qt::AlignBottom); ui->tempGraph->legend->setBrush(QBrush(QColor(255,255,255,230))); ui->tempGraph->xAxis->setLabel("Seconds (s)"); ui->tempGraph->yAxis->setLabel("Temperature (\u00B0C)"); ui->tempGraph->yAxis->setRange(0, 70); /* // Cell bar graph group = new QCPBarsGroup(ui->cellBarGraph); barsNormal = new QCPBars(ui->cellBarGraph->xAxis, ui->cellBarGraph->yAxis); barsBalance = new QCPBars(ui->cellBarGraph->xAxis, ui->cellBarGraph->yAxis); barsNormal->setBrush(QColor(0, 255, 0, 50)); barsNormal->setPen(QColor(0, 211, 56)); barsNormal->setWidth(0.9); barsNormal->setBarsGroup(group); barsBalance->setBrush(QColor(0, 0, 255, 50)); barsBalance->setPen(QColor(0, 211, 56)); barsBalance->setWidth(0.9); barsBalance->setBarsGroup(group); barsBalance->moveAbove(barsNormal); ui->cellBarGraph->xAxis->setRange(0.5, 12); ui->cellBarGraph->yAxis->setRange(2.5, 4.15); ui->cellBarGraph->yAxis->setLabel("Voltage (V)"); ui->cellBarGraph->xAxis->setTickLabelRotation(85); ui->cellBarGraph->xAxis->setSubTicks(false); ui->cellBarGraph->xAxis->setTickLength(0, 5); */ connect(mTimer, &QTimer::timeout,this, &VisualizationPage::timerSlot); } void VisualizationPage::initForCharts() { ui->rtText->setVisible(false); mTimer = new QTimer(this); //mTimer->start(20); mTimer->start(1000); mSecondCounter = 0.0; mLastUpdateTime = 0; mUpdateValPlot = false; QFont legendFont = font(); legendFont.setPointSize(9); connect(mTimer, &QTimer::timeout,this, &VisualizationPage::timerSlot); } void VisualizationPage::timerSlot() { // // We will start revieve Data WHEN // SEE - void MainWindowNew::onTimerSlot() // one of those left-tab-bar buttons are selected (ui->pbMainMenuBarVisualization->isChecked() || ui->pbMainMenuBarVisualization->isChecked()) // if ( #if TURN_ON_DUMMY_DATA_FLOW_TO_GRAPHS true #else mUpdateValPlot && mIsThisPageActivated #endif ) { //COMM_GET_BMS_CELLS /* int dataSize = mPackVoltage.size(); QVector xAxis(dataSize); for (int i = 0;i < mSeconds.size();i++) { xAxis[i] = mSeconds[i]; } */ // Current and duty-plot ///int graphIndex = 0; ///ui->ivLCGraph->graph(graphIndex++)->setData(xAxis, mPackVoltage); ///ui->ivLCGraph->graph(graphIndex++)->setData(xAxis, mLCLoadVoltage); ///ui->ivLCGraph->graph(graphIndex++)->setData(xAxis, mLCLoadCurrent); ///graphIndex = 0; ///ui->ivHCGraph->graph(graphIndex++)->setData(xAxis, mHCLoadVoltage); ///ui->ivHCGraph->graph(graphIndex++)->setData(xAxis, mHCLoadCurrent); ///graphIndex = 0; ///ui->cellGraph->graph(graphIndex++)->setData(xAxis, mCellVHigh); ///ui->cellGraph->graph(graphIndex++)->setData(xAxis, mCellVAverage); ///ui->cellGraph->graph(graphIndex++)->setData(xAxis, mCellVLow); ///graphIndex = 0; ///mTempBMSLow.fill(0,1); ///ui->tempGraph->graph(graphIndex++)->setData(xAxis, mTempBMSHigh); ///ui->tempGraph->graph(graphIndex++)->setData(xAxis, mTempBMSAverage); ///ui->tempGraph->graph(graphIndex++)->setData(xAxis, mTempBMSLow); // V double valV = mPackVoltage.empty() ? 0 : mPackVoltage.last(); //double valVMax = mHCLoadVoltage.empty() ? 0 : mHCLoadVoltage.last(); //double valVMid = mPackVoltage.empty() ? 0 : mPackVoltage.last(); //double valVMin = mLCLoadVoltage.empty() ? 0 : mLCLoadVoltage.last(); // increas X chartV->appendNextX(); // then set all new Ys chartV->appendYToSeries(VoltageMax, valV); //chartV->appendYToSeries(VoltageMax, valVMax); //chartV->appendYToSeries(VoltageMid, valVMid); //chartV->appendYToSeries(VoltageMin, valVMin); ui->lbVMaxLegendVal->setText(QString::number(valV,'f',2)); //ui->lbVMaxLegendVal->setText(QString::number(valVMax,'f',2)); //ui->lbVMidLegendVal->setText(QString::number(valVMid,'f',2)); //ui->lbVMinLegendVal->setText(QString::number(valVMin,'f',2)); chartV->update(); ui->chartViewVoltage->repaint(); // A //mMCLoadCurrent_.fill(0, 1); double valA = mPackCurrent.empty() ? 0 : mPackCurrent.last(); //double valAMax = mHCLoadCurrent.empty() ? 0 : mHCLoadCurrent.last(); //double valAMid = mMCLoadCurrent_.empty() ? 0 : mMCLoadCurrent_.last(); //double valAMin = mLCLoadCurrent.empty() ? 0 : mLCLoadCurrent.last(); // increas X chartA->appendNextX(); // then set all new Ys chartA->appendYToSeries(AmperageMax, valA); //chartA->appendYToSeries(AmperageMax, valAMax); //chartA->appendYToSeries(AmperageMid, valAMid); //chartA->appendYToSeries(AmperageMin, valAMin); ui->lbAMaxLegendVal->setText(QString::number(valA,'f',2)); //ui->lbAMaxLegendVal->setText(QString::number(valAMax,'f',2)); //ui->lbAMidLegendVal->setText(QString::number(valAMid,'f',2)); //ui->lbAMinLegendVal->setText(QString::number(valAMin,'f',2)); chartA->update(); ui->chartViewAmperage->repaint(); // T Bat //mTempBattLow_.fill(0, 1); double valTMax = mTempBattHigh.empty() ? 0 : mTempBattHigh.last(); double valTMid = mTempBattAverage.empty() ? 0 : mTempBattAverage.last(); double valTMin = mTempBattLow.empty() ? 0 : mTempBattLow.last(); // increas X chartT->appendNextX(); // then set all new Ys /* chartT->appendYToSeries(TemperatureMax, valTMax); chartT->appendYToSeries(TemperatureMid, valTMid); chartT->appendYToSeries(TemperatureMin, valTMin); */ chartT->appendYToSeries(TemperatureBatMax, valTMax); chartT->appendYToSeries(TemperatureBatMid, valTMid); chartT->appendYToSeries(TemperatureBatMin, valTMin); ui->lbTMaxLegendVal->setText(QString::number(valTMax,'f',2)); ui->lbTMidLegendVal->setText(QString::number(valTMid,'f',2)); ui->lbTMinLegendVal->setText(QString::number(valTMin,'f',2)); chartT->update(); ui->chartViewTemperature->repaint(); // T Bms //mTempBMSLow_.fill(0, 1); double valTBMax = mTempBMSHigh.empty() ? 0 : mTempBMSHigh.last(); double valTBMid = mTempBMSAverage.empty() ? 0 : mTempBMSAverage.last(); double valTBMin = mTempBMSLow.empty() ? 0 : mTempBMSLow.last(); // increas X chartTB->appendNextX(); // then set all new Ys /* chartT->appendYToSeries(TemperatureMax, valTMax); chartT->appendYToSeries(TemperatureMid, valTMid); chartT->appendYToSeries(TemperatureMin, valTMin); */ chartTB->appendYToSeries(TemperatureBmsMax, valTBMax); chartTB->appendYToSeries(TemperatureBmsMid, valTBMid); chartTB->appendYToSeries(TemperatureBmsMin, valTBMin); ui->lbTMaxLegendValBms->setText(QString::number(valTBMax,'f',2)); ui->lbTMidLegendValBms->setText(QString::number(valTBMid,'f',2)); ui->lbTMinLegendValBms->setText(QString::number(valTBMin,'f',2)); chartTB->update(); ui->chartViewTemperatureBms->repaint(); // C double valCMax = mCellVHigh.empty() ? 0 : mCellVHigh.last(); double valCMid = mCellVAverage.empty() ? 0 : mCellVAverage.last(); double valCMin = mCellVLow.empty() ? 0 : mCellVLow.last(); // increas X chartC->appendNextX(); // then set all new Ys chartC->appendYToSeries(CellsMax, valCMax); chartC->appendYToSeries(CellsMid, valCMid); chartC->appendYToSeries(CellsMin, valCMin); ui->lbCMaxLegendVal->setText(QString::number(valCMax,'f',2)); ui->lbCMidLegendVal->setText(QString::number(valCMid,'f',2)); ui->lbCMinLegendVal->setText(QString::number(valCMin,'f',2)); chartC->update(); ui->chartViewCells->repaint(); // Cells // mCellsVals; //double valCMax = mCellVHigh.empty() ? 0 : mCellVHigh.last(); //double valCMid = mCellVAverage.empty() ? 0 : mCellVAverage.last(); //double valCMin = mCellVLow.empty() ? 0 : mCellVLow.last(); // increas X chartCA->appendNextX(); // then set all new Ys try { for(int i = 0; i < mCellsVals.size(); ++i) { chartCA->appendYToSeries((ChartsForCellsIndex)(i), mCellsVals.at(i)); } } catch (...) { // mCellsVals.at out of bound EXCEPTION handling } //ui->lbCMaxLegendVal->setText(QString::number(valCMax,'f',2)); //ui->lbCMidLegendVal->setText(QString::number(valCMid,'f',2)); //ui->lbCMinLegendVal->setText(QString::number(valCMin,'f',2)); chartCA->update(); ui->chartViewCellsAll->repaint(); /* ui->tempGraph->graph(graphIndex++)->setData(xAxis, mTempBattHigh); ui->tempGraph->graph(graphIndex++)->setData(xAxis, mTempBattAverage); ui->tempGraph->graph(graphIndex++)->setData(xAxis, mTempBattLow); ///if (ui->autoscaleButton->isChecked()) { ///ui->ivLCGraph->rescaleAxes(); ///ui->ivHCGraph->rescaleAxes(); ///ui->cellGraph->rescaleAxes(); ui->tempGraph->rescaleAxes(); } ///ui->ivLCGraph->replot(); ///ui->ivHCGraph->replot(); ///ui->cellGraph->replot(); ui->tempGraph->replot(); ///ui->cellBarGraph->replot(); mUpdateValPlot = false; */ } } /* // OLD CODE void VisualizationPage::timerSlot() { if (mUpdateValPlot) { int dataSize = mPackVoltage.size(); QVector xAxis(dataSize); for (int i = 0;i < mSeconds.size();i++) { xAxis[i] = mSeconds[i]; } // Current and duty-plot int graphIndex = 0; ///ui->ivLCGraph->graph(graphIndex++)->setData(xAxis, mPackVoltage); ///ui->ivLCGraph->graph(graphIndex++)->setData(xAxis, mLCLoadVoltage); ///ui->ivLCGraph->graph(graphIndex++)->setData(xAxis, mLCLoadCurrent); graphIndex = 0; ///ui->ivHCGraph->graph(graphIndex++)->setData(xAxis, mHCLoadVoltage); ///ui->ivHCGraph->graph(graphIndex++)->setData(xAxis, mHCLoadCurrent); graphIndex = 0; ///ui->cellGraph->graph(graphIndex++)->setData(xAxis, mCellVHigh); ///ui->cellGraph->graph(graphIndex++)->setData(xAxis, mCellVAverage); ///ui->cellGraph->graph(graphIndex++)->setData(xAxis, mCellVLow); graphIndex = 0; mTempBMSLow.fill(0,1); ui->tempGraph->graph(graphIndex++)->setData(xAxis, mTempBMSHigh); ui->tempGraph->graph(graphIndex++)->setData(xAxis, mTempBMSAverage); ui->tempGraph->graph(graphIndex++)->setData(xAxis, mTempBMSLow); //ui->tempGraph->graph(graphIndex++)->setData(xAxis, mTempBattHigh); //ui->tempGraph->graph(graphIndex++)->setData(xAxis, mTempBattAverage); ///if (ui->autoscaleButton->isChecked()) { ///ui->ivLCGraph->rescaleAxes(); ///ui->ivHCGraph->rescaleAxes(); ///ui->cellGraph->rescaleAxes(); ui->tempGraph->rescaleAxes(); } ///ui->ivLCGraph->replot(); ///ui->ivHCGraph->replot(); ///ui->cellGraph->replot(); ui->tempGraph->replot(); ///ui->cellBarGraph->replot(); mUpdateValPlot = false; } } */ void VisualizationPage::valuesReceived(BMS_VALUES values) { ui->rtText->setValues(values); const int maxS = 500; appendDoubleAndTrunc(&mPackVoltage, values.packVoltage, maxS); appendDoubleAndTrunc(&mPackCurrent, values.packCurrent, maxS); appendDoubleAndTrunc(&mLCLoadVoltage, values.loadLCVoltage, maxS); appendDoubleAndTrunc(&mLCLoadCurrent, values.loadLCCurrent, maxS); appendDoubleAndTrunc(&mHCLoadVoltage, values.loadHCVoltage, maxS); appendDoubleAndTrunc(&mHCLoadCurrent, values.loadHCCurrent, maxS); appendDoubleAndTrunc(&mChargerVoltage, values.chargerVoltage, maxS); appendDoubleAndTrunc(&mAuxVoltage, values.auxVoltage, maxS); appendDoubleAndTrunc(&mAuxCurrent, values.auxCurrent, maxS); appendDoubleAndTrunc(&mCellVHigh, values.cVHigh, maxS); appendDoubleAndTrunc(&mCellVAverage, values.cVAverage, maxS); appendDoubleAndTrunc(&mCellVLow, values.cVLow, maxS); appendDoubleAndTrunc(&mTempBMSHigh, values.tempBMSHigh, maxS); appendDoubleAndTrunc(&mTempBMSAverage, values.tempBMSAverage, maxS); appendDoubleAndTrunc(&mTempBMSLow, values.tempBMSLow, maxS); appendDoubleAndTrunc(&mTempBattHigh, values.tempBattHigh, maxS); appendDoubleAndTrunc(&mTempBattAverage, values.tempBattAverage, maxS); appendDoubleAndTrunc(&mTempBattLow, values.tempBattLow, maxS); appendDoubleAndTrunc(&mHumidity, values.humidity, maxS); qint64 tNow = QDateTime::currentMSecsSinceEpoch(); double elapsed = (double)(tNow - mLastUpdateTime) / 1000.0; if (elapsed > 1.0) { elapsed = 1.0; } mSecondCounter += elapsed; appendDoubleAndTrunc(&mSeconds, mSecondCounter, maxS); mLastUpdateTime = tNow; mUpdateValPlot = true; /* ui->rtText->setValues(values); const int maxS = 500; appendDoubleAndTrunc(&mPackVoltage, values.packVoltage, maxS); appendDoubleAndTrunc(&mLCLoadVoltage, values.loadLCVoltage, maxS); appendDoubleAndTrunc(&mLCLoadCurrent, values.loadLCCurrent, maxS); appendDoubleAndTrunc(&mHCLoadVoltage, values.loadHCVoltage, maxS); appendDoubleAndTrunc(&mHCLoadCurrent, values.loadHCCurrent, maxS); appendDoubleAndTrunc(&mAuxVoltage, values.auxVoltage, maxS); appendDoubleAndTrunc(&mAuxCurrent, values.auxCurrent, maxS); appendDoubleAndTrunc(&mCellVHigh, values.cVHigh, maxS); appendDoubleAndTrunc(&mCellVAverage, values.cVAverage, maxS); appendDoubleAndTrunc(&mCellVLow, values.cVLow, maxS); appendDoubleAndTrunc(&mTempBMSHigh, values.tempBMSHigh, maxS); appendDoubleAndTrunc(&mTempBMSAverage, values.tempBMSAverage, maxS); //appendDoubleAndTrunc(&mTempBMSLow_, values.tempBMSLow_, maxS); appendDoubleAndTrunc(&mTempBattHigh, values.tempBattHigh, maxS); appendDoubleAndTrunc(&mTempBattAverage, values.tempBattAverage, maxS); //appendDoubleAndTrunc(&mTempBattLow_, values.tempBattLow_, maxS); qint64 tNow = QDateTime::currentMSecsSinceEpoch(); double elapsed = (double)(tNow - mLastUpdateTime) / 1000.0; if (elapsed > 1.0) { elapsed = 1.0; } mSecondCounter += elapsed; appendDoubleAndTrunc(&mSeconds, mSecondCounter, maxS); mLastUpdateTime = tNow; mUpdateValPlot = true; */ } void VisualizationPage::cellsReceived(int cellCount, QVector cellVoltageArray) { initListWidgetOfCells(cellCount); mCellsVals = cellVoltageArray; QVector dataxNew; dataxNew.clear(); QVector datayNormal; datayNormal.clear(); QVector datayBalance; datayBalance.clear(); QVector labels; int indexPointer; double cellHardUnder = mDieBieMS->bmsConfig()->getParamDouble("cellHardUnderVoltage"); double cellHardOver = mDieBieMS->bmsConfig()->getParamDouble("cellHardOverVoltage"); for(indexPointer = 0; indexPointer < cellCount; indexPointer++){ dataxNew.append(indexPointer + 1); if(cellVoltageArray[indexPointer] < 0.0){ datayNormal.append(0.0); datayBalance.append(fabs(cellVoltageArray[indexPointer])); }else{ datayNormal.append(fabs(cellVoltageArray[indexPointer])); datayBalance.append(0.0); } QString voltageString = QStringLiteral("%1V (C").arg(fabs(cellVoltageArray[indexPointer]), 0, 'f',3); labels.append(voltageString + QString::number(indexPointer) + ")"); } int z =0; //QSharedPointer textTicker(new QCPAxisTickerText); //textTicker->addTicks(dataxNew, labels); //ui->cellBarGraph->xAxis->setTicker(textTicker); //ui->cellBarGraph->xAxis->setRange(0.5, indexPointer + 0.5); //ui->cellBarGraph->yAxis->setRange(cellHardUnder, cellHardOver); //barsNormal->setData(dataxNew, datayNormal); //barsBalance->setData(dataxNew, datayBalance); } /* void VisualizationPage::timerSlot() { if (mUpdateValPlot) { int dataSize = mPackVoltage.size(); QVector xAxis(dataSize); for (int i = 0;i < mSeconds.size();i++) { xAxis[i] = mSeconds[i]; } // Current and duty-plot int graphIndex = 0; ui->ivLCGraph->graph(graphIndex++)->setData(xAxis, mPackVoltage); ui->ivLCGraph->graph(graphIndex++)->setData(xAxis, mLCLoadVoltage); ui->ivLCGraph->graph(graphIndex++)->setData(xAxis, mLCLoadCurrent); #if 0 graphIndex = 0; ui->cellGraph->graph(graphIndex++)->setData(xAxis, mCellVHigh); ui->cellGraph->graph(graphIndex++)->setData(xAxis, mCellVAverage); ui->cellGraph->graph(graphIndex++)->setData(xAxis, mCellVLow); #endif graphIndex = 0; ui->cellLimitsGraph->graph(graphIndex++)->setData(xAxis, mCellVHigh); ui->cellLimitsGraph->graph(graphIndex++)->setData(xAxis, mCellVAverage); ui->cellLimitsGraph->graph(graphIndex++)->setData(xAxis, mCellVLow); graphIndex = 0; ui->tempGraph->graph(graphIndex++)->setData(xAxis, mTempBMSHigh); ui->tempGraph->graph(graphIndex++)->setData(xAxis, mTempBMSAverage); ui->tempGraph->graph(graphIndex++)->setData(xAxis, mTempBMSLow); ui->tempGraph->graph(graphIndex++)->setData(xAxis, mTempBattHigh); ui->tempGraph->graph(graphIndex++)->setData(xAxis, mTempBattAverage); ui->tempGraph->graph(graphIndex++)->setData(xAxis, mTempBattLow); if (ui->autoscaleButton->isChecked()) { ui->ivLCGraph->rescaleAxes(); #if 0 // do not autoscale since we're displaying cell voltages ui->cellGraph->rescaleAxes(); #endif // only scale X axis ui->cellGraph->xAxis->rescale(); ui->cellLimitsGraph->xAxis->rescale(); ui->tempGraph->rescaleAxes(); } ui->ivLCGraph->replot(); ui->cellGraph->replot(); ui->cellLimitsGraph->replot(); ui->tempGraph->replot(); ui->cellBarGraph->replot(); ui->auxBarGraph->replot(); ui->expBarGraph->replot(); mUpdateValPlot = false; } } void VisualizationPage::valuesReceived(BMS_VALUES values) { ui->rtText->setValues(values); const int maxS = 500; appendDoubleAndTrunc(&mPackVoltage, values.packVoltage, maxS); appendDoubleAndTrunc(&mLCLoadVoltage, values.loadLCVoltage, maxS); appendDoubleAndTrunc(&mLCLoadCurrent, values.loadLCCurrent, maxS); appendDoubleAndTrunc(&mHCLoadVoltage, values.loadHCVoltage, maxS); appendDoubleAndTrunc(&mHCLoadCurrent, values.loadHCCurrent, maxS); appendDoubleAndTrunc(&mChargerVoltage, values.chargerVoltage, maxS); appendDoubleAndTrunc(&mAuxVoltage, values.auxVoltage, maxS); appendDoubleAndTrunc(&mAuxCurrent, values.auxCurrent, maxS); appendDoubleAndTrunc(&mCellVHigh, values.cVHigh, maxS); appendDoubleAndTrunc(&mCellVAverage, values.cVAverage, maxS); appendDoubleAndTrunc(&mCellVLow, values.cVLow, maxS); appendDoubleAndTrunc(&mTempBMSHigh, values.tempBMSHigh, maxS); appendDoubleAndTrunc(&mTempBMSAverage, values.tempBMSAverage, maxS); appendDoubleAndTrunc(&mTempBMSLow, values.tempBMSLow, maxS); appendDoubleAndTrunc(&mTempBattHigh, values.tempBattHigh, maxS); appendDoubleAndTrunc(&mTempBattAverage, values.tempBattAverage, maxS); appendDoubleAndTrunc(&mTempBattLow, values.tempBattLow, maxS); appendDoubleAndTrunc(&mHumidity, values.humidity, maxS); qint64 tNow = QDateTime::currentMSecsSinceEpoch(); double elapsed = (double)(tNow - mLastUpdateTime) / 1000.0; if (elapsed > 1.0) { elapsed = 1.0; } mSecondCounter += elapsed; appendDoubleAndTrunc(&mSeconds, mSecondCounter, maxS); mLastUpdateTime = tNow; mUpdateValPlot = true; } void VisualizationPage::cellsReceived(int cellCount, QVector cellVoltageArray){ QVector dataxNew; dataxNew.clear(); QVector datayNormal; datayNormal.clear(); QVector datayBalance; datayBalance.clear(); QVector labels; int indexPointer; double cellHardUnder = mDieBieMS->bmsConfig()->getParamDouble("cellHardUnderVoltage"); double cellHardOver = mDieBieMS->bmsConfig()->getParamDouble("cellHardOverVoltage"); for(indexPointer = 0; indexPointer < cellCount; indexPointer++){ dataxNew.append(indexPointer + 1); if(cellVoltageArray[indexPointer] < 0.0){ datayNormal.append(0.0); datayBalance.append(fabs(cellVoltageArray[indexPointer])); }else{ datayNormal.append(fabs(cellVoltageArray[indexPointer])); datayBalance.append(0.0); } QString voltageString = QStringLiteral("%1V (C").arg(fabs(cellVoltageArray[indexPointer]), 0, 'f',3); labels.append(voltageString + QString::number(indexPointer+1) + ")"); } QSharedPointer textTicker(new QCPAxisTickerText); textTicker->addTicks(dataxNew, labels); int idx = 0; double plotx = mSeconds.empty() ? 0 : mSeconds.last(); for(auto v : cellVoltageArray) { // if ( auto *pg = ui->cellGraph->graph(idx) ) // { // auto ploty = fabs(v); // pg->addData(plotx, ploty); // } // ++idx; } // ui->cellBarGraph->xAxis->setTicker(textTicker); // ui->cellBarGraph->xAxis->setRange(0.5, indexPointer + 0.5); // ui->cellBarGraph->yAxis->setRange(cellHardUnder, cellHardOver); // barsNormal->setData(dataxNew, datayNormal); // barsBalance->setData(dataxNew, datayBalance); } */ void VisualizationPage::auxReceived(int auxCount, QVector auxVoltageArray){ QVector dataxNew; dataxNew.clear(); QVector datayNormal; datayNormal.clear(); QVector labels; int indexPointer; for(indexPointer = 0; indexPointer < auxCount; indexPointer++){ dataxNew.append(indexPointer + 1); if(auxVoltageArray[indexPointer] < -50.0){ datayNormal.append(0.0); }else{ datayNormal.append(auxVoltageArray[indexPointer]); } QString voltageString = QStringLiteral("%1°C (TH").arg(auxVoltageArray[indexPointer], 0, 'f',3); labels.append(voltageString + QString::number(indexPointer+1) + ")"); } QSharedPointer textTicker(new QCPAxisTickerText); textTicker->addTicks(dataxNew, labels); /*ui->auxBarGraph->xAxis->setTicker(textTicker); ui->auxBarGraph->xAxis->setRange(0.5, indexPointer + 0.5); ui->auxBarGraph->yAxis->setRange(-40, 75); barsTemperature->setData(dataxNew, datayNormal);*/ } void VisualizationPage::expTempReceived(int expTempCount, QVector expTempVoltageArray){ QVector dataxNew; dataxNew.clear(); QVector datayNormal; datayNormal.clear(); QVector labels; int indexPointer; for(indexPointer = 0; indexPointer < expTempCount; indexPointer++){ dataxNew.append(indexPointer + 1); if(expTempVoltageArray[indexPointer] < -50.0){ datayNormal.append(0.0); }else{ datayNormal.append(expTempVoltageArray[indexPointer]); } QString voltageString = QStringLiteral("%1°C (T").arg(expTempVoltageArray[indexPointer], 0, 'f',3); labels.append(voltageString + QString::number(indexPointer) + ")"); } QSharedPointer textTicker(new QCPAxisTickerText); textTicker->addTicks(dataxNew, labels); /*ui->expBarGraph->xAxis->setTicker(textTicker); ui->expBarGraph->xAxis->setRange(0.5, indexPointer + 0.5); ui->expBarGraph->yAxis->setRange(-40, 75); ExpBarsTemperature->setData(dataxNew, datayNormal);*/ } void VisualizationPage::appendDoubleAndTrunc(QVector *vec, double num, int maxSize) { vec->append(num); if(vec->size() > maxSize) { vec->remove(0, vec->size() - maxSize); } } void VisualizationPage::on_checkBox_stateChanged(int arg1) { if(ui->checkBox->isChecked()) { chartT->hideSeriesWithNumber(TemperatureBatMax); } else { chartT->showSeriesWithNumber(TemperatureBatMax); } }