Merge pull request #245 from collin80/WIP

Wip
This commit is contained in:
Collin Kidder
2020-09-30 18:42:57 -07:00
committed by GitHub
158 changed files with 10444 additions and 1909 deletions
+13 -13
View File
@@ -48,7 +48,7 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString, bool o
QString buildString;
int startByte = startBit / 8;
int bytes = signalSize / 8;
for (int x = 0; x < bytes; x++) buildString.append(frame.data[startByte + x]);
for (int x = 0; x < bytes; x++) buildString.append(frame.payload().data()[startByte + x]);
outString = buildString;
cachedValue = outString;
return true;
@@ -69,7 +69,7 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString, bool o
if (valType == SIGNED_INT) isSigned = true;
if (valType == SIGNED_INT || valType == UNSIGNED_INT)
{
result = Utility::processIntegerSignal(frame.data, startBit, signalSize, intelByteOrder, isSigned);
result = Utility::processIntegerSignal(frame.payload(), startBit, signalSize, intelByteOrder, isSigned);
endResult = ((double)result * factor) + bias;
result = (int64_t)endResult;
// if factor is an integer, we don't need the possibly human-unreadable float representation
@@ -82,19 +82,19 @@ bool DBC_SIGNAL::processAsText(const CANFrame &frame, QString &outString, bool o
//that the bytes that make up the integer are instead treated as having made up
//a 32 bit single precision float. That's evil incarnate but it is very fast and small
//in terms of new code.
result = Utility::processIntegerSignal(frame.data, startBit, 32, intelByteOrder, false);
result = Utility::processIntegerSignal(frame.payload(), startBit, 32, intelByteOrder, false);
endResult = (*((float *)(&result)) * factor) + bias;
}
else //double precision float
{
if ( frame.len < 8 )
if ( frame.payload().length() < 8 )
{
result = 0;
return false;
}
//like the above, this is rotten and evil and wrong in so many ways. Force
//calculation of a 64 bit integer and then cast it into a double.
result = Utility::processIntegerSignal(frame.data, 0, 64, intelByteOrder, false);
result = Utility::processIntegerSignal(frame.payload(), 0, 64, intelByteOrder, false);
endResult = (*((double *)(&result)) * factor) + bias;
}
@@ -158,13 +158,13 @@ bool DBC_SIGNAL::processAsInt(const CANFrame &frame, int32_t &outValue)
}
if (valType == SIGNED_INT) isSigned = true;
if ( static_cast<int>(frame.len * 8) < (startBit + signalSize) )
if ( static_cast<int>(frame.payload().length() * 8) < (startBit + signalSize) )
{
result = 0;
return false;
}
result = static_cast<int32_t>(Utility::processIntegerSignal(frame.data, startBit, signalSize, intelByteOrder, isSigned));
result = static_cast<int32_t>(Utility::processIntegerSignal(frame.payload(), startBit, signalSize, intelByteOrder, isSigned));
double endResult = (result * factor) + bias;
result = static_cast<int32_t>(endResult);
@@ -203,19 +203,19 @@ bool DBC_SIGNAL::processAsDouble(const CANFrame &frame, double &outValue)
if (valType == SIGNED_INT) isSigned = true;
if (valType == SIGNED_INT || valType == UNSIGNED_INT)
{
if ( frame.len*8 < (startBit+signalSize) )
if ( frame.payload().length() * 8 < (startBit+signalSize) )
{
result = 0;
return false;
}
result = Utility::processIntegerSignal(frame.data, startBit, signalSize, intelByteOrder, isSigned);
result = Utility::processIntegerSignal(frame.payload(), startBit, signalSize, intelByteOrder, isSigned);
endResult = ((double)result * factor) + bias;
result = (int64_t)endResult;
}
/*TODO: It should be noted that the below floating point has not even been tested. For shame! Test it!*/
else if (valType == SP_FLOAT)
{
if ( frame.len*8 < (startBit+32) )
if ( frame.payload().length() * 8 < (startBit + 32) )
{
result = 0;
return false;
@@ -225,19 +225,19 @@ bool DBC_SIGNAL::processAsDouble(const CANFrame &frame, double &outValue)
//that the bytes that make up the integer are instead treated as having made up
//a 32 bit single precision float. That's evil incarnate but it is very fast and small
//in terms of new code.
result = Utility::processIntegerSignal(frame.data, startBit, 32, false, false);
result = Utility::processIntegerSignal(frame.payload(), startBit, 32, false, false);
endResult = (*((float *)(&result)) * factor) + bias;
}
else //double precision float
{
if ( frame.len < 8 )
if ( frame.payload().length() < 8 )
{
result = 0;
return false;
}
//like the above, this is rotten and evil and wrong in so many ways. Force
//calculation of a 64 bit integer and then cast it into a double.
result = Utility::processIntegerSignal(frame.data, 0, 64, false, false);
result = Utility::processIntegerSignal(frame.payload(), 0, 64, false, false);
endResult = (*((double *)(&result)) * factor) + bias;
}
cachedValue = endResult;
+15
View File
@@ -74,6 +74,11 @@ public:
DBC_ATTRIBUTE_VALUE *findAttrValByName(QString name);
DBC_ATTRIBUTE_VALUE *findAttrValByIdx(int idx);
friend bool operator<(const DBC_NODE& l, const DBC_NODE& r)
{
return (l.name.toLower() < r.name.toLower());
}
};
class DBC_MESSAGE; //forward reference so that DBC_SIGNAL can compile before we get to real definition of DBC_MESSAGE
@@ -107,6 +112,11 @@ public: //TODO: this is sloppy. It shouldn't all be public!
QString makePrettyOutput(double floatVal, int64_t intVal, bool outputName = true, bool isInteger = false);
DBC_ATTRIBUTE_VALUE *findAttrValByName(QString name);
DBC_ATTRIBUTE_VALUE *findAttrValByIdx(int idx);
friend bool operator<(const DBC_SIGNAL& l, const DBC_SIGNAL& r)
{
return (l.name.toLower() < r.name.toLower());
}
};
class DBCSignalHandler; //forward declaration to keep from having to include dbchandler.h in this file and thus create a loop
@@ -129,6 +139,11 @@ public:
DBC_ATTRIBUTE_VALUE *findAttrValByName(QString name);
DBC_ATTRIBUTE_VALUE *findAttrValByIdx(int idx);
friend bool operator<(const DBC_MESSAGE& l, const DBC_MESSAGE& r)
{
return (l.name.toLower() < r.name.toLower());
}
};
+246 -10
View File
@@ -8,6 +8,9 @@
#include <QApplication>
#include <QPalette>
#include <QSettings>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>
#include "utility.h"
#include "connections/canconmanager.h"
@@ -43,9 +46,16 @@ bool DBCSignalHandler::addSignal(DBC_SIGNAL &sig)
bool DBCSignalHandler::removeSignal(DBC_SIGNAL *sig)
{
Q_UNUSED(sig);
//if (sigs.removeAll(*sig) > 0) return true;
return false;
qDebug() << "Total # of signals: " << getCount();
for (int i = 0; i < getCount(); i++)
{
if (sigs[i].name == sig->name)
{
sigs.removeAt(i);
qDebug() << "Removed signal at idx " << i;
}
}
return true;
}
bool DBCSignalHandler::removeSignal(int idx)
@@ -82,6 +92,11 @@ int DBCSignalHandler::getCount()
return sigs.count();
}
void DBCSignalHandler::sort()
{
std::sort(sigs.begin(), sigs.end());
}
DBC_MESSAGE* DBCMessageHandler::findMsgByID(uint32_t id)
{
if (messages.count() == 0) return nullptr;
@@ -148,6 +163,20 @@ DBC_MESSAGE* DBCMessageHandler::findMsgByName(QString name)
return nullptr;
}
//allow for finding a message just by part of the name
DBC_MESSAGE* DBCMessageHandler::findMsgByPartialName(QString name)
{
if (messages.count() == 0) return nullptr;
for (int i = 0; i < messages.count(); i++)
{
if (messages[i].name.contains(name, Qt::CaseInsensitive))
{
return &messages[i];
}
}
return nullptr;
}
bool DBCMessageHandler::addMessage(DBC_MESSAGE &msg)
{
messages.append(msg);
@@ -156,9 +185,16 @@ bool DBCMessageHandler::addMessage(DBC_MESSAGE &msg)
bool DBCMessageHandler::removeMessage(DBC_MESSAGE *msg)
{
Q_UNUSED(msg);
//if (messages.removeAll(*msg) > 0) return true;
return false;
qDebug() << "Total # of messages: " << getCount();
for (int i = 0; i < getCount(); i++)
{
if (messages[i].name == msg->name)
{
messages.removeAt(i);
qDebug() << "Removed message at idx " << i;
}
}
return true;
}
bool DBCMessageHandler::removeMessageByIndex(int idx)
@@ -210,6 +246,15 @@ int DBCMessageHandler::getCount()
return messages.count();
}
void DBCMessageHandler::sort()
{
std::sort(messages.begin(), messages.end());
for (int i = 0; i < messages.count(); i++)
{
messages[i].sigHandler->sort();
}
}
bool DBCMessageHandler::filterLabeling()
{
return filterLabelingEnabled;
@@ -235,6 +280,7 @@ DBCFile::DBCFile()
messageHandler = new DBCMessageHandler;
messageHandler->setMatchingCriteria(EXACT);
messageHandler->setFilterLabeling(false);
isDirty = false;
}
DBCFile::DBCFile(const DBCFile& cpy) : QObject()
@@ -252,6 +298,7 @@ DBCFile::DBCFile(const DBCFile& cpy) : QObject()
dbc_nodes.append(cpy.dbc_nodes);
dbc_attributes.clear();
dbc_attributes.append(cpy.dbc_attributes);
isDirty = cpy.isDirty;
}
DBCFile& DBCFile::operator=(const DBCFile& cpy)
@@ -270,6 +317,12 @@ DBCFile& DBCFile::operator=(const DBCFile& cpy)
return *this;
}
void DBCFile::sort()
{
std::sort(dbc_nodes.begin(), dbc_nodes.end()); //sort node names
messageHandler->sort(); //sort messages, each of which sorts its signals too
}
DBC_NODE* DBCFile::findNodeByIdx(int idx)
{
if (idx < 0) return nullptr;
@@ -349,6 +402,17 @@ void DBCFile::findAttributesByType(DBC_ATTRIBUTE_TYPE typ, QList<DBC_ATTRIBUTE>
}
}
//there's no external way to clear the flag. It is only cleared when the file is saved by this object.
void DBCFile::setDirtyFlag()
{
isDirty = true;
}
bool DBCFile::getDirtyFlag()
{
return isDirty;
}
DBC_MESSAGE* DBCFile::parseMessageLine(QString line)
{
QRegularExpression regex;
@@ -704,6 +768,7 @@ void DBCFile::loadFile(QString fileName)
DBC_MESSAGE *currentMessage = nullptr;
DBC_ATTRIBUTE attr;
int numSigFaults = 0, numMsgFaults = 0;
int linesSinceYield = 0;
bool inMultilineBU = false;
@@ -730,6 +795,12 @@ void DBCFile::loadFile(QString fileName)
rawLine = QString(inFile->readLine());
line = rawLine.simplified();
linesSinceYield++;
if (linesSinceYield > 100)
{
qApp->processEvents();
}
if (inMultilineBU)
{
if (rawLine.startsWith("\t") || rawLine.startsWith(" "))
@@ -967,6 +1038,7 @@ void DBCFile::loadFile(QString fileName)
this->fileName = fileList[fileList.length() - 1]; //whoops... same name as parameter in this function.
filePath = fileName.left(fileName.length() - this->fileName.length());
assocBuses = -1;
isDirty = false;
}
QVariant DBCFile::processAttributeVal(QString input, DBC_ATTRIBUTE_VAL_TYPE typ)
@@ -1183,7 +1255,10 @@ void DBCFile::saveFile(QString fileName)
msgNumber++;
}
msgOutput.append("BO_ " + QString::number(msg->ID) + " " + msg->name + ": " + QString::number(msg->len) +
uint32_t ID = msg->ID;
if (msg->ID > 0x7FF) 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");
if (msg->comment.length() > 0)
{
@@ -1374,6 +1449,8 @@ void DBCFile::saveFile(QString fileName)
outFile->close();
delete outFile;
isDirty = false;
QStringList fileList = fileName.split('/');
this->fileName = fileList[fileList.length() - 1]; //whoops... same name as parameter in this function.
filePath = fileName.left(fileName.length() - this->fileName.length());
@@ -1417,6 +1494,7 @@ int DBCHandler::createBlankFile()
//add our custom attributes to the new file so that we know they're already there.
attr.attrType = MESSAGE;
attr.defaultValue = QApplication::palette().color(QPalette::Base).name();
qDebug() << attr.defaultValue;
attr.enumVals.clear();
attr.lower = 0;
attr.upper = 0;
@@ -1426,6 +1504,7 @@ int DBCHandler::createBlankFile()
attr.attrType = MESSAGE;
attr.defaultValue = QApplication::palette().color(QPalette::WindowText).name();
qDebug() << attr.defaultValue;
attr.enumVals.clear();
attr.lower = 0;
attr.upper = 0;
@@ -1451,6 +1530,11 @@ int DBCHandler::createBlankFile()
attr.valType = QINT;
newFile.dbc_attributes.append(attr);
DBC_NODE falseNode;
falseNode.name = "Vector__XXX";
falseNode.comment = "Default node if none specified";
newFile.dbc_nodes.append(falseNode);
loadedFiles.append(newFile);
return loadedFiles.count();
}
@@ -1495,6 +1579,158 @@ DBCFile* DBCHandler::loadDBCFile(int idx)
return nullptr;
}
DBCFile* DBCHandler::loadJSONFile(QString filename)
{
QSettings settings;
DBCFile *thisFile;
DBC_MESSAGE *pMsg;
createBlankFile();
thisFile = &loadedFiles.last();
QFile *inFile = new QFile(filename);
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug() << "Could not open JSON file for reading.";
delete inFile;
return nullptr;
}
QByteArray wholeFileData = inFile->readAll();
inFile->close();
delete inFile;
//qDebug() << "Data Length: " << wholeFileData.length();
QJsonDocument jsonDoc = QJsonDocument::fromJson(wholeFileData);
if (jsonDoc.isNull())
{
qDebug() << "Couldn't load and parse the JSON file for some reason.";
return nullptr;
}
qDebug() << "Loaded JSON";
QJsonObject jsonObj = jsonDoc.object();
QJsonObject jsonMessages = jsonObj["messages"].toObject();
QJsonObject::iterator iter;
for (iter = jsonMessages.begin(); iter != jsonMessages.end(); iter++)
{
qDebug() << iter.key();
DBC_MESSAGE msg;
msg.ID = static_cast<uint32_t>(iter->toObject().find("message_id").value().toInt());
msg.name = QString(iter.key().toUtf8());
msg.len = static_cast<unsigned int>(iter->toObject().find("length_bytes").value().toInt());
msg.sender = thisFile->findNodeByIdx(0);
QString nodeName = iter->toObject().find("originNode").value().toString();
msg.sender = thisFile->findNodeByName(nodeName);
msg.bgColor = QColor(thisFile->findAttributeByName("GenMsgBackgroundColor")->defaultValue.toString());
msg.fgColor = QColor(thisFile->findAttributeByName("GenMsgForegroundColor")->defaultValue.toString());
if (!msg.sender && nodeName.length() > 1)
{
DBC_NODE node;
node.name = nodeName;
thisFile->dbc_nodes.append(node);
msg.sender = thisFile->findNodeByName(nodeName);
}
if (nodeName.length() < 2) msg.sender = thisFile->findNodeByIdx(0);
thisFile->messageHandler->addMessage(msg);
pMsg = thisFile->messageHandler->findMsgByID(msg.ID);
if (!pMsg)
{
qDebug() << "pMsg was null... I have no idea how that is possible. DEBUG ME";
return nullptr;
}
QJsonObject jsonSigs = iter->toObject().find("signals").value().toObject();
QJsonObject::iterator sigIter;
for (sigIter = jsonSigs.begin(); sigIter != jsonSigs.end(); sigIter++)
{
qDebug() << sigIter.key();
DBC_SIGNAL sig;
QJsonObject sigObj = sigIter->toObject();
if (sigObj.isEmpty())
{
qDebug() << "EMPTY!?";
}
sig.name = QString(sigIter.key().toUtf8());
sig.factor = sigObj.find("scale").value().toDouble();
sig.bias = sigObj.find("offset").value().toDouble();
sig.max = sigObj.find("max").value().toDouble();
sig.min = sigObj.find("min").value().toDouble();
sig.startBit = sigObj.find("start_position").value().toInt();
sig.unitName = sigObj.find("units").value().toString();
sig.signalSize = sigObj.find("width").value().toInt();
sig.isMultiplexed = false;
sig.isMultiplexor = false;
sig.parentMessage = pMsg;
if (!sigObj.find("mux_id")->isUndefined())
{
QJsonValue muxVal = sigObj.find("mux_id").value();
sig.multiplexValue = muxVal.toInt();
sig.isMultiplexed = true;
}
else
{
sig.multiplexValue = 0;
}
QJsonValue muxerVal = sigObj.find("is_muxer").value();
if (!muxerVal.isNull())
{
if (muxerVal.toBool())
{
sig.isMultiplexor = true;
}
}
QJsonObject valuesObj = sigObj.find("value_description")->toObject();
if (!valuesObj.isEmpty())
{
QJsonObject::iterator valIter;
for (valIter = valuesObj.begin(); valIter != valuesObj.end(); valIter++)
{
DBC_VAL_ENUM_ENTRY valEnum;
valEnum.value = valIter.value().toInt();
valEnum.descript = valIter.key().toUtf8();
sig.valList.append(valEnum);
}
}
QJsonArray rxArray = sigObj.find("receivers")->toArray();
if (rxArray.size() < 1) sig.receiver = thisFile->findNodeByIdx(0);
else
{
qDebug() << rxArray[0].toString();
sig.receiver = thisFile->findNodeByName(rxArray[0].toString());
if (!sig.receiver && rxArray[0].toString().length() > 1)
{
DBC_NODE node;
node.name = rxArray[0].toString();
thisFile->dbc_nodes.append(node);
sig.receiver = thisFile->findNodeByName(rxArray[0].toString());
}
if (!sig.receiver) sig.receiver = thisFile->findNodeByIdx(0);
}
if (!sigObj.find("endianness").value().toString().compare("BIG"))
{
sig.intelByteOrder = false;
}
else sig.intelByteOrder = true;
if (!sigObj.find("signedness").value().toString().compare("UNSIGNED"))
{
sig.valType = DBC_SIG_VAL_TYPE::UNSIGNED_INT;
}
else sig.valType = DBC_SIG_VAL_TYPE::SIGNED_INT;
pMsg->sigHandler->addSignal(sig);
if (sig.isMultiplexor) //if this signal was the multiplexor then store that info
{
DBC_SIGNAL *pSig = pMsg->sigHandler->findSignalByName(sig.name);
if (pSig) pMsg->multiplexorSignal = pSig;
}
}
}
thisFile->setDirtyFlag();
return thisFile;
}
void DBCHandler::removeDBCFile(int idx)
{
if (loadedFiles.count() == 0) return;
@@ -1516,7 +1752,7 @@ void DBCHandler::swapFiles(int pos1, int pos2)
if (pos2 < 0) return;
if (pos2 >= loadedFiles.count()) return;
loadedFiles.swap(pos1, pos2);
loadedFiles.swapItemsAt(pos1, pos2);
}
/*
@@ -1529,9 +1765,9 @@ DBC_MESSAGE* DBCHandler::findMessage(const CANFrame &frame)
{
for(int i = 0; i < loadedFiles.count(); i++)
{
if (loadedFiles[i].getAssocBus() == -1 || frame.bus == (unsigned int)loadedFiles[i].getAssocBus())
if (loadedFiles[i].getAssocBus() == -1 || frame.bus == loadedFiles[i].getAssocBus())
{
DBC_MESSAGE* msg = loadedFiles[i].messageHandler->findMsgByID(frame.ID);
DBC_MESSAGE* msg = loadedFiles[i].messageHandler->findMsgByID(frame.frameId());
if (msg != nullptr) return msg;
}
}
+10
View File
@@ -29,6 +29,8 @@ public:
bool removeSignal(QString name);
void removeAllSignals();
int getCount();
void sort();
private:
QList<DBC_SIGNAL> sigs; //signals is a reserved word or I'd have used that
};
@@ -40,6 +42,7 @@ public:
DBC_MESSAGE *findMsgByID(uint32_t id);
DBC_MESSAGE *findMsgByIdx(int idx);
DBC_MESSAGE *findMsgByName(QString name);
DBC_MESSAGE *findMsgByPartialName(QString name);
bool addMessage(DBC_MESSAGE &msg);
bool removeMessage(DBC_MESSAGE *msg);
bool removeMessageByIndex(int idx);
@@ -51,6 +54,8 @@ public:
void setMatchingCriteria(MatchingCriteria_t mc);
void setFilterLabeling( bool labelFiltering );
bool filterLabeling();
void sort();
private:
QList<DBC_MESSAGE> messages;
MatchingCriteria_t matchingCriteria;
@@ -78,6 +83,9 @@ public:
QString getPath();
int getAssocBus();
void setAssocBus(int bus);
void setDirtyFlag();
bool getDirtyFlag();
void sort();
DBCMessageHandler *messageHandler;
QList<DBC_NODE> dbc_nodes;
@@ -86,6 +94,7 @@ private:
QString fileName;
QString filePath;
int assocBuses; //-1 = all buses, 0 = first bus, 1 = second bus, etc.
bool isDirty; //has the file been modified?
bool parseAttribute(QString inpString, DBC_ATTRIBUTE &attr);
QVariant processAttributeVal(QString input, DBC_ATTRIBUTE_VAL_TYPE typ);
@@ -113,6 +122,7 @@ public:
DBCFile* getFileByIdx(int idx);
DBCFile* getFileByName(QString name);
int createBlankFile();
DBCFile* loadJSONFile(QString);
static DBCHandler *getReference();
private:
+41 -2
View File
@@ -1,6 +1,7 @@
#include "dbcloadsavewindow.h"
#include "ui_dbcloadsavewindow.h"
#include <QComboBox>
#include <QFileDialog>
#include <QMessageBox>
#include <qevent.h>
#include "helpwindow.h"
@@ -152,7 +153,38 @@ void DBCLoadSaveWindow::newFile()
void DBCLoadSaveWindow::loadFile()
{
DBCFile *file = dbcHandler->loadDBCFile(-1);
DBCFile *file = nullptr;
QString filename;
QFileDialog dialog;
QSettings settings;
QStringList filters;
filters.append(QString(tr("DBC File (*.dbc)")));
filters.append(QString(tr("Tesla JSON File (*.json)")));
dialog.setDirectory(settings.value("DBC/LoadSaveDirectory", dialog.directory().path()).toString());
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setNameFilters(filters);
dialog.setViewMode(QFileDialog::Detail);
if (dialog.exec() == QDialog::Accepted)
{
filename = dialog.selectedFiles()[0];
//right now there is only one file type that can be loaded here so just do it.
settings.setValue("DBC/LoadSaveDirectory", dialog.directory().path());
if (dialog.selectedNameFilter() == filters[0])
{
if (!filename.contains('.')) filename += ".dbc";
file = dbcHandler->loadDBCFile(filename);
}
if (dialog.selectedNameFilter() == filters[1])
{
if (!filename.contains('.')) filename += ".json";
file = dbcHandler->loadJSONFile(filename);
}
}
if(file) {
inhibitCellProcessing=true;
int idx = ui->tableFiles->rowCount();
@@ -184,6 +216,11 @@ void DBCLoadSaveWindow::loadFile()
}
}
void DBCLoadSaveWindow::loadJSON()
{
}
void DBCLoadSaveWindow::saveFile()
{
int idx = ui->tableFiles->currentRow();
@@ -247,6 +284,8 @@ void DBCLoadSaveWindow::editFile()
void DBCLoadSaveWindow::matchingCriteriaChanged(int index)
{
Q_UNUSED(index)
if (inhibitCellProcessing) return;
// We don't know which combobox changed, so we just update all of them
for (int row=0; row<ui->tableFiles->rowCount(); row++)
@@ -289,7 +328,7 @@ void DBCLoadSaveWindow::cellChanged(int row, int col)
{
DBCFile *file = dbcHandler->getFileByIdx(row);
int bus = ui->tableFiles->item(row, col)->text().toInt();
int numBuses = CANConManager::getInstance()->getNumBuses();
//int numBuses = CANConManager::getInstance()->getNumBuses();
if (bus > -2)
{
file->setAssocBus(bus);
+1
View File
@@ -21,6 +21,7 @@ public:
private slots:
void loadFile();
void loadJSON();
void saveFile();
void removeFile();
void moveUp();
+542 -410
View File
File diff suppressed because it is too large Load Diff
+41 -14
View File
@@ -3,8 +3,13 @@
#include <QDialog>
#include <QDebug>
#include <QIcon>
#include <QTreeWidget>
#include <QRandomGenerator>
#include "dbchandler.h"
#include "dbcsignaleditor.h"
#include "dbcmessageeditor.h"
#include "dbcnodeeditor.h"
#include "utility.h"
namespace Ui {
@@ -20,35 +25,57 @@ public:
~DBCMainEditor();
void setFileIdx(int idx);
public slots:
void updatedNode(DBC_NODE *node);
void updatedMessage(DBC_MESSAGE *msg);
void updatedSignal(DBC_SIGNAL *sig);
private slots:
void onCellChangedNode(int,int);
void onCellClickedNode(int, int);
void onCellClickedMessage(int, int);
void onCellChangedMessage(int,int);
void onCustomMenuNode(QPoint);
void onCustomMenuMessage(QPoint);
void deleteCurrentNode();
void deleteCurrentMessage();
void onTreeDoubleClicked(const QModelIndex &index);
void currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *prev);
void onCustomMenuTree(QPoint);
void deleteCurrentTreeItem();
void deleteNode(DBC_NODE *node);
void deleteMessage(DBC_MESSAGE *msg);
void deleteSignal(DBC_SIGNAL *sig);
void handleSearch();
void handleSearchForward();
void handleSearchBackward();
void newNode();
void newMessage();
void newSignal();
private:
Ui::DBCMainEditor *ui;
DBCHandler *dbcHandler;
const QVector<CANFrame> *referenceFrames;
DBCSignalEditor *sigEditor;
int currRow;
DBCMessageEditor *msgEditor;
DBCNodeEditor *nodeEditor;
DBCFile *dbcFile;
int fileIdx;
bool inhibitCellChanged;
QIcon nodeIcon;
QIcon messageIcon;
QIcon signalIcon;
QIcon multiplexorSignalIcon;
QIcon multiplexedSignalIcon;
QList<QTreeWidgetItem *> searchItems;
int searchItemPos;
//bidirectional mapping of QTreeWidget items back and forth to DBC objects
QMap<DBC_NODE*, QTreeWidgetItem *> nodeToItem;
QMap<DBC_MESSAGE*, QTreeWidgetItem *> messageToItem;
QMap<DBC_SIGNAL*, QTreeWidgetItem *> signalToItem;
QMap<QTreeWidgetItem*, DBC_NODE*> itemToNode;
QMap<QTreeWidgetItem*, DBC_MESSAGE*> itemToMessage;
QMap<QTreeWidgetItem*, DBC_SIGNAL*> itemToSignal;
QRandomGenerator randGen;
void refreshNodesTable();
void refreshMessagesTable(const DBC_NODE *node);
void showEvent(QShowEvent* event);
void closeEvent(QCloseEvent *event);
bool eventFilter(QObject *obj, QEvent *event);
void readSettings();
void writeSettings();
void insertBlankRow();
void refreshTree();
};
#endif // DBCMAINEDITOR_H
+266
View File
@@ -0,0 +1,266 @@
#include "dbcmessageeditor.h"
#include "ui_dbcmessageeditor.h"
#include <QSettings>
#include <QKeyEvent>
#include <QColorDialog>
#include "helpwindow.h"
#include "utility.h"
DBCMessageEditor::DBCMessageEditor(QWidget *parent) :
QDialog(parent),
ui(new Ui::DBCMessageEditor)
{
ui->setupUi(this);
readSettings();
dbcHandler = DBCHandler::getReference();
dbcMessage = nullptr;
suppressEditCallbacks = false;
connect(ui->lineComment, &QLineEdit::editingFinished,
[=]()
{
if (dbcMessage == nullptr) return;
if (suppressEditCallbacks) return;
if (dbcMessage->comment != ui->lineComment->text()) dbcFile->setDirtyFlag();
dbcMessage->comment = ui->lineComment->text();
emit updatedTreeInfo(dbcMessage);
});
connect(ui->lineFrameID, &QLineEdit::editingFinished,
[=]()
{
if (dbcMessage == nullptr) return;
if (suppressEditCallbacks) return;
if (dbcMessage->ID != Utility::ParseStringToNum(ui->lineFrameID->text())) dbcFile->setDirtyFlag();
dbcMessage->ID = Utility::ParseStringToNum(ui->lineFrameID->text());
emit updatedTreeInfo(dbcMessage);
});
connect(ui->lineMsgName, &QLineEdit::editingFinished,
[=]()
{
if (dbcMessage == nullptr) return;
if (suppressEditCallbacks) return;
if (dbcMessage->name != ui->lineMsgName->text().simplified().replace(' ', '_')) dbcFile->setDirtyFlag();
dbcMessage->name = ui->lineMsgName->text().simplified().replace(' ', '_');
emit updatedTreeInfo(dbcMessage);
});
connect(ui->lineFrameLen, &QLineEdit::editingFinished,
[=]()
{
if (dbcMessage == nullptr) return;
if (suppressEditCallbacks) return;
if (dbcMessage->len != Utility::ParseStringToNum(ui->lineFrameLen->text())) dbcFile->setDirtyFlag();
dbcMessage->len = Utility::ParseStringToNum(ui->lineFrameLen->text());
});
connect(ui->comboSender, &QComboBox::currentTextChanged,
[=](const QString newText)
{
if (dbcMessage == nullptr) return;
if (suppressEditCallbacks) return;
DBC_NODE *node = dbcFile->findNodeByName(newText);
if (!node) return;
if (node != dbcMessage->sender) dbcFile->setDirtyFlag();
dbcMessage->sender = node;
emit updatedTreeInfo(dbcMessage);
});
connect(ui->comboSender->lineEdit(), &QLineEdit::editingFinished,
[=]()
{
if (dbcMessage == nullptr) return;
if (suppressEditCallbacks) return;
QString newText = ui->comboSender->currentText();
DBC_NODE *node = dbcFile->findNodeByName(newText);
if (!node)
{
DBC_NODE newNode;
newNode.name = newText;
dbcFile->dbc_nodes.append(newNode);
node = dbcFile->findNodeByName(newText);
ui->comboSender->addItem(newText);
}
if (node != dbcMessage->sender) dbcFile->setDirtyFlag();
dbcMessage->sender = node;
emit updatedTreeInfo(dbcMessage);
});
connect(ui->btnTextColor, &QAbstractButton::clicked,
[=]()
{
if (suppressEditCallbacks) return;
QColor newColor = QColorDialog::getColor(dbcMessage->fgColor);
if (dbcMessage->fgColor != newColor) dbcFile->setDirtyFlag();
dbcMessage->fgColor = newColor;
DBC_ATTRIBUTE_VALUE *val = dbcMessage->findAttrValByName("GenMsgForegroundColor");
if (val)
{
val->value = newColor.name();
}
else
{
DBC_ATTRIBUTE_VALUE newVal;
newVal.attrName = "GenMsgForegroundColor";
newVal.value = newColor.name();
dbcMessage->attributes.append(newVal);
}
generateSampleText();
});
connect(ui->btnBackgroundColor, &QAbstractButton::clicked,
[=]()
{
if (suppressEditCallbacks) return;
QColor newColor = QColorDialog::getColor(dbcMessage->bgColor);
if (dbcMessage->bgColor != newColor) dbcFile->setDirtyFlag();
dbcMessage->bgColor = newColor;
DBC_ATTRIBUTE_VALUE *val = dbcMessage->findAttrValByName("GenMsgBackgroundColor");
if (val)
{
val->value = newColor.name();
}
else
{
DBC_ATTRIBUTE_VALUE newVal;
newVal.attrName = "GenMsgBackgroundColor";
newVal.value = newColor.name();
dbcMessage->attributes.append(newVal);
}
generateSampleText();
});
installEventFilter(this);
}
DBCMessageEditor::~DBCMessageEditor()
{
removeEventFilter(this);
delete ui;
}
void DBCMessageEditor::closeEvent(QCloseEvent *event)
{
Q_UNUSED(event);
writeSettings();
}
bool DBCMessageEditor::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::KeyRelease) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
switch (keyEvent->key())
{
case Qt::Key_F1:
HelpWindow::getRef()->showHelp("messageeditor.html");
break;
}
return true;
} else {
// standard event processing
return QObject::eventFilter(obj, event);
}
return false;
}
void DBCMessageEditor::setFileIdx(int idx)
{
if (idx < 0 || idx > dbcHandler->getFileCount() - 1) return;
dbcFile = dbcHandler->getFileByIdx(idx);
suppressEditCallbacks = true;
ui->comboSender->clear();
for (int x = 0; x < dbcFile->dbc_nodes.count(); x++)
{
ui->comboSender->addItem(dbcFile->dbc_nodes[x].name);
}
suppressEditCallbacks = false;
}
void DBCMessageEditor::readSettings()
{
QSettings settings;
if (settings.value("Main/SaveRestorePositions", false).toBool())
{
resize(settings.value("DBCMessageEditor/WindowSize", QSize(340, 400)).toSize());
move(settings.value("DBCMessageEditor/WindowPos", QPoint(100, 100)).toPoint());
}
}
void DBCMessageEditor::writeSettings()
{
QSettings settings;
if (settings.value("Main/SaveRestorePositions", false).toBool())
{
settings.setValue("DBCMessageEditor/WindowSize", size());
settings.setValue("DBCMessageEditor/WindowPos", pos());
}
}
void DBCMessageEditor::setMessageRef(DBC_MESSAGE *msg)
{
dbcMessage = msg;
}
void DBCMessageEditor::showEvent(QShowEvent* event)
{
QDialog::showEvent(event);
refreshView();
}
void DBCMessageEditor::refreshView()
{
suppressEditCallbacks = true;
ui->lineComment->setText(dbcMessage->comment);
ui->lineFrameID->setText(Utility::formatCANID(dbcMessage->ID));
ui->lineMsgName->setText(dbcMessage->name);
ui->lineFrameLen->setText(QString::number(dbcMessage->len));
for (int i = 0; i < ui->comboSender->count(); i++)
{
if (ui->comboSender->itemText(i) == dbcMessage->sender->name)
{
ui->comboSender->setCurrentIndex(i);
break;
}
}
suppressEditCallbacks = false;
generateSampleText();
}
void DBCMessageEditor::generateSampleText()
{
QBrush fg, bg;
if (dbcMessage->fgColor.isValid()) fg = QBrush(dbcMessage->fgColor);
else fg = QBrush(QColor(dbcFile->findAttributeByName("GenMsgForegroundColor")->defaultValue.toString()));
if (dbcMessage->bgColor.isValid()) bg = QBrush(dbcMessage->bgColor);
else bg = QBrush(QColor(dbcFile->findAttributeByName("GenMsgBackgroundColor")->defaultValue.toString()));
ui->listSample->clear();
QListWidgetItem *item = new QListWidgetItem("Test String");
item->setForeground(fg);
item->setBackground(bg);
ui->listSample->addItem(item);
item = new QListWidgetItem("0x20F TestMsg");
item->setForeground(fg);
item->setBackground(bg);
ui->listSample->addItem(item);
item = new QListWidgetItem("20 FF 10 A1 BB CC 4D");
item->setForeground(fg);
item->setBackground(bg);
ui->listSample->addItem(item);
item = new QListWidgetItem("1024.3434");
item->setForeground(fg);
item->setBackground(bg);
ui->listSample->addItem(item);
}
+42
View File
@@ -0,0 +1,42 @@
#ifndef DBCMESSAGEEDITOR_H
#define DBCMESSAGEEDITOR_H
#include <QDialog>
#include "dbc_classes.h"
#include "dbchandler.h"
namespace Ui {
class DBCMessageEditor;
}
class DBCMessageEditor : public QDialog
{
Q_OBJECT
public:
explicit DBCMessageEditor(QWidget *parent = nullptr);
~DBCMessageEditor();
void showEvent(QShowEvent*);
void setMessageRef(DBC_MESSAGE *msg);
void setFileIdx(int idx);
void refreshView();
signals:
void updatedTreeInfo(DBC_MESSAGE *msg);
private:
Ui::DBCMessageEditor *ui;
DBCHandler *dbcHandler;
DBC_MESSAGE *dbcMessage;
DBCFile *dbcFile;
bool suppressEditCallbacks;
void closeEvent(QCloseEvent *event);
bool eventFilter(QObject *obj, QEvent *event);
void readSettings();
void writeSettings();
void generateSampleText();
};
#endif // DBCMESSAGEEDITOR_H
+148
View File
@@ -0,0 +1,148 @@
#include "dbcnodeeditor.h"
#include "ui_dbcnodeeditor.h"
#include <QSettings>
#include <QKeyEvent>
#include <QColorDialog>
#include "helpwindow.h"
#include "utility.h"
DBCNodeEditor::DBCNodeEditor(QWidget *parent) :
QDialog(parent),
ui(new Ui::DBCNodeEditor)
{
ui->setupUi(this);
readSettings();
dbcHandler = DBCHandler::getReference();
dbcNode = nullptr;
connect(ui->lineComment, &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);
}
DBCNodeEditor::~DBCNodeEditor()
{
removeEventFilter(this);
delete ui;
}
void DBCNodeEditor::closeEvent(QCloseEvent *event)
{
Q_UNUSED(event);
writeSettings();
}
bool DBCNodeEditor::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::KeyRelease) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
switch (keyEvent->key())
{
case Qt::Key_F1:
HelpWindow::getRef()->showHelp("nodeeditor.html");
break;
}
return true;
} else {
// standard event processing
return QObject::eventFilter(obj, event);
}
return false;
}
void DBCNodeEditor::setFileIdx(int idx)
{
if (idx < 0 || idx > dbcHandler->getFileCount() - 1) return;
dbcFile = dbcHandler->getFileByIdx(idx);
}
void DBCNodeEditor::readSettings()
{
QSettings settings;
if (settings.value("Main/SaveRestorePositions", false).toBool())
{
resize(settings.value("DBCNodeEditor/WindowSize", QSize(312, 128)).toSize());
move(settings.value("DBCNodeEditor/WindowPos", QPoint(100, 100)).toPoint());
}
}
void DBCNodeEditor::writeSettings()
{
QSettings settings;
if (settings.value("Main/SaveRestorePositions", false).toBool())
{
settings.setValue("DBCNodeEditor/WindowSize", size());
settings.setValue("DBCNodeEditor/WindowPos", pos());
}
}
void DBCNodeEditor::setNodeRef(DBC_NODE *node)
{
dbcNode = node;
}
void DBCNodeEditor::showEvent(QShowEvent* event)
{
QDialog::showEvent(event);
refreshView();
}
void DBCNodeEditor::refreshView()
{
ui->lineComment->setText(dbcNode->comment);
ui->lineMsgName->setText(dbcNode->name);
//generateSampleText();
}
void DBCNodeEditor::generateSampleText()
{
/*
QBrush fg, bg;
if (dbcMessage->fgColor.isValid()) fg = QBrush(dbcMessage->fgColor);
else fg = QBrush(QColor(dbcFile->findAttributeByName("GenMsgForegroundColor")->defaultValue.toString()));
if (dbcMessage->bgColor.isValid()) bg = QBrush(dbcMessage->bgColor);
else bg = QBrush(QColor(dbcFile->findAttributeByName("GenMsgBackgroundColor")->defaultValue.toString()));
ui->listSample->clear();
QListWidgetItem *item = new QListWidgetItem("Test String");
item->setForeground(fg);
item->setBackground(bg);
ui->listSample->addItem(item);
item = new QListWidgetItem("0x20F TestMsg");
item->setForeground(fg);
item->setBackground(bg);
ui->listSample->addItem(item);
item = new QListWidgetItem("20 FF 10 A1 BB CC 4D");
item->setForeground(fg);
item->setBackground(bg);
ui->listSample->addItem(item);
item = new QListWidgetItem("1024.3434");
item->setForeground(fg);
item->setBackground(bg);
ui->listSample->addItem(item);
*/
}
+41
View File
@@ -0,0 +1,41 @@
#ifndef DBCNODEEDITOR_H
#define DBCNODEEDITOR_H
#include <QDialog>
#include "dbc_classes.h"
#include "dbchandler.h"
namespace Ui {
class DBCNodeEditor;
}
class DBCNodeEditor : public QDialog
{
Q_OBJECT
public:
explicit DBCNodeEditor(QWidget *parent = nullptr);
~DBCNodeEditor();
void showEvent(QShowEvent*);
void setNodeRef(DBC_NODE *node);
void setFileIdx(int idx);
void refreshView();
signals:
void updatedTreeInfo(DBC_NODE *node);
private:
Ui::DBCNodeEditor *ui;
DBCHandler *dbcHandler;
DBC_NODE *dbcNode;
DBCFile *dbcFile;
void closeEvent(QCloseEvent *event);
bool eventFilter(QObject *obj, QEvent *event);
void readSettings();
void writeSettings();
void generateSampleText();
};
#endif // DBCNODEEDITOR_H
+56 -144
View File
@@ -4,6 +4,7 @@
#include <QDebug>
#include <QMenu>
#include <QSettings>
#include <QRandomGenerator>
#include <qevent.h>
#include "helpwindow.h"
@@ -15,8 +16,6 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
readSettings();
qsrand(QDateTime::currentMSecsSinceEpoch());
dbcHandler = DBCHandler::getReference();
dbcMessage = nullptr;
currentSignal = nullptr;
@@ -35,10 +34,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
ui->comboType->addItem("DOUBLE PRECISION");
ui->comboType->addItem("STRING");
connect(ui->signalsList, SIGNAL(currentRowChanged(int)), this, SLOT(clickSignalList(int)));
connect(ui->bitfield, SIGNAL(gridClicked(int,int)), this, SLOT(bitfieldClicked(int,int)));
connect(ui->signalsList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onCustomMenuSignals(QPoint)));
ui->signalsList->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->valuesTable, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onCustomMenuValues(QPoint)));
ui->valuesTable->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->valuesTable, SIGNAL(cellChanged(int,int)), this, SLOT(onValuesCellChanged(int,int)));
@@ -48,6 +44,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
[=]()
{
if (currentSignal == nullptr) return;
if (currentSignal->intelByteOrder != ui->cbIntelFormat->isChecked()) dbcFile->setDirtyFlag();
currentSignal->intelByteOrder = ui->cbIntelFormat->isChecked();
fillSignalForm(currentSignal);
});
@@ -56,7 +53,9 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
[=]()
{
if (currentSignal == nullptr) return;
currentSignal->receiver = dbcFile->findNodeByName(ui->comboReceiver->currentText());
DBC_NODE *node = dbcFile->findNodeByName(ui->comboReceiver->currentText());
if (currentSignal->receiver != node) dbcFile->setDirtyFlag();
currentSignal->receiver = node;
});
connect(ui->comboType, &QComboBox::currentTextChanged,
[=]()
@@ -84,6 +83,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
currentSignal->valType = STRING;
break;
}
dbcFile->setDirtyFlag();
fillSignalForm(currentSignal);
});
connect(ui->txtBias, &QLineEdit::editingFinished,
@@ -93,7 +93,11 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
double temp;
bool result;
temp = ui->txtBias->text().toDouble(&result);
if (result) currentSignal->bias = temp;
if (result)
{
if (currentSignal->bias != temp) dbcFile->setDirtyFlag();
currentSignal->bias = temp;
}
});
connect(ui->txtMaxVal, &QLineEdit::editingFinished,
@@ -103,7 +107,11 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
double temp;
bool result;
temp = ui->txtMaxVal->text().toDouble(&result);
if (result) currentSignal->max = temp;
if (result)
{
if (currentSignal->max != temp) dbcFile->setDirtyFlag();
currentSignal->max = temp;
}
});
connect(ui->txtMinVal, &QLineEdit::editingFinished,
@@ -113,7 +121,11 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
double temp;
bool result;
temp = ui->txtMinVal->text().toDouble(&result);
if (result) currentSignal->min = temp;
if (result)
{
if (currentSignal->min != temp) dbcFile->setDirtyFlag();
currentSignal->min = temp;
}
});
connect(ui->txtScale, &QLineEdit::editingFinished,
[=]()
@@ -122,19 +134,26 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
double temp;
bool result;
temp = ui->txtScale->text().toDouble(&result);
if (result) currentSignal->factor = temp;
if (result)
{
if (currentSignal->factor != temp) dbcFile->setDirtyFlag();
currentSignal->factor = temp;
}
});
connect(ui->txtComment, &QLineEdit::editingFinished,
[=]()
{
if (currentSignal == nullptr) return;
if (currentSignal->comment != ui->txtComment->text().simplified().replace(' ','_')) dbcFile->setDirtyFlag();
currentSignal->comment = ui->txtComment->text().simplified().replace(' ', '_');
emit updatedTreeInfo(currentSignal);
});
connect(ui->txtUnitName, &QLineEdit::editingFinished,
[=]()
{
if (currentSignal == nullptr) return;
if (currentSignal->unitName != ui->txtUnitName->text().simplified().replace(' ','_')) dbcFile->setDirtyFlag();
currentSignal->unitName = ui->txtUnitName->text().simplified().replace(' ', '_');
});
connect(ui->txtBitLength, &QLineEdit::textChanged,
@@ -143,8 +162,9 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
if (currentSignal == nullptr) return;
int temp;
temp = Utility::ParseStringToNum(ui->txtBitLength->text());
if (temp < 0) return;
if (temp > 63) return;
if (temp < 1) return;
if (temp > 64) return;
if (currentSignal->signalSize != temp) dbcFile->setDirtyFlag();
if (currentSignal->valType != SP_FLOAT && currentSignal->valType != DP_FLOAT)
currentSignal->signalSize = temp;
fillSignalForm(currentSignal);
@@ -154,9 +174,10 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
{
if (currentSignal == nullptr) return;
QString tempNameStr = ui->txtName->text().simplified().replace(' ', '_');
if (currentSignal->name != tempNameStr) dbcFile->setDirtyFlag();
if (tempNameStr.length() > 0) currentSignal->name = tempNameStr;
//need to update the list too.
ui->signalsList->currentItem()->setText(currentSignal->name);
//need to update the tree too.
emit updatedTreeInfo(currentSignal);
});
connect(ui->txtMultiplexValue, &QLineEdit::editingFinished,
@@ -165,6 +186,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
if (currentSignal == nullptr) return;
int temp;
temp = Utility::ParseStringToNum(ui->txtMultiplexValue->text());
if (currentSignal->multiplexValue != temp) dbcFile->setDirtyFlag();
//TODO: could look up the multiplexor and ensure that the value is within a range that the multiplexor could return
currentSignal->multiplexValue = temp;
});
@@ -178,6 +200,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
//if the set multiplexor for the message was this signal then clear it
if (dbcMessage->multiplexorSignal == currentSignal) dbcMessage->multiplexorSignal = nullptr;
}
dbcFile->setDirtyFlag();
});
connect(ui->rbMultiplexor, &QRadioButton::toggled,
@@ -192,6 +215,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
//we just set that this is the multiplexor so update the message to show that as well.
dbcMessage->multiplexorSignal = currentSignal;
}
dbcFile->setDirtyFlag();
});
connect(ui->rbNotMulti, &QRadioButton::toggled,
@@ -203,6 +227,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
currentSignal->isMultiplexor = false;
if (dbcMessage->multiplexorSignal == currentSignal) dbcMessage->multiplexorSignal = nullptr;
}
dbcFile->setDirtyFlag();
});
installEventFilter(this);
@@ -229,9 +254,6 @@ bool DBCSignalEditor::eventFilter(QObject *obj, QEvent *event)
case Qt::Key_F1:
HelpWindow::getRef()->showHelp("signaleditor.html");
break;
case Qt::Key_F2:
cloneSignal();
break;
}
return true;
} else {
@@ -279,12 +301,24 @@ void DBCSignalEditor::setMessageRef(DBC_MESSAGE *msg)
dbcMessage = msg;
}
void DBCSignalEditor::setSignalRef(DBC_SIGNAL *sig)
{
currentSignal = sig;
}
void DBCSignalEditor::showEvent(QShowEvent* event)
{
QDialog::showEvent(event);
currentSignal = nullptr;
refreshSignalsList();
fillSignalForm(currentSignal);
fillValueTable(currentSignal);
}
void DBCSignalEditor::refreshView()
{
fillSignalForm(currentSignal);
fillValueTable(currentSignal);
}
void DBCSignalEditor::onValuesCellChanged(int row,int col)
@@ -318,21 +352,6 @@ void DBCSignalEditor::onValuesCellChanged(int row,int col)
}
}
void DBCSignalEditor::onCustomMenuSignals(QPoint point)
{
QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose);
menu->addAction(tr("Add a new signal"), this, SLOT(addNewSignal()));
if (ui->signalsList->currentRow() != -1)
{
menu->addAction(tr("Clone currently selected signal"), this, SLOT(cloneSignal()));
menu->addAction(tr("Delete currently selected signal"), this, SLOT(deleteCurrentSignal()));
}
menu->popup(ui->signalsList->mapToGlobal(point));
}
void DBCSignalEditor::onCustomMenuValues(QPoint point)
{
QMenu *menu = new QMenu(this);
@@ -343,86 +362,6 @@ void DBCSignalEditor::onCustomMenuValues(QPoint point)
menu->popup(ui->valuesTable->mapToGlobal(point));
}
void DBCSignalEditor::addNewSignal()
{
int num = qrand() % 70000;
QString newName = "SIGNAL" + QString::number(num);
DBC_SIGNAL newSig;
newSig.name = newName;
newSig.bias = 0.0;
newSig.factor = 1.0;
newSig.intelByteOrder = true;
newSig.max = 0.0;
newSig.min = 0.0;
newSig.receiver = dbcFile->findNodeByIdx(0);
newSig.signalSize = 1;
newSig.startBit = 0;
newSig.valType = UNSIGNED_INT;
newSig.isMultiplexed = false;
newSig.isMultiplexor = false;
newSig.multiplexValue = 0;
newSig.parentMessage = dbcMessage;
dbcMessage->sigHandler->addSignal(newSig);
/* add item at the end of the list and select it */
/* this will call clickSignalList */
ui->signalsList->addItem(newName);
ui->signalsList->setCurrentRow(ui->signalsList->count()-1);
}
void DBCSignalEditor::cloneSignal()
{
int num = qrand() % 100;
int idx = ui->signalsList->currentRow();
if (idx < 0) return;
DBC_SIGNAL *oldSig = dbcMessage->sigHandler->findSignalByIdx(idx);
if (!oldSig) return;
QString newName = oldSig->name + QString::number(num);
DBC_SIGNAL newSig;
newSig.name = newName;
newSig.bias = oldSig->bias;
newSig.factor = oldSig->factor;
newSig.intelByteOrder = oldSig->intelByteOrder;
newSig.max = oldSig->max;
newSig.min = oldSig->min;
newSig.receiver = oldSig->receiver;
newSig.signalSize = oldSig->signalSize;
newSig.startBit = oldSig->startBit;
newSig.valType = oldSig->valType;
newSig.valList.append(oldSig->valList);
newSig.isMultiplexed = oldSig->isMultiplexed;
newSig.isMultiplexor = oldSig->isMultiplexor; //maybe should force this false since you can't have two or more!
newSig.multiplexValue = oldSig->multiplexValue;
newSig.parentMessage = dbcMessage;
dbcMessage->sigHandler->addSignal(newSig);
/* add item at the end of the list */
ui->signalsList->addItem(newName);
//unlike adding a signal we don't want to select the new signal here.
//ui->signalsList->setCurrentRow(ui->signalsList->count()-1);
}
void DBCSignalEditor::deleteCurrentSignal()
{
int currIdx = ui->signalsList->currentRow();
//if(currIdx==ui->signalsList->count()-1)
//return;
if (currIdx > -1)
{
delete(ui->signalsList->item(currIdx));
dbcMessage->sigHandler->removeSignal(currIdx);
currentSignal = nullptr;
}
}
void DBCSignalEditor::deleteCurrentValue()
{
int currIdx = ui->valuesTable->currentRow();
@@ -433,25 +372,6 @@ void DBCSignalEditor::deleteCurrentValue()
}
}
void DBCSignalEditor::refreshSignalsList()
{
ui->signalsList->clear();
for (int x = 0; x < dbcMessage->sigHandler->getCount(); x++)
{
DBC_SIGNAL *sig = dbcMessage->sigHandler->findSignalByIdx(x);
ui->signalsList->addItem(sig->name);
}
if( ui->signalsList->count()>0 ) {
/* click first element */
ui->signalsList->setCurrentRow(0);
}
else
clickSignalList(-1);
}
/* fillSignalForm also handles group "enabled" state */
/* WARNING: fillSignalForm can be called recursively since it is in the listener of cbIntelFormat */
void DBCSignalEditor::fillSignalForm(DBC_SIGNAL *sig)
@@ -585,7 +505,7 @@ void DBCSignalEditor::fillValueTable(DBC_SIGNAL *sig)
for (int i = 0; i < sig->valList.count(); i++)
{
QTableWidgetItem *val = new QTableWidgetItem(Utility::formatNumber(sig->valList[i].value));
QTableWidgetItem *val = new QTableWidgetItem(Utility::formatNumber((uint64_t)sig->valList[i].value));
QTableWidgetItem *desc = new QTableWidgetItem(sig->valList[i].descript);
rowIdx = ui->valuesTable->rowCount();
ui->valuesTable->insertRow(rowIdx);
@@ -599,16 +519,6 @@ void DBCSignalEditor::fillValueTable(DBC_SIGNAL *sig)
inhibitCellChanged = false;
}
void DBCSignalEditor::clickSignalList(int row)
{
//qDebug() << ui->signalsList->item(row)->text();
DBC_SIGNAL *thisSig = (row<0) ? nullptr : dbcMessage->sigHandler->findSignalByName(ui->signalsList->item(row)->text());
currentSignal = thisSig;
fillSignalForm(thisSig);
fillValueTable(thisSig);
}
void DBCSignalEditor::bitfieldClicked(int x, int y)
{
int bit = (7 - x) + (y * 8);
@@ -644,6 +554,7 @@ void DBCSignalEditor::generateUsedBits()
{
int byt = y / 8;
usedBits[byt] |= 1 << (y % 8);
ui->bitfield->setUsedSignalNum(y, x);
}
}
else //big endian / motorola format
@@ -654,6 +565,7 @@ void DBCSignalEditor::generateUsedBits()
{
int byt = startBit / 8;
usedBits[byt] |= 1 << (startBit % 8);
ui->bitfield->setUsedSignalNum(startBit, x);
size--;
if ((startBit % 8) == 0) startBit += 15;
else startBit--;
+6 -7
View File
@@ -16,19 +16,19 @@ class DBCSignalEditor : public QDialog
public:
explicit DBCSignalEditor(QWidget *parent = 0);
void setMessageRef(DBC_MESSAGE *msg);
void showEvent(QShowEvent*);
void setFileIdx(int idx);
void setSignalRef(DBC_SIGNAL *sig);
void showEvent(QShowEvent*);
~DBCSignalEditor();
void refreshView();
signals:
void updatedTreeInfo(DBC_SIGNAL *sig);
private slots:
void clickSignalList(int);
void bitfieldClicked(int x, int y);
void onValuesCellChanged(int row,int col);
void onCustomMenuSignals(QPoint);
void onCustomMenuValues(QPoint);
void addNewSignal();
void cloneSignal();
void deleteCurrentSignal();
void deleteCurrentValue();
private:
@@ -39,7 +39,6 @@ private:
DBCFile *dbcFile;
bool inhibitCellChanged;
void refreshSignalsList();
void fillSignalForm(DBC_SIGNAL *sig);
void fillValueTable(DBC_SIGNAL *sig);
void generateUsedBits();