Gazebo Gui

API Reference

8.3.0
MinimalScene.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef GZ_GUI_PLUGINS_MINIMALSCENE_HH_
19 #define GZ_GUI_PLUGINS_MINIMALSCENE_HH_
20 
21 #include <string>
22 #include <memory>
23 
24 #include <gz/common/KeyEvent.hh>
25 #include <gz/common/MouseEvent.hh>
26 #include <gz/math/Color.hh>
27 #include <gz/math/Pose3.hh>
28 #include <gz/math/Vector2.hh>
29 #include <gz/utils/ImplPtr.hh>
31 
32 #include "gz/gui/Plugin.hh"
33 
34 #include "MinimalSceneRhi.hh"
35 
36 namespace gz::gui::plugins
37 {
69  class MinimalScene : public Plugin
70  {
71  Q_OBJECT
72 
74  Q_PROPERTY(
75  QString loadingError
76  READ LoadingError
77  WRITE SetLoadingError
78  NOTIFY LoadingErrorChanged
79  )
80 
81 
82  public: MinimalScene();
83 
87  public slots: void OnHovered(int _mouseX, int _mouseY);
88 
91  public slots: void OnFocusWindow();
92 
97  public slots: void OnDropped(const QString &_drop,
98  int _mouseX, int _mouseY);
99 
100  // Documentation inherited
101  public: virtual void LoadConfig(const tinyxml2::XMLElement *_pluginElem)
102  override;
103 
106  public: Q_INVOKABLE QString LoadingError() const;
107 
110  public: Q_INVOKABLE void SetLoadingError(const QString &_loadingError);
111 
113  signals: void LoadingErrorChanged();
114 
116  public: QString loadingError;
117 
120  GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
121  };
122 
123  class RenderSync;
124 
132  {
134  public: GzRenderer();
135 
139  public: void Render(RenderSync *_renderSync,
140  RenderThreadRhi &_renderThreadRhi);
141 
148 
151  public: void SetGraphicsAPI(const rendering::GraphicsAPI &_graphicsAPI);
152 
154  public: void Destroy();
155 
158  public: void NewMouseEvent(const common::MouseEvent &_e);
159 
162  public: void NewHoverEvent(const math::Vector2i &_hoverPos);
163 
167  public: void NewDropEvent(const std::string &_dropText,
168  const math::Vector2i &_dropPos);
169 
172  public: void HandleKeyPress(const common::KeyEvent &_e);
173 
176  public: void HandleKeyRelease(const common::KeyEvent &_e);
177 
179  private: void HandleMouseEvent();
180 
182  private: void BroadcastHoverPos();
183 
185  private: void BroadcastDrag();
186 
188  private: void BroadcastLeftClick();
189 
191  private: void BroadcastRightClick();
192 
194  private: void BroadcastMousePress();
195 
197  private: void BroadcastScroll();
198 
200  private: void BroadcastKeyRelease();
201 
203  private: void BroadcastDrop();
204 
206  private: void BroadcastKeyPress();
207 
209  public: std::string engineName = "ogre";
210 
212  public: std::string sceneName = "scene";
213 
215  public: math::Pose3d cameraPose = math::Pose3d(0, 0, 2, 0, 0.4, 0);
216 
218  public: double cameraNearClip = 0.01;
219 
221  public: double cameraFarClip = 1000.0;
222 
224  public: math::Color backgroundColor = math::Color::Black;
225 
227  public: math::Color ambientLight = math::Color(0.3f, 0.3f, 0.3f, 1.0f);
228 
230  public: bool initialized = false;
231 
233  public: QSize textureSize = QSize(1024, 1024);
234 
236  public: bool textureDirty = true;
237 
239  public: bool skyEnable = false;
240 
242  public: math::Angle cameraHFOV = math::Angle(M_PI * 0.5);
243 
245  public: std::string cameraViewController{""};
246 
250 
253  GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
254  };
255 
257  class RenderThread : public QThread
258  {
259  Q_OBJECT
260 
262  public: RenderThread();
263 
267  public slots: void RenderNext(RenderSync *_renderSync);
268 
270  public slots: void ShutDown();
271 
273  public slots: void SizeChanged();
274 
279  signals: void TextureReady(void* _texturePtr, const QSize &_size);
280 
283  public: void SetErrorCb(std::function<void(const QString &)> _cb);
284 
286  public: std::function<void(const QString &)> errorCb;
287 
289  public: QOffscreenSurface *Surface() const;
290 
293  public: void SetSurface(QOffscreenSurface *_surface);
294 
296  public: QOpenGLContext *Context() const;
297 
300  public: void SetContext(QOpenGLContext *_context);
301 
304  public: void SetGraphicsAPI(const rendering::GraphicsAPI &_graphicsAPI);
305 
309 
312 
315  };
316 
318  class RenderWindowItem : public QQuickItem
319  {
320  Q_OBJECT
321 
324  public: explicit RenderWindowItem(QQuickItem *_parent = nullptr);
325 
326  public: ~RenderWindowItem();
327 
330  public: void SetBackgroundColor(const math::Color &_color);
331 
334  public: void SetAmbientLight(const math::Color &_ambient);
335 
338  public: void SetEngineName(const std::string &_name);
339 
342  public: void SetSceneName(const std::string &_name);
343 
346  public: void SetCameraPose(const math::Pose3d &_pose);
347 
350  public: void SetCameraNearClip(double _near);
351 
354  public: void SetCameraFarClip(double _far);
355 
359  public: void OnHovered(const gz::math::Vector2i &_hoverPos);
360 
364  public: void OnDropped(const QString &_drop,
365  const gz::math::Vector2i &_dropPos);
366 
369  public: void SetSkyEnabled(const bool &_sky);
370 
373  public: void SetCameraHFOV(const math::Angle &_fov);
374 
377  public: void SetGraphicsAPI(const rendering::GraphicsAPI& _graphicsAPI);
378 
381  public: void SetCameraViewController(const std::string &_view_controller);
382 
384  public Q_SLOTS: void Ready();
385 
388  public: void HandleKeyPress(const common::KeyEvent &_e);
389 
392  public: void HandleKeyRelease(const common::KeyEvent &_e);
393 
396  public: void SetErrorCb(std::function<void(const QString &)> _cb);
397 
399  public: void StopRendering();
400 
401  // Documentation inherited
402  protected: virtual void mousePressEvent(QMouseEvent *_e) override;
403 
404  // Documentation inherited
405  protected: virtual void mouseReleaseEvent(QMouseEvent *_e) override;
406 
407  // Documentation inherited
408  protected: virtual void mouseMoveEvent(QMouseEvent *_e) override;
409 
410  // Documentation inherited
411  protected: virtual void keyPressEvent(QKeyEvent *_e) override;
412 
413  // Documentation inherited
414  protected: virtual void keyReleaseEvent(QKeyEvent *_e) override;
415 
416  // Documentation inherited
417  protected: virtual void wheelEvent(QWheelEvent *_e) override;
418 
425  private: QSGNode *updatePaintNode(QSGNode *_oldNode,
426  QQuickItem::UpdatePaintNodeData *_data) override;
427 
430  GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
431  };
432 
434  class TextureNode : public QObject, public QSGSimpleTextureNode
435  {
436  Q_OBJECT
437 
444  public: explicit TextureNode(QQuickWindow *_window,
445  RenderSync &_renderSync,
446  const rendering::GraphicsAPI &_graphicsAPI,
447  rendering::CameraPtr &_camera);
448 
450  public: ~TextureNode() override;
451 
456  // public slots: void NewTexture(uint _id, const QSize &_size);
457  public slots: void NewTexture(void* _texturePtr, const QSize &_size);
458 
461  public slots: void PrepareNode();
462 
464  signals: void TextureInUse(RenderSync *_renderSync);
465 
468  signals: void PendingNewTexture();
469 
471  public: QSize size = QSize(0, 0);
472 
474  public: QMutex mutex;
475 
477  public: RenderSync &renderSync;
478 
480  public: QQuickWindow *window = nullptr;
481 
483  private: std::unique_ptr<TextureNodeRhi> rhi;
484  };
485 } // namespace gz::gui::plugins
486 
487 #endif // GZ_GUI_PLUGINS_MINIMALSCENE_HH_