2026-09-18 16:22:20 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <QHash>
|
|
|
|
|
#include <QPoint>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QStringList>
|
|
|
|
|
#include <QVector3D>
|
|
|
|
|
#include <QWidget>
|
|
|
|
|
|
|
|
|
|
class QLabel;
|
2026-09-23 11:11:49 +08:00
|
|
|
class QComboBox;
|
2026-09-18 16:22:20 +08:00
|
|
|
class QLineEdit;
|
|
|
|
|
class QProgressBar;
|
|
|
|
|
class QPushButton;
|
|
|
|
|
class QShowEvent;
|
|
|
|
|
class QTimer;
|
|
|
|
|
class QVBoxLayout;
|
|
|
|
|
|
|
|
|
|
namespace Qt3DCore {
|
|
|
|
|
class QEntity;
|
|
|
|
|
class QTransform;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace Qt3DExtras {
|
|
|
|
|
class Qt3DWindow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace Qt3DRender {
|
|
|
|
|
class QCamera;
|
|
|
|
|
class QScreenRayCaster;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class UrdfViewerWidget : public QWidget
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit UrdfViewerWidget(QWidget *parent = nullptr);
|
|
|
|
|
~UrdfViewerWidget() override;
|
|
|
|
|
|
|
|
|
|
QString currentFile() const;
|
|
|
|
|
void prepareLoad(const QString &filePath);
|
|
|
|
|
bool loadUrdf(const QString &filePath);
|
2026-09-23 11:11:49 +08:00
|
|
|
bool loadModelForIdentity(const QString &manufacturer, const QString &model,
|
|
|
|
|
const QString &subtype, const QString &descriptionId);
|
2026-09-18 16:22:20 +08:00
|
|
|
void setJointPositions(const QHash<QString, double> &positions);
|
|
|
|
|
QStringList jointNames() const;
|
|
|
|
|
QHash<QString, double> teachingPositions() const;
|
|
|
|
|
QString selectedTeachingJoint() const;
|
|
|
|
|
void setTeachingEnabled(bool enabled);
|
|
|
|
|
void selectTeachingJoint(const QString &jointName);
|
|
|
|
|
void setTeachingJointPosition(const QString &jointName, double position);
|
|
|
|
|
void restoreTeachingFromTelemetry();
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
bool eventFilter(QObject *watched, QEvent *event) override;
|
|
|
|
|
void showEvent(QShowEvent *event) override;
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void logMessage(const QString &level, const QString &message);
|
|
|
|
|
void modelLoaded(const QString &filePath, int linkCount, int jointCount);
|
|
|
|
|
void teachingModeChanged(bool enabled);
|
|
|
|
|
void teachingJointSelected(const QString &jointName, double position,
|
|
|
|
|
double lower, double upper);
|
|
|
|
|
void teachingPositionsChanged(const QHash<QString, double> &positions);
|
|
|
|
|
|
|
|
|
|
private slots:
|
2026-09-23 11:11:49 +08:00
|
|
|
void chooseBundledUrdf(int index);
|
2026-09-18 16:22:20 +08:00
|
|
|
void chooseUrdf();
|
|
|
|
|
void reloadUrdf();
|
|
|
|
|
void resetView();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct JointBinding {
|
|
|
|
|
int type = 0;
|
|
|
|
|
QVector3D axis;
|
|
|
|
|
Qt3DCore::QTransform *transform = nullptr;
|
|
|
|
|
double lower = 0.0;
|
|
|
|
|
double upper = 0.0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void clearModel();
|
|
|
|
|
void ensureSceneInitialized();
|
|
|
|
|
void setLoading(bool loading, const QString &message = QString());
|
|
|
|
|
void orbitCamera(const QPoint &delta);
|
|
|
|
|
void panCamera(const QPoint &delta);
|
|
|
|
|
void zoomCamera(int angleDelta);
|
|
|
|
|
void applyJointPositions(const QHash<QString, double> &positions);
|
|
|
|
|
void attachTeachingPicker(Qt3DCore::QEntity *entity, const QString &jointName);
|
|
|
|
|
void attachTeachingPickersRecursively(Qt3DCore::QEntity *root,
|
|
|
|
|
const QString &jointName);
|
|
|
|
|
void emitTeachingSelection();
|
|
|
|
|
void setMotionDemoRunning(bool running);
|
|
|
|
|
void advanceMotionDemo();
|
2026-09-23 11:11:49 +08:00
|
|
|
void refreshBundledModels();
|
|
|
|
|
void syncModelSelection(const QString &filePath);
|
2026-09-18 16:22:20 +08:00
|
|
|
QString resolveMeshPath(const QString &uri) const;
|
|
|
|
|
void scheduleViewAll();
|
|
|
|
|
|
|
|
|
|
Qt3DExtras::Qt3DWindow *m_view = nullptr;
|
|
|
|
|
Qt3DRender::QCamera *m_camera = nullptr;
|
|
|
|
|
Qt3DRender::QScreenRayCaster *m_teachingRayCaster = nullptr;
|
|
|
|
|
Qt3DCore::QEntity *m_rootEntity = nullptr;
|
|
|
|
|
Qt3DCore::QEntity *m_modelRoot = nullptr;
|
|
|
|
|
QVBoxLayout *m_layout = nullptr;
|
|
|
|
|
QWidget *m_viewportPlaceholder = nullptr;
|
|
|
|
|
QWidget *m_viewContainer = nullptr;
|
|
|
|
|
QLabel *m_loadingTitle = nullptr;
|
|
|
|
|
QLabel *m_loadingDetail = nullptr;
|
|
|
|
|
QProgressBar *m_loadingProgress = nullptr;
|
2026-09-23 11:11:49 +08:00
|
|
|
QComboBox *m_modelCombo = nullptr;
|
2026-09-18 16:22:20 +08:00
|
|
|
QLineEdit *m_pathEdit = nullptr;
|
|
|
|
|
QLabel *m_statusLabel = nullptr;
|
|
|
|
|
QPushButton *m_reloadButton = nullptr;
|
|
|
|
|
QPushButton *m_demoButton = nullptr;
|
|
|
|
|
QTimer *m_demoTimer = nullptr;
|
|
|
|
|
QHash<QString, JointBinding> m_joints;
|
|
|
|
|
QStringList m_jointOrder;
|
|
|
|
|
QHash<QString, double> m_jointPositions;
|
|
|
|
|
QHash<QString, double> m_latestTelemetryPositions;
|
|
|
|
|
QString m_selectedTeachingJoint;
|
|
|
|
|
QPoint m_lastMousePosition;
|
|
|
|
|
Qt::MouseButton m_dragButton = Qt::NoButton;
|
|
|
|
|
bool m_teachingEnabled = false;
|
|
|
|
|
bool m_jointDragActive = false;
|
|
|
|
|
bool m_sceneInitialized = false;
|
|
|
|
|
int m_demoElapsedMs = 0;
|
|
|
|
|
QString m_modelSummary;
|
|
|
|
|
QString m_currentFile;
|
|
|
|
|
QString m_urdfDirectory;
|
|
|
|
|
};
|