Go to the documentation of this file.
18 #ifndef GZ_GAZEBO_GUI_SCENE3D_HH_
19 #define GZ_GAZEBO_GUI_SCENE3D_HH_
21 #include <gz/msgs/boolean.pb.h>
22 #include <gz/msgs/gui_camera.pb.h>
23 #include <gz/msgs/stringmsg.pb.h>
24 #include <gz/msgs/vector3d.pb.h>
25 #include <gz/msgs/video_record.pb.h>
31 #include <sdf/Root.hh>
33 #include <gz/math/Color.hh>
34 #include <gz/math/Pose3.hh>
35 #include <gz/math/Vector2.hh>
36 #include <gz/math/Vector3.hh>
38 #include <gz/common/MouseEvent.hh>
39 #include <gz/common/KeyEvent.hh>
41 #include <gz/rendering/Camera.hh>
45 #include "gz/gui/qt.h"
53 inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
54 class IgnRendererPrivate;
55 class RenderWindowItemPrivate;
88 QString errorPopupText
90 WRITE SetErrorPopupText
91 NOTIFY ErrorPopupTextChanged
99 NOTIFY LoadingErrorChanged
109 public:
void LoadConfig(const tinyxml2::XMLElement *_pluginElem) override;
119 public slots:
void OnDropped(const QString &_drop,
120 int _mouseX,
int _mouseY);
125 public slots:
void OnHovered(
int _mouseX,
int _mouseY);
129 public slots:
void OnFocusWindow();
132 protected:
bool eventFilter(QObject *_obj, QEvent *_event) override;
138 private:
bool OnTransformMode(const msgs::StringMsg &_msg,
139 msgs::Boolean &_res);
145 private:
bool OnRecordVideo(const msgs::VideoRecord &_msg,
146 msgs::Boolean &_res);
152 private:
bool OnMoveTo(const msgs::StringMsg &_msg,
153 msgs::Boolean &_res);
159 private:
bool OnFollow(const msgs::StringMsg &_msg,
160 msgs::Boolean &_res);
166 private:
bool OnFollowOffset(const msgs::
Vector3d &_msg,
167 msgs::Boolean &_res);
173 private:
bool OnViewAngle(const msgs::
Vector3d &_msg,
174 msgs::Boolean &_res);
180 private:
bool OnMoveToPose(const msgs::GUICamera &_msg,
181 msgs::Boolean &_res);
188 private:
bool OnViewTransparent(const msgs::StringMsg &_msg,
189 msgs::Boolean &_res);
196 private:
bool OnViewCOM(const msgs::StringMsg &_msg,
197 msgs::Boolean &_res);
203 private:
bool OnViewInertia(const msgs::StringMsg &_msg,
204 msgs::Boolean &_res);
210 private:
bool OnViewJoints(const msgs::StringMsg &_msg,
211 msgs::Boolean &_res);
217 private:
bool OnViewWireframes(const msgs::StringMsg &_msg,
218 msgs::Boolean &_res);
224 private:
bool OnViewCollisions(const msgs::StringMsg &_msg,
225 msgs::Boolean &_res);
229 public: Q_INVOKABLE QString ErrorPopupText() const;
233 public: Q_INVOKABLE
void SetErrorPopupText(const QString &_errorTxt);
236 signals:
void ErrorPopupTextChanged();
241 signals:
void popupError();
247 private:
bool OnViewControl(const msgs::StringMsg &_msg,
248 msgs::Boolean &_res);
252 public: Q_INVOKABLE QString LoadingError() const;
256 public: Q_INVOKABLE
void SetLoadingError(const QString &_loadingError);
259 signals:
void LoadingErrorChanged();
262 public: QString loadingError;
266 private:
std::unique_ptr<Scene3DPrivate> dataPtr;
290 public:
void Render(RenderSync *_renderSync);
298 public:
void Destroy();
305 public:
void SetTransformMode(
const std::string &_mode);
313 public:
void SetModelPath(
const std::string &_filePath);
318 public:
void SetDropdownMenuEnabled(
bool _enableDropdownMenu);
324 public:
void SetRecordVideo(
bool _record,
const std::string &_format,
329 public:
void SetRecordVideoUseSimTime(
bool _useSimTime);
333 public:
void SetRecordVideoLockstep(
bool _lockstep);
337 public:
void SetRecordVideoBitrate(
unsigned int _bitrate);
341 public:
void SetMoveTo(
const std::string &_target);
348 public:
void SetFollowTarget(
const std::string &_target,
349 bool _waitForTarget =
false);
363 public:
void SetViewTransparentTarget(
const std::string &_target);
367 public:
void SetViewCOMTarget(
const std::string &_target);
371 public:
void SetViewInertiaTarget(
const std::string &_target);
375 public:
void SetViewJointsTarget(
const std::string &_target);
379 public:
void SetViewWireframesTarget(
const std::string &_target);
383 public:
void SetViewCollisionsTarget(
const std::string &_target);
387 public:
void SetViewController(
const std::string &_viewController);
391 public:
void SetFollowPGain(
double _gain);
396 public:
void SetFollowWorldFrame(
bool _worldFrame);
408 public:
bool FollowWorldFrame()
const;
416 public:
void SetInitCameraPose(
const math::Pose3d &_pose);
430 public:
void HandleKeyPress(QKeyEvent *_e);
434 public:
void HandleKeyRelease(QKeyEvent *_e);
467 public:
void SnapPoint(
476 public:
void RequestSelectionChange(
Entity _selectedEntity,
477 bool _deselectAll,
bool _sendEvent);
487 private:
double SnapValue(
488 double _coord,
double _interval,
double _sensitivity)
const;
495 private:
void HandleMouseEvent();
498 private:
void HandleMouseContextMenu();
501 private:
void HandleMouseViewControl();
504 private:
void HandleMouseTransformControl();
507 private:
void HandleEntitySelection();
510 private:
void HandleModelPlacement();
513 private:
void BroadcastHoverPos();
516 private:
void BroadcastLeftClick();
519 private:
void BroadcastRightClick();
523 private:
Entity UniqueId();
528 public:
bool GeneratePreview(
const sdf::Root &_sdf);
531 public:
void TerminateSpawnPreview();
552 private:
void OnMoveToComplete();
555 private:
void OnViewAngleComplete();
558 private:
void OnMoveToPoseComplete();
564 private:
void UpdateSelectedEntity(
const rendering::NodePtr &_node,
570 private:
void DeselectAllEntities(
bool _sendEvent);
573 signals:
void ContextMenuRequested(QString _entity);
579 signals:
void FollowTargetChanged(
const std::string &_target,
580 bool _waitForTarget);
595 public: uint32_t visibilityMask = 0xFFFFFFFFu;
598 public:
bool initialized =
false;
601 public: QSize textureSize = QSize(1024, 1024);
604 public:
bool textureDirty =
false;
622 public slots:
void RenderNext(RenderSync *renderSync);
625 public slots:
void ShutDown();
628 public slots:
void SizeChanged();
634 signals:
void TextureReady(uint _id,
const QSize &_size);
638 public:
void SetErrorCb(
std::function<
void(
const QString &)> _cb);
644 public: QOffscreenSurface *surface =
nullptr;
647 public: QOpenGLContext *context =
nullptr;
679 public:
void SetInitCameraPose(
const math::Pose3d &_pose);
683 public:
void SetVisibilityMask(uint32_t _mask);
687 public:
void SetTransformMode(
const std::string &_mode);
695 public:
void SetModelPath(
const std::string &_filePath);
700 public:
void SetDropdownMenuEnabled(
bool _enableDropdownMenu);
706 public:
void SetRecordVideo(
bool _record,
const std::string &_format,
711 public:
void SetRecordVideoUseSimTime(
bool _useSimTime);
715 public:
void SetRecordVideoLockstep(
bool _lockstep);
719 public:
void SetRecordVideoBitrate(
unsigned int _bitrate);
723 public:
void SetMoveTo(
const std::string &_target);
730 public Q_SLOTS:
void SetFollowTarget(
const std::string &_target,
731 bool _waitForTarget =
false);
745 public:
void SetViewTransparentTarget(
const std::string &_target);
749 public:
void SetViewCOMTarget(
const std::string &_target);
753 public:
void SetViewInertiaTarget(
const std::string &_target);
757 public:
void SetViewJointsTarget(
const std::string &_target);
761 public:
void SetViewWireframesTarget(
const std::string &_target);
765 public:
void SetViewCollisionsTarget(
const std::string &_target);
769 public:
void SetViewController(
const std::string &_viewController);
773 public:
void SetFollowPGain(
double _gain);
778 public:
void SetFollowWorldFrame(
bool _worldFrame);
786 public:
void SetWorldName(
const std::string &_name);
798 public:
void UpdateSelectedEntity(
Entity _entity,
805 public:
void DeselectAllEntities(
bool _sendEvent);
828 public:
void OnHovered(
const gz::math::Vector2i &_hoverPos);
834 public:
bool RendererInitialized()
const;
837 public Q_SLOTS:
void Ready();
841 public:
void HandleKeyPress(QKeyEvent *_e);
845 public:
void HandleKeyRelease(QKeyEvent *_e);
848 protected:
void mousePressEvent(QMouseEvent *_e)
override;
851 protected:
void mouseReleaseEvent(QMouseEvent *_e)
override;
854 protected:
void mouseMoveEvent(QMouseEvent *_e)
override;
857 protected:
void wheelEvent(QWheelEvent *_e)
override;
865 private: QSGNode *updatePaintNode(QSGNode *_oldNode,
866 QQuickItem::UpdatePaintNodeData *_data)
override;
872 signals:
void openContextMenu(QString _entity);
876 public slots:
void OnContextMenuRequested(QString _entity);
880 public:
void SetErrorCb(
std::function<
void(
const QString &)> _cb);
896 public:
explicit TextureNode(QQuickWindow *_window,
897 RenderSync &_renderSync);
906 public slots:
void NewTexture(uint _id,
const QSize &_size);
910 public slots:
void PrepareNode();
915 signals:
void TextureInUse(RenderSync *_renderSync);
919 signals:
void PendingNewTexture();
925 public: QSize size = QSize(0, 0);
934 public: QSGTexture *texture =
nullptr;
937 public: QQuickWindow *window =
nullptr;
Base class for a GUI System.
Definition: gz/sim/gui/GuiSystem.hh:44
uint64_t Entity
An Entity identifies a single object in simulation such as a model, link, or light....
Definition: gz/sim/Entity.hh:58
Q_INVOKABLE void SetErrorPopupText(const QString &_errorTxt)
Set the text for the popup error message.
This library is part of the Gazebo project.
The EntityComponentManager constructs, deletes, and returns components and entities....
Definition: gz/sim/EntityComponentManager.hh:66
Q_INVOKABLE QString LoadingError() const
Get the loading error string.
void OnFocusWindow()
Callback when the mouse enters the render window to focus the window for mouse/key events.
QMutex mutex
Mutex to protect the texture variables.
Definition: Scene3D.hh:928
Texture node for displaying the render texture from ign-renderer.
Definition: Scene3D.hh:888
Rendering thread.
Definition: Scene3D.hh:612
GLuint textureId
Render texture id Values is constantly constantly cycled/swapped/changed from a worker thread Don't r...
Definition: Scene3D.hh:586
Ign-rendering renderer. All ign-rendering calls should be performed inside this class as it makes sur...
Definition: Scene3D.hh:277
Creates an ignition rendering scene and user camera. It is possible to orbit the camera around the sc...
Definition: Scene3D.hh:82
void OnHovered(int _mouseX, int _mouseY)
Callback when the mouse hovers to a new position.
Q_INVOKABLE QString ErrorPopupText() const
Get the text for the popup error message.
bool eventFilter(QObject *_obj, QEvent *_event) override
Information passed to systems on the update callback.
Definition: include/gz/sim/Types.hh:38
QString loadingError
Loading error message.
Definition: Scene3D.hh:100
static const Vector2< T > Zero
QString errorPopupText
Text for popup error.
Definition: Scene3D.hh:92
Definition: gz/sim/rendering/RenderUtil.hh:45
std::string worldName
Name of the world.
Definition: Scene3D.hh:592
void ErrorPopupTextChanged()
Notify the popup error text has changed.
void OnDropped(const QString &_drop, int _mouseX, int _mouseY)
Callback when receives a drop event.
void popupError()
Notify that an error has occurred (opens popup) Note that the function name needs to start with lower...
void Update(const UpdateInfo &_info, EntityComponentManager &_ecm) override
Update callback called every time the system is stepped. This is called at an Ignition transport thre...
RenderSync & renderSync
See RenderSync.
Definition: Scene3D.hh:931
IgnRenderer ignRenderer
Ign-rendering renderer.
Definition: Scene3D.hh:650
A QQUickItem that manages the render window.
Definition: Scene3D.hh:655
void LoadConfig(const tinyxml2::XMLElement *_pluginElem) override
void LoadingErrorChanged()
Notify that loading error has changed.
std::function< void(const QString &)> errorCb
Function to be called if there are errors.
Definition: Scene3D.hh:641
Vector3< double > Vector3d
Q_INVOKABLE void SetLoadingError(const QString &_loadingError)
Set the loading error message.