diff --git a/SavvyCAN.pro b/SavvyCAN.pro index 4346f2e..f293ad7 100644 --- a/SavvyCAN.pro +++ b/SavvyCAN.pro @@ -58,7 +58,8 @@ SOURCES += main.cpp\ connections/canconnectionmodel.cpp \ connections/connectionwindow.cpp \ re/graphingwindow.cpp \ - re/newgraphdialog.cpp + re/newgraphdialog.cpp \ + bisectwindow.cpp HEADERS += mainwindow.h \ can_structs.h \ @@ -105,7 +106,9 @@ HEADERS += mainwindow.h \ connections/canconnectionmodel.h \ connections/connectionwindow.h \ re/graphingwindow.h \ - re/newgraphdialog.h + re/newgraphdialog.h \ + ui/bisectwindow.h \ + bisectwindow.h FORMS += ui/candatagrid.ui \ ui/connectionwindow.ui \ @@ -129,7 +132,8 @@ FORMS += ui/candatagrid.ui \ ui/rangestatewindow.ui \ ui/scriptingwindow.ui \ ui/snifferwindow.ui \ - ui/udsscanwindow.ui + ui/udsscanwindow.ui \ + ui/bisectwindow.ui DISTFILES += diff --git a/bisectwindow.cpp b/bisectwindow.cpp new file mode 100644 index 0000000..a404c14 --- /dev/null +++ b/bisectwindow.cpp @@ -0,0 +1,154 @@ +#include "bisectwindow.h" +#include "ui_bisectwindow.h" + +#include "mainwindow.h" +#include "framefileio.h" + +#include +#include + +BisectWindow::BisectWindow(const QVector *frames, QWidget *parent) : + QDialog(parent), + ui(new Ui::BisectWindow) +{ + ui->setupUi(this); + + modelFrames = frames; + + connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int))); + connect(ui->btnCalculate, &QAbstractButton::clicked, this, &BisectWindow::handleCalculateButton); + connect(ui->btnReplaceFrames, &QAbstractButton::clicked, this, &BisectWindow::handleReplaceButton); + connect(ui->btnSaveFrames, &QAbstractButton::clicked, this, &BisectWindow::handleSaveButton); + connect(ui->slideFrameNumber, &QSlider::sliderReleased, this, &BisectWindow::updateFrameNumText); + connect(ui->slidePercentage, &QSlider::sliderReleased, this, &BisectWindow::updatePercentText); + connect(ui->editFrameNumber, &QLineEdit::editingFinished, this, &BisectWindow::updateFrameNumSlider); + connect(ui->editPercentage, &QLineEdit::editingFinished, this, &BisectWindow::updatePercentSlider); +} + +BisectWindow::~BisectWindow() +{ + delete ui; +} + +void BisectWindow::showEvent(QShowEvent* event) +{ + QDialog::showEvent(event); + refreshIDList(); + refreshFrameNumbers(); + updateFrameNumText(); + updatePercentText(); +} + +void BisectWindow::refreshIDList() +{ + int id; + for (int i = 0; i < modelFrames->count(); i++) + { + id = modelFrames->at(i).ID; + if (!foundID.contains(id)) + { + foundID.append(id); + } + } + + std::sort(foundID.begin(), foundID.end()); + + foreach (int id, foundID) { + ui->cbIDLower->addItem(Utility::formatNumber(id)); + ui->cbIDUpper->addItem(Utility::formatNumber(id)); + } +} + +void BisectWindow::refreshFrameNumbers() +{ + ui->labelMainListNum->setText(QString::number(modelFrames->count())); + ui->labelSplitNum->setText(QString::number(splitFrames.count())); + ui->slideFrameNumber->setMaximum(modelFrames->count()); +} + +void BisectWindow::updatedFrames(int numFrames) +{ + if (numFrames == -1) //all frames deleted + { + refreshFrameNumbers(); + } + else if (numFrames == -2) //all new set of frames. Reset + { + refreshFrameNumbers(); + refreshIDList(); + } + else //just got some new frames. See if they are relevant. + { + + } +} + +void BisectWindow::handleCalculateButton() +{ + splitFrames.clear(); + bool saveLower = ui->rbLowerSection->isChecked(); + int targetFrameNum; + if (ui->rbFrameNumber->isChecked() || ui->rbPercentage->isChecked()) + { + if (ui->rbFrameNumber->isChecked()) targetFrameNum = ui->slideFrameNumber->value(); + else targetFrameNum = modelFrames->count() * ui->slidePercentage->value() / 10000; + if (saveLower) + { + for (int i = 0; i < targetFrameNum; i++) splitFrames.append(modelFrames->at(i)); + } + else + { + for (int i = targetFrameNum; i < modelFrames->count(); i++) splitFrames.append(modelFrames->at(i)); + } + } + else if (ui->rbIDRange->isChecked()) + { + int lowerID = Utility::ParseStringToNum2(ui->cbIDLower->currentText()); + int upperID = Utility::ParseStringToNum2(ui->cbIDUpper->currentText()); + for (int i = 0; i < modelFrames->count(); i++) + { + if (modelFrames->at(i).ID >= lowerID && modelFrames->at(i).ID <= upperID) splitFrames.append(modelFrames->at(i)); + } + } + refreshFrameNumbers(); +} + +void BisectWindow::handleReplaceButton() +{ + +} + +void BisectWindow::handleSaveButton() +{ + QMessageBox msg; + QString filename; + if (FrameFileIO::saveFrameFile(filename, &splitFrames)) + { + msg.setText(tr("Successfully saved file")); + } + else + { + msg.setText(tr("Error while attempting to save.")); + } + msg.exec(); +} + +void BisectWindow::updateFrameNumSlider() +{ + ui->slideFrameNumber->setValue(ui->editFrameNumber->text().toInt()); +} + +void BisectWindow::updatePercentSlider() +{ + ui->slidePercentage->setValue(ui->editPercentage->text().toFloat() * 100); +} + +void BisectWindow::updateFrameNumText() +{ + ui->editFrameNumber->setText(QString::number(ui->slideFrameNumber->value())); +} + +void BisectWindow::updatePercentText() +{ + ui->editPercentage->setText(QString::number(ui->slidePercentage->value() / 100.0f)); +} diff --git a/bisectwindow.h b/bisectwindow.h new file mode 100644 index 0000000..77f3ebc --- /dev/null +++ b/bisectwindow.h @@ -0,0 +1,46 @@ +#ifndef BISECTWINDOW_H +#define BISECTWINDOW_H + +#include +#include "can_structs.h" + +namespace Ui { +class BisectWindow; +} + +class BisectWindow : public QDialog +{ + Q_OBJECT + +public: + explicit BisectWindow(const QVector *frames, QWidget *parent = 0); + ~BisectWindow(); + void showEvent(QShowEvent*); + +signals: + void sendCANFrame(const CANFrame *, int); + void sendFrameBatch(const QList *); + +private slots: + void updatedFrames(int numFrames); + void handleSaveButton(); + void handleReplaceButton(); + void handleCalculateButton(); + void updateFrameNumSlider(); + void updatePercentSlider(); + void updateFrameNumText(); + void updatePercentText(); + +private: + Ui::BisectWindow *ui; + const QVector *modelFrames; + QVector splitFrames; + QList foundID; + + void refreshIDList(); + void refreshFrameNumbers(); +}; + +#endif // BISECTWINDOW_H + + diff --git a/mainwindow.cpp b/mainwindow.cpp index a407d5d..9498a0c 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -81,6 +81,7 @@ MainWindow::MainWindow(QWidget *parent) : motorctrlConfigWindow = NULL; isoWindow = NULL; snifferWindow = NULL; + bisectWindow = NULL; dbcHandler = new DBCHandler; bDirty = false; inhibitFilterUpdate = false; @@ -126,6 +127,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->actionISO_TP_Decoder, &QAction::triggered, this, &MainWindow::showISOInterpreterWindow); connect(ui->actionSniffer, &QAction::triggered, this, &MainWindow::showSnifferWindow); connect(ui->actionMotorControlConfig, &QAction::triggered, this, &MainWindow::showMCConfigWindow); + connect(ui->actionCapture_Bisector, &QAction::triggered, this, &MainWindow::showBisectWindow); connect(CANConManager::getInstance(), &CANConManager::framesReceived, model, &CANFrameModel::addFrames); @@ -274,6 +276,13 @@ MainWindow::~MainWindow() snifferWindow = NULL; } + if (bisectWindow) + { + bisectWindow->close(); + delete bisectWindow; + bisectWindow = NULL; + } + delete model; delete elapsedTime; delete dbcHandler; @@ -854,6 +863,14 @@ void MainWindow::showSnifferWindow() snifferWindow->show(); } +void MainWindow::showBisectWindow() +{ + if (!bisectWindow) + { + bisectWindow = new BisectWindow(model->getListReference()); + } + bisectWindow->show(); +} void MainWindow::showFrameSenderWindow() { diff --git a/mainwindow.h b/mainwindow.h index 5061563..97f4a07 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -11,6 +11,7 @@ #include "re/graphingwindow.h" #include "re/frameinfowindow.h" #include "frameplaybackwindow.h" +#include "bisectwindow.h" #include "re/flowviewwindow.h" #include "framesenderwindow.h" #include "re/filecomparatorwindow.h" @@ -71,6 +72,7 @@ private slots: void showUDSScanWindow(); void showISOInterpreterWindow(); void showSnifferWindow(); + void showBisectWindow(); void exitApp(); void handleSaveDecoded(); void connectionFailed(); @@ -143,6 +145,7 @@ private: ISOTP_InterpreterWindow *isoWindow; SnifferWindow* snifferWindow; MotorControllerConfigWindow *motorctrlConfigWindow; + BisectWindow* bisectWindow; //various private storage QLabel lbStatusConnected; diff --git a/ui/bisectwindow.ui b/ui/bisectwindow.ui new file mode 100644 index 0000000..439386b --- /dev/null +++ b/ui/bisectwindow.ui @@ -0,0 +1,223 @@ + + + BisectWindow + + + + 0 + 0 + 692 + 319 + + + + Bisector Window + + + + + + Splitting Strategy: + + + Qt::AlignCenter + + + + + + + + ID Range + + + + + + + + + + TO + + + Qt::AlignCenter + + + + + + + + + + + + + + Frame Number + + + true + + + + + + + Qt::Horizontal + + + + + + + + + + + + + + Percentage + + + + + + + 1 + + + 10000 + + + 10 + + + 100 + + + Qt::Horizontal + + + + + + + + + + + + + + + Save Which Side: + + + Qt::AlignCenter + + + + + + Lower Section + + + true + + + + + + + Upper Section + + + + + + + + + + + + + 12 + + + + Number of Frames in Main List: + + + + + + + + 14 + + + + 0 + + + + + + + + 12 + + + + Saved Frames after split: + + + + + + + + 14 + + + + 0 + + + + + + + + + + + Calculate Split + + + + + + + Save split frames to a new file + + + + + + + Replace main list with split frames + + + + + + + + + + diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index b5124e1..a0c47ee 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -215,6 +215,7 @@ + @@ -413,6 +414,11 @@ MotorControlConfig + + + Capture Bisector + +