Gazebo Gui

API Reference

9.0.0~pre1
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{
71 class MinimalScene : public Plugin
72 {
73 Q_OBJECT
74
76 Q_PROPERTY(
77 QString loadingError
78 READ LoadingError
79 WRITE SetLoadingError
80 NOTIFY LoadingErrorChanged
81 )
82
83
84 public: MinimalScene();
85
89 public slots: void OnHovered(int _mouseX, int _mouseY);
90
93 public slots: void OnFocusWindow();
94
99 public slots: void OnDropped(const QString &_drop,
100 int _mouseX, int _mouseY);
101
102 // Documentation inherited
103 public: virtual void LoadConfig(const tinyxml2::XMLElement *_pluginElem)
104 override;
105
108 public: Q_INVOKABLE QString LoadingError() const;
109
112 public: Q_INVOKABLE void SetLoadingError(const QString &_loadingError);
113
115 signals: void LoadingErrorChanged();
116
118 public: QString loadingError;
119
122 GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
123 };
124
125 class RenderSync;
126
134 {
136 public: GzRenderer();
137
141 public: void Render(RenderSync *_renderSync,
142 RenderThreadRhi &_renderThreadRhi);
143
150
153 public: void SetGraphicsAPI(const rendering::GraphicsAPI &_graphicsAPI);
154
156 public: void Destroy();
157
160 public: void NewMouseEvent(const common::MouseEvent &_e);
161
164 public: void NewHoverEvent(const math::Vector2i &_hoverPos);
165
169 public: void NewDropEvent(const std::string &_dropText,
170 const math::Vector2i &_dropPos);
171
174 public: void HandleKeyPress(const common::KeyEvent &_e);
175
178 public: void HandleKeyRelease(const common::KeyEvent &_e);
179
181 private: void HandleMouseEvent();
182
184 private: void BroadcastHoverPos();
185
187 private: void BroadcastDrag();
188
190 private: void BroadcastLeftClick();
191
193 private: void BroadcastRightClick();
194
196 private: void BroadcastMousePress();
197
199 private: void BroadcastScroll();
200
202 private: void BroadcastKeyRelease();
203
205 private: void BroadcastDrop();
206
208 private: void BroadcastKeyPress();
209
211 public: std::string engineName = "ogre";
212
214 public: std::string sceneName = "scene";
215
217 public: math::Pose3d cameraPose = math::Pose3d(0, 0, 2, 0, 0.4, 0);
218
220 public: double cameraNearClip = 0.01;
221
223 public: double cameraFarClip = 1000.0;
224
226 public: math::Color backgroundColor = math::Color::Black;
227
229 public: math::Color ambientLight = math::Color(0.3f, 0.3f, 0.3f, 1.0f);
230
232 public: bool initialized = false;
233
235 public: QSize textureSize = QSize(1024, 1024);
236
238 public: bool textureDirty = true;
239
241 public: bool skyEnable = false;
242
244 public: std::optional<unsigned int> directionalLightTextureSize;
245
247 public: math::Angle cameraHFOV = math::Angle(M_PI * 0.5);
248
250 public: std::string cameraViewController{""};
251
254 public: rendering::CameraPtr Camera();
255
258 GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
259 };
260
262 class RenderThread : public QThread
263 {
264 Q_OBJECT
265
267 public: RenderThread();
268
272 public slots: void RenderNext(gz::gui::plugins::RenderSync *_renderSync);
273
275 public slots: void ShutDown();
276
278 public slots: void SizeChanged();
279
284 signals: void TextureReady(void* _texturePtr, const QSize &_size);
285
288 public: void SetErrorCb(std::function<void(const QString &)> _cb);
289
291 public: std::function<void(const QString &)> errorCb;
292
294 public: QOffscreenSurface *Surface() const;
295
298 public: void SetSurface(QOffscreenSurface *_surface);
299
301 public: QOpenGLContext *Context() const;
302
305 public: void SetContext(QOpenGLContext *_context);
306
309 public: void SetGraphicsAPI(const rendering::GraphicsAPI &_graphicsAPI);
310
314
317
320 };
321
323 class RenderWindowItem : public QQuickItem
324 {
325 Q_OBJECT
326
329 public: explicit RenderWindowItem(QQuickItem *_parent = nullptr);
330
332
335 public: void SetBackgroundColor(const math::Color &_color);
336
339 public: void SetAmbientLight(const math::Color &_ambient);
340
343 public: void SetEngineName(const std::string &_name);
344
347 public: void SetSceneName(const std::string &_name);
348
351 public: void SetCameraPose(const math::Pose3d &_pose);
352
355 public: void SetCameraNearClip(double _near);
356
359 public: void SetCameraFarClip(double _far);
360
364 public: void OnHovered(const gz::math::Vector2i &_hoverPos);
365
369 public: void OnDropped(const QString &_drop,
370 const gz::math::Vector2i &_dropPos);
371
374 public: void SetSkyEnabled(const bool &_sky);
375
379 public: bool SetShadowTextureSize(rendering::LightType _lightType,
380 unsigned int _textureSize);
381
384 public: void SetCameraHFOV(const math::Angle &_fov);
385
388 public: void SetGraphicsAPI(const rendering::GraphicsAPI& _graphicsAPI);
389
392 public: void SetCameraViewController(const std::string &_view_controller);
393
395 public Q_SLOTS: void Ready();
396
399 public: void HandleKeyPress(const common::KeyEvent &_e);
400
403 public: void HandleKeyRelease(const common::KeyEvent &_e);
404
407 public: void SetErrorCb(std::function<void(const QString &)> _cb);
408
410 public: void StopRendering();
411
412 // Documentation inherited
413 protected: virtual void mousePressEvent(QMouseEvent *_e) override;
414
415 // Documentation inherited
416 protected: virtual void mouseReleaseEvent(QMouseEvent *_e) override;
417
418 // Documentation inherited
419 protected: virtual void mouseMoveEvent(QMouseEvent *_e) override;
420
421 // Documentation inherited
422 protected: virtual void keyPressEvent(QKeyEvent *_e) override;
423
424 // Documentation inherited
425 protected: virtual void keyReleaseEvent(QKeyEvent *_e) override;
426
427 // Documentation inherited
428 protected: virtual void wheelEvent(QWheelEvent *_e) override;
429
436 private: QSGNode *updatePaintNode(QSGNode *_oldNode,
437 QQuickItem::UpdatePaintNodeData *_data) override;
438
441 GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
442 };
443
445 class TextureNode : public QObject, public QSGSimpleTextureNode
446 {
447 Q_OBJECT
448
455 public: explicit TextureNode(QQuickWindow *_window,
456 RenderSync &_renderSync,
457 const rendering::GraphicsAPI &_graphicsAPI,
458 rendering::CameraPtr &_camera);
459
461 public: ~TextureNode() override;
462
467 // public slots: void NewTexture(uint _id, const QSize &_size);
468 public slots: void NewTexture(void* _texturePtr, const QSize &_size);
469
472 public slots: void PrepareNode();
473
475 signals: void TextureInUse(gz::gui::plugins::RenderSync *_renderSync);
476
479 signals: void PendingNewTexture();
480
482 public: QSize size = QSize(0, 0);
483
485 public: QMutex mutex;
486
488 public: RenderSync &renderSync;
489
491 public: QQuickWindow *window = nullptr;
492
495 };
496} // namespace gz::gui::plugins
497
498#endif // GZ_GUI_PLUGINS_MINIMALSCENE_HH_