Add tracking of DBC editing in order to warn when exiting without saving, add sorting to DBC routines, add a new screen that allows one to compare two DBC files for changes/differences.

This commit is contained in:
Collin Kidder
2020-07-29 20:45:36 -04:00
parent 4cfb4b903a
commit a5b7410629
14 changed files with 738 additions and 13 deletions
+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);
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());
}
};
+48 -1
View File
@@ -92,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;
@@ -241,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;
@@ -266,6 +280,7 @@ DBCFile::DBCFile()
messageHandler = new DBCMessageHandler;
messageHandler->setMatchingCriteria(EXACT);
messageHandler->setFilterLabeling(false);
isDirty = false;
}
DBCFile::DBCFile(const DBCFile& cpy) : QObject()
@@ -283,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)
@@ -301,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;
@@ -380,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;
@@ -735,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;
@@ -761,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(" "))
@@ -998,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)
@@ -1214,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)
{
@@ -1405,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());
@@ -1681,6 +1727,7 @@ DBCFile* DBCHandler::loadJSONFile(QString filename)
}
}
}
thisFile->setDirtyFlag();
return thisFile;
}
+8
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
};
@@ -52,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;
@@ -79,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;
@@ -87,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);
+6 -2
View File
@@ -399,6 +399,7 @@ void DBCMainEditor::newNode()
itemToNode.insert(nodeItem, nodePtr);
ui->treeDBC->addTopLevelItem(nodeItem);
ui->treeDBC->setCurrentItem(nodeItem);
dbcFile->setDirtyFlag();
}
@@ -465,6 +466,7 @@ void DBCMainEditor::newMessage()
itemToMessage.insert(newMsgItem, msgPtr);
nodeItem->addChild(newMsgItem);
ui->treeDBC->setCurrentItem(newMsgItem);
dbcFile->setDirtyFlag();
}
void DBCMainEditor::newSignal()
@@ -519,7 +521,7 @@ void DBCMainEditor::newSignal()
itemToSignal.insert(newSigItem, sigPtr);
msgItem->addChild(newSigItem);
ui->treeDBC->setCurrentItem(newSigItem);
dbcFile->setDirtyFlag();
}
//gets confirmation before calling the real routines that delete things
@@ -628,6 +630,7 @@ void DBCMainEditor::deleteNode(DBC_NODE *node)
itemToNode.remove(currItem);
ui->treeDBC->removeItemWidget(currItem, 0);
delete currItem;
dbcFile->setDirtyFlag();
}
void DBCMainEditor::deleteMessage(DBC_MESSAGE *msg)
@@ -648,7 +651,7 @@ void DBCMainEditor::deleteMessage(DBC_MESSAGE *msg)
messageToItem.remove(msg);
ui->treeDBC->removeItemWidget(currItem, 0);
delete currItem;
dbcFile->setDirtyFlag();
}
void DBCMainEditor::deleteSignal(DBC_SIGNAL *sig)
@@ -662,4 +665,5 @@ void DBCMainEditor::deleteSignal(DBC_SIGNAL *sig)
signalToItem.remove(sig);
ui->treeDBC->removeItemWidget(currItem, 0);
delete currItem;
dbcFile->setDirtyFlag();
}
+6 -2
View File
@@ -22,6 +22,7 @@ DBCMessageEditor::DBCMessageEditor(QWidget *parent) :
[=]()
{
if (dbcMessage == nullptr) return;
if (dbcMessage->comment != ui->lineComment->text()) dbcFile->setDirtyFlag();
dbcMessage->comment = ui->lineComment->text();
emit updatedTreeInfo(dbcMessage);
});
@@ -30,6 +31,7 @@ DBCMessageEditor::DBCMessageEditor(QWidget *parent) :
[=]()
{
if (dbcMessage == nullptr) return;
if (dbcMessage->ID != Utility::ParseStringToNum(ui->lineFrameID->text())) dbcFile->setDirtyFlag();
dbcMessage->ID = Utility::ParseStringToNum(ui->lineFrameID->text());
emit updatedTreeInfo(dbcMessage);
});
@@ -38,6 +40,7 @@ DBCMessageEditor::DBCMessageEditor(QWidget *parent) :
[=]()
{
if (dbcMessage == nullptr) return;
if (dbcMessage->name != ui->lineMsgName->text().simplified().replace(' ', '_')) dbcFile->setDirtyFlag();
dbcMessage->name = ui->lineMsgName->text().simplified().replace(' ', '_');
emit updatedTreeInfo(dbcMessage);
});
@@ -46,6 +49,7 @@ DBCMessageEditor::DBCMessageEditor(QWidget *parent) :
[=]()
{
if (dbcMessage == nullptr) return;
if (dbcMessage->len != Utility::ParseStringToNum(ui->lineFrameLen->text())) dbcFile->setDirtyFlag();
dbcMessage->len = Utility::ParseStringToNum(ui->lineFrameLen->text());
});
@@ -53,7 +57,7 @@ DBCMessageEditor::DBCMessageEditor(QWidget *parent) :
[=]()
{
QColor newColor = QColorDialog::getColor(dbcMessage->fgColor);
if (dbcMessage->fgColor != newColor) dbcFile->setDirtyFlag();
dbcMessage->fgColor = newColor;
DBC_ATTRIBUTE_VALUE *val = dbcMessage->findAttrValByName("GenMsgForegroundColor");
if (val)
@@ -74,7 +78,7 @@ DBCMessageEditor::DBCMessageEditor(QWidget *parent) :
[=]()
{
QColor newColor = QColorDialog::getColor(dbcMessage->bgColor);
if (dbcMessage->bgColor != newColor) dbcFile->setDirtyFlag();
dbcMessage->bgColor = newColor;
DBC_ATTRIBUTE_VALUE *val = dbcMessage->findAttrValByName("GenMsgBackgroundColor");
if (val)
+2
View File
@@ -22,6 +22,7 @@ DBCNodeEditor::DBCNodeEditor(QWidget *parent) :
[=]()
{
if (dbcNode == nullptr) return;
if (dbcNode->comment != ui->lineComment->text()) dbcFile->setDirtyFlag();
dbcNode->comment = ui->lineComment->text();
emit updatedTreeInfo(dbcNode);
});
@@ -30,6 +31,7 @@ DBCNodeEditor::DBCNodeEditor(QWidget *parent) :
[=]()
{
if (dbcNode == nullptr) return;
if (dbcNode->name != ui->lineMsgName->text()) dbcFile->setDirtyFlag();
dbcNode->name = ui->lineMsgName->text();
emit updatedTreeInfo(dbcNode);
});
+33 -5
View File
@@ -44,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);
});
@@ -52,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,
[=]()
@@ -80,6 +83,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
currentSignal->valType = STRING;
break;
}
dbcFile->setDirtyFlag();
fillSignalForm(currentSignal);
});
connect(ui->txtBias, &QLineEdit::editingFinished,
@@ -89,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,
@@ -99,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,
@@ -109,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,
[=]()
@@ -118,12 +134,17 @@ 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);
});
@@ -132,6 +153,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
[=]()
{
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,
@@ -142,6 +164,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
temp = Utility::ParseStringToNum(ui->txtBitLength->text());
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);
@@ -151,6 +174,7 @@ 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 tree too.
emit updatedTreeInfo(currentSignal);
@@ -162,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;
});
@@ -175,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,
@@ -189,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,
@@ -200,6 +227,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
currentSignal->isMultiplexor = false;
if (dbcMessage->multiplexorSignal == currentSignal) dbcMessage->multiplexorSignal = nullptr;
}
dbcFile->setDirtyFlag();
});
installEventFilter(this);