OpenWalnut  1.5.0dev
WUIQtViewWidget.cpp
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 #include <memory>
26 #include <string>
27 
28 #include <boost/uuid/uuid.hpp>
29 #include <boost/uuid/uuid_generators.hpp>
30 #include <boost/uuid/uuid_io.hpp>
31 
32 #include "../guiElements/WQtPropertyTriggerAction.h"
33 #include "WUIQtViewWidget.h"
34 #include "core/common/WConditionOneShot.h"
35 #include "core/common/WFlag.h"
36 
38  std::string title,
39  WGECamera::ProjectionMode projectionMode,
40  WMainWindow* mainWindow,
41  WUIQtWidgetBase::SPtr parent ):
42  WUIViewWidget( title ),
43  WUIQtWidgetBase( mainWindow, parent ),
44  m_projectionMode( projectionMode ),
45  m_widgetDock( NULL )
46 {
47  // initialize members
48 }
49 
51 {
52  // cleanup
53 }
54 
56 {
57  return QString::fromStdString( getTitle() );
58 }
59 
60 osg::ref_ptr< WGEGroupNode > WUIQtViewWidget::getScene() const
61 {
62  return m_scene;
63 }
64 
65 std::shared_ptr< WGEViewer > WUIQtViewWidget::getViewer() const
66 {
67  // should be safe to call from outside the GUI thread !?
68  return m_widgetDock->getGLWidget()->getViewer();
69 }
70 
72 {
74  {
75  // should be safe to call from outside the GUI thread !?
76  return static_cast< size_t >( m_widgetDock->getGLWidget()->getViewer()->getCamera()->getViewport()->height() );
77  }
78  else
79  {
80  return 0;
81  }
82 }
83 
84 size_t WUIQtViewWidget::width() const
85 {
87  {
88  // should be safe to call from outside the GUI thread !?
89  return static_cast< size_t >( m_widgetDock->getGLWidget()->getViewer()->getCamera()->getViewport()->width() );
90  }
91  else
92  {
93  return 0;
94  }
95 }
96 
97 void WUIQtViewWidget::addEventHandler( osgGA::GUIEventHandler* handler )
98 {
100  {
101  // should be safe to call from outside the GUI thread !?
102  m_widgetDock->getGLWidget()->getViewer()->getView()->addEventHandler( handler );
103  }
104 }
105 
107 {
109 }
110 
111 void WUIQtViewWidget::setVisible( bool visible )
112 {
113  WUIQtWidgetBase::setVisible( visible );
114 }
115 
117 {
119 }
120 
122 {
123  // nothing to do
124 }
125 
127 {
128  // use WUIViewWidget to handle this
130 }
131 
133 {
135 }
136 
138 {
139  // WGEViewers need to have unique names. Create a uuid for this new viewer
140  std::string uuid = boost::lexical_cast<std::string>( boost::uuids::random_generator()() );
141 
142  // this is called from withing the GUI thread -> we can safely create QT widgets here
143  m_widgetDock = new WQtGLDockWidget( QString::fromStdString( getTitle() + uuid ),
144  QString::fromStdString( getTitle() ), getCompellingQParent(), m_projectionMode );
145  m_widgetDock->setObjectName( QString( "Custom Dock Window " ) + QString::fromStdString( getTitle() ) );
146 
147  // custom widgets need to take care of this! Besides this, if this widget is nested, it will not restore no matter what you set here.
149 
150  // define some scene
151  m_scene = new WGEGroupNode();
152  m_scene->setDataVariance( osg::Object::DYNAMIC );
153  m_widgetDock->getGLWidget()->getViewer()->setScene( m_scene );
154 
155  // remove the close button for embedded views
156  if( getQtParent() )
157  {
159  }
160 
162 }
163 
165 {
167 }
168 
169 void WUIQtViewWidget::addCameraPreset( WPropTrigger preset, WGEImage::SPtr icon )
170 {
171  WQtGui::execInGUIThread( boost::bind( &WUIQtViewWidget::addCameraPresetGT, this, preset, icon ) );
172 }
173 
175 {
176  if( m_widgetDock )
177  {
178  m_widgetDock->getCameraPresetMenu()->clear();
180  }
181 }
182 
183 void WUIQtViewWidget::addCameraPresetGT( WPropTrigger preset, WGEImage::SPtr icon )
184 {
185  if( m_widgetDock )
186  {
188 
190  if( !icon )
191  {
192  propAction->setIcon( WQtGui::getMainWindow()->getIconManager()->getIcon( "configure" ) );
193  }
194  else
195  {
196  propAction->setIcon( WIconManager::convertToIcon( icon ) );
197  }
198  m->addAction( propAction );
200  }
201 }
ProjectionMode
List of possible camera modes.
Definition: WGECamera.h:44
Class to wrap around the osg Group node and providing a thread safe add/removal mechanism.
Definition: WGEGroupNode.h:48
std::shared_ptr< WGEImage > SPtr
Convenience typedef for a std::shared_ptr< WGEImage >.
Definition: WGEImage.h:48
static QIcon convertToIcon(WGEImage::SPtr image)
Convert a WGEImage to an QIcon.
This class contains the main window and the layout of the widgets within the window.
Definition: WMainWindow.h:66
void disableCloseButton(bool disable=true)
Disable close button? Might come in handy when embedding these widgets into others.
Dock widget containing only a GLWidget.
WQtGLWidget * getGLWidget() const
Gets the contained GL widget instance.
void setSaveViewerSettings(bool enable=true)
Allow turning the automatic save and restore of viewer-settings.
void updateCameraPresetButton()
Update camera button.
QMenu * getCameraPresetMenu() const
Get the menu used for camera presets.
std::shared_ptr< WGEViewer > getViewer() const
Get the included viewer.
static WMainWindow * getMainWindow()
Returns the current main window instance or NULL if not existent.
Definition: WQtGui.cpp:88
static void execInGUIThread(boost::function< void(void) > functor, WCondition::SPtr notify=WCondition::SPtr())
Call a given function from within the GUI thread.
Definition: WQtGui.cpp:409
Implements a property action for WPropTrigger.
virtual void setVisible(bool visible=true)
Hide/show this widget.
virtual void clearCameraPresets()
Remove any pre-existing camera preset.
virtual void close()
Handle shutdown.
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 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 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.
QWidget * getCompellingQParent() const
Returns the parent to use for your implementation in realizeImpl.
virtual void show()
Show this widget if not yet visible.
std::shared_ptr< WUIQtWidgetBase > SPtr
Convenience typedef for a std::shared_ptr< WUIQtWidgetBase >.
virtual void setVisible(bool visible=true)
Hide/show this widget.
virtual bool isVisible() const
Check if the widget is hidden or not.
virtual void closeImpl()
Close the widget.
QWidget * embedContent(QWidget *content)
This method can be used if you just create some QWidget and do not want to take care about embedding ...
WUIQtWidgetBase::SPtr getQtParent() const
Parent widget.
Custom widget which is created by a module to display custom information.
Definition: WUIViewWidget.h:67
void close()
Close the widget.
virtual std::string getTitle() const
Get the title of the widget.