mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-29 02:22:09 +08:00
cabana: load dbc from paste (#26098)
old-commit-hash: 12058c21c73c7777e260334827b30f4d24c8313d
This commit is contained in:
+1
-1
Submodule opendbc updated: dde0ff6f44...e37ef84f1a
@@ -1,5 +1,6 @@
|
||||
#include "tools/cabana/dbcmanager.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <QVector>
|
||||
|
||||
DBCManager::DBCManager(QObject *parent) : QObject(parent) {}
|
||||
@@ -16,6 +17,17 @@ void DBCManager::open(const QString &dbc_file_name) {
|
||||
emit DBCFileChanged();
|
||||
}
|
||||
|
||||
void DBCManager::open(const QString &name, const QString &content) {
|
||||
this->dbc_name = name;
|
||||
std::istringstream stream(content.toStdString());
|
||||
dbc = const_cast<DBC *>(dbc_parse_from_stream(name.toStdString(), stream));
|
||||
msg_map.clear();
|
||||
for (auto &msg : dbc->msgs) {
|
||||
msg_map[msg.address] = &msg;
|
||||
}
|
||||
emit DBCFileChanged();
|
||||
}
|
||||
|
||||
void save(const QString &dbc_file_name) {
|
||||
// TODO: save DBC to file
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ public:
|
||||
~DBCManager();
|
||||
|
||||
void open(const QString &dbc_file_name);
|
||||
void open(const QString &name, const QString &content);
|
||||
void save(const QString &dbc_file_name);
|
||||
|
||||
void addSignal(const QString &id, const Signal &sig);
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#include "tools/cabana/messageswidget.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QCompleter>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QFontDatabase>
|
||||
#include <QHeaderView>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QTextEdit>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "tools/cabana/dbcmanager.h"
|
||||
@@ -16,20 +17,23 @@ MessagesWidget::MessagesWidget(QWidget *parent) : QWidget(parent) {
|
||||
|
||||
// DBC file selector
|
||||
QHBoxLayout *dbc_file_layout = new QHBoxLayout();
|
||||
QComboBox *combo = new QComboBox(this);
|
||||
dbc_combo = new QComboBox(this);
|
||||
auto dbc_names = dbc()->allDBCNames();
|
||||
for (const auto &name : dbc_names) {
|
||||
combo->addItem(QString::fromStdString(name));
|
||||
dbc_combo->addItem(QString::fromStdString(name));
|
||||
}
|
||||
combo->model()->sort(0);
|
||||
combo->setEditable(true);
|
||||
combo->setCurrentText(QString());
|
||||
combo->setInsertPolicy(QComboBox::NoInsert);
|
||||
combo->completer()->setCompletionMode(QCompleter::PopupCompletion);
|
||||
dbc_combo->model()->sort(0);
|
||||
dbc_combo->setEditable(true);
|
||||
dbc_combo->setCurrentText(QString());
|
||||
dbc_combo->setInsertPolicy(QComboBox::NoInsert);
|
||||
dbc_combo->completer()->setCompletionMode(QCompleter::PopupCompletion);
|
||||
QFont font;
|
||||
font.setBold(true);
|
||||
combo->lineEdit()->setFont(font);
|
||||
dbc_file_layout->addWidget(combo);
|
||||
dbc_combo->lineEdit()->setFont(font);
|
||||
dbc_file_layout->addWidget(dbc_combo);
|
||||
|
||||
QPushButton *load_from_paste = new QPushButton(tr("Load from paste"), this);
|
||||
dbc_file_layout->addWidget(load_from_paste);
|
||||
|
||||
dbc_file_layout->addStretch();
|
||||
QPushButton *save_btn = new QPushButton(tr("Save DBC"), this);
|
||||
@@ -64,7 +68,8 @@ MessagesWidget::MessagesWidget(QWidget *parent) : QWidget(parent) {
|
||||
// signals/slots
|
||||
QObject::connect(filter, &QLineEdit::textChanged, proxy_model, &QSortFilterProxyModel::setFilterFixedString);
|
||||
QObject::connect(can, &CANMessages::updated, model, &MessageListModel::updateState);
|
||||
QObject::connect(combo, SIGNAL(activated(const QString &)), SLOT(dbcSelectionChanged(const QString &)));
|
||||
QObject::connect(dbc_combo, SIGNAL(activated(const QString &)), SLOT(dbcSelectionChanged(const QString &)));
|
||||
QObject::connect(load_from_paste, &QPushButton::clicked, this, &MessagesWidget::loadFromPaste);
|
||||
QObject::connect(save_btn, &QPushButton::clicked, [=]() {
|
||||
// TODO: save DBC to file
|
||||
});
|
||||
@@ -75,7 +80,7 @@ MessagesWidget::MessagesWidget(QWidget *parent) : QWidget(parent) {
|
||||
});
|
||||
|
||||
// For test purpose
|
||||
combo->setCurrentText("toyota_nodsu_pt_generated");
|
||||
dbc_combo->setCurrentText("toyota_nodsu_pt_generated");
|
||||
}
|
||||
|
||||
void MessagesWidget::dbcSelectionChanged(const QString &dbc_file) {
|
||||
@@ -84,6 +89,14 @@ void MessagesWidget::dbcSelectionChanged(const QString &dbc_file) {
|
||||
table_widget->sortByColumn(0, Qt::AscendingOrder);
|
||||
}
|
||||
|
||||
void MessagesWidget::loadFromPaste() {
|
||||
LoadDBCDialog dlg(this);
|
||||
if (dlg.exec()) {
|
||||
dbc()->open("from paste", dlg.dbc_edit->toPlainText());
|
||||
dbc_combo->setCurrentText("loaded from paste");
|
||||
}
|
||||
}
|
||||
|
||||
// MessageListModel
|
||||
|
||||
QVariant MessageListModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||
@@ -133,3 +146,17 @@ void MessageListModel::updateState() {
|
||||
emit dataChanged(index(0, 0), index(row_count - 1, 3), {Qt::DisplayRole});
|
||||
}
|
||||
}
|
||||
|
||||
LoadDBCDialog::LoadDBCDialog(QWidget *parent) : QDialog(parent) {
|
||||
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
||||
dbc_edit = new QTextEdit(this);
|
||||
dbc_edit->setAcceptRichText(false);
|
||||
dbc_edit->setPlaceholderText(tr("paste DBC file here"));
|
||||
main_layout->addWidget(dbc_edit);
|
||||
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
main_layout->addWidget(buttonBox);
|
||||
|
||||
setFixedWidth(640);
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QTableView>
|
||||
#include <QTextEdit>
|
||||
|
||||
#include "tools/cabana/canmessages.h"
|
||||
|
||||
class LoadDBCDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LoadDBCDialog(QWidget *parent);
|
||||
QTextEdit *dbc_edit;
|
||||
};
|
||||
|
||||
class MessageListModel : public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
|
||||
@@ -28,11 +39,13 @@ public:
|
||||
|
||||
public slots:
|
||||
void dbcSelectionChanged(const QString &dbc_file);
|
||||
void loadFromPaste();
|
||||
|
||||
signals:
|
||||
void msgSelectionChanged(const QString &message_id);
|
||||
|
||||
protected:
|
||||
QTableView *table_widget;
|
||||
QComboBox *dbc_combo;
|
||||
MessageListModel *model;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user