Gazebo Gui

API Reference

8.4.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 {
70  class MinimalScene : public Plugin
71  {
72  Q_OBJECT
73 
75  Q_PROPERTY(
76  QString loadingError
77  READ LoadingError
78  WRITE SetLoadingError
79  NOTIFY LoadingErrorChanged
80  )
81 
82 
83  public: MinimalScene();
84 
88  public slots: void OnHovered(int _mouseX, int _mouseY);
89 
92  public slots: void OnFocusWindow();
93 
98  public slots: void OnDropped(const QString &_drop,
99  int _mouseX, int _mouseY);
100 
101  // Documentation inherited
102  public: virtual void LoadConfig(const tinyxml2::XMLElement *_pluginElem)
103  override;
104 
107  public: Q_INVOKABLE QString LoadingError() const;
108 
111  public: Q_INVOKABLE void SetLoadingError(const QString &_loadingError);
112 
114  signals: void LoadingErrorChanged();
115 
117  public: QString loadingError;
118 
121  GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
122  };
123 
124  class RenderSync;
125 
133  {
135  public: GzRenderer();
136 
140  public: void Render(RenderSync *_renderSync,
141  RenderThreadRhi &_renderThreadRhi);
142 
149 
152  public: void SetGraphicsAPI(const rendering::GraphicsAPI &_graphicsAPI);
153 
155  public: void Destroy();
156 
159  public: void NewMouseEvent(const common::MouseEvent &_e);
160 
163  public: void NewHoverEvent(const math::Vector2i &_hoverPos);
164 
168  public: void NewDropEvent(const std::string &_dropText,
169  const math::Vector2i &_dropPos);
170 
173  public: void HandleKeyPress(const common::KeyEvent &_e);
174 
177  public: void HandleKeyRelease(const common::KeyEvent &_e);
178 
180  private: void HandleMouseEvent();
181 
183  private: void BroadcastHoverPos();
184 
186  private: void BroadcastDrag();
187 
189  private: void BroadcastLeftClick();
190 
192  private: void BroadcastRightClick();
193 
195  private: void BroadcastMousePress();
196 
198  private: void BroadcastScroll();
199 
201  private: void BroadcastKeyRelease();
202 
204  private: void BroadcastDrop();
205 
207  private: void BroadcastKeyPress();
208 
210  public: std::string engineName = "ogre";
211 
213  public: std::string sceneName = "scene";
214 
216  public: math::Pose3d cameraPose = math::Pose3d(0, 0, 2, 0, 0.4, 0);
217 
219  public: double cameraNearClip = 0.01;
220 
222  public: double cameraFarClip = 1000.0;
223 
225  public: unsigned int cameraAntiAliasing = 8;
226 
228  public: math::Color backgroundColor = math::Color::Black;
229 
231  public: math::Color ambientLight = math::Color(0.3f, 0.3f, 0.3f, 1.0f);
232 
234  public: bool initialized = false;
235 
237  public: QSize textureSize = QSize(1024, 1024);
238 
240  public: bool textureDirty = true;
241 
243  public: bool skyEnable = false;
244 
246  public: math::Angle cameraHFOV = math::Angle(M_PI * 0.5);
247 
249  public: std::string cameraViewController{""};
250 
254 
257  GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
258  };
259 
261  class RenderThread : public QThread
262  {
263  Q_OBJECT
264 
266  public: RenderThread();
267 
271  public slots: void RenderNext(RenderSync *_renderSync);
272 
274  public slots: void ShutDown();
275 
277  public slots: void SizeChanged();
278 
283  signals: void TextureReady(void* _texturePtr, const QSize &_size);
284 
287  public: void SetErrorCb(std::function<void(const QString &)> _cb);
288 
290  public: std::function<void(const QString &)> errorCb;
291 
293  public: QOffscreenSurface *Surface() const;
294 
297  public: void SetSurface(QOffscreenSurface *_surface);
298 
300  public: QOpenGLContext *Context() const;
301 
304  public: void SetContext(QOpenGLContext *_context);
305 
308  public: void SetGraphicsAPI(const rendering::GraphicsAPI &_graphicsAPI);
309 
313 
316 
319  };
320 
322  class RenderWindowItem : public QQuickItem
323  {
324  Q_OBJECT
325 
328  public: explicit RenderWindowItem(QQuickItem *_parent = nullptr);
329 
330  public: ~RenderWindowItem();
331 
334  public: void SetBackgroundColor(const math::Color &_color);
335 
338  public: void SetAmbientLight(const math::Color &_ambient);
339 
342  public: void SetEngineName(const std::string &_name);
343 
346  public: void SetSceneName(const std::string &_name);
347 
350  public: void SetCameraPose(const math::Pose3d &_pose);
351 
354  public: void SetCameraNearClip(double _near);
355 
358  public: void SetCameraFarClip(double _far);
359 
362  public: void SetAntiAliasing(unsigned int _aa);
363 
367  public: void OnHovered(const gz::math::Vector2i &_hoverPos);
368 
372  public: void OnDropped(const QString &_drop,
373  const gz::math::Vector2i &_dropPos);
374 
377  public: void SetSkyEnabled(const bool &_sky);
378 
381  public: void SetCameraHFOV(const math::Angle &_fov);
382 
385  public: void SetGraphicsAPI(const rendering::GraphicsAPI& _graphicsAPI);
386 
389  public: void SetCameraViewController(const std::string &_view_controller);
390 
392  public Q_SLOTS: void Ready();
393 
396  public: void HandleKeyPress(const common::KeyEvent &_e);
397 
400  public: void HandleKeyRelease(const common::KeyEvent &_e);
401 
404  public: void SetErrorCb(std::function<void(const QString &)> _cb);
405 
407  public: void StopRendering();
408 
409  // Documentation inherited
410  protected: virtual void mousePressEvent(QMouseEvent *_e) override;
411 
412  // Documentation inherited
413  protected: virtual void mouseReleaseEvent(QMouseEvent *_e) override;
414 
415  // Documentation inherited
416  protected: virtual void mouseMoveEvent(QMouseEvent *_e) override;
417 
418  // Documentation inherited
419  protected: virtual void keyPressEvent(QKeyEvent *_e) override;
420 
421  // Documentation inherited
422  protected: virtual void keyReleaseEvent(QKeyEvent *_e) override;
423 
424  // Documentation inherited
425  protected: virtual void wheelEvent(QWheelEvent *_e) override;
426 
433  private: QSGNode *updatePaintNode(QSGNode *_oldNode,
434  QQuickItem::UpdatePaintNodeData *_data) override;
435 
438  GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
439  };
440 
442  class TextureNode : public QObject, public QSGSimpleTextureNode
443  {
444  Q_OBJECT
445 
452  public: explicit TextureNode(QQuickWindow *_window,
453  RenderSync &_renderSync,
454  const rendering::GraphicsAPI &_graphicsAPI,
455  rendering::CameraPtr &_camera);
456 
458  public: ~TextureNode() override;
459 
464  // public slots: void NewTexture(uint _id, const QSize &_size);
465  public slots: void NewTexture(void* _texturePtr, const QSize &_size);
466 
469  public slots: void PrepareNode();
470 
472  signals: void TextureInUse(RenderSync *_renderSync);
473 
476  signals: void PendingNewTexture();
477 
479  public: QSize size = QSize(0, 0);
480 
482  public: QMutex mutex;
483 
485  public: RenderSync &renderSync;
486 
488  public: QQuickWindow *window = nullptr;
489 
491  private: std::unique_ptr<TextureNodeRhi> rhi;
492  };
493 } // namespace gz::gui::plugins
494 
495 #endif // GZ_GUI_PLUGINS_MINIMALSCENE_HH_