2026-09-18 16:22:20 +08:00
|
|
|
|
#include "mainwindow.h"
|
|
|
|
|
|
|
2026-10-14 17:15:46 +08:00
|
|
|
|
#include "agvmapviewwidget.h"
|
2026-09-18 16:22:20 +08:00
|
|
|
|
#include "audiostreammanager.h"
|
2026-10-16 09:39:44 +08:00
|
|
|
|
#include "cameracapabilities.h"
|
2026-09-18 16:22:20 +08:00
|
|
|
|
#include "robotclient.h"
|
2026-10-26 17:35:27 +08:00
|
|
|
|
#include "tcpjogcontroller.h"
|
2026-10-14 17:15:46 +08:00
|
|
|
|
#include "tcptoolstore.h"
|
2026-11-04 15:00:14 +08:00
|
|
|
|
#include "usercoordinatewidget.h"
|
2026-10-14 17:15:46 +08:00
|
|
|
|
#include "handeyemotionwidget.h"
|
|
|
|
|
|
#include "tactileheatmapwidget.h"
|
|
|
|
|
|
#include "jointfloweditor.h"
|
2026-09-18 16:22:20 +08:00
|
|
|
|
#include "rpcservicewidget.h"
|
|
|
|
|
|
#include "uiicons.h"
|
|
|
|
|
|
#include "urdfviewerwidget.h"
|
|
|
|
|
|
#include "ui_agvservicepage.h"
|
|
|
|
|
|
#include "ui_agvstatusdialog.h"
|
|
|
|
|
|
#include "ui_audioservicepage.h"
|
|
|
|
|
|
#include "ui_armservicepage.h"
|
|
|
|
|
|
#include "ui_cameraservicepage.h"
|
|
|
|
|
|
#include "ui_diagnosticspage.h"
|
|
|
|
|
|
#include "ui_quicserverpage.h"
|
|
|
|
|
|
#include "ui_systemservicepage.h"
|
|
|
|
|
|
|
2026-10-14 17:15:46 +08:00
|
|
|
|
#include <QDialogButtonBox>
|
2026-09-18 16:22:20 +08:00
|
|
|
|
#include <QAbstractItemView>
|
|
|
|
|
|
#include <QAbstractButton>
|
|
|
|
|
|
#include <QCheckBox>
|
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
|
#include <QCoreApplication>
|
2026-10-14 17:15:46 +08:00
|
|
|
|
#include <QCursor>
|
2026-09-18 16:22:20 +08:00
|
|
|
|
#include <QDir>
|
|
|
|
|
|
#include <QDialog>
|
|
|
|
|
|
#include <QDoubleSpinBox>
|
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
|
#include <QFile>
|
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
|
#include <QFrame>
|
2026-09-23 16:04:01 +08:00
|
|
|
|
#include <QFormLayout>
|
2026-09-18 16:22:20 +08:00
|
|
|
|
#include <QGraphicsDropShadowEffect>
|
|
|
|
|
|
#include <QGridLayout>
|
|
|
|
|
|
#include <QHeaderView>
|
2026-09-23 11:11:49 +08:00
|
|
|
|
#include <QHBoxLayout>
|
2026-10-14 17:15:46 +08:00
|
|
|
|
#include <QInputDialog>
|
2026-09-18 16:22:20 +08:00
|
|
|
|
#include <QLineEdit>
|
|
|
|
|
|
#include <QJsonArray>
|
|
|
|
|
|
#include <QJsonDocument>
|
|
|
|
|
|
#include <QJsonObject>
|
|
|
|
|
|
#include <QLabel>
|
2026-10-16 09:39:44 +08:00
|
|
|
|
#include "appmessagebox.h"
|
2026-09-18 16:22:20 +08:00
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
#include <QRegularExpression>
|
2026-10-14 17:15:46 +08:00
|
|
|
|
#include <QSettings>
|
2026-09-18 16:22:20 +08:00
|
|
|
|
#include <QSignalBlocker>
|
2026-10-14 17:15:46 +08:00
|
|
|
|
#include <QSettings>
|
2026-09-18 16:22:20 +08:00
|
|
|
|
#include <QSlider>
|
|
|
|
|
|
#include <QSpinBox>
|
2026-10-14 17:15:46 +08:00
|
|
|
|
#include <QStackedWidget>
|
2026-09-18 16:22:20 +08:00
|
|
|
|
#include <QSplitter>
|
|
|
|
|
|
#include <QStyledItemDelegate>
|
2026-09-23 16:04:01 +08:00
|
|
|
|
#include <QTabBar>
|
2026-09-18 16:22:20 +08:00
|
|
|
|
#include <QTabWidget>
|
|
|
|
|
|
#include <QTableWidget>
|
|
|
|
|
|
#include <QTextDocument>
|
|
|
|
|
|
#include <QTextEdit>
|
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
#include <QtMath>
|
2026-11-04 15:00:14 +08:00
|
|
|
|
#include <memory>
|
2026-09-18 16:22:20 +08:00
|
|
|
|
|
2026-10-14 17:15:46 +08:00
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2026-09-18 16:22:20 +08:00
|
|
|
|
namespace {
|
|
|
|
|
|
class FramelessToolDialog final : public QDialog
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
|
|
|
|
|
explicit FramelessToolDialog(QWidget *parent = nullptr)
|
2026-10-14 17:15:46 +08:00
|
|
|
|
: QDialog(parent, Qt::Tool | Qt::FramelessWindowHint)
|
2026-09-18 16:22:20 +08:00
|
|
|
|
{
|
|
|
|
|
|
setAttribute(Qt::WA_TranslucentBackground);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setDragHandle(QWidget *handle)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_dragHandle = handle;
|
|
|
|
|
|
if (!m_dragHandle)
|
|
|
|
|
|
return;
|
|
|
|
|
|
m_dragHandle->installEventFilter(this);
|
|
|
|
|
|
const QList<QWidget *> children = m_dragHandle->findChildren<QWidget *>();
|
|
|
|
|
|
for (QWidget *child : children) {
|
|
|
|
|
|
if (!qobject_cast<QAbstractButton *>(child))
|
|
|
|
|
|
child->installEventFilter(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
2026-10-14 17:15:46 +08:00
|
|
|
|
bool nativeEvent(const QByteArray &eventType, void *message, long *result) override
|
|
|
|
|
|
{
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
|
Q_UNUSED(eventType)
|
|
|
|
|
|
MSG *nativeMessage = static_cast<MSG *>(message);
|
|
|
|
|
|
if (nativeMessage && nativeMessage->message == WM_NCHITTEST && result
|
|
|
|
|
|
&& !isMaximized()) {
|
|
|
|
|
|
const QPoint position = mapFromGlobal(QCursor::pos());
|
|
|
|
|
|
const int border = 8;
|
|
|
|
|
|
const bool left = position.x() >= 0 && position.x() < border;
|
|
|
|
|
|
const bool right = position.x() < width() && position.x() >= width() - border;
|
|
|
|
|
|
const bool top = position.y() >= 0 && position.y() < border;
|
|
|
|
|
|
const bool bottom = position.y() < height() && position.y() >= height() - border;
|
|
|
|
|
|
if (top && left) { *result = HTTOPLEFT; return true; }
|
|
|
|
|
|
if (top && right) { *result = HTTOPRIGHT; return true; }
|
|
|
|
|
|
if (bottom && left) { *result = HTBOTTOMLEFT; return true; }
|
|
|
|
|
|
if (bottom && right) { *result = HTBOTTOMRIGHT; return true; }
|
|
|
|
|
|
if (left) { *result = HTLEFT; return true; }
|
|
|
|
|
|
if (right) { *result = HTRIGHT; return true; }
|
|
|
|
|
|
if (top) { *result = HTTOP; return true; }
|
|
|
|
|
|
if (bottom) { *result = HTBOTTOM; return true; }
|
|
|
|
|
|
}
|
|
|
|
|
|
#else
|
|
|
|
|
|
Q_UNUSED(eventType)
|
|
|
|
|
|
Q_UNUSED(message)
|
|
|
|
|
|
Q_UNUSED(result)
|
|
|
|
|
|
#endif
|
|
|
|
|
|
return QDialog::nativeEvent(eventType, message, result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-18 16:22:20 +08:00
|
|
|
|
bool eventFilter(QObject *watched, QEvent *event) override
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_dragHandle && event) {
|
|
|
|
|
|
if (event->type() == QEvent::MouseButtonPress) {
|
|
|
|
|
|
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
|
|
|
|
|
if (mouseEvent->button() == Qt::LeftButton) {
|
|
|
|
|
|
m_dragging = true;
|
|
|
|
|
|
m_dragOffset = mouseEvent->globalPos() - frameGeometry().topLeft();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (event->type() == QEvent::MouseMove && m_dragging) {
|
|
|
|
|
|
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
|
|
|
|
|
if (mouseEvent->buttons() & Qt::LeftButton) {
|
|
|
|
|
|
move(mouseEvent->globalPos() - m_dragOffset);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (event->type() == QEvent::MouseButtonRelease) {
|
|
|
|
|
|
m_dragging = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return QDialog::eventFilter(watched, event);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
QWidget *m_dragHandle = nullptr;
|
|
|
|
|
|
QPoint m_dragOffset;
|
|
|
|
|
|
bool m_dragging = false;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-10-14 17:15:46 +08:00
|
|
|
|
QString requestFlowNodeName(QWidget *parent, const QString &title,
|
|
|
|
|
|
const QString &initialValue, bool *accepted)
|
|
|
|
|
|
{
|
|
|
|
|
|
FramelessToolDialog dialog(parent);
|
|
|
|
|
|
dialog.setObjectName(QStringLiteral("jointFlowChildDialog"));
|
|
|
|
|
|
dialog.setModal(true);
|
|
|
|
|
|
dialog.setMinimumSize(420, 210);
|
|
|
|
|
|
dialog.resize(460, 230);
|
|
|
|
|
|
QVBoxLayout *outerLayout = new QVBoxLayout(&dialog);
|
|
|
|
|
|
outerLayout->setContentsMargins(12, 12, 12, 12);
|
|
|
|
|
|
outerLayout->setSpacing(0);
|
|
|
|
|
|
QFrame *surface = new QFrame(&dialog);
|
|
|
|
|
|
surface->setObjectName(QStringLiteral("jointFlowChildSurface"));
|
|
|
|
|
|
QVBoxLayout *surfaceLayout = new QVBoxLayout(surface);
|
|
|
|
|
|
surfaceLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
surfaceLayout->setSpacing(0);
|
|
|
|
|
|
QWidget *titleBar = new QWidget(surface);
|
|
|
|
|
|
titleBar->setObjectName(QStringLiteral("jointFlowChildTitleBar"));
|
|
|
|
|
|
titleBar->setFixedHeight(44);
|
|
|
|
|
|
QHBoxLayout *titleLayout = new QHBoxLayout(titleBar);
|
|
|
|
|
|
titleLayout->setContentsMargins(12, 0, 0, 0);
|
|
|
|
|
|
titleLayout->setSpacing(9);
|
|
|
|
|
|
QLabel *mark = new QLabel(QStringLiteral("C"), titleBar);
|
|
|
|
|
|
mark->setObjectName(QStringLiteral("jointFlowDialogMark"));
|
|
|
|
|
|
mark->setAlignment(Qt::AlignCenter);
|
|
|
|
|
|
mark->setFixedSize(24, 24);
|
|
|
|
|
|
QLabel *titleLabel = new QLabel(title, titleBar);
|
|
|
|
|
|
titleLabel->setObjectName(QStringLiteral("jointFlowDialogTitle"));
|
|
|
|
|
|
QPushButton *closeButton = new QPushButton(titleBar);
|
|
|
|
|
|
closeButton->setObjectName(QStringLiteral("jointFlowDialogCloseButton"));
|
|
|
|
|
|
closeButton->setFixedSize(46, 43);
|
|
|
|
|
|
closeButton->setIcon(UiIcons::icon(QStringLiteral(":/icons/x.svg"),
|
|
|
|
|
|
QColor(QStringLiteral("#4f5964")), QColor(QStringLiteral("#4f5964"))));
|
|
|
|
|
|
titleLayout->addWidget(mark);
|
|
|
|
|
|
titleLayout->addWidget(titleLabel);
|
|
|
|
|
|
titleLayout->addStretch(1);
|
|
|
|
|
|
titleLayout->addWidget(closeButton);
|
|
|
|
|
|
surfaceLayout->addWidget(titleBar);
|
|
|
|
|
|
QWidget *content = new QWidget(surface);
|
|
|
|
|
|
content->setObjectName(QStringLiteral("jointFlowChildContent"));
|
|
|
|
|
|
QVBoxLayout *contentLayout = new QVBoxLayout(content);
|
|
|
|
|
|
contentLayout->setContentsMargins(18, 16, 18, 16);
|
|
|
|
|
|
contentLayout->setSpacing(9);
|
|
|
|
|
|
QLabel *fieldLabel = new QLabel(
|
|
|
|
|
|
title.contains(QStringLiteral("点位组")) ? QStringLiteral("组名称")
|
|
|
|
|
|
: QStringLiteral("节点名称"),
|
|
|
|
|
|
content);
|
|
|
|
|
|
QLineEdit *nameEdit = new QLineEdit(initialValue, content);
|
|
|
|
|
|
QHBoxLayout *actions = new QHBoxLayout;
|
|
|
|
|
|
QPushButton *cancelButton = new QPushButton(QStringLiteral("取消"), content);
|
|
|
|
|
|
cancelButton->setObjectName(QStringLiteral("secondaryButton"));
|
|
|
|
|
|
QPushButton *okButton = new QPushButton(QStringLiteral("确定"), content);
|
|
|
|
|
|
okButton->setObjectName(QStringLiteral("primaryButton"));
|
|
|
|
|
|
actions->addStretch(1);
|
|
|
|
|
|
actions->addWidget(cancelButton);
|
|
|
|
|
|
actions->addWidget(okButton);
|
|
|
|
|
|
contentLayout->addWidget(fieldLabel);
|
|
|
|
|
|
contentLayout->addWidget(nameEdit);
|
|
|
|
|
|
contentLayout->addStretch(1);
|
|
|
|
|
|
contentLayout->addLayout(actions);
|
|
|
|
|
|
surfaceLayout->addWidget(content, 1);
|
|
|
|
|
|
outerLayout->addWidget(surface);
|
|
|
|
|
|
dialog.setDragHandle(titleBar);
|
|
|
|
|
|
QObject::connect(closeButton, &QPushButton::clicked, &dialog, &QDialog::reject);
|
|
|
|
|
|
QObject::connect(cancelButton, &QPushButton::clicked, &dialog, &QDialog::reject);
|
|
|
|
|
|
QObject::connect(okButton, &QPushButton::clicked, &dialog, &QDialog::accept);
|
|
|
|
|
|
QObject::connect(nameEdit, &QLineEdit::returnPressed, &dialog, &QDialog::accept);
|
|
|
|
|
|
QTimer::singleShot(0, nameEdit, [nameEdit]() {
|
|
|
|
|
|
nameEdit->setFocus();
|
|
|
|
|
|
nameEdit->setCursorPosition(nameEdit->text().size());
|
|
|
|
|
|
});
|
|
|
|
|
|
const bool ok = dialog.exec() == QDialog::Accepted;
|
|
|
|
|
|
if (accepted)
|
|
|
|
|
|
*accepted = ok;
|
|
|
|
|
|
return ok ? nameEdit->text().trimmed() : QString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-18 16:22:20 +08:00
|
|
|
|
class AccentRowDelegate final : public QStyledItemDelegate
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
|
|
|
|
|
explicit AccentRowDelegate(QObject *parent = nullptr)
|
|
|
|
|
|
: QStyledItemDelegate(parent)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
|
|
|
|
|
const QModelIndex &index) const override
|
|
|
|
|
|
{
|
|
|
|
|
|
QStyleOptionViewItem cleanOption(option);
|
|
|
|
|
|
cleanOption.state &= ~QStyle::State_HasFocus;
|
|
|
|
|
|
QStyledItemDelegate::paint(painter, cleanOption, index);
|
|
|
|
|
|
if ((option.state & QStyle::State_Selected) && index.column() == 0) {
|
|
|
|
|
|
painter->save();
|
|
|
|
|
|
painter->fillRect(QRect(option.rect.left(), option.rect.top(),
|
|
|
|
|
|
3, option.rect.height()),
|
|
|
|
|
|
QColor(QStringLiteral("#237ddd")));
|
|
|
|
|
|
painter->restore();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
QWidget *withRpcExplorer(QWidget *commonPage, RobotClient *client,
|
|
|
|
|
|
const QString &serviceName)
|
|
|
|
|
|
{
|
|
|
|
|
|
QTabWidget *tabs = new QTabWidget;
|
|
|
|
|
|
tabs->setObjectName(QStringLiteral("serviceTabs"));
|
|
|
|
|
|
tabs->setDocumentMode(true);
|
|
|
|
|
|
tabs->addTab(commonPage, QStringLiteral("常用操作"));
|
|
|
|
|
|
tabs->addTab(new RpcServiceWidget(serviceName, client), QStringLiteral("全部接口"));
|
|
|
|
|
|
return tabs;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget *MainWindow::createSystemPage()
|
|
|
|
|
|
{
|
|
|
|
|
|
QWidget *page = new QWidget;
|
|
|
|
|
|
Ui::SystemServicePage ui;
|
|
|
|
|
|
ui.setupUi(page);
|
|
|
|
|
|
|
|
|
|
|
|
m_cpuValue = ui.cpuValue;
|
|
|
|
|
|
m_memoryValue = ui.memoryValue;
|
|
|
|
|
|
m_diskValue = ui.diskValue;
|
|
|
|
|
|
m_deviceValue = ui.deviceValue;
|
|
|
|
|
|
m_systemNameValue = ui.systemNameValue;
|
|
|
|
|
|
m_systemVersionValue = ui.systemVersionValue;
|
|
|
|
|
|
m_systemOsValue = ui.systemOsValue;
|
|
|
|
|
|
m_systemTargetEdit = ui.systemTargetEdit;
|
|
|
|
|
|
m_systemRefreshButton = ui.systemRefreshButton;
|
|
|
|
|
|
m_systemStopButton = ui.systemStopButton;
|
|
|
|
|
|
|
2026-09-23 11:11:49 +08:00
|
|
|
|
QWidget *legacyConnectionPanel = m_connectButton->parentWidget();
|
|
|
|
|
|
QWidget *connectionState = m_connectionText->parentWidget();
|
|
|
|
|
|
auto *connectionPanel = new QFrame(page);
|
|
|
|
|
|
connectionPanel->setObjectName(QStringLiteral("systemConnectionPanel"));
|
|
|
|
|
|
auto *connectionPanelLayout = new QVBoxLayout(connectionPanel);
|
|
|
|
|
|
connectionPanelLayout->setContentsMargins(12, 10, 12, 10);
|
|
|
|
|
|
connectionPanelLayout->setSpacing(8);
|
|
|
|
|
|
|
|
|
|
|
|
auto *connectionStatusRow = new QHBoxLayout;
|
|
|
|
|
|
connectionStatusRow->addStretch(1);
|
|
|
|
|
|
connectionState->setParent(connectionPanel);
|
|
|
|
|
|
connectionState->setObjectName(QStringLiteral("systemConnectionState"));
|
|
|
|
|
|
connectionState->setProperty("connected", false);
|
|
|
|
|
|
m_connectionText->setStyleSheet(QString());
|
|
|
|
|
|
connectionStatusRow->addWidget(connectionState);
|
|
|
|
|
|
connectionPanelLayout->addLayout(connectionStatusRow);
|
|
|
|
|
|
|
|
|
|
|
|
auto *connectionControls = new QHBoxLayout;
|
|
|
|
|
|
connectionControls->setSpacing(8);
|
|
|
|
|
|
connectionControls->addStretch(1);
|
|
|
|
|
|
m_hostEdit->setParent(connectionPanel);
|
|
|
|
|
|
m_hostEdit->setFixedSize(280, 34);
|
|
|
|
|
|
connectionControls->addWidget(m_hostEdit, 0, Qt::AlignBottom);
|
|
|
|
|
|
m_portSpin->setParent(connectionPanel);
|
|
|
|
|
|
m_portSpin->setObjectName(QStringLiteral("systemConnectionPort"));
|
|
|
|
|
|
m_portSpin->setFixedSize(90, 34);
|
|
|
|
|
|
connectionControls->addWidget(m_portSpin, 0, Qt::AlignBottom);
|
|
|
|
|
|
|
|
|
|
|
|
auto *connectionActions = new QVBoxLayout;
|
|
|
|
|
|
connectionActions->setSpacing(4);
|
|
|
|
|
|
m_demoCheck->setParent(connectionPanel);
|
|
|
|
|
|
m_connectButton->setParent(connectionPanel);
|
|
|
|
|
|
m_connectButton->setObjectName(QStringLiteral("primaryButton"));
|
|
|
|
|
|
m_connectButton->setFixedSize(112, 34);
|
|
|
|
|
|
connectionActions->addWidget(m_demoCheck);
|
|
|
|
|
|
connectionActions->addWidget(m_connectButton);
|
|
|
|
|
|
connectionControls->addLayout(connectionActions);
|
|
|
|
|
|
connectionPanelLayout->addLayout(connectionControls);
|
|
|
|
|
|
|
|
|
|
|
|
if (legacyConnectionPanel)
|
|
|
|
|
|
legacyConnectionPanel->hide();
|
|
|
|
|
|
ui.pageLayout->insertWidget(0, connectionPanel);
|
|
|
|
|
|
|
2026-09-18 16:22:20 +08:00
|
|
|
|
m_systemRefreshButton->setIcon(style()->standardIcon(QStyle::SP_BrowserReload));
|
|
|
|
|
|
m_systemStopButton->setIcon(style()->standardIcon(QStyle::SP_MediaStop));
|
|
|
|
|
|
connect(m_systemRefreshButton, &QPushButton::clicked,
|
|
|
|
|
|
m_client, &RobotClient::requestSystemRefresh);
|
|
|
|
|
|
connect(m_systemStopButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->requestSystemStopAll(m_systemTargetEdit->text().trimmed());
|
|
|
|
|
|
});
|
|
|
|
|
|
m_serviceButtons << m_systemRefreshButton << m_systemStopButton;
|
|
|
|
|
|
return withRpcExplorer(page, m_client, QStringLiteral("cmvr.api.SystemService"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget *MainWindow::createArmPage()
|
|
|
|
|
|
{
|
|
|
|
|
|
QWidget *page = new QWidget;
|
|
|
|
|
|
Ui::ArmServicePage ui;
|
|
|
|
|
|
ui.setupUi(page);
|
|
|
|
|
|
|
|
|
|
|
|
m_armHeaderControls = new QWidget(this);
|
|
|
|
|
|
m_armHeaderControls->setObjectName(QStringLiteral("armHeaderControls"));
|
|
|
|
|
|
QHBoxLayout *armHeaderLayout = new QHBoxLayout(m_armHeaderControls);
|
|
|
|
|
|
armHeaderLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
armHeaderLayout->setSpacing(8);
|
|
|
|
|
|
ui.armDeviceLabel->hide();
|
|
|
|
|
|
ui.armIdEdit->setParent(m_armHeaderControls);
|
|
|
|
|
|
ui.armTelemetryButton->setParent(m_armHeaderControls);
|
|
|
|
|
|
m_armSideCombo = new QComboBox(m_armHeaderControls);
|
2026-09-23 11:11:49 +08:00
|
|
|
|
m_armSideCombo->setObjectName(QStringLiteral("armDeviceCombo"));
|
|
|
|
|
|
m_armSideCombo->setMinimumWidth(240);
|
|
|
|
|
|
m_armSideCombo->setToolTip(QStringLiteral("选择边缘端在线机械臂"));
|
|
|
|
|
|
ui.armIdEdit->hide();
|
2026-09-18 16:22:20 +08:00
|
|
|
|
ui.armTelemetryButton->setObjectName(QStringLiteral("armTelemetryStatus"));
|
|
|
|
|
|
ui.armTelemetryButton->setText(QStringLiteral("遥测 未启动"));
|
|
|
|
|
|
ui.armTelemetryButton->setIcon(UiIcons::icon(
|
|
|
|
|
|
QStringLiteral(":/icons/activity.svg"),
|
|
|
|
|
|
QColor(QStringLiteral("#62706b")), QColor(QStringLiteral("#177553")),
|
|
|
|
|
|
QColor(QStringLiteral("#9aa3ad")), 15));
|
|
|
|
|
|
ui.armTelemetryButton->setIconSize(QSize(15, 15));
|
|
|
|
|
|
ui.armTelemetryButton->setFixedWidth(136);
|
|
|
|
|
|
armHeaderLayout->addWidget(m_armSideCombo);
|
|
|
|
|
|
armHeaderLayout->addWidget(ui.armTelemetryButton);
|
|
|
|
|
|
m_armGlobalStopButton = new QPushButton(QStringLiteral("全局停止"), m_armHeaderControls);
|
|
|
|
|
|
m_armGlobalStopButton->setObjectName(QStringLiteral("dangerButton"));
|
|
|
|
|
|
m_armGlobalStopButton->setIcon(UiIcons::icon(
|
|
|
|
|
|
QStringLiteral(":/icons/octagon-x.svg"), Qt::white, Qt::white,
|
|
|
|
|
|
QColor(QStringLiteral("#f4dddd")), 16));
|
|
|
|
|
|
m_armGlobalStopButton->setIconSize(QSize(16, 16));
|
|
|
|
|
|
m_armGlobalStopButton->setFixedWidth(110);
|
|
|
|
|
|
m_armGlobalStopButton->setToolTip(QStringLiteral("调用 SystemService.stopAll"));
|
|
|
|
|
|
armHeaderLayout->addWidget(m_armGlobalStopButton);
|
|
|
|
|
|
if (m_headerLayout)
|
|
|
|
|
|
m_headerLayout->insertWidget(2, m_armHeaderControls);
|
|
|
|
|
|
ui.serviceHeader->hide();
|
|
|
|
|
|
|
|
|
|
|
|
const int modelTabIndex = ui.armTabs->indexOf(ui.urdfTab);
|
|
|
|
|
|
if (modelTabIndex >= 0) {
|
|
|
|
|
|
ui.armTabs->removeTab(modelTabIndex);
|
|
|
|
|
|
ui.armTabs->insertTab(0, ui.urdfTab, QStringLiteral("模型与控制"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
m_armIdEdit = ui.armIdEdit;
|
|
|
|
|
|
m_armTelemetryButton = ui.armTelemetryButton;
|
|
|
|
|
|
m_armDeviceSummary = ui.commandSubtitle;
|
|
|
|
|
|
m_servoStatusValue = ui.servoStatusValue;
|
|
|
|
|
|
m_faultStatusValue = ui.faultStatusValue;
|
|
|
|
|
|
m_velocitySpin = ui.velocitySpin;
|
|
|
|
|
|
m_accelerationSpin = ui.accelerationSpin;
|
2026-09-23 16:04:01 +08:00
|
|
|
|
ui.velocityLabel->setText(QStringLiteral("速度"));
|
|
|
|
|
|
ui.accelerationLabel->setText(QStringLiteral("加速度"));
|
|
|
|
|
|
m_velocitySpin->setToolTip(QStringLiteral("SpeedJ 关节点动的最大速度"));
|
|
|
|
|
|
m_accelerationSpin->setToolTip(QStringLiteral("SpeedJ 关节点动的最大加速度"));
|
|
|
|
|
|
|
|
|
|
|
|
QLabel *jointLimitsTitle = new QLabel(QStringLiteral("SpeedJ 关节限制"), ui.commandBody);
|
|
|
|
|
|
jointLimitsTitle->setObjectName(QStringLiteral("eyebrow"));
|
|
|
|
|
|
ui.motionForm->insertRow(0, jointLimitsTitle);
|
|
|
|
|
|
|
|
|
|
|
|
QLabel *cartesianLimitsTitle = new QLabel(
|
|
|
|
|
|
QStringLiteral("SpeedL 笛卡尔限制"), ui.commandBody);
|
|
|
|
|
|
cartesianLimitsTitle->setObjectName(QStringLiteral("eyebrow"));
|
|
|
|
|
|
ui.motionForm->insertRow(3, cartesianLimitsTitle);
|
|
|
|
|
|
m_cartesianVelocitySpin = new QDoubleSpinBox(ui.commandBody);
|
|
|
|
|
|
m_cartesianVelocitySpin->setRange(0.001, 5.0);
|
|
|
|
|
|
m_cartesianVelocitySpin->setDecimals(3);
|
|
|
|
|
|
m_cartesianVelocitySpin->setSingleStep(0.01);
|
|
|
|
|
|
m_cartesianVelocitySpin->setSuffix(QStringLiteral(" m/s"));
|
|
|
|
|
|
m_cartesianVelocitySpin->setToolTip(
|
|
|
|
|
|
QStringLiteral("SpeedL 平移点动的最大线速度;旋转点动按相同数值使用 rad/s"));
|
|
|
|
|
|
m_cartesianAccelerationSpin = new QDoubleSpinBox(ui.commandBody);
|
|
|
|
|
|
m_cartesianAccelerationSpin->setRange(0.001, 20.0);
|
|
|
|
|
|
m_cartesianAccelerationSpin->setDecimals(3);
|
|
|
|
|
|
m_cartesianAccelerationSpin->setSingleStep(0.01);
|
|
|
|
|
|
m_cartesianAccelerationSpin->setSuffix(QStringLiteral(" m/s²"));
|
|
|
|
|
|
m_cartesianAccelerationSpin->setToolTip(
|
|
|
|
|
|
QStringLiteral("SpeedL 使用的笛卡尔加速度限制"));
|
|
|
|
|
|
ui.motionForm->addRow(QStringLiteral("速度"), m_cartesianVelocitySpin);
|
|
|
|
|
|
ui.motionForm->addRow(QStringLiteral("加速度"), m_cartesianAccelerationSpin);
|
2026-09-18 16:22:20 +08:00
|
|
|
|
m_torqueOnButton = ui.torqueOnButton;
|
|
|
|
|
|
m_torqueOffButton = ui.torqueOffButton;
|
|
|
|
|
|
m_clearFaultButton = ui.clearFaultButton;
|
2026-10-29 11:46:39 +08:00
|
|
|
|
QPushButton *frameDiscoveryButton = new QPushButton(QStringLiteral("调用坐标系遍历"), ui.commandBody);
|
|
|
|
|
|
frameDiscoveryButton->setObjectName(QStringLiteral("armFrameDiscoveryButton"));
|
|
|
|
|
|
frameDiscoveryButton->setToolTip(QStringLiteral("调用 ListBaseFrame,触发服务端 frameGetChildren;不处理返回数据"));
|
|
|
|
|
|
ui.commandBodyLayout->insertWidget(
|
|
|
|
|
|
ui.commandBodyLayout->indexOf(m_clearFaultButton) + 1, frameDiscoveryButton);
|
|
|
|
|
|
connect(frameDiscoveryButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->requestArmFrameDiscovery(m_armIdEdit->text().trimmed());
|
|
|
|
|
|
});
|
2026-09-18 16:22:20 +08:00
|
|
|
|
m_zeroJointCombo = ui.zeroJointCombo;
|
|
|
|
|
|
m_calibrateZeroButton = ui.calibrateZeroButton;
|
|
|
|
|
|
m_stopButton = ui.stopButton;
|
|
|
|
|
|
m_motionTable = ui.motionTable;
|
|
|
|
|
|
m_sendMoveButton = ui.sendMoveButton;
|
|
|
|
|
|
m_jointTable = ui.jointTable;
|
|
|
|
|
|
m_urdfViewer = ui.urdfViewer;
|
|
|
|
|
|
m_teachModeButton = ui.teachModeButton;
|
|
|
|
|
|
m_teachRestoreButton = ui.teachRestoreButton;
|
|
|
|
|
|
m_teachSendButton = ui.teachSendButton;
|
|
|
|
|
|
m_teachSelectedLabel = ui.teachSelectedLabel;
|
|
|
|
|
|
m_teachPositionSpin = ui.teachPositionSpin;
|
|
|
|
|
|
m_teachJointTable = ui.teachJointTable;
|
2026-10-26 17:35:27 +08:00
|
|
|
|
m_trajectoryFileNameEdit = ui.trajectoryFileNameEdit;
|
|
|
|
|
|
m_enterTeachingButton = ui.enterTeachingButton;
|
|
|
|
|
|
m_startTrajectoryRecordingButton = ui.startTrajectoryRecordingButton;
|
|
|
|
|
|
m_completeTeachingButton = ui.completeTeachingButton;
|
|
|
|
|
|
m_stopTrajectoryRecordingButton = ui.stopTrajectoryRecordingButton;
|
|
|
|
|
|
m_exitTeachingButton = ui.exitTeachingButton;
|
|
|
|
|
|
m_deviceTeachingStateLabel = ui.deviceTeachingStateLabel;
|
2026-09-23 11:11:49 +08:00
|
|
|
|
ui.jointTitle->setText(QStringLiteral("关节实时状态"));
|
2026-09-18 16:22:20 +08:00
|
|
|
|
ui.jointTitle->setContentsMargins(16, 0, 0, 4);
|
2026-09-23 11:11:49 +08:00
|
|
|
|
ui.poseTitle->setText(QStringLiteral("末端实时位姿"));
|
2026-09-23 16:04:01 +08:00
|
|
|
|
ui.poseSubtitle->setObjectName(QStringLiteral("poseFrameBadge"));
|
|
|
|
|
|
ui.poseSubtitle->setAlignment(Qt::AlignCenter);
|
|
|
|
|
|
ui.poseValue->hide();
|
|
|
|
|
|
ui.updatedValue->hide();
|
|
|
|
|
|
|
2026-10-14 17:15:46 +08:00
|
|
|
|
QWidget *moveJPage = new QWidget;
|
|
|
|
|
|
moveJPage->setObjectName(QStringLiteral("jointFlowWorkspace"));
|
|
|
|
|
|
QVBoxLayout *moveJLayout = new QVBoxLayout(moveJPage);
|
|
|
|
|
|
moveJLayout->setContentsMargins(16, 14, 16, 16);
|
|
|
|
|
|
moveJLayout->setSpacing(12);
|
|
|
|
|
|
|
|
|
|
|
|
QFrame *groupPanel = new QFrame(moveJPage);
|
|
|
|
|
|
groupPanel->setObjectName(QStringLiteral("jointProgramGroupPanel"));
|
|
|
|
|
|
QHBoxLayout *groupLayout = new QHBoxLayout(groupPanel);
|
|
|
|
|
|
groupLayout->setContentsMargins(12, 8, 12, 8);
|
|
|
|
|
|
groupLayout->setSpacing(8);
|
|
|
|
|
|
QLabel *groupLabel = new QLabel(QStringLiteral("点位组"), groupPanel);
|
|
|
|
|
|
groupLabel->setObjectName(QStringLiteral("jointFlowSectionTitle"));
|
|
|
|
|
|
QLabel *groupHint = new QLabel(
|
|
|
|
|
|
QStringLiteral("每个组独立保存点位记录和执行流程"), groupPanel);
|
|
|
|
|
|
groupHint->setObjectName(QStringLiteral("jointFlowSectionSubtitle"));
|
|
|
|
|
|
m_jointProgramGroupCombo = new QComboBox(groupPanel);
|
|
|
|
|
|
m_jointProgramGroupCombo->setMinimumWidth(220);
|
|
|
|
|
|
m_jointProgramGroupCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
|
|
|
|
|
QPushButton *newGroupButton = new QPushButton(QStringLiteral("新建组"), groupPanel);
|
|
|
|
|
|
QPushButton *renameGroupButton = new QPushButton(QStringLiteral("重命名"), groupPanel);
|
|
|
|
|
|
newGroupButton->setObjectName(QStringLiteral("primaryButton"));
|
|
|
|
|
|
renameGroupButton->setObjectName(QStringLiteral("secondaryButton"));
|
|
|
|
|
|
groupLayout->addWidget(groupLabel);
|
|
|
|
|
|
groupLayout->addWidget(groupHint);
|
|
|
|
|
|
groupLayout->addStretch(1);
|
|
|
|
|
|
groupLayout->addWidget(m_jointProgramGroupCombo);
|
|
|
|
|
|
groupLayout->addWidget(newGroupButton);
|
|
|
|
|
|
groupLayout->addWidget(renameGroupButton);
|
|
|
|
|
|
moveJLayout->addWidget(groupPanel);
|
|
|
|
|
|
|
|
|
|
|
|
connect(m_jointProgramGroupCombo,
|
|
|
|
|
|
QOverload<int>::of(&QComboBox::currentIndexChanged),
|
|
|
|
|
|
this, [this](int index) { activateJointProgramGroup(index); });
|
|
|
|
|
|
connect(newGroupButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
bool ok = false;
|
|
|
|
|
|
const QString name = requestFlowNodeName(
|
|
|
|
|
|
m_jointFlowDialog, QStringLiteral("新建点位组"), QStringLiteral("新建组"), &ok);
|
|
|
|
|
|
if (!ok || name.isEmpty())
|
|
|
|
|
|
return;
|
|
|
|
|
|
for (const JointProgramGroup &group : m_jointProgramGroups) {
|
|
|
|
|
|
if (group.name.compare(name, Qt::CaseInsensitive) == 0) {
|
2026-10-16 09:39:44 +08:00
|
|
|
|
AppMessageBox::information(m_jointFlowDialog, QStringLiteral("新建点位组"),
|
2026-10-14 17:15:46 +08:00
|
|
|
|
QStringLiteral("已存在同名点位组。"));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
storeCurrentJointProgramGroup();
|
|
|
|
|
|
JointProgramGroup group;
|
|
|
|
|
|
group.name = name;
|
|
|
|
|
|
m_jointProgramGroups.append(group);
|
|
|
|
|
|
const int newIndex = m_jointProgramGroups.size() - 1;
|
|
|
|
|
|
m_updatingJointProgramGroup = true;
|
|
|
|
|
|
m_jointProgramGroupCombo->addItem(name);
|
|
|
|
|
|
m_jointProgramGroupCombo->setCurrentIndex(newIndex);
|
|
|
|
|
|
m_updatingJointProgramGroup = false;
|
|
|
|
|
|
activateJointProgramGroup(newIndex);
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(renameGroupButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
if (m_activeJointProgramGroup < 0
|
|
|
|
|
|
|| m_activeJointProgramGroup >= m_jointProgramGroups.size())
|
|
|
|
|
|
return;
|
|
|
|
|
|
const QString oldName = m_jointProgramGroups.at(m_activeJointProgramGroup).name;
|
|
|
|
|
|
bool ok = false;
|
|
|
|
|
|
const QString name = requestFlowNodeName(
|
|
|
|
|
|
m_jointFlowDialog, QStringLiteral("重命名点位组"), oldName, &ok);
|
|
|
|
|
|
if (!ok || name.isEmpty() || name == oldName)
|
|
|
|
|
|
return;
|
|
|
|
|
|
for (int i = 0; i < m_jointProgramGroups.size(); ++i) {
|
|
|
|
|
|
if (i != m_activeJointProgramGroup
|
|
|
|
|
|
&& m_jointProgramGroups.at(i).name.compare(name, Qt::CaseInsensitive) == 0) {
|
2026-10-16 09:39:44 +08:00
|
|
|
|
AppMessageBox::information(m_jointFlowDialog, QStringLiteral("重命名点位组"),
|
2026-10-14 17:15:46 +08:00
|
|
|
|
QStringLiteral("已存在同名点位组。"));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
m_jointProgramGroups[m_activeJointProgramGroup].name = name;
|
|
|
|
|
|
m_updatingJointProgramGroup = true;
|
|
|
|
|
|
m_jointProgramGroupCombo->setItemText(m_activeJointProgramGroup, name);
|
|
|
|
|
|
m_updatingJointProgramGroup = false;
|
|
|
|
|
|
saveJointPrograms();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
QFrame *pointPanel = new QFrame(moveJPage);
|
|
|
|
|
|
pointPanel->setObjectName(QStringLiteral("jointPointPanel"));
|
|
|
|
|
|
QVBoxLayout *pointLayout = new QVBoxLayout(pointPanel);
|
|
|
|
|
|
pointLayout->setContentsMargins(12, 10, 12, 10);
|
|
|
|
|
|
pointLayout->setSpacing(8);
|
|
|
|
|
|
QHBoxLayout *pointHeader = new QHBoxLayout;
|
|
|
|
|
|
QLabel *pointTitle = new QLabel(QStringLiteral("关节点位记录与循环"), pointPanel);
|
|
|
|
|
|
pointTitle->setObjectName(QStringLiteral("jointFlowSectionTitle"));
|
|
|
|
|
|
QLabel *pointSubtitle = new QLabel(
|
2026-10-20 16:49:27 +08:00
|
|
|
|
QStringLiteral("可记录单臂或多臂点位,也可组合已有点位,原记录保留"), pointPanel);
|
2026-10-14 17:15:46 +08:00
|
|
|
|
pointSubtitle->setObjectName(QStringLiteral("jointFlowSectionSubtitle"));
|
|
|
|
|
|
QVBoxLayout *pointHeading = new QVBoxLayout;
|
|
|
|
|
|
pointHeading->setSpacing(2);
|
|
|
|
|
|
pointHeading->addWidget(pointTitle);
|
|
|
|
|
|
pointHeading->addWidget(pointSubtitle);
|
|
|
|
|
|
m_jointPointNameEdit = new QLineEdit(pointPanel);
|
|
|
|
|
|
m_jointPointNameEdit->setPlaceholderText(QStringLiteral("动作名称,例如:抓取准备"));
|
|
|
|
|
|
m_jointPointNameEdit->setMinimumWidth(220);
|
|
|
|
|
|
m_recordJointPointButton = new QPushButton(QStringLiteral("记录当前角度"), pointPanel);
|
|
|
|
|
|
m_recordJointPointButton->setObjectName(QStringLiteral("primaryButton"));
|
|
|
|
|
|
pointHeader->addLayout(pointHeading);
|
|
|
|
|
|
pointHeader->addStretch(1);
|
|
|
|
|
|
pointHeader->addWidget(m_jointPointNameEdit);
|
|
|
|
|
|
pointHeader->addWidget(m_recordJointPointButton);
|
|
|
|
|
|
pointLayout->addLayout(pointHeader);
|
|
|
|
|
|
|
|
|
|
|
|
m_jointPointTable = new QTableWidget(0, 5, pointPanel);
|
|
|
|
|
|
m_jointPointTable->setObjectName(QStringLiteral("jointPointTable"));
|
|
|
|
|
|
m_jointPointTable->setAlternatingRowColors(true);
|
|
|
|
|
|
m_jointPointTable->setHorizontalHeaderLabels({
|
|
|
|
|
|
QStringLiteral("动作名称"), QStringLiteral("机械臂"), QStringLiteral("Device ID"),
|
|
|
|
|
|
QStringLiteral("关节数"), QStringLiteral("关节角度(rad)")});
|
|
|
|
|
|
m_jointPointTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
|
|
m_jointPointTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
|
|
|
|
m_jointPointTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
|
|
m_jointPointTable->verticalHeader()->setVisible(false);
|
|
|
|
|
|
m_jointPointTable->verticalHeader()->setDefaultSectionSize(28);
|
|
|
|
|
|
m_jointPointTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
|
|
|
|
|
m_jointPointTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
|
|
|
|
|
m_jointPointTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
|
|
|
|
|
|
m_jointPointTable->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
|
|
|
|
|
|
m_jointPointTable->horizontalHeader()->setSectionResizeMode(4, QHeaderView::Stretch);
|
|
|
|
|
|
m_jointPointTable->setMinimumHeight(132);
|
|
|
|
|
|
pointLayout->addWidget(m_jointPointTable);
|
|
|
|
|
|
m_jointPointDetailLabel = new QLabel(QStringLiteral("选择点位后查看详细关节角度"), pointPanel);
|
|
|
|
|
|
m_jointPointDetailLabel->setObjectName(QStringLiteral("mutedLabel"));
|
|
|
|
|
|
m_jointPointDetailLabel->setWordWrap(true);
|
|
|
|
|
|
m_jointPointDetailLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
|
|
|
|
|
pointLayout->addWidget(m_jointPointDetailLabel);
|
|
|
|
|
|
|
|
|
|
|
|
QHBoxLayout *pointActions = new QHBoxLayout;
|
|
|
|
|
|
m_runJointPointButton = new QPushButton(QStringLiteral("执行选中点位"), pointPanel);
|
|
|
|
|
|
m_deleteJointPointButton = new QPushButton(QStringLiteral("删除选中"), pointPanel);
|
|
|
|
|
|
m_runJointPointButton->setObjectName(QStringLiteral("primaryButton"));
|
|
|
|
|
|
m_deleteJointPointButton->setObjectName(QStringLiteral("dangerOutlineButton"));
|
|
|
|
|
|
QLabel *loopCountLabel = new QLabel(QStringLiteral("循环次数"), pointPanel);
|
|
|
|
|
|
m_jointPointLoopCount = new QSpinBox(pointPanel);
|
|
|
|
|
|
m_jointPointLoopCount->setRange(1, 10000);
|
|
|
|
|
|
m_jointPointLoopCount->setValue(1);
|
|
|
|
|
|
m_startJointPointLoopButton = new QPushButton(QStringLiteral("执行自定义流程"), pointPanel);
|
|
|
|
|
|
m_stopJointPointLoopButton = new QPushButton(QStringLiteral("停止循环"), pointPanel);
|
|
|
|
|
|
m_stopJointPointLoopButton->setEnabled(false);
|
|
|
|
|
|
m_jointPointLoopStatus = new QLabel(QStringLiteral("未运行"), pointPanel);
|
|
|
|
|
|
m_jointPointLoopStatus->setObjectName(QStringLiteral("mutedLabel"));
|
|
|
|
|
|
pointActions->addWidget(m_runJointPointButton);
|
|
|
|
|
|
pointActions->addWidget(m_deleteJointPointButton);
|
2026-10-20 16:49:27 +08:00
|
|
|
|
auto *combineButton=new QPushButton(QStringLiteral("组合选中点位"),pointPanel);
|
|
|
|
|
|
combineButton->setToolTip(QStringLiteral("填写新名称,选择不同机械臂的已有点位,生成组合点位;保留原点位"));
|
|
|
|
|
|
pointActions->addWidget(combineButton);
|
|
|
|
|
|
connect(combineButton,&QPushButton::clicked,this,&MainWindow::combineSelectedJointPoints);
|
2026-10-14 17:15:46 +08:00
|
|
|
|
pointActions->addStretch(1);
|
|
|
|
|
|
pointActions->addWidget(m_jointPointLoopStatus);
|
|
|
|
|
|
pointLayout->addLayout(pointActions);
|
|
|
|
|
|
connect(m_recordJointPointButton, &QPushButton::clicked,
|
|
|
|
|
|
this, &MainWindow::recordCurrentJointPoint);
|
|
|
|
|
|
connect(m_runJointPointButton, &QPushButton::clicked,
|
|
|
|
|
|
this, &MainWindow::executeSelectedJointPoint);
|
|
|
|
|
|
connect(m_startJointPointLoopButton, &QPushButton::clicked,
|
|
|
|
|
|
this, &MainWindow::startJointPointLoop);
|
|
|
|
|
|
connect(m_stopJointPointLoopButton, &QPushButton::clicked, this, [this]() {
|
2026-10-20 16:49:27 +08:00
|
|
|
|
stopJointPointMotion();
|
2026-10-14 17:15:46 +08:00
|
|
|
|
stopJointPointLoop(QStringLiteral("用户停止"));
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_deleteJointPointButton, &QPushButton::clicked, this, [this]() {
|
2026-10-20 16:49:27 +08:00
|
|
|
|
if (m_jointPointLoopActive || m_jointPointMovePending || m_jointPointCapturePending)
|
2026-10-14 17:15:46 +08:00
|
|
|
|
return;
|
|
|
|
|
|
QList<int> rows;
|
|
|
|
|
|
for (const QModelIndex &index : m_jointPointTable->selectionModel()->selectedRows())
|
|
|
|
|
|
rows.append(index.row());
|
|
|
|
|
|
std::sort(rows.begin(), rows.end(), std::greater<int>());
|
|
|
|
|
|
QStringList removedNames;
|
|
|
|
|
|
for (int row : rows) {
|
|
|
|
|
|
if (row >= 0 && row < m_recordedJointPoints.size()) {
|
|
|
|
|
|
removedNames.append(m_recordedJointPoints.at(row).name);
|
|
|
|
|
|
m_recordedJointPoints.removeAt(row);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_jointFlowEditor)
|
|
|
|
|
|
m_jointFlowEditor->removePointReferences(removedNames);
|
|
|
|
|
|
refreshRecordedJointPoints();
|
|
|
|
|
|
refreshJointFlowTable();
|
|
|
|
|
|
saveJointPrograms();
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_jointPointTable, &QTableWidget::cellClicked, this,
|
|
|
|
|
|
[this](int row, int) {
|
|
|
|
|
|
if (row < 0 || row >= m_recordedJointPoints.size())
|
|
|
|
|
|
return;
|
|
|
|
|
|
const RecordedJointPoint &point = m_recordedJointPoints.at(row);
|
|
|
|
|
|
QStringList details;
|
2026-10-20 16:49:27 +08:00
|
|
|
|
for (const auto &t : point.targets()) {
|
|
|
|
|
|
QStringList angles;
|
|
|
|
|
|
for (int i=0;i<t.jointNames.size() && i<t.positions.size();++i)
|
|
|
|
|
|
angles.append(QStringLiteral("%1 = %2 rad").arg(t.jointNames[i]).arg(t.positions[i],0,'f',6));
|
|
|
|
|
|
details.append(t.deviceId+QStringLiteral(": ")+angles.join(" "));
|
2026-10-14 17:15:46 +08:00
|
|
|
|
}
|
2026-10-20 16:49:27 +08:00
|
|
|
|
m_jointPointDetailLabel->setText(point.name+"\n"+details.join("\n"));
|
2026-10-14 17:15:46 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
QFrame *flowPanel = new QFrame(moveJPage);
|
|
|
|
|
|
flowPanel->setObjectName(QStringLiteral("jointFlowPanel"));
|
|
|
|
|
|
QVBoxLayout *flowLayout = new QVBoxLayout(flowPanel);
|
|
|
|
|
|
flowLayout->setContentsMargins(12, 10, 12, 10);
|
|
|
|
|
|
flowLayout->setSpacing(8);
|
|
|
|
|
|
QLabel *flowTitle = new QLabel(QStringLiteral("自定义执行流程"), flowPanel);
|
|
|
|
|
|
flowTitle->setObjectName(QStringLiteral("jointFlowSectionTitle"));
|
|
|
|
|
|
QLabel *flowSubtitle = new QLabel(
|
|
|
|
|
|
QStringLiteral("选中节点后可在其后插入,拖动可调整同级执行顺序"), flowPanel);
|
|
|
|
|
|
flowSubtitle->setObjectName(QStringLiteral("jointFlowSectionSubtitle"));
|
|
|
|
|
|
QLabel *intervalLabel = new QLabel(QStringLiteral("完成后等待"), flowPanel);
|
|
|
|
|
|
m_jointPointInterval = new QDoubleSpinBox(flowPanel);
|
|
|
|
|
|
m_jointPointInterval->setRange(0.0, 3600.0);
|
|
|
|
|
|
m_jointPointInterval->setDecimals(1);
|
|
|
|
|
|
m_jointPointInterval->setValue(1.0);
|
|
|
|
|
|
m_jointPointInterval->setSuffix(QStringLiteral(" s"));
|
|
|
|
|
|
m_jointFlowGroupCount = new QSpinBox(flowPanel);
|
|
|
|
|
|
m_jointFlowGroupCount->setRange(1, 10000);
|
|
|
|
|
|
m_jointFlowGroupCount->setValue(2);
|
|
|
|
|
|
QLabel *insertionContextLabel = new QLabel(QStringLiteral("添加到:根流程(末尾)"), flowPanel);
|
|
|
|
|
|
insertionContextLabel->setObjectName(QStringLiteral("jointFlowContextChip"));
|
|
|
|
|
|
QPushButton *insertAtRootButton = new QPushButton(
|
|
|
|
|
|
QStringLiteral("切换到根流程末尾"), flowPanel);
|
|
|
|
|
|
QPushButton *enterSelectedLoopButton = new QPushButton(
|
|
|
|
|
|
QStringLiteral("添加到选中循环"), flowPanel);
|
|
|
|
|
|
QPushButton *addFlowStepButton = new QPushButton(QStringLiteral("+ 单步节点"), flowPanel);
|
|
|
|
|
|
QPushButton *addFlowLoopButton = new QPushButton(QStringLiteral("+ 循环节点"), flowPanel);
|
|
|
|
|
|
insertAtRootButton->setObjectName(QStringLiteral("secondaryButton"));
|
|
|
|
|
|
enterSelectedLoopButton->setObjectName(QStringLiteral("secondaryButton"));
|
|
|
|
|
|
addFlowStepButton->setObjectName(QStringLiteral("primaryButton"));
|
|
|
|
|
|
addFlowLoopButton->setObjectName(QStringLiteral("secondaryButton"));
|
|
|
|
|
|
QHBoxLayout *flowHeader = new QHBoxLayout;
|
|
|
|
|
|
QVBoxLayout *flowHeading = new QVBoxLayout;
|
|
|
|
|
|
flowHeading->setSpacing(2);
|
|
|
|
|
|
flowHeading->addWidget(flowTitle);
|
|
|
|
|
|
flowHeading->addWidget(flowSubtitle);
|
|
|
|
|
|
flowHeader->addLayout(flowHeading);
|
|
|
|
|
|
flowHeader->addStretch(1);
|
|
|
|
|
|
flowHeader->addWidget(insertionContextLabel);
|
|
|
|
|
|
flowLayout->addLayout(flowHeader);
|
|
|
|
|
|
|
|
|
|
|
|
QFrame *flowToolbar = new QFrame(flowPanel);
|
|
|
|
|
|
flowToolbar->setObjectName(QStringLiteral("jointFlowToolbar"));
|
|
|
|
|
|
QHBoxLayout *flowBuilder = new QHBoxLayout(flowToolbar);
|
|
|
|
|
|
flowBuilder->setContentsMargins(10, 8, 10, 8);
|
|
|
|
|
|
flowBuilder->setSpacing(8);
|
|
|
|
|
|
flowBuilder->addWidget(insertAtRootButton);
|
|
|
|
|
|
flowBuilder->addWidget(enterSelectedLoopButton);
|
|
|
|
|
|
flowBuilder->addSpacing(8);
|
|
|
|
|
|
flowBuilder->addWidget(intervalLabel);
|
|
|
|
|
|
flowBuilder->addWidget(m_jointPointInterval);
|
|
|
|
|
|
flowBuilder->addWidget(addFlowStepButton);
|
|
|
|
|
|
flowBuilder->addStretch(1);
|
|
|
|
|
|
flowBuilder->addWidget(new QLabel(QStringLiteral("循环次数"), flowPanel));
|
|
|
|
|
|
flowBuilder->addWidget(m_jointFlowGroupCount);
|
|
|
|
|
|
flowBuilder->addWidget(addFlowLoopButton);
|
|
|
|
|
|
flowLayout->addWidget(flowToolbar);
|
|
|
|
|
|
QLabel *flowHint = new QLabel(QStringLiteral(
|
|
|
|
|
|
"未选中节点时添加到当前流程末尾;选中节点后,新节点将插入到该节点之后。"
|
|
|
|
|
|
"选中循环并点击“添加到选中循环”可添加第一个或末尾子节点;"
|
|
|
|
|
|
"点击“切换到根流程末尾”可退出循环并继续添加根节点。"
|
|
|
|
|
|
"双击卡片编辑参数;左键拖动仅调整同级顺序并自动吸附,右键拖动画布。"
|
|
|
|
|
|
"循环卡片右上角可展开或收起子节点。"), flowPanel);
|
|
|
|
|
|
flowHint->setObjectName(QStringLiteral("mutedLabel"));
|
|
|
|
|
|
flowLayout->addWidget(flowHint);
|
|
|
|
|
|
m_jointFlowEditor = new JointFlowEditor(flowPanel);
|
|
|
|
|
|
flowLayout->addWidget(m_jointFlowEditor);
|
|
|
|
|
|
QHBoxLayout *flowActions = new QHBoxLayout;
|
|
|
|
|
|
QPushButton *flowDeleteButton = new QPushButton(QStringLiteral("删除选中节点"), flowPanel);
|
|
|
|
|
|
flowDeleteButton->setObjectName(QStringLiteral("dangerOutlineButton"));
|
|
|
|
|
|
QLabel *flowVelocityLabel = new QLabel(QStringLiteral("MoveJ 速度"), flowPanel);
|
|
|
|
|
|
m_jointFlowVelocitySpin = new QDoubleSpinBox(flowPanel);
|
|
|
|
|
|
m_jointFlowVelocitySpin->setRange(0.001, 10.0);
|
|
|
|
|
|
m_jointFlowVelocitySpin->setDecimals(3);
|
|
|
|
|
|
m_jointFlowVelocitySpin->setSingleStep(0.01);
|
|
|
|
|
|
m_jointFlowVelocitySpin->setValue(0.1);
|
|
|
|
|
|
m_jointFlowVelocitySpin->setSuffix(QStringLiteral(" rad/s"));
|
|
|
|
|
|
m_jointFlowVelocitySpin->setMinimumWidth(140);
|
|
|
|
|
|
QLabel *flowAccelerationLabel = new QLabel(QStringLiteral("加速度"), flowPanel);
|
|
|
|
|
|
m_jointFlowAccelerationSpin = new QDoubleSpinBox(flowPanel);
|
|
|
|
|
|
m_jointFlowAccelerationSpin->setRange(0.001, 20.0);
|
|
|
|
|
|
m_jointFlowAccelerationSpin->setDecimals(3);
|
|
|
|
|
|
m_jointFlowAccelerationSpin->setSingleStep(0.01);
|
|
|
|
|
|
m_jointFlowAccelerationSpin->setValue(0.1);
|
|
|
|
|
|
m_jointFlowAccelerationSpin->setSuffix(QStringLiteral(" rad/s²"));
|
|
|
|
|
|
m_jointFlowAccelerationSpin->setMinimumWidth(140);
|
|
|
|
|
|
m_startJointPointLoopButton->setObjectName(QStringLiteral("primaryButton"));
|
|
|
|
|
|
m_stopJointPointLoopButton->setObjectName(QStringLiteral("dangerButton"));
|
|
|
|
|
|
flowActions->addWidget(flowDeleteButton);
|
|
|
|
|
|
flowActions->addSpacing(10);
|
|
|
|
|
|
flowActions->addWidget(flowVelocityLabel);
|
|
|
|
|
|
flowActions->addWidget(m_jointFlowVelocitySpin);
|
|
|
|
|
|
flowActions->addWidget(flowAccelerationLabel);
|
|
|
|
|
|
flowActions->addWidget(m_jointFlowAccelerationSpin);
|
|
|
|
|
|
flowActions->addStretch(1);
|
|
|
|
|
|
flowActions->addWidget(loopCountLabel);
|
|
|
|
|
|
loopCountLabel->setVisible(false);
|
|
|
|
|
|
m_jointPointLoopCount->setVisible(false);
|
|
|
|
|
|
flowActions->addWidget(m_startJointPointLoopButton);
|
|
|
|
|
|
flowActions->addWidget(m_stopJointPointLoopButton);
|
|
|
|
|
|
flowLayout->addLayout(flowActions);
|
|
|
|
|
|
QSplitter *jointFlowSplitter = new QSplitter(Qt::Vertical, moveJPage);
|
|
|
|
|
|
jointFlowSplitter->setObjectName(QStringLiteral("jointFlowSplitter"));
|
|
|
|
|
|
jointFlowSplitter->addWidget(pointPanel);
|
|
|
|
|
|
jointFlowSplitter->addWidget(flowPanel);
|
|
|
|
|
|
jointFlowSplitter->setStretchFactor(0, 1);
|
|
|
|
|
|
jointFlowSplitter->setStretchFactor(1, 3);
|
|
|
|
|
|
jointFlowSplitter->setSizes({245, 510});
|
|
|
|
|
|
moveJLayout->addWidget(jointFlowSplitter, 1);
|
|
|
|
|
|
|
|
|
|
|
|
connect(addFlowStepButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
const QModelIndexList rows = m_jointPointTable->selectionModel()->selectedRows();
|
|
|
|
|
|
if (rows.isEmpty()) {
|
2026-10-16 09:39:44 +08:00
|
|
|
|
AppMessageBox::information(m_jointFlowDialog, QStringLiteral("添加单步节点"),
|
2026-10-14 17:15:46 +08:00
|
|
|
|
QStringLiteral("请先选择一个已记录点位。"));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
const int row = rows.first().row();
|
|
|
|
|
|
if (row >= 0 && row < m_recordedJointPoints.size()) {
|
|
|
|
|
|
const QString executionUnit = m_recordedJointPoints.at(row).name;
|
|
|
|
|
|
bool ok = false;
|
|
|
|
|
|
const QString nodeName = requestFlowNodeName(
|
|
|
|
|
|
m_jointFlowDialog, QStringLiteral("新增单步节点"), executionUnit, &ok);
|
|
|
|
|
|
if (ok && !nodeName.isEmpty())
|
|
|
|
|
|
m_jointFlowEditor->addSingleNode(nodeName, executionUnit,
|
|
|
|
|
|
m_jointPointInterval->value());
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(addFlowLoopButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
bool ok = false;
|
|
|
|
|
|
const QString nodeName = requestFlowNodeName(
|
|
|
|
|
|
m_jointFlowDialog, QStringLiteral("新增循环节点"), QStringLiteral("循环"), &ok);
|
|
|
|
|
|
if (ok && !nodeName.isEmpty())
|
|
|
|
|
|
m_jointFlowEditor->addLoopNode(nodeName, m_jointFlowGroupCount->value(),
|
|
|
|
|
|
m_jointPointInterval->value());
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(insertAtRootButton, &QPushButton::clicked,
|
|
|
|
|
|
m_jointFlowEditor, &JointFlowEditor::setInsertionAtRoot);
|
|
|
|
|
|
connect(enterSelectedLoopButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
if (!m_jointFlowEditor->useSelectedLoopAsInsertionParent()) {
|
2026-10-16 09:39:44 +08:00
|
|
|
|
AppMessageBox::information(m_jointFlowDialog, QStringLiteral("添加到循环"),
|
2026-10-14 17:15:46 +08:00
|
|
|
|
QStringLiteral("请先在画布中选择一个循环节点。"));
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_jointFlowEditor, &JointFlowEditor::insertionContextChanged,
|
|
|
|
|
|
insertionContextLabel, [insertionContextLabel](const QString &description) {
|
|
|
|
|
|
insertionContextLabel->setText(QStringLiteral("添加到:%1").arg(description));
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(flowDeleteButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_jointFlowEditor->removeSelectedNode();
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_jointFlowEditor, &JointFlowEditor::changed, this, [this]() {
|
|
|
|
|
|
saveJointPrograms();
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_jointFlowVelocitySpin, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
|
|
|
|
|
|
this, [this](double) { saveJointPrograms(); });
|
|
|
|
|
|
connect(m_jointFlowAccelerationSpin, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
|
|
|
|
|
|
this, [this](double) { saveJointPrograms(); });
|
|
|
|
|
|
FramelessToolDialog *jointFlowDialog = new FramelessToolDialog(this);
|
|
|
|
|
|
m_jointFlowDialog = jointFlowDialog;
|
|
|
|
|
|
m_jointFlowDialog->setObjectName(QStringLiteral("jointFlowDialog"));
|
|
|
|
|
|
m_jointFlowDialog->setWindowTitle(QStringLiteral("机械臂点位与流程编排"));
|
|
|
|
|
|
m_jointFlowDialog->setModal(false);
|
|
|
|
|
|
m_jointFlowDialog->resize(1480, 920);
|
|
|
|
|
|
m_jointFlowDialog->setMinimumSize(1120, 740);
|
|
|
|
|
|
QVBoxLayout *jointFlowDialogLayout = new QVBoxLayout(m_jointFlowDialog);
|
|
|
|
|
|
jointFlowDialogLayout->setContentsMargins(14, 14, 14, 14);
|
|
|
|
|
|
jointFlowDialogLayout->setSpacing(0);
|
|
|
|
|
|
QFrame *jointFlowSurface = new QFrame(m_jointFlowDialog);
|
|
|
|
|
|
jointFlowSurface->setObjectName(QStringLiteral("jointFlowDialogSurface"));
|
|
|
|
|
|
QVBoxLayout *jointFlowSurfaceLayout = new QVBoxLayout(jointFlowSurface);
|
|
|
|
|
|
jointFlowSurfaceLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
jointFlowSurfaceLayout->setSpacing(0);
|
|
|
|
|
|
QWidget *jointFlowTitleBar = new QWidget(jointFlowSurface);
|
|
|
|
|
|
jointFlowTitleBar->setObjectName(QStringLiteral("jointFlowDialogTitleBar"));
|
|
|
|
|
|
jointFlowTitleBar->setFixedHeight(46);
|
|
|
|
|
|
QHBoxLayout *jointFlowTitleLayout = new QHBoxLayout(jointFlowTitleBar);
|
|
|
|
|
|
jointFlowTitleLayout->setContentsMargins(12, 0, 0, 0);
|
|
|
|
|
|
jointFlowTitleLayout->setSpacing(9);
|
|
|
|
|
|
QLabel *jointFlowMark = new QLabel(QStringLiteral("C"), jointFlowTitleBar);
|
|
|
|
|
|
jointFlowMark->setObjectName(QStringLiteral("jointFlowDialogMark"));
|
|
|
|
|
|
jointFlowMark->setAlignment(Qt::AlignCenter);
|
|
|
|
|
|
jointFlowMark->setFixedSize(25, 25);
|
|
|
|
|
|
QLabel *jointFlowTitle = new QLabel(QStringLiteral("机械臂点位与流程编排"), jointFlowTitleBar);
|
|
|
|
|
|
jointFlowTitle->setObjectName(QStringLiteral("jointFlowDialogTitle"));
|
|
|
|
|
|
QLabel *jointFlowSubtitle = new QLabel(QStringLiteral("POINT & FLOW"), jointFlowTitleBar);
|
|
|
|
|
|
jointFlowSubtitle->setObjectName(QStringLiteral("jointFlowDialogSubtitle"));
|
|
|
|
|
|
QPushButton *jointFlowMinimize = new QPushButton(jointFlowTitleBar);
|
|
|
|
|
|
jointFlowMinimize->setObjectName(QStringLiteral("jointFlowDialogWindowButton"));
|
|
|
|
|
|
jointFlowMinimize->setToolTip(QStringLiteral("最小化"));
|
|
|
|
|
|
jointFlowMinimize->setFixedSize(46, 45);
|
|
|
|
|
|
jointFlowMinimize->setIcon(UiIcons::icon(QStringLiteral(":/icons/minus.svg"),
|
|
|
|
|
|
QColor(QStringLiteral("#4f5964")), QColor(QStringLiteral("#202832"))));
|
|
|
|
|
|
QPushButton *jointFlowClose = new QPushButton(jointFlowTitleBar);
|
|
|
|
|
|
jointFlowClose->setObjectName(QStringLiteral("jointFlowDialogCloseButton"));
|
|
|
|
|
|
jointFlowClose->setToolTip(QStringLiteral("关闭"));
|
|
|
|
|
|
jointFlowClose->setFixedSize(48, 45);
|
|
|
|
|
|
jointFlowClose->setIcon(UiIcons::icon(QStringLiteral(":/icons/x.svg"),
|
|
|
|
|
|
QColor(QStringLiteral("#4f5964")), QColor(QStringLiteral("#4f5964"))));
|
|
|
|
|
|
jointFlowTitleLayout->addWidget(jointFlowMark);
|
|
|
|
|
|
jointFlowTitleLayout->addWidget(jointFlowTitle);
|
|
|
|
|
|
jointFlowTitleLayout->addWidget(jointFlowSubtitle);
|
|
|
|
|
|
jointFlowTitleLayout->addStretch(1);
|
|
|
|
|
|
jointFlowTitleLayout->addWidget(jointFlowMinimize);
|
|
|
|
|
|
jointFlowTitleLayout->addWidget(jointFlowClose);
|
|
|
|
|
|
jointFlowSurfaceLayout->addWidget(jointFlowTitleBar);
|
|
|
|
|
|
jointFlowSurfaceLayout->addWidget(moveJPage, 1);
|
|
|
|
|
|
jointFlowDialogLayout->addWidget(jointFlowSurface);
|
|
|
|
|
|
jointFlowDialog->setDragHandle(jointFlowTitleBar);
|
|
|
|
|
|
QGraphicsDropShadowEffect *jointFlowShadow = new QGraphicsDropShadowEffect(jointFlowSurface);
|
|
|
|
|
|
jointFlowShadow->setBlurRadius(28.0);
|
|
|
|
|
|
jointFlowShadow->setOffset(0.0, 5.0);
|
|
|
|
|
|
jointFlowShadow->setColor(QColor(24, 34, 44, 78));
|
|
|
|
|
|
jointFlowSurface->setGraphicsEffect(jointFlowShadow);
|
|
|
|
|
|
connect(jointFlowMinimize, &QPushButton::clicked,
|
|
|
|
|
|
m_jointFlowDialog, &QDialog::showMinimized);
|
|
|
|
|
|
connect(jointFlowClose, &QPushButton::clicked,
|
|
|
|
|
|
m_jointFlowDialog, &QDialog::hide);
|
2026-09-23 16:04:01 +08:00
|
|
|
|
QFrame *poseMetrics = new QFrame(ui.telemetryPanel);
|
|
|
|
|
|
poseMetrics->setObjectName(QStringLiteral("poseMetrics"));
|
|
|
|
|
|
QGridLayout *poseMetricsLayout = new QGridLayout(poseMetrics);
|
|
|
|
|
|
poseMetricsLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
poseMetricsLayout->setHorizontalSpacing(8);
|
|
|
|
|
|
poseMetricsLayout->setVerticalSpacing(8);
|
|
|
|
|
|
const QStringList poseAxes = {
|
|
|
|
|
|
QStringLiteral("X"), QStringLiteral("Y"), QStringLiteral("Z"),
|
|
|
|
|
|
QStringLiteral("RX"), QStringLiteral("RY"), QStringLiteral("RZ")
|
|
|
|
|
|
};
|
|
|
|
|
|
const QStringList poseUnits = {
|
|
|
|
|
|
QStringLiteral("m"), QStringLiteral("m"), QStringLiteral("m"),
|
|
|
|
|
|
QStringLiteral("rad"), QStringLiteral("rad"), QStringLiteral("rad")
|
|
|
|
|
|
};
|
|
|
|
|
|
m_poseMetricValues.clear();
|
|
|
|
|
|
for (int index = 0; index < poseAxes.size(); ++index) {
|
|
|
|
|
|
QFrame *metricCard = new QFrame(poseMetrics);
|
|
|
|
|
|
metricCard->setObjectName(QStringLiteral("poseMetricCard"));
|
|
|
|
|
|
QVBoxLayout *metricLayout = new QVBoxLayout(metricCard);
|
|
|
|
|
|
metricLayout->setContentsMargins(10, 8, 10, 8);
|
|
|
|
|
|
metricLayout->setSpacing(3);
|
|
|
|
|
|
QLabel *axisLabel = new QLabel(poseAxes.at(index), metricCard);
|
|
|
|
|
|
axisLabel->setObjectName(QStringLiteral("poseMetricAxis"));
|
|
|
|
|
|
QLabel *valueLabel = new QLabel(QStringLiteral("--"), metricCard);
|
|
|
|
|
|
valueLabel->setObjectName(QStringLiteral("poseMetricValue"));
|
|
|
|
|
|
QLabel *unitLabel = new QLabel(poseUnits.at(index), metricCard);
|
|
|
|
|
|
unitLabel->setObjectName(QStringLiteral("poseMetricUnit"));
|
|
|
|
|
|
QHBoxLayout *valueLayout = new QHBoxLayout;
|
|
|
|
|
|
valueLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
valueLayout->setSpacing(5);
|
|
|
|
|
|
valueLayout->addWidget(valueLabel);
|
|
|
|
|
|
valueLayout->addWidget(unitLabel);
|
|
|
|
|
|
valueLayout->addStretch(1);
|
|
|
|
|
|
metricLayout->addWidget(axisLabel);
|
|
|
|
|
|
metricLayout->addLayout(valueLayout);
|
|
|
|
|
|
poseMetricsLayout->addWidget(metricCard, index / 3, index % 3);
|
|
|
|
|
|
m_poseMetricValues.append(valueLabel);
|
|
|
|
|
|
}
|
|
|
|
|
|
ui.poseLayout->insertWidget(2, poseMetrics, 1);
|
|
|
|
|
|
ui.telemetryLayout->setSpacing(14);
|
|
|
|
|
|
ui.telemetryLayout->setStretch(0, 1);
|
|
|
|
|
|
ui.telemetryLayout->setStretch(1, 1);
|
2026-09-23 11:11:49 +08:00
|
|
|
|
|
2026-10-14 17:15:46 +08:00
|
|
|
|
// Keep the MoveJ target panel in its own position-control tab. The model
|
|
|
|
|
|
// workspace below only replaces the old teaching/telemetry arrangement.
|
|
|
|
|
|
ui.targetsPanel->show();
|
|
|
|
|
|
m_syncCurrentToTargetButton = new QPushButton(
|
|
|
|
|
|
QStringLiteral("当前位置同步到目标"), ui.targetsPanel);
|
|
|
|
|
|
m_syncCurrentToTargetButton->setObjectName(QStringLiteral("secondaryButton"));
|
|
|
|
|
|
m_syncCurrentToTargetButton->setToolTip(
|
|
|
|
|
|
QStringLiteral("按关节名称将最新遥测位置复制到目标角度和目标弧度"));
|
|
|
|
|
|
const int zeroButtonIndex = ui.targetsHeader->indexOf(ui.zeroButton);
|
|
|
|
|
|
ui.targetsHeader->insertWidget(
|
|
|
|
|
|
zeroButtonIndex >= 0 ? zeroButtonIndex : ui.targetsHeader->count(),
|
|
|
|
|
|
m_syncCurrentToTargetButton);
|
|
|
|
|
|
|
|
|
|
|
|
QFrame *moveJParameters = new QFrame(ui.targetsPanel);
|
|
|
|
|
|
moveJParameters->setObjectName(QStringLiteral("jointFlowToolbar"));
|
|
|
|
|
|
QHBoxLayout *moveJParametersLayout = new QHBoxLayout(moveJParameters);
|
|
|
|
|
|
moveJParametersLayout->setContentsMargins(12, 8, 12, 8);
|
|
|
|
|
|
moveJParametersLayout->setSpacing(8);
|
|
|
|
|
|
QLabel *moveJParametersTitle = new QLabel(
|
|
|
|
|
|
QStringLiteral("MoveJ 运动参数"), moveJParameters);
|
|
|
|
|
|
moveJParametersTitle->setObjectName(QStringLiteral("eyebrow"));
|
|
|
|
|
|
QLabel *moveJVelocityLabel = new QLabel(QStringLiteral("速度"), moveJParameters);
|
|
|
|
|
|
m_moveJVelocitySpin = new QDoubleSpinBox(moveJParameters);
|
|
|
|
|
|
m_moveJVelocitySpin->setRange(0.001, 10.0);
|
|
|
|
|
|
m_moveJVelocitySpin->setDecimals(3);
|
|
|
|
|
|
m_moveJVelocitySpin->setSingleStep(0.01);
|
|
|
|
|
|
m_moveJVelocitySpin->setValue(0.1);
|
|
|
|
|
|
m_moveJVelocitySpin->setSuffix(QStringLiteral(" rad/s"));
|
|
|
|
|
|
m_moveJVelocitySpin->setMinimumWidth(150);
|
|
|
|
|
|
QLabel *moveJAccelerationLabel = new QLabel(
|
|
|
|
|
|
QStringLiteral("加速度"), moveJParameters);
|
|
|
|
|
|
m_moveJAccelerationSpin = new QDoubleSpinBox(moveJParameters);
|
|
|
|
|
|
m_moveJAccelerationSpin->setRange(0.001, 20.0);
|
|
|
|
|
|
m_moveJAccelerationSpin->setDecimals(3);
|
|
|
|
|
|
m_moveJAccelerationSpin->setSingleStep(0.01);
|
|
|
|
|
|
m_moveJAccelerationSpin->setValue(0.1);
|
|
|
|
|
|
m_moveJAccelerationSpin->setSuffix(QStringLiteral(" rad/s²"));
|
|
|
|
|
|
m_moveJAccelerationSpin->setMinimumWidth(150);
|
|
|
|
|
|
moveJParametersLayout->addWidget(moveJParametersTitle);
|
|
|
|
|
|
moveJParametersLayout->addSpacing(12);
|
|
|
|
|
|
moveJParametersLayout->addWidget(moveJVelocityLabel);
|
|
|
|
|
|
moveJParametersLayout->addWidget(m_moveJVelocitySpin);
|
|
|
|
|
|
moveJParametersLayout->addWidget(moveJAccelerationLabel);
|
|
|
|
|
|
moveJParametersLayout->addWidget(m_moveJAccelerationSpin);
|
|
|
|
|
|
moveJParametersLayout->addStretch(1);
|
|
|
|
|
|
ui.targetsLayout->insertWidget(1, moveJParameters);
|
2026-09-23 11:11:49 +08:00
|
|
|
|
ui.teachPanel->hide();
|
|
|
|
|
|
ui.urdfTabLayout->removeWidget(ui.urdfViewer);
|
|
|
|
|
|
ui.urdfTabLayout->removeWidget(ui.teachPanel);
|
|
|
|
|
|
|
|
|
|
|
|
QWidget *workspace = new QWidget(ui.urdfTab);
|
|
|
|
|
|
QVBoxLayout *workspaceLayout = new QVBoxLayout(workspace);
|
|
|
|
|
|
workspaceLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
workspaceLayout->setSpacing(10);
|
2026-09-18 16:22:20 +08:00
|
|
|
|
|
2026-09-23 11:11:49 +08:00
|
|
|
|
QSplitter *modelJogWorkspace = new QSplitter(Qt::Horizontal, workspace);
|
|
|
|
|
|
modelJogWorkspace->setObjectName(QStringLiteral("armModelJogSplitter"));
|
|
|
|
|
|
modelJogWorkspace->setChildrenCollapsible(false);
|
|
|
|
|
|
modelJogWorkspace->setHandleWidth(8);
|
|
|
|
|
|
modelJogWorkspace->addWidget(ui.urdfViewer);
|
2026-09-18 16:22:20 +08:00
|
|
|
|
|
2026-09-23 11:11:49 +08:00
|
|
|
|
QFrame *jogPanel = new QFrame(modelJogWorkspace);
|
|
|
|
|
|
jogPanel->setObjectName(QStringLiteral("armJogPanel"));
|
|
|
|
|
|
jogPanel->setMinimumWidth(440);
|
|
|
|
|
|
QVBoxLayout *jogLayout = new QVBoxLayout(jogPanel);
|
|
|
|
|
|
jogLayout->setContentsMargins(12, 10, 12, 10);
|
|
|
|
|
|
jogLayout->setSpacing(8);
|
|
|
|
|
|
QHBoxLayout *jogHeader = new QHBoxLayout;
|
|
|
|
|
|
QLabel *jogTitle = new QLabel(QStringLiteral("速度控制"), jogPanel);
|
|
|
|
|
|
jogTitle->setObjectName(QStringLiteral("sectionTitle"));
|
|
|
|
|
|
QLabel *jogHint = new QLabel(QStringLiteral("按住执行,松开即停"), jogPanel);
|
|
|
|
|
|
jogHint->setObjectName(QStringLiteral("panelSubtitle"));
|
2026-10-14 17:15:46 +08:00
|
|
|
|
QPushButton *openJointFlowButton = new QPushButton(
|
|
|
|
|
|
QStringLiteral("点位与流程…"), jogPanel);
|
|
|
|
|
|
openJointFlowButton->setObjectName(QStringLiteral("secondaryButton"));
|
2026-09-23 11:11:49 +08:00
|
|
|
|
jogHeader->addWidget(jogTitle);
|
|
|
|
|
|
jogHeader->addStretch(1);
|
|
|
|
|
|
jogHeader->addWidget(jogHint);
|
2026-10-14 17:15:46 +08:00
|
|
|
|
jogHeader->addWidget(openJointFlowButton);
|
2026-09-23 11:11:49 +08:00
|
|
|
|
jogLayout->addLayout(jogHeader);
|
2026-10-14 17:15:46 +08:00
|
|
|
|
connect(openJointFlowButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
if (!m_jointFlowDialog)
|
|
|
|
|
|
return;
|
|
|
|
|
|
m_jointFlowDialog->show();
|
|
|
|
|
|
m_jointFlowDialog->raise();
|
|
|
|
|
|
m_jointFlowDialog->activateWindow();
|
|
|
|
|
|
});
|
2026-09-23 11:11:49 +08:00
|
|
|
|
|
|
|
|
|
|
m_jogModeTabs = new QTabWidget(jogPanel);
|
|
|
|
|
|
m_jogModeTabs->setObjectName(QStringLiteral("armJogModeTabs"));
|
|
|
|
|
|
m_jogModeTabs->setDocumentMode(true);
|
|
|
|
|
|
QWidget *jointJogPage = new QWidget(m_jogModeTabs);
|
|
|
|
|
|
QVBoxLayout *jointJogPageLayout = new QVBoxLayout(jointJogPage);
|
|
|
|
|
|
jointJogPageLayout->setContentsMargins(0, 8, 0, 0);
|
|
|
|
|
|
m_jointJogRowsHost = new QWidget(jointJogPage);
|
|
|
|
|
|
m_jointJogRowsLayout = new QVBoxLayout(m_jointJogRowsHost);
|
|
|
|
|
|
m_jointJogRowsLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
m_jointJogRowsLayout->setSpacing(5);
|
|
|
|
|
|
jointJogPageLayout->addWidget(m_jointJogRowsHost);
|
|
|
|
|
|
jointJogPageLayout->addStretch(1);
|
|
|
|
|
|
m_jogModeTabs->addTab(jointJogPage, QStringLiteral("关节速度"));
|
|
|
|
|
|
|
|
|
|
|
|
QWidget *cartesianJogPage = new QWidget(m_jogModeTabs);
|
|
|
|
|
|
QVBoxLayout *cartesianLayout = new QVBoxLayout(cartesianJogPage);
|
|
|
|
|
|
cartesianLayout->setContentsMargins(0, 8, 0, 0);
|
|
|
|
|
|
cartesianLayout->setSpacing(6);
|
|
|
|
|
|
QLabel *framesTitle = new QLabel(QStringLiteral("控制坐标系"), cartesianJogPage);
|
|
|
|
|
|
framesTitle->setObjectName(QStringLiteral("eyebrow"));
|
|
|
|
|
|
cartesianLayout->addWidget(framesTitle);
|
|
|
|
|
|
QGridLayout *frameGrid = new QGridLayout;
|
|
|
|
|
|
frameGrid->setHorizontalSpacing(6);
|
|
|
|
|
|
QLabel *baseFrameLabel = new QLabel(QStringLiteral("基座坐标"), cartesianJogPage);
|
|
|
|
|
|
QLabel *tcpFrameLabel = new QLabel(QStringLiteral("工具坐标"), cartesianJogPage);
|
|
|
|
|
|
m_baseFrameCombo = new QComboBox(cartesianJogPage);
|
|
|
|
|
|
m_tcpFrameCombo = new QComboBox(cartesianJogPage);
|
2026-10-14 17:15:46 +08:00
|
|
|
|
m_tcpFrameCombo->setObjectName(QStringLiteral("armTcpFrameCombo"));
|
|
|
|
|
|
m_armPoseSubtitle = ui.poseSubtitle;
|
2026-09-23 11:11:49 +08:00
|
|
|
|
m_baseFrameCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
|
|
m_tcpFrameCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
|
|
frameGrid->addWidget(baseFrameLabel, 0, 0);
|
|
|
|
|
|
frameGrid->addWidget(m_baseFrameCombo, 0, 1);
|
|
|
|
|
|
frameGrid->addWidget(tcpFrameLabel, 0, 2);
|
|
|
|
|
|
frameGrid->addWidget(m_tcpFrameCombo, 0, 3);
|
|
|
|
|
|
cartesianLayout->addLayout(frameGrid);
|
|
|
|
|
|
|
2026-09-23 16:04:01 +08:00
|
|
|
|
m_cartesianJogPoseLabels.clear();
|
|
|
|
|
|
const auto createJogButton = [this](QWidget *parent, const QString &text,
|
|
|
|
|
|
int axis, int direction,
|
|
|
|
|
|
const QString &tone,
|
|
|
|
|
|
const QString &role,
|
|
|
|
|
|
int width, int height) {
|
|
|
|
|
|
QPushButton *button = new QPushButton(text, parent);
|
|
|
|
|
|
button->setObjectName(QStringLiteral("cartesianPadButton"));
|
|
|
|
|
|
button->setProperty("axisTone", tone);
|
|
|
|
|
|
button->setProperty("padRole", role);
|
|
|
|
|
|
button->setFixedSize(width, height);
|
|
|
|
|
|
button->setAutoRepeat(false);
|
|
|
|
|
|
connect(button, &QPushButton::pressed, this,
|
|
|
|
|
|
[this, axis, direction]() { startCartesianJog(axis, direction); });
|
|
|
|
|
|
connect(button, &QPushButton::released, this, &MainWindow::stopArmJog);
|
|
|
|
|
|
return button;
|
2026-09-18 16:22:20 +08:00
|
|
|
|
};
|
2026-09-23 16:04:01 +08:00
|
|
|
|
const auto createPoseStrip = [this](QWidget *parent, const QStringList &axes,
|
|
|
|
|
|
const QStringList &units) {
|
|
|
|
|
|
QWidget *strip = new QWidget(parent);
|
|
|
|
|
|
QHBoxLayout *layout = new QHBoxLayout(strip);
|
|
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
layout->setSpacing(6);
|
|
|
|
|
|
for (int index = 0; index < axes.size(); ++index) {
|
|
|
|
|
|
QFrame *chip = new QFrame(strip);
|
|
|
|
|
|
chip->setObjectName(QStringLiteral("cartesianPoseChip"));
|
|
|
|
|
|
QHBoxLayout *chipLayout = new QHBoxLayout(chip);
|
|
|
|
|
|
chipLayout->setContentsMargins(7, 4, 7, 4);
|
|
|
|
|
|
chipLayout->setSpacing(5);
|
|
|
|
|
|
QLabel *axisLabel = new QLabel(axes.at(index), chip);
|
|
|
|
|
|
axisLabel->setObjectName(QStringLiteral("cartesianPoseAxis"));
|
|
|
|
|
|
QLabel *valueLabel = new QLabel(
|
|
|
|
|
|
QStringLiteral("-- %1").arg(units.at(index)), chip);
|
|
|
|
|
|
valueLabel->setObjectName(QStringLiteral("cartesianPoseValue"));
|
|
|
|
|
|
chipLayout->addWidget(axisLabel);
|
|
|
|
|
|
chipLayout->addStretch(1);
|
|
|
|
|
|
chipLayout->addWidget(valueLabel);
|
|
|
|
|
|
layout->addWidget(chip, 1);
|
|
|
|
|
|
m_cartesianJogPoseLabels.append(valueLabel);
|
2026-09-23 11:11:49 +08:00
|
|
|
|
}
|
2026-09-23 16:04:01 +08:00
|
|
|
|
return strip;
|
|
|
|
|
|
};
|
2026-10-14 17:15:46 +08:00
|
|
|
|
const auto createAxisControls = [&createJogButton](QWidget *parent, int firstAxis,
|
|
|
|
|
|
const QStringList &names) {
|
|
|
|
|
|
auto *layout = new QHBoxLayout;
|
|
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
layout->setSpacing(6);
|
|
|
|
|
|
const QStringList tones = {QStringLiteral("x"), QStringLiteral("y"), QStringLiteral("z")};
|
|
|
|
|
|
for (int i = 0; i < names.size(); ++i) {
|
|
|
|
|
|
auto *pair = new QHBoxLayout;
|
|
|
|
|
|
pair->setSpacing(4);
|
|
|
|
|
|
for (int direction : {-1, 1}) {
|
|
|
|
|
|
auto *button = createJogButton(parent,
|
|
|
|
|
|
QStringLiteral("%1 %2").arg(direction < 0 ? QStringLiteral("−") : QStringLiteral("+"), names.at(i)),
|
|
|
|
|
|
firstAxis + i, direction, tones.at(i), QStringLiteral("compact"), 48, 42);
|
|
|
|
|
|
button->setMinimumWidth(42);
|
|
|
|
|
|
button->setMaximumWidth(QWIDGETSIZE_MAX);
|
|
|
|
|
|
button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
|
|
button->setToolTip(QStringLiteral("按住沿 %1 %2 运动,松开停止")
|
|
|
|
|
|
.arg(names.at(i), direction < 0 ? QStringLiteral("负向") : QStringLiteral("正向")));
|
|
|
|
|
|
pair->addWidget(button, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
layout->addLayout(pair, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
return layout;
|
2026-09-23 16:04:01 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *cartesianControls = new QVBoxLayout;
|
|
|
|
|
|
cartesianControls->setSpacing(10);
|
|
|
|
|
|
|
|
|
|
|
|
QFrame *translationGroup = new QFrame(cartesianJogPage);
|
|
|
|
|
|
translationGroup->setObjectName(QStringLiteral("cartesianControlGroup"));
|
|
|
|
|
|
QVBoxLayout *translationLayout = new QVBoxLayout(translationGroup);
|
|
|
|
|
|
translationLayout->setContentsMargins(10, 8, 10, 10);
|
|
|
|
|
|
translationLayout->setSpacing(7);
|
|
|
|
|
|
QLabel *translationTitle = new QLabel(QStringLiteral("平移控制"), translationGroup);
|
|
|
|
|
|
translationTitle->setObjectName(QStringLiteral("cartesianGroupTitle"));
|
|
|
|
|
|
translationLayout->addWidget(translationTitle);
|
|
|
|
|
|
translationLayout->addWidget(createPoseStrip(
|
|
|
|
|
|
translationGroup,
|
|
|
|
|
|
{QStringLiteral("X"), QStringLiteral("Y"), QStringLiteral("Z")},
|
|
|
|
|
|
{QStringLiteral("m"), QStringLiteral("m"), QStringLiteral("m")}));
|
2026-10-14 17:15:46 +08:00
|
|
|
|
translationLayout->addLayout(createAxisControls(translationGroup, 0,
|
|
|
|
|
|
{QStringLiteral("X"), QStringLiteral("Y"), QStringLiteral("Z")}));
|
|
|
|
|
|
cartesianControls->addWidget(translationGroup);
|
2026-09-23 16:04:01 +08:00
|
|
|
|
|
|
|
|
|
|
QFrame *rotationGroup = new QFrame(cartesianJogPage);
|
|
|
|
|
|
rotationGroup->setObjectName(QStringLiteral("cartesianControlGroup"));
|
|
|
|
|
|
QVBoxLayout *rotationLayout = new QVBoxLayout(rotationGroup);
|
|
|
|
|
|
rotationLayout->setContentsMargins(10, 8, 10, 10);
|
|
|
|
|
|
rotationLayout->setSpacing(7);
|
|
|
|
|
|
QLabel *rotationTitle = new QLabel(QStringLiteral("旋转控制"), rotationGroup);
|
|
|
|
|
|
rotationTitle->setObjectName(QStringLiteral("cartesianGroupTitle"));
|
|
|
|
|
|
rotationLayout->addWidget(rotationTitle);
|
|
|
|
|
|
rotationLayout->addWidget(createPoseStrip(
|
|
|
|
|
|
rotationGroup,
|
|
|
|
|
|
{QStringLiteral("RX"), QStringLiteral("RY"), QStringLiteral("RZ")},
|
|
|
|
|
|
{QStringLiteral("rad"), QStringLiteral("rad"), QStringLiteral("rad")}));
|
2026-10-14 17:15:46 +08:00
|
|
|
|
rotationLayout->addLayout(createAxisControls(rotationGroup, 3,
|
|
|
|
|
|
{QStringLiteral("RX"), QStringLiteral("RY"), QStringLiteral("RZ")}));
|
|
|
|
|
|
cartesianControls->addWidget(rotationGroup);
|
|
|
|
|
|
|
|
|
|
|
|
cartesianLayout->addLayout(cartesianControls);
|
2026-09-23 11:11:49 +08:00
|
|
|
|
cartesianLayout->addStretch(1);
|
2026-09-23 16:04:01 +08:00
|
|
|
|
if (QTabBar *jogTabBar = m_jogModeTabs->findChild<QTabBar *>()) {
|
|
|
|
|
|
jogTabBar->setExpanding(true);
|
|
|
|
|
|
jogTabBar->setUsesScrollButtons(false);
|
|
|
|
|
|
jogTabBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
|
|
}
|
2026-09-23 11:11:49 +08:00
|
|
|
|
m_jogModeTabs->addTab(cartesianJogPage, QStringLiteral("笛卡尔速度"));
|
2026-10-14 17:15:46 +08:00
|
|
|
|
m_handEyeMotion = new HandEyeMotionWidget(m_jogModeTabs);
|
|
|
|
|
|
m_jogModeTabs->addTab(m_handEyeMotion, QStringLiteral("视觉坐标"));
|
2026-09-23 11:11:49 +08:00
|
|
|
|
jogLayout->addWidget(m_jogModeTabs, 1);
|
|
|
|
|
|
|
|
|
|
|
|
QHBoxLayout *speedLayout = new QHBoxLayout;
|
|
|
|
|
|
QLabel *speedLabel = new QLabel(QStringLiteral("速度倍率"), jogPanel);
|
|
|
|
|
|
m_jogSpeedValue = new QLabel(QStringLiteral("35%"), jogPanel);
|
|
|
|
|
|
m_jogSpeedValue->setObjectName(QStringLiteral("accentValue"));
|
|
|
|
|
|
m_jogSpeedSlider = new QSlider(Qt::Horizontal, jogPanel);
|
|
|
|
|
|
m_jogSpeedSlider->setRange(1, 100);
|
|
|
|
|
|
m_jogSpeedSlider->setValue(35);
|
2026-10-14 17:15:46 +08:00
|
|
|
|
m_jogReadyLabel = new QLabel(QStringLiteral("未连接"), jogPanel);
|
|
|
|
|
|
m_jogReadyLabel->setObjectName(QStringLiteral("armReadyLabel"));
|
2026-09-23 11:11:49 +08:00
|
|
|
|
speedLayout->addWidget(speedLabel);
|
|
|
|
|
|
speedLayout->addWidget(m_jogSpeedValue);
|
|
|
|
|
|
speedLayout->addWidget(m_jogSpeedSlider, 1);
|
2026-10-14 17:15:46 +08:00
|
|
|
|
speedLayout->addWidget(m_jogReadyLabel);
|
2026-09-23 11:11:49 +08:00
|
|
|
|
jogLayout->addLayout(speedLayout);
|
|
|
|
|
|
QHBoxLayout *jogFooter = new QHBoxLayout;
|
|
|
|
|
|
QLabel *holdHint = new QLabel(
|
|
|
|
|
|
QStringLiteral("按住 + / − 按钮,以当前速度倍率运动;松开立即停止"), jogPanel);
|
|
|
|
|
|
holdHint->setObjectName(QStringLiteral("panelSubtitle"));
|
|
|
|
|
|
holdHint->setWordWrap(true);
|
|
|
|
|
|
m_jogStopButton = new QPushButton(QStringLiteral("立即停止"), jogPanel);
|
|
|
|
|
|
m_jogStopButton->setObjectName(QStringLiteral("dangerOutlineButton"));
|
|
|
|
|
|
m_jogStopButton->setMinimumWidth(132);
|
|
|
|
|
|
jogFooter->addWidget(holdHint, 1);
|
|
|
|
|
|
jogFooter->addWidget(m_jogStopButton);
|
|
|
|
|
|
jogLayout->addLayout(jogFooter);
|
|
|
|
|
|
modelJogWorkspace->addWidget(jogPanel);
|
|
|
|
|
|
modelJogWorkspace->setStretchFactor(0, 3);
|
|
|
|
|
|
modelJogWorkspace->setStretchFactor(1, 2);
|
|
|
|
|
|
modelJogWorkspace->setSizes({780, 520});
|
|
|
|
|
|
workspaceLayout->addWidget(modelJogWorkspace, 3);
|
2026-09-18 16:22:20 +08:00
|
|
|
|
|
2026-09-23 11:11:49 +08:00
|
|
|
|
ui.telemetryPanel->setParent(workspace);
|
|
|
|
|
|
ui.telemetryPanel->setMinimumHeight(230);
|
|
|
|
|
|
workspaceLayout->addWidget(ui.telemetryPanel, 2);
|
|
|
|
|
|
ui.urdfTabLayout->addWidget(workspace);
|
|
|
|
|
|
|
|
|
|
|
|
const int commandTabIndex = ui.armTabs->indexOf(ui.jointControlTab);
|
|
|
|
|
|
if (commandTabIndex >= 0)
|
2026-10-14 17:15:46 +08:00
|
|
|
|
ui.armTabs->setTabText(commandTabIndex, QStringLiteral("关节位置控制"));
|
|
|
|
|
|
ui.jointControlTab->show();
|
2026-10-29 11:46:39 +08:00
|
|
|
|
|
|
|
|
|
|
// Device teaching must not remain under the retired, hidden model editor.
|
|
|
|
|
|
// Keep it independent of URDF loading and the model-only teaching controls.
|
|
|
|
|
|
QWidget *deviceTeachingPage = new QWidget(ui.armTabs);
|
|
|
|
|
|
deviceTeachingPage->setObjectName(QStringLiteral("armDeviceTeachingPage"));
|
|
|
|
|
|
QVBoxLayout *deviceTeachingLayout = new QVBoxLayout(deviceTeachingPage);
|
|
|
|
|
|
deviceTeachingLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
QFrame *deviceTeachingPanel = new QFrame(deviceTeachingPage);
|
|
|
|
|
|
deviceTeachingPanel->setObjectName(QStringLiteral("panel"));
|
|
|
|
|
|
QVBoxLayout *deviceTeachingPanelLayout = new QVBoxLayout(deviceTeachingPanel);
|
|
|
|
|
|
deviceTeachingPanelLayout->setContentsMargins(18, 16, 18, 16);
|
|
|
|
|
|
deviceTeachingPanelLayout->setSpacing(14);
|
|
|
|
|
|
QHBoxLayout *teachingHeader = new QHBoxLayout;
|
|
|
|
|
|
QLabel *teachingTitle = new QLabel(QStringLiteral("设备拖动示教"), deviceTeachingPanel);
|
|
|
|
|
|
teachingTitle->setObjectName(QStringLiteral("sectionTitle"));
|
|
|
|
|
|
teachingHeader->addWidget(teachingTitle);
|
|
|
|
|
|
teachingHeader->addStretch(1);
|
|
|
|
|
|
m_deviceTeachingStateLabel->setParent(deviceTeachingPanel);
|
|
|
|
|
|
m_deviceTeachingStateLabel->setText(QStringLiteral("尚未操作"));
|
|
|
|
|
|
teachingHeader->addWidget(m_deviceTeachingStateLabel);
|
|
|
|
|
|
deviceTeachingPanelLayout->addLayout(teachingHeader);
|
|
|
|
|
|
|
|
|
|
|
|
QHBoxLayout *trajectoryFileLayout = new QHBoxLayout;
|
|
|
|
|
|
trajectoryFileLayout->addWidget(new QLabel(QStringLiteral("轨迹文件名"), deviceTeachingPanel));
|
|
|
|
|
|
m_trajectoryFileNameEdit->setParent(deviceTeachingPanel);
|
|
|
|
|
|
trajectoryFileLayout->addWidget(m_trajectoryFileNameEdit, 1);
|
|
|
|
|
|
m_trajectoryFileNameEdit->setPlaceholderText(QStringLiteral("轨迹名称(自动保存为 .csv,不覆盖已有文件)"));
|
|
|
|
|
|
m_trajectoryFrequencySpin = new QDoubleSpinBox(deviceTeachingPanel);
|
|
|
|
|
|
m_trajectoryFrequencySpin->setObjectName(QStringLiteral("trajectoryFrequencySpin"));
|
|
|
|
|
|
m_trajectoryFrequencySpin->setRange(1, 100);
|
|
|
|
|
|
m_trajectoryFrequencySpin->setDecimals(0);
|
|
|
|
|
|
m_trajectoryFrequencySpin->setValue(100);
|
|
|
|
|
|
m_trajectoryFrequencySpin->setSuffix(QStringLiteral(" Hz"));
|
|
|
|
|
|
trajectoryFileLayout->addWidget(new QLabel(QStringLiteral("采样频率"), deviceTeachingPanel));
|
|
|
|
|
|
trajectoryFileLayout->addWidget(m_trajectoryFrequencySpin);
|
|
|
|
|
|
deviceTeachingPanelLayout->addLayout(trajectoryFileLayout);
|
|
|
|
|
|
QHBoxLayout *teachingActions = new QHBoxLayout;
|
|
|
|
|
|
teachingActions->setSpacing(8);
|
|
|
|
|
|
const QList<QPushButton *> teachingButtons{
|
|
|
|
|
|
m_enterTeachingButton, m_exitTeachingButton,
|
|
|
|
|
|
m_startTrajectoryRecordingButton, m_stopTrajectoryRecordingButton,
|
|
|
|
|
|
m_completeTeachingButton};
|
|
|
|
|
|
for (int i = 0; i < teachingButtons.size(); ++i) {
|
|
|
|
|
|
QPushButton *button = teachingButtons.at(i);
|
|
|
|
|
|
button->setParent(deviceTeachingPanel);
|
|
|
|
|
|
if (i == 2) teachingActions->addStretch(1);
|
|
|
|
|
|
teachingActions->addWidget(button);
|
|
|
|
|
|
button->show();
|
|
|
|
|
|
}
|
|
|
|
|
|
deviceTeachingPanelLayout->addLayout(teachingActions);
|
|
|
|
|
|
QLabel *teachingHint = new QLabel(QStringLiteral(
|
|
|
|
|
|
"记录实际关节角和控制器时间,CSV 保存在服务端。完成示教后,先到起点,再回放。"), deviceTeachingPanel);
|
|
|
|
|
|
teachingHint->setObjectName(QStringLiteral("mutedLabel"));
|
|
|
|
|
|
teachingHint->setWordWrap(true);
|
|
|
|
|
|
deviceTeachingPanelLayout->addWidget(teachingHint);
|
|
|
|
|
|
m_trajectoryRecordingStatus = new QLabel(QStringLiteral("尚未读取录制状态"), deviceTeachingPanel);
|
|
|
|
|
|
m_trajectoryRecordingStatus->setWordWrap(true);
|
|
|
|
|
|
m_trajectoryRecordingStatus->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
|
|
|
|
|
deviceTeachingPanelLayout->addWidget(m_trajectoryRecordingStatus);
|
|
|
|
|
|
|
|
|
|
|
|
QFrame *replayPanel = new QFrame(deviceTeachingPage);
|
|
|
|
|
|
replayPanel->setObjectName(QStringLiteral("panel"));
|
|
|
|
|
|
QVBoxLayout *replayLayout = new QVBoxLayout(replayPanel);
|
|
|
|
|
|
replayLayout->setContentsMargins(18, 16, 18, 16);
|
|
|
|
|
|
replayLayout->setSpacing(14);
|
|
|
|
|
|
QLabel *replayTitle = new QLabel(QStringLiteral("已保存轨迹 · 回放"), replayPanel);
|
|
|
|
|
|
replayTitle->setObjectName(QStringLiteral("sectionTitle"));
|
|
|
|
|
|
replayLayout->addWidget(replayTitle);
|
|
|
|
|
|
QHBoxLayout *replayFileRow = new QHBoxLayout;
|
|
|
|
|
|
m_recordedTrajectoryCombo = new QComboBox(replayPanel);
|
|
|
|
|
|
m_recordedTrajectoryCombo->setObjectName(QStringLiteral("recordedTrajectoryCombo"));
|
|
|
|
|
|
m_refreshTrajectoriesButton = new QPushButton(QStringLiteral("刷新轨迹"), replayPanel);
|
|
|
|
|
|
replayFileRow->addWidget(m_recordedTrajectoryCombo, 1);
|
|
|
|
|
|
replayFileRow->addWidget(m_refreshTrajectoriesButton);
|
|
|
|
|
|
replayLayout->addLayout(replayFileRow);
|
|
|
|
|
|
m_trajectoryDirectoryLabel = new QLabel(QStringLiteral("保存目录:待读取"), replayPanel);
|
|
|
|
|
|
m_trajectoryDirectoryLabel->setObjectName(QStringLiteral("mutedLabel"));
|
|
|
|
|
|
m_trajectoryDirectoryLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
|
|
|
|
|
m_trajectoryDirectoryLabel->setWordWrap(true);
|
|
|
|
|
|
replayLayout->addWidget(m_trajectoryDirectoryLabel);
|
|
|
|
|
|
QHBoxLayout *smoothingRow = new QHBoxLayout;
|
|
|
|
|
|
const auto limitSpin = [replayPanel, smoothingRow](const QString &text, double initial, const QString &unit) {
|
|
|
|
|
|
smoothingRow->addWidget(new QLabel(text, replayPanel));
|
|
|
|
|
|
auto *spin = new QDoubleSpinBox(replayPanel);
|
|
|
|
|
|
spin->setRange(0.001, 100);
|
|
|
|
|
|
spin->setDecimals(3);
|
|
|
|
|
|
spin->setValue(initial);
|
|
|
|
|
|
spin->setSuffix(unit);
|
|
|
|
|
|
smoothingRow->addWidget(spin, 1);
|
|
|
|
|
|
return spin;
|
|
|
|
|
|
};
|
|
|
|
|
|
m_trajectoryVelocitySpin = limitSpin(QStringLiteral("最大速度"), 0.3, QStringLiteral(" rad/s"));
|
|
|
|
|
|
m_trajectoryAccelerationSpin = limitSpin(QStringLiteral("加速度"), 0.5, QStringLiteral(" rad/s²"));
|
|
|
|
|
|
m_trajectoryJerkSpin = limitSpin(QStringLiteral("加加速度"), 2.0, QStringLiteral(" rad/s³"));
|
|
|
|
|
|
replayLayout->addLayout(smoothingRow);
|
|
|
|
|
|
auto *smoothingHint = new QLabel(QStringLiteral(
|
|
|
|
|
|
"BSplineSmoother 平滑后回放,首尾保持不变;中间路径及停顿节奏可能变化,时长可能延长。"), replayPanel);
|
|
|
|
|
|
smoothingHint->setObjectName(QStringLiteral("mutedLabel"));
|
|
|
|
|
|
smoothingHint->setWordWrap(true);
|
|
|
|
|
|
replayLayout->addWidget(smoothingHint);
|
|
|
|
|
|
QHBoxLayout *replayActions = new QHBoxLayout;
|
|
|
|
|
|
m_trajectoryReplayRatioSpin = new QDoubleSpinBox(replayPanel);
|
|
|
|
|
|
m_trajectoryReplayRatioSpin->setRange(10, 100);
|
|
|
|
|
|
m_trajectoryReplayRatioSpin->setDecimals(0);
|
|
|
|
|
|
m_trajectoryReplayRatioSpin->setValue(100);
|
|
|
|
|
|
m_trajectoryReplayRatioSpin->setSuffix(QStringLiteral(" %"));
|
|
|
|
|
|
replayActions->addWidget(new QLabel(QStringLiteral("回放速度"), replayPanel));
|
|
|
|
|
|
replayActions->addWidget(m_trajectoryReplayRatioSpin);
|
|
|
|
|
|
replayActions->addStretch();
|
|
|
|
|
|
m_trajectoryStartButton = new QPushButton(QStringLiteral("到轨迹起点"), replayPanel);
|
|
|
|
|
|
m_trajectoryStartButton->setObjectName(QStringLiteral("trajectoryStartButton"));
|
|
|
|
|
|
m_trajectoryReplayButton = new QPushButton(QStringLiteral("回放轨迹"), replayPanel);
|
|
|
|
|
|
m_trajectoryReplayButton->setObjectName(QStringLiteral("primaryButton"));
|
|
|
|
|
|
m_trajectoryStopButton = new QPushButton(QStringLiteral("停止运动"), replayPanel);
|
|
|
|
|
|
m_trajectoryStopButton->setObjectName(QStringLiteral("dangerButton"));
|
|
|
|
|
|
replayActions->addWidget(m_trajectoryStartButton);
|
|
|
|
|
|
replayActions->addWidget(m_trajectoryReplayButton);
|
|
|
|
|
|
replayActions->addWidget(m_trajectoryStopButton);
|
|
|
|
|
|
replayLayout->addLayout(replayActions);
|
|
|
|
|
|
m_trajectoryStatusTimer = new QTimer(this);
|
|
|
|
|
|
m_trajectoryStatusTimer->setInterval(1000);
|
|
|
|
|
|
connect(m_trajectoryStatusTimer, &QTimer::timeout, this, [this, deviceTeachingPage] {
|
|
|
|
|
|
if (m_connected && deviceTeachingPage->isVisible())
|
|
|
|
|
|
m_client->requestRecordedTrajectories(m_armIdEdit->text().trimmed());
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_refreshTrajectoriesButton, &QPushButton::clicked, this, [this] {
|
|
|
|
|
|
m_client->requestRecordedTrajectories(m_armIdEdit->text().trimmed());
|
|
|
|
|
|
});
|
|
|
|
|
|
const auto replay = [this](bool toStart) {
|
|
|
|
|
|
const QString file = m_recordedTrajectoryCombo->currentData().toString();
|
|
|
|
|
|
if (file.isEmpty()) {
|
|
|
|
|
|
m_deviceTeachingStateLabel->setText(QStringLiteral("请刷新并选择 CSV 轨迹")); return;
|
|
|
|
|
|
}
|
|
|
|
|
|
const QString prompt = toStart
|
2026-11-04 15:00:14 +08:00
|
|
|
|
? QStringLiteral("机械臂将按速度上限 %1 rad/s、加速度上限 %2 rad/s²、加加速度上限 %3 rad/s³ 平滑移动到轨迹起点。请确认路径和现场安全。")
|
|
|
|
|
|
.arg(m_trajectoryVelocitySpin->value())
|
|
|
|
|
|
.arg(m_trajectoryAccelerationSpin->value())
|
|
|
|
|
|
.arg(m_trajectoryJerkSpin->value())
|
2026-10-29 11:46:39 +08:00
|
|
|
|
: QStringLiteral("即将回放 %1,速度 %2%。请确认已退出示教、到达起点且现场安全。")
|
|
|
|
|
|
.arg(file).arg(m_trajectoryReplayRatioSpin->value());
|
|
|
|
|
|
if (AppMessageBox::warning(this, QStringLiteral("确认机械臂运动"), prompt,
|
|
|
|
|
|
AppMessageBox::Yes | AppMessageBox::Cancel,
|
|
|
|
|
|
AppMessageBox::Cancel) != AppMessageBox::Yes) return;
|
|
|
|
|
|
m_deviceTeachingStateLabel->setText(toStart ? QStringLiteral("正在到轨迹起点") : QStringLiteral("正在回放轨迹"));
|
|
|
|
|
|
m_client->requestReplayTrajectory(m_armIdEdit->text().trimmed(), file,
|
|
|
|
|
|
m_trajectoryReplayRatioSpin->value() / 100.0, toStart,
|
|
|
|
|
|
{{"velocity", m_trajectoryVelocitySpin->value()}, {"acceleration", m_trajectoryAccelerationSpin->value()},
|
|
|
|
|
|
{"jerk", m_trajectoryJerkSpin->value()}});
|
|
|
|
|
|
};
|
|
|
|
|
|
connect(m_trajectoryStartButton, &QPushButton::clicked, this, [replay] { replay(true); });
|
|
|
|
|
|
connect(m_trajectoryReplayButton, &QPushButton::clicked, this, [replay] { replay(false); });
|
|
|
|
|
|
connect(m_trajectoryStopButton, &QPushButton::clicked, this, [this] {
|
|
|
|
|
|
m_client->requestArmStop(m_armIdEdit->text().trimmed());
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_client, &RobotClient::recordedTrajectoriesReceived, this,
|
|
|
|
|
|
[this](const QString &id, const QVariantList &files, const QVariantMap &state, bool success, const QString &detail) {
|
|
|
|
|
|
if (id != m_armIdEdit->text().trimmed()) return;
|
|
|
|
|
|
if (!success) {
|
|
|
|
|
|
m_trajectoryStatusTimer->stop();
|
|
|
|
|
|
m_trajectoryRecordingStatus->setText(QStringLiteral("读取轨迹失败:%1").arg(detail));
|
|
|
|
|
|
m_recordedTrajectoryCombo->clear();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
const QString selected = m_recordedTrajectoryCombo->currentData().toString();
|
|
|
|
|
|
const QSignalBlocker blocker(m_recordedTrajectoryCombo);
|
|
|
|
|
|
m_recordedTrajectoryCombo->clear();
|
|
|
|
|
|
for (const auto &value : files) {
|
|
|
|
|
|
const auto row = value.toMap();
|
|
|
|
|
|
m_recordedTrajectoryCombo->addItem(QStringLiteral("%1 · %2 s · %3 点 · %4 Hz")
|
|
|
|
|
|
.arg(row.value("fileName").toString()).arg(row.value("duration").toDouble(), 0, 'f', 2)
|
|
|
|
|
|
.arg(row.value("samples").toULongLong()).arg(row.value("frequency").toDouble()), row.value("fileName"));
|
|
|
|
|
|
}
|
|
|
|
|
|
const int index = m_recordedTrajectoryCombo->findData(selected);
|
|
|
|
|
|
if (index >= 0) m_recordedTrajectoryCombo->setCurrentIndex(index);
|
|
|
|
|
|
m_trajectoryDirectoryLabel->setText(QStringLiteral("服务端目录:%1").arg(state.value("directory").toString()));
|
|
|
|
|
|
const QString error = state.value("error").toString();
|
|
|
|
|
|
m_trajectoryRecordingStatus->setText(!error.isEmpty() ? QStringLiteral("录制异常:%1").arg(error)
|
|
|
|
|
|
: state.value("recording").toBool() ? QStringLiteral("正在记录 %1 · %2 点")
|
|
|
|
|
|
.arg(state.value("fileName").toString()).arg(state.value("samples").toULongLong())
|
|
|
|
|
|
: QStringLiteral("未在录制 · %1 份可回放轨迹").arg(files.size()));
|
|
|
|
|
|
if (state.value("recording").toBool()) m_trajectoryStatusTimer->start();
|
|
|
|
|
|
else m_trajectoryStatusTimer->stop();
|
|
|
|
|
|
});
|
|
|
|
|
|
m_trajectoryFileNameEdit->show();
|
|
|
|
|
|
m_deviceTeachingStateLabel->show();
|
|
|
|
|
|
deviceTeachingLayout->addWidget(deviceTeachingPanel);
|
|
|
|
|
|
deviceTeachingLayout->addWidget(replayPanel);
|
|
|
|
|
|
deviceTeachingLayout->addStretch(1);
|
|
|
|
|
|
ui.armTabs->addTab(deviceTeachingPage, QStringLiteral("拖动示教"));
|
2026-11-04 15:00:14 +08:00
|
|
|
|
auto *userCoordinates = new UserCoordinateWidget(m_client, ui.armTabs);
|
|
|
|
|
|
ui.armTabs->addTab(userCoordinates, QStringLiteral("自定义坐标系"));
|
|
|
|
|
|
struct CoordinateConnection { QString requestedEndpoint; bool ready=false; };
|
|
|
|
|
|
const auto coordinateConnection=std::make_shared<CoordinateConnection>();
|
|
|
|
|
|
const auto syncUserCoordinates = [this,userCoordinates,coordinateConnection] {
|
|
|
|
|
|
userCoordinates->setContext(endpoint(),m_armIdEdit->text().trimmed(),
|
|
|
|
|
|
coordinateConnection->ready && coordinateConnection->requestedEndpoint==endpoint());
|
|
|
|
|
|
};
|
|
|
|
|
|
connect(m_armIdEdit,&QLineEdit::textChanged,userCoordinates,[syncUserCoordinates](const QString&){syncUserCoordinates();});
|
|
|
|
|
|
connect(m_hostEdit,&QLineEdit::textChanged,userCoordinates,[syncUserCoordinates](const QString&){syncUserCoordinates();});
|
|
|
|
|
|
connect(m_portSpin,QOverload<int>::of(&QSpinBox::valueChanged),userCoordinates,[syncUserCoordinates](int){syncUserCoordinates();});
|
|
|
|
|
|
connect(m_client,&RobotClient::connectRequested,userCoordinates,
|
|
|
|
|
|
[coordinateConnection,syncUserCoordinates](const QString &host,int port,bool){
|
|
|
|
|
|
coordinateConnection->requestedEndpoint=QStringLiteral("%1:%2").arg(host.trimmed()).arg(port);
|
|
|
|
|
|
coordinateConnection->ready=false;syncUserCoordinates();
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_client,&RobotClient::connectionChanged,userCoordinates,
|
|
|
|
|
|
[coordinateConnection,syncUserCoordinates](bool connected,int,const QString&){coordinateConnection->ready=connected;syncUserCoordinates();});
|
|
|
|
|
|
syncUserCoordinates();
|
2026-10-29 11:46:39 +08:00
|
|
|
|
connect(m_armIdEdit, &QLineEdit::textChanged, this, [this]() {
|
|
|
|
|
|
m_deviceTeachingStateLabel->setText(QStringLiteral("尚未操作"));
|
|
|
|
|
|
m_deviceTeachingStateLabel->setToolTip(QString());
|
|
|
|
|
|
m_trajectoryStatusTimer->stop();
|
|
|
|
|
|
m_recordedTrajectoryCombo->clear();
|
|
|
|
|
|
m_trajectoryRecordingStatus->setText(QStringLiteral("尚未读取录制状态"));
|
|
|
|
|
|
m_trajectoryDirectoryLabel->setText(QStringLiteral("保存目录:待读取"));
|
|
|
|
|
|
});
|
2026-09-23 11:11:49 +08:00
|
|
|
|
ui.armTabs->addTab(new RpcServiceWidget(QStringLiteral("cmvr.api.ArmService"), m_client),
|
|
|
|
|
|
QStringLiteral("全部接口"));
|
|
|
|
|
|
ui.armTabs->setCurrentWidget(ui.urdfTab);
|
2026-09-18 16:22:20 +08:00
|
|
|
|
|
|
|
|
|
|
m_torqueOnButton->setIcon(UiIcons::icon(QStringLiteral(":/icons/power.svg")));
|
|
|
|
|
|
m_torqueOffButton->setIcon(UiIcons::icon(QStringLiteral(":/icons/power-off.svg")));
|
|
|
|
|
|
m_clearFaultButton->setIcon(UiIcons::icon(QStringLiteral(":/icons/shield-check.svg")));
|
|
|
|
|
|
m_calibrateZeroButton->setIcon(UiIcons::icon(QStringLiteral(":/icons/crosshair.svg")));
|
|
|
|
|
|
m_stopButton->setIcon(UiIcons::icon(QStringLiteral(":/icons/square.svg"), Qt::white,
|
|
|
|
|
|
Qt::white, QColor(QStringLiteral("#f4dddd"))));
|
2026-10-14 17:15:46 +08:00
|
|
|
|
m_sendMoveButton->setIcon(UiIcons::icon(QStringLiteral(":/icons/send.svg"), Qt::white,
|
|
|
|
|
|
Qt::white, QColor(QStringLiteral("#e8eef5"))));
|
2026-09-23 11:11:49 +08:00
|
|
|
|
m_jogStopButton->setIcon(UiIcons::icon(QStringLiteral(":/icons/square.svg"),
|
|
|
|
|
|
QColor(QStringLiteral("#cc3434"))));
|
2026-09-18 16:22:20 +08:00
|
|
|
|
connect(m_armIdEdit, &QLineEdit::textChanged, m_armDeviceSummary,
|
|
|
|
|
|
&QLabel::setText);
|
|
|
|
|
|
connect(m_armGlobalStopButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
const QString target = m_armIdEdit->text().trimmed();
|
|
|
|
|
|
m_client->requestSystemStopAll(target.isEmpty() ? QStringLiteral("*") : target);
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_armTelemetryButton, &QPushButton::clicked, this, [this](bool enabled) {
|
2026-10-14 17:15:46 +08:00
|
|
|
|
if (enabled && m_armIdEdit->text().trimmed().isEmpty()) {
|
2026-10-16 09:39:44 +08:00
|
|
|
|
AppMessageBox::warning(this, QStringLiteral("ArmService"),
|
2026-10-14 17:15:46 +08:00
|
|
|
|
QStringLiteral("请先选择机械臂设备。"));
|
|
|
|
|
|
setArmTelemetryEnabled(false);
|
2026-09-18 16:22:20 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-10-14 17:15:46 +08:00
|
|
|
|
setArmTelemetryEnabled(enabled);
|
2026-09-18 16:22:20 +08:00
|
|
|
|
});
|
|
|
|
|
|
connect(m_torqueOnButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->requestTorque(m_armIdEdit->text().trimmed(), true);
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_torqueOffButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->requestTorque(m_armIdEdit->text().trimmed(), false);
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_clearFaultButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->requestArmClearFault(m_armIdEdit->text().trimmed());
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_calibrateZeroButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
const QString deviceId = m_armIdEdit->text().trimmed();
|
|
|
|
|
|
const QString jointName = m_zeroJointCombo->currentText().trimmed();
|
|
|
|
|
|
if (deviceId.isEmpty()) {
|
2026-10-16 09:39:44 +08:00
|
|
|
|
AppMessageBox::warning(this, QStringLiteral("零位标定"),
|
2026-09-18 16:22:20 +08:00
|
|
|
|
QStringLiteral("请先填写机械臂设备 ID。"));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (jointName.isEmpty()) {
|
2026-10-16 09:39:44 +08:00
|
|
|
|
AppMessageBox::warning(this, QStringLiteral("零位标定"),
|
2026-09-18 16:22:20 +08:00
|
|
|
|
QStringLiteral("请选择需要设置零位的关节。"));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
const QString prompt = QStringLiteral(
|
|
|
|
|
|
"即将把设备 %1 的关节 %2 当前位置设置为零位。\n\n"
|
|
|
|
|
|
"该操作会改变关节坐标基准,是否继续?")
|
|
|
|
|
|
.arg(deviceId, jointName);
|
2026-10-16 09:39:44 +08:00
|
|
|
|
if (AppMessageBox::warning(this, QStringLiteral("确认零位标定"), prompt,
|
|
|
|
|
|
AppMessageBox::Yes | AppMessageBox::Cancel,
|
|
|
|
|
|
AppMessageBox::Cancel) != AppMessageBox::Yes) {
|
2026-09-18 16:22:20 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
m_client->requestArmCalibrateZero(deviceId, jointName);
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_stopButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->requestArmStop(m_armIdEdit->text().trimmed());
|
|
|
|
|
|
});
|
2026-10-26 17:35:27 +08:00
|
|
|
|
connect(m_enterTeachingButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->requestEnterTeachingMode(m_armIdEdit->text().trimmed());
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_startTrajectoryRecordingButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->requestStartTrajectoryRecording(m_armIdEdit->text().trimmed(),
|
2026-10-29 11:46:39 +08:00
|
|
|
|
m_trajectoryFileNameEdit->text().trimmed(),
|
|
|
|
|
|
m_trajectoryFrequencySpin->value());
|
2026-10-26 17:35:27 +08:00
|
|
|
|
});
|
|
|
|
|
|
connect(m_completeTeachingButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->requestCompleteTeaching(m_armIdEdit->text().trimmed());
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_stopTrajectoryRecordingButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->requestStopTrajectoryRecording(m_armIdEdit->text().trimmed());
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_exitTeachingButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->requestExitTeachingMode(m_armIdEdit->text().trimmed());
|
|
|
|
|
|
});
|
2026-10-14 17:15:46 +08:00
|
|
|
|
connect(ui.zeroButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
for (QDoubleSpinBox *spin : m_targetSpins)
|
|
|
|
|
|
spin->setValue(0.0);
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_syncCurrentToTargetButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
QStringList missing;
|
|
|
|
|
|
for (int row = 0; row < m_activeArmJointNames.size(); ++row) {
|
|
|
|
|
|
const QString &jointName = m_activeArmJointNames.at(row);
|
|
|
|
|
|
if (!m_latestArmJointPositions.contains(jointName)
|
|
|
|
|
|
|| row >= m_targetRadianSpins.size()) {
|
|
|
|
|
|
missing.append(jointName);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
m_targetRadianSpins.at(row)->setValue(
|
|
|
|
|
|
m_latestArmJointPositions.value(jointName));
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!missing.isEmpty()) {
|
2026-10-16 09:39:44 +08:00
|
|
|
|
AppMessageBox::warning(this, QStringLiteral("同步当前位置"),
|
2026-10-14 17:15:46 +08:00
|
|
|
|
QStringLiteral("以下关节尚无遥测位置:\n%1\n\n请先启动遥测。")
|
|
|
|
|
|
.arg(missing.join(QStringLiteral(", "))));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
appendLog(QStringLiteral("OK"),
|
|
|
|
|
|
QStringLiteral("已将 %1 个关节的遥测位置同步到 MoveJ 目标")
|
|
|
|
|
|
.arg(m_activeArmJointNames.size()));
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_sendMoveButton, &QPushButton::clicked, this, &MainWindow::sendMoveJ);
|
2026-09-23 11:11:49 +08:00
|
|
|
|
connect(m_jogStopButton, &QPushButton::clicked, this, &MainWindow::stopArmJog);
|
|
|
|
|
|
connect(m_jogSpeedSlider, &QSlider::valueChanged, this, [this](int value) {
|
|
|
|
|
|
m_jogSpeedValue->setText(QStringLiteral("%1%").arg(value));
|
2026-09-18 16:22:20 +08:00
|
|
|
|
});
|
2026-10-26 17:35:27 +08:00
|
|
|
|
connect(m_jogModeTabs, &QTabWidget::currentChanged, this, [this](int) {
|
|
|
|
|
|
if (m_armJogActive) stopArmJog();
|
|
|
|
|
|
if (m_tcpJog) m_tcpJog->stop();
|
2026-09-18 16:22:20 +08:00
|
|
|
|
});
|
2026-09-23 11:11:49 +08:00
|
|
|
|
connect(m_client, &RobotClient::armFramesReceived, this,
|
2026-10-14 17:15:46 +08:00
|
|
|
|
[this](const QString &deviceId,
|
2026-09-23 11:11:49 +08:00
|
|
|
|
const QStringList &baseFrames,
|
|
|
|
|
|
const QStringList &tcpFrames) {
|
2026-10-14 17:15:46 +08:00
|
|
|
|
if (!m_connected || !m_armIdEdit || deviceId != m_armIdEdit->text().trimmed())
|
2026-09-18 16:22:20 +08:00
|
|
|
|
return;
|
2026-09-23 11:11:49 +08:00
|
|
|
|
const auto fillFrames = [](QComboBox *combo, const QStringList &frames,
|
|
|
|
|
|
const QString &preferred, const QString &fallback) {
|
|
|
|
|
|
if (!combo)
|
|
|
|
|
|
return;
|
|
|
|
|
|
const QString previous = combo->currentText();
|
|
|
|
|
|
const QSignalBlocker blocker(combo);
|
|
|
|
|
|
combo->clear();
|
|
|
|
|
|
combo->addItems(frames);
|
|
|
|
|
|
if (combo->count() == 0)
|
|
|
|
|
|
combo->addItem(preferred.isEmpty() ? fallback : preferred);
|
|
|
|
|
|
const QString wanted = previous.isEmpty() ? preferred : previous;
|
|
|
|
|
|
const int index = combo->findText(wanted);
|
|
|
|
|
|
combo->setCurrentIndex(index >= 0 ? index : 0);
|
2026-09-18 16:22:20 +08:00
|
|
|
|
};
|
2026-09-23 11:11:49 +08:00
|
|
|
|
fillFrames(m_baseFrameCombo, baseFrames, m_armDefaultBaseFrame,
|
|
|
|
|
|
QStringLiteral("base"));
|
2026-10-16 09:39:44 +08:00
|
|
|
|
m_controllerBaseFrames = baseFrames;
|
2026-10-14 17:15:46 +08:00
|
|
|
|
m_controllerTcpFrames = tcpFrames;
|
|
|
|
|
|
refreshTcpChoices();
|
|
|
|
|
|
});
|
2026-09-23 11:11:49 +08:00
|
|
|
|
connect(m_baseFrameCombo, &QComboBox::currentTextChanged, this,
|
2026-10-14 17:15:46 +08:00
|
|
|
|
[this](const QString &) { updateArmPoseFrames(); });
|
2026-09-23 11:11:49 +08:00
|
|
|
|
connect(m_tcpFrameCombo, &QComboBox::currentTextChanged, this,
|
2026-10-14 17:15:46 +08:00
|
|
|
|
[this](const QString &) {
|
|
|
|
|
|
updateArmPoseFrames();
|
|
|
|
|
|
QSettings settings; QString error;
|
|
|
|
|
|
const QString name = selectedLocalTcp() ? m_tcpFrameCombo->currentData().toString().mid(6) : QString();
|
|
|
|
|
|
if (!m_armIdEdit->text().trimmed().isEmpty()
|
|
|
|
|
|
&& !TcpToolStore::select(settings,endpoint(),m_armIdEdit->text().trimmed(),name,error))
|
|
|
|
|
|
appendLog(QStringLiteral("ERROR"),error);
|
|
|
|
|
|
});
|
2026-09-18 16:22:20 +08:00
|
|
|
|
connect(m_urdfViewer, &UrdfViewerWidget::logMessage,
|
|
|
|
|
|
this, &MainWindow::appendLog);
|
|
|
|
|
|
|
2026-10-14 17:15:46 +08:00
|
|
|
|
m_jointTable->setColumnCount(5);
|
2026-09-18 16:22:20 +08:00
|
|
|
|
m_jointTable->setHorizontalHeaderLabels({QStringLiteral("关节"), QStringLiteral("位置 rad"),
|
2026-10-14 17:15:46 +08:00
|
|
|
|
QStringLiteral("速度 rad/s"), QStringLiteral("加速度 rad/s²"),
|
|
|
|
|
|
QStringLiteral("电流 mA")});
|
2026-09-18 16:22:20 +08:00
|
|
|
|
m_jointTable->setAlternatingRowColors(true);
|
|
|
|
|
|
m_jointTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
|
|
m_jointTable->setSelectionMode(QAbstractItemView::NoSelection);
|
|
|
|
|
|
m_jointTable->verticalHeader()->setVisible(false);
|
|
|
|
|
|
m_jointTable->verticalHeader()->setDefaultSectionSize(28);
|
|
|
|
|
|
m_jointTable->horizontalHeader()->setStretchLastSection(true);
|
|
|
|
|
|
|
2026-10-14 17:15:46 +08:00
|
|
|
|
m_motionTable->setColumnCount(5);
|
|
|
|
|
|
m_motionTable->setHorizontalHeaderLabels({
|
|
|
|
|
|
QStringLiteral("关节"), QStringLiteral("当前位置 (°)"),
|
|
|
|
|
|
QStringLiteral("当前位置 (rad)"), QStringLiteral("目标角度 (°)"),
|
|
|
|
|
|
QStringLiteral("目标弧度 (rad)")});
|
|
|
|
|
|
m_motionTable->setAlternatingRowColors(true);
|
|
|
|
|
|
m_motionTable->setSelectionMode(QAbstractItemView::NoSelection);
|
|
|
|
|
|
m_motionTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
|
|
m_motionTable->verticalHeader()->setVisible(false);
|
|
|
|
|
|
m_motionTable->verticalHeader()->setDefaultSectionSize(38);
|
|
|
|
|
|
m_motionTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
|
|
|
|
|
m_motionTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
|
|
|
|
|
|
m_motionTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
|
|
|
|
|
|
m_motionTable->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Stretch);
|
|
|
|
|
|
m_motionTable->horizontalHeader()->setSectionResizeMode(4, QHeaderView::Stretch);
|
|
|
|
|
|
|
2026-09-23 11:11:49 +08:00
|
|
|
|
m_activeArmJointNames.clear();
|
|
|
|
|
|
m_jointTable->setRowCount(0);
|
|
|
|
|
|
m_zeroJointCombo->clear();
|
2026-10-14 17:15:46 +08:00
|
|
|
|
rebuildArmJogControls();
|
2026-09-18 16:22:20 +08:00
|
|
|
|
|
|
|
|
|
|
connect(m_armSideCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
2026-09-23 11:11:49 +08:00
|
|
|
|
[this, poseSubtitle = ui.poseSubtitle](int) {
|
2026-09-18 16:22:20 +08:00
|
|
|
|
const QString oldDeviceId = m_armIdEdit->text().trimmed();
|
2026-09-23 11:11:49 +08:00
|
|
|
|
const QString newDeviceId = m_armSideCombo->currentData().toString().trimmed();
|
|
|
|
|
|
if (newDeviceId.isEmpty() || newDeviceId == oldDeviceId)
|
|
|
|
|
|
return;
|
2026-10-26 17:35:27 +08:00
|
|
|
|
setArmTelemetryEnabled(false);
|
2026-09-23 11:11:49 +08:00
|
|
|
|
m_armIdEdit->setText(newDeviceId);
|
|
|
|
|
|
m_activeArmJointNames.clear();
|
2026-10-14 17:15:46 +08:00
|
|
|
|
m_latestArmJointPositions.clear();
|
2026-09-23 11:11:49 +08:00
|
|
|
|
m_jointTable->setRowCount(0);
|
2026-10-14 17:15:46 +08:00
|
|
|
|
m_targetSpins.clear();
|
|
|
|
|
|
m_targetRadianSpins.clear();
|
|
|
|
|
|
m_motionTable->clearContents();
|
|
|
|
|
|
m_motionTable->setRowCount(0);
|
|
|
|
|
|
m_sendMoveButton->setEnabled(false);
|
|
|
|
|
|
m_syncCurrentToTargetButton->setEnabled(false);
|
2026-09-23 11:11:49 +08:00
|
|
|
|
rebuildArmJogControls();
|
|
|
|
|
|
m_zeroJointCombo->clear();
|
2026-10-16 09:39:44 +08:00
|
|
|
|
m_controllerBaseFrames.clear();
|
|
|
|
|
|
m_controllerTcpFrames.clear();
|
2026-09-23 11:11:49 +08:00
|
|
|
|
m_armDefaultBaseFrame.clear();
|
|
|
|
|
|
m_armDefaultTcpFrame.clear();
|
2026-10-16 09:39:44 +08:00
|
|
|
|
refreshTcpChoices();
|
2026-09-18 16:22:20 +08:00
|
|
|
|
m_latestArmPose.clear();
|
2026-09-23 16:04:01 +08:00
|
|
|
|
for (QLabel *valueLabel : m_poseMetricValues)
|
|
|
|
|
|
valueLabel->setText(QStringLiteral("--"));
|
2026-09-23 11:11:49 +08:00
|
|
|
|
poseSubtitle->setText(QStringLiteral("等待 SDK 默认坐标系信息"));
|
|
|
|
|
|
if (m_connected) {
|
|
|
|
|
|
m_client->requestArmInfo(newDeviceId);
|
2026-09-18 16:22:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
m_serviceButtons << m_armTelemetryButton << m_armGlobalStopButton
|
|
|
|
|
|
<< m_torqueOnButton << m_torqueOffButton
|
2026-10-29 11:46:39 +08:00
|
|
|
|
<< m_clearFaultButton << frameDiscoveryButton << m_calibrateZeroButton
|
2026-10-14 17:15:46 +08:00
|
|
|
|
<< m_stopButton << m_jogStopButton << m_sendMoveButton
|
2026-10-26 17:35:27 +08:00
|
|
|
|
<< m_syncCurrentToTargetButton << m_enterTeachingButton
|
|
|
|
|
|
<< m_startTrajectoryRecordingButton << m_completeTeachingButton
|
|
|
|
|
|
<< m_stopTrajectoryRecordingButton << m_exitTeachingButton;
|
2026-10-29 11:46:39 +08:00
|
|
|
|
m_serviceButtons << m_refreshTrajectoriesButton << m_trajectoryStartButton
|
|
|
|
|
|
<< m_trajectoryReplayButton << m_trajectoryStopButton;
|
2026-09-18 16:22:20 +08:00
|
|
|
|
return page;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QStringList MainWindow::configuredCameraIds() const
|
|
|
|
|
|
{
|
2026-10-14 17:15:46 +08:00
|
|
|
|
if (!m_cameraDeviceCombo)
|
2026-09-18 16:22:20 +08:00
|
|
|
|
return {};
|
2026-10-14 17:15:46 +08:00
|
|
|
|
const QString cameraId = m_cameraDeviceCombo->currentData().toString().trimmed();
|
|
|
|
|
|
return cameraId.isEmpty() ? QStringList() : QStringList{cameraId};
|
2026-09-18 16:22:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::rebuildCameraPreviewGrid(const QStringList &cameraIds)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!m_cameraPreviewGrid || !m_cameraPreviewContainer)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
QSet<QString> requested;
|
|
|
|
|
|
for (const QString &cameraId : cameraIds)
|
|
|
|
|
|
requested.insert(cameraId);
|
|
|
|
|
|
const QStringList existingIds = m_cameraPreviewTiles.keys();
|
|
|
|
|
|
for (const QString &cameraId : existingIds) {
|
|
|
|
|
|
if (requested.contains(cameraId))
|
|
|
|
|
|
continue;
|
|
|
|
|
|
CameraPreviewTile tile = m_cameraPreviewTiles.take(cameraId);
|
|
|
|
|
|
m_cameraPreviewGrid->removeWidget(tile.container);
|
|
|
|
|
|
delete tile.container;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (const QString &cameraId : cameraIds) {
|
|
|
|
|
|
if (m_cameraPreviewTiles.contains(cameraId))
|
|
|
|
|
|
continue;
|
|
|
|
|
|
CameraPreviewTile tile;
|
|
|
|
|
|
QFrame *container = new QFrame(m_cameraPreviewContainer);
|
|
|
|
|
|
container->setObjectName(QStringLiteral("cameraPreviewTile"));
|
|
|
|
|
|
container->setFrameShape(QFrame::StyledPanel);
|
|
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout(container);
|
|
|
|
|
|
layout->setContentsMargins(8, 8, 8, 8);
|
|
|
|
|
|
layout->setSpacing(6);
|
|
|
|
|
|
|
|
|
|
|
|
QHBoxLayout *header = new QHBoxLayout;
|
|
|
|
|
|
QLabel *title = new QLabel(cameraId, container);
|
|
|
|
|
|
title->setObjectName(QStringLiteral("sectionTitle"));
|
|
|
|
|
|
QLabel *status = new QLabel(QStringLiteral("已停止"), container);
|
|
|
|
|
|
status->setObjectName(QStringLiteral("panelSubtitle"));
|
|
|
|
|
|
header->addWidget(title);
|
|
|
|
|
|
header->addStretch(1);
|
|
|
|
|
|
header->addWidget(status);
|
|
|
|
|
|
|
|
|
|
|
|
VideoRenderWidget *render = new VideoRenderWidget(container);
|
|
|
|
|
|
render->setObjectName(QStringLiteral("imageView"));
|
|
|
|
|
|
render->setMinimumSize(280, 180);
|
|
|
|
|
|
render->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
|
|
render->clearFrame(QStringLiteral("等待视频流"));
|
|
|
|
|
|
QLabel *meta = new QLabel(QStringLiteral("等待连接"), container);
|
|
|
|
|
|
meta->setObjectName(QStringLiteral("panelSubtitle"));
|
|
|
|
|
|
meta->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
|
|
|
|
|
|
|
|
|
|
|
layout->addLayout(header);
|
|
|
|
|
|
layout->addWidget(render, 1);
|
|
|
|
|
|
layout->addWidget(meta);
|
|
|
|
|
|
tile.container = container;
|
|
|
|
|
|
tile.render = render;
|
|
|
|
|
|
tile.status = status;
|
|
|
|
|
|
tile.meta = meta;
|
|
|
|
|
|
m_cameraPreviewTiles.insert(cameraId, tile);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (const QString &cameraId : cameraIds)
|
|
|
|
|
|
m_cameraPreviewGrid->removeWidget(m_cameraPreviewTiles.value(cameraId).container);
|
|
|
|
|
|
const int columns = cameraIds.size() <= 1 ? 1 : 2;
|
|
|
|
|
|
for (int index = 0; index < cameraIds.size(); ++index) {
|
|
|
|
|
|
CameraPreviewTile &tile = m_cameraPreviewTiles[cameraIds.at(index)];
|
|
|
|
|
|
m_cameraPreviewGrid->addWidget(tile.container, index / columns, index % columns);
|
|
|
|
|
|
}
|
|
|
|
|
|
for (int column = 0; column < 2; ++column)
|
|
|
|
|
|
m_cameraPreviewGrid->setColumnStretch(column, column < columns ? 1 : 0);
|
|
|
|
|
|
|
|
|
|
|
|
m_videoRender = cameraIds.isEmpty()
|
|
|
|
|
|
? nullptr : m_cameraPreviewTiles.value(cameraIds.first()).render;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-16 09:39:44 +08:00
|
|
|
|
void MainWindow::refreshCameraDepthControls()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!m_cameraStreamModeCombo || !m_cameraDeviceCombo) return;
|
|
|
|
|
|
const QString cameraId = m_cameraDeviceCombo->currentData().toString();
|
|
|
|
|
|
const QVariantMap capabilities = m_cameraCapabilitiesById.value(cameraId);
|
|
|
|
|
|
const bool depth = CameraCapabilities::depthStream(capabilities);
|
|
|
|
|
|
if (m_depthSnapshotButton)
|
|
|
|
|
|
m_depthSnapshotButton->setVisible(CameraCapabilities::depthImage(capabilities));
|
|
|
|
|
|
const QString previousMode = m_cameraStreamModeCombo->currentData().toString();
|
|
|
|
|
|
const QSignalBlocker blocker(m_cameraStreamModeCombo);
|
|
|
|
|
|
if (!depth) {
|
|
|
|
|
|
for (int i = m_cameraStreamModeCombo->count() - 1; i >= 0; --i)
|
|
|
|
|
|
if (m_cameraStreamModeCombo->itemData(i).toString() != QStringLiteral("rgb"))
|
|
|
|
|
|
m_cameraStreamModeCombo->removeItem(i);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (m_cameraStreamModeCombo->findData(QStringLiteral("depth")) < 0)
|
|
|
|
|
|
m_cameraStreamModeCombo->addItem(QStringLiteral("深度"), QStringLiteral("depth"));
|
|
|
|
|
|
if (m_cameraStreamModeCombo->findData(QStringLiteral("rgbd")) < 0)
|
|
|
|
|
|
m_cameraStreamModeCombo->addItem(QStringLiteral("RGB + 深度"), QStringLiteral("rgbd"));
|
|
|
|
|
|
}
|
|
|
|
|
|
const int index = m_cameraStreamModeCombo->findData(previousMode);
|
|
|
|
|
|
m_cameraStreamModeCombo->setCurrentIndex(index >= 0 ? index : 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-18 16:22:20 +08:00
|
|
|
|
void MainWindow::refreshCameraStreamControls()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_cameraStreaming = !m_runningCameraIds.isEmpty();
|
|
|
|
|
|
m_cameraStreamButton->setEnabled(m_connected);
|
|
|
|
|
|
m_cameraStreamButton->setText(m_cameraStreaming ? QStringLiteral("停止全部预览")
|
|
|
|
|
|
: QStringLiteral("开始预览"));
|
|
|
|
|
|
m_cameraStreamButton->setIcon(style()->standardIcon(
|
|
|
|
|
|
m_cameraStreaming ? QStyle::SP_MediaStop : QStyle::SP_MediaPlay));
|
|
|
|
|
|
m_cameraStreamButton->setObjectName(m_cameraStreaming
|
|
|
|
|
|
? QStringLiteral("dangerButton") : QStringLiteral("primaryButton"));
|
|
|
|
|
|
m_cameraStreamButton->style()->unpolish(m_cameraStreamButton);
|
|
|
|
|
|
m_cameraStreamButton->style()->polish(m_cameraStreamButton);
|
2026-10-14 17:15:46 +08:00
|
|
|
|
m_cameraDeviceCombo->setEnabled(!m_cameraStreaming && !m_cameraRecording
|
|
|
|
|
|
&& m_cameraDeviceCombo->count() > 0);
|
|
|
|
|
|
m_cameraCodecCombo->setEnabled(false);
|
2026-09-18 16:22:20 +08:00
|
|
|
|
m_cameraStreamModeCombo->setEnabled(!m_cameraStreaming);
|
|
|
|
|
|
m_snapshotButton->setEnabled(m_connected && !m_cameraStreaming);
|
2026-10-14 17:15:46 +08:00
|
|
|
|
if (m_depthSnapshotButton)
|
|
|
|
|
|
m_depthSnapshotButton->setEnabled(m_connected && !m_cameraStreaming);
|
2026-09-18 16:22:20 +08:00
|
|
|
|
m_cameraStreamStateLabel->setText(m_cameraStreaming
|
|
|
|
|
|
? QStringLiteral("%1 路播放中").arg(m_runningCameraIds.size())
|
|
|
|
|
|
: QStringLiteral("已停止"));
|
2026-10-16 09:39:44 +08:00
|
|
|
|
refreshCameraDepthControls();
|
2026-09-18 16:22:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget *MainWindow::createCameraPage()
|
|
|
|
|
|
{
|
|
|
|
|
|
QWidget *page = new QWidget;
|
|
|
|
|
|
Ui::CameraServicePage ui;
|
|
|
|
|
|
ui.setupUi(page);
|
|
|
|
|
|
|
|
|
|
|
|
m_imageMetaLabel = ui.imageMetaLabel;
|
|
|
|
|
|
m_saveImageButton = ui.saveImageButton;
|
|
|
|
|
|
ui.viewerLayout->removeWidget(ui.imageLabel);
|
|
|
|
|
|
ui.imageLabel->hide();
|
|
|
|
|
|
ui.imageLabel->deleteLater();
|
|
|
|
|
|
m_videoRender = nullptr;
|
|
|
|
|
|
m_cameraPreviewContainer = new QWidget(page);
|
2026-10-14 17:15:46 +08:00
|
|
|
|
m_cameraPreviewContainer->setObjectName(QStringLiteral("cameraPreviewContainer"));
|
2026-09-18 16:22:20 +08:00
|
|
|
|
m_cameraPreviewGrid = new QGridLayout(m_cameraPreviewContainer);
|
|
|
|
|
|
m_cameraPreviewGrid->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
m_cameraPreviewGrid->setSpacing(10);
|
|
|
|
|
|
ui.viewerLayout->addWidget(m_cameraPreviewContainer, 1);
|
2026-10-14 17:15:46 +08:00
|
|
|
|
m_cameraDeviceCombo = ui.cameraDeviceCombo;
|
2026-09-18 16:22:20 +08:00
|
|
|
|
m_snapshotButton = ui.snapshotButton;
|
2026-10-14 17:15:46 +08:00
|
|
|
|
m_depthSnapshotButton = new QPushButton(QStringLiteral("获取深度图像"), ui.controlsPanel);
|
|
|
|
|
|
m_depthSnapshotButton->setObjectName(QStringLiteral("secondaryButton"));
|
2026-10-16 09:39:44 +08:00
|
|
|
|
m_depthSnapshotButton->hide();
|
2026-10-14 17:15:46 +08:00
|
|
|
|
const int snapshotIndex = ui.controlsLayout->indexOf(m_snapshotButton);
|
|
|
|
|
|
ui.controlsLayout->insertWidget(snapshotIndex + 1, m_depthSnapshotButton);
|
2026-09-18 16:22:20 +08:00
|
|
|
|
m_cameraStreamButton = ui.cameraStreamButton;
|
|
|
|
|
|
m_cameraCodecCombo = ui.codecCombo;
|
|
|
|
|
|
m_cameraStreamModeCombo = ui.streamModeCombo;
|
|
|
|
|
|
// Qt 5.12's uic does not preserve QComboBox item userData from this UI
|
|
|
|
|
|
// file, so set the protocol values explicitly before reading currentData().
|
|
|
|
|
|
m_cameraStreamModeCombo->setItemData(0, QStringLiteral("rgb"));
|
|
|
|
|
|
m_cameraStreamModeCombo->setItemData(1, QStringLiteral("depth"));
|
|
|
|
|
|
m_cameraStreamModeCombo->setItemData(2, QStringLiteral("rgbd"));
|
|
|
|
|
|
m_cameraStreamStateLabel = ui.cameraStreamStateLabel;
|
|
|
|
|
|
m_cameraRecordPathEdit = ui.recordPathEdit;
|
|
|
|
|
|
m_cameraRecordButton = ui.cameraRecordButton;
|
|
|
|
|
|
m_cameraRecordStateLabel = ui.cameraRecordStateLabel;
|
|
|
|
|
|
m_saveImageButton->setIcon(style()->standardIcon(QStyle::SP_DialogSaveButton));
|
|
|
|
|
|
m_snapshotButton->setIcon(style()->standardIcon(QStyle::SP_DialogOpenButton));
|
2026-10-14 17:15:46 +08:00
|
|
|
|
m_depthSnapshotButton->setIcon(style()->standardIcon(QStyle::SP_DialogOpenButton));
|
2026-09-18 16:22:20 +08:00
|
|
|
|
m_cameraStreamButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
|
|
|
|
|
|
m_cameraRecordButton->setIcon(style()->standardIcon(QStyle::SP_DialogSaveButton));
|
|
|
|
|
|
|
|
|
|
|
|
connect(m_saveImageButton, &QPushButton::clicked, this, &MainWindow::saveSnapshot);
|
|
|
|
|
|
connect(m_snapshotButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
const QStringList cameraIds = configuredCameraIds();
|
|
|
|
|
|
if (!cameraIds.isEmpty())
|
|
|
|
|
|
m_client->requestSnapshot(cameraIds.first());
|
|
|
|
|
|
});
|
2026-10-14 17:15:46 +08:00
|
|
|
|
connect(m_depthSnapshotButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
const QStringList cameraIds = configuredCameraIds();
|
2026-10-16 09:39:44 +08:00
|
|
|
|
if (!cameraIds.isEmpty() && CameraCapabilities::depthImage(
|
|
|
|
|
|
m_cameraCapabilitiesById.value(cameraIds.first())))
|
2026-10-14 17:15:46 +08:00
|
|
|
|
m_client->requestDepthSnapshot(cameraIds.first());
|
|
|
|
|
|
});
|
2026-09-18 16:22:20 +08:00
|
|
|
|
connect(m_cameraCodecCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
|
|
|
|
|
this, [this](int index) {
|
|
|
|
|
|
const QString codec = index == 1 ? QStringLiteral("h265") : QStringLiteral("h264");
|
|
|
|
|
|
m_client->setCameraStreamCodec(codec);
|
|
|
|
|
|
if (m_cameraStreaming) {
|
|
|
|
|
|
m_cameraStreamStateLabel->setText(
|
|
|
|
|
|
QStringLiteral("切换至 %1,等待关键帧")
|
|
|
|
|
|
.arg(index == 1 ? QStringLiteral("H.265") : QStringLiteral("H.264")));
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2026-10-14 17:15:46 +08:00
|
|
|
|
connect(m_cameraDeviceCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
|
|
|
|
|
this, [this](int) {
|
2026-10-16 09:39:44 +08:00
|
|
|
|
refreshCameraDepthControls();
|
2026-10-14 17:15:46 +08:00
|
|
|
|
if (!m_cameraStreaming) {
|
2026-09-18 16:22:20 +08:00
|
|
|
|
rebuildCameraPreviewGrid(configuredCameraIds());
|
2026-10-14 17:15:46 +08:00
|
|
|
|
saveSettings();
|
|
|
|
|
|
}
|
|
|
|
|
|
const QStringList cameraIds = configuredCameraIds();
|
|
|
|
|
|
if (m_connected && !cameraIds.isEmpty())
|
|
|
|
|
|
m_client->requestCameraStatus(cameraIds.first());
|
2026-09-18 16:22:20 +08:00
|
|
|
|
});
|
|
|
|
|
|
connect(m_cameraStreamButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
if (m_cameraStreaming) {
|
|
|
|
|
|
m_cameraStreamButton->setEnabled(false);
|
|
|
|
|
|
m_cameraStreamButton->setText(QStringLiteral("正在停止..."));
|
|
|
|
|
|
m_client->stopCameraStream();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const QStringList cameraIds = configuredCameraIds();
|
|
|
|
|
|
if (cameraIds.isEmpty()) {
|
|
|
|
|
|
appendLog(QStringLiteral("WARN"),
|
2026-10-14 17:15:46 +08:00
|
|
|
|
QStringLiteral("服务端未返回可用的摄像头设备"));
|
2026-09-18 16:22:20 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
saveSettings();
|
|
|
|
|
|
rebuildCameraPreviewGrid(cameraIds);
|
|
|
|
|
|
const QString codec = m_cameraCodecCombo->currentIndex() == 1
|
|
|
|
|
|
? QStringLiteral("h265") : QStringLiteral("h264");
|
|
|
|
|
|
const QString mode = m_cameraStreamModeCombo->currentData().toString().isEmpty()
|
|
|
|
|
|
? QStringLiteral("rgb") : m_cameraStreamModeCombo->currentData().toString();
|
|
|
|
|
|
for (const QString &cameraId : cameraIds)
|
|
|
|
|
|
m_client->startCameraStream(cameraId, codec, mode);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_cameraRecordButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_cameraRecordButton->setEnabled(false);
|
|
|
|
|
|
if (m_cameraRecording) {
|
|
|
|
|
|
m_cameraRecordButton->setText(QStringLiteral("正在停止..."));
|
|
|
|
|
|
const QStringList cameraIds = configuredCameraIds();
|
|
|
|
|
|
if (!cameraIds.isEmpty())
|
|
|
|
|
|
m_client->stopCameraRecording(cameraIds.first());
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const QString path = m_cameraRecordPathEdit->text().trimmed();
|
|
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
|
|
m_cameraRecordButton->setEnabled(m_connected);
|
|
|
|
|
|
appendLog(QStringLiteral("WARN"), QStringLiteral("请填写服务端录像保存路径"));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
saveSettings();
|
|
|
|
|
|
m_cameraRecordButton->setText(QStringLiteral("正在启动..."));
|
|
|
|
|
|
const QStringList cameraIds = configuredCameraIds();
|
|
|
|
|
|
if (cameraIds.isEmpty()) {
|
|
|
|
|
|
m_cameraRecordButton->setEnabled(m_connected);
|
|
|
|
|
|
appendLog(QStringLiteral("WARN"),
|
2026-10-14 17:15:46 +08:00
|
|
|
|
QStringLiteral("服务端未返回可用的摄像头设备"));
|
2026-09-18 16:22:20 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
m_client->startCameraRecording(cameraIds.first(), path);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
rebuildCameraPreviewGrid(configuredCameraIds());
|
2026-10-14 17:15:46 +08:00
|
|
|
|
ui.viewerTitle->setText(QStringLiteral("RGB / 深度预览"));
|
|
|
|
|
|
m_serviceButtons << m_snapshotButton << m_depthSnapshotButton
|
|
|
|
|
|
<< m_cameraStreamButton << m_cameraRecordButton;
|
2026-09-18 16:22:20 +08:00
|
|
|
|
return withRpcExplorer(page, m_client, QStringLiteral("cmvr.api.CameraService"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget *MainWindow::createAgvPage()
|
|
|
|
|
|
{
|
|
|
|
|
|
QWidget *page = new QWidget;
|
|
|
|
|
|
Ui::AgvServicePage ui;
|
|
|
|
|
|
ui.setupUi(page);
|
|
|
|
|
|
|
|
|
|
|
|
FramelessToolDialog *statusDialog = new FramelessToolDialog(this);
|
|
|
|
|
|
m_agvStatusDialog = statusDialog;
|
|
|
|
|
|
m_agvStatusDialog->setAttribute(Qt::WA_DeleteOnClose, false);
|
|
|
|
|
|
Ui::AgvStatusDialog statusUi;
|
|
|
|
|
|
statusUi.setupUi(m_agvStatusDialog);
|
|
|
|
|
|
QGraphicsDropShadowEffect *dialogShadow =
|
|
|
|
|
|
new QGraphicsDropShadowEffect(statusUi.agvDialogSurface);
|
|
|
|
|
|
dialogShadow->setBlurRadius(28.0);
|
|
|
|
|
|
dialogShadow->setOffset(0.0, 5.0);
|
|
|
|
|
|
dialogShadow->setColor(QColor(24, 34, 44, 78));
|
|
|
|
|
|
statusUi.agvDialogSurface->setGraphicsEffect(dialogShadow);
|
|
|
|
|
|
statusDialog->setDragHandle(statusUi.agvDialogTitleBar);
|
|
|
|
|
|
statusUi.agvDialogCloseButton->setIcon(UiIcons::icon(
|
|
|
|
|
|
QStringLiteral(":/icons/x.svg"), QColor(QStringLiteral("#4f5964")),
|
|
|
|
|
|
QColor(QStringLiteral("#4f5964"))));
|
|
|
|
|
|
connect(statusUi.agvDialogCloseButton, &QPushButton::clicked,
|
|
|
|
|
|
m_agvStatusDialog, &QDialog::reject);
|
|
|
|
|
|
statusUi.statusLayout->setColumnStretch(1, 1);
|
|
|
|
|
|
statusUi.statusLayout->setColumnStretch(3, 1);
|
|
|
|
|
|
|
|
|
|
|
|
m_agvIdEdit = ui.agvIdEdit;
|
|
|
|
|
|
m_agvStatusRefreshTimer = new QTimer(page);
|
|
|
|
|
|
m_agvStatusRefreshTimer->setInterval(1000);
|
2026-10-14 17:15:46 +08:00
|
|
|
|
m_agvMapRefreshTimer = new QTimer(page);
|
|
|
|
|
|
m_agvMapRefreshTimer->setTimerType(Qt::PreciseTimer);
|
|
|
|
|
|
connect(m_agvMapRefreshTimer, &QTimer::timeout,
|
|
|
|
|
|
this, &MainWindow::presentPendingAgvMapFrame);
|
2026-09-18 16:22:20 +08:00
|
|
|
|
m_agvConnectionValue = statusUi.agvConnectionValue;
|
|
|
|
|
|
m_agvPoseValue = statusUi.agvPoseValue;
|
|
|
|
|
|
m_agvMotionValue = statusUi.agvMotionValue;
|
|
|
|
|
|
m_agvBatteryValue = statusUi.agvBatteryValue;
|
|
|
|
|
|
m_agvMapValue = statusUi.agvMapValue;
|
|
|
|
|
|
m_agvNavigationValue = statusUi.agvNavigationValue;
|
|
|
|
|
|
m_agvErrorValue = statusUi.agvErrorValue;
|
|
|
|
|
|
m_agvModeValue = statusUi.agvModeValue;
|
|
|
|
|
|
m_agvMotionStateValue = statusUi.agvMotionStateValue;
|
|
|
|
|
|
m_agvSafetyValue = statusUi.agvSafetyValue;
|
|
|
|
|
|
m_agvPowerValue = statusUi.agvPowerValue;
|
|
|
|
|
|
m_agvTimestampValue = statusUi.agvTimestampValue;
|
|
|
|
|
|
m_agvMapOverview = ui.agvMapOverview;
|
|
|
|
|
|
m_agvMappingPreview = ui.mappingPreview;
|
|
|
|
|
|
m_agvMappingStateLabel = ui.mappingStateLabel;
|
|
|
|
|
|
m_agvProgress = statusUi.agvProgress;
|
|
|
|
|
|
m_agvXSpin = ui.agvXSpin;
|
|
|
|
|
|
m_agvYSpin = ui.agvYSpin;
|
|
|
|
|
|
m_agvThetaSpin = ui.agvThetaSpin;
|
|
|
|
|
|
m_agvMaxSpeedSpin = ui.agvMaxSpeedSpin;
|
|
|
|
|
|
m_agvVxSpin = ui.agvVxSpin;
|
|
|
|
|
|
m_agvVySpin = ui.agvVySpin;
|
|
|
|
|
|
m_agvWzSpin = ui.agvWzSpin;
|
|
|
|
|
|
m_agvMapCombo = ui.agvMapCombo;
|
|
|
|
|
|
m_agvStationCombo = ui.agvStationCombo;
|
|
|
|
|
|
m_agvStationTable = ui.agvStationTable;
|
|
|
|
|
|
ui.refreshButton->setIcon(UiIcons::icon(QStringLiteral(":/icons/rotate-ccw.svg"),
|
|
|
|
|
|
QColor(QStringLiteral("#66727d"))));
|
|
|
|
|
|
ui.emergencyButton->setIcon(UiIcons::icon(QStringLiteral(":/icons/octagon-x.svg"),
|
|
|
|
|
|
QColor(QStringLiteral("#ffffff"))));
|
|
|
|
|
|
m_agvStationCombo->lineEdit()->setPlaceholderText(QStringLiteral("选择或输入站点 ID"));
|
|
|
|
|
|
m_agvMapCombo->lineEdit()->setPlaceholderText(QStringLiteral("地图名称"));
|
|
|
|
|
|
|
|
|
|
|
|
m_agvStationTable->setHorizontalHeaderLabels({QStringLiteral("站点"), QStringLiteral("类型"),
|
|
|
|
|
|
QStringLiteral("X"), QStringLiteral("Y")});
|
|
|
|
|
|
m_agvStationTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
|
|
m_agvStationTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
|
|
m_agvStationTable->verticalHeader()->setVisible(false);
|
|
|
|
|
|
m_agvStationTable->horizontalHeader()->setStretchLastSection(true);
|
2026-10-14 17:15:46 +08:00
|
|
|
|
m_agvStatusRefreshTimer->setInterval(500);
|
|
|
|
|
|
m_agvManualVelocityTimer = new QTimer(page);
|
|
|
|
|
|
m_agvManualVelocityTimer->setInterval(150);
|
|
|
|
|
|
connect(m_agvManualVelocityTimer, &QTimer::timeout, this, [this]() {
|
|
|
|
|
|
if (!m_agvManualMotionActive || !m_connected)
|
|
|
|
|
|
return;
|
|
|
|
|
|
m_client->requestAgvVelocity(m_agvIdEdit->text().trimmed(),
|
|
|
|
|
|
m_agvManualVx, m_agvManualVy,
|
|
|
|
|
|
m_agvManualWz);
|
2026-09-18 16:22:20 +08:00
|
|
|
|
});
|
2026-10-14 17:15:46 +08:00
|
|
|
|
|
|
|
|
|
|
m_agvControlWorkspace = new QWidget(ui.agvTabs);
|
|
|
|
|
|
m_agvControlWorkspace->setObjectName(QStringLiteral("agvControlWorkspace"));
|
|
|
|
|
|
QHBoxLayout *workspaceLayout = new QHBoxLayout(m_agvControlWorkspace);
|
|
|
|
|
|
workspaceLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
workspaceLayout->setSpacing(12);
|
|
|
|
|
|
|
|
|
|
|
|
QWidget *leftColumn = new QWidget(m_agvControlWorkspace);
|
|
|
|
|
|
QVBoxLayout *leftLayout = new QVBoxLayout(leftColumn);
|
|
|
|
|
|
leftLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
leftLayout->setSpacing(12);
|
|
|
|
|
|
QWidget *rightColumn = new QWidget(m_agvControlWorkspace);
|
|
|
|
|
|
QVBoxLayout *rightLayout = new QVBoxLayout(rightColumn);
|
|
|
|
|
|
rightLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
rightLayout->setSpacing(12);
|
|
|
|
|
|
workspaceLayout->addWidget(leftColumn, 7);
|
|
|
|
|
|
workspaceLayout->addWidget(rightColumn, 4);
|
|
|
|
|
|
|
|
|
|
|
|
ui.mappingPreviewPanel->setParent(leftColumn);
|
|
|
|
|
|
ui.mappingPreviewPanel->setMinimumSize(0, 0);
|
|
|
|
|
|
ui.mappingPreviewTitle->setText(QStringLiteral("实时地图"));
|
|
|
|
|
|
ui.mappingPreviewLayout->removeWidget(ui.mappingPreview);
|
|
|
|
|
|
ui.mappingPreview->hide();
|
|
|
|
|
|
m_agvMappingPreview = nullptr;
|
|
|
|
|
|
|
|
|
|
|
|
QHBoxLayout *mapToolbar = new QHBoxLayout;
|
|
|
|
|
|
QLabel *mapLegend = new QLabel(
|
|
|
|
|
|
QStringLiteral("蓝色箭头:AGV 当前位姿 · 虚线:运动轨迹"),
|
|
|
|
|
|
ui.mappingPreviewPanel);
|
|
|
|
|
|
mapLegend->setObjectName(QStringLiteral("panelSubtitle"));
|
|
|
|
|
|
QLabel *mapRefreshLabel = new QLabel(QStringLiteral("刷新率"),
|
|
|
|
|
|
ui.mappingPreviewPanel);
|
|
|
|
|
|
mapRefreshLabel->setObjectName(QStringLiteral("panelSubtitle"));
|
|
|
|
|
|
m_agvMapRefreshCombo = new QComboBox(ui.mappingPreviewPanel);
|
|
|
|
|
|
m_agvMapRefreshCombo->setObjectName(QStringLiteral("agvMapRefreshCombo"));
|
|
|
|
|
|
m_agvMapRefreshCombo->addItem(QStringLiteral("自动"), 0);
|
|
|
|
|
|
m_agvMapRefreshCombo->addItem(QStringLiteral("1 Hz"), 1000);
|
|
|
|
|
|
m_agvMapRefreshCombo->addItem(QStringLiteral("2 Hz"), 500);
|
|
|
|
|
|
m_agvMapRefreshCombo->addItem(QStringLiteral("5 Hz"), 200);
|
|
|
|
|
|
m_agvMapRefreshCombo->addItem(QStringLiteral("10 Hz"), 100);
|
|
|
|
|
|
m_agvMapRefreshCombo->setMaximumWidth(96);
|
|
|
|
|
|
m_agvMapRefreshCombo->setToolTip(
|
|
|
|
|
|
QStringLiteral("控制上位机地图画面的刷新频率;自动模式跟随地图数据"));
|
|
|
|
|
|
QPushButton *zoomOutButton = new QPushButton(QStringLiteral("−"),
|
|
|
|
|
|
ui.mappingPreviewPanel);
|
|
|
|
|
|
QPushButton *zoomInButton = new QPushButton(QStringLiteral("+"),
|
|
|
|
|
|
ui.mappingPreviewPanel);
|
|
|
|
|
|
QPushButton *resetViewButton = new QPushButton(QStringLiteral("适应窗口"),
|
|
|
|
|
|
ui.mappingPreviewPanel);
|
|
|
|
|
|
QPushButton *clearTrackButton = new QPushButton(QStringLiteral("清除轨迹"),
|
|
|
|
|
|
ui.mappingPreviewPanel);
|
|
|
|
|
|
for (QPushButton *button : {zoomOutButton, zoomInButton,
|
|
|
|
|
|
resetViewButton, clearTrackButton}) {
|
|
|
|
|
|
button->setObjectName(QStringLiteral("agvMapToolButton"));
|
|
|
|
|
|
button->setMinimumHeight(30);
|
|
|
|
|
|
}
|
|
|
|
|
|
zoomOutButton->setMaximumWidth(42);
|
|
|
|
|
|
zoomInButton->setMaximumWidth(42);
|
|
|
|
|
|
mapToolbar->addWidget(mapLegend);
|
|
|
|
|
|
mapToolbar->addStretch();
|
|
|
|
|
|
mapToolbar->addWidget(mapRefreshLabel);
|
|
|
|
|
|
mapToolbar->addWidget(m_agvMapRefreshCombo);
|
|
|
|
|
|
mapToolbar->addSpacing(4);
|
|
|
|
|
|
mapToolbar->addWidget(zoomOutButton);
|
|
|
|
|
|
mapToolbar->addWidget(zoomInButton);
|
|
|
|
|
|
mapToolbar->addWidget(resetViewButton);
|
|
|
|
|
|
mapToolbar->addWidget(clearTrackButton);
|
|
|
|
|
|
ui.mappingPreviewLayout->insertLayout(1, mapToolbar);
|
|
|
|
|
|
|
|
|
|
|
|
m_agvMapView = new AgvMapViewWidget(ui.mappingPreviewPanel);
|
|
|
|
|
|
m_agvMapView->setObjectName(QStringLiteral("agvLiveMap"));
|
|
|
|
|
|
m_agvMapView->setStreamMessage(QStringLiteral("连接设备后自动加载实时地图"));
|
|
|
|
|
|
ui.mappingPreviewLayout->insertWidget(2, m_agvMapView, 1);
|
|
|
|
|
|
leftLayout->addWidget(ui.mappingPreviewPanel, 1);
|
|
|
|
|
|
|
|
|
|
|
|
QFrame *mapActionsPanel = new QFrame(leftColumn);
|
|
|
|
|
|
mapActionsPanel->setObjectName(QStringLiteral("panel"));
|
|
|
|
|
|
QVBoxLayout *mapActionsLayout = new QVBoxLayout(mapActionsPanel);
|
|
|
|
|
|
mapActionsLayout->setContentsMargins(18, 14, 18, 14);
|
|
|
|
|
|
mapActionsLayout->setSpacing(9);
|
|
|
|
|
|
QLabel *mapActionsTitle = new QLabel(QStringLiteral("地图与建图"),
|
|
|
|
|
|
mapActionsPanel);
|
|
|
|
|
|
mapActionsTitle->setObjectName(QStringLiteral("sectionTitle"));
|
|
|
|
|
|
QLabel *mapActionsSubtitle = new QLabel(
|
|
|
|
|
|
QStringLiteral("加载已有地图、重新定位,或创建新的建图会话"),
|
|
|
|
|
|
mapActionsPanel);
|
|
|
|
|
|
mapActionsSubtitle->setObjectName(QStringLiteral("panelSubtitle"));
|
|
|
|
|
|
mapActionsLayout->addWidget(mapActionsTitle);
|
|
|
|
|
|
mapActionsLayout->addWidget(mapActionsSubtitle);
|
|
|
|
|
|
|
|
|
|
|
|
QHBoxLayout *mapSelectionRow = new QHBoxLayout;
|
|
|
|
|
|
ui.agvMapCombo->setParent(mapActionsPanel);
|
|
|
|
|
|
ui.inventoryButton->setParent(mapActionsPanel);
|
|
|
|
|
|
ui.switchMapButton->setParent(mapActionsPanel);
|
|
|
|
|
|
ui.inventoryButton->setText(QStringLiteral("刷新列表"));
|
|
|
|
|
|
ui.switchMapButton->setText(QStringLiteral("加载地图"));
|
|
|
|
|
|
mapSelectionRow->addWidget(ui.agvMapCombo, 1);
|
|
|
|
|
|
mapSelectionRow->addWidget(ui.inventoryButton);
|
|
|
|
|
|
mapSelectionRow->addWidget(ui.switchMapButton);
|
|
|
|
|
|
mapActionsLayout->addLayout(mapSelectionRow);
|
|
|
|
|
|
|
|
|
|
|
|
QPushButton *addMapButton = new QPushButton(QStringLiteral("新增地图"),
|
|
|
|
|
|
mapActionsPanel);
|
|
|
|
|
|
QPushButton *relocalizeButton = new QPushButton(QStringLiteral("重新定位"),
|
|
|
|
|
|
mapActionsPanel);
|
|
|
|
|
|
m_agvDeleteMapButton = new QPushButton(QStringLiteral("删除地图"),
|
|
|
|
|
|
mapActionsPanel);
|
|
|
|
|
|
m_agvDeleteMapButton->setObjectName(QStringLiteral("dangerOutlineButton"));
|
|
|
|
|
|
m_agvDeleteMapButton->setEnabled(false);
|
|
|
|
|
|
m_agvDeleteMapButton->setToolTip(
|
|
|
|
|
|
QStringLiteral("当前边缘系统未提供删除地图接口"));
|
|
|
|
|
|
QHBoxLayout *mapOperationRow = new QHBoxLayout;
|
|
|
|
|
|
mapOperationRow->addWidget(addMapButton);
|
|
|
|
|
|
mapOperationRow->addWidget(relocalizeButton);
|
|
|
|
|
|
mapOperationRow->addWidget(m_agvDeleteMapButton);
|
|
|
|
|
|
mapActionsLayout->addLayout(mapOperationRow);
|
|
|
|
|
|
|
|
|
|
|
|
QGridLayout *mappingForm = new QGridLayout;
|
|
|
|
|
|
QLabel *mappingNameLabel = new QLabel(QStringLiteral("新地图"),
|
|
|
|
|
|
mapActionsPanel);
|
|
|
|
|
|
QLabel *mappingDimensionLabel = new QLabel(QStringLiteral("类型"),
|
|
|
|
|
|
mapActionsPanel);
|
|
|
|
|
|
ui.mappingNameEdit->setParent(mapActionsPanel);
|
|
|
|
|
|
ui.mappingDimensionCombo->setParent(mapActionsPanel);
|
|
|
|
|
|
ui.mappingRealtimeCheck->setParent(mapActionsPanel);
|
|
|
|
|
|
mappingForm->addWidget(mappingNameLabel, 0, 0);
|
|
|
|
|
|
mappingForm->addWidget(ui.mappingNameEdit, 0, 1);
|
|
|
|
|
|
mappingForm->addWidget(mappingDimensionLabel, 0, 2);
|
|
|
|
|
|
mappingForm->addWidget(ui.mappingDimensionCombo, 0, 3);
|
|
|
|
|
|
mappingForm->addWidget(ui.mappingRealtimeCheck, 1, 1, 1, 3);
|
|
|
|
|
|
mappingForm->setColumnStretch(1, 1);
|
|
|
|
|
|
mappingForm->setColumnStretch(3, 1);
|
|
|
|
|
|
mapActionsLayout->addLayout(mappingForm);
|
|
|
|
|
|
|
|
|
|
|
|
ui.startMappingButton->setParent(mapActionsPanel);
|
|
|
|
|
|
ui.stopMappingButton->setParent(mapActionsPanel);
|
|
|
|
|
|
QHBoxLayout *mappingButtonRow = new QHBoxLayout;
|
|
|
|
|
|
mappingButtonRow->addWidget(ui.startMappingButton);
|
|
|
|
|
|
mappingButtonRow->addWidget(ui.stopMappingButton);
|
|
|
|
|
|
mapActionsLayout->addLayout(mappingButtonRow);
|
|
|
|
|
|
|
|
|
|
|
|
ui.uploadMapButton->setParent(mapActionsPanel);
|
|
|
|
|
|
ui.downloadMapButton->setParent(mapActionsPanel);
|
|
|
|
|
|
QHBoxLayout *transferRow = new QHBoxLayout;
|
|
|
|
|
|
transferRow->addWidget(ui.uploadMapButton);
|
|
|
|
|
|
transferRow->addWidget(ui.downloadMapButton);
|
|
|
|
|
|
mapActionsLayout->addLayout(transferRow);
|
|
|
|
|
|
leftLayout->addWidget(mapActionsPanel);
|
|
|
|
|
|
|
|
|
|
|
|
statusUi.agvDialogSurface->setGraphicsEffect(nullptr);
|
|
|
|
|
|
statusUi.agvDialogSurface->setParent(rightColumn);
|
|
|
|
|
|
statusUi.agvDialogSurface->setMinimumSize(0, 0);
|
|
|
|
|
|
statusUi.agvDialogTitleBar->hide();
|
|
|
|
|
|
statusUi.agvDialogContentLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
statusUi.navigationStatusPanel->setMaximumHeight(150);
|
|
|
|
|
|
rightLayout->addWidget(statusUi.agvDialogSurface, 3);
|
|
|
|
|
|
|
|
|
|
|
|
ui.velocityPanel->setParent(rightColumn);
|
|
|
|
|
|
ui.velocityPanel->setMinimumSize(0, 0);
|
|
|
|
|
|
ui.velocityTitle->setText(QStringLiteral("手动速度控制"));
|
|
|
|
|
|
ui.velocitySubtitle->setText(
|
|
|
|
|
|
QStringLiteral("按住方向按钮或 Q/W/E/A/S/D 键运动,松开即停止"));
|
|
|
|
|
|
m_agvVxSpin->setMinimum(0.0);
|
|
|
|
|
|
m_agvVySpin->setMinimum(0.0);
|
|
|
|
|
|
m_agvWzSpin->setMinimum(0.0);
|
|
|
|
|
|
if (qFuzzyIsNull(m_agvVySpin->value()))
|
|
|
|
|
|
m_agvVySpin->setValue(0.2);
|
|
|
|
|
|
ui.rotateLeftButton->setText(QStringLiteral("左旋 (Q)"));
|
|
|
|
|
|
ui.forwardButton->setText(QStringLiteral("前进 (W)"));
|
|
|
|
|
|
ui.rotateRightButton->setText(QStringLiteral("右旋 (E)"));
|
|
|
|
|
|
ui.leftButton->setText(QStringLiteral("左移 (A)"));
|
|
|
|
|
|
ui.rightButton->setText(QStringLiteral("右移 (D)"));
|
|
|
|
|
|
ui.backwardButton->setText(QStringLiteral("后退 (S)"));
|
|
|
|
|
|
ui.velocityButton->hide();
|
|
|
|
|
|
rightLayout->addWidget(ui.velocityPanel, 4);
|
|
|
|
|
|
|
|
|
|
|
|
const auto removeOriginalTab = [tabs = ui.agvTabs](QWidget *tab) {
|
|
|
|
|
|
const int index = tabs->indexOf(tab);
|
|
|
|
|
|
if (index >= 0)
|
|
|
|
|
|
tabs->removeTab(index);
|
|
|
|
|
|
};
|
|
|
|
|
|
removeOriginalTab(ui.manualTab);
|
|
|
|
|
|
removeOriginalTab(ui.mapTab);
|
|
|
|
|
|
removeOriginalTab(ui.mappingTab);
|
|
|
|
|
|
ui.agvTabs->insertTab(0, m_agvControlWorkspace,
|
|
|
|
|
|
QStringLiteral("控制与建图"));
|
|
|
|
|
|
ui.agvTabs->setCurrentWidget(m_agvControlWorkspace);
|
|
|
|
|
|
|
|
|
|
|
|
connect(zoomOutButton, &QPushButton::clicked,
|
|
|
|
|
|
m_agvMapView, &AgvMapViewWidget::zoomOut);
|
|
|
|
|
|
connect(zoomInButton, &QPushButton::clicked,
|
|
|
|
|
|
m_agvMapView, &AgvMapViewWidget::zoomIn);
|
|
|
|
|
|
connect(resetViewButton, &QPushButton::clicked,
|
|
|
|
|
|
m_agvMapView, &AgvMapViewWidget::resetView);
|
|
|
|
|
|
connect(clearTrackButton, &QPushButton::clicked,
|
|
|
|
|
|
m_agvMapView, &AgvMapViewWidget::clearTrajectory);
|
|
|
|
|
|
connect(m_agvMapRefreshCombo,
|
|
|
|
|
|
QOverload<int>::of(&QComboBox::currentIndexChanged),
|
|
|
|
|
|
this, [this](int) {
|
|
|
|
|
|
const int intervalMs = m_agvMapRefreshCombo->currentData().toInt();
|
|
|
|
|
|
if (intervalMs <= 0) {
|
|
|
|
|
|
m_agvMapRefreshTimer->stop();
|
|
|
|
|
|
presentPendingAgvMapFrame();
|
2026-09-18 16:22:20 +08:00
|
|
|
|
return;
|
2026-10-14 17:15:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
m_agvMapRefreshTimer->setInterval(intervalMs);
|
|
|
|
|
|
if (m_agvMapStreamActive)
|
|
|
|
|
|
m_agvMapRefreshTimer->start();
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(addMapButton, &QPushButton::clicked, this,
|
|
|
|
|
|
[this, nameEdit = ui.mappingNameEdit]() {
|
|
|
|
|
|
bool accepted = false;
|
|
|
|
|
|
const QString name = QInputDialog::getText(
|
|
|
|
|
|
this, QStringLiteral("新增地图"), QStringLiteral("地图名称"),
|
|
|
|
|
|
QLineEdit::Normal, nameEdit->text(), &accepted).trimmed();
|
|
|
|
|
|
if (!accepted || name.isEmpty())
|
2026-09-18 16:22:20 +08:00
|
|
|
|
return;
|
2026-10-14 17:15:46 +08:00
|
|
|
|
nameEdit->setText(name);
|
|
|
|
|
|
nameEdit->setFocus();
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(relocalizeButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
QDialog dialog(this);
|
|
|
|
|
|
dialog.setWindowTitle(QStringLiteral("AGV 重新定位"));
|
|
|
|
|
|
QFormLayout *form = new QFormLayout(&dialog);
|
|
|
|
|
|
QDoubleSpinBox *xSpin = new QDoubleSpinBox(&dialog);
|
|
|
|
|
|
QDoubleSpinBox *ySpin = new QDoubleSpinBox(&dialog);
|
|
|
|
|
|
QDoubleSpinBox *thetaSpin = new QDoubleSpinBox(&dialog);
|
|
|
|
|
|
for (QDoubleSpinBox *spin : {xSpin, ySpin}) {
|
|
|
|
|
|
spin->setRange(-10000.0, 10000.0);
|
|
|
|
|
|
spin->setDecimals(3);
|
|
|
|
|
|
spin->setSuffix(QStringLiteral(" m"));
|
2026-09-18 16:22:20 +08:00
|
|
|
|
}
|
2026-10-14 17:15:46 +08:00
|
|
|
|
thetaSpin->setRange(-6.283, 6.283);
|
|
|
|
|
|
thetaSpin->setDecimals(3);
|
|
|
|
|
|
thetaSpin->setSuffix(QStringLiteral(" rad"));
|
|
|
|
|
|
xSpin->setValue(m_latestAgvState.value(QStringLiteral("x")).toDouble());
|
|
|
|
|
|
ySpin->setValue(m_latestAgvState.value(QStringLiteral("y")).toDouble());
|
|
|
|
|
|
thetaSpin->setValue(
|
|
|
|
|
|
m_latestAgvState.value(QStringLiteral("theta")).toDouble());
|
|
|
|
|
|
form->addRow(QStringLiteral("X"), xSpin);
|
|
|
|
|
|
form->addRow(QStringLiteral("Y"), ySpin);
|
|
|
|
|
|
form->addRow(QStringLiteral("航向"), thetaSpin);
|
|
|
|
|
|
QDialogButtonBox *buttons = new QDialogButtonBox(
|
|
|
|
|
|
QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &dialog);
|
|
|
|
|
|
connect(buttons, &QDialogButtonBox::accepted,
|
|
|
|
|
|
&dialog, &QDialog::accept);
|
|
|
|
|
|
connect(buttons, &QDialogButtonBox::rejected,
|
|
|
|
|
|
&dialog, &QDialog::reject);
|
|
|
|
|
|
form->addRow(buttons);
|
|
|
|
|
|
if (dialog.exec() == QDialog::Accepted) {
|
|
|
|
|
|
m_client->requestAgvRelocalize(
|
|
|
|
|
|
m_agvIdEdit->text().trimmed(), xSpin->value(),
|
|
|
|
|
|
ySpin->value(), thetaSpin->value());
|
2026-09-18 16:22:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2026-10-14 17:15:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connect(ui.refreshButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->requestAgvRefresh(m_agvIdEdit->text().trimmed());
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_agvStatusRefreshTimer, &QTimer::timeout, this, [this]() {
|
|
|
|
|
|
if (m_connected && m_pages && m_pages->currentIndex() == 3)
|
|
|
|
|
|
m_client->requestAgvRefresh(m_agvIdEdit->text().trimmed());
|
2026-09-18 16:22:20 +08:00
|
|
|
|
});
|
|
|
|
|
|
connect(ui.navigatePoseButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->requestAgvNavigatePose(m_agvIdEdit->text().trimmed(), m_agvXSpin->value(),
|
|
|
|
|
|
m_agvYSpin->value(), m_agvThetaSpin->value(),
|
|
|
|
|
|
m_agvMaxSpeedSpin->value());
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(ui.navigateStationButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->requestAgvNavigateStation(m_agvIdEdit->text().trimmed(),
|
|
|
|
|
|
m_agvStationCombo->currentText().trimmed(),
|
|
|
|
|
|
m_agvMaxSpeedSpin->value());
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(ui.pauseButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->requestAgvAction(m_agvIdEdit->text().trimmed(), QStringLiteral("Pause"));
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(ui.resumeButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->requestAgvAction(m_agvIdEdit->text().trimmed(), QStringLiteral("Resume"));
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(ui.cancelButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->requestAgvAction(m_agvIdEdit->text().trimmed(), QStringLiteral("Cancel"));
|
|
|
|
|
|
});
|
2026-10-14 17:15:46 +08:00
|
|
|
|
connect(ui.forwardButton, &QPushButton::pressed, this, [this]() {
|
|
|
|
|
|
startAgvManualMotion(qAbs(m_agvVxSpin->value()), 0.0, 0.0);
|
2026-09-18 16:22:20 +08:00
|
|
|
|
});
|
2026-10-14 17:15:46 +08:00
|
|
|
|
connect(ui.backwardButton, &QPushButton::pressed, this, [this]() {
|
|
|
|
|
|
startAgvManualMotion(-qAbs(m_agvVxSpin->value()), 0.0, 0.0);
|
2026-09-18 16:22:20 +08:00
|
|
|
|
});
|
2026-10-14 17:15:46 +08:00
|
|
|
|
connect(ui.leftButton, &QPushButton::pressed, this, [this]() {
|
|
|
|
|
|
startAgvManualMotion(0.0, qAbs(m_agvVySpin->value()), 0.0);
|
2026-09-18 16:22:20 +08:00
|
|
|
|
});
|
2026-10-14 17:15:46 +08:00
|
|
|
|
connect(ui.rightButton, &QPushButton::pressed, this, [this]() {
|
|
|
|
|
|
startAgvManualMotion(0.0, -qAbs(m_agvVySpin->value()), 0.0);
|
2026-09-18 16:22:20 +08:00
|
|
|
|
});
|
2026-10-14 17:15:46 +08:00
|
|
|
|
connect(ui.rotateLeftButton, &QPushButton::pressed, this, [this]() {
|
|
|
|
|
|
startAgvManualMotion(0.0, 0.0, qAbs(m_agvWzSpin->value()));
|
2026-09-18 16:22:20 +08:00
|
|
|
|
});
|
2026-10-14 17:15:46 +08:00
|
|
|
|
connect(ui.rotateRightButton, &QPushButton::pressed, this, [this]() {
|
|
|
|
|
|
startAgvManualMotion(0.0, 0.0, -qAbs(m_agvWzSpin->value()));
|
2026-09-18 16:22:20 +08:00
|
|
|
|
});
|
2026-10-14 17:15:46 +08:00
|
|
|
|
for (QPushButton *button : {
|
|
|
|
|
|
ui.forwardButton, ui.backwardButton, ui.leftButton,
|
|
|
|
|
|
ui.rightButton, ui.rotateLeftButton, ui.rotateRightButton}) {
|
|
|
|
|
|
connect(button, &QPushButton::released, this,
|
|
|
|
|
|
[this]() { stopAgvManualMotion(); });
|
|
|
|
|
|
}
|
|
|
|
|
|
connect(ui.manualStopButton, &QPushButton::clicked, this,
|
|
|
|
|
|
[this]() { stopAgvManualMotion(); });
|
2026-09-18 16:22:20 +08:00
|
|
|
|
connect(ui.zeroVelocityButton, &QPushButton::clicked, this, [this]() {
|
2026-10-14 17:15:46 +08:00
|
|
|
|
stopAgvManualMotion();
|
2026-09-18 16:22:20 +08:00
|
|
|
|
m_agvVxSpin->setValue(0.0);
|
|
|
|
|
|
m_agvVySpin->setValue(0.0);
|
|
|
|
|
|
m_agvWzSpin->setValue(0.0);
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(statusUi.stopVelocityButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->requestAgvAction(m_agvIdEdit->text().trimmed(),
|
|
|
|
|
|
QStringLiteral("StopVelocity"));
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(statusUi.clearFaultButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->requestAgvAction(m_agvIdEdit->text().trimmed(), QStringLiteral("ClearFault"));
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(ui.emergencyButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->requestAgvAction(m_agvIdEdit->text().trimmed(),
|
|
|
|
|
|
QStringLiteral("EmergencyStop"));
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(ui.inventoryButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->requestAgvInventory(m_agvIdEdit->text().trimmed());
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(ui.switchMapButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->requestAgvSwitchMap(m_agvIdEdit->text().trimmed(),
|
|
|
|
|
|
m_agvMapCombo->currentText().trimmed());
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(ui.uploadMapButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
const QString path = QFileDialog::getOpenFileName(
|
|
|
|
|
|
this, QStringLiteral("选择需要上传的地图文件"));
|
|
|
|
|
|
if (path.isEmpty())
|
|
|
|
|
|
return;
|
|
|
|
|
|
QFile file(path);
|
|
|
|
|
|
if (!file.open(QIODevice::ReadOnly)) {
|
2026-10-16 09:39:44 +08:00
|
|
|
|
AppMessageBox::warning(this, QStringLiteral("上传地图"),
|
2026-09-18 16:22:20 +08:00
|
|
|
|
QStringLiteral("无法读取地图文件:%1").arg(path));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
QString mapName = m_agvMapCombo->currentText().trimmed();
|
|
|
|
|
|
if (mapName.isEmpty())
|
|
|
|
|
|
mapName = QFileInfo(path).completeBaseName();
|
|
|
|
|
|
QJsonObject request;
|
|
|
|
|
|
request.insert(QStringLiteral("mapName"), mapName);
|
|
|
|
|
|
request.insert(QStringLiteral("content"), QString::fromUtf8(file.readAll()));
|
|
|
|
|
|
m_client->requestRpc(QStringLiteral("cmvr.api.AgvService"),
|
|
|
|
|
|
QStringLiteral("uploadMap"),
|
|
|
|
|
|
QString::fromUtf8(QJsonDocument(request).toJson(QJsonDocument::Compact)),
|
|
|
|
|
|
m_agvIdEdit->text().trimmed());
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(ui.downloadMapButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
const QString mapName = m_agvMapCombo->currentText().trimmed();
|
|
|
|
|
|
if (mapName.isEmpty()) {
|
2026-10-16 09:39:44 +08:00
|
|
|
|
AppMessageBox::warning(this, QStringLiteral("下载地图"),
|
2026-09-18 16:22:20 +08:00
|
|
|
|
QStringLiteral("请先选择或输入地图名称"));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
m_agvDownloadPath = QFileDialog::getSaveFileName(
|
|
|
|
|
|
this, QStringLiteral("保存地图"), mapName + QStringLiteral(".json"));
|
|
|
|
|
|
if (m_agvDownloadPath.isEmpty())
|
|
|
|
|
|
return;
|
|
|
|
|
|
QJsonObject request;
|
|
|
|
|
|
request.insert(QStringLiteral("mapName"), mapName);
|
|
|
|
|
|
m_client->requestRpc(QStringLiteral("cmvr.api.AgvService"),
|
|
|
|
|
|
QStringLiteral("downloadMap"),
|
|
|
|
|
|
QString::fromUtf8(QJsonDocument(request).toJson(QJsonDocument::Compact)),
|
|
|
|
|
|
m_agvIdEdit->text().trimmed());
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_client, &RobotClient::rpcFinished, page,
|
|
|
|
|
|
[this](const QString &service, const QString &method,
|
|
|
|
|
|
bool success, const QString &responseJson) {
|
|
|
|
|
|
if (service != QStringLiteral("cmvr.api.AgvService") ||
|
|
|
|
|
|
method != QStringLiteral("downloadMap") || m_agvDownloadPath.isEmpty())
|
|
|
|
|
|
return;
|
|
|
|
|
|
const QString outputPath = m_agvDownloadPath;
|
|
|
|
|
|
m_agvDownloadPath.clear();
|
|
|
|
|
|
if (!success)
|
|
|
|
|
|
return;
|
|
|
|
|
|
const QJsonDocument response = QJsonDocument::fromJson(responseJson.toUtf8());
|
|
|
|
|
|
QFile output(outputPath);
|
|
|
|
|
|
if (!response.isObject() || !output.open(QIODevice::WriteOnly)) {
|
|
|
|
|
|
appendLog(QStringLiteral("ERROR"),
|
|
|
|
|
|
QStringLiteral("AGV 地图无法保存到 %1").arg(outputPath));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
output.write(response.object().value(QStringLiteral("content")).toString().toUtf8());
|
|
|
|
|
|
output.close();
|
|
|
|
|
|
appendLog(QStringLiteral("OK"),
|
|
|
|
|
|
QStringLiteral("AGV 地图已保存到 %1").arg(outputPath));
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_agvStationTable, &QTableWidget::cellDoubleClicked, this,
|
|
|
|
|
|
[this, ui](int row, int) {
|
|
|
|
|
|
if (QTableWidgetItem *item = m_agvStationTable->item(row, 0)) {
|
|
|
|
|
|
m_agvStationCombo->setCurrentText(item->text());
|
|
|
|
|
|
ui.agvTabs->setCurrentWidget(ui.navigationTab);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(ui.followPathButton, &QPushButton::clicked, this, [this, ui]() {
|
|
|
|
|
|
QVariantList path;
|
|
|
|
|
|
const QStringList lines = ui.agvPathEdit->toPlainText().split(
|
|
|
|
|
|
QLatin1Char('\n'), QString::SkipEmptyParts);
|
|
|
|
|
|
for (int row = 0; row < lines.size(); ++row) {
|
|
|
|
|
|
const QStringList pair = lines.at(row).split(QLatin1Char(','), QString::KeepEmptyParts);
|
|
|
|
|
|
if (pair.size() != 2 || pair.at(0).trimmed().isEmpty()
|
|
|
|
|
|
|| pair.at(1).trimmed().isEmpty()) {
|
2026-10-16 09:39:44 +08:00
|
|
|
|
AppMessageBox::warning(
|
2026-09-18 16:22:20 +08:00
|
|
|
|
this, QStringLiteral("路径格式错误"),
|
|
|
|
|
|
QStringLiteral("第 %1 行格式无效,请使用“起点站点,终点站点”。").arg(row + 1));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
QVariantMap segment;
|
|
|
|
|
|
segment.insert(QStringLiteral("sourceStation"), pair.at(0).trimmed());
|
|
|
|
|
|
segment.insert(QStringLiteral("targetStation"), pair.at(1).trimmed());
|
|
|
|
|
|
path.append(segment);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (path.isEmpty()) {
|
2026-10-16 09:39:44 +08:00
|
|
|
|
AppMessageBox::warning(this, QStringLiteral("路径为空"),
|
2026-09-18 16:22:20 +08:00
|
|
|
|
QStringLiteral("请至少输入一个路径段。"));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
m_client->requestAgvFollowPath(m_agvIdEdit->text().trimmed(), path,
|
|
|
|
|
|
m_agvMaxSpeedSpin->value());
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(ui.startMappingButton, &QPushButton::clicked, this, [this, ui]() {
|
|
|
|
|
|
static const QStringList dimensions = {
|
|
|
|
|
|
QStringLiteral("AGV_MAP_2D"), QStringLiteral("AGV_MAP_3D"),
|
|
|
|
|
|
QStringLiteral("AGV_MAP_2D_AND_3D")
|
|
|
|
|
|
};
|
|
|
|
|
|
QJsonObject request;
|
|
|
|
|
|
request.insert(QStringLiteral("dimension"),
|
|
|
|
|
|
dimensions.value(ui.mappingDimensionCombo->currentIndex()));
|
|
|
|
|
|
request.insert(QStringLiteral("mapName"), ui.mappingNameEdit->text().trimmed());
|
|
|
|
|
|
request.insert(QStringLiteral("realTime"), ui.mappingRealtimeCheck->isChecked());
|
|
|
|
|
|
m_client->requestRpc(QStringLiteral("cmvr.api.AgvService"),
|
|
|
|
|
|
QStringLiteral("startMapping"),
|
|
|
|
|
|
QString::fromUtf8(QJsonDocument(request).toJson(QJsonDocument::Compact)),
|
|
|
|
|
|
m_agvIdEdit->text().trimmed());
|
|
|
|
|
|
ui.mappingStateLabel->setText(QStringLiteral("建图启动请求已发送"));
|
|
|
|
|
|
});
|
2026-10-14 17:15:46 +08:00
|
|
|
|
m_agvStopMappingButton = ui.stopMappingButton;
|
2026-09-18 16:22:20 +08:00
|
|
|
|
connect(ui.stopMappingButton, &QPushButton::clicked, this, [this, ui]() {
|
2026-10-14 17:15:46 +08:00
|
|
|
|
m_agvStopMappingRetryPending = false;
|
|
|
|
|
|
m_agvStopMappingButton->setEnabled(false);
|
2026-09-18 16:22:20 +08:00
|
|
|
|
m_client->requestAgvAction(m_agvIdEdit->text().trimmed(),
|
|
|
|
|
|
QStringLiteral("StopMapping"));
|
|
|
|
|
|
ui.mappingStateLabel->setText(QStringLiteral("正在停止建图"));
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(ui.startMapStreamButton, &QPushButton::clicked, this, [this, ui]() {
|
|
|
|
|
|
m_client->startAgvMapStream(
|
|
|
|
|
|
m_agvIdEdit->text().trimmed(), ui.mappingNameEdit->text().trimmed(),
|
|
|
|
|
|
ui.mappingDimensionCombo->currentIndex() + 1,
|
|
|
|
|
|
ui.streamSnapshotCheck->isChecked(),
|
|
|
|
|
|
ui.streamIncrementalCheck->isChecked());
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(ui.stopMapStreamButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
m_client->stopAgvMapStream();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
ui.agvTabs->addTab(new RpcServiceWidget(QStringLiteral("cmvr.api.AgvService"), m_client),
|
|
|
|
|
|
QStringLiteral("全部接口"));
|
|
|
|
|
|
|
|
|
|
|
|
m_serviceButtons << ui.refreshButton << ui.navigatePoseButton << ui.navigateStationButton
|
|
|
|
|
|
<< ui.pauseButton << ui.resumeButton << ui.cancelButton
|
|
|
|
|
|
<< ui.velocityButton << statusUi.stopVelocityButton
|
|
|
|
|
|
<< statusUi.clearFaultButton
|
2026-10-14 17:15:46 +08:00
|
|
|
|
<< ui.emergencyButton << ui.inventoryButton << ui.switchMapButton << relocalizeButton
|
2026-09-18 16:22:20 +08:00
|
|
|
|
<< ui.forwardButton << ui.backwardButton << ui.leftButton << ui.rightButton
|
|
|
|
|
|
<< ui.rotateLeftButton << ui.rotateRightButton << ui.manualStopButton
|
|
|
|
|
|
<< ui.followPathButton << ui.startMappingButton << ui.stopMappingButton
|
|
|
|
|
|
<< ui.startMapStreamButton << ui.stopMapStreamButton
|
|
|
|
|
|
<< ui.uploadMapButton << ui.downloadMapButton;
|
|
|
|
|
|
return page;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget *MainWindow::createAudioPage(bool speaker)
|
|
|
|
|
|
{
|
|
|
|
|
|
QWidget *page = new QWidget;
|
|
|
|
|
|
Ui::AudioServicePage ui;
|
|
|
|
|
|
ui.setupUi(page);
|
2026-09-23 11:11:49 +08:00
|
|
|
|
if (speaker)
|
|
|
|
|
|
m_speakerIdEdit = ui.deviceIdEdit;
|
|
|
|
|
|
else
|
|
|
|
|
|
m_microphoneIdEdit = ui.deviceIdEdit;
|
2026-09-18 16:22:20 +08:00
|
|
|
|
|
|
|
|
|
|
const QString serviceName = speaker ? QStringLiteral("cmvr.api.SpeakerService")
|
|
|
|
|
|
: QStringLiteral("cmvr.api.MicPhoneService");
|
|
|
|
|
|
ui.serviceTitle->setText(speaker ? QStringLiteral("扬声器服务")
|
|
|
|
|
|
: QStringLiteral("麦克风服务"));
|
|
|
|
|
|
ui.serviceSubtitle->setText(
|
|
|
|
|
|
speaker ? QStringLiteral("采集麦克风或解码本地文件,并以 PCM 音频流发送到设备")
|
|
|
|
|
|
: QStringLiteral("从设备拉取音频流,实时解码并通过本机扬声器播放"));
|
|
|
|
|
|
ui.pathLabel->setText(speaker ? QStringLiteral("服务端音频路径")
|
|
|
|
|
|
: QStringLiteral("服务端录音路径"));
|
|
|
|
|
|
ui.pathEdit->setPlaceholderText(
|
|
|
|
|
|
speaker ? QStringLiteral("例如 C:/audio/test.wav(由设备端读取)")
|
|
|
|
|
|
: QStringLiteral("例如 C:/record/mic.wav(由设备端写入)"));
|
|
|
|
|
|
ui.startButton->setText(speaker ? QStringLiteral("播放音频")
|
|
|
|
|
|
: QStringLiteral("开始录音"));
|
|
|
|
|
|
|
|
|
|
|
|
ui.speakerStreamWidget->setVisible(speaker);
|
|
|
|
|
|
ui.microphoneStreamWidget->setVisible(!speaker);
|
|
|
|
|
|
ui.streamTitle->setText(speaker ? QStringLiteral("流式发送")
|
|
|
|
|
|
: QStringLiteral("拉流播放"));
|
|
|
|
|
|
ui.browseLocalFileButton->setIcon(style()->standardIcon(QStyle::SP_DirOpenIcon));
|
|
|
|
|
|
ui.browseLocalFileButton->setText(QString());
|
|
|
|
|
|
|
|
|
|
|
|
if (speaker) {
|
|
|
|
|
|
m_speakerStreamStartButton = ui.streamStartButton;
|
|
|
|
|
|
m_speakerStreamStopButton = ui.streamStopButton;
|
|
|
|
|
|
ui.inputDeviceCombo->addItems(AudioStreamManager::inputDeviceNames());
|
|
|
|
|
|
if (ui.inputDeviceCombo->count() == 0)
|
|
|
|
|
|
ui.inputDeviceCombo->addItem(QStringLiteral("未检测到音频输入设备"));
|
|
|
|
|
|
auto updateSourceControls = [sourceCombo = ui.sourceCombo,
|
|
|
|
|
|
inputCombo = ui.inputDeviceCombo,
|
|
|
|
|
|
fileEdit = ui.localFileEdit,
|
|
|
|
|
|
browseButton = ui.browseLocalFileButton]() {
|
|
|
|
|
|
const bool fileSource = sourceCombo->currentIndex() == 1;
|
|
|
|
|
|
inputCombo->setEnabled(!fileSource);
|
|
|
|
|
|
fileEdit->setEnabled(fileSource);
|
|
|
|
|
|
browseButton->setEnabled(fileSource);
|
|
|
|
|
|
};
|
|
|
|
|
|
connect(ui.sourceCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
|
|
|
|
|
page, [updateSourceControls](int) { updateSourceControls(); });
|
|
|
|
|
|
updateSourceControls();
|
|
|
|
|
|
connect(ui.browseLocalFileButton, &QPushButton::clicked, page,
|
|
|
|
|
|
[this, fileEdit = ui.localFileEdit]() {
|
|
|
|
|
|
const QString fileName = QFileDialog::getOpenFileName(
|
|
|
|
|
|
this, QStringLiteral("选择音频文件"), fileEdit->text(),
|
|
|
|
|
|
QStringLiteral("音频文件 (*.wav *.mp3 *.aac *.m4a *.wma);;所有文件 (*.*)"));
|
|
|
|
|
|
if (!fileName.isEmpty())
|
|
|
|
|
|
fileEdit->setText(QDir::toNativeSeparators(fileName));
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(ui.streamStartButton, &QPushButton::clicked, page,
|
|
|
|
|
|
[this, deviceEdit = ui.deviceIdEdit, sourceCombo = ui.sourceCombo,
|
|
|
|
|
|
inputCombo = ui.inputDeviceCombo, fileEdit = ui.localFileEdit,
|
|
|
|
|
|
sampleRateCombo = ui.sampleRateCombo,
|
|
|
|
|
|
channelsCombo = ui.channelsCombo, stateLabel = ui.streamStateLabel]() {
|
|
|
|
|
|
const QString deviceId = deviceEdit->text().trimmed();
|
|
|
|
|
|
if (deviceId.isEmpty()) {
|
2026-10-16 09:39:44 +08:00
|
|
|
|
AppMessageBox::warning(this, QStringLiteral("流式发送"),
|
2026-09-18 16:22:20 +08:00
|
|
|
|
QStringLiteral("请填写扬声器设备 ID。"));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
const int sampleRate = sampleRateCombo->currentText().toInt();
|
|
|
|
|
|
const int channels = channelsCombo->currentIndex() + 1;
|
|
|
|
|
|
m_client->startSpeakerAudioStream(deviceId);
|
|
|
|
|
|
const bool started = sourceCombo->currentIndex() == 0
|
|
|
|
|
|
? m_audioManager->startCapture(inputCombo->currentText(), sampleRate, channels)
|
|
|
|
|
|
: m_audioManager->startFileDecode(fileEdit->text().trimmed(), sampleRate, channels);
|
|
|
|
|
|
if (!started)
|
|
|
|
|
|
m_client->stopSpeakerAudioStream();
|
|
|
|
|
|
else
|
|
|
|
|
|
stateLabel->setText(QStringLiteral("正在启动流式发送..."));
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(ui.streamStopButton, &QPushButton::clicked, page, [this]() {
|
|
|
|
|
|
m_audioManager->stopSource();
|
|
|
|
|
|
m_client->stopSpeakerAudioStream();
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_audioManager, &AudioStreamManager::sourceStateChanged, page,
|
|
|
|
|
|
[this, startButton = ui.streamStartButton, stopButton = ui.streamStopButton,
|
|
|
|
|
|
deviceEdit = ui.deviceIdEdit, stateLabel = ui.streamStateLabel]
|
|
|
|
|
|
(bool running, const QString &detail) {
|
|
|
|
|
|
startButton->setEnabled(m_connected && !running);
|
|
|
|
|
|
stopButton->setEnabled(m_connected && running);
|
|
|
|
|
|
deviceEdit->setEnabled(!running);
|
|
|
|
|
|
stateLabel->setText(detail);
|
|
|
|
|
|
if (!running)
|
|
|
|
|
|
m_client->stopSpeakerAudioStream();
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
m_microphoneStreamStartButton = ui.playbackStartButton;
|
|
|
|
|
|
m_microphoneStreamStopButton = ui.playbackStopButton;
|
|
|
|
|
|
ui.outputDeviceCombo->addItems(AudioStreamManager::outputDeviceNames());
|
|
|
|
|
|
if (ui.outputDeviceCombo->count() == 0)
|
|
|
|
|
|
ui.outputDeviceCombo->addItem(QStringLiteral("未检测到音频输出设备"));
|
|
|
|
|
|
connect(ui.localVolumeSlider, &QSlider::valueChanged, page,
|
|
|
|
|
|
[this, valueLabel = ui.localVolumeValue](int value) {
|
|
|
|
|
|
valueLabel->setText(QStringLiteral("%1 %").arg(value));
|
|
|
|
|
|
m_audioManager->setOutputVolume(value);
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(ui.playbackStartButton, &QPushButton::clicked, page,
|
|
|
|
|
|
[this, deviceEdit = ui.deviceIdEdit,
|
|
|
|
|
|
outputCombo = ui.outputDeviceCombo,
|
|
|
|
|
|
volumeSlider = ui.localVolumeSlider,
|
|
|
|
|
|
stateLabel = ui.streamStateLabel]() {
|
|
|
|
|
|
const QString deviceId = deviceEdit->text().trimmed();
|
|
|
|
|
|
if (deviceId.isEmpty()) {
|
2026-10-16 09:39:44 +08:00
|
|
|
|
AppMessageBox::warning(this, QStringLiteral("拉流播放"),
|
2026-09-18 16:22:20 +08:00
|
|
|
|
QStringLiteral("请填写麦克风设备 ID。"));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
m_audioManager->setOutputDevice(outputCombo->currentText());
|
|
|
|
|
|
m_audioManager->setOutputVolume(volumeSlider->value());
|
|
|
|
|
|
m_client->startMicrophoneAudioStream(deviceId);
|
|
|
|
|
|
stateLabel->setText(QStringLiteral("正在建立音频拉流..."));
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(ui.playbackStopButton, &QPushButton::clicked, page, [this]() {
|
|
|
|
|
|
m_client->stopMicrophoneAudioStream();
|
|
|
|
|
|
m_audioManager->stopPlayback();
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_audioManager, &AudioStreamManager::playbackStateChanged, page,
|
|
|
|
|
|
[this, stateLabel = ui.streamStateLabel](bool running, const QString &detail) {
|
|
|
|
|
|
stateLabel->setText(detail);
|
|
|
|
|
|
if (!running && m_connected)
|
|
|
|
|
|
m_client->stopMicrophoneAudioStream();
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_audioManager, &AudioStreamManager::playbackStatistics, page,
|
|
|
|
|
|
[statsLabel = ui.streamStatsLabel](quint64 frames, quint64 bytes,
|
|
|
|
|
|
qint64 durationMs) {
|
|
|
|
|
|
statsLabel->setText(QStringLiteral("%1 帧 / %2 KB / %3 s")
|
|
|
|
|
|
.arg(frames).arg(bytes / 1024.0, 0, 'f', 1)
|
|
|
|
|
|
.arg(durationMs / 1000.0, 0, 'f', 1));
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
connect(m_client, &RobotClient::audioStreamStateChanged, page,
|
|
|
|
|
|
[this, serviceName, speaker, startButton = speaker ? ui.streamStartButton
|
|
|
|
|
|
: ui.playbackStartButton,
|
|
|
|
|
|
stopButton = speaker ? ui.streamStopButton : ui.playbackStopButton,
|
|
|
|
|
|
deviceEdit = ui.deviceIdEdit, stateLabel = ui.streamStateLabel]
|
|
|
|
|
|
(const QString &service, bool running, const QString &detail) {
|
|
|
|
|
|
if (service != (speaker ? QStringLiteral("SpeakerService")
|
|
|
|
|
|
: QStringLiteral("MicPhoneService")))
|
|
|
|
|
|
return;
|
|
|
|
|
|
startButton->setEnabled(m_connected && !running);
|
|
|
|
|
|
stopButton->setEnabled(m_connected && running);
|
|
|
|
|
|
deviceEdit->setEnabled(!running);
|
|
|
|
|
|
stateLabel->setText(detail);
|
|
|
|
|
|
if (!running) {
|
|
|
|
|
|
if (speaker)
|
|
|
|
|
|
m_audioManager->stopSource();
|
|
|
|
|
|
else
|
|
|
|
|
|
m_audioManager->stopPlayback();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_client, &RobotClient::audioStreamStatistics, page,
|
|
|
|
|
|
[serviceName, statsLabel = ui.streamStatsLabel]
|
|
|
|
|
|
(const QString &service, quint64 frames, quint64 bytes, qint64 durationMs) {
|
|
|
|
|
|
const QString expected = serviceName.section(QLatin1Char('.'), -1);
|
|
|
|
|
|
if (service != expected)
|
|
|
|
|
|
return;
|
|
|
|
|
|
statsLabel->setText(QStringLiteral("%1 帧 / %2 KB / %3 s")
|
|
|
|
|
|
.arg(frames).arg(bytes / 1024.0, 0, 'f', 1)
|
|
|
|
|
|
.arg(durationMs / 1000.0, 0, 'f', 1));
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
auto request = [this, serviceName, deviceEdit = ui.deviceIdEdit,
|
|
|
|
|
|
pathEdit = ui.pathEdit, volumeSpin = ui.volumeSpin,
|
|
|
|
|
|
speaker](const QString &method) {
|
|
|
|
|
|
QJsonObject header;
|
|
|
|
|
|
header.insert(QStringLiteral("deviceId"), deviceEdit->text().trimmed());
|
|
|
|
|
|
QJsonObject document;
|
|
|
|
|
|
document.insert(QStringLiteral("header"), header);
|
|
|
|
|
|
if (method == QStringLiteral("PlayAudio"))
|
|
|
|
|
|
document.insert(QStringLiteral("audioPath"), pathEdit->text().trimmed());
|
|
|
|
|
|
else if (method == QStringLiteral("StartRecord"))
|
|
|
|
|
|
document.insert(QStringLiteral("filePath"), pathEdit->text().trimmed());
|
|
|
|
|
|
else if (method == QStringLiteral("SetVolume"))
|
|
|
|
|
|
document.insert(QStringLiteral("volume"), volumeSpin->value());
|
|
|
|
|
|
m_client->requestRpc(serviceName, method,
|
|
|
|
|
|
QString::fromUtf8(QJsonDocument(document).toJson(QJsonDocument::Compact)),
|
|
|
|
|
|
deviceEdit->text().trimmed());
|
|
|
|
|
|
Q_UNUSED(speaker)
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
connect(ui.statusButton, &QPushButton::clicked, this,
|
|
|
|
|
|
[request]() { request(QStringLiteral("GetStatus")); });
|
|
|
|
|
|
connect(ui.startButton, &QPushButton::clicked, this,
|
|
|
|
|
|
[request, speaker]() { request(speaker ? QStringLiteral("PlayAudio")
|
|
|
|
|
|
: QStringLiteral("StartRecord")); });
|
|
|
|
|
|
connect(ui.pauseButton, &QPushButton::clicked, this,
|
|
|
|
|
|
[request, speaker]() { request(speaker ? QStringLiteral("PausePlayback")
|
|
|
|
|
|
: QStringLiteral("PauseRecord")); });
|
|
|
|
|
|
connect(ui.resumeButton, &QPushButton::clicked, this,
|
|
|
|
|
|
[request, speaker]() { request(speaker ? QStringLiteral("ResumePlayback")
|
|
|
|
|
|
: QStringLiteral("ResumeRecord")); });
|
|
|
|
|
|
connect(ui.stopButton, &QPushButton::clicked, this,
|
|
|
|
|
|
[request, speaker]() { request(speaker ? QStringLiteral("StopPlayback")
|
|
|
|
|
|
: QStringLiteral("StopRecord")); });
|
|
|
|
|
|
connect(ui.getVolumeButton, &QPushButton::clicked, this,
|
|
|
|
|
|
[request]() { request(QStringLiteral("GetVolume")); });
|
|
|
|
|
|
connect(ui.setVolumeButton, &QPushButton::clicked, this,
|
|
|
|
|
|
[request]() { request(QStringLiteral("SetVolume")); });
|
|
|
|
|
|
|
|
|
|
|
|
QLabel *resultLabel = ui.resultLabel;
|
|
|
|
|
|
connect(m_client, &RobotClient::rpcFinished, page,
|
|
|
|
|
|
[serviceName, resultLabel](const QString &service, const QString &method,
|
|
|
|
|
|
bool success, const QString &response) {
|
|
|
|
|
|
if (service != serviceName)
|
|
|
|
|
|
return;
|
|
|
|
|
|
resultLabel->setText(QStringLiteral("%1 %2\n%3")
|
|
|
|
|
|
.arg(method, success ? QStringLiteral("成功")
|
|
|
|
|
|
: QStringLiteral("失败"),
|
|
|
|
|
|
response.left(1000)));
|
|
|
|
|
|
});
|
|
|
|
|
|
m_serviceButtons << ui.statusButton << ui.startButton << ui.pauseButton
|
|
|
|
|
|
<< ui.resumeButton << ui.stopButton << ui.getVolumeButton
|
|
|
|
|
|
<< ui.setVolumeButton;
|
|
|
|
|
|
return withRpcExplorer(page, m_client, serviceName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget *MainWindow::createRpcPage(const QString &serviceName)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new RpcServiceWidget(serviceName, m_client);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-14 17:15:46 +08:00
|
|
|
|
QWidget *MainWindow::createDexHandPage()
|
|
|
|
|
|
{
|
|
|
|
|
|
QWidget *page = new QWidget;
|
|
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout(page);
|
|
|
|
|
|
layout->setContentsMargins(16, 12, 16, 14);
|
|
|
|
|
|
layout->setSpacing(10);
|
|
|
|
|
|
|
|
|
|
|
|
QFrame *header = new QFrame(page);
|
|
|
|
|
|
header->setObjectName(QStringLiteral("panel"));
|
|
|
|
|
|
QHBoxLayout *headerLayout = new QHBoxLayout(header);
|
|
|
|
|
|
QLabel *title = new QLabel(QStringLiteral("灵巧手控制"), header);
|
|
|
|
|
|
title->setObjectName(QStringLiteral("sectionTitle"));
|
|
|
|
|
|
m_dexHandDeviceCombo = new QComboBox(header);
|
|
|
|
|
|
m_dexHandDeviceCombo->setMinimumWidth(320);
|
|
|
|
|
|
m_dexHandDeviceCombo->setToolTip(QStringLiteral("从 cmvr-es 在线设备列表自动加载"));
|
|
|
|
|
|
QPushButton *refreshButton = new QPushButton(QStringLiteral("刷新状态"), header);
|
|
|
|
|
|
m_dexHandStateLabel = new QLabel(QStringLiteral("未获取"), header);
|
|
|
|
|
|
m_dexHandStateLabel->setObjectName(QStringLiteral("panelSubtitle"));
|
|
|
|
|
|
headerLayout->addWidget(title);
|
|
|
|
|
|
headerLayout->addStretch(1);
|
|
|
|
|
|
headerLayout->addWidget(new QLabel(QStringLiteral("设备"), header));
|
|
|
|
|
|
headerLayout->addWidget(m_dexHandDeviceCombo);
|
|
|
|
|
|
headerLayout->addWidget(refreshButton);
|
|
|
|
|
|
headerLayout->addWidget(m_dexHandStateLabel);
|
|
|
|
|
|
layout->addWidget(header);
|
|
|
|
|
|
|
|
|
|
|
|
QSplitter *splitter = new QSplitter(Qt::Vertical, page);
|
|
|
|
|
|
splitter->setChildrenCollapsible(false);
|
|
|
|
|
|
m_dexHandStateTable = new QTableWidget(6, 8, splitter);
|
|
|
|
|
|
m_dexHandStateTable->setHorizontalHeaderLabels({
|
|
|
|
|
|
QStringLiteral("自由度"), QStringLiteral("角度"), QStringLiteral("位置"),
|
|
|
|
|
|
QStringLiteral("速度"), QStringLiteral("受力"), QStringLiteral("电流"),
|
|
|
|
|
|
QStringLiteral("温度"), QStringLiteral("状态")});
|
|
|
|
|
|
m_dexHandStateTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
|
|
m_dexHandStateTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
|
|
m_dexHandStateTable->verticalHeader()->setVisible(false);
|
|
|
|
|
|
m_dexHandStateTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
|
|
|
|
m_dexHandStateTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
|
|
|
|
|
|
|
|
|
|
|
QFrame *tactilePanel = new QFrame(splitter);
|
|
|
|
|
|
m_dexHandTactilePanel = tactilePanel;
|
|
|
|
|
|
tactilePanel->setObjectName(QStringLiteral("panel"));
|
|
|
|
|
|
QVBoxLayout *tactileLayout = new QVBoxLayout(tactilePanel);
|
|
|
|
|
|
QHBoxLayout *tactileHeader = new QHBoxLayout;
|
|
|
|
|
|
QLabel *tactileTitle = new QLabel(QStringLiteral("食指触觉(12 × 5)"), tactilePanel);
|
|
|
|
|
|
tactileTitle->setObjectName(QStringLiteral("sectionTitle"));
|
|
|
|
|
|
m_dexHandTactileStateLabel = new QLabel(QStringLiteral("未启动"), tactilePanel);
|
|
|
|
|
|
m_dexHandTactileStateLabel->setObjectName(QStringLiteral("panelSubtitle"));
|
|
|
|
|
|
m_dexHandTactileStartButton = new QPushButton(QStringLiteral("开始触觉流"), tactilePanel);
|
|
|
|
|
|
m_dexHandTactileStopButton = new QPushButton(QStringLiteral("停止"), tactilePanel);
|
|
|
|
|
|
m_dexHandTactileStopButton->setEnabled(false);
|
|
|
|
|
|
tactileHeader->addWidget(tactileTitle);
|
|
|
|
|
|
tactileHeader->addStretch(1);
|
|
|
|
|
|
tactileHeader->addWidget(m_dexHandTactileStateLabel);
|
|
|
|
|
|
tactileHeader->addWidget(m_dexHandTactileStartButton);
|
|
|
|
|
|
tactileHeader->addWidget(m_dexHandTactileStopButton);
|
|
|
|
|
|
tactileLayout->addLayout(tactileHeader);
|
|
|
|
|
|
m_dexHandTactileHeatmap = new TactileHeatmapWidget(tactilePanel);
|
|
|
|
|
|
m_dexHandTactileHeatmap->setToolTip(
|
|
|
|
|
|
QStringLiteral("颜色表示单点法向力;数值单位 mN"));
|
|
|
|
|
|
tactileLayout->addWidget(m_dexHandTactileHeatmap);
|
|
|
|
|
|
// Keep tactile controls hidden until GetStatus explicitly reports support.
|
|
|
|
|
|
tactilePanel->hide();
|
|
|
|
|
|
|
|
|
|
|
|
m_dexHandCommandTabs = new QTabWidget(splitter);
|
|
|
|
|
|
m_dexHandCommandTabs->setDocumentMode(true);
|
|
|
|
|
|
const QStringList freedomNames = {
|
|
|
|
|
|
QStringLiteral("小拇指"), QStringLiteral("无名指"), QStringLiteral("中指"),
|
|
|
|
|
|
QStringLiteral("食指"), QStringLiteral("大拇指弯曲"), QStringLiteral("大拇指旋转")};
|
|
|
|
|
|
const auto addCommandPage = [this, &freedomNames, refreshButton](const QString &titleText,
|
|
|
|
|
|
const QString &command,
|
|
|
|
|
|
QList<QDoubleSpinBox *> &spins) {
|
|
|
|
|
|
QWidget *commandPage = new QWidget(m_dexHandCommandTabs);
|
|
|
|
|
|
QVBoxLayout *commandLayout = new QVBoxLayout(commandPage);
|
|
|
|
|
|
commandLayout->setContentsMargins(12, 12, 12, 12);
|
|
|
|
|
|
QLabel *hint = new QLabel(
|
|
|
|
|
|
QStringLiteral("按服务端统一归一化范围设置;100% 对应设备该参数最大值。"),
|
|
|
|
|
|
commandPage);
|
|
|
|
|
|
hint->setObjectName(QStringLiteral("panelSubtitle"));
|
|
|
|
|
|
commandLayout->addWidget(hint);
|
|
|
|
|
|
QGridLayout *grid = new QGridLayout;
|
|
|
|
|
|
grid->setHorizontalSpacing(12);
|
|
|
|
|
|
grid->setVerticalSpacing(8);
|
|
|
|
|
|
for (int index = 0; index < freedomNames.size(); ++index) {
|
|
|
|
|
|
QLabel *label = new QLabel(freedomNames.at(index), commandPage);
|
|
|
|
|
|
QDoubleSpinBox *spin = new QDoubleSpinBox(commandPage);
|
|
|
|
|
|
spin->setRange(0.0, 100.0);
|
|
|
|
|
|
spin->setDecimals(1);
|
|
|
|
|
|
spin->setSingleStep(1.0);
|
|
|
|
|
|
spin->setSuffix(QStringLiteral(" %"));
|
|
|
|
|
|
spins.append(spin);
|
|
|
|
|
|
grid->addWidget(label, index / 2, (index % 2) * 2);
|
|
|
|
|
|
grid->addWidget(spin, index / 2, (index % 2) * 2 + 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
commandLayout->addLayout(grid);
|
|
|
|
|
|
QHBoxLayout *actions = new QHBoxLayout;
|
|
|
|
|
|
QPushButton *copyButton = new QPushButton(QStringLiteral("复制当前状态"), commandPage);
|
|
|
|
|
|
QPushButton *sendButton = new QPushButton(QStringLiteral("发送%1").arg(titleText), commandPage);
|
|
|
|
|
|
sendButton->setObjectName(QStringLiteral("primaryButton"));
|
|
|
|
|
|
actions->addStretch(1);
|
|
|
|
|
|
actions->addWidget(copyButton);
|
|
|
|
|
|
actions->addWidget(sendButton);
|
|
|
|
|
|
commandLayout->addLayout(actions);
|
|
|
|
|
|
const QList<QDoubleSpinBox *> commandSpins = spins;
|
|
|
|
|
|
connect(copyButton, &QPushButton::clicked, this, [this, command, commandSpins]() {
|
|
|
|
|
|
const QString key = command == QStringLiteral("angle") ? QStringLiteral("angle")
|
|
|
|
|
|
: command == QStringLiteral("position") ? QStringLiteral("position")
|
|
|
|
|
|
: command == QStringLiteral("speed") ? QStringLiteral("speed")
|
|
|
|
|
|
: QStringLiteral("force");
|
|
|
|
|
|
const double maximum = command == QStringLiteral("position") ? 2000.0
|
|
|
|
|
|
: command == QStringLiteral("force") ? 3000.0 : 1000.0;
|
|
|
|
|
|
for (int row = 0; row < commandSpins.size() && row < m_dexHandStateTable->rowCount(); ++row) {
|
|
|
|
|
|
const int column = key == QStringLiteral("angle") ? 1
|
|
|
|
|
|
: key == QStringLiteral("position") ? 2
|
|
|
|
|
|
: key == QStringLiteral("speed") ? 3 : 4;
|
|
|
|
|
|
const QTableWidgetItem *item = m_dexHandStateTable->item(row, column);
|
|
|
|
|
|
if (item)
|
|
|
|
|
|
commandSpins.at(row)->setValue(item->text().toDouble() * 100.0 / maximum);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(sendButton, &QPushButton::clicked, this, [this, command, commandSpins]() {
|
|
|
|
|
|
const QString deviceId = m_dexHandDeviceCombo->currentData().toString();
|
|
|
|
|
|
if (deviceId.isEmpty()) {
|
2026-10-16 09:39:44 +08:00
|
|
|
|
AppMessageBox::warning(this, QStringLiteral("灵巧手控制"),
|
2026-10-14 17:15:46 +08:00
|
|
|
|
QStringLiteral("服务端未返回可用灵巧手设备"));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
QVariantList values;
|
|
|
|
|
|
for (QDoubleSpinBox *spin : commandSpins)
|
|
|
|
|
|
values.append(spin->value() / 100.0);
|
|
|
|
|
|
m_client->requestDexHandCommand(deviceId, command, values);
|
|
|
|
|
|
});
|
|
|
|
|
|
m_serviceButtons << refreshButton << copyButton << sendButton;
|
|
|
|
|
|
m_dexHandCommandTabs->addTab(commandPage, titleText);
|
|
|
|
|
|
};
|
|
|
|
|
|
addCommandPage(QStringLiteral("角度"), QStringLiteral("angle"), m_dexHandAngleSpins);
|
|
|
|
|
|
addCommandPage(QStringLiteral("位置"), QStringLiteral("position"), m_dexHandPositionSpins);
|
|
|
|
|
|
addCommandPage(QStringLiteral("速度"), QStringLiteral("speed"), m_dexHandSpeedSpins);
|
|
|
|
|
|
addCommandPage(QStringLiteral("力"), QStringLiteral("force"), m_dexHandForceSpins);
|
|
|
|
|
|
|
|
|
|
|
|
splitter->addWidget(m_dexHandStateTable);
|
|
|
|
|
|
splitter->addWidget(tactilePanel);
|
|
|
|
|
|
splitter->addWidget(m_dexHandCommandTabs);
|
|
|
|
|
|
splitter->setStretchFactor(0, 2);
|
|
|
|
|
|
splitter->setStretchFactor(1, 3);
|
|
|
|
|
|
splitter->setStretchFactor(2, 3);
|
|
|
|
|
|
layout->addWidget(splitter, 1);
|
|
|
|
|
|
|
|
|
|
|
|
const auto refresh = [this]() {
|
|
|
|
|
|
const QString deviceId = m_dexHandDeviceCombo->currentData().toString();
|
|
|
|
|
|
if (m_connected && !deviceId.isEmpty())
|
|
|
|
|
|
m_client->requestDexHandStatus(deviceId);
|
|
|
|
|
|
};
|
|
|
|
|
|
connect(refreshButton, &QPushButton::clicked, this, refresh);
|
|
|
|
|
|
connect(m_dexHandDeviceCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
|
|
|
|
|
this, [this, refresh](int) {
|
|
|
|
|
|
m_client->stopDexHandTactileStream();
|
|
|
|
|
|
refresh();
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_dexHandTactileStartButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
const QString deviceId = m_dexHandDeviceCombo->currentData().toString();
|
|
|
|
|
|
if (!deviceId.isEmpty()) m_client->startDexHandTactileStream(deviceId);
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_dexHandTactileStopButton, &QPushButton::clicked,
|
|
|
|
|
|
m_client, &RobotClient::stopDexHandTactileStream);
|
|
|
|
|
|
m_serviceButtons << m_dexHandTactileStartButton << m_dexHandTactileStopButton;
|
|
|
|
|
|
m_dexHandRefreshTimer = new QTimer(page);
|
|
|
|
|
|
m_dexHandRefreshTimer->setInterval(1000);
|
|
|
|
|
|
connect(m_dexHandRefreshTimer, &QTimer::timeout, this, refresh);
|
|
|
|
|
|
m_dexHandRefreshTimer->start();
|
|
|
|
|
|
|
|
|
|
|
|
return withRpcExplorer(page, m_client, QStringLiteral("cmvr.api.DexHandService"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-18 16:22:20 +08:00
|
|
|
|
QWidget *MainWindow::createQuicPage()
|
|
|
|
|
|
{
|
|
|
|
|
|
QWidget *page = new QWidget;
|
|
|
|
|
|
Ui::QuicServerPage ui;
|
|
|
|
|
|
ui.setupUi(page);
|
|
|
|
|
|
|
|
|
|
|
|
m_quicBindEdit = ui.quicBindEdit;
|
|
|
|
|
|
m_quicPortSpin = ui.quicPortSpin;
|
|
|
|
|
|
m_quicAlpnEdit = ui.quicAlpnEdit;
|
|
|
|
|
|
m_quicCertificateEdit = ui.quicCertificateEdit;
|
|
|
|
|
|
m_quicPasswordEdit = ui.quicPasswordEdit;
|
|
|
|
|
|
m_quicToggleButton = ui.quicToggleButton;
|
|
|
|
|
|
m_quicStateValue = ui.quicStateValue;
|
|
|
|
|
|
m_quicBoundValue = ui.quicBoundValue;
|
|
|
|
|
|
m_quicClientValue = ui.quicClientValue;
|
|
|
|
|
|
m_quicRegistrationValue = ui.quicRegistrationValue;
|
|
|
|
|
|
m_quicHeartbeatValue = ui.quicHeartbeatValue;
|
|
|
|
|
|
m_quicDatagramValue = ui.quicDatagramValue;
|
|
|
|
|
|
m_quicDatagramBytesValue = ui.quicDatagramBytesValue;
|
|
|
|
|
|
m_quicNodeValue = ui.quicNodeValue;
|
|
|
|
|
|
m_quicBootValue = ui.quicBootValue;
|
|
|
|
|
|
m_quicGrpcValue = ui.quicGrpcValue;
|
|
|
|
|
|
m_quicPeerValue = ui.quicPeerValue;
|
|
|
|
|
|
m_quicLogView = ui.quicLogView;
|
|
|
|
|
|
ui.browseCertificateButton->setIcon(style()->standardIcon(QStyle::SP_DirOpenIcon));
|
|
|
|
|
|
ui.clearQuicLogButton->setIcon(style()->standardIcon(QStyle::SP_DialogResetButton));
|
|
|
|
|
|
ui.configurationGrid->setColumnStretch(0, 3);
|
|
|
|
|
|
ui.configurationGrid->setColumnStretch(1, 1);
|
|
|
|
|
|
ui.configurationGrid->setColumnStretch(2, 2);
|
|
|
|
|
|
for (int column = 0; column < 6; ++column)
|
|
|
|
|
|
ui.statusLayout->setColumnStretch(column, column == 0 ? 2 : 1);
|
|
|
|
|
|
for (int column = 0; column < 4; ++column)
|
|
|
|
|
|
ui.nodeLayout->setColumnStretch(column, 1);
|
|
|
|
|
|
m_quicLogView->document()->setMaximumBlockCount(800);
|
|
|
|
|
|
|
|
|
|
|
|
connect(ui.browseCertificateButton, &QPushButton::clicked, this, [this]() {
|
|
|
|
|
|
const QString path = QFileDialog::getOpenFileName(
|
|
|
|
|
|
this, QStringLiteral("选择 QUIC 测试证书"), m_quicCertificateEdit->text(),
|
|
|
|
|
|
QStringLiteral("PKCS#12 证书 (*.pfx *.p12);;所有文件 (*.*)"));
|
|
|
|
|
|
if (!path.isEmpty())
|
|
|
|
|
|
m_quicCertificateEdit->setText(QDir::toNativeSeparators(path));
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_quicToggleButton, &QPushButton::clicked,
|
|
|
|
|
|
this, &MainWindow::toggleQuicServer);
|
|
|
|
|
|
connect(ui.clearQuicLogButton, &QPushButton::clicked,
|
|
|
|
|
|
m_quicLogView, &QTextEdit::clear);
|
|
|
|
|
|
return page;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget *MainWindow::createDiagnosticsPage()
|
|
|
|
|
|
{
|
|
|
|
|
|
QWidget *page = new QWidget;
|
|
|
|
|
|
Ui::DiagnosticsPage ui;
|
|
|
|
|
|
ui.setupUi(page);
|
|
|
|
|
|
|
|
|
|
|
|
m_endpointValue = ui.endpointValue;
|
|
|
|
|
|
m_backendValue = ui.backendValue;
|
|
|
|
|
|
m_buildValue = ui.buildValue;
|
|
|
|
|
|
m_logView = ui.logView;
|
|
|
|
|
|
m_backendValue->setText(m_client->grpcAvailable()
|
|
|
|
|
|
? QStringLiteral("gRPC C++")
|
|
|
|
|
|
: QStringLiteral("Demo only"));
|
|
|
|
|
|
m_buildValue->setText(QStringLiteral("Qt %1 · %2")
|
|
|
|
|
|
.arg(QString::fromLatin1(qVersion()),
|
|
|
|
|
|
#ifdef QT_NO_DEBUG
|
|
|
|
|
|
QStringLiteral("Release")));
|
|
|
|
|
|
#else
|
|
|
|
|
|
QStringLiteral("Debug")));
|
|
|
|
|
|
#endif
|
|
|
|
|
|
ui.infoLayout->setColumnStretch(0, 2);
|
|
|
|
|
|
ui.infoLayout->setColumnStretch(1, 1);
|
|
|
|
|
|
ui.infoLayout->setColumnStretch(2, 1);
|
|
|
|
|
|
ui.clearLogButton->setIcon(style()->standardIcon(QStyle::SP_DialogResetButton));
|
|
|
|
|
|
m_logView->document()->setMaximumBlockCount(1200);
|
|
|
|
|
|
connect(ui.clearLogButton, &QPushButton::clicked, m_logView, &QTextEdit::clear);
|
|
|
|
|
|
return page;
|
|
|
|
|
|
}
|