Ignition Gui

API Reference

7.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 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 {
56  class MinimalScene : public Plugin
57  {
58  Q_OBJECT
59 
61  public: MinimalScene();
62 
66  public slots: void OnHovered(int _mouseX, int _mouseY);
67 
70  public slots: void OnFocusWindow();
71 
76  public slots: void OnDropped(const QString &_drop,
77  int _mouseX, int _mouseY);
78 
79  // Documentation inherited
80  public: virtual void LoadConfig(const tinyxml2::XMLElement *_pluginElem)
81  override;
82 
85  IGN_UTILS_UNIQUE_IMPL_PTR(dataPtr)
86  };
87 
88  class RenderSync;
89 
97  {
99  public: IgnRenderer();
100 
103  public: void Render(RenderSync *_renderSync);
104 
106  public: void Initialize();
107 
109  public: void Destroy();
110 
113  public: void NewMouseEvent(const common::MouseEvent &_e);
114 
117  public: void NewHoverEvent(const math::Vector2i &_hoverPos);
118 
122  public: void NewDropEvent(const std::string &_dropText,
123  const math::Vector2i &_dropPos);
124 
127  public: void HandleKeyPress(const common::KeyEvent &_e);
128 
131  public: void HandleKeyRelease(const common::KeyEvent &_e);
132 
134  private: void HandleMouseEvent();
135 
137  private: void BroadcastHoverPos();
138 
140  private: void BroadcastDrag();
141 
143  private: void BroadcastLeftClick();
144 
146  private: void BroadcastRightClick();
147 
149  private: void BroadcastMousePress();
150 
152  private: void BroadcastScroll();
153 
155  private: void BroadcastKeyRelease();
156 
158  private: void BroadcastDrop();
159 
161  private: void BroadcastKeyPress();
162 
167  private: math::Vector3d ScreenToScene(const math::Vector2i &_screenPos)
168  const;
169 
173  public: GLuint textureId;
174 
176  public: std::string engineName = "ogre";
177 
179  public: std::string sceneName = "scene";
180 
182  public: math::Pose3d cameraPose = math::Pose3d(0, 0, 2, 0, 0.4, 0);
183 
185  public: math::Color backgroundColor = math::Color::Black;
186 
188  public: math::Color ambientLight = math::Color(0.3f, 0.3f, 0.3f, 1.0f);
189 
191  public: bool initialized = false;
192 
194  public: QSize textureSize = QSize(1024, 1024);
195 
197  public: bool textureDirty = false;
198 
203 
207 
210 
215 
217  public: bool skyEnable = false;
218 
221  IGN_UTILS_UNIQUE_IMPL_PTR(dataPtr)
222  };
223 
225  class RenderThread : public QThread
226  {
227  Q_OBJECT
228 
230  public: RenderThread();
231 
234  public slots: void RenderNext(RenderSync *renderSync);
235 
237  public slots: void ShutDown();
238 
240  public slots: void SizeChanged();
241 
246  signals: void TextureReady(uint _id, const QSize &_size);
247 
249  public: QOffscreenSurface *surface = nullptr;
250 
252  public: QOpenGLContext *context = nullptr;
253 
256  };
257 
259  class RenderWindowItem : public QQuickItem
260  {
261  Q_OBJECT
262 
265  public: explicit RenderWindowItem(QQuickItem *_parent = nullptr);
266 
267  public: ~RenderWindowItem();
268 
271  public: void SetBackgroundColor(const math::Color &_color);
272 
275  public: void SetAmbientLight(const math::Color &_ambient);
276 
279  public: void SetEngineName(const std::string &_name);
280 
283  public: void SetSceneName(const std::string &_name);
284 
287  public: void SetCameraPose(const math::Pose3d &_pose);
288 
293  public: void SetSceneService(const std::string &_service);
294 
299  public: void SetPoseTopic(const std::string &_topic);
300 
305  public: void SetDeletionTopic(const std::string &_topic);
306 
310  public: void SetSceneTopic(const std::string &_topic);
311 
315  public: void OnHovered(const ignition::math::Vector2i &_hoverPos);
316 
320  public: void OnDropped(const QString &_drop,
321  const ignition::math::Vector2i &_dropPos);
322 
325  public: void SetSkyEnabled(const bool &_sky);
326 
328  public Q_SLOTS: void Ready();
329 
332  public: void HandleKeyPress(const common::KeyEvent &_e);
333 
336  public: void HandleKeyRelease(const common::KeyEvent &_e);
337 
338  // Documentation inherited
339  protected: virtual void mousePressEvent(QMouseEvent *_e) override;
340 
341  // Documentation inherited
342  protected: virtual void mouseReleaseEvent(QMouseEvent *_e) override;
343 
344  // Documentation inherited
345  protected: virtual void mouseMoveEvent(QMouseEvent *_e) override;
346 
347  // Documentation inherited
348  protected: virtual void keyPressEvent(QKeyEvent *_e) override;
349 
350  // Documentation inherited
351  protected: virtual void keyReleaseEvent(QKeyEvent *_e) override;
352 
353  // Documentation inherited
354  protected: virtual void wheelEvent(QWheelEvent *_e) override;
355 
362  private: QSGNode *updatePaintNode(QSGNode *_oldNode,
363  QQuickItem::UpdatePaintNodeData *_data) override;
364 
367  IGN_UTILS_UNIQUE_IMPL_PTR(dataPtr)
368  };
369 
371  class TextureNode : public QObject, public QSGSimpleTextureNode
372  {
373  Q_OBJECT
374 
377  public: explicit TextureNode(QQuickWindow *_window,
378  RenderSync &_renderSync);
379 
381  public: ~TextureNode() override;
382 
387  public slots: void NewTexture(uint _id, const QSize &_size);
388 
391  public slots: void PrepareNode();
392 
394  signals: void TextureInUse(RenderSync *_renderSync);
395 
398  signals: void PendingNewTexture();
399 
401  public: uint id = 0;
402 
404  public: QSize size = QSize(0, 0);
405 
407  public: QMutex mutex;
408 
410  public: RenderSync &renderSync;
411 
413  public: QSGTexture *texture = nullptr;
414 
416  public: QQuickWindow *window = nullptr;
417  };
418 }
419 }
420 }
421 
422 #endif
Creates a new ignition rendering scene or adds a user-camera to an existing scene. It is possible to orbit the camera around the scene with the mouse. Use other plugins to manage objects in the scene.
Definition: MinimalScene.hh:56
void OnHovered(int _mouseX, int _mouseY)
Callback when the mouse hovers to a new position.
GLuint textureId
Render texture id.
Definition: MinimalScene.hh:173
std::string sceneService
Scene service. If not empty, a request will be made to get the scene information using this service a...
Definition: MinimalScene.hh:202
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.
void OnFocusWindow()
Callback when the mouse enters the render window to focus the window for mouse/key events...
std::string poseTopic
Scene pose topic. If not empty, a node will subcribe to this topic to get pose updates of objects in ...
Definition: MinimalScene.hh:206
Pose3< double > Pose3d
RenderSync & renderSync
See RenderSync.
Definition: MinimalScene.hh:410
A QQUickItem that manages the render window.
Definition: MinimalScene.hh:259
std::string deletionTopic
Ign-transport deletion topic name.
Definition: MinimalScene.hh:209
Ign-rendering renderer. All ign-rendering calls should be performed inside this class as it makes sur...
Definition: MinimalScene.hh:96
Rendering thread.
Definition: MinimalScene.hh:225
QMutex mutex
Mutex to protect the texture variables.
Definition: MinimalScene.hh:407
Texture node for displaying the render texture from ign-renderer.
Definition: MinimalScene.hh:371
std::string sceneTopic
Ign-transport scene topic name New scene messages will be published to this topic when an entities ar...
Definition: MinimalScene.hh:214
IgnRenderer ignRenderer
Ign-rendering renderer.
Definition: MinimalScene.hh:255
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