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 OnViewAngle(const msgs::
Vector3d &_msg,
167 msgs::Boolean &_res);
173 private:
bool OnMoveToPose(const msgs::GUICamera &_msg,
174 msgs::Boolean &_res);
180 private:
bool OnViewCollisions(const msgs::StringMsg &_msg,
181 msgs::Boolean &_res);
185 public: Q_INVOKABLE QString ErrorPopupText() const;
189 public: Q_INVOKABLE
void SetErrorPopupText(const QString &_errorTxt);
192 signals:
void ErrorPopupTextChanged();
197 signals:
void popupError();
201 public: Q_INVOKABLE QString LoadingError() const;
205 public: Q_INVOKABLE
void SetLoadingError(const QString &_loadingError);
208 signals:
void LoadingErrorChanged();
211 public: QString loadingError;
215 private:
std::unique_ptr<Scene3DPrivate> dataPtr;
235 public:
void Render();
243 public:
void Destroy();
250 public:
void SetTransformMode(
const std::string &_mode);
258 public:
void SetModelPath(
const std::string &_filePath);
263 public:
void SetDropdownMenuEnabled(
bool _enableDropdownMenu);
269 public:
void SetRecordVideo(
bool _record,
const std::string &_format,
274 public:
void SetRecordVideoUseSimTime(
bool _useSimTime);
278 public:
void SetRecordVideoLockstep(
bool _lockstep);
282 public:
void SetRecordVideoBitrate(
unsigned int _bitrate);
286 public:
void SetMoveTo(
const std::string &_target);
293 public:
void SetFollowTarget(
const std::string &_target,
294 bool _waitForTarget =
false);
308 public:
void SetViewCollisionsTarget(
const std::string &_target);
312 public:
void SetFollowPGain(
double _gain);
317 public:
void SetFollowWorldFrame(
bool _worldFrame);
329 public:
bool FollowWorldFrame()
const;
337 public:
void SetInitCameraPose(
const math::Pose3d &_pose);
351 public:
void HandleKeyPress(QKeyEvent *_e);
355 public:
void HandleKeyRelease(QKeyEvent *_e);
388 public:
void SnapPoint(
397 public:
void RequestSelectionChange(
Entity _selectedEntity,
398 bool _deselectAll,
bool _sendEvent);
408 private:
double SnapValue(
409 double _coord,
double _interval,
double _sensitivity)
const;
416 private:
void HandleMouseEvent();
419 private:
void HandleMouseContextMenu();
422 private:
void HandleMouseViewControl();
425 private:
void HandleMouseTransformControl();
428 private:
void HandleEntitySelection();
431 private:
void HandleModelPlacement();
434 private:
void BroadcastHoverPos();
437 private:
void BroadcastLeftClick();
440 private:
void BroadcastRightClick();
444 private:
Entity UniqueId();
449 public:
bool GeneratePreview(
const sdf::Root &_sdf);
452 public:
void TerminateSpawnPreview();
473 private:
void OnMoveToComplete();
476 private:
void OnViewAngleComplete();
479 private:
void OnMoveToPoseComplete();
485 private:
void UpdateSelectedEntity(
const rendering::NodePtr &_node,
491 private:
void DeselectAllEntities(
bool _sendEvent);
494 signals:
void ContextMenuRequested(QString _entity);
500 signals:
void FollowTargetChanged(
const std::string &_target,
501 bool _waitForTarget);
504 public: GLuint textureId = 0u;
513 public:
bool initialized =
false;
516 public: QSize textureSize = QSize(1024, 1024);
519 public:
bool textureDirty =
false;
535 public slots:
void RenderNext();
538 public slots:
void ShutDown();
541 public slots:
void SizeChanged();
547 signals:
void TextureReady(
int _id,
const QSize &_size);
551 public:
void SetErrorCb(
std::function<
void(
const QString &)> _cb);
557 public: QOffscreenSurface *surface =
nullptr;
560 public: QOpenGLContext *context =
nullptr;
592 public:
void SetInitCameraPose(
const math::Pose3d &_pose);
596 public:
void SetTransformMode(
const std::string &_mode);
604 public:
void SetModelPath(
const std::string &_filePath);
609 public:
void SetDropdownMenuEnabled(
bool _enableDropdownMenu);
615 public:
void SetRecordVideo(
bool _record,
const std::string &_format,
620 public:
void SetRecordVideoUseSimTime(
bool _useSimTime);
624 public:
void SetRecordVideoLockstep(
bool _lockstep);
628 public:
void SetRecordVideoBitrate(
unsigned int _bitrate);
632 public:
void SetMoveTo(
const std::string &_target);
639 public Q_SLOTS:
void SetFollowTarget(
const std::string &_target,
640 bool _waitForTarget =
false);
654 public:
void SetViewCollisionsTarget(
const std::string &_target);
658 public:
void SetFollowPGain(
double _gain);
663 public:
void SetFollowWorldFrame(
bool _worldFrame);
671 public:
void SetWorldName(
const std::string &_name);
683 public:
void UpdateSelectedEntity(
Entity _entity,
690 public:
void DeselectAllEntities(
bool _sendEvent);
713 public:
void OnHovered(
const gz::math::Vector2i &_hoverPos);
719 public:
bool RendererInitialized()
const;
722 public Q_SLOTS:
void Ready();
726 public:
void HandleKeyPress(QKeyEvent *_e);
730 public:
void HandleKeyRelease(QKeyEvent *_e);
733 protected:
void mousePressEvent(QMouseEvent *_e)
override;
736 protected:
void mouseReleaseEvent(QMouseEvent *_e)
override;
739 protected:
void mouseMoveEvent(QMouseEvent *_e)
override;
742 protected:
void wheelEvent(QWheelEvent *_e)
override;
750 private: QSGNode *updatePaintNode(QSGNode *_oldNode,
751 QQuickItem::UpdatePaintNodeData *_data)
override;
757 signals:
void openContextMenu(QString _entity);
761 public slots:
void OnContextMenuRequested(QString _entity);
765 public:
void SetErrorCb(
std::function<
void(
const QString &)> _cb);
779 public:
explicit TextureNode(QQuickWindow *_window);
788 public slots:
void NewTexture(
int _id,
const QSize &_size);
792 public slots:
void PrepareNode();
796 signals:
void TextureInUse();
800 signals:
void PendingNewTexture();
806 public: QSize size = QSize(0, 0);
812 public: QSGTexture *texture =
nullptr;
815 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:59
Q_INVOKABLE void SetErrorPopupText(const QString &_errorTxt)
Set the text for the popup error message.
This library is part of the Ignition Robotics project.
The EntityComponentManager constructs, deletes, and returns components and entities....
Definition: gz/sim/EntityComponentManager.hh:65
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:809
Texture node for displaying the render texture from ign-renderer.
Definition: Scene3D.hh:773
Rendering thread.
Definition: Scene3D.hh:527
Ign-rendering renderer. All ign-rendering calls should be performed inside this class as it makes sur...
Definition: Scene3D.hh:224
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:37
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:44
std::string worldName
Name of the world.
Definition: Scene3D.hh:510
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...
IgnRenderer ignRenderer
Ign-rendering renderer.
Definition: Scene3D.hh:563
A QQUickItem that manages the render window.
Definition: Scene3D.hh:568
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:554
Vector3< double > Vector3d
Q_INVOKABLE void SetLoadingError(const QString &_loadingError)
Set the loading error message.