OpenWalnut  1.5.0dev
WQtNavGLWidget.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 <iostream>
26 #include <map>
27 #include <memory>
28 #include <string>
29 
30 #include <QApplication>
31 #include <QDockWidget>
32 #include <QKeyEvent>
33 #include <QVBoxLayout>
34 
35 #include "WQtNavGLWidget.h"
36 #include "core/graphicsEngine/WGECamera.h"
37 #include "core/graphicsEngine/WGEScene.h"
38 #include "core/graphicsEngine/WGEViewer.h"
39 #include "events/WEventTypes.h"
40 #include "events/WPropertyChangedEvent.h"
41 
42 WQtNavGLWidget::WQtNavGLWidget( QString viewTitle, QString dockTitle, QWidget* parent, std::string sliderTitle, const QWidget * shareWidget )
43  : WQtGLDockWidget( viewTitle, dockTitle, parent, WGECamera::TWO_D_UNIT, shareWidget )
44 {
45  propertyWidgetMap.clear();
46  m_sliderTitle = QString( sliderTitle.c_str() );
47 
48  setMinimumWidth( 200 );
49  setMaximumWidth( 300 );
50 
51  m_scene = new WGEScene();
52  m_scene->setDataVariance( osg::Object::DYNAMIC );
53  getGLWidget()->getViewer()->requestContinuousUpdate( false );
54  getGLWidget()->getViewer()->setScene( m_scene );
55 }
56 
58 {
59  for( std::map< std::shared_ptr< WPropertyBase >, WPropertyDoubleWidget* >::iterator it = propertyWidgetMap.begin();
60  it != propertyWidgetMap.end();
61  ++it )
62  {
63  if( it->second != 0 )
64  {
65  delete it->second;
66  }
67  }
68 }
69 
70 void WQtNavGLWidget::setSliderTitle( std::string title )
71 {
72  m_sliderTitle = QString( title.c_str() );
73 }
74 
75 void WQtNavGLWidget::setSliderProperty( std::shared_ptr< WPropertyBase > prop )
76 {
77  WPropertyDoubleWidget* propWidget;
78  propWidget = new WPropertyDoubleWidget( prop->toPropDouble(), NULL, parentWidget() );
79  propertyWidgetMap[prop] = propWidget;
80  m_layout->addWidget( propWidget );
81  m_layout->setStretchFactor( getGLWidget(), 1 );
82  m_layout->setStretchFactor( propWidget, 0 );
83 }
84 
85 void WQtNavGLWidget::removeSliderProperty( std::shared_ptr< WPropertyBase > prop )
86 {
87  WPropertyDoubleWidget* propWidget = propertyWidgetMap[prop];
88  m_layout->removeWidget( propWidget );
89  delete propWidget;
90  propertyWidgetMap.erase( prop );
91 }
92 
Class for wrapping around the OSG Camera class.
Definition: WGECamera.h:36
Class for managing the OpenSceneGraph root node.
Definition: WGEScene.h:36
Implements a property widget for WPropDouble.
Dock widget containing only a GLWidget.
WQtGLWidget * getGLWidget() const
Gets the contained GL widget instance.
QVBoxLayout * m_layout
Layout of this widget.
std::shared_ptr< WGEViewer > getViewer() const
Get the included viewer.
osg::ref_ptr< WGEGroupNode > m_scene
the scene which is displayed by the GL widget
WQtNavGLWidget(QString viewTitle, QString dockTitle, QWidget *parent, std::string sliderTitle="pos", const QWidget *shareWidget=0)
default constructor
void removeSliderProperty(std::shared_ptr< WPropertyBase > prop)
Remove the property to control by the slider.
void setSliderProperty(std::shared_ptr< WPropertyBase > prop)
Sets the property to control by the slider.
void setSliderTitle(std::string title)
Set the title of the slider used in this nav widget.
std::map< std::shared_ptr< WPropertyBase >, WPropertyDoubleWidget * > propertyWidgetMap
Map holding the widgets for module properties added automatically.
QString m_sliderTitle
The slider's title.
virtual ~WQtNavGLWidget()
destructor.