Ignition Gui

API Reference

6.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 IGNITION_GUI_PLUGINS_SCENE3D_HH_
19 #define IGNITION_GUI_PLUGINS_SCENE3D_HH_
20 
21 #include <string>
22 #include <memory>
23 
26 #include <ignition/math/Color.hh>
27 #include <ignition/math/Pose3.hh>
28 #include <ignition/math/Vector2.hh>
29 #include <ignition/utils/ImplPtr.hh>
30 
31 #include "ignition/gui/Plugin.hh"
32 
33 namespace ignition
34 {
35 namespace gui
36 {
37 namespace plugins
38 {
64  class MinimalScene : public Plugin
65  {
66  Q_OBJECT
67 
69  Q_PROPERTY(
71  READ LoadingError
72  WRITE SetLoadingError
73  NOTIFY LoadingErrorChanged
74  )
75 
76 
77  public: MinimalScene();
78 
82  public slots: void OnHovered(int _mouseX, int _mouseY);
83 
86  public slots: void OnFocusWindow();
87 
92  public slots: void OnDropped(const QString &_drop,
93  int _mouseX, int _mouseY);
94 
95  // Documentation inherited
96  public: virtual void LoadConfig(const tinyxml2::XMLElement *_pluginElem)
97  override;
98 
101  public: Q_INVOKABLE QString LoadingError() const;
102 
105  public: Q_INVOKABLE void SetLoadingError(const QString &_loadingError);
106 
108  signals: void LoadingErrorChanged();
109 
111  public: QString loadingError;
112 
115  IGN_UTILS_UNIQUE_IMPL_PTR(dataPtr)
116  };
117 
118  class RenderSync;
119 
127  {
129  public: IgnRenderer();
130 
133  public: void Render(RenderSync *_renderSync);
134 
138  public: std::string Initialize();
139 
141  public: void Destroy();
142 
145  public: void NewMouseEvent(const common::MouseEvent &_e);
146 
149  public: void NewHoverEvent(const math::Vector2i &_hoverPos);
150 
154  public: void NewDropEvent(const std::string &_dropText,
155  const math::Vector2i &_dropPos);
156 
159  public: void HandleKeyPress(const common::KeyEvent &_e);
160 
163  public: void HandleKeyRelease(const common::KeyEvent &_e);
164 
166  private: void HandleMouseEvent();
167 
169  private: void BroadcastHoverPos();
170 
172  private: void BroadcastDrag();
173 
175  private: void BroadcastLeftClick();
176 
178  private: void BroadcastRightClick();
179 
181  private: void BroadcastMousePress();
182 
184  private: void BroadcastScroll();
185 
187  private: void BroadcastKeyRelease();
188 
190  private: void BroadcastDrop();
191 
193  private: void BroadcastKeyPress();
194 
199  private: math::Vector3d ScreenToScene(const math::Vector2i &_screenPos)
200  const;
201 
205  public: GLuint textureId;
206 
208  public: std::string engineName = "ogre";
209 
211  public: std::string sceneName = "scene";
212 
214  public: math::Pose3d cameraPose = math::Pose3d(0, 0, 2, 0, 0.4, 0);
215 
217  public: double cameraNearClip = 0.01;
218 
220  public: double cameraFarClip = 1000.0;
221 
223  public: math::Color backgroundColor = math::Color::Black;
224 
226  public: math::Color ambientLight = math::Color(0.3f, 0.3f, 0.3f, 1.0f);
227 
229  public: bool initialized = false;
230 
232  public: QSize textureSize = QSize(1024, 1024);
233 
235  public: bool textureDirty = false;
236 
238  public: bool skyEnable = false;
239 
242  IGN_UTILS_UNIQUE_IMPL_PTR(dataPtr)
243  };
244 
246  class RenderThread : public QThread
247  {
248  Q_OBJECT
249 
251  public: RenderThread();
252 
256  public slots: void RenderNext(RenderSync *_renderSync);
257 
259  public slots: void ShutDown();
260 
262  public slots: void SizeChanged();
263 
268  signals: void TextureReady(uint _id, const QSize &_size);
269 
272  public: void SetErrorCb(std::function<void(const QString &)> _cb);
273 
276 
278  public: QOffscreenSurface *surface = nullptr;
279 
281  public: QOpenGLContext *context = nullptr;
282 
285  };
286 
288  class RenderWindowItem : public QQuickItem
289  {
290  Q_OBJECT
291 
294  public: explicit RenderWindowItem(QQuickItem *_parent = nullptr);
295 
296  public: ~RenderWindowItem();
297 
300  public: void SetBackgroundColor(const math::Color &_color);
301 
304  public: void SetAmbientLight(const math::Color &_ambient);
305 
308  public: void SetEngineName(const std::string &_name);
309 
312  public: void SetSceneName(const std::string &_name);
313 
316  public: void SetCameraPose(const math::Pose3d &_pose);
317 
320  public: void SetCameraNearClip(double _near);
321 
324  public: void SetCameraFarClip(double _far);
325 
329  public: void OnHovered(const ignition::math::Vector2i &_hoverPos);
330 
334  public: void OnDropped(const QString &_drop,
335  const ignition::math::Vector2i &_dropPos);
336 
339  public: void SetSkyEnabled(const bool &_sky);
340 
342  public Q_SLOTS: void Ready();
343 
346  public: void HandleKeyPress(const common::KeyEvent &_e);
347 
350  public: void HandleKeyRelease(const common::KeyEvent &_e);
351 
354  public: void SetErrorCb(std::function<void(const QString &)> _cb);
355 
357  public: void StopRendering();
358 
359  // Documentation inherited
360  protected: virtual void mousePressEvent(QMouseEvent *_e) override;
361 
362  // Documentation inherited
363  protected: virtual void mouseReleaseEvent(QMouseEvent *_e) override;
364 
365  // Documentation inherited
366  protected: virtual void mouseMoveEvent(QMouseEvent *_e) override;
367 
368  // Documentation inherited
369  protected: virtual void keyPressEvent(QKeyEvent *_e) override;
370 
371  // Documentation inherited
372  protected: virtual void keyReleaseEvent(QKeyEvent *_e) override;
373 
374  // Documentation inherited
375  protected: virtual void wheelEvent(QWheelEvent *_e) override;
376 
383  private: QSGNode *updatePaintNode(QSGNode *_oldNode,
384  QQuickItem::UpdatePaintNodeData *_data) override;
385 
388  IGN_UTILS_UNIQUE_IMPL_PTR(dataPtr)
389  };
390 
392  class TextureNode : public QObject, public QSGSimpleTextureNode
393  {
394  Q_OBJECT
395 
400  public: explicit TextureNode(QQuickWindow *_window,
401  RenderSync &_renderSync);
402 
404  public: ~TextureNode() override;
405 
410  public slots: void NewTexture(uint _id, const QSize &_size);
411 
414  public slots: void PrepareNode();
415 
417  signals: void TextureInUse(RenderSync *_renderSync);
418 
421  signals: void PendingNewTexture();
422 
424  public: uint id = 0;
425 
427  public: QSize size = QSize(0, 0);
428 
430  public: QMutex mutex;
431 
433  public: RenderSync &renderSync;
434 
436  public: QSGTexture *texture = nullptr;
437 
439  public: QQuickWindow *window = nullptr;
440  };
441 }
442 }
443 }
444 
445 #endif
Creates an ignition rendering scene and user camera. It is possible to orbit the camera around the sc...
Definition: MinimalScene.hh:64
void OnHovered(int _mouseX, int _mouseY)
Callback when the mouse hovers to a new position.
GLuint textureId
Render texture id.
Definition: MinimalScene.hh:205
Q_INVOKABLE void SetLoadingError(const QString &_loadingError)
Set the loading error message.
Definition: Application.hh:35
Q_INVOKABLE QString LoadingError() const
Get the loading error string.
void OnDropped(const QString &_drop, int _mouseX, int _mouseY)
Callback when receives a drop event.
Base class for Ignition GUI plugins.
Definition: Plugin.hh:54
STL class.
std::function< void(const QString &)> errorCb
Function to be called if there are errors.
Definition: MinimalScene.hh:275
void OnFocusWindow()
Callback when the mouse enters the render window to focus the window for mouse/key events...
Pose3< double > Pose3d
RenderSync & renderSync
See RenderSync.
Definition: MinimalScene.hh:433
A QQUickItem that manages the render window.
Definition: MinimalScene.hh:288
Ign-rendering renderer. All ign-rendering calls should be performed inside this class as it makes sur...
Definition: MinimalScene.hh:126
Rendering thread.
Definition: MinimalScene.hh:246
QMutex mutex
Mutex to protect the texture variables.
Definition: MinimalScene.hh:430
Texture node for displaying the render texture from ign-renderer.
Definition: MinimalScene.hh:392
void LoadingErrorChanged()
Notify that loading error has changed.
QString loadingError
Loading error message.
Definition: MinimalScene.hh:74
IgnRenderer ignRenderer
Ign-rendering renderer.
Definition: MinimalScene.hh:284
virtual void LoadConfig(const tinyxml2::XMLElement *_pluginElem) override
Load the plugin with a configuration file. Override this on custom plugins to handle custom configura...
static const Color Black