feat: refine arm point workflow editor

This commit is contained in:
linbo 2026-10-10 11:38:26 +08:00
parent aeca58c087
commit d527f8ff24
5 changed files with 508 additions and 418 deletions

View File

@ -1,4 +1,5 @@
#include "jointfloweditor.h"
#include "uiicons.h"
#include <QGraphicsItem>
#include <QGraphicsScene>
@ -9,8 +10,12 @@
#include <QDialog>
#include <QDialogButtonBox>
#include <QDoubleSpinBox>
#include <QEvent>
#include <QFormLayout>
#include <QFrame>
#include <QJsonObject>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QMouseEvent>
#include <QPainter>
@ -28,6 +33,88 @@ namespace {
constexpr qreal kNodeWidth = 190.0;
constexpr qreal kNodeHeight = 76.0;
class NodeEditDialog final : public QDialog
{
public:
NodeEditDialog(const QString &title, QWidget *parent)
: QDialog(parent, Qt::Tool | Qt::FramelessWindowHint)
{
setObjectName(QStringLiteral("jointFlowChildDialog"));
setAttribute(Qt::WA_TranslucentBackground);
QVBoxLayout *outerLayout = new QVBoxLayout(this);
outerLayout->setContentsMargins(12, 12, 12, 12);
outerLayout->setSpacing(0);
QFrame *surface = new QFrame(this);
surface->setObjectName(QStringLiteral("jointFlowChildSurface"));
QVBoxLayout *surfaceLayout = new QVBoxLayout(surface);
surfaceLayout->setContentsMargins(0, 0, 0, 0);
surfaceLayout->setSpacing(0);
m_titleBar = new QWidget(surface);
m_titleBar->setObjectName(QStringLiteral("jointFlowChildTitleBar"));
m_titleBar->setFixedHeight(44);
QHBoxLayout *titleLayout = new QHBoxLayout(m_titleBar);
titleLayout->setContentsMargins(12, 0, 0, 0);
titleLayout->setSpacing(9);
QLabel *mark = new QLabel(QStringLiteral("C"), m_titleBar);
mark->setObjectName(QStringLiteral("jointFlowDialogMark"));
mark->setAlignment(Qt::AlignCenter);
mark->setFixedSize(24, 24);
QLabel *titleLabel = new QLabel(title, m_titleBar);
titleLabel->setObjectName(QStringLiteral("jointFlowDialogTitle"));
QPushButton *closeButton = new QPushButton(m_titleBar);
closeButton->setObjectName(QStringLiteral("jointFlowDialogCloseButton"));
closeButton->setFixedSize(46, 43);
closeButton->setIcon(UiIcons::icon(QStringLiteral(":/icons/x.svg"),
QColor(QStringLiteral("#4f5964")), QColor(QStringLiteral("#ffffff"))));
titleLayout->addWidget(mark);
titleLayout->addWidget(titleLabel);
titleLayout->addStretch(1);
titleLayout->addWidget(closeButton);
surfaceLayout->addWidget(m_titleBar);
QWidget *content = new QWidget(surface);
content->setObjectName(QStringLiteral("jointFlowChildContent"));
m_contentLayout = new QVBoxLayout(content);
m_contentLayout->setContentsMargins(18, 16, 18, 16);
m_contentLayout->setSpacing(12);
surfaceLayout->addWidget(content, 1);
outerLayout->addWidget(surface);
m_titleBar->installEventFilter(this);
titleLabel->installEventFilter(this);
mark->installEventFilter(this);
connect(closeButton, &QPushButton::clicked, this, &QDialog::reject);
}
QVBoxLayout *contentLayout() const { return m_contentLayout; }
protected:
bool eventFilter(QObject *watched, QEvent *event) override
{
if ((watched == m_titleBar || (watched && watched->parent() == m_titleBar)) && 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);
move(mouseEvent->globalPos() - m_dragOffset);
return true;
} else if (event->type() == QEvent::MouseButtonRelease) {
m_dragging = false;
}
}
return QDialog::eventFilter(watched, event);
}
private:
QWidget *m_titleBar = nullptr;
QVBoxLayout *m_contentLayout = nullptr;
QPoint m_dragOffset;
bool m_dragging = false;
};
class FlowGraphicsView final : public QGraphicsView
{
public:
@ -102,13 +189,13 @@ public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
{
painter->setRenderHint(QPainter::Antialiasing);
const QColor fill = m_loop ? QColor("#262044") : QColor("#163447");
const QColor border = m_active ? QColor("#56d39b")
: (isSelected() ? QColor("#64b5f6") : QColor("#52606d"));
const QColor fill = m_loop ? QColor("#f4efff") : QColor("#ffffff");
const QColor border = m_active ? QColor("#20a36a")
: (isSelected() ? QColor("#1b6ef3") : QColor("#cbd6e2"));
painter->setPen(QPen(border, m_active ? 3.0 : 1.5));
painter->setBrush(fill);
painter->drawRoundedRect(boundingRect().adjusted(1, 1, -1, -1), 10, 10);
painter->setPen(QColor("#f2f5f7"));
painter->setPen(QColor("#25313d"));
QFont titleFont = painter->font();
titleFont.setBold(true);
painter->setFont(titleFont);
@ -116,14 +203,14 @@ public:
Qt::AlignLeft | Qt::AlignVCenter,
m_title);
if (m_loop) {
const QColor buttonFill = m_collapsePressed ? QColor("#2563a8")
: m_collapseHovered ? QColor("#244d78") : QColor("#17263a");
const QColor buttonFill = m_collapsePressed ? QColor("#d8e9ff")
: m_collapseHovered ? QColor("#e8f2ff") : QColor("#ffffff");
const QColor buttonBorder = m_collapseHovered || m_collapsePressed
? QColor("#64b5f6") : QColor("#71869b");
? QColor("#1b6ef3") : QColor("#b8c7d8");
painter->setPen(QPen(buttonBorder, 1.4));
painter->setBrush(buttonFill);
painter->drawRoundedRect(collapseButtonRect(), 5, 5);
painter->setPen(QPen(QColor("#f4f8fc"), 1.8,
painter->setPen(QPen(QColor("#286fc2"), 1.8,
Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
const QPointF center = collapseButtonRect().center();
QPolygonF arrow;
@ -139,7 +226,7 @@ public:
painter->drawPolyline(arrow);
}
painter->setFont(QFont());
painter->setPen(QColor("#aeb8c2"));
painter->setPen(QColor("#687684"));
painter->drawText(QRectF(14, 38, kNodeWidth - 28, 26), Qt::AlignLeft | Qt::AlignVCenter,
m_subtitle);
}
@ -218,11 +305,13 @@ private:
JointFlowEditor::JointFlowEditor(QWidget *parent) : QWidget(parent)
{
setObjectName(QStringLiteral("jointFlowEditor"));
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
m_scene = new QGraphicsScene(this);
m_scene->setBackgroundBrush(QColor("#10161d"));
m_scene->setBackgroundBrush(QColor("#f4f7fa"));
m_view = new FlowGraphicsView(m_scene, this);
m_view->setObjectName(QStringLiteral("jointFlowCanvas"));
m_view->setRenderHint(QPainter::Antialiasing);
m_view->setDragMode(QGraphicsView::RubberBandDrag);
m_view->setMinimumHeight(230);
@ -466,11 +555,10 @@ void JointFlowEditor::editNode(const QString &id)
Node *node = nodeById(id);
if (!node) return;
QDialog dialog(this);
dialog.setWindowTitle(node->type == SingleNode
? QStringLiteral("编辑单步节点") : QStringLiteral("编辑循环节点"));
NodeEditDialog dialog(node->type == SingleNode
? QStringLiteral("编辑单步节点") : QStringLiteral("编辑循环节点"), this);
dialog.setMinimumWidth(420);
QVBoxLayout *dialogLayout = new QVBoxLayout(&dialog);
QVBoxLayout *dialogLayout = dialog.contentLayout();
QFormLayout *form = new QFormLayout;
QLineEdit *nameEdit = new QLineEdit(node->nodeName, &dialog);
form->addRow(QStringLiteral("节点名称"), nameEdit);
@ -638,7 +726,7 @@ void JointFlowEditor::rebuildScene()
continue;
const QPointF from = cards.value(node.parentId)->sceneBoundingRect().center();
const QPointF to = cards.value(node.id)->sceneBoundingRect().center();
m_scene->addLine(QLineF(from, to), QPen(QColor("#667788"), 2.0));
m_scene->addLine(QLineF(from, to), QPen(QColor("#9aabc0"), 2.0));
}
QStringList parentIds{QString()};
for (const Node &node : m_nodes)
@ -651,7 +739,7 @@ void JointFlowEditor::rebuildScene()
if (!cards.contains(previous->id) || !cards.contains(current->id)) continue;
const QPointF from = cards.value(previous->id)->sceneBoundingRect().center();
const QPointF to = cards.value(current->id)->sceneBoundingRect().center();
m_scene->addLine(QLineF(from, to), QPen(QColor("#3f8db3"), 1.5, Qt::DashLine));
m_scene->addLine(QLineF(from, to), QPen(QColor("#5a91cf"), 1.5, Qt::DashLine));
}
}
m_scene->setSceneRect(m_scene->itemsBoundingRect().adjusted(-60, -60, 60, 60));

View File

@ -1447,25 +1447,7 @@ void MainWindow::updateTelemetry(const QString &deviceId, const QVariantList &jo
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()) {
const double position = joint.value(QStringLiteral("position")).toDouble();
table->item(row, 1)->setText(QStringLiteral("%1°").arg(
qRadiansToDegrees(position),
0, 'f', 2));
table->item(row, 2)->setText(QString::number(position, 'f', 6));
}
}
}
m_lastArmTelemetryMs = nowMs;
if (!pose.isEmpty()) {
m_latestArmPose = pose;
@ -2185,11 +2167,7 @@ void MainWindow::appendLog(const QString &level, const QString &message)
void MainWindow::sendMoveJ()
{
QVariantList positions;
const bool leftArm = m_armSideCombo
&& m_armSideCombo->currentData().toString() == QStringLiteral("left");
const QList<QDoubleSpinBox *> &spins = leftArm
? m_leftTargetSpins : m_rightTargetSpins;
for (QDoubleSpinBox *spin : spins)
for (QDoubleSpinBox *spin : m_targetSpins)
positions.append(qDegreesToRadians(spin->value()));
m_client->requestMoveJ(m_armIdEdit->text().trimmed(), positions,
m_velocitySpin->value(), m_accelerationSpin->value());
@ -2249,9 +2227,7 @@ void MainWindow::recordCurrentJointPoint()
}
}
const bool leftArm = m_armSideCombo
&& m_armSideCombo->currentData().toString() == QStringLiteral("left");
const QStringList jointNames = leftArm ? m_leftArmJointNames : m_rightArmJointNames;
const QStringList jointNames = m_activeArmJointNames;
if (jointNames.isEmpty()) {
QMessageBox::warning(this, QStringLiteral("记录关节点位"),
QStringLiteral("当前 URDF 中没有该机械臂的可运动关节。"));
@ -2260,8 +2236,9 @@ void MainWindow::recordCurrentJointPoint()
RecordedJointPoint point;
point.name = name;
point.side = leftArm ? QStringLiteral("left") : QStringLiteral("right");
point.deviceId = m_armIdEdit->text().trimmed();
point.side = point.deviceId.contains(QStringLiteral("left"), Qt::CaseInsensitive)
? QStringLiteral("left") : QStringLiteral("right");
point.jointNames = jointNames;
QStringList missing;
for (const QString &jointName : jointNames) {
@ -2477,25 +2454,8 @@ void MainWindow::loadSettings()
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("left_ethercat_arm") : QStringLiteral("right_ethercat_arm");
QString armDeviceId = settings.value(QStringLiteral("arm/device"),
defaultArmDeviceId).toString().trimmed();
if (armDeviceId == QStringLiteral("left_arm") ||
armDeviceId == QStringLiteral("eyou_left_arm")) {
armDeviceId = QStringLiteral("left_ethercat_arm");
} else if (armDeviceId == QStringLiteral("right_arm") ||
armDeviceId == QStringLiteral("eyou_arm") ||
armDeviceId == QStringLiteral("eyou_right_arm")) {
armDeviceId = QStringLiteral("right_ethercat_arm");
}
QStringLiteral("demo_arm")).toString().trimmed();
m_armIdEdit->setText(armDeviceId);
if (m_armSideCombo && !armDeviceId.isEmpty())
m_armSideCombo->addItem(armDeviceId, armDeviceId);

View File

@ -194,12 +194,7 @@ private:
TrendWidget *m_trend = nullptr;
QTableWidget *m_jointTable = nullptr;
QTableWidget *m_motionTable = nullptr;
QTableWidget *m_leftMotionTable = nullptr;
QList<QDoubleSpinBox *> m_targetSpins;
QList<QDoubleSpinBox *> m_leftTargetSpins;
QList<QDoubleSpinBox *> m_rightTargetSpins;
QStringList m_leftArmJointNames;
QStringList m_rightArmJointNames;
QStringList m_activeArmJointNames;
QList<QDoubleSpinBox *> m_moveJPoseSpins;
QComboBox *m_moveJPoseBaseLinkCombo = nullptr;

View File

@ -23,6 +23,7 @@
#include <QCheckBox>
#include <QComboBox>
#include <QCoreApplication>
#include <QCursor>
#include <QDir>
#include <QDialog>
#include <QDoubleSpinBox>
@ -62,13 +63,16 @@
#include <QVBoxLayout>
#include <QtMath>
#ifdef Q_OS_WIN
#include <windows.h>
#endif
namespace {
class FramelessToolDialog final : public QDialog
{
public:
explicit FramelessToolDialog(QWidget *parent = nullptr)
: QDialog(parent, Qt::Tool | Qt::FramelessWindowHint
| Qt::WindowStaysOnTopHint)
: QDialog(parent, Qt::Tool | Qt::FramelessWindowHint)
{
setAttribute(Qt::WA_TranslucentBackground);
}
@ -87,6 +91,36 @@ public:
}
protected:
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);
}
bool eventFilter(QObject *watched, QEvent *event) override
{
if (m_dragHandle && event) {
@ -116,6 +150,80 @@ private:
bool m_dragging = false;
};
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("#ffffff"))));
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(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->selectAll();
});
const bool ok = dialog.exec() == QDialog::Accepted;
if (accepted)
*accepted = ok;
return ok ? nameEdit->text().trimmed() : QString();
}
class AccentRowDelegate final : public QStyledItemDelegate
{
public:
@ -140,31 +248,6 @@ public:
}
};
QStringList armJointNames(bool leftArm)
{
const QString prefix = leftArm ? QStringLiteral("L_") : QStringLiteral("R_");
return {
prefix + QStringLiteral("SHOULDER_P"), prefix + QStringLiteral("SHOULDER_R"),
prefix + QStringLiteral("SHOULDER_Y"), prefix + QStringLiteral("ELBOW_R"),
prefix + QStringLiteral("WRIST_P"), prefix + QStringLiteral("WRIST_Y"),
prefix + QStringLiteral("WRIST_R")
};
}
bool isArmJointForSide(const QString &jointName, bool leftArm)
{
const QString lower = jointName.toLower();
const QString sideWord = leftArm ? QStringLiteral("left") : QStringLiteral("right");
const QString sidePrefix = leftArm ? QStringLiteral("l_") : QStringLiteral("r_");
return lower.contains(sideWord + QStringLiteral("_arm"))
|| lower.contains(sideWord + QStringLiteral("arm"))
|| (lower.startsWith(sidePrefix)
&& (lower.contains(QStringLiteral("shoulder"))
|| lower.contains(QStringLiteral("elbow"))
|| lower.contains(QStringLiteral("wrist"))
|| lower.contains(QStringLiteral("arm"))));
}
QWidget *withRpcExplorer(QWidget *commonPage, RobotClient *client,
const QString &serviceName)
{
@ -296,29 +379,6 @@ QWidget *MainWindow::createArmPage()
ui.armTabs->insertTab(0, ui.urdfTab, QStringLiteral("模型与控制"));
}
// Keep device safety controls, the model, MoveJ targets and teaching in one workspace.
ui.commandPanel->setParent(ui.urdfTab);
ui.urdfTabLayout->insertWidget(0, ui.commandPanel);
// Qt3D preview is disabled in release builds. Keep the viewer alive and
// hidden so it can still parse the URDF and provide the joint list, while
// giving the complete workspace height to the command/point-flow tables.
ui.urdfTabLayout->removeWidget(ui.urdfViewer);
ui.urdfViewer->hide();
ui.targetsPanel->setMinimumHeight(0);
ui.targetsPanel->setMaximumHeight(QWIDGETSIZE_MAX);
ui.targetsPanel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
ui.urdfTabLayout->insertWidget(1, ui.targetsPanel, 1);
ui.urdfTabLayout->setStretch(0, 0);
ui.urdfTabLayout->setStretch(1, 1);
const int legacyCommandTabIndex = ui.armTabs->indexOf(ui.jointControlTab);
if (legacyCommandTabIndex >= 0) {
ui.armTabs->removeTab(legacyCommandTabIndex);
ui.jointControlTab->hide();
}
ui.armTabs->setCurrentWidget(ui.urdfTab);
m_armIdEdit = ui.armIdEdit;
m_armTelemetryButton = ui.armTelemetryButton;
m_armDeviceSummary = ui.commandSubtitle;
@ -379,69 +439,41 @@ QWidget *MainWindow::createArmPage()
ui.poseValue->hide();
ui.updatedValue->hide();
QWidget *directMovePage = new QWidget;
QVBoxLayout *directMoveLayout = new QVBoxLayout(directMovePage);
directMoveLayout->setContentsMargins(0, 8, 0, 0);
directMoveLayout->setSpacing(8);
QSplitter *armTargetTables = new QSplitter(Qt::Vertical, directMovePage);
armTargetTables->setObjectName(QStringLiteral("armTargetTables"));
armTargetTables->setChildrenCollapsible(false);
QWidget *leftTargets = new QWidget(armTargetTables);
leftTargets->setObjectName(QStringLiteral("armTargetGroup"));
QVBoxLayout *leftTargetsLayout = new QVBoxLayout(leftTargets);
leftTargetsLayout->setContentsMargins(0, 4, 6, 0);
QLabel *leftTargetsTitle = new QLabel(QStringLiteral("左臂 · left_ethercat_arm"), leftTargets);
leftTargetsTitle->setObjectName(QStringLiteral("eyebrow"));
m_leftMotionTable = new QTableWidget(7, 4, leftTargets);
m_leftMotionTable->setObjectName(QStringLiteral("leftMotionTable"));
leftTargetsLayout->addWidget(leftTargetsTitle);
leftTargetsLayout->addWidget(m_leftMotionTable);
QWidget *rightTargets = new QWidget(armTargetTables);
rightTargets->setObjectName(QStringLiteral("armTargetGroup"));
QVBoxLayout *rightTargetsLayout = new QVBoxLayout(rightTargets);
rightTargetsLayout->setContentsMargins(6, 4, 0, 0);
QLabel *rightTargetsTitle = new QLabel(QStringLiteral("右臂 · right_ethercat_arm"), rightTargets);
rightTargetsTitle->setObjectName(QStringLiteral("eyebrow"));
m_motionTable->setParent(rightTargets);
rightTargetsLayout->addWidget(rightTargetsTitle);
rightTargetsLayout->addWidget(m_motionTable);
armTargetTables->addWidget(leftTargets);
armTargetTables->addWidget(rightTargets);
armTargetTables->setSizes({340, 340});
directMoveLayout->addWidget(armTargetTables, 1);
QHBoxLayout *directMoveActions = new QHBoxLayout;
ui.zeroButton->setParent(directMovePage);
ui.safetyHint->setParent(directMovePage);
m_sendMoveButton->setParent(directMovePage);
directMoveActions->addWidget(ui.zeroButton);
directMoveActions->addWidget(ui.safetyHint, 1);
directMoveActions->addWidget(m_sendMoveButton);
directMoveLayout->addLayout(directMoveActions);
QWidget *moveJPage = new QWidget;
moveJPage->setObjectName(QStringLiteral("jointFlowWorkspace"));
QVBoxLayout *moveJLayout = new QVBoxLayout(moveJPage);
moveJLayout->setContentsMargins(0, 0, 0, 0);
moveJLayout->setSpacing(10);
moveJLayout->setContentsMargins(16, 14, 16, 16);
moveJLayout->setSpacing(12);
QFrame *pointPanel = new QFrame(moveJPage);
pointPanel->setObjectName(QStringLiteral("panelCard"));
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("panelTitle"));
pointTitle->setObjectName(QStringLiteral("jointFlowSectionTitle"));
QLabel *pointSubtitle = new QLabel(
QStringLiteral("记录当前关节角度,作为流程中的可执行点位"), pointPanel);
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);
pointHeader->addWidget(pointTitle);
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)")});
@ -466,6 +498,8 @@ QWidget *MainWindow::createArmPage()
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);
@ -480,8 +514,6 @@ QWidget *MainWindow::createArmPage()
pointActions->addStretch(1);
pointActions->addWidget(m_jointPointLoopStatus);
pointLayout->addLayout(pointActions);
moveJLayout->addWidget(pointPanel, 2);
connect(m_recordJointPointButton, &QPushButton::clicked,
this, &MainWindow::recordCurrentJointPoint);
connect(m_runJointPointButton, &QPushButton::clicked,
@ -533,13 +565,15 @@ QWidget *MainWindow::createArmPage()
});
QFrame *flowPanel = new QFrame(moveJPage);
flowPanel->setObjectName(QStringLiteral("panelCard"));
flowPanel->setObjectName(QStringLiteral("jointFlowPanel"));
QVBoxLayout *flowLayout = new QVBoxLayout(flowPanel);
flowLayout->setContentsMargins(12, 10, 12, 10);
flowLayout->setSpacing(8);
QHBoxLayout *flowBuilder = new QHBoxLayout;
QLabel *flowTitle = new QLabel(QStringLiteral("自定义执行流程"), flowPanel);
flowTitle->setObjectName(QStringLiteral("panelTitle"));
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);
@ -550,23 +584,41 @@ QWidget *MainWindow::createArmPage()
m_jointFlowGroupCount->setRange(1, 10000);
m_jointFlowGroupCount->setValue(2);
QLabel *insertionContextLabel = new QLabel(QStringLiteral("添加到:根流程"), flowPanel);
insertionContextLabel->setObjectName(QStringLiteral("mutedLabel"));
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);
flowBuilder->addWidget(flowTitle);
flowBuilder->addWidget(insertionContextLabel);
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->addStretch(1);
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->addLayout(flowBuilder);
flowLayout->addWidget(flowToolbar);
QLabel *flowHint = new QLabel(QStringLiteral(
"默认在根流程添加;选中循环后点击“进入选中循环”,可向循环内添加节点。"
"点击“返回根流程”退出循环;双击卡片编辑参数,左键拖动节点,右键拖动画布。"
@ -577,6 +629,9 @@ QWidget *MainWindow::createArmPage()
flowLayout->addWidget(m_jointFlowEditor);
QHBoxLayout *flowActions = new QHBoxLayout;
QPushButton *flowDeleteButton = new QPushButton(QStringLiteral("删除选中节点"), flowPanel);
flowDeleteButton->setObjectName(QStringLiteral("dangerOutlineButton"));
m_startJointPointLoopButton->setObjectName(QStringLiteral("primaryButton"));
m_stopJointPointLoopButton->setObjectName(QStringLiteral("dangerButton"));
flowActions->addWidget(flowDeleteButton);
flowActions->addStretch(1);
flowActions->addWidget(loopCountLabel);
@ -585,12 +640,19 @@ QWidget *MainWindow::createArmPage()
flowActions->addWidget(m_startJointPointLoopButton);
flowActions->addWidget(m_stopJointPointLoopButton);
flowLayout->addLayout(flowActions);
moveJLayout->addWidget(flowPanel, 3);
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()) {
QMessageBox::information(this, QStringLiteral("添加单步节点"),
QMessageBox::information(m_jointFlowDialog, QStringLiteral("添加单步节点"),
QStringLiteral("请先选择一个已记录点位。"));
return;
}
@ -598,9 +660,8 @@ QWidget *MainWindow::createArmPage()
if (row >= 0 && row < m_recordedJointPoints.size()) {
const QString executionUnit = m_recordedJointPoints.at(row).name;
bool ok = false;
const QString nodeName = QInputDialog::getText(
this, QStringLiteral("新增单步节点"), QStringLiteral("节点名称"),
QLineEdit::Normal, executionUnit, &ok).trimmed();
const QString nodeName = requestFlowNodeName(
m_jointFlowDialog, QStringLiteral("新增单步节点"), executionUnit, &ok);
if (ok && !nodeName.isEmpty())
m_jointFlowEditor->addSingleNode(nodeName, executionUnit,
m_jointPointInterval->value());
@ -608,9 +669,8 @@ QWidget *MainWindow::createArmPage()
});
connect(addFlowLoopButton, &QPushButton::clicked, this, [this]() {
bool ok = false;
const QString nodeName = QInputDialog::getText(
this, QStringLiteral("新增循环节点"), QStringLiteral("节点名称"),
QLineEdit::Normal, QStringLiteral("循环"), &ok).trimmed();
const QString nodeName = requestFlowNodeName(
m_jointFlowDialog, QStringLiteral("新增循环节点"), QStringLiteral("循环"), &ok);
if (ok && !nodeName.isEmpty())
m_jointFlowEditor->addLoopNode(nodeName, m_jointFlowGroupCount->value(),
m_jointPointInterval->value());
@ -619,7 +679,7 @@ QWidget *MainWindow::createArmPage()
m_jointFlowEditor, &JointFlowEditor::setInsertionAtRoot);
connect(enterSelectedLoopButton, &QPushButton::clicked, this, [this]() {
if (!m_jointFlowEditor->useSelectedLoopAsInsertionParent()) {
QMessageBox::information(this, QStringLiteral("进入循环"),
QMessageBox::information(m_jointFlowDialog, QStringLiteral("进入循环"),
QStringLiteral("请先在画布中选择一个循环节点。"));
}
});
@ -634,15 +694,73 @@ QWidget *MainWindow::createArmPage()
QSettings settings;
saveJointPrograms(settings);
});
m_jointFlowDialog = new QDialog(this);
FramelessToolDialog *jointFlowDialog = new FramelessToolDialog(this);
m_jointFlowDialog = jointFlowDialog;
m_jointFlowDialog->setObjectName(QStringLiteral("jointFlowDialog"));
m_jointFlowDialog->setWindowTitle(QStringLiteral("机械臂点位与流程编排"));
m_jointFlowDialog->setModal(false);
m_jointFlowDialog->resize(1120, 780);
m_jointFlowDialog->setMinimumSize(860, 620);
m_jointFlowDialog->resize(1240, 820);
m_jointFlowDialog->setMinimumSize(980, 680);
QVBoxLayout *jointFlowDialogLayout = new QVBoxLayout(m_jointFlowDialog);
jointFlowDialogLayout->setContentsMargins(12, 12, 12, 12);
jointFlowDialogLayout->addWidget(moveJPage);
const QStringList poseLabels = {
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("#ffffff"))));
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);
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")
};
@ -650,13 +768,6 @@ QWidget *MainWindow::createArmPage()
QStringLiteral("m"), QStringLiteral("m"), QStringLiteral("m"),
QStringLiteral("rad"), QStringLiteral("rad"), QStringLiteral("rad")
};
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 = poseLabels;
m_poseMetricValues.clear();
for (int index = 0; index < poseAxes.size(); ++index) {
QFrame *metricCard = new QFrame(poseMetrics);
@ -686,9 +797,9 @@ QWidget *MainWindow::createArmPage()
ui.telemetryLayout->setStretch(0, 1);
ui.telemetryLayout->setStretch(1, 1);
// Combine the new hold-to-jog controls with the point/flow editor retained
// from the arm workflow branch. The URDF viewer remains alive for parsing,
// but stays hidden to avoid the release-only Qt3D crash and free the space.
// Replace the old target/teaching workspace with hold-to-jog controls and
// a read-only telemetry panel.
ui.targetsPanel->hide();
ui.teachPanel->hide();
ui.urdfTabLayout->removeWidget(ui.urdfViewer);
ui.urdfTabLayout->removeWidget(ui.teachPanel);
@ -961,9 +1072,6 @@ QWidget *MainWindow::createArmPage()
jogTabBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
}
m_jogModeTabs->addTab(cartesianJogPage, QStringLiteral("笛卡尔速度"));
m_jogModeTabs->addTab(directMovePage, QStringLiteral("MoveJ 目标"));
ui.urdfTabLayout->removeWidget(ui.targetsPanel);
ui.targetsPanel->hide();
jogLayout->addWidget(m_jogModeTabs, 1);
QHBoxLayout *speedLayout = new QHBoxLayout;
@ -992,10 +1100,9 @@ QWidget *MainWindow::createArmPage()
jogFooter->addWidget(m_jogStopButton);
jogLayout->addLayout(jogFooter);
modelJogWorkspace->addWidget(jogPanel);
ui.urdfViewer->hide();
modelJogWorkspace->setStretchFactor(0, 0);
modelJogWorkspace->setStretchFactor(1, 1);
modelJogWorkspace->setSizes({0, 1300});
modelJogWorkspace->setStretchFactor(0, 3);
modelJogWorkspace->setStretchFactor(1, 2);
modelJogWorkspace->setSizes({780, 520});
workspaceLayout->addWidget(modelJogWorkspace, 3);
ui.telemetryPanel->setParent(workspace);
@ -1070,12 +1177,9 @@ QWidget *MainWindow::createArmPage()
connect(m_stopButton, &QPushButton::clicked, this, [this]() {
m_client->requestArmStop(m_armIdEdit->text().trimmed());
});
connect(ui.zeroButton, &QPushButton::clicked, this, [this]() {
const bool leftArm = m_armSideCombo->currentData().toString() == QStringLiteral("left");
const QList<QDoubleSpinBox *> &spins = leftArm
? m_leftTargetSpins : m_rightTargetSpins;
for (QDoubleSpinBox *spin : spins)
spin->setValue(0.0);
connect(m_jogStopButton, &QPushButton::clicked, this, &MainWindow::stopArmJog);
connect(m_jogSpeedSlider, &QSlider::valueChanged, this, [this](int value) {
m_jogSpeedValue->setText(QStringLiteral("%1%").arg(value));
});
connect(m_jogModeTabs, &QTabWidget::currentChanged, this, [this](int index) {
stopArmJog();
@ -1125,33 +1229,6 @@ QWidget *MainWindow::createArmPage()
connect(m_urdfViewer, &UrdfViewerWidget::logMessage,
this, &MainWindow::appendLog);
const auto configureMotionTable = [](QTableWidget *table) {
table->setColumnCount(5);
table->setHorizontalHeaderLabels({QStringLiteral("关节"), QStringLiteral("当前角度"),
QStringLiteral("当前弧度"), QStringLiteral("目标角度"),
QStringLiteral("目标弧度")});
table->setAlternatingRowColors(true);
table->setSelectionBehavior(QAbstractItemView::SelectRows);
table->setSelectionMode(QAbstractItemView::SingleSelection);
table->setShowGrid(false);
table->verticalHeader()->setVisible(false);
table->verticalHeader()->setDefaultSectionSize(29);
table->horizontalHeader()->setFixedHeight(32);
table->horizontalHeader()->setHighlightSections(false);
for (int column = 0; column < 5; ++column)
table->horizontalHeader()->setSectionResizeMode(column, QHeaderView::Fixed);
table->setColumnWidth(0, 112);
table->setColumnWidth(1, 76);
table->setColumnWidth(2, 92);
table->setColumnWidth(3, 118);
table->setColumnWidth(4, 96);
table->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
table->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
table->setMinimumHeight(32 + 7 * 29 + 2);
};
configureMotionTable(m_leftMotionTable);
configureMotionTable(m_motionTable);
m_jointTable->setHorizontalHeaderLabels({QStringLiteral("关节"), QStringLiteral("位置 rad"),
QStringLiteral("速度 rad/s"), QStringLiteral("加速度 rad/s²")});
m_jointTable->setAlternatingRowColors(true);
@ -1161,81 +1238,9 @@ QWidget *MainWindow::createArmPage()
m_jointTable->verticalHeader()->setDefaultSectionSize(28);
m_jointTable->horizontalHeader()->setStretchLastSection(true);
m_targetSpins.clear();
m_leftArmJointNames = armJointNames(true);
m_rightArmJointNames = armJointNames(false);
const auto populateMotionTable = [this](QTableWidget *table, bool leftArm,
const QStringList &jointNames) {
QList<QDoubleSpinBox *> &sideSpins = leftArm
? m_leftTargetSpins : m_rightTargetSpins;
sideSpins.clear();
table->clearContents();
table->setRowCount(jointNames.size());
table->setMinimumHeight(32 + qMin(jointNames.size(), 10) * 29 + 2);
for (int row = 0; row < jointNames.size(); ++row) {
const QString jointName = jointNames.at(row);
table->setItem(row, 0, new QTableWidgetItem(jointName));
table->setItem(row, 1, new QTableWidgetItem(QStringLiteral("--")));
table->setItem(row, 2, new QTableWidgetItem(QStringLiteral("--")));
QDoubleSpinBox *target = new QDoubleSpinBox(table);
target->setRange(-180.0, 180.0);
target->setDecimals(3);
target->setSingleStep(1.0);
target->setSuffix(QStringLiteral(" °"));
target->setFrame(false);
target->setEnabled(m_connected);
m_targetSpins.append(target);
sideSpins.append(target);
table->setCellWidget(row, 3, target);
QTableWidgetItem *radians = new QTableWidgetItem(QStringLiteral("0.000000"));
radians->setFlags(radians->flags() & ~Qt::ItemIsEditable);
table->setItem(row, 4, radians);
connect(target, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
[this, table, row, jointName](double degrees) {
if (row < table->rowCount() && table->item(row, 4))
table->item(row, 4)->setText(
QString::number(qDegreesToRadians(degrees), 'f', 6));
if (m_teachModeButton->isChecked())
m_urdfViewer->setTeachingJointPosition(
jointName, qDegreesToRadians(degrees));
});
}
};
populateMotionTable(m_leftMotionTable, true, m_leftArmJointNames);
populateMotionTable(m_motionTable, false, m_rightArmJointNames);
const QStringList allJointNames = armJointNames(true) + armJointNames(false);
m_jointTable->clearContents();
m_jointTable->setRowCount(allJointNames.size());
for (int row = 0; row < allJointNames.size(); ++row) {
m_jointTable->setItem(row, 0, new QTableWidgetItem(allJointNames.at(row)));
for (int column = 1; column < 4; ++column)
m_jointTable->setItem(row, column, new QTableWidgetItem(QStringLiteral("--")));
}
const auto refreshActiveArmControls = [this]() {
const bool leftArm = m_armSideCombo->currentData().toString() == QStringLiteral("left");
m_activeArmJointNames = leftArm ? m_leftArmJointNames : m_rightArmJointNames;
QStringList zeroJointNames;
const QStringList urdfNames = m_urdfViewer->jointNames();
for (const QString &name : urdfNames) {
if (isArmJointForSide(name, leftArm))
zeroJointNames.append(name);
}
if (zeroJointNames.isEmpty())
zeroJointNames = m_activeArmJointNames;
const QString selectedJoint = m_zeroJointCombo->currentText();
const QSignalBlocker blocker(m_zeroJointCombo);
m_zeroJointCombo->clear();
m_zeroJointCombo->addItems(zeroJointNames);
const int selectedIndex = m_zeroJointCombo->findText(selectedJoint);
if (selectedIndex >= 0)
m_zeroJointCombo->setCurrentIndex(selectedIndex);
m_zeroJointCombo->setEnabled(!zeroJointNames.isEmpty());
m_calibrateZeroButton->setEnabled(m_connected && !zeroJointNames.isEmpty());
};
refreshActiveArmControls();
m_activeArmJointNames.clear();
m_jointTable->setRowCount(0);
m_zeroJointCombo->clear();
connect(m_armSideCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
[this, poseSubtitle = ui.poseSubtitle](int) {
@ -1246,9 +1251,13 @@ QWidget *MainWindow::createArmPage()
const bool telemetryRunning = m_armTelemetryButton->isChecked();
if (telemetryRunning)
m_client->setArmTelemetry(oldDeviceId, false);
const bool leftArm = m_armSideCombo->currentData().toString() == QStringLiteral("left");
m_armIdEdit->setText(leftArm ? QStringLiteral("left_ethercat_arm")
: QStringLiteral("right_ethercat_arm"));
m_armIdEdit->setText(newDeviceId);
m_activeArmJointNames.clear();
m_jointTable->setRowCount(0);
rebuildArmJogControls();
m_zeroJointCombo->clear();
m_armDefaultBaseFrame.clear();
m_armDefaultTcpFrame.clear();
m_latestArmPose.clear();
for (QLabel *valueLabel : m_poseMetricValues)
valueLabel->setText(QStringLiteral("--"));
@ -1260,110 +1269,6 @@ QWidget *MainWindow::createArmPage()
if (telemetryRunning)
m_client->setArmTelemetry(newDeviceId, true);
});
connect(m_urdfViewer, &UrdfViewerWidget::modelLoaded, this,
[this, refreshActiveArmControls, populateMotionTable](const QString &, int, int) {
const QStringList urdfNames = m_urdfViewer->jointNames();
QStringList leftNames;
QStringList rightNames;
for (const QString &name : urdfNames) {
if (isArmJointForSide(name, true))
leftNames.append(name);
else if (isArmJointForSide(name, false))
rightNames.append(name);
}
// A single-arm URDF often uses neutral names such as joint1..joint6.
// In that case bind all movable joints to the currently selected arm.
if (leftNames.isEmpty() && rightNames.isEmpty() && !urdfNames.isEmpty()) {
if (m_armSideCombo->currentData().toString() == QStringLiteral("left"))
leftNames = urdfNames;
else
rightNames = urdfNames;
}
m_leftArmJointNames = leftNames;
m_rightArmJointNames = rightNames;
m_targetSpins.clear();
populateMotionTable(m_leftMotionTable, true, m_leftArmJointNames);
populateMotionTable(m_motionTable, false, m_rightArmJointNames);
m_jointTable->clearContents();
m_jointTable->setRowCount(urdfNames.size());
for (int row = 0; row < urdfNames.size(); ++row) {
m_jointTable->setItem(row, 0, new QTableWidgetItem(urdfNames.at(row)));
for (int column = 1; column < 4; ++column)
m_jointTable->setItem(row, column,
new QTableWidgetItem(QStringLiteral("--")));
}
refreshActiveArmControls();
m_teachModeButton->setEnabled(!urdfNames.isEmpty());
});
connect(m_teachModeButton, &QPushButton::toggled, this, [this](bool enabled) {
m_urdfViewer->setTeachingEnabled(enabled);
if (enabled && !m_activeArmJointNames.isEmpty())
m_urdfViewer->selectTeachingJoint(m_activeArmJointNames.first());
});
connect(m_urdfViewer, &UrdfViewerWidget::teachingModeChanged, this,
[this](bool enabled) {
const QSignalBlocker blocker(m_teachModeButton);
m_teachModeButton->setChecked(enabled);
m_teachModeButton->setText(enabled ? QStringLiteral("退出示教")
: QStringLiteral("示教模式"));
m_teachRestoreButton->setEnabled(enabled);
if (!enabled) {
m_teachSelectedJoint.clear();
m_leftMotionTable->clearSelection();
m_motionTable->clearSelection();
}
});
connect(m_urdfViewer, &UrdfViewerWidget::teachingJointSelected, this,
[this](const QString &jointName, double, double, double) {
const int row = m_activeArmJointNames.indexOf(jointName);
if (row < 0) {
if (!m_activeArmJointNames.isEmpty())
m_urdfViewer->selectTeachingJoint(m_activeArmJointNames.first());
return;
}
m_teachSelectedJoint = jointName;
const int zeroIndex = m_zeroJointCombo->findText(jointName);
if (zeroIndex >= 0)
m_zeroJointCombo->setCurrentIndex(zeroIndex);
const bool leftArm = m_armSideCombo->currentData().toString() == QStringLiteral("left");
(leftArm ? m_leftMotionTable : m_motionTable)->selectRow(row);
});
connect(m_urdfViewer, &UrdfViewerWidget::teachingPositionsChanged, this,
[this](const QHash<QString, double> &positions) {
for (int side = 0; side < 2; ++side) {
const bool leftArm = side == 0;
QTableWidget *table = leftArm ? m_leftMotionTable : m_motionTable;
const QStringList &names = leftArm ? m_leftArmJointNames : m_rightArmJointNames;
const QList<QDoubleSpinBox *> &spins = leftArm
? m_leftTargetSpins : m_rightTargetSpins;
for (int row = 0; row < names.size() && row < spins.size(); ++row) {
if (!positions.contains(names.at(row)))
continue;
const double radians = positions.value(names.at(row));
const QSignalBlocker blocker(spins.at(row));
spins.at(row)->setValue(qRadiansToDegrees(radians));
table->item(row, 4)->setText(QString::number(radians, 'f', 6));
}
}
});
connect(m_teachRestoreButton, &QPushButton::clicked,
m_urdfViewer, &UrdfViewerWidget::restoreTeachingFromTelemetry);
const auto connectMotionTable = [this](QTableWidget *table, bool leftArm) {
connect(table, &QTableWidget::cellClicked, this,
[this, leftArm](int row, int) {
const int sideIndex = m_armSideCombo->findData(
leftArm ? QStringLiteral("left") : QStringLiteral("right"));
if (sideIndex >= 0 && sideIndex != m_armSideCombo->currentIndex())
m_armSideCombo->setCurrentIndex(sideIndex);
const QStringList &names = leftArm ? m_leftArmJointNames : m_rightArmJointNames;
if (m_teachModeButton->isChecked() && row >= 0 && row < names.size())
m_urdfViewer->selectTeachingJoint(names.at(row));
});
};
connectMotionTable(m_leftMotionTable, true);
connectMotionTable(m_motionTable, false);
m_serviceButtons << m_armTelemetryButton << m_armGlobalStopButton
<< m_torqueOnButton << m_torqueOffButton

View File

@ -1612,6 +1612,148 @@ QToolTip {
border: none;
padding: 5px;
}
/* Arm point and flow planner */
QDialog#jointFlowDialog {
background: transparent;
border: none;
}
QDialog#jointFlowChildDialog {
background: transparent;
border: none;
}
QFrame#jointFlowChildSurface {
background: #f5f7fa;
border: 1px solid #cbd2da;
border-radius: 9px;
}
QWidget#jointFlowChildTitleBar {
background: #f8fafc;
border: none;
border-bottom: 1px solid #dce1e6;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
}
QWidget#jointFlowChildContent {
background: #ffffff;
border: none;
border-bottom-left-radius: 8px;
border-bottom-right-radius: 8px;
}
QWidget#jointFlowChildContent QLabel {
color: #4f5d69;
font-weight: 600;
}
QWidget#jointFlowChildContent QLineEdit {
min-height: 34px;
padding: 0 10px;
background: #ffffff;
border: 1px solid #bfc9d4;
border-radius: 5px;
selection-background-color: #1b6ef3;
}
QWidget#jointFlowChildContent QLineEdit:focus {
border: 1px solid #1b6ef3;
}
QFrame#jointFlowDialogSurface {
background: #f3f6f9;
border: 1px solid #cbd2da;
border-radius: 9px;
}
QWidget#jointFlowDialogTitleBar {
background: #f8fafc;
border: none;
border-bottom: 1px solid #dce1e6;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
}
QLabel#jointFlowDialogMark {
color: #ffffff;
background: #1b6ef3;
border-radius: 5px;
font-size: 12px;
font-weight: 700;
}
QLabel#jointFlowDialogTitle {
color: #202832;
font-size: 13px;
font-weight: 700;
}
QLabel#jointFlowDialogSubtitle {
color: #78838f;
font-size: 11px;
}
QPushButton#jointFlowDialogWindowButton,
QPushButton#jointFlowDialogCloseButton {
min-height: 45px;
padding: 0;
background: transparent;
border: none;
border-radius: 0;
}
QPushButton#jointFlowDialogWindowButton:hover {
background: #e9edf2;
}
QPushButton#jointFlowDialogCloseButton {
border-top-right-radius: 8px;
}
QPushButton#jointFlowDialogCloseButton:hover {
background: #d83b3b;
}
QWidget#jointFlowWorkspace {
background: #f3f6f9;
}
QFrame#jointPointPanel,
QFrame#jointFlowPanel {
background: #ffffff;
border: 1px solid #dce3ea;
border-radius: 8px;
}
QLabel#jointFlowSectionTitle {
color: #202a34;
font-size: 14px;
font-weight: 700;
}
QLabel#jointFlowSectionSubtitle {
color: #77838f;
font-size: 11px;
}
QLabel#jointFlowContextChip {
color: #155dcc;
background: #eaf3ff;
border: 1px solid #c9def8;
border-radius: 12px;
padding: 4px 10px;
font-weight: 600;
}
QFrame#jointFlowToolbar {
background: #f7f9fb;
border: 1px solid #e1e7ed;
border-radius: 6px;
}
QPushButton#secondaryButton {
color: #2866a8;
background: #ffffff;
border-color: #b9cde2;
}
QPushButton#secondaryButton:hover {
color: #155dcc;
background: #edf5ff;
border-color: #6fa7e5;
}
QTableWidget#jointPointTable {
border: 1px solid #e0e6ec;
border-radius: 6px;
}
QGraphicsView#jointFlowCanvas {
background: #f4f7fa;
border: 1px solid #dce3ea;
border-radius: 6px;
}
QSplitter#jointFlowSplitter::handle {
height: 10px;
background: transparent;
}
QFrame#bottomStatusBar {
background: #ffffff;
border: none;