Gazebo Gui

API Reference

10.0.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#include <optional>
24
25#include <gz/common/KeyEvent.hh>
27#include <gz/math/Color.hh>
28#include <gz/math/Pose3.hh>
29#include <gz/math/Vector2.hh>
30#include <gz/utils/ImplPtr.hh>
32#include <gz/rendering/Light.hh>
33
34#include "gz/gui/Plugin.hh"
35
36#include "MinimalSceneRhi.hh"
37
38namespace gz::gui::plugins
39{
72 class MinimalScene : public Plugin
73 {
74 Q_OBJECT
75
77 Q_PROPERTY(
78 QString loadingError
79 READ LoadingError
80 WRITE SetLoadingError
81 NOTIFY LoadingErrorChanged
82 )
83
84
85 public: MinimalScene();
86
90 public slots: void OnHovered(int _mouseX, int _mouseY);
91
94 public slots: void OnFocusWindow();
95
100 public slots: void OnDropped(const QString &_drop,
101 int _mouseX, int _mouseY);
102
103 // Documentation inherited
104 public: virtual void LoadConfig(const tinyxml2::XMLElement *_pluginElem)
105 override;
106
109 public: Q_INVOKABLE QString LoadingError() const;
110
113 public: Q_INVOKABLE void SetLoadingError(const QString &_loadingError);
114
116 signals: void LoadingErrorChanged();
117
119 public: QString loadingError;
120
123 GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
124 };
125
126 class RenderSync;
127
135 {
137 public: GzRenderer();
138
142 public: void Render(RenderSync *_renderSync,
143 RenderThreadRhi &_renderThreadRhi);
144
151
154 public: void SetGraphicsAPI(const rendering::GraphicsAPI &_graphicsAPI);
155
157 public: void Destroy();
158
161 public: void NewMouseEvent(const common::MouseEvent &_e);
162
165 public: void NewHoverEvent(const math::Vector2i &_hoverPos);
166
170 public: void NewDropEvent(const std::string &_dropText,
171 const math::Vector2i &_dropPos);
172
175 public: void HandleKeyPress(const common::KeyEvent &_e);
176
179 public: void HandleKeyRelease(const common::KeyEvent &_e);
180
182 private: void HandleMouseEvent();
183
185 private: void BroadcastHoverPos();
186
188 private: void BroadcastDrag();
189
191 private: void BroadcastLeftClick();
192
194 private: void BroadcastRightClick();
195
197 private: void BroadcastMousePress();
198
200 private: void BroadcastScroll();
201
203 private: void BroadcastKeyRelease();
204
206 private: void BroadcastDrop();
207
209 private: void BroadcastKeyPress();
210
212 public: std::string engineName = "ogre";
213
215 public: std::string sceneName = "scene";
216
218 public: math::Pose3d cameraPose = math::Pose3d(0, 0, 2, 0, 0.4, 0);
219
221 public: double cameraNearClip = 0.01;
222
224 public: double cameraFarClip = 1000.0;
225
227 public: unsigned int cameraAntiAliasing = 8;
228
230 public: math::Color backgroundColor = math::Color::Black;
231
233 public: math::Color ambientLight = math::Color(0.3f, 0.3f, 0.3f, 1.0f);
234
236 public: bool initialized = false;
237
239 public: QSize textureSize = QSize(1024, 1024);
240
242 public: bool textureDirty = true;
243
245 public: bool skyEnable = false;
246
248 public: std::optional<unsigned int> directionalLightTextureSize;
249
251 public: math::Angle cameraHFOV = math::Angle(M_PI * 0.5);
252
254 public: std::string cameraViewController{""};
255
258 public: rendering::CameraPtr Camera();
259
262 GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
263 };
264
266 class RenderThread : public QThread
267 {
268 Q_OBJECT
269
271 public: RenderThread();
272
276 public slots: void RenderNext(gz::gui::plugins::RenderSync *_renderSync);
277
279 public slots: void ShutDown();
280
282 public slots: void SizeChanged();
283
288 signals: void TextureReady(void* _texturePtr, const QSize &_size);
289
292 public: void SetErrorCb(std::function<void(const QString &)> _cb);
293
295 public: std::function<void(const QString &)> errorCb;
296
298 public: QOffscreenSurface *Surface() const;
299
302 public: void SetSurface(QOffscreenSurface *_surface);
303
305 public: QOpenGLContext *Context() const;
306
309 public: void SetContext(QOpenGLContext *_context);
310
313 public: void SetGraphicsAPI(const rendering::GraphicsAPI &_graphicsAPI);
314
318
321
324 };
325
327 class RenderWindowItem : public QQuickItem
328 {
329 Q_OBJECT
330
333 public: explicit RenderWindowItem(QQuickItem *_parent = nullptr);
334
336
339 public: void SetBackgroundColor(const math::Color &_color);
340
343 public: void SetAmbientLight(const math::Color &_ambient);
344
347 public: void SetEngineName(const std::string &_name);
348
351 public: void SetSceneName(const std::string &_name);
352
355 public: void SetCameraPose(const math::Pose3d &_pose);
356
359 public: void SetCameraNearClip(double _near);
360
363 public: void SetCameraFarClip(double _far);
364
367 public: void SetAntiAliasing(unsigned int _aa);
368
372 public: void OnHovered(const gz::math::Vector2i &_hoverPos);
373
377 public: void OnDropped(const QString &_drop,
378 const gz::math::Vector2i &_dropPos);
379
382 public: void SetSkyEnabled(const bool &_sky);
383
387 public: bool SetShadowTextureSize(rendering::LightType _lightType,
388 unsigned int _textureSize);
389
392 public: void SetCameraHFOV(const math::Angle &_fov);
393
396 public: void SetGraphicsAPI(const rendering::GraphicsAPI& _graphicsAPI);
397
400 public: void SetCameraViewController(const std::string &_view_controller);
401
403 public Q_SLOTS: void Ready();
404
407 public: void HandleKeyPress(const common::KeyEvent &_e);
408
411 public: void HandleKeyRelease(const common::KeyEvent &_e);
412
415 public: void SetErrorCb(std::function<void(const QString &)> _cb);
416
418 public: void StopRendering();
419
420 // Documentation inherited
421 protected: virtual void mousePressEvent(QMouseEvent *_e) override;
422
423 // Documentation inherited
424 protected: virtual void mouseReleaseEvent(QMouseEvent *_e) override;
425
426 // Documentation inherited
427 protected: virtual void mouseMoveEvent(QMouseEvent *_e) override;
428
429 // Documentation inherited
430 protected: virtual void keyPressEvent(QKeyEvent *_e) override;
431
432 // Documentation inherited
433 protected: virtual void keyReleaseEvent(QKeyEvent *_e) override;
434
435 // Documentation inherited
436 protected: virtual void wheelEvent(QWheelEvent *_e) override;
437
444 private: QSGNode *updatePaintNode(QSGNode *_oldNode,
445 QQuickItem::UpdatePaintNodeData *_data) override;
446
449 GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
450 };
451
453 class TextureNode : public QObject, public QSGSimpleTextureNode
454 {
455 Q_OBJECT
456
463 public: explicit TextureNode(QQuickWindow *_window,
464 RenderSync &_renderSync,
465 const rendering::GraphicsAPI &_graphicsAPI,
466 rendering::CameraPtr &_camera);
467
469 public: ~TextureNode() override;
470
475 // public slots: void NewTexture(uint _id, const QSize &_size);
476 public slots: void NewTexture(void* _texturePtr, const QSize &_size);
477
480 public slots: void PrepareNode();
481
483 signals: void TextureInUse(gz::gui::plugins::RenderSync *_renderSync);
484
487 signals: void PendingNewTexture();
488
490 public: QSize size = QSize(0, 0);
491
493 public: QMutex mutex;
494
496 public: RenderSync &renderSync;
497
499 public: QQuickWindow *window = nullptr;
500
503 };
504} // namespace gz::gui::plugins
505
506#endif // GZ_GUI_PLUGINS_MINIMALSCENE_HH_