From e6058ead34896ff5bae396231bd11c67839a968e Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Tue, 20 Sep 2022 16:23:18 -0500 Subject: [PATCH 01/10] Progress! Masked error caused by saving dbc while editor is open that causes msg IDs to go crazy by making editor modal, but that affects all other windows, so might be a better fix. Added new value type of VALUE_STRING, probably better named ENUMERATED_STRING, and it uses the table in the editor to define the enum. Fixed a bug in the signal viewer load when a signal is not matched (I found it by renaming a signal and then loading) --- dbc/dbc_classes.cpp | 15 +++++++++++++-- dbc/dbc_classes.h | 3 ++- dbc/dbchandler.cpp | 6 ++++++ dbc/dbcloadsavewindow.cpp | 1 + dbc/dbcsignaleditor.cpp | 9 ++++++++- signalviewerwindow.cpp | 7 ++++--- 6 files changed, 34 insertions(+), 7 deletions(-) diff --git a/dbc/dbc_classes.cpp b/dbc/dbc_classes.cpp index 5467b4f..2a43815 100644 --- a/dbc/dbc_classes.cpp +++ b/dbc/dbc_classes.cpp @@ -137,6 +137,17 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString, bool o cachedValue = outString; return true; } + else if(valType == VALUE_STRING) + { + result = Utility::processIntegerSignal(frame.payload(), startBit, signalSize, intelByteOrder, isSigned); + + if(!getValueString(result, outString)) + { + outString = "Signal string value is undefined"; + } + + return true; + } if (valType == SIGNED_INT) isSigned = true; if (valType == SIGNED_INT || valType == UNSIGNED_INT) @@ -229,7 +240,7 @@ bool DBC_SIGNAL::processAsInt(const CANFrame &frame, int32_t &outValue) int32_t result = 0; bool isSigned = false; - if (valType == STRING || valType == SP_FLOAT || valType == DP_FLOAT) + if (valType == STRING || valType == VALUE_STRING || valType == SP_FLOAT || valType == DP_FLOAT) { return false; } @@ -262,7 +273,7 @@ bool DBC_SIGNAL::processAsDouble(const CANFrame &frame, double &outValue) bool isSigned = false; double endResult; - if (valType == STRING) + if (valType == STRING || valType == VALUE_STRING) { return false; } diff --git a/dbc/dbc_classes.h b/dbc/dbc_classes.h index fd085c2..b093a5d 100644 --- a/dbc/dbc_classes.h +++ b/dbc/dbc_classes.h @@ -21,7 +21,8 @@ enum DBC_SIG_VAL_TYPE SIGNED_INT, SP_FLOAT, DP_FLOAT, - STRING + STRING, + VALUE_STRING }; enum DBC_ATTRIBUTE_VAL_TYPE diff --git a/dbc/dbchandler.cpp b/dbc/dbchandler.cpp index d60dd1b..0dd3cd4 100644 --- a/dbc/dbchandler.cpp +++ b/dbc/dbchandler.cpp @@ -576,6 +576,9 @@ DBC_SIGNAL* DBCFile::parseSignalLine(QString line, DBC_MESSAGE *msg) sig.valType = DP_FLOAT; sig.intelByteOrder = true; break; + case 7: //double point float in little endian + sig.valType = VALUE_STRING; + break; } sig.factor = match.captured(6 + offset).toDouble(); sig.bias = match.captured(7 + offset).toDouble(); @@ -1443,6 +1446,9 @@ bool DBCFile::saveFile(QString fileName) case STRING: msgOutput.append("4-"); break; + case VALUE_STRING: + msgOutput.append("7-"); + break; default: msgOutput.append("0-"); break; diff --git a/dbc/dbcloadsavewindow.cpp b/dbc/dbcloadsavewindow.cpp index 7136379..fd38dd9 100644 --- a/dbc/dbcloadsavewindow.cpp +++ b/dbc/dbcloadsavewindow.cpp @@ -285,6 +285,7 @@ void DBCLoadSaveWindow::editFile() if (idx < 0) return; editorWindow->setFileIdx(idx); + editorWindow->setModal(true); editorWindow->show(); } diff --git a/dbc/dbcsignaleditor.cpp b/dbc/dbcsignaleditor.cpp index b81c11c..606ff63 100644 --- a/dbc/dbcsignaleditor.cpp +++ b/dbc/dbcsignaleditor.cpp @@ -34,6 +34,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) : ui->comboType->addItem("SINGLE PRECISION"); ui->comboType->addItem("DOUBLE PRECISION"); ui->comboType->addItem("STRING"); + ui->comboType->addItem("ENUMERATED STRING"); ui->bitfield->setMode(GridMode::SIGNAL_VIEW); @@ -84,7 +85,10 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) : break; case 4: currentSignal->valType = STRING; - break; + break; + case 5: + currentSignal->valType = VALUE_STRING; + break; } dbcFile->setDirtyFlag(); fillSignalForm(currentSignal); @@ -577,6 +581,9 @@ void DBCSignalEditor::fillSignalForm(DBC_SIGNAL *sig) case STRING: ui->comboType->setCurrentIndex(4); break; + case VALUE_STRING: + ui->comboType->setCurrentIndex(5); + break; } for (int i = 0; i < ui->comboReceiver->count(); i++) diff --git a/signalviewerwindow.cpp b/signalviewerwindow.cpp index cb70364..6346168 100644 --- a/signalviewerwindow.cpp +++ b/signalviewerwindow.cpp @@ -286,13 +286,14 @@ void SignalViewerWindow::loadDefinitions(bool append) if (msg = dbcHandler->findMessage(msgName)) { sig = msg->sigHandler->findSignalByName(sigName); - loadedSignals.append(sig); + if(sig) + loadedSignals.append(sig); } else if(msg = dbcHandler->findMessage(msgId)) { sig = msg->sigHandler->findSignalByName(sigName); - //fix anything up about the name? - loadedSignals.append(sig); + if(sig) + loadedSignals.append(sig); } else { From da7a721494ab474abc17d7a438e470faeedbbfde Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Tue, 20 Sep 2022 16:27:53 -0500 Subject: [PATCH 02/10] Changed default signalviewer message matching to be by ID --- signalviewerwindow.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/signalviewerwindow.cpp b/signalviewerwindow.cpp index 6346168..2835699 100644 --- a/signalviewerwindow.cpp +++ b/signalviewerwindow.cpp @@ -283,14 +283,15 @@ void SignalViewerWindow::loadDefinitions(bool append) QString msgName = QString(tokens[2]); QString sigName = QString(tokens[3]); DBC_MESSAGE *msg;; - if (msg = dbcHandler->findMessage(msgName)) + if(msg = dbcHandler->findMessage(msgId)) { sig = msg->sigHandler->findSignalByName(sigName); if(sig) loadedSignals.append(sig); } - else if(msg = dbcHandler->findMessage(msgId)) + else if (msg = dbcHandler->findMessage(msgName)) { + //this is not a very safe way to match since messages names can be duplicated sig = msg->sigHandler->findSignalByName(sigName); if(sig) loadedSignals.append(sig); From 6accf2e9e7fa8adef80ff4294db26fa9159fdab9 Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Tue, 20 Sep 2022 16:48:11 -0500 Subject: [PATCH 03/10] Fixed bug in extended addressing check where ID was being AND'ed with 80000000 decimal instead of hex --- dbc/dbchandler.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/dbc/dbchandler.cpp b/dbc/dbchandler.cpp index 0dd3cd4..3c11d33 100644 --- a/dbc/dbchandler.cpp +++ b/dbc/dbchandler.cpp @@ -453,7 +453,7 @@ DBC_MESSAGE* DBCFile::parseMessageLine(QString line) DBC_MESSAGE msg; uint32_t ID = match.captured(1).toULong(); //the ID is always stored in decimal format msg.ID = ID & 0x1FFFFFFFul; - msg.extendedID = (ID & 80000000ul) ? true : false; + msg.extendedID = (ID & 0x80000000ul) ? true : false; msg.name = match.captured(2); msg.len = match.captured(3).toUInt(); msg.sender = findNodeByName(match.captured(4)); @@ -1372,7 +1372,10 @@ bool DBCFile::saveFile(QString fileName) } uint32_t ID = msg->ID; - if (msg->ID > 0x7FF || msg->extendedID) msg->ID += 0x80000000ul; //set bit 31 if this ID is extended. + if (msg->ID > 0x7FF || msg->extendedID) + { + msg->ID += 0x80000000ul; //set bit 31 if this ID is extended. + } msgOutput.append("BO_ " + QString::number(ID) + " " + msg->name + ": " + QString::number(msg->len) + " " + msg->sender->name + "\n"); @@ -1571,7 +1574,10 @@ bool DBCFile::saveFile(QString fileName) DBC_MESSAGE *msg = messageHandler->findMsgByIdx(x); uint32_t ID = msg->ID; - if (msg->ID > 0x7FF || msg->extendedID) msg->ID += 0x80000000ul; //set bit 31 if this ID is extended. + if (msg->ID > 0x7FF || msg->extendedID) + { + msg->ID += 0x80000000ul; //set bit 31 if this ID is extended. + } for (int s = 0; s < msg->sigHandler->getCount(); s++) { From d9e371c494bf721f3edb35c72330dbd3dd45eedc Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Tue, 20 Sep 2022 16:50:04 -0500 Subject: [PATCH 04/10] The last commit of the ext ID fix removed need for modal editor --- dbc/dbcloadsavewindow.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/dbc/dbcloadsavewindow.cpp b/dbc/dbcloadsavewindow.cpp index fd38dd9..7136379 100644 --- a/dbc/dbcloadsavewindow.cpp +++ b/dbc/dbcloadsavewindow.cpp @@ -285,7 +285,6 @@ void DBCLoadSaveWindow::editFile() if (idx < 0) return; editorWindow->setFileIdx(idx); - editorWindow->setModal(true); editorWindow->show(); } From 0ee9eacbb3e16973b0564fc9e20c1a592518b6af Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Tue, 20 Sep 2022 17:08:20 -0500 Subject: [PATCH 05/10] realized that the value list was already supported so reverted my custom code. The issue that made me go down this path is related to the little endian checkbox mysteriously and inconsistently unchecking and therefore interpreting enum values wrong...would really like to find this. --- dbc/dbc_classes.cpp | 15 ++------------- dbc/dbc_classes.h | 3 +-- dbc/dbchandler.cpp | 6 ------ dbc/dbcsignaleditor.cpp | 6 ------ 4 files changed, 3 insertions(+), 27 deletions(-) diff --git a/dbc/dbc_classes.cpp b/dbc/dbc_classes.cpp index 2a43815..5467b4f 100644 --- a/dbc/dbc_classes.cpp +++ b/dbc/dbc_classes.cpp @@ -137,17 +137,6 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString, bool o cachedValue = outString; return true; } - else if(valType == VALUE_STRING) - { - result = Utility::processIntegerSignal(frame.payload(), startBit, signalSize, intelByteOrder, isSigned); - - if(!getValueString(result, outString)) - { - outString = "Signal string value is undefined"; - } - - return true; - } if (valType == SIGNED_INT) isSigned = true; if (valType == SIGNED_INT || valType == UNSIGNED_INT) @@ -240,7 +229,7 @@ bool DBC_SIGNAL::processAsInt(const CANFrame &frame, int32_t &outValue) int32_t result = 0; bool isSigned = false; - if (valType == STRING || valType == VALUE_STRING || valType == SP_FLOAT || valType == DP_FLOAT) + if (valType == STRING || valType == SP_FLOAT || valType == DP_FLOAT) { return false; } @@ -273,7 +262,7 @@ bool DBC_SIGNAL::processAsDouble(const CANFrame &frame, double &outValue) bool isSigned = false; double endResult; - if (valType == STRING || valType == VALUE_STRING) + if (valType == STRING) { return false; } diff --git a/dbc/dbc_classes.h b/dbc/dbc_classes.h index b093a5d..fd085c2 100644 --- a/dbc/dbc_classes.h +++ b/dbc/dbc_classes.h @@ -21,8 +21,7 @@ enum DBC_SIG_VAL_TYPE SIGNED_INT, SP_FLOAT, DP_FLOAT, - STRING, - VALUE_STRING + STRING }; enum DBC_ATTRIBUTE_VAL_TYPE diff --git a/dbc/dbchandler.cpp b/dbc/dbchandler.cpp index 3c11d33..9088bda 100644 --- a/dbc/dbchandler.cpp +++ b/dbc/dbchandler.cpp @@ -576,9 +576,6 @@ DBC_SIGNAL* DBCFile::parseSignalLine(QString line, DBC_MESSAGE *msg) sig.valType = DP_FLOAT; sig.intelByteOrder = true; break; - case 7: //double point float in little endian - sig.valType = VALUE_STRING; - break; } sig.factor = match.captured(6 + offset).toDouble(); sig.bias = match.captured(7 + offset).toDouble(); @@ -1449,9 +1446,6 @@ bool DBCFile::saveFile(QString fileName) case STRING: msgOutput.append("4-"); break; - case VALUE_STRING: - msgOutput.append("7-"); - break; default: msgOutput.append("0-"); break; diff --git a/dbc/dbcsignaleditor.cpp b/dbc/dbcsignaleditor.cpp index 606ff63..b4bd6a3 100644 --- a/dbc/dbcsignaleditor.cpp +++ b/dbc/dbcsignaleditor.cpp @@ -86,9 +86,6 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) : case 4: currentSignal->valType = STRING; break; - case 5: - currentSignal->valType = VALUE_STRING; - break; } dbcFile->setDirtyFlag(); fillSignalForm(currentSignal); @@ -581,9 +578,6 @@ void DBCSignalEditor::fillSignalForm(DBC_SIGNAL *sig) case STRING: ui->comboType->setCurrentIndex(4); break; - case VALUE_STRING: - ui->comboType->setCurrentIndex(5); - break; } for (int i = 0; i < ui->comboReceiver->count(); i++) From 74366d1c6b07bd91dd2d3428400fc5f7e219547f Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Tue, 20 Sep 2022 17:49:04 -0500 Subject: [PATCH 06/10] context menu in place for node rebase/duplicate need to add menu for rebase options and code for both actions --- dbc/dbcmaineditor.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++ dbc/dbcmaineditor.h | 5 ++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/dbc/dbcmaineditor.cpp b/dbc/dbcmaineditor.cpp index 54a046b..d10fcc3 100644 --- a/dbc/dbcmaineditor.cpp +++ b/dbc/dbcmaineditor.cpp @@ -21,11 +21,14 @@ DBCMainEditor::DBCMainEditor( const QVector *frames, QWidget *parent) dbcHandler = DBCHandler::getReference(); referenceFrames = frames; + ui->treeDBC->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->btnSearch, &QAbstractButton::clicked, this, &DBCMainEditor::handleSearch); connect(ui->lineSearch, &QLineEdit::returnPressed, this, &DBCMainEditor::handleSearch); connect(ui->btnSearchNext, &QAbstractButton::clicked, this, &DBCMainEditor::handleSearchForward); connect(ui->btnSearchPrev, &QAbstractButton::clicked, this, &DBCMainEditor::handleSearchBackward); connect(ui->treeDBC, &QTreeWidget::doubleClicked, this, &DBCMainEditor::onTreeDoubleClicked); + connect(ui->treeDBC, &QTreeWidget::customContextMenuRequested, this, &DBCMainEditor::onTreeContextMenu); connect(ui->treeDBC, &QTreeWidget::currentItemChanged, this, &DBCMainEditor::currentItemChanged); connect(ui->btnDelete, &QAbstractButton::clicked, this, &DBCMainEditor::deleteCurrentTreeItem); connect(ui->btnNewNode, &QAbstractButton::clicked, this, &DBCMainEditor::newNode); @@ -298,6 +301,51 @@ void DBCMainEditor::onTreeDoubleClicked(const QModelIndex &index) } } +void DBCMainEditor::onTreeContextMenu(const QPoint & pos) +{ + QTreeWidgetItem* firstCol = ui->treeDBC->currentItem(); + bool ret = false; + DBC_MESSAGE *msg; + DBC_SIGNAL *sig; + DBC_NODE *node; + uint32_t msgID; + QString idString; + + qDebug() << firstCol->data(0, Qt::UserRole) << " - " << firstCol->text(0); + + switch (firstCol->data(0, Qt::UserRole).toInt()) + { + case 1: //a node + idString = firstCol->text(0).split(" ")[0]; + node = dbcFile->findNodeByName(idString); + + QAction *actionRebase = new QAction(QIcon(":/Resource/warning32.ico"), tr("Rebase all messages"), this); + actionRebase->setStatusTip(tr("Rebase all messages in node")); + connect(actionRebase, SIGNAL(triggered()), this, SLOT(onRebaseMessages())); + + QAction *actionDupe = new QAction(QIcon(":/Resource/warning32.ico"), tr("Duplicate node"), this); + actionDupe->setStatusTip(tr("Duplicate node and messages")); + connect(actionDupe, SIGNAL(triggered()), this, SLOT(onDuplicateNode())); + + QMenu menu(this); + menu.addAction(actionRebase); + menu.addAction(actionDupe); + + QPoint pt(pos); + menu.exec( ui->treeDBC->mapToGlobal(pos) ); + break; + } +} + +void DBCMainEditor::onRebaseMessages() +{ + qDebug() << "rebase!!"; +} + +void DBCMainEditor::onDuplicateNode() +{ + qDebug() << "dupe!!"; +} /* * Recreate the whole tree with pretty icons and custom user roles that give the rest of code an easy way to figure out whether a given tree node diff --git a/dbc/dbcmaineditor.h b/dbc/dbcmaineditor.h index bfc3acd..dc8ea7c 100644 --- a/dbc/dbcmaineditor.h +++ b/dbc/dbcmaineditor.h @@ -32,6 +32,7 @@ public slots: private slots: void onTreeDoubleClicked(const QModelIndex &index); + void onTreeContextMenu(const QPoint & pos); void currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *prev); void onCustomMenuTree(QPoint); void deleteCurrentTreeItem(); @@ -43,7 +44,9 @@ private slots: void handleSearchBackward(); void newNode(); void newMessage(); - void newSignal(); + void newSignal(); + void onRebaseMessages(); + void onDuplicateNode(); private: Ui::DBCMainEditor *ui; From 27b58552df7219ec7d27b7c88a59ebe074f509ef Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Wed, 21 Sep 2022 18:04:11 -0500 Subject: [PATCH 07/10] rebase working but definitely needs clean up for all the whatifs --- SavvyCAN.pro | 3 + canframemodel.cpp | 1 + dbc/dbchandler.cpp | 18 ++++ dbc/dbchandler.h | 1 + dbc/dbcmaineditor.cpp | 18 +++- dbc/dbcmaineditor.h | 2 + dbc/dbcnoderebaseeditor.cpp | 166 ++++++++++++++++++++++++++++++++++++ dbc/dbcnoderebaseeditor.h | 42 +++++++++ ui/dbcnoderebaseeditor.ui | 75 ++++++++++++++++ 9 files changed, 325 insertions(+), 1 deletion(-) create mode 100644 dbc/dbcnoderebaseeditor.cpp create mode 100644 dbc/dbcnoderebaseeditor.h create mode 100644 ui/dbcnoderebaseeditor.ui diff --git a/SavvyCAN.pro b/SavvyCAN.pro index 9df479e..0a7094b 100644 --- a/SavvyCAN.pro +++ b/SavvyCAN.pro @@ -67,6 +67,7 @@ SOURCES += main.cpp\ dbc/dbcmaineditor.cpp \ dbc/dbcnodeeditor.cpp \ dbc/dbcsignaleditor.cpp \ + dbc/dbcnoderebaseeditor.cpp \ re/discretestatewindow.cpp \ re/filecomparatorwindow.cpp \ re/flowviewwindow.cpp \ @@ -100,6 +101,7 @@ HEADERS += mainwindow.h \ canframemodel.h \ connections/socketcand.h \ connections/mqtt_bus.h \ + dbc/dbcnoderebaseeditor.h \ mqtt/qmqtt.h \ mqtt/qmqtt_client.h \ mqtt/qmqtt_client_p.h \ @@ -188,6 +190,7 @@ FORMS += ui/candatagrid.ui \ ui/connectionwindow.ui \ ui/dbcloadsavewindow.ui \ ui/dbcmaineditor.ui \ + ui/dbcnoderebaseeditor.ui \ ui/dbcsignaleditor.ui \ ui/dbcnodeeditor.ui \ ui/discretestatewindow.ui \ diff --git a/canframemodel.cpp b/canframemodel.cpp index aef3a34..03bb5d7 100644 --- a/canframemodel.cpp +++ b/canframemodel.cpp @@ -380,6 +380,7 @@ void CANFrameModel::recalcOverwrite() //Then replace the old list of frames with just the unique list frames.clear(); frames.append(overWriteFrames.values().toVector()); + frames.reserve(preallocSize); filteredFrames.clear(); filteredFrames.reserve(preallocSize); diff --git a/dbc/dbchandler.cpp b/dbc/dbchandler.cpp index 9088bda..23523ec 100644 --- a/dbc/dbchandler.cpp +++ b/dbc/dbchandler.cpp @@ -177,6 +177,24 @@ DBC_MESSAGE* DBCMessageHandler::findMsgByPartialName(QString name) return nullptr; } +QList DBCMessageHandler::findMsgsByNode(DBC_NODE* node) +{ + QList messagesForNode; + + if (messages.count() == 0) + return messagesForNode; + + for (int i = 0; i < messages.count(); i++) + { + if (messages[i].sender == node) + { + messagesForNode.append(&messages[i]); + } + } + + return messagesForNode; +} + bool DBCMessageHandler::addMessage(DBC_MESSAGE &msg) { messages.append(msg); diff --git a/dbc/dbchandler.h b/dbc/dbchandler.h index 9e040cb..925bc8c 100644 --- a/dbc/dbchandler.h +++ b/dbc/dbchandler.h @@ -43,6 +43,7 @@ public: DBC_MESSAGE *findMsgByIdx(int idx); DBC_MESSAGE *findMsgByName(QString name); DBC_MESSAGE *findMsgByPartialName(QString name); + QList findMsgsByNode(DBC_NODE *node); bool addMessage(DBC_MESSAGE &msg); bool removeMessage(DBC_MESSAGE *msg); bool removeMessageByIndex(int idx); diff --git a/dbc/dbcmaineditor.cpp b/dbc/dbcmaineditor.cpp index d10fcc3..88e3753 100644 --- a/dbc/dbcmaineditor.cpp +++ b/dbc/dbcmaineditor.cpp @@ -38,11 +38,13 @@ DBCMainEditor::DBCMainEditor( const QVector *frames, QWidget *parent) sigEditor = new DBCSignalEditor(this); msgEditor = new DBCMessageEditor(this); nodeEditor = new DBCNodeEditor(this); + nodeRebaseEditor = new DBCNodeRebaseEditor(this); //all three might potentially change the data stored and force the tree to be updated connect(sigEditor, &DBCSignalEditor::updatedTreeInfo, this, &DBCMainEditor::updatedSignal); connect(msgEditor, &DBCMessageEditor::updatedTreeInfo, this, &DBCMainEditor::updatedMessage); connect(nodeEditor, &DBCNodeEditor::updatedTreeInfo, this, &DBCMainEditor::updatedNode); + connect(nodeRebaseEditor, &DBCNodeRebaseEditor::updatedTreeInfo, this, &DBCMainEditor::updatedMessage); nodeIcon = QIcon(":/icons/images/node.png"); messageIcon = QIcon(":/icons/images/message.png"); @@ -339,7 +341,21 @@ void DBCMainEditor::onTreeContextMenu(const QPoint & pos) void DBCMainEditor::onRebaseMessages() { - qDebug() << "rebase!!"; + QTreeWidgetItem* firstCol = ui->treeDBC->currentItem(); + bool ret = false; + DBC_MESSAGE *msg; + DBC_SIGNAL *sig; + DBC_NODE *node; + uint32_t msgID; + QString idString; + + idString = firstCol->text(0).split(" ")[0]; + node = dbcFile->findNodeByName(idString); + nodeRebaseEditor->setFileIdx(fileIdx); + nodeRebaseEditor->setNodeRef(node); + nodeRebaseEditor->refreshView(); + nodeRebaseEditor->setModal(true); + nodeRebaseEditor->show(); } void DBCMainEditor::onDuplicateNode() diff --git a/dbc/dbcmaineditor.h b/dbc/dbcmaineditor.h index dc8ea7c..62f0876 100644 --- a/dbc/dbcmaineditor.h +++ b/dbc/dbcmaineditor.h @@ -10,6 +10,7 @@ #include "dbcsignaleditor.h" #include "dbcmessageeditor.h" #include "dbcnodeeditor.h" +#include "dbcnoderebaseeditor.h" #include "utility.h" namespace Ui { @@ -55,6 +56,7 @@ private: DBCSignalEditor *sigEditor; DBCMessageEditor *msgEditor; DBCNodeEditor *nodeEditor; + DBCNodeRebaseEditor *nodeRebaseEditor; DBCFile *dbcFile; int fileIdx; QIcon nodeIcon; diff --git a/dbc/dbcnoderebaseeditor.cpp b/dbc/dbcnoderebaseeditor.cpp new file mode 100644 index 0000000..393b656 --- /dev/null +++ b/dbc/dbcnoderebaseeditor.cpp @@ -0,0 +1,166 @@ +#include "dbcnoderebaseeditor.h" +#include "ui_dbcnoderebaseeditor.h" + +#include +#include +#include +#include "helpwindow.h" +#include "utility.h" + +DBCNodeRebaseEditor::DBCNodeRebaseEditor(QWidget *parent) : + QDialog(parent), + ui(new Ui::DBCNodeRebaseEditor) +{ + ui->setupUi(this); + + readSettings(); + + dbcHandler = DBCHandler::getReference(); + dbcNode = nullptr; + + connect(ui->btnDoRebase, &QPushButton::pressed, + [=]() + { + if (dbcNode == nullptr) return; + if (lowestMsgId > 0x1FFFFFFFul) return; + + uint newBase = Utility::ParseStringToNum(ui->lineEdit->text()); + + if (newBase <= 0x1FFFFFFFul && newBase != lowestMsgId) + { + uint rebaseDiff = newBase - lowestMsgId; + + QList messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode); + if(messagesForNode.count() == 0) + { + return; + } + + for (int i=0; iID += rebaseDiff; + emit updatedTreeInfo(messagesForNode[i]); + } + + dbcFile->setDirtyFlag(); + } + + + }); + +// connect(ui->lineOriginalBaseId, &QLineEdit::editingFinished, +// [=]() +// { +// if (dbcNode == nullptr) return; +// if (dbcNode->comment != ui->lineComment->text()) dbcFile->setDirtyFlag(); +// dbcNode->comment = ui->lineComment->text(); +// emit updatedTreeInfo(dbcNode); +// }); + +// connect(ui->lineMsgName, &QLineEdit::editingFinished, +// [=]() +// { +// if (dbcNode == nullptr) return; +// if (dbcNode->name != ui->lineMsgName->text()) dbcFile->setDirtyFlag(); +// dbcNode->name = ui->lineMsgName->text(); +// emit updatedTreeInfo(dbcNode); +// }); + + installEventFilter(this); +} + +DBCNodeRebaseEditor::~DBCNodeRebaseEditor() +{ + removeEventFilter(this); + delete ui; +} + +void DBCNodeRebaseEditor::closeEvent(QCloseEvent *event) +{ + Q_UNUSED(event); + writeSettings(); +} + +bool DBCNodeRebaseEditor::eventFilter(QObject *obj, QEvent *event) +{ + if (event->type() == QEvent::KeyRelease) { + QKeyEvent *keyEvent = static_cast(event); + switch (keyEvent->key()) + { + case Qt::Key_F1: + HelpWindow::getRef()->showHelp("nodeeditor.md"); + break; + } + return true; + } else { + // standard event processing + return QObject::eventFilter(obj, event); + } + return false; +} + +void DBCNodeRebaseEditor::setFileIdx(int idx) +{ + if (idx < 0 || idx > dbcHandler->getFileCount() - 1) return; + dbcFile = dbcHandler->getFileByIdx(idx); +} + +void DBCNodeRebaseEditor::readSettings() +{ + QSettings settings; + if (settings.value("Main/SaveRestorePositions", false).toBool()) + { + resize(settings.value("DBCNodeRebaseEditor/WindowSize", QSize(312, 128)).toSize()); + move(Utility::constrainedWindowPos(settings.value("DBCNodeRebaseEditor/WindowPos", QPoint(100, 100)).toPoint())); + } +} + +void DBCNodeRebaseEditor::writeSettings() +{ + QSettings settings; + + if (settings.value("Main/SaveRestorePositions", false).toBool()) + { + settings.setValue("DBCNodeRebaseEditor/WindowSize", size()); + settings.setValue("DBCNodeRebaseEditor/WindowPos", pos()); + } +} + + +void DBCNodeRebaseEditor::setNodeRef(DBC_NODE *node) +{ + dbcNode = node; +} + +void DBCNodeRebaseEditor::showEvent(QShowEvent* event) +{ + QDialog::showEvent(event); + + refreshView(); +} + +void DBCNodeRebaseEditor::refreshView() +{ + if(dbcNode) + { + QList messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode); + if(messagesForNode.count() == 0) + { + //?? + + } + + lowestMsgId = 0xFFFFFFFF; + + for (int i=0; iID < lowestMsgId) + lowestMsgId = messagesForNode[i]->ID; + } + + ui->lineOriginalBaseId->setText(Utility::formatCANID(lowestMsgId & 0x1FFFFFFFul)); + ui->lineMsgName->setText(dbcNode->name); + } + + //generateSampleText(); +} diff --git a/dbc/dbcnoderebaseeditor.h b/dbc/dbcnoderebaseeditor.h new file mode 100644 index 0000000..8e787f0 --- /dev/null +++ b/dbc/dbcnoderebaseeditor.h @@ -0,0 +1,42 @@ +#ifndef DBCNODEREBASEEDITOR_H +#define DBCNODEREBASEEDITOR_H + +#include +#include "dbc_classes.h" +#include "dbchandler.h" + +namespace Ui { +class DBCNodeRebaseEditor; +} + +class DBCNodeRebaseEditor : public QDialog +{ + Q_OBJECT + +public: + explicit DBCNodeRebaseEditor(QWidget *parent = nullptr); + ~DBCNodeRebaseEditor(); + void showEvent(QShowEvent*); + void setNodeRef(DBC_NODE *node); + void setFileIdx(int idx); + void refreshView(); + +signals: + void updatedTreeInfo(DBC_MESSAGE *msg); + +private: + Ui::DBCNodeRebaseEditor *ui; + + DBCHandler *dbcHandler; + DBC_NODE *dbcNode; + DBCFile *dbcFile; + + void closeEvent(QCloseEvent *event); + bool eventFilter(QObject *obj, QEvent *event); + void readSettings(); + void writeSettings(); + + uint lowestMsgId; +}; + +#endif // DBCNODEREBASEEDITOR_H diff --git a/ui/dbcnoderebaseeditor.ui b/ui/dbcnoderebaseeditor.ui new file mode 100644 index 0000000..58bc46c --- /dev/null +++ b/ui/dbcnoderebaseeditor.ui @@ -0,0 +1,75 @@ + + + DBCNodeRebaseEditor + + + + 0 + 0 + 303 + 159 + + + + Dialog + + + + + 10 + 20 + 283 + 116 + + + + + + + Node Name: + + + + + + + + + + Current Base ID: + + + + + + + + + + New Base ID: + + + + + + + + + + Rebase All Messages in Node + + + + + + + Cancel + + + + + + + + + From 47d63c6296e0bfc7f4307bee2fea6ee4993fdd43 Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Thu, 22 Sep 2022 18:04:27 -0500 Subject: [PATCH 08/10] duplicate works! multiplexed signals are not copied at this time need to learn more about them first need to do clean up and corner case handling --- SavvyCAN.pro | 4 + dbc/dbcmaineditor.cpp | 105 +++++++++++++++++++- dbc/dbcmaineditor.h | 4 + dbc/dbcnodeduplicateeditor.cpp | 171 +++++++++++++++++++++++++++++++++ dbc/dbcnodeduplicateeditor.h | 45 +++++++++ dbc/dbcnoderebaseeditor.cpp | 9 +- ui/dbcnodeduplicateeditor.ui | 75 +++++++++++++++ ui/dbcnoderebaseeditor.ui | 2 +- 8 files changed, 409 insertions(+), 6 deletions(-) create mode 100644 dbc/dbcnodeduplicateeditor.cpp create mode 100644 dbc/dbcnodeduplicateeditor.h create mode 100644 ui/dbcnodeduplicateeditor.ui diff --git a/SavvyCAN.pro b/SavvyCAN.pro index 0a7094b..b8f445b 100644 --- a/SavvyCAN.pro +++ b/SavvyCAN.pro @@ -21,6 +21,7 @@ ICON = icons/SavvyIcon.icns SOURCES += main.cpp\ connections/mqtt_bus.cpp \ + dbc/dbcnodeduplicateeditor.cpp \ mqtt/qmqtt_client.cpp \ mqtt/qmqtt_client_p.cpp \ mqtt/qmqtt_frame.cpp \ @@ -101,6 +102,7 @@ HEADERS += mainwindow.h \ canframemodel.h \ connections/socketcand.h \ connections/mqtt_bus.h \ + dbc/dbcnodeduplicateeditor.h \ dbc/dbcnoderebaseeditor.h \ mqtt/qmqtt.h \ mqtt/qmqtt_client.h \ @@ -185,11 +187,13 @@ HEADERS += mainwindow.h \ pcaplite.h FORMS += ui/candatagrid.ui \ + ui/dbcnodeduplicateeditor.ui \ ui/dbccomparatorwindow.ui \ ui/dbcmessageeditor.ui \ ui/connectionwindow.ui \ ui/dbcloadsavewindow.ui \ ui/dbcmaineditor.ui \ + ui/dbcnodeduplicateeditor.ui \ ui/dbcnoderebaseeditor.ui \ ui/dbcsignaleditor.ui \ ui/dbcnodeeditor.ui \ diff --git a/dbc/dbcmaineditor.cpp b/dbc/dbcmaineditor.cpp index 88e3753..2415bd5 100644 --- a/dbc/dbcmaineditor.cpp +++ b/dbc/dbcmaineditor.cpp @@ -31,7 +31,7 @@ DBCMainEditor::DBCMainEditor( const QVector *frames, QWidget *parent) connect(ui->treeDBC, &QTreeWidget::customContextMenuRequested, this, &DBCMainEditor::onTreeContextMenu); connect(ui->treeDBC, &QTreeWidget::currentItemChanged, this, &DBCMainEditor::currentItemChanged); connect(ui->btnDelete, &QAbstractButton::clicked, this, &DBCMainEditor::deleteCurrentTreeItem); - connect(ui->btnNewNode, &QAbstractButton::clicked, this, &DBCMainEditor::newNode); + connect(ui->btnNewNode, &QAbstractButton::clicked, this, QOverload<>::of(&DBCMainEditor::newNode)); connect(ui->btnNewMessage, &QAbstractButton::clicked, this, &DBCMainEditor::newMessage); connect(ui->btnNewSignal, &QAbstractButton::clicked, this, &DBCMainEditor::newSignal); @@ -39,12 +39,17 @@ DBCMainEditor::DBCMainEditor( const QVector *frames, QWidget *parent) msgEditor = new DBCMessageEditor(this); nodeEditor = new DBCNodeEditor(this); nodeRebaseEditor = new DBCNodeRebaseEditor(this); + nodeDuplicateEditor = new DBCNodeDuplicateEditor(this); //all three might potentially change the data stored and force the tree to be updated connect(sigEditor, &DBCSignalEditor::updatedTreeInfo, this, &DBCMainEditor::updatedSignal); connect(msgEditor, &DBCMessageEditor::updatedTreeInfo, this, &DBCMainEditor::updatedMessage); connect(nodeEditor, &DBCNodeEditor::updatedTreeInfo, this, &DBCMainEditor::updatedNode); connect(nodeRebaseEditor, &DBCNodeRebaseEditor::updatedTreeInfo, this, &DBCMainEditor::updatedMessage); + connect(nodeDuplicateEditor, &DBCNodeDuplicateEditor::updatedTreeInfo, this, &DBCMainEditor::updatedMessage); + connect(nodeDuplicateEditor, &DBCNodeDuplicateEditor::createNode, this, QOverload::of(&DBCMainEditor::newNode)); + connect(nodeDuplicateEditor, &DBCNodeDuplicateEditor::cloneMessageToNode, this, &DBCMainEditor::copyMessageToNode); + connect(nodeDuplicateEditor, &DBCNodeDuplicateEditor::nodeAdded, this, &DBCMainEditor::refreshTree); nodeIcon = QIcon(":/icons/images/node.png"); messageIcon = QIcon(":/icons/images/message.png"); @@ -360,7 +365,21 @@ void DBCMainEditor::onRebaseMessages() void DBCMainEditor::onDuplicateNode() { - qDebug() << "dupe!!"; + QTreeWidgetItem* firstCol = ui->treeDBC->currentItem(); + bool ret = false; + DBC_MESSAGE *msg; + DBC_SIGNAL *sig; + DBC_NODE *node; + uint32_t msgID; + QString idString; + + idString = firstCol->text(0).split(" ")[0]; + node = dbcFile->findNodeByName(idString); + nodeDuplicateEditor->setFileIdx(fileIdx); + nodeDuplicateEditor->setNodeRef(node); + nodeDuplicateEditor->refreshView(); + nodeDuplicateEditor->setModal(true); + nodeDuplicateEditor->show(); } /* @@ -545,11 +564,18 @@ void DBCMainEditor::updatedSignal(DBC_SIGNAL *sig) else qDebug() << "That signal doesn't exist. That's a bug dude."; } -void DBCMainEditor::newNode() +void DBCMainEditor::newNode(QString nodeName) { DBC_NODE node; DBC_NODE *nodePtr; - node.name = "Unnamed" + QString::number(randGen.bounded(50000)); + if(nodeName.isEmpty()) + { + node.name = "Unnamed" + QString::number(randGen.bounded(50000)); + } + else + { + node.name = nodeName; + } dbcFile->dbc_nodes.append(node); nodePtr = dbcFile->findNodeByName(node.name); QTreeWidgetItem *nodeItem = new QTreeWidgetItem(); @@ -563,6 +589,77 @@ void DBCMainEditor::newNode() dbcFile->setDirtyFlag(); } +void DBCMainEditor::newNode() +{ + newNode(QString()); +} + +void DBCMainEditor::copyMessageToNode(DBC_NODE *parentNode, DBC_MESSAGE *source, uint newMsgId) +{ + DBC_NODE *node = parentNode; + if (!node) node = dbcFile->findNodeByIdx(0); + QTreeWidgetItem *nodeItem = nullptr; + DBC_MESSAGE msg; + DBC_MESSAGE *msgPtr; + + nodeItem = ui->treeDBC->currentItem(); + + msg.name = source->name; + msg.ID = newMsgId; + msg.len = source->len; + msg.bgColor = source->bgColor; + msg.fgColor = source->fgColor; + msg.comment = source->comment; + msg.sender = node; + + DBC_SIGNAL *sigSource; + int sigCount = source->sigHandler->getCount(); + + for(int i=0; isigHandler->findSignalByIdx(i); + + DBC_SIGNAL sig; + + //Does not properly handle multiplexed signals, for now + sig.name = sigSource->name; + sig.bias = sigSource->bias; + sig.isMultiplexed = false; //sigSource->isMultiplexed; + sig.isMultiplexor = false; //sigSource->isMultiplexor; + sig.max = sigSource->max; + sig.min = sigSource->min; + sig.multiplexLowValue = sigSource->multiplexLowValue; + sig.multiplexHighValue = sigSource->multiplexHighValue; + sig.factor = sigSource->factor; + sig.intelByteOrder = sigSource->intelByteOrder; + sig.parentMessage = &msg; + sig.multiplexParent = nullptr; //need to learn about multiplexed signals and track them when copying + sig.receiver = node; + sig.signalSize = sigSource->signalSize; + sig.startBit = sigSource->startBit; + sig.valType = sigSource->valType; + + + sig.parentMessage = &msg; + msg.sigHandler->addSignal(sig); + } + + msg.sigHandler->sort(); + + dbcFile->messageHandler->addMessage(msg); + msgPtr = dbcFile->messageHandler->findMsgByIdx(dbcFile->messageHandler->getCount() - 1); + QTreeWidgetItem *newMsgItem = new QTreeWidgetItem(); + QString msgInfo = Utility::formatCANID(msg.ID) + " " + msg.name; + if (msg.comment.count() > 0) msgInfo.append(" - ").append(msg.comment); + newMsgItem->setText(0, msgInfo); + newMsgItem->setIcon(0, messageIcon); + newMsgItem->setData(0, Qt::UserRole, 2); + messageToItem.insert(msgPtr, newMsgItem); + itemToMessage.insert(newMsgItem, msgPtr); + nodeItem->addChild(newMsgItem); + //ui->treeDBC->setCurrentItem(newMsgItem); + dbcFile->setDirtyFlag(); +} //create a new message with it's parent being the node we're currently within void DBCMainEditor::newMessage() diff --git a/dbc/dbcmaineditor.h b/dbc/dbcmaineditor.h index 62f0876..5977f82 100644 --- a/dbc/dbcmaineditor.h +++ b/dbc/dbcmaineditor.h @@ -11,6 +11,7 @@ #include "dbcmessageeditor.h" #include "dbcnodeeditor.h" #include "dbcnoderebaseeditor.h" +#include "dbcnodeduplicateeditor.h" #include "utility.h" namespace Ui { @@ -43,7 +44,9 @@ private slots: void handleSearch(); void handleSearchForward(); void handleSearchBackward(); + void newNode(QString nodeName); void newNode(); + void copyMessageToNode(DBC_NODE *node, DBC_MESSAGE *source, uint newMsgId); void newMessage(); void newSignal(); void onRebaseMessages(); @@ -57,6 +60,7 @@ private: DBCMessageEditor *msgEditor; DBCNodeEditor *nodeEditor; DBCNodeRebaseEditor *nodeRebaseEditor; + DBCNodeDuplicateEditor *nodeDuplicateEditor; DBCFile *dbcFile; int fileIdx; QIcon nodeIcon; diff --git a/dbc/dbcnodeduplicateeditor.cpp b/dbc/dbcnodeduplicateeditor.cpp new file mode 100644 index 0000000..c2a3164 --- /dev/null +++ b/dbc/dbcnodeduplicateeditor.cpp @@ -0,0 +1,171 @@ +#include "dbcnodeduplicateeditor.h" +#include "ui_dbcnodeduplicateeditor.h" + +#include +#include +#include +#include "helpwindow.h" +#include "utility.h" + +DBCNodeDuplicateEditor::DBCNodeDuplicateEditor(QWidget *parent) : + QDialog(parent), + ui(new Ui::DBCNodeDuplicateEditor) +{ + ui->setupUi(this); + + readSettings(); + + dbcHandler = DBCHandler::getReference(); + dbcNode = nullptr; + + connect(ui->btnDuplicate, &QPushButton::pressed, + [=]() + { + if (dbcNode == nullptr) return; + if (lowestMsgId > 0x1FFFFFFFul) return; + + uint newBase = Utility::ParseStringToNum(ui->lineNewBaseId->text()); + + if (newBase <= 0x1FFFFFFFul && newBase != lowestMsgId) + { + uint rebaseDiff = newBase - lowestMsgId; + + QList messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode); + if(messagesForNode.count() == 0) + { + return; + } + + if(ui->lineNodeName->text().isEmpty()) + { + //tell! + return; + } + + QString newNodeName = ui->lineNodeName->text(); + emit createNode(newNodeName); + + DBC_NODE *nodePtr = dbcFile->findNodeByName(newNodeName); + + if(nodePtr == nullptr) + { + //uhoh + return; + } + + for (int i=0; iID + rebaseDiff; + emit cloneMessageToNode(nodePtr, messagesForNode[i], newMsgId); + } + + dbcFile->setDirtyFlag(); + emit nodeAdded(); + } + }); + + connect(ui->btnCancel, &QPushButton::pressed, + [=]() + { + + + }); + + installEventFilter(this); +} + +DBCNodeDuplicateEditor::~DBCNodeDuplicateEditor() +{ + removeEventFilter(this); + delete ui; +} + +void DBCNodeDuplicateEditor::closeEvent(QCloseEvent *event) +{ + Q_UNUSED(event); + writeSettings(); +} + +bool DBCNodeDuplicateEditor::eventFilter(QObject *obj, QEvent *event) +{ + if (event->type() == QEvent::KeyRelease) { + QKeyEvent *keyEvent = static_cast(event); + switch (keyEvent->key()) + { + case Qt::Key_F1: + HelpWindow::getRef()->showHelp("nodeeditor.md"); + break; + } + return true; + } else { + // standard event processing + return QObject::eventFilter(obj, event); + } + return false; +} + +void DBCNodeDuplicateEditor::setFileIdx(int idx) +{ + if (idx < 0 || idx > dbcHandler->getFileCount() - 1) return; + dbcFile = dbcHandler->getFileByIdx(idx); +} + +void DBCNodeDuplicateEditor::readSettings() +{ + QSettings settings; + if (settings.value("Main/SaveRestorePositions", false).toBool()) + { + resize(settings.value("DBCNodeDuplicateEditor/WindowSize", QSize(312, 128)).toSize()); + move(Utility::constrainedWindowPos(settings.value("DBCNodeDuplicateEditor/WindowPos", QPoint(100, 100)).toPoint())); + } +} + +void DBCNodeDuplicateEditor::writeSettings() +{ + QSettings settings; + + if (settings.value("Main/SaveRestorePositions", false).toBool()) + { + settings.setValue("DBCNodeDuplicateEditor/WindowSize", size()); + settings.setValue("DBCNodeDuplicateEditor/WindowPos", pos()); + } +} + + +void DBCNodeDuplicateEditor::setNodeRef(DBC_NODE *node) +{ + dbcNode = node; +} + +void DBCNodeDuplicateEditor::showEvent(QShowEvent* event) +{ + QDialog::showEvent(event); + + refreshView(); +} + +void DBCNodeDuplicateEditor::refreshView() +{ + if(dbcNode) + { + QList messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode); + if(messagesForNode.count() == 0) + { + //?? + + } + + lowestMsgId = 0xFFFFFFFF; + + for (int i=0; iID < lowestMsgId) + lowestMsgId = messagesForNode[i]->ID; + } + + ui->lineOriginalBaseId->setText(Utility::formatCANID(lowestMsgId & 0x1FFFFFFFul)); + ui->lineNodeName->setText(dbcNode->name + QString("_Copy")); + } + + //generateSampleText(); +} diff --git a/dbc/dbcnodeduplicateeditor.h b/dbc/dbcnodeduplicateeditor.h new file mode 100644 index 0000000..9a29a93 --- /dev/null +++ b/dbc/dbcnodeduplicateeditor.h @@ -0,0 +1,45 @@ +#ifndef DBCNODEDUPLICATEEDITOR_H +#define DBCNODEDUPLICATEEDITOR_H + +#include +#include "dbc_classes.h" +#include "dbchandler.h" + +namespace Ui { +class DBCNodeDuplicateEditor; +} + +class DBCNodeDuplicateEditor : public QDialog +{ + Q_OBJECT + +public: + explicit DBCNodeDuplicateEditor(QWidget *parent = nullptr); + ~DBCNodeDuplicateEditor(); + void showEvent(QShowEvent*); + void setNodeRef(DBC_NODE *node); + void setFileIdx(int idx); + void refreshView(); + +signals: + void updatedTreeInfo(DBC_MESSAGE *msg); + void createNode(QString nodeName); + void cloneMessageToNode(DBC_NODE *parentNode, DBC_MESSAGE *source, uint newMsgId); + void nodeAdded(); + +private: + Ui::DBCNodeDuplicateEditor *ui; + + DBCHandler *dbcHandler; + DBC_NODE *dbcNode; + DBCFile *dbcFile; + + void closeEvent(QCloseEvent *event); + bool eventFilter(QObject *obj, QEvent *event); + void readSettings(); + void writeSettings(); + + uint lowestMsgId; +}; + +#endif // DBCNODEDUPLICATEEDITOR_H diff --git a/dbc/dbcnoderebaseeditor.cpp b/dbc/dbcnoderebaseeditor.cpp index 393b656..5a8f6bb 100644 --- a/dbc/dbcnoderebaseeditor.cpp +++ b/dbc/dbcnoderebaseeditor.cpp @@ -46,6 +46,13 @@ DBCNodeRebaseEditor::DBCNodeRebaseEditor(QWidget *parent) : } + }); + + connect(ui->btnCancel, &QPushButton::pressed, + [=]() + { + + }); // connect(ui->lineOriginalBaseId, &QLineEdit::editingFinished, @@ -159,7 +166,7 @@ void DBCNodeRebaseEditor::refreshView() } ui->lineOriginalBaseId->setText(Utility::formatCANID(lowestMsgId & 0x1FFFFFFFul)); - ui->lineMsgName->setText(dbcNode->name); + ui->lineNodeName->setText(dbcNode->name); } //generateSampleText(); diff --git a/ui/dbcnodeduplicateeditor.ui b/ui/dbcnodeduplicateeditor.ui new file mode 100644 index 0000000..a07c435 --- /dev/null +++ b/ui/dbcnodeduplicateeditor.ui @@ -0,0 +1,75 @@ + + + DBCNodeDuplicateEditor + + + + 0 + 0 + 314 + 193 + + + + Dialog + + + + + 10 + 10 + 290 + 116 + + + + + + + New Node Name: + + + + + + + + + + Current Base ID: + + + + + + + + + + New Base ID: + + + + + + + + + + Duplicate Node + + + + + + + Cancel + + + + + + + + + diff --git a/ui/dbcnoderebaseeditor.ui b/ui/dbcnoderebaseeditor.ui index 58bc46c..ddcfbe1 100644 --- a/ui/dbcnoderebaseeditor.ui +++ b/ui/dbcnoderebaseeditor.ui @@ -31,7 +31,7 @@ - + From e86cfb277a24096b7cb3f3536d2592bf672bef39 Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Sun, 9 Oct 2022 10:45:30 -0500 Subject: [PATCH 09/10] Cleaned up all the UI elements and error checking for rebase and duplicate --- connections/socketcand.cpp | 4 + dbc/dbcmaineditor.cpp | 18 +++-- dbc/dbcnodeduplicateeditor.cpp | 131 +++++++++++++++++++++------------ dbc/dbcnodeduplicateeditor.h | 2 +- dbc/dbcnoderebaseeditor.cpp | 120 ++++++++++++++++++------------ dbc/dbcnoderebaseeditor.h | 2 +- ui/dbcnodeduplicateeditor.ui | 19 ++++- ui/dbcnoderebaseeditor.ui | 30 ++++++-- 8 files changed, 211 insertions(+), 115 deletions(-) diff --git a/connections/socketcand.cpp b/connections/socketcand.cpp index 8a6e5da..3388047 100644 --- a/connections/socketcand.cpp +++ b/connections/socketcand.cpp @@ -291,6 +291,10 @@ QString SocketCANd::decodeFrames(QString data, int busNum) if(frameParsed.length() < 4) { qDebug() << "Received frame doesn't contain any data: " << data; + + //todo + //this is not totally true, ive seen frames come through that look like < frame 1F020240 1664924225.371291 > + //if we found the closing token but theres no data then remove the message from the buffer return data; } diff --git a/dbc/dbcmaineditor.cpp b/dbc/dbcmaineditor.cpp index 2415bd5..53982e3 100644 --- a/dbc/dbcmaineditor.cpp +++ b/dbc/dbcmaineditor.cpp @@ -358,9 +358,11 @@ void DBCMainEditor::onRebaseMessages() node = dbcFile->findNodeByName(idString); nodeRebaseEditor->setFileIdx(fileIdx); nodeRebaseEditor->setNodeRef(node); - nodeRebaseEditor->refreshView(); - nodeRebaseEditor->setModal(true); - nodeRebaseEditor->show(); + if(nodeRebaseEditor->refreshView()) + { + nodeRebaseEditor->setModal(true); + nodeRebaseEditor->show(); + } } void DBCMainEditor::onDuplicateNode() @@ -376,10 +378,12 @@ void DBCMainEditor::onDuplicateNode() idString = firstCol->text(0).split(" ")[0]; node = dbcFile->findNodeByName(idString); nodeDuplicateEditor->setFileIdx(fileIdx); - nodeDuplicateEditor->setNodeRef(node); - nodeDuplicateEditor->refreshView(); - nodeDuplicateEditor->setModal(true); - nodeDuplicateEditor->show(); + nodeDuplicateEditor->setNodeRef(node); + if(nodeDuplicateEditor->refreshView()) + { + nodeDuplicateEditor->setModal(true); + nodeDuplicateEditor->show(); + } } /* diff --git a/dbc/dbcnodeduplicateeditor.cpp b/dbc/dbcnodeduplicateeditor.cpp index c2a3164..0c5b546 100644 --- a/dbc/dbcnodeduplicateeditor.cpp +++ b/dbc/dbcnodeduplicateeditor.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "helpwindow.h" #include "utility.h" @@ -18,58 +19,87 @@ DBCNodeDuplicateEditor::DBCNodeDuplicateEditor(QWidget *parent) : dbcHandler = DBCHandler::getReference(); dbcNode = nullptr; - connect(ui->btnDuplicate, &QPushButton::pressed, - [=]() + connect(ui->btnDuplicate, &QPushButton::pressed, + [=]() + { + if (dbcNode == nullptr) return; + if (lowestMsgId > 0x1FFFFFFFul) return; + + uint newBase = Utility::ParseStringToNum(ui->lineNewBaseId->text()); + + if(newBase <= 0 || newBase > 0x1FFFFFFFul) { - if (dbcNode == nullptr) return; - if (lowestMsgId > 0x1FFFFFFFul) return; + QMessageBox::question(this, "Invalid Address", "The new address is outside of the valid range.", + QMessageBox::Ok); + return; + } - uint newBase = Utility::ParseStringToNum(ui->lineNewBaseId->text()); + if(newBase == lowestMsgId) + { + QMessageBox::question(this, "Invalid Address", "The new address is the same as the original.", + QMessageBox::Ok); + return; + } - if (newBase <= 0x1FFFFFFFul && newBase != lowestMsgId) + uint rebaseDiff = newBase - lowestMsgId; + + QList messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode); + if(messagesForNode.count() == 0) + { + QMessageBox::question(this, "No Messages", "The node has no messages to duplicate.", + QMessageBox::Ok); + return; + } + + if(ui->lineNodeName->text().isEmpty()) + { + QMessageBox::question(this, "No Name", "The new node needs a name before it can be created.", + QMessageBox::Ok); + return; + } + + QString newNodeName = ui->lineNodeName->text(); + emit createNode(newNodeName); + + DBC_NODE *nodePtr = dbcFile->findNodeByName(newNodeName); + + if(nodePtr == nullptr) + { + QMessageBox::question(this, "Node Invalid", "There was an problem identifying the selected node.", + QMessageBox::Ok); + return; + } + + for (int i=0; iID + rebaseDiff; + + if(newMsgId < 0 || newMsgId > 0x1FFFFFFFul) { - uint rebaseDiff = newBase - lowestMsgId; - - QList messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode); - if(messagesForNode.count() == 0) - { - return; - } - - if(ui->lineNodeName->text().isEmpty()) - { - //tell! - return; - } - - QString newNodeName = ui->lineNodeName->text(); - emit createNode(newNodeName); - - DBC_NODE *nodePtr = dbcFile->findNodeByName(newNodeName); - - if(nodePtr == nullptr) - { - //uhoh - return; - } - - for (int i=0; iID + rebaseDiff; - emit cloneMessageToNode(nodePtr, messagesForNode[i], newMsgId); - } - - dbcFile->setDirtyFlag(); - emit nodeAdded(); + QMessageBox::question(this, "Invalid Address Range", "The new starting address would cause a message to be outside of the valid address range.", + QMessageBox::Ok); + return; } - }); + } - connect(ui->btnCancel, &QPushButton::pressed, - [=]() + for (int i=0; iID + rebaseDiff; + emit cloneMessageToNode(nodePtr, messagesForNode[i], newMsgId); + } + dbcFile->setDirtyFlag(); + emit nodeAdded(); - }); + this->close(); + + }); + + connect(ui->btnCancel, &QPushButton::pressed, + [=]() + { + this->close(); + }); installEventFilter(this); } @@ -144,19 +174,20 @@ void DBCNodeDuplicateEditor::showEvent(QShowEvent* event) refreshView(); } -void DBCNodeDuplicateEditor::refreshView() +bool DBCNodeDuplicateEditor::refreshView() { + ui->lineNewBaseId->setText(""); + if(dbcNode) { QList messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode); + lowestMsgId = 0xFFFFFFFF; + if(messagesForNode.count() == 0) { - //?? - + return false; } - lowestMsgId = 0xFFFFFFFF; - for (int i=0; iID < lowestMsgId) @@ -165,7 +196,9 @@ void DBCNodeDuplicateEditor::refreshView() ui->lineOriginalBaseId->setText(Utility::formatCANID(lowestMsgId & 0x1FFFFFFFul)); ui->lineNodeName->setText(dbcNode->name + QString("_Copy")); + + return true; } - //generateSampleText(); + return false; } diff --git a/dbc/dbcnodeduplicateeditor.h b/dbc/dbcnodeduplicateeditor.h index 9a29a93..57610bd 100644 --- a/dbc/dbcnodeduplicateeditor.h +++ b/dbc/dbcnodeduplicateeditor.h @@ -19,7 +19,7 @@ public: void showEvent(QShowEvent*); void setNodeRef(DBC_NODE *node); void setFileIdx(int idx); - void refreshView(); + bool refreshView(); signals: void updatedTreeInfo(DBC_MESSAGE *msg); diff --git a/dbc/dbcnoderebaseeditor.cpp b/dbc/dbcnoderebaseeditor.cpp index 5a8f6bb..8ce105d 100644 --- a/dbc/dbcnoderebaseeditor.cpp +++ b/dbc/dbcnoderebaseeditor.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "helpwindow.h" #include "utility.h" @@ -18,60 +19,78 @@ DBCNodeRebaseEditor::DBCNodeRebaseEditor(QWidget *parent) : dbcHandler = DBCHandler::getReference(); dbcNode = nullptr; - connect(ui->btnDoRebase, &QPushButton::pressed, - [=]() + connect(ui->btnDoRebase, &QPushButton::pressed, + [=]() + { + if (dbcNode == nullptr) { - if (dbcNode == nullptr) return; - if (lowestMsgId > 0x1FFFFFFFul) return; + QMessageBox::question(this, "Node Invalid", "There was an problem identifying the selected node.", + QMessageBox::Ok); + return; + } - uint newBase = Utility::ParseStringToNum(ui->lineEdit->text()); + if (lowestMsgId > 0x1FFFFFFFul) + { + QMessageBox::question(this, "No Valid Messages", "The node has no valid messages to change.", + QMessageBox::Ok); + return; + } - if (newBase <= 0x1FFFFFFFul && newBase != lowestMsgId) + uint newBase = Utility::ParseStringToNum(ui->lineNewBaseId->text()); + + if(newBase <= 0 || newBase > 0x1FFFFFFFul) + { + QMessageBox::question(this, "Invalid Address", "The new address is outside of the valid range.", + QMessageBox::Ok); + return; + } + + if(newBase == lowestMsgId) + { + QMessageBox::question(this, "Invalid Address", "The new address is the same as the original.", + QMessageBox::Ok); + return; + } + + uint rebaseDiff = newBase - lowestMsgId; + + QList messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode); + if(messagesForNode.count() == 0) + { + QMessageBox::question(this, "No Messages", "The node has no messages to change.", + QMessageBox::Ok); + return; + } + + for (int i=0; iID + rebaseDiff; + + if(newMsgId < 0 || newMsgId > 0x1FFFFFFFul) { - uint rebaseDiff = newBase - lowestMsgId; - - QList messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode); - if(messagesForNode.count() == 0) - { - return; - } - - for (int i=0; iID += rebaseDiff; - emit updatedTreeInfo(messagesForNode[i]); - } - - dbcFile->setDirtyFlag(); + QMessageBox::question(this, "Invalid Address Range", "The new starting address would cause a message to be outside of the valid address range.", + QMessageBox::Ok); + return; } + } - - }); - - connect(ui->btnCancel, &QPushButton::pressed, - [=]() + for (int i=0; iID += rebaseDiff; + emit updatedTreeInfo(messagesForNode[i]); + } + dbcFile->setDirtyFlag(); - }); + this->close(); -// connect(ui->lineOriginalBaseId, &QLineEdit::editingFinished, -// [=]() -// { -// if (dbcNode == nullptr) return; -// if (dbcNode->comment != ui->lineComment->text()) dbcFile->setDirtyFlag(); -// dbcNode->comment = ui->lineComment->text(); -// emit updatedTreeInfo(dbcNode); -// }); + }); -// connect(ui->lineMsgName, &QLineEdit::editingFinished, -// [=]() -// { -// if (dbcNode == nullptr) return; -// if (dbcNode->name != ui->lineMsgName->text()) dbcFile->setDirtyFlag(); -// dbcNode->name = ui->lineMsgName->text(); -// emit updatedTreeInfo(dbcNode); -// }); + connect(ui->btnCancel, &QPushButton::pressed, + [=]() + { + this->close(); + }); installEventFilter(this); } @@ -146,19 +165,20 @@ void DBCNodeRebaseEditor::showEvent(QShowEvent* event) refreshView(); } -void DBCNodeRebaseEditor::refreshView() +bool DBCNodeRebaseEditor::refreshView() { + ui->lineNewBaseId->setText(""); + if(dbcNode) { QList messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode); + lowestMsgId = 0xFFFFFFFF; + if(messagesForNode.count() == 0) { - //?? - + return false; } - lowestMsgId = 0xFFFFFFFF; - for (int i=0; iID < lowestMsgId) @@ -167,7 +187,9 @@ void DBCNodeRebaseEditor::refreshView() ui->lineOriginalBaseId->setText(Utility::formatCANID(lowestMsgId & 0x1FFFFFFFul)); ui->lineNodeName->setText(dbcNode->name); + + return true; } - //generateSampleText(); + return false; } diff --git a/dbc/dbcnoderebaseeditor.h b/dbc/dbcnoderebaseeditor.h index 8e787f0..26f1645 100644 --- a/dbc/dbcnoderebaseeditor.h +++ b/dbc/dbcnoderebaseeditor.h @@ -19,7 +19,7 @@ public: void showEvent(QShowEvent*); void setNodeRef(DBC_NODE *node); void setFileIdx(int idx); - void refreshView(); + bool refreshView(); signals: void updatedTreeInfo(DBC_MESSAGE *msg); diff --git a/ui/dbcnodeduplicateeditor.ui b/ui/dbcnodeduplicateeditor.ui index a07c435..b236251 100644 --- a/ui/dbcnodeduplicateeditor.ui +++ b/ui/dbcnodeduplicateeditor.ui @@ -7,11 +7,17 @@ 0 0 314 - 193 + 144 + + + 0 + 0 + + - Dialog + Duplicate Node @@ -41,7 +47,14 @@ - + + + true + + + true + + diff --git a/ui/dbcnoderebaseeditor.ui b/ui/dbcnoderebaseeditor.ui index ddcfbe1..3c043cc 100644 --- a/ui/dbcnoderebaseeditor.ui +++ b/ui/dbcnoderebaseeditor.ui @@ -7,11 +7,17 @@ 0 0 303 - 159 + 148 + + + 0 + 0 + + - Dialog + Rebase All Node Messages @@ -31,7 +37,14 @@ - + + + true + + + true + + @@ -41,7 +54,14 @@ - + + + true + + + true + + @@ -51,7 +71,7 @@ - + From 04f4af1bf9f1eaa42e8a63c9c19f456c13f1b04d Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Sun, 9 Oct 2022 10:57:25 -0500 Subject: [PATCH 10/10] One lingering thing removed before PR --- dbc/dbcsignaleditor.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/dbc/dbcsignaleditor.cpp b/dbc/dbcsignaleditor.cpp index b4bd6a3..3788781 100644 --- a/dbc/dbcsignaleditor.cpp +++ b/dbc/dbcsignaleditor.cpp @@ -34,7 +34,6 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) : ui->comboType->addItem("SINGLE PRECISION"); ui->comboType->addItem("DOUBLE PRECISION"); ui->comboType->addItem("STRING"); - ui->comboType->addItem("ENUMERATED STRING"); ui->bitfield->setMode(GridMode::SIGNAL_VIEW);