1207 lines
56 KiB
C++
1207 lines
56 KiB
C++
|
|
#include "mainwindow.h"
|
||
|
|
#include "videorenderwidget.h"
|
||
|
|
|
||
|
|
#include "audiostreammanager.h"
|
||
|
|
#include "configeditorwidget.h"
|
||
|
|
#include "robotclient.h"
|
||
|
|
#include "quictestserver.h"
|
||
|
|
#include "trendwidget.h"
|
||
|
|
#include "uiicons.h"
|
||
|
|
#include "urdfviewerwidget.h"
|
||
|
|
#include "ui_mainwindow.h"
|
||
|
|
|
||
|
|
#include <QButtonGroup>
|
||
|
|
#include <QCheckBox>
|
||
|
|
#include <QComboBox>
|
||
|
|
#include <QCoreApplication>
|
||
|
|
#include <QCursor>
|
||
|
|
#include <QDateTime>
|
||
|
|
#include <QDoubleSpinBox>
|
||
|
|
#include <QDir>
|
||
|
|
#include <QEvent>
|
||
|
|
#include <QFileDialog>
|
||
|
|
#include <QFileInfo>
|
||
|
|
#include <QHeaderView>
|
||
|
|
#include <QHBoxLayout>
|
||
|
|
#include <QImage>
|
||
|
|
#include <QLabel>
|
||
|
|
#include <QLineEdit>
|
||
|
|
#include <QListView>
|
||
|
|
#include <QMessageBox>
|
||
|
|
#include <QPainter>
|
||
|
|
#include <QPixmap>
|
||
|
|
#include <QProgressBar>
|
||
|
|
#include <QPushButton>
|
||
|
|
#include <QResizeEvent>
|
||
|
|
#include <QSettings>
|
||
|
|
#include <QSpinBox>
|
||
|
|
#include <QStackedWidget>
|
||
|
|
#include <QStyle>
|
||
|
|
#include <QTableWidget>
|
||
|
|
#include <QTextEdit>
|
||
|
|
#include <QTimer>
|
||
|
|
#include <QtMath>
|
||
|
|
|
||
|
|
#ifdef Q_OS_WIN
|
||
|
|
#include <windows.h>
|
||
|
|
#endif
|
||
|
|
|
||
|
|
namespace {
|
||
|
|
const QStringList kPageTitles = {
|
||
|
|
QStringLiteral("SystemService"), QStringLiteral("机械臂控制"),
|
||
|
|
QStringLiteral("CameraService"), QStringLiteral("AgvService"),
|
||
|
|
QStringLiteral("SpeakerService"), QStringLiteral("MicPhoneService"),
|
||
|
|
QStringLiteral("DexHandService"), QStringLiteral("BioHeadService"),
|
||
|
|
QStringLiteral("HlcService"), QStringLiteral("TestService"),
|
||
|
|
QStringLiteral("QUIC Server"),
|
||
|
|
QStringLiteral("项目配置"),
|
||
|
|
QStringLiteral("运行日志")
|
||
|
|
};
|
||
|
|
const QStringList kPageSubtitles = {
|
||
|
|
QStringLiteral("系统信息、运行资源与全局停止"),
|
||
|
|
QStringLiteral("设备服务 / ArmService"),
|
||
|
|
QStringLiteral("相机状态、图像采集与预览"),
|
||
|
|
QStringLiteral("底盘状态、导航、速度与地图操作"),
|
||
|
|
QStringLiteral("扬声器状态、音频播放、流式音频与音量控制"),
|
||
|
|
QStringLiteral("麦克风状态、录音、音频流与音量控制"),
|
||
|
|
QStringLiteral("灵巧手状态、位置、角度、力、速度与传感器"),
|
||
|
|
QStringLiteral("仿生头状态、表情、说话动作与紧急停止"),
|
||
|
|
QStringLiteral("触控坐标与最大作用力控制"),
|
||
|
|
QStringLiteral("测试服务原始请求与反馈"),
|
||
|
|
QStringLiteral("监听 edge 接入、注册、心跳与媒体数据报"),
|
||
|
|
QStringLiteral("远端查看、校验并编辑 cmvr_es 项目配置"),
|
||
|
|
QStringLiteral("检查连接信息与 RPC 执行记录")
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
MainWindow::MainWindow(QWidget *parent)
|
||
|
|
: QMainWindow(parent), m_client(new RobotClient(this)),
|
||
|
|
m_audioManager(new AudioStreamManager(this)),
|
||
|
|
m_quicServer(new QuicTestServer(this))
|
||
|
|
{
|
||
|
|
setWindowFlags(Qt::Window | Qt::FramelessWindowHint
|
||
|
|
| Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint
|
||
|
|
| Qt::WindowCloseButtonHint);
|
||
|
|
setAttribute(Qt::WA_NativeWindow);
|
||
|
|
|
||
|
|
Ui::MainWindowForm ui;
|
||
|
|
ui.setupUi(this);
|
||
|
|
m_windowSurface = ui.windowSurface;
|
||
|
|
m_customTitleBar = ui.customTitleBar;
|
||
|
|
m_titleBarPage = ui.titleBarPage;
|
||
|
|
m_titleBarBuild = ui.titleBarBuild;
|
||
|
|
m_minimizeWindowButton = ui.minimizeWindowButton;
|
||
|
|
m_maximizeWindowButton = ui.maximizeWindowButton;
|
||
|
|
m_closeWindowButton = ui.closeWindowButton;
|
||
|
|
m_pages = ui.pages;
|
||
|
|
m_hostEdit = ui.hostEdit;
|
||
|
|
m_portSpin = ui.portSpin;
|
||
|
|
m_demoCheck = ui.demoCheck;
|
||
|
|
m_connectButton = ui.connectButton;
|
||
|
|
m_pageTitle = ui.pageTitle;
|
||
|
|
m_pageSubtitle = ui.pageSubtitle;
|
||
|
|
m_headerLayout = ui.headerLayout;
|
||
|
|
m_latencyLabel = ui.latencyLabel;
|
||
|
|
m_connectionDot = ui.connectionDot;
|
||
|
|
m_connectionText = ui.connectionText;
|
||
|
|
m_bottomLogLevel = ui.bottomLogLevel;
|
||
|
|
m_bottomLogMessage = ui.bottomLogMessage;
|
||
|
|
m_bottomVersion = ui.bottomVersion;
|
||
|
|
m_titleBarBuild->setText(QStringLiteral("Qt %1 · %2")
|
||
|
|
.arg(QString::fromLatin1(qVersion()),
|
||
|
|
#ifdef QT_NO_DEBUG
|
||
|
|
QStringLiteral("Release")));
|
||
|
|
#else
|
||
|
|
QStringLiteral("Debug")));
|
||
|
|
#endif
|
||
|
|
m_minimizeWindowButton->setIcon(UiIcons::icon(
|
||
|
|
QStringLiteral(":/icons/minus.svg"), QColor(QStringLiteral("#4f5964")),
|
||
|
|
QColor(QStringLiteral("#202832"))));
|
||
|
|
m_maximizeWindowButton->setIcon(UiIcons::icon(
|
||
|
|
QStringLiteral(":/icons/square.svg"), QColor(QStringLiteral("#4f5964")),
|
||
|
|
QColor(QStringLiteral("#202832"))));
|
||
|
|
m_closeWindowButton->setIcon(UiIcons::icon(
|
||
|
|
QStringLiteral(":/icons/x.svg"), QColor(QStringLiteral("#4f5964")),
|
||
|
|
QColor(QStringLiteral("#ffffff"))));
|
||
|
|
connect(m_minimizeWindowButton, &QPushButton::clicked,
|
||
|
|
this, &QWidget::showMinimized);
|
||
|
|
connect(m_maximizeWindowButton, &QPushButton::clicked, this, [this]() {
|
||
|
|
isMaximized() ? showNormal() : showMaximized();
|
||
|
|
});
|
||
|
|
connect(m_closeWindowButton, &QPushButton::clicked, this, &QWidget::close);
|
||
|
|
m_latencyLabel->setObjectName(QStringLiteral("statusChip"));
|
||
|
|
ui.workspaceLabel->setContentsMargins(18, 0, 0, 8);
|
||
|
|
ui.connectionTitle->hide();
|
||
|
|
m_bottomVersion->setText(QStringLiteral("CMVR %1").arg(
|
||
|
|
QCoreApplication::applicationVersion()));
|
||
|
|
|
||
|
|
QWidget *sidebarState = new QWidget(ui.connectionPanel);
|
||
|
|
sidebarState->setObjectName(QStringLiteral("sidebarConnectionState"));
|
||
|
|
QHBoxLayout *sidebarStateLayout = new QHBoxLayout(sidebarState);
|
||
|
|
sidebarStateLayout->setContentsMargins(0, 0, 0, 0);
|
||
|
|
sidebarStateLayout->setSpacing(6);
|
||
|
|
m_connectionDot->setParent(sidebarState);
|
||
|
|
m_connectionText->setParent(sidebarState);
|
||
|
|
m_latencyLabel->setParent(sidebarState);
|
||
|
|
sidebarStateLayout->addWidget(m_connectionDot);
|
||
|
|
sidebarStateLayout->addWidget(m_connectionText);
|
||
|
|
sidebarStateLayout->addStretch(1);
|
||
|
|
sidebarStateLayout->addWidget(m_latencyLabel);
|
||
|
|
ui.connectionLayout->insertWidget(0, sidebarState);
|
||
|
|
m_sidebarEndpointValue = new QLabel(QStringLiteral("--"), ui.connectionPanel);
|
||
|
|
m_sidebarEndpointValue->setObjectName(QStringLiteral("sidebarEndpoint"));
|
||
|
|
m_sidebarQuicValue = new QLabel(QStringLiteral("QUIC 未启动"), ui.connectionPanel);
|
||
|
|
m_sidebarQuicValue->setObjectName(QStringLiteral("sidebarDetail"));
|
||
|
|
m_sidebarQuicValue->setWordWrap(true);
|
||
|
|
ui.connectionLayout->insertWidget(1, m_sidebarEndpointValue);
|
||
|
|
ui.connectionLayout->insertWidget(2, m_sidebarQuicValue);
|
||
|
|
|
||
|
|
m_navGroup = new QButtonGroup(this);
|
||
|
|
m_navGroup->setExclusive(true);
|
||
|
|
m_navButtons = {
|
||
|
|
ui.systemNavButton, ui.armNavButton, ui.cameraNavButton,
|
||
|
|
ui.agvNavButton, ui.speakerNavButton, ui.microphoneNavButton,
|
||
|
|
ui.dexhandNavButton, ui.bioheadNavButton, ui.hlcNavButton,
|
||
|
|
ui.testNavButton, ui.quicNavButton, ui.configurationNavButton,
|
||
|
|
ui.diagnosticsNavButton
|
||
|
|
};
|
||
|
|
const QStringList icons = {
|
||
|
|
QStringLiteral(":/icons/activity.svg"),
|
||
|
|
QStringLiteral(":/icons/bot.svg"),
|
||
|
|
QStringLiteral(":/icons/camera.svg"),
|
||
|
|
QStringLiteral(":/icons/move.svg"),
|
||
|
|
QStringLiteral(":/icons/volume-2.svg"),
|
||
|
|
QStringLiteral(":/icons/mic.svg"),
|
||
|
|
QStringLiteral(":/icons/hand.svg"),
|
||
|
|
QStringLiteral(":/icons/scan-face.svg"),
|
||
|
|
QStringLiteral(":/icons/crosshair.svg"),
|
||
|
|
QStringLiteral(":/icons/braces.svg"),
|
||
|
|
QStringLiteral(":/icons/radio-tower.svg"),
|
||
|
|
QStringLiteral(":/icons/braces.svg"),
|
||
|
|
QStringLiteral(":/icons/scroll-text.svg")
|
||
|
|
};
|
||
|
|
for (int i = 0; i < m_navButtons.size(); ++i) {
|
||
|
|
m_navButtons.at(i)->setIcon(UiIcons::icon(
|
||
|
|
icons.at(i), QColor(QStringLiteral("#b8c2cc")),
|
||
|
|
QColor(QStringLiteral("#ffffff")),
|
||
|
|
QColor(QStringLiteral("#66727d"))));
|
||
|
|
m_navGroup->addButton(m_navButtons.at(i), i);
|
||
|
|
}
|
||
|
|
connect(m_navGroup, QOverload<int>::of(&QButtonGroup::buttonClicked),
|
||
|
|
this, &MainWindow::selectPage);
|
||
|
|
connect(m_connectButton, &QPushButton::clicked, this, &MainWindow::toggleConnection);
|
||
|
|
|
||
|
|
m_pages->addWidget(createSystemPage());
|
||
|
|
m_pages->addWidget(createArmPage());
|
||
|
|
m_pages->addWidget(createCameraPage());
|
||
|
|
m_pages->addWidget(createAgvPage());
|
||
|
|
m_pages->addWidget(createAudioPage(true));
|
||
|
|
m_pages->addWidget(createAudioPage(false));
|
||
|
|
m_pages->addWidget(createRpcPage(QStringLiteral("cmvr.api.DexHandService")));
|
||
|
|
m_pages->addWidget(createRpcPage(QStringLiteral("cmvr.api.BioHeadService")));
|
||
|
|
m_pages->addWidget(createRpcPage(QStringLiteral("cmvr.api.HlcService")));
|
||
|
|
m_pages->addWidget(createRpcPage(QStringLiteral("cmvr.api.TestService")));
|
||
|
|
m_pages->addWidget(createQuicPage());
|
||
|
|
m_pages->addWidget(new ConfigEditorWidget(m_client, m_pages));
|
||
|
|
m_pages->addWidget(createDiagnosticsPage());
|
||
|
|
|
||
|
|
const QString comboPopupStyle = QStringLiteral(
|
||
|
|
"QListView {"
|
||
|
|
" background: #ffffff; color: #33404c;"
|
||
|
|
" border: 1px solid #cfd4da; border-radius: 4px;"
|
||
|
|
" padding: 4px; outline: 0;"
|
||
|
|
"}"
|
||
|
|
"QListView::item {"
|
||
|
|
" min-height: 32px; padding: 0 10px;"
|
||
|
|
" border: none; border-radius: 3px;"
|
||
|
|
"}"
|
||
|
|
"QListView::item:hover {"
|
||
|
|
" color: #27313b; background: #f3f7fb;"
|
||
|
|
"}"
|
||
|
|
"QListView::item:selected {"
|
||
|
|
" color: #145da8; background: #e8f2ff; font-weight: 600;"
|
||
|
|
"}"
|
||
|
|
);
|
||
|
|
const QList<QComboBox *> comboBoxes = findChildren<QComboBox *>();
|
||
|
|
for (QComboBox *comboBox : comboBoxes) {
|
||
|
|
QListView *popupView = new QListView(comboBox);
|
||
|
|
popupView->setObjectName(QStringLiteral("comboPopupView"));
|
||
|
|
popupView->setSpacing(1);
|
||
|
|
popupView->setUniformItemSizes(true);
|
||
|
|
popupView->setStyleSheet(comboPopupStyle);
|
||
|
|
comboBox->setView(popupView);
|
||
|
|
}
|
||
|
|
|
||
|
|
connect(m_client, &RobotClient::connectionChanged, this, &MainWindow::updateConnection);
|
||
|
|
connect(m_client, &RobotClient::telemetryReceived, this, &MainWindow::updateTelemetry);
|
||
|
|
connect(m_client, &RobotClient::systemStatusReceived, this, &MainWindow::updateSystemStatus);
|
||
|
|
connect(m_client, &RobotClient::systemInfoReceived, this, &MainWindow::updateSystemInfo);
|
||
|
|
connect(m_client, &RobotClient::imageReceived, this, &MainWindow::updateImage);
|
||
|
|
connect(m_client, &RobotClient::videoFrameReceived, this, &MainWindow::updateVideoFrame);
|
||
|
|
connect(m_client, &RobotClient::cameraStreamStateChanged,
|
||
|
|
this, &MainWindow::updateCameraStreamState);
|
||
|
|
connect(m_client, &RobotClient::cameraRecordingStateChanged,
|
||
|
|
this, &MainWindow::updateCameraRecordingState);
|
||
|
|
connect(m_client, &RobotClient::agvStateReceived, this, &MainWindow::updateAgvState);
|
||
|
|
connect(m_client, &RobotClient::agvInventoryReceived, this, &MainWindow::updateAgvInventory);
|
||
|
|
connect(m_client, &RobotClient::agvMapFrameReceived, this,
|
||
|
|
[this](const QImage &image, const QString &detail) {
|
||
|
|
m_agvMappingPreview->setText(QString());
|
||
|
|
m_agvMappingPreview->setPixmap(QPixmap::fromImage(image).scaled(
|
||
|
|
m_agvMappingPreview->size(), Qt::KeepAspectRatio,
|
||
|
|
Qt::SmoothTransformation));
|
||
|
|
m_agvMappingStateLabel->setText(detail);
|
||
|
|
});
|
||
|
|
connect(m_client, &RobotClient::agvMapStreamStateChanged, this,
|
||
|
|
[this](bool running, const QString &detail) {
|
||
|
|
m_agvMappingStateLabel->setProperty("running", running);
|
||
|
|
m_agvMappingStateLabel->setText(detail);
|
||
|
|
m_agvMappingStateLabel->style()->unpolish(m_agvMappingStateLabel);
|
||
|
|
m_agvMappingStateLabel->style()->polish(m_agvMappingStateLabel);
|
||
|
|
});
|
||
|
|
connect(m_client, &RobotClient::commandFinished, this, &MainWindow::handleCommand);
|
||
|
|
connect(m_client, &RobotClient::logMessage, this, &MainWindow::appendLog);
|
||
|
|
connect(m_audioManager, &AudioStreamManager::speakerFrameReady,
|
||
|
|
m_client, &RobotClient::sendSpeakerAudioFrame);
|
||
|
|
connect(m_client, &RobotClient::audioFrameReceived,
|
||
|
|
m_audioManager, &AudioStreamManager::playPcmFrame);
|
||
|
|
connect(m_audioManager, &AudioStreamManager::logMessage,
|
||
|
|
this, &MainWindow::appendLog);
|
||
|
|
connect(m_quicServer, &QuicTestServer::runningChanged,
|
||
|
|
this, &MainWindow::updateQuicRunning);
|
||
|
|
connect(m_quicServer, &QuicTestServer::clientCountChanged, this, [this](int count) {
|
||
|
|
m_quicClientValue->setText(QString::number(count));
|
||
|
|
});
|
||
|
|
connect(m_quicServer, &QuicTestServer::statisticsChanged, this,
|
||
|
|
[this](quint64 registrations, quint64 heartbeats,
|
||
|
|
quint64 datagrams, quint64 datagramBytes) {
|
||
|
|
m_quicRegistrationValue->setText(QString::number(registrations));
|
||
|
|
m_quicHeartbeatValue->setText(QString::number(heartbeats));
|
||
|
|
m_quicDatagramValue->setText(QString::number(datagrams));
|
||
|
|
m_quicDatagramBytesValue->setText(QString::number(datagramBytes));
|
||
|
|
});
|
||
|
|
connect(m_quicServer, &QuicTestServer::nodeRegistered, this,
|
||
|
|
[this](const QString &nodeId, const QString &bootId,
|
||
|
|
const QString &grpcEndpoint, const QString &peerAddress) {
|
||
|
|
m_quicNodeValue->setText(nodeId);
|
||
|
|
m_quicBootValue->setText(bootId);
|
||
|
|
m_quicGrpcValue->setText(grpcEndpoint);
|
||
|
|
m_quicPeerValue->setText(peerAddress);
|
||
|
|
});
|
||
|
|
connect(m_quicServer, &QuicTestServer::logMessage,
|
||
|
|
this, &MainWindow::appendQuicLog);
|
||
|
|
|
||
|
|
loadSettings();
|
||
|
|
const QStringList startupArguments = QCoreApplication::arguments();
|
||
|
|
const int cameraCodecArgument = startupArguments.indexOf(
|
||
|
|
QStringLiteral("--camera-codec"));
|
||
|
|
if (cameraCodecArgument >= 0 && cameraCodecArgument + 1 < startupArguments.size()) {
|
||
|
|
const QString codec = startupArguments.at(cameraCodecArgument + 1).trimmed().toLower();
|
||
|
|
m_cameraCodecCombo->setCurrentIndex(
|
||
|
|
codec == QStringLiteral("h265") || codec == QStringLiteral("hevc") ? 1 : 0);
|
||
|
|
}
|
||
|
|
int initialPage = 0;
|
||
|
|
const QStringList arguments = startupArguments;
|
||
|
|
const int pageArgument = arguments.indexOf(QStringLiteral("--page-index"));
|
||
|
|
if (pageArgument >= 0 && pageArgument + 1 < arguments.size()) {
|
||
|
|
bool validPage = false;
|
||
|
|
const int requestedPage = arguments.at(pageArgument + 1).toInt(&validPage);
|
||
|
|
if (validPage && requestedPage >= 0 && requestedPage < m_pages->count())
|
||
|
|
initialPage = requestedPage;
|
||
|
|
}
|
||
|
|
selectPage(initialPage);
|
||
|
|
setControlsEnabled(false);
|
||
|
|
appendLog(QStringLiteral("INFO"), QStringLiteral("CMVR 控制台已启动"));
|
||
|
|
appendLog(QStringLiteral("INFO"), m_client->grpcAvailable()
|
||
|
|
? QStringLiteral("原生 gRPC 后端可用")
|
||
|
|
: QStringLiteral("当前为界面构建,真实 gRPC 后端未编译"));
|
||
|
|
|
||
|
|
QTimer::singleShot(250, this, [this]() {
|
||
|
|
if (m_demoCheck->isChecked())
|
||
|
|
toggleConnection();
|
||
|
|
});
|
||
|
|
QTimer::singleShot(0, this, &MainWindow::updateWindowChrome);
|
||
|
|
}
|
||
|
|
|
||
|
|
MainWindow::~MainWindow()
|
||
|
|
{
|
||
|
|
m_audioManager->stopSource();
|
||
|
|
m_audioManager->stopPlayback();
|
||
|
|
m_client->stopSpeakerAudioStream();
|
||
|
|
m_client->stopMicrophoneAudioStream();
|
||
|
|
m_quicServer->stopServer();
|
||
|
|
saveSettings();
|
||
|
|
}
|
||
|
|
|
||
|
|
bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
|
||
|
|
{
|
||
|
|
#ifdef Q_OS_WIN
|
||
|
|
Q_UNUSED(eventType)
|
||
|
|
MSG *nativeMessage = static_cast<MSG *>(message);
|
||
|
|
if (nativeMessage && nativeMessage->message == WM_GETMINMAXINFO && result) {
|
||
|
|
MINMAXINFO *minMaxInfo = reinterpret_cast<MINMAXINFO *>(nativeMessage->lParam);
|
||
|
|
MONITORINFO monitorInfo = {};
|
||
|
|
monitorInfo.cbSize = sizeof(MONITORINFO);
|
||
|
|
const HMONITOR monitor = MonitorFromWindow(nativeMessage->hwnd,
|
||
|
|
MONITOR_DEFAULTTONEAREST);
|
||
|
|
if (minMaxInfo && GetMonitorInfoW(monitor, &monitorInfo)) {
|
||
|
|
const RECT &workArea = monitorInfo.rcWork;
|
||
|
|
const RECT &monitorArea = monitorInfo.rcMonitor;
|
||
|
|
minMaxInfo->ptMaxPosition.x = workArea.left - monitorArea.left;
|
||
|
|
minMaxInfo->ptMaxPosition.y = workArea.top - monitorArea.top;
|
||
|
|
minMaxInfo->ptMaxSize.x = workArea.right - workArea.left;
|
||
|
|
minMaxInfo->ptMaxSize.y = workArea.bottom - workArea.top;
|
||
|
|
minMaxInfo->ptMaxTrackSize = minMaxInfo->ptMaxSize;
|
||
|
|
*result = 0;
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (nativeMessage && nativeMessage->message == WM_NCHITTEST && result) {
|
||
|
|
const QPoint localPosition = mapFromGlobal(QCursor::pos());
|
||
|
|
const int resizeBorder = 7;
|
||
|
|
if (!isMaximized()) {
|
||
|
|
const bool left = localPosition.x() >= 0
|
||
|
|
&& localPosition.x() < resizeBorder;
|
||
|
|
const bool right = localPosition.x() < width()
|
||
|
|
&& localPosition.x() >= width() - resizeBorder;
|
||
|
|
const bool top = localPosition.y() >= 0
|
||
|
|
&& localPosition.y() < resizeBorder;
|
||
|
|
const bool bottom = localPosition.y() < height()
|
||
|
|
&& localPosition.y() >= height() - resizeBorder;
|
||
|
|
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; }
|
||
|
|
}
|
||
|
|
|
||
|
|
if (m_customTitleBar) {
|
||
|
|
const QPoint titlePosition = m_customTitleBar->mapFrom(this, localPosition);
|
||
|
|
if (m_customTitleBar->rect().contains(titlePosition)) {
|
||
|
|
QWidget *target = childAt(localPosition);
|
||
|
|
while (target && target != m_customTitleBar) {
|
||
|
|
if (qobject_cast<QPushButton *>(target)) {
|
||
|
|
*result = HTCLIENT;
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
target = target->parentWidget();
|
||
|
|
}
|
||
|
|
*result = HTCAPTION;
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
#else
|
||
|
|
Q_UNUSED(eventType)
|
||
|
|
Q_UNUSED(message)
|
||
|
|
Q_UNUSED(result)
|
||
|
|
#endif
|
||
|
|
return QMainWindow::nativeEvent(eventType, message, result);
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::changeEvent(QEvent *event)
|
||
|
|
{
|
||
|
|
QMainWindow::changeEvent(event);
|
||
|
|
if (event && event->type() == QEvent::WindowStateChange)
|
||
|
|
updateWindowChrome();
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::resizeEvent(QResizeEvent *event)
|
||
|
|
{
|
||
|
|
QMainWindow::resizeEvent(event);
|
||
|
|
updateWindowChrome();
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::updateWindowChrome()
|
||
|
|
{
|
||
|
|
if (!m_windowSurface || !m_maximizeWindowButton || m_updatingWindowChrome)
|
||
|
|
return;
|
||
|
|
|
||
|
|
const bool maximized = isMaximized();
|
||
|
|
const bool stateChanged = !m_windowChromeInitialized
|
||
|
|
|| m_windowChromeMaximized != maximized;
|
||
|
|
const bool sizeChanged = !m_windowChromeInitialized
|
||
|
|
|| m_windowChromeSize != size();
|
||
|
|
if (!stateChanged && !sizeChanged)
|
||
|
|
return;
|
||
|
|
|
||
|
|
m_updatingWindowChrome = true;
|
||
|
|
if (stateChanged) {
|
||
|
|
m_windowSurface->setProperty("maximized", maximized);
|
||
|
|
m_windowSurface->style()->unpolish(m_windowSurface);
|
||
|
|
m_windowSurface->style()->polish(m_windowSurface);
|
||
|
|
m_windowSurface->update();
|
||
|
|
}
|
||
|
|
|
||
|
|
if (stateChanged) {
|
||
|
|
m_maximizeWindowButton->setIcon(UiIcons::icon(
|
||
|
|
maximized ? QStringLiteral(":/icons/copy.svg")
|
||
|
|
: QStringLiteral(":/icons/square.svg"),
|
||
|
|
QColor(QStringLiteral("#4f5964")), QColor(QStringLiteral("#202832"))));
|
||
|
|
m_maximizeWindowButton->setToolTip(
|
||
|
|
maximized ? QStringLiteral("还原") : QStringLiteral("最大化"));
|
||
|
|
}
|
||
|
|
m_windowChromeSize = size();
|
||
|
|
m_windowChromeMaximized = maximized;
|
||
|
|
m_windowChromeInitialized = true;
|
||
|
|
m_updatingWindowChrome = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
void MainWindow::toggleQuicServer()
|
||
|
|
{
|
||
|
|
if (m_quicServer->isRunning()) {
|
||
|
|
m_quicToggleButton->setEnabled(false);
|
||
|
|
m_quicStateValue->setText(QStringLiteral("正在停止..."));
|
||
|
|
m_quicServer->stopServer();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
saveSettings();
|
||
|
|
m_quicToggleButton->setEnabled(false);
|
||
|
|
m_quicStateValue->setText(QStringLiteral("正在启动..."));
|
||
|
|
m_quicServer->startServer(m_quicBindEdit->text().trimmed(),
|
||
|
|
static_cast<quint16>(m_quicPortSpin->value()),
|
||
|
|
m_quicAlpnEdit->text().trimmed(),
|
||
|
|
m_quicCertificateEdit->text().trimmed(),
|
||
|
|
m_quicPasswordEdit->text());
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::updateQuicRunning(bool running, quint16 port, const QString &detail)
|
||
|
|
{
|
||
|
|
m_quicToggleButton->setEnabled(true);
|
||
|
|
m_quicToggleButton->setText(running ? QStringLiteral("停止 QUIC Server")
|
||
|
|
: QStringLiteral("启动 QUIC Server"));
|
||
|
|
m_quicToggleButton->setObjectName(running ? QStringLiteral("dangerButton")
|
||
|
|
: QStringLiteral("primaryButton"));
|
||
|
|
m_quicToggleButton->style()->unpolish(m_quicToggleButton);
|
||
|
|
m_quicToggleButton->style()->polish(m_quicToggleButton);
|
||
|
|
m_quicStateValue->setText(running ? QStringLiteral("运行中") : detail);
|
||
|
|
m_quicBoundValue->setText(running
|
||
|
|
? QStringLiteral("%1:%2").arg(m_quicBindEdit->text().trimmed()).arg(port)
|
||
|
|
: QStringLiteral("--"));
|
||
|
|
if (m_sidebarQuicValue) {
|
||
|
|
m_sidebarQuicValue->setText(running
|
||
|
|
? QStringLiteral("QUIC %1:%2").arg(m_quicBindEdit->text().trimmed()).arg(port)
|
||
|
|
: QStringLiteral("QUIC 未启动"));
|
||
|
|
m_sidebarQuicValue->setToolTip(detail);
|
||
|
|
}
|
||
|
|
m_quicBindEdit->setEnabled(!running);
|
||
|
|
m_quicPortSpin->setEnabled(!running);
|
||
|
|
m_quicAlpnEdit->setEnabled(!running);
|
||
|
|
m_quicCertificateEdit->setEnabled(!running);
|
||
|
|
m_quicPasswordEdit->setEnabled(!running);
|
||
|
|
appendQuicLog(running ? QStringLiteral("OK") : QStringLiteral("INFO"), detail);
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::appendQuicLog(const QString &level, const QString &message)
|
||
|
|
{
|
||
|
|
if (!m_quicLogView)
|
||
|
|
return;
|
||
|
|
QString color = QStringLiteral("#aeb6c0");
|
||
|
|
if (level == QStringLiteral("ERROR"))
|
||
|
|
color = QStringLiteral("#ff7b72");
|
||
|
|
else if (level == QStringLiteral("WARN"))
|
||
|
|
color = QStringLiteral("#e3b341");
|
||
|
|
else if (level == QStringLiteral("OK"))
|
||
|
|
color = QStringLiteral("#56d39b");
|
||
|
|
const QString timestamp = QDateTime::currentDateTime().toString("HH:mm:ss.zzz");
|
||
|
|
m_quicLogView->append(QStringLiteral("<span style='color:#747d87'>%1</span> "
|
||
|
|
"<span style='color:%2;font-weight:600'>[%3]</span> %4")
|
||
|
|
.arg(timestamp, color, level, message.toHtmlEscaped()));
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::selectPage(int index)
|
||
|
|
{
|
||
|
|
if (!m_pages || index < 0 || index >= kPageTitles.size())
|
||
|
|
return;
|
||
|
|
m_pages->setCurrentIndex(index);
|
||
|
|
m_pageTitle->setText(kPageTitles.at(index));
|
||
|
|
m_pageSubtitle->setText(kPageSubtitles.at(index));
|
||
|
|
if (m_titleBarPage && index < m_navButtons.size())
|
||
|
|
m_titleBarPage->setText(m_navButtons.at(index)->text());
|
||
|
|
if (m_armHeaderControls)
|
||
|
|
m_armHeaderControls->setVisible(index == 1);
|
||
|
|
if (index == 1)
|
||
|
|
ensureArmModelLoaded();
|
||
|
|
if (index != 3 && m_agvStatusSwitch && m_agvStatusSwitch->isChecked())
|
||
|
|
m_agvStatusSwitch->setChecked(false);
|
||
|
|
if (index < m_navButtons.size())
|
||
|
|
m_navButtons.at(index)->setChecked(true);
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::ensureArmModelLoaded()
|
||
|
|
{
|
||
|
|
if (!m_urdfViewer || m_pendingUrdfPath.isEmpty()
|
||
|
|
|| !m_urdfViewer->currentFile().isEmpty() || m_armModelLoadScheduled) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
m_armModelLoadScheduled = true;
|
||
|
|
m_urdfViewer->prepareLoad(m_pendingUrdfPath);
|
||
|
|
QTimer::singleShot(450, this, [this]() {
|
||
|
|
if (!m_pages || m_pages->currentIndex() != 1) {
|
||
|
|
m_armModelLoadScheduled = false;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
const QString path = m_pendingUrdfPath;
|
||
|
|
if (m_urdfViewer && m_urdfViewer->currentFile().isEmpty())
|
||
|
|
m_urdfViewer->loadUrdf(path);
|
||
|
|
m_armModelLoadScheduled = false;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::toggleConnection()
|
||
|
|
{
|
||
|
|
if (m_connected) {
|
||
|
|
m_connectButton->setEnabled(false);
|
||
|
|
m_connectButton->setText(QStringLiteral("正在断开…"));
|
||
|
|
m_client->disconnectFromServer();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (m_hostEdit->text().trimmed().isEmpty()) {
|
||
|
|
QMessageBox::warning(this, QStringLiteral("连接参数"), QStringLiteral("请填写主机地址。"));
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
saveSettings();
|
||
|
|
m_connectButton->setEnabled(false);
|
||
|
|
m_connectButton->setText(QStringLiteral("正在连接…"));
|
||
|
|
m_connectionText->setText(QStringLiteral("连接中"));
|
||
|
|
m_connectionDot->setStyleSheet(QStringLiteral("color:#df8b24; font-size:12px;"));
|
||
|
|
m_endpointValue->setText(endpoint());
|
||
|
|
appendLog(QStringLiteral("INFO"), QStringLiteral("正在连接 %1").arg(endpoint()));
|
||
|
|
m_client->connectToServer(m_hostEdit->text(), m_portSpin->value(), m_demoCheck->isChecked());
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::updateConnection(bool connected, int latencyMs, const QString &detail)
|
||
|
|
{
|
||
|
|
m_connected = connected;
|
||
|
|
m_connectButton->setEnabled(true);
|
||
|
|
m_connectButton->setText(connected ? QStringLiteral("断开连接") : QStringLiteral("连接"));
|
||
|
|
m_connectionText->setText(connected ? QStringLiteral("gRPC 已连接")
|
||
|
|
: QStringLiteral("gRPC 未连接"));
|
||
|
|
m_connectionDot->setStyleSheet(QStringLiteral("color:%1; font-size:12px;")
|
||
|
|
.arg(connected ? QStringLiteral("#25a878") : QStringLiteral("#9aa1aa")));
|
||
|
|
m_latencyLabel->setText(connected ? QStringLiteral("%1 ms").arg(latencyMs) : QStringLiteral("-- ms"));
|
||
|
|
if (m_sidebarEndpointValue)
|
||
|
|
m_sidebarEndpointValue->setText(endpoint());
|
||
|
|
m_hostEdit->setEnabled(!connected);
|
||
|
|
m_portSpin->setEnabled(!connected);
|
||
|
|
m_demoCheck->setEnabled(!connected);
|
||
|
|
m_hostEdit->setVisible(!connected);
|
||
|
|
m_portSpin->setVisible(!connected);
|
||
|
|
m_demoCheck->setVisible(!connected);
|
||
|
|
setControlsEnabled(connected);
|
||
|
|
if (m_agvStatusRefreshTimer && m_agvStatusSwitch
|
||
|
|
&& m_agvStatusSwitch->isChecked()) {
|
||
|
|
if (connected) {
|
||
|
|
m_client->requestAgvRefresh(m_agvIdEdit->text().trimmed());
|
||
|
|
m_agvStatusRefreshTimer->start();
|
||
|
|
} else {
|
||
|
|
m_agvStatusRefreshTimer->stop();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (!connected) {
|
||
|
|
m_audioManager->stopSource();
|
||
|
|
m_audioManager->stopPlayback();
|
||
|
|
m_runningCameraIds.clear();
|
||
|
|
for (auto it = m_cameraPreviewTiles.begin();
|
||
|
|
it != m_cameraPreviewTiles.end(); ++it) {
|
||
|
|
it->status->setText(QStringLiteral("已断开"));
|
||
|
|
}
|
||
|
|
refreshCameraStreamControls();
|
||
|
|
}
|
||
|
|
if (!connected && m_armTelemetryButton) {
|
||
|
|
m_armTelemetryButton->setChecked(false);
|
||
|
|
m_armTelemetryButton->setText(QStringLiteral("遥测 未启动"));
|
||
|
|
m_armTelemetryButton->setProperty("active", false);
|
||
|
|
m_armTelemetryButton->style()->unpolish(m_armTelemetryButton);
|
||
|
|
m_armTelemetryButton->style()->polish(m_armTelemetryButton);
|
||
|
|
m_armIdEdit->setEnabled(true);
|
||
|
|
}
|
||
|
|
if (!connected) {
|
||
|
|
const QList<QLabel *> armStates = {m_servoStatusValue, m_faultStatusValue};
|
||
|
|
for (QLabel *label : armStates) {
|
||
|
|
if (!label)
|
||
|
|
continue;
|
||
|
|
label->setText(QStringLiteral("未知"));
|
||
|
|
label->setProperty("state", QStringLiteral("unknown"));
|
||
|
|
label->style()->unpolish(label);
|
||
|
|
label->style()->polish(label);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (connected)
|
||
|
|
m_client->requestSystemRefresh();
|
||
|
|
appendLog(connected ? QStringLiteral("INFO") : QStringLiteral("WARN"), detail);
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::updateTelemetry(const QVariantList &joints, const QVariantMap &pose)
|
||
|
|
{
|
||
|
|
QHash<QString, QVariantMap> byName;
|
||
|
|
QHash<QString, double> jointPositions;
|
||
|
|
for (const QVariant &value : joints) {
|
||
|
|
const QVariantMap joint = value.toMap();
|
||
|
|
const QString name = joint.value(QStringLiteral("name")).toString();
|
||
|
|
byName.insert(name, joint);
|
||
|
|
jointPositions.insert(name, joint.value(QStringLiteral("position")).toDouble());
|
||
|
|
}
|
||
|
|
|
||
|
|
if (m_urdfViewer)
|
||
|
|
m_urdfViewer->setJointPositions(jointPositions);
|
||
|
|
|
||
|
|
for (int row = 0; m_jointTable && row < m_jointTable->rowCount(); ++row) {
|
||
|
|
const QTableWidgetItem *nameItem = m_jointTable->item(row, 0);
|
||
|
|
if (!nameItem)
|
||
|
|
continue;
|
||
|
|
const QVariantMap joint = byName.value(nameItem->text());
|
||
|
|
if (joint.isEmpty())
|
||
|
|
continue;
|
||
|
|
const double position = joint.value(QStringLiteral("position")).toDouble();
|
||
|
|
const double velocity = joint.value(QStringLiteral("velocity")).toDouble();
|
||
|
|
const double effort = joint.value(QStringLiteral("effort")).toDouble();
|
||
|
|
m_jointTable->item(row, 1)->setText(QString::number(position, 'f', 5));
|
||
|
|
m_jointTable->item(row, 2)->setText(QString::number(velocity, 'f', 5));
|
||
|
|
m_jointTable->item(row, 3)->setText(QString::number(effort, 'f', 3));
|
||
|
|
if (row == 0 && m_trend)
|
||
|
|
m_trend->appendSample(position, velocity);
|
||
|
|
}
|
||
|
|
|
||
|
|
const QList<QTableWidget *> motionTables = {m_leftMotionTable, m_motionTable};
|
||
|
|
for (QTableWidget *table : motionTables) {
|
||
|
|
if (!table)
|
||
|
|
continue;
|
||
|
|
for (int row = 0; row < table->rowCount(); ++row) {
|
||
|
|
const QTableWidgetItem *nameItem = table->item(row, 0);
|
||
|
|
if (!nameItem)
|
||
|
|
continue;
|
||
|
|
const QVariantMap joint = byName.value(nameItem->text());
|
||
|
|
if (!joint.isEmpty())
|
||
|
|
table->item(row, 1)->setText(QStringLiteral("%1°").arg(
|
||
|
|
qRadiansToDegrees(joint.value(QStringLiteral("position")).toDouble()),
|
||
|
|
0, 'f', 2));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!pose.isEmpty()) {
|
||
|
|
m_latestArmPose = pose;
|
||
|
|
m_poseValue->setText(QStringLiteral("X %1 m\nY %2 m\nZ %3 m\n\nRX %4 rad\nRY %5 rad\nRZ %6 rad")
|
||
|
|
.arg(pose.value(QStringLiteral("x")).toDouble(), 0, 'f', 4)
|
||
|
|
.arg(pose.value(QStringLiteral("y")).toDouble(), 0, 'f', 4)
|
||
|
|
.arg(pose.value(QStringLiteral("z")).toDouble(), 0, 'f', 4)
|
||
|
|
.arg(pose.value(QStringLiteral("rx")).toDouble(), 0, 'f', 4)
|
||
|
|
.arg(pose.value(QStringLiteral("ry")).toDouble(), 0, 'f', 4)
|
||
|
|
.arg(pose.value(QStringLiteral("rz")).toDouble(), 0, 'f', 4));
|
||
|
|
}
|
||
|
|
m_updatedValue->setText(QStringLiteral("更新于 %1").arg(QDateTime::currentDateTime().toString("HH:mm:ss.zzz")));
|
||
|
|
if (m_bottomLogLevel && m_bottomLogMessage) {
|
||
|
|
m_bottomLogLevel->setText(QStringLiteral("[OK]"));
|
||
|
|
m_bottomLogLevel->setProperty("level", QStringLiteral("ok"));
|
||
|
|
m_bottomLogLevel->style()->unpolish(m_bottomLogLevel);
|
||
|
|
m_bottomLogLevel->style()->polish(m_bottomLogLevel);
|
||
|
|
m_bottomLogMessage->setText(QStringLiteral("Arm Telemetry · 已接收 %1 个关节状态 · %2")
|
||
|
|
.arg(joints.size()).arg(QDateTime::currentDateTime().toString("HH:mm:ss.zzz")));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::updateSystemStatus(double cpu, double memory, double disk, int devices)
|
||
|
|
{
|
||
|
|
m_cpuValue->setText(QString::number(cpu, 'f', 0));
|
||
|
|
m_memoryValue->setText(QString::number(memory, 'f', 0));
|
||
|
|
m_diskValue->setText(QString::number(disk, 'f', 0));
|
||
|
|
m_deviceValue->setText(QString::number(devices));
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::updateSystemInfo(const QVariantMap &info)
|
||
|
|
{
|
||
|
|
m_systemNameValue->setText(info.value(QStringLiteral("name"), QStringLiteral("--")).toString());
|
||
|
|
m_systemVersionValue->setText(info.value(QStringLiteral("version"), QStringLiteral("--")).toString());
|
||
|
|
const QString platform = QStringLiteral("%1 · %2")
|
||
|
|
.arg(info.value(QStringLiteral("os"), QStringLiteral("--")).toString(),
|
||
|
|
info.value(QStringLiteral("architecture"), QStringLiteral("--")).toString());
|
||
|
|
m_systemOsValue->setText(platform);
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::updateAgvState(const QVariantMap &state, const QVariantMap &navigation)
|
||
|
|
{
|
||
|
|
const bool controllerConnected = state.value(QStringLiteral("connected")).toBool();
|
||
|
|
const bool localized = state.value(QStringLiteral("localized")).toBool();
|
||
|
|
const bool fault = state.value(QStringLiteral("fault")).toBool();
|
||
|
|
const bool emergency = state.value(QStringLiteral("emergency")).toBool();
|
||
|
|
m_agvConnectionValue->setText(QStringLiteral("%1 · %2%3")
|
||
|
|
.arg(controllerConnected ? QStringLiteral("在线") : QStringLiteral("离线"),
|
||
|
|
localized ? QStringLiteral("已定位") : QStringLiteral("未定位"),
|
||
|
|
(fault || emergency) ? QStringLiteral(" · 异常") : QString()));
|
||
|
|
m_agvMapValue->setText(QStringLiteral("%1 / %2")
|
||
|
|
.arg(state.value(QStringLiteral("map"), QStringLiteral("--")).toString(),
|
||
|
|
state.value(QStringLiteral("station"), QStringLiteral("--")).toString()));
|
||
|
|
m_agvPoseValue->setText(QStringLiteral("%1, %2, %3")
|
||
|
|
.arg(state.value(QStringLiteral("x")).toDouble(), 0, 'f', 2)
|
||
|
|
.arg(state.value(QStringLiteral("y")).toDouble(), 0, 'f', 2)
|
||
|
|
.arg(state.value(QStringLiteral("theta")).toDouble(), 0, 'f', 2));
|
||
|
|
m_agvMotionValue->setText(QStringLiteral("%1 / %2 / %3")
|
||
|
|
.arg(state.value(QStringLiteral("vx")).toDouble(), 0, 'f', 2)
|
||
|
|
.arg(state.value(QStringLiteral("vy")).toDouble(), 0, 'f', 2)
|
||
|
|
.arg(state.value(QStringLiteral("wz")).toDouble(), 0, 'f', 2));
|
||
|
|
m_agvBatteryValue->setText(QStringLiteral("%1%").arg(
|
||
|
|
state.value(QStringLiteral("battery")).toDouble() * 100.0, 0, 'f', 0));
|
||
|
|
m_agvNavigationValue->setText(navigation.value(QStringLiteral("message"), QStringLiteral("--")).toString());
|
||
|
|
m_agvErrorValue->setText(state.value(QStringLiteral("error"), QStringLiteral("无")).toString());
|
||
|
|
m_agvModeValue->setText(QStringLiteral("模式 %1").arg(
|
||
|
|
state.value(QStringLiteral("mode")).toInt()));
|
||
|
|
m_agvMotionStateValue->setText(QStringLiteral("%1 / %2")
|
||
|
|
.arg(localized ? QStringLiteral("已定位") : QStringLiteral("未定位"),
|
||
|
|
state.value(QStringLiteral("moving")).toBool()
|
||
|
|
? QStringLiteral("运动中") : QStringLiteral("静止")));
|
||
|
|
m_agvSafetyValue->setText(QStringLiteral("%1 / %2")
|
||
|
|
.arg(fault ? QStringLiteral("有故障") : QStringLiteral("正常"),
|
||
|
|
emergency ? QStringLiteral("已急停") : QStringLiteral("未急停")));
|
||
|
|
m_agvPowerValue->setText(QStringLiteral("%1 V / %2 A / %3 °C")
|
||
|
|
.arg(state.value(QStringLiteral("voltage")).toDouble(), 0, 'f', 2)
|
||
|
|
.arg(state.value(QStringLiteral("current")).toDouble(), 0, 'f', 2)
|
||
|
|
.arg(state.value(QStringLiteral("temperature")).toDouble(), 0, 'f', 1));
|
||
|
|
const double timestamp = state.value(QStringLiteral("timestamp")).toDouble();
|
||
|
|
m_agvTimestampValue->setText(timestamp > 0.0
|
||
|
|
? QDateTime::fromMSecsSinceEpoch(qRound64(timestamp * 1000.0))
|
||
|
|
.toString(QStringLiteral("yyyy-MM-dd HH:mm:ss.zzz"))
|
||
|
|
: QStringLiteral("--"));
|
||
|
|
m_agvProgress->setValue(qBound(0, qRound(navigation.value(QStringLiteral("progress")).toDouble() * 100.0), 100));
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::updateAgvInventory(const QStringList &maps, const QVariantList &stations)
|
||
|
|
{
|
||
|
|
const QString selectedMap = m_agvMapCombo->currentText();
|
||
|
|
m_agvMapCombo->clear();
|
||
|
|
m_agvMapCombo->addItems(maps);
|
||
|
|
const int mapIndex = m_agvMapCombo->findText(selectedMap);
|
||
|
|
if (mapIndex >= 0)
|
||
|
|
m_agvMapCombo->setCurrentIndex(mapIndex);
|
||
|
|
|
||
|
|
const QString selectedStation = m_agvStationCombo->currentText();
|
||
|
|
m_agvStationCombo->clear();
|
||
|
|
m_agvStationTable->setRowCount(stations.size());
|
||
|
|
for (int row = 0; row < stations.size(); ++row) {
|
||
|
|
const QVariantMap station = stations.at(row).toMap();
|
||
|
|
const QString stationId = station.value(QStringLiteral("id")).toString();
|
||
|
|
m_agvStationCombo->addItem(stationId);
|
||
|
|
m_agvStationTable->setItem(row, 0, new QTableWidgetItem(stationId));
|
||
|
|
m_agvStationTable->setItem(row, 1, new QTableWidgetItem(station.value(QStringLiteral("type")).toString()));
|
||
|
|
m_agvStationTable->setItem(row, 2, new QTableWidgetItem(QString::number(
|
||
|
|
station.value(QStringLiteral("x")).toDouble(), 'f', 3)));
|
||
|
|
m_agvStationTable->setItem(row, 3, new QTableWidgetItem(QString::number(
|
||
|
|
station.value(QStringLiteral("y")).toDouble(), 'f', 3)));
|
||
|
|
}
|
||
|
|
const int stationIndex = m_agvStationCombo->findText(selectedStation);
|
||
|
|
if (stationIndex >= 0)
|
||
|
|
m_agvStationCombo->setCurrentIndex(stationIndex);
|
||
|
|
|
||
|
|
QPixmap preview(960, 280);
|
||
|
|
preview.fill(QColor(QStringLiteral("#eef2f6")));
|
||
|
|
QPainter painter(&preview);
|
||
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
||
|
|
painter.setPen(QPen(QColor(QStringLiteral("#d5dee6")), 1));
|
||
|
|
for (int x = 60; x < preview.width(); x += 100)
|
||
|
|
painter.drawLine(x, 24, x, preview.height() - 24);
|
||
|
|
for (int y = 40; y < preview.height(); y += 60)
|
||
|
|
painter.drawLine(36, y, preview.width() - 36, y);
|
||
|
|
if (stations.isEmpty()) {
|
||
|
|
painter.setPen(QColor(QStringLiteral("#71808e")));
|
||
|
|
painter.drawText(preview.rect(), Qt::AlignCenter,
|
||
|
|
QStringLiteral("当前地图没有可显示的站点"));
|
||
|
|
} else {
|
||
|
|
double minX = stations.first().toMap().value(QStringLiteral("x")).toDouble();
|
||
|
|
double maxX = minX;
|
||
|
|
double minY = stations.first().toMap().value(QStringLiteral("y")).toDouble();
|
||
|
|
double maxY = minY;
|
||
|
|
for (const QVariant &entry : stations) {
|
||
|
|
const QVariantMap station = entry.toMap();
|
||
|
|
minX = qMin(minX, station.value(QStringLiteral("x")).toDouble());
|
||
|
|
maxX = qMax(maxX, station.value(QStringLiteral("x")).toDouble());
|
||
|
|
minY = qMin(minY, station.value(QStringLiteral("y")).toDouble());
|
||
|
|
maxY = qMax(maxY, station.value(QStringLiteral("y")).toDouble());
|
||
|
|
}
|
||
|
|
if (qFuzzyCompare(minX, maxX)) { minX -= 1.0; maxX += 1.0; }
|
||
|
|
if (qFuzzyCompare(minY, maxY)) { minY -= 1.0; maxY += 1.0; }
|
||
|
|
QPointF previous;
|
||
|
|
for (int i = 0; i < stations.size(); ++i) {
|
||
|
|
const QVariantMap station = stations.at(i).toMap();
|
||
|
|
const QPointF point(
|
||
|
|
60.0 + (station.value(QStringLiteral("x")).toDouble() - minX) /
|
||
|
|
(maxX - minX) * (preview.width() - 120.0),
|
||
|
|
40.0 + (maxY - station.value(QStringLiteral("y")).toDouble()) /
|
||
|
|
(maxY - minY) * (preview.height() - 80.0));
|
||
|
|
if (i > 0) {
|
||
|
|
painter.setPen(QPen(QColor(QStringLiteral("#9db7ce")), 2));
|
||
|
|
painter.drawLine(previous, point);
|
||
|
|
}
|
||
|
|
painter.setPen(Qt::NoPen);
|
||
|
|
painter.setBrush(QColor(QStringLiteral("#218c74")));
|
||
|
|
painter.drawEllipse(point, 7, 7);
|
||
|
|
painter.setPen(QColor(QStringLiteral("#26323d")));
|
||
|
|
painter.drawText(point + QPointF(10, -8),
|
||
|
|
station.value(QStringLiteral("id")).toString());
|
||
|
|
previous = point;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
painter.end();
|
||
|
|
m_agvMapOverview->setPixmap(preview.scaled(
|
||
|
|
m_agvMapOverview->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::updateImage(const QImage &image, const QString &detail)
|
||
|
|
{
|
||
|
|
m_lastImage = image;
|
||
|
|
if (m_videoRender)
|
||
|
|
m_videoRender->setImage(image);
|
||
|
|
m_imageMetaLabel->setText(detail);
|
||
|
|
m_saveImageButton->setEnabled(true);
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::updateVideoFrame(const QString &cameraId, const VideoFrame &frame,
|
||
|
|
const QString &detail)
|
||
|
|
{
|
||
|
|
const QString resolvedId = cameraId.isEmpty() && !m_cameraPreviewTiles.isEmpty()
|
||
|
|
? m_cameraPreviewTiles.constBegin().key() : cameraId;
|
||
|
|
const auto it = m_cameraPreviewTiles.find(resolvedId);
|
||
|
|
if (it == m_cameraPreviewTiles.end())
|
||
|
|
return;
|
||
|
|
it->render->setFrame(frame);
|
||
|
|
it->meta->setText(detail);
|
||
|
|
m_imageMetaLabel->setText(QStringLiteral("%1 | %2").arg(resolvedId, detail));
|
||
|
|
m_saveImageButton->setEnabled(true);
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::updateCameraStreamState(const QString &cameraId, bool running,
|
||
|
|
const QString &detail)
|
||
|
|
{
|
||
|
|
const QString resolvedId = cameraId.isEmpty() && !m_cameraPreviewTiles.isEmpty()
|
||
|
|
? m_cameraPreviewTiles.constBegin().key() : cameraId;
|
||
|
|
if (running)
|
||
|
|
m_runningCameraIds.insert(resolvedId);
|
||
|
|
else
|
||
|
|
m_runningCameraIds.remove(resolvedId);
|
||
|
|
|
||
|
|
const auto it = m_cameraPreviewTiles.find(resolvedId);
|
||
|
|
if (it != m_cameraPreviewTiles.end()) {
|
||
|
|
it->status->setText(running ? QStringLiteral("播放中")
|
||
|
|
: QStringLiteral("已停止"));
|
||
|
|
it->status->setToolTip(detail);
|
||
|
|
if (!running && !detail.isEmpty())
|
||
|
|
it->meta->setText(detail);
|
||
|
|
}
|
||
|
|
refreshCameraStreamControls();
|
||
|
|
m_cameraStreamStateLabel->setToolTip(detail);
|
||
|
|
if (!detail.isEmpty()) {
|
||
|
|
const bool failed = detail.contains(QStringLiteral("失败"));
|
||
|
|
appendLog(failed ? QStringLiteral("ERROR") : QStringLiteral("INFO"),
|
||
|
|
QStringLiteral("%1: %2").arg(resolvedId, detail));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::updateCameraRecordingState(bool recording, const QString &detail)
|
||
|
|
{
|
||
|
|
m_cameraRecording = recording;
|
||
|
|
if (!m_cameraRecordButton || !m_cameraRecordPathEdit || !m_cameraRecordStateLabel)
|
||
|
|
return;
|
||
|
|
m_cameraRecordButton->setEnabled(m_connected);
|
||
|
|
m_cameraRecordButton->setText(recording ? QStringLiteral("停止录像")
|
||
|
|
: QStringLiteral("开始录像"));
|
||
|
|
m_cameraRecordButton->setIcon(style()->standardIcon(
|
||
|
|
recording ? QStyle::SP_MediaStop : QStyle::SP_DialogSaveButton));
|
||
|
|
m_cameraRecordButton->setObjectName(recording ? QStringLiteral("dangerButton")
|
||
|
|
: QStringLiteral("primaryButton"));
|
||
|
|
m_cameraRecordButton->style()->unpolish(m_cameraRecordButton);
|
||
|
|
m_cameraRecordButton->style()->polish(m_cameraRecordButton);
|
||
|
|
m_cameraRecordPathEdit->setEnabled(!recording);
|
||
|
|
m_cameraIdEdit->setEnabled(!m_cameraStreaming && !recording);
|
||
|
|
m_cameraRecordStateLabel->setText(recording ? QStringLiteral("录像中")
|
||
|
|
: QStringLiteral("未录像"));
|
||
|
|
m_cameraRecordStateLabel->setToolTip(detail);
|
||
|
|
if (!detail.isEmpty())
|
||
|
|
appendLog(QStringLiteral("INFO"), detail);
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::handleCommand(const QString &command, bool success, const QString &detail)
|
||
|
|
{
|
||
|
|
QLabel *stateLabel = nullptr;
|
||
|
|
QString stateText;
|
||
|
|
if (command == QStringLiteral("Torque On")) {
|
||
|
|
stateLabel = m_servoStatusValue;
|
||
|
|
stateText = success ? QStringLiteral("已使能") : QStringLiteral("使能失败");
|
||
|
|
} else if (command == QStringLiteral("Torque Off")) {
|
||
|
|
stateLabel = m_servoStatusValue;
|
||
|
|
stateText = success ? QStringLiteral("已去使能") : QStringLiteral("操作失败");
|
||
|
|
} else if (command == QStringLiteral("Clear Fault")) {
|
||
|
|
stateLabel = m_faultStatusValue;
|
||
|
|
stateText = success ? QStringLiteral("正常") : QStringLiteral("清除失败");
|
||
|
|
}
|
||
|
|
if (stateLabel) {
|
||
|
|
stateLabel->setText(stateText);
|
||
|
|
stateLabel->setProperty("state", success ? QStringLiteral("good")
|
||
|
|
: QStringLiteral("error"));
|
||
|
|
stateLabel->style()->unpolish(stateLabel);
|
||
|
|
stateLabel->style()->polish(stateLabel);
|
||
|
|
}
|
||
|
|
if (!success && (command == QStringLiteral("Camera Start Recording")
|
||
|
|
|| command == QStringLiteral("Camera Stop Recording"))) {
|
||
|
|
updateCameraRecordingState(m_cameraRecording, detail);
|
||
|
|
}
|
||
|
|
if (success && m_agvStatusSwitch
|
||
|
|
&& (command == QStringLiteral("AGV NavigateToPose")
|
||
|
|
|| command == QStringLiteral("AGV NavigateToStation")
|
||
|
|
|| command == QStringLiteral("AGV FollowPath"))) {
|
||
|
|
m_agvStatusSwitch->setChecked(true);
|
||
|
|
}
|
||
|
|
appendLog(success ? QStringLiteral("OK") : QStringLiteral("ERROR"),
|
||
|
|
QStringLiteral("%1 · %2").arg(command, detail));
|
||
|
|
if (!success)
|
||
|
|
m_connectionText->setToolTip(detail);
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::appendLog(const QString &level, const QString &message)
|
||
|
|
{
|
||
|
|
if (m_bottomLogLevel && m_bottomLogMessage) {
|
||
|
|
const QString normalizedLevel = level.toLower();
|
||
|
|
m_bottomLogLevel->setText(QStringLiteral("[%1]").arg(level));
|
||
|
|
m_bottomLogLevel->setProperty("level", normalizedLevel);
|
||
|
|
m_bottomLogLevel->style()->unpolish(m_bottomLogLevel);
|
||
|
|
m_bottomLogLevel->style()->polish(m_bottomLogLevel);
|
||
|
|
m_bottomLogMessage->setText(QStringLiteral("%1 · %2")
|
||
|
|
.arg(message, QDateTime::currentDateTime().toString("HH:mm:ss.zzz")));
|
||
|
|
m_bottomLogMessage->setToolTip(message);
|
||
|
|
}
|
||
|
|
if (!m_logView)
|
||
|
|
return;
|
||
|
|
QString color = QStringLiteral("#aeb6c0");
|
||
|
|
if (level == QStringLiteral("ERROR"))
|
||
|
|
color = QStringLiteral("#ff7b72");
|
||
|
|
else if (level == QStringLiteral("WARN"))
|
||
|
|
color = QStringLiteral("#e3b341");
|
||
|
|
else if (level == QStringLiteral("OK"))
|
||
|
|
color = QStringLiteral("#56d39b");
|
||
|
|
const QString timestamp = QDateTime::currentDateTime().toString("HH:mm:ss.zzz");
|
||
|
|
m_logView->append(QStringLiteral("<span style='color:#747d87'>%1</span> "
|
||
|
|
"<span style='color:%2;font-weight:600'>[%3]</span> %4")
|
||
|
|
.arg(timestamp, color, level, message.toHtmlEscaped()));
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::sendMoveJ()
|
||
|
|
{
|
||
|
|
QVariantList positions;
|
||
|
|
const bool leftArm = m_armSideCombo
|
||
|
|
&& m_armSideCombo->currentData().toString() == QStringLiteral("left");
|
||
|
|
const int offset = leftArm ? 0 : 7;
|
||
|
|
for (int i = 0; i < 7 && offset + i < m_targetSpins.size(); ++i)
|
||
|
|
positions.append(qDegreesToRadians(m_targetSpins.at(offset + i)->value()));
|
||
|
|
m_client->requestMoveJ(m_armIdEdit->text().trimmed(), positions,
|
||
|
|
m_velocitySpin->value(), m_accelerationSpin->value());
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::sendMoveJPose()
|
||
|
|
{
|
||
|
|
if (m_moveJPoseSpins.size() != 6 || !m_moveJPoseBaseLinkCombo)
|
||
|
|
return;
|
||
|
|
QVariantMap pose;
|
||
|
|
static const QStringList keys = {
|
||
|
|
QStringLiteral("x"), QStringLiteral("y"), QStringLiteral("z"),
|
||
|
|
QStringLiteral("rx"), QStringLiteral("ry"), QStringLiteral("rz")
|
||
|
|
};
|
||
|
|
for (int i = 0; i < keys.size(); ++i)
|
||
|
|
pose.insert(keys.at(i), m_moveJPoseSpins.at(i)->value());
|
||
|
|
const bool leftArm = m_armSideCombo->currentData().toString() == QStringLiteral("left");
|
||
|
|
m_client->requestMoveJPose(m_armIdEdit->text().trimmed(), pose,
|
||
|
|
m_moveJPoseBaseLinkCombo->currentText().trimmed(),
|
||
|
|
leftArm ? QStringLiteral("L_FINGER_TIP")
|
||
|
|
: QStringLiteral("R_FINGER_TIP"),
|
||
|
|
m_velocitySpin->value(), m_accelerationSpin->value());
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::saveSnapshot()
|
||
|
|
{
|
||
|
|
QImage image = m_cameraStreaming && m_videoRender
|
||
|
|
? m_videoRender->grabFramebuffer() : m_lastImage;
|
||
|
|
if (image.isNull())
|
||
|
|
return;
|
||
|
|
const QString defaultName = QStringLiteral("cmvr_rgb_%1.png")
|
||
|
|
.arg(QDateTime::currentDateTime().toString("yyyyMMdd_HHmmss"));
|
||
|
|
const QString path = QFileDialog::getSaveFileName(this, QStringLiteral("保存 RGB 图像"),
|
||
|
|
defaultName, QStringLiteral("PNG 图像 (*.png);;JPEG 图像 (*.jpg)"));
|
||
|
|
if (path.isEmpty())
|
||
|
|
return;
|
||
|
|
const bool saved = image.save(path);
|
||
|
|
appendLog(saved ? QStringLiteral("OK") : QStringLiteral("ERROR"),
|
||
|
|
saved ? QStringLiteral("图像已保存:%1").arg(path)
|
||
|
|
: QStringLiteral("图像保存失败:%1").arg(path));
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::loadSettings()
|
||
|
|
{
|
||
|
|
QSettings settings;
|
||
|
|
m_hostEdit->setText(settings.value(QStringLiteral("connection/host"), QStringLiteral("192.168.0.28")).toString());
|
||
|
|
m_hostEdit->setCursorPosition(0);
|
||
|
|
m_portSpin->setValue(settings.value(QStringLiteral("connection/port"), 50052).toInt());
|
||
|
|
m_demoCheck->setChecked(settings.value(QStringLiteral("connection/demo"), true).toBool());
|
||
|
|
m_systemTargetEdit->setText(settings.value(QStringLiteral("system/target"), QStringLiteral("*")).toString());
|
||
|
|
const QString armSide = settings.value(QStringLiteral("arm/side"),
|
||
|
|
QStringLiteral("right")).toString();
|
||
|
|
if (m_armSideCombo) {
|
||
|
|
const int sideIndex = m_armSideCombo->findData(armSide);
|
||
|
|
if (sideIndex >= 0)
|
||
|
|
m_armSideCombo->setCurrentIndex(sideIndex);
|
||
|
|
}
|
||
|
|
const QString defaultArmDeviceId = armSide == QStringLiteral("left")
|
||
|
|
? QStringLiteral("eyou_left_arm") : QStringLiteral("eyou_right_arm");
|
||
|
|
QString armDeviceId = settings.value(QStringLiteral("arm/device"),
|
||
|
|
defaultArmDeviceId).toString().trimmed();
|
||
|
|
if (armDeviceId == QStringLiteral("left_arm")) {
|
||
|
|
armDeviceId = QStringLiteral("eyou_left_arm");
|
||
|
|
} else if (armDeviceId == QStringLiteral("right_arm") ||
|
||
|
|
armDeviceId == QStringLiteral("eyou_arm")) {
|
||
|
|
armDeviceId = QStringLiteral("eyou_right_arm");
|
||
|
|
}
|
||
|
|
m_armIdEdit->setText(armDeviceId);
|
||
|
|
m_cameraIdEdit->setText(settings.value(QStringLiteral("camera/device"), QStringLiteral("camera")).toString());
|
||
|
|
rebuildCameraPreviewGrid(configuredCameraIds());
|
||
|
|
m_cameraRecordPathEdit->setText(settings.value(
|
||
|
|
QStringLiteral("camera/recordPath"),
|
||
|
|
QStringLiteral("/mnt/data/cmvr/record/camera.mp4")).toString());
|
||
|
|
const QString cameraCodec = settings.value(QStringLiteral("camera/codec"),
|
||
|
|
QStringLiteral("h264")).toString().toLower();
|
||
|
|
m_cameraCodecCombo->setCurrentIndex(
|
||
|
|
cameraCodec == QStringLiteral("h265") || cameraCodec == QStringLiteral("hevc") ? 1 : 0);
|
||
|
|
if (m_cameraStreamModeCombo) {
|
||
|
|
const QString cameraMode = settings.value(QStringLiteral("camera/streamMode"),
|
||
|
|
QStringLiteral("rgb")).toString().toLower();
|
||
|
|
const int modeIndex = m_cameraStreamModeCombo->findData(cameraMode);
|
||
|
|
if (modeIndex >= 0)
|
||
|
|
m_cameraStreamModeCombo->setCurrentIndex(modeIndex);
|
||
|
|
}
|
||
|
|
m_agvIdEdit->setText(settings.value(QStringLiteral("agv/device"), QStringLiteral("agv")).toString());
|
||
|
|
m_velocitySpin->setValue(settings.value(QStringLiteral("motion/velocity"), 1.0).toDouble());
|
||
|
|
m_accelerationSpin->setValue(settings.value(QStringLiteral("motion/acceleration"), 0.5).toDouble());
|
||
|
|
const QDir applicationDirectory(QCoreApplication::applicationDirPath());
|
||
|
|
const QString defaultUrdf = applicationDirectory.filePath(QStringLiteral("models/demo_arm.urdf"));
|
||
|
|
QString configuredUrdf = settings.value(QStringLiteral("arm/urdf"), defaultUrdf)
|
||
|
|
.toString().trimmed();
|
||
|
|
if (!configuredUrdf.isEmpty() && QFileInfo(configuredUrdf).isRelative())
|
||
|
|
configuredUrdf = applicationDirectory.absoluteFilePath(configuredUrdf);
|
||
|
|
m_pendingUrdfPath = QFileInfo::exists(configuredUrdf)
|
||
|
|
? QFileInfo(configuredUrdf).absoluteFilePath()
|
||
|
|
: (QFileInfo::exists(defaultUrdf) ? QFileInfo(defaultUrdf).absoluteFilePath()
|
||
|
|
: QString());
|
||
|
|
m_quicBindEdit->setText(settings.value(QStringLiteral("quic/bindAddress"),
|
||
|
|
QStringLiteral("127.0.0.1")).toString());
|
||
|
|
m_quicPortSpin->setValue(settings.value(QStringLiteral("quic/port"), 4433).toInt());
|
||
|
|
m_quicAlpnEdit->setText(settings.value(QStringLiteral("quic/alpn"),
|
||
|
|
QStringLiteral("cmvr-quic-edge/1")).toString());
|
||
|
|
const QDir applicationDir(QCoreApplication::applicationDirPath());
|
||
|
|
const QString defaultCertificate = applicationDir.filePath(
|
||
|
|
QStringLiteral("quic-test-server.pfx"));
|
||
|
|
QString certificatePath = settings.value(
|
||
|
|
QStringLiteral("quic/certificate"),
|
||
|
|
QStringLiteral("quic-test-server.pfx")).toString().trimmed();
|
||
|
|
if (QFileInfo(certificatePath).isRelative())
|
||
|
|
certificatePath = applicationDir.filePath(certificatePath);
|
||
|
|
if (!QFileInfo(certificatePath).isFile()) {
|
||
|
|
certificatePath = defaultCertificate;
|
||
|
|
settings.setValue(QStringLiteral("quic/certificate"),
|
||
|
|
QStringLiteral("quic-test-server.pfx"));
|
||
|
|
}
|
||
|
|
m_quicCertificateEdit->setText(QDir::toNativeSeparators(certificatePath));
|
||
|
|
m_quicPasswordEdit->setText(QStringLiteral("cmvr-test"));
|
||
|
|
m_endpointValue->setText(endpoint());
|
||
|
|
if (m_sidebarEndpointValue)
|
||
|
|
m_sidebarEndpointValue->setText(endpoint());
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::saveSettings()
|
||
|
|
{
|
||
|
|
QSettings settings;
|
||
|
|
settings.setValue(QStringLiteral("connection/host"), m_hostEdit->text().trimmed());
|
||
|
|
settings.setValue(QStringLiteral("connection/port"), m_portSpin->value());
|
||
|
|
settings.setValue(QStringLiteral("connection/demo"), m_demoCheck->isChecked());
|
||
|
|
settings.setValue(QStringLiteral("system/target"), m_systemTargetEdit->text().trimmed());
|
||
|
|
settings.setValue(QStringLiteral("arm/device"), m_armIdEdit->text().trimmed());
|
||
|
|
if (m_armSideCombo)
|
||
|
|
settings.setValue(QStringLiteral("arm/side"), m_armSideCombo->currentData().toString());
|
||
|
|
settings.setValue(QStringLiteral("camera/device"), m_cameraIdEdit->text().trimmed());
|
||
|
|
settings.setValue(QStringLiteral("camera/recordPath"),
|
||
|
|
m_cameraRecordPathEdit->text().trimmed());
|
||
|
|
settings.setValue(QStringLiteral("camera/codec"),
|
||
|
|
m_cameraCodecCombo->currentIndex() == 1
|
||
|
|
? QStringLiteral("h265") : QStringLiteral("h264"));
|
||
|
|
if (m_cameraStreamModeCombo)
|
||
|
|
settings.setValue(QStringLiteral("camera/streamMode"),
|
||
|
|
m_cameraStreamModeCombo->currentData().toString());
|
||
|
|
settings.setValue(QStringLiteral("agv/device"), m_agvIdEdit->text().trimmed());
|
||
|
|
settings.setValue(QStringLiteral("motion/velocity"), m_velocitySpin->value());
|
||
|
|
settings.setValue(QStringLiteral("motion/acceleration"), m_accelerationSpin->value());
|
||
|
|
if (m_urdfViewer && !m_urdfViewer->currentFile().isEmpty())
|
||
|
|
settings.setValue(QStringLiteral("arm/urdf"), m_urdfViewer->currentFile());
|
||
|
|
else if (!m_pendingUrdfPath.isEmpty())
|
||
|
|
settings.setValue(QStringLiteral("arm/urdf"), m_pendingUrdfPath);
|
||
|
|
settings.setValue(QStringLiteral("quic/bindAddress"), m_quicBindEdit->text().trimmed());
|
||
|
|
settings.setValue(QStringLiteral("quic/port"), m_quicPortSpin->value());
|
||
|
|
settings.setValue(QStringLiteral("quic/alpn"), m_quicAlpnEdit->text().trimmed());
|
||
|
|
const QString certificatePath = QDir::fromNativeSeparators(
|
||
|
|
m_quicCertificateEdit->text().trimmed());
|
||
|
|
const QString bundledCertificate = QDir(QCoreApplication::applicationDirPath())
|
||
|
|
.filePath(QStringLiteral("quic-test-server.pfx"));
|
||
|
|
settings.setValue(
|
||
|
|
QStringLiteral("quic/certificate"),
|
||
|
|
QFileInfo(certificatePath).absoluteFilePath() ==
|
||
|
|
QFileInfo(bundledCertificate).absoluteFilePath()
|
||
|
|
? QStringLiteral("quic-test-server.pfx")
|
||
|
|
: certificatePath);
|
||
|
|
}
|
||
|
|
|
||
|
|
void MainWindow::setControlsEnabled(bool enabled)
|
||
|
|
{
|
||
|
|
for (QPushButton *button : m_serviceButtons) {
|
||
|
|
if (button)
|
||
|
|
button->setEnabled(enabled);
|
||
|
|
}
|
||
|
|
for (QDoubleSpinBox *spin : m_targetSpins)
|
||
|
|
spin->setEnabled(enabled);
|
||
|
|
for (QDoubleSpinBox *spin : m_moveJPoseSpins)
|
||
|
|
spin->setEnabled(enabled);
|
||
|
|
if (m_moveJPoseBaseLinkCombo)
|
||
|
|
m_moveJPoseBaseLinkCombo->setEnabled(enabled);
|
||
|
|
if (m_velocitySpin)
|
||
|
|
m_velocitySpin->setEnabled(enabled);
|
||
|
|
if (m_accelerationSpin)
|
||
|
|
m_accelerationSpin->setEnabled(enabled);
|
||
|
|
if (m_calibrateZeroButton)
|
||
|
|
m_calibrateZeroButton->setEnabled(enabled && m_zeroJointCombo
|
||
|
|
&& m_zeroJointCombo->count() > 0);
|
||
|
|
if (m_teachSendButton)
|
||
|
|
m_teachSendButton->setEnabled(enabled && m_teachModeButton
|
||
|
|
&& m_teachModeButton->isChecked());
|
||
|
|
if (m_speakerStreamStartButton)
|
||
|
|
m_speakerStreamStartButton->setEnabled(enabled);
|
||
|
|
if (m_speakerStreamStopButton)
|
||
|
|
m_speakerStreamStopButton->setEnabled(false);
|
||
|
|
if (m_microphoneStreamStartButton)
|
||
|
|
m_microphoneStreamStartButton->setEnabled(enabled);
|
||
|
|
if (m_microphoneStreamStopButton)
|
||
|
|
m_microphoneStreamStopButton->setEnabled(false);
|
||
|
|
}
|
||
|
|
|
||
|
|
QString MainWindow::endpoint() const
|
||
|
|
{
|
||
|
|
return QStringLiteral("%1:%2").arg(m_hostEdit->text().trimmed()).arg(m_portSpin->value());
|
||
|
|
}
|