OpenWalnut  1.5.0dev
WUIQtViewWidget.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WUIQTVIEWWIDGET_H
26 #define WUIQTVIEWWIDGET_H
27 
28 #include <memory>
29 #include <string>
30 
31 
32 #include "../WMainWindow.h"
33 #include "../WQtGLDockWidget.h"
34 #include "../WQtGLWidget.h"
35 #include "WUIQtWidgetBase.h"
36 #include "core/common/WCondition.h"
37 #include "core/graphicsEngine/WGECamera.h"
38 #include "core/graphicsEngine/WGEGroupNode.h"
39 #include "core/graphicsEngine/WGEViewer.h"
40 #include "core/ui/WUIViewWidget.h"
41 
42 /**
43  * Implementation of \ref WUIViewWidget.
44  */
46  public WUIQtWidgetBase
47 {
48 public:
49  /**
50  * Convenience typedef for a std::shared_ptr< WUIQtViewWidget >.
51  */
52  typedef std::shared_ptr< WUIQtViewWidget > SPtr;
53 
54  /**
55  * Convenience typedef for a std::shared_ptr< const WUIQtViewWidget >.
56  */
57  typedef std::shared_ptr< const WUIQtViewWidget > ConstSPtr;
58 
59  /**
60  * Default constructor.
61  *
62  * \param mainWindow the main window instance
63  * \param parent the Qt parent. Can be NULL.
64  * \param title the title of the widget
65  * \param projectionMode the kind of projection which should be used
66  */
68  std::string title,
69  WGECamera::ProjectionMode projectionMode,
70  WMainWindow* mainWindow,
72 
73  /**
74  * Destructor.
75  */
76  virtual ~WUIQtViewWidget();
77 
78  /**
79  * Title as QString.
80  *
81  * \return the title
82  */
83  virtual QString getTitleQString() const;
84 
85  /**
86  * Get the scene which is displayed
87  *
88  * \return the scene as osg::ref_ptr
89  */
90  virtual osg::ref_ptr< WGEGroupNode > getScene() const;
91 
92  /**
93  * Get the viewer which is used
94  *
95  * \return the viewer as shared_ptr
96  */
97  virtual std::shared_ptr< WGEViewer > getViewer() const;
98 
99  /**
100  * Returns the height of the viewport of the camera.
101  *
102  * \return Height in pixels.
103  */
104  virtual size_t height() const;
105 
106  /**
107  * Returns the width of the viewport of the camera.
108  *
109  * \return Width in pixels.
110  */
111  virtual size_t width() const;
112 
113  /**
114  * Adds an event handler to the widget's view.
115  *
116  * \param handler Pointer to the handler.
117  */
118  virtual void addEventHandler( osgGA::GUIEventHandler* handler );
119 
120  /**
121  * Show this widget if not yet visible.
122  */
123  virtual void show();
124 
125  /**
126  * Hide/show this widget. Unlike close(), you can show the widget again using show().
127  *
128  * \param visible false to hide widget
129  */
130  virtual void setVisible( bool visible = true );
131 
132  /**
133  * Check if the widget is hidden or not.
134  *
135  * \return true if visible.
136  */
137  virtual bool isVisible() const;
138 
139  /**
140  * Handle shutdown. This includes notification of the creating module and closing the widget. Can be called from any thread.
141  * Implement in your implementation.
142  */
143  virtual void close();
144 
145  /**
146  * Implement \ref WUIWidgetBase::addAction.
147  *
148  * \param group the property to use.
149  * \param icon the icon to use. Consider a minimum size of 32x32.
150  */
151  virtual void addAction( WPropGroup group, WGEImage::SPtr icon = WGEImage::SPtr() )
152  {
153  WUIQtWidgetBase::addAction( group, icon );
154  }
155 
156  /**
157  * Implement \ref WUIWidgetBase::addAction.
158  *
159  * \param trigger the property to use.
160  * \param icon the icon to use. Consider a minimum size of 32x32.
161  */
162  virtual void addAction( WPropTrigger trigger, WGEImage::SPtr icon = WGEImage::SPtr() )
163  {
164  WUIQtWidgetBase::addAction( trigger, icon );
165  }
166 
167  /**
168  * Implement \ref WUIWidgetBase::addAction.
169  *
170  * \param toggle the property to use.
171  * \param icon the icon to use. Consider a minimum size of 32x32.
172  */
173  virtual void addAction( WPropBool toggle, WGEImage::SPtr icon = WGEImage::SPtr() )
174  {
175  WUIQtWidgetBase::addAction( toggle, icon );
176  }
177 
178  /**
179  * Remove any pre-existing camera preset. Implements \ref WUIViewWidget::clearCameraPresets.
180  */
181  virtual void clearCameraPresets();
182 
183  /**
184  * Add a custom camera preset. Implements \ref WUIViewWidget::addCameraPreset
185  *
186  * \param preset the trigger to set the preset.
187  * \param icon optional icon.
188  */
189  virtual void addCameraPreset( WPropTrigger preset, WGEImage::SPtr icon = WGEImage::SPtr() );
190 protected:
191  /**
192  * Realize the widget. This method blocks until the GUI thread created the widget. Called from within the GUI thread! So you can safely do Qt
193  * stuff.
194  */
195  virtual void realizeImpl();
196 
197  /**
198  * Close the widget. When done, the widget can be safely deleted.
199  */
200  virtual void closeImpl();
201 
202  /**
203  * Cleanup the GUI. Do not delete m_widget, or your content widget. This is done by WUIQtWidgetBase. This method allows you to free resources
204  * that are not automatically freed by the Qt delete mechanism.
205  */
206  virtual void cleanUpGT();
207 
208  /**
209  * Remove any pre-existing camera preset. Implements \ref WUIViewWidget::clearCameraPresets.
210  */
211  virtual void clearCameraPresetsGT();
212 
213  /**
214  * Add a custom camera preset. Implements \ref WUIViewWidget::addCameraPreset
215  *
216  * \param preset the trigger to set the preset.
217  * \param icon optional icon.
218  */
219  virtual void addCameraPresetGT( WPropTrigger preset, WGEImage::SPtr icon = WGEImage::SPtr() );
220 private:
221  /**
222  * Projection mode of the cam
223  */
225 
226  /**
227  * Scene in this view
228  */
229  osg::ref_ptr< WGEGroupNode > m_scene;
230 
231  /**
232  * The Qt widget representing this abstract widget.
233  * \note this is the same pointer as WUIQtWidgetBase::m_widget as WQtGLDockWidget.
234  */
236 };
237 
238 #endif // WUIQTVIEWWIDGET_H
239 
ProjectionMode
List of possible camera modes.
Definition: WGECamera.h:44
std::shared_ptr< WGEImage > SPtr
Convenience typedef for a std::shared_ptr< WGEImage >.
Definition: WGEImage.h:48
This class contains the main window and the layout of the widgets within the window.
Definition: WMainWindow.h:66
Dock widget containing only a GLWidget.
Implementation of WUIViewWidget.
virtual void setVisible(bool visible=true)
Hide/show this widget.
std::shared_ptr< const WUIQtViewWidget > ConstSPtr
Convenience typedef for a std::shared_ptr< const WUIQtViewWidget >.
std::shared_ptr< WUIQtViewWidget > SPtr
Convenience typedef for a std::shared_ptr< WUIQtViewWidget >.
virtual void clearCameraPresets()
Remove any pre-existing camera preset.
virtual void close()
Handle shutdown.
virtual void addAction(WPropBool toggle, WGEImage::SPtr icon=WGEImage::SPtr())
Implement WUIWidgetBase::addAction.
WQtGLDockWidget * m_widgetDock
The Qt widget representing this abstract widget.
WGECamera::ProjectionMode m_projectionMode
Projection mode of the cam.
virtual void addCameraPreset(WPropTrigger preset, WGEImage::SPtr icon=WGEImage::SPtr())
Add a custom camera preset.
virtual void show()
Show this widget if not yet visible.
virtual ~WUIQtViewWidget()
Destructor.
virtual void addCameraPresetGT(WPropTrigger preset, WGEImage::SPtr icon=WGEImage::SPtr())
Add a custom camera preset.
virtual QString getTitleQString() const
Title as QString.
WUIQtViewWidget(std::string title, WGECamera::ProjectionMode projectionMode, WMainWindow *mainWindow, WUIQtWidgetBase::SPtr parent=WUIQtWidgetBase::SPtr())
Default constructor.
virtual void addAction(WPropGroup group, WGEImage::SPtr icon=WGEImage::SPtr())
Implement WUIWidgetBase::addAction.
virtual void cleanUpGT()
Cleanup the GUI.
virtual osg::ref_ptr< WGEGroupNode > getScene() const
Get the scene which is displayed.
osg::ref_ptr< WGEGroupNode > m_scene
Scene in this view.
virtual void addAction(WPropTrigger trigger, WGEImage::SPtr icon=WGEImage::SPtr())
Implement WUIWidgetBase::addAction.
virtual void closeImpl()
Close the widget.
virtual bool isVisible() const
Check if the widget is hidden or not.
virtual size_t height() const
Returns the height of the viewport of the camera.
virtual void addEventHandler(osgGA::GUIEventHandler *handler)
Adds an event handler to the widget's view.
virtual void realizeImpl()
Realize the widget.
virtual std::shared_ptr< WGEViewer > getViewer() const
Get the viewer which is used.
virtual size_t width() const
Returns the width of the viewport of the camera.
virtual void clearCameraPresetsGT()
Remove any pre-existing camera preset.
Implementation of WUIWidgetBase.
std::shared_ptr< WUIQtWidgetBase > SPtr
Convenience typedef for a std::shared_ptr< WUIQtWidgetBase >.
virtual void addAction(WPropGroup group, WGEImage::SPtr icon=WGEImage::SPtr())
Implement WUIWidgetBase::addAction.
Custom widget which is created by a module to display custom information.
Definition: WUIViewWidget.h:67