CEDRIC  Revision_backup-2009-02
MyCameraWidget.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Copyright (C) 2008 Boris Iven, Max Hermann
4  *
5  * This file is part of the "CEDRIC Event Display" application.
6  *
7  *****************************************************************************/
8 
9 #ifndef MYCAMERAWIDGET_H
10 #define MYCAMERAWIDGET_H
11 
12 #include "OsgWidget.h"
13 #include "MyCamera.h"
14 #include "ClipRect.h"
15 #include "PickingHandler.h"
16 #include <osg/Node>
17 #include <osgText/Text>
18 #include <osg/MatrixTransform>
19 #include <string>
20 class Selectable;
21 
28 {
29  Q_OBJECT
30 
31 public:
33  enum MouseMode { ROTATE,
36  };
37 
38  MyCameraWidget( QWidget* parent=0 );
39 
40  virtual ~MyCameraWidget() {}
41 
42  //~ /// Force a minimum size
43  //~ QSize minimumSizeHint() const { return QSize( 400, 400 ); }
44 
46  int getProjection() const { return m_myCamera->getProjection(); }
47 
49  int getMouseMode() const { return m_mouseMode; }
50 
53 
55  virtual void setSceneData( osg::Node* node );
56 
57 signals:
59  void positionChanged( float x, float y, float z );
60 
62  void focusChanged( bool );
63 
65  void doubleClicked( Selectable* selectable );
66 
67 public slots:
68  /* --> a more usefull home() function is implemented in EventViewerWidget!
70  void home()
71  {
72  getCameraManipulator()->home( 0.0 );
73  triggerRedraw();
74  }
75  */
76 
79  void setProjection( int proj ) { m_myCamera->setProjection( proj ); }
80 
82  void setMouseMode( int mode );
83 
84 protected slots:
86  void mouseOverNode( osg::Node* node );
87 
89  virtual void focusInEvent( QFocusEvent* /*event*/ )
90  {
91  //~ cout << "MyCameraWidget " << this << " received focus" << endl;
92  emit focusChanged( true );
93  }
94 
96  virtual void focusOutEvent( QFocusEvent* /*event*/ )
97  {
98  //~ cout << "MyCameraWidget " << this << " lost focus" << endl;
99  emit focusChanged( false );
100  }
101 
102  void myCameraChanged();
103 
104 protected:
106  virtual void paintGL();
107 
109  virtual void resizeGL( int width, int height );
110 
112  osg::Node* createHUD( osgText::Text* text );
113 
115  osg::Node* MyCameraWidget::createAxesView();
116 
118  virtual void mouseMoveEvent ( QMouseEvent* event );
120  virtual void mousePressEvent ( QMouseEvent* event );
121  virtual void mouseReleaseEvent( QMouseEvent* event );
122  virtual void mouseDoubleClickEvent( QMouseEvent* event );
123  virtual void wheelEvent ( QWheelEvent* event );
125 
126 //private:
129 
132 
133  osg::ref_ptr<osg::Node> m_hud;
134 
135  osg::ref_ptr<PickingHandler> m_pickingHandler;
136 
137  osg::ref_ptr<osg::MatrixTransform> m_axes;
138  osg::ref_ptr<osg::Node> m_axesView;
139 };
140 
141 #endif
Simple rectangle structure (e.g. usefull for saving ortho clipplanes)
Definition: ClipRect.h:28
osg::ref_ptr< osg::MatrixTransform > m_axes
Definition: MyCameraWidget.h:137
Definition: Selectable.h:15
virtual ~MyCameraWidget()
Definition: MyCameraWidget.h:40
virtual void mousePressEvent(QMouseEvent *event)
Definition: MyCameraWidget.cpp:148
Trackball rotation on left mouse button.
Definition: MyCameraWidget.h:33
Picking/Selection on left mouse button.
Definition: MyCameraWidget.h:35
virtual void mouseReleaseEvent(QMouseEvent *event)
Definition: MyCameraWidget.cpp:183
virtual void paintGL()
Override OsgViewerWidget::paintGL() for overpainting via OpenGL.
Definition: MyCameraWidget.cpp:226
void mouseOverNode(osg::Node *node)
Corresponding signal from PickingHandler is connected here.
Definition: MyCameraWidget.cpp:98
Qt Widget for osgViewer::Viewer.
Definition: OsgWidget.h:109
Manage modelview and projection, allows switching between ORTHOGRAPHIC and PERSPECTIVE projection...
Definition: MyCamera.h:44
osg::ref_ptr< osg::Node > m_hud
Definition: MyCameraWidget.h:133
MyCamera * m_myCamera
Definition: MyCameraWidget.h:127
void doubleClicked(Selectable *selectable)
Emitted when in SELECTION mode currently highlighted Selectable is double-clicked.
osg::ref_ptr< PickingHandler > m_pickingHandler
heads-up-display, should be an osg::Camera to make aspect ratio adjustion in resizeGL work ...
Definition: MyCameraWidget.h:135
osg::Node * createAxesView()
Helper function which creates a little 3d view in the lower left of fixed size showing the 3d coordin...
Definition: MyCameraWidget.cpp:331
virtual void wheelEvent(QWheelEvent *event)
Definition: MyCameraWidget.cpp:214
virtual void setSceneData(osg::Node *node)
Override to append own HUD.
Definition: MyCameraWidget.cpp:75
int getProjection() const
Get current Projection setting.
Definition: MyCamera.h:114
int getMouseMode() const
Get current mouse action mode.
Definition: MyCameraWidget.h:49
osg::ref_ptr< osg::Node > m_axesView
Definition: MyCameraWidget.h:138
void setMouseMode(int mode)
Set mouse action mode (see enum MouseMode for a list of supported action modes)
Definition: MyCameraWidget.cpp:103
Rubberband zoom on left mouse button.
Definition: MyCameraWidget.h:34
void setProjection(int proj)
Set either ORTHOGRAPHIC or PERSPECTIVE projection (default is PERSPECTIVE)
Definition: MyCamera.h:102
virtual void resizeGL(int width, int height)
Override OsgAdapterWidget::resizeGL() for changing HUD aspect ratio also.
Definition: MyCameraWidget.cpp:271
void focusChanged(bool)
On focusInEvent/focusOutEvent this signal is emitted respectively with true/false as parameter...
virtual void mouseDoubleClickEvent(QMouseEvent *event)
Definition: MyCameraWidget.cpp:130
osg::Node * createHUD(osgText::Text *text)
Helper function which creates a simple heads-up-display which is later used to show name of highlight...
Definition: MyCameraWidget.cpp:292
virtual void focusInEvent(QFocusEvent *)
Override QWidget::focusInEvent() to notice that we received focus.
Definition: MyCameraWidget.h:89
MouseMode
Different action modes for mouse.
Definition: MyCameraWidget.h:33
MyCameraWidget(QWidget *parent=0)
Definition: MyCameraWidget.cpp:31
Viewer based on MyCamera providing Trackball rotation, Rubberband zoom and Picking.
Definition: MyCameraWidget.h:27
void positionChanged(float x, float y, float z)
Unprojected mouse position.
virtual void focusOutEvent(QFocusEvent *)
Override QWidget::focusOutEvent() to notice that we lost focus.
Definition: MyCameraWidget.h:96
ClipRect m_rubberbandRect
Definition: MyCameraWidget.h:131
void myCameraChanged()
Definition: MyCameraWidget.cpp:92
virtual void mouseMoveEvent(QMouseEvent *event)
Override Qt mouse events to allow different mouse modes.
Definition: MyCameraWidget.cpp:114
int getProjection() const
Get projection setting of MyCamera member (see MyCamera::Projection for supported projections) ...
Definition: MyCameraWidget.h:46
bool m_rubberbandActive
Definition: MyCameraWidget.h:130
MyCamera * getMyCamera()
Access to MyCamera class (e.g. for switching between orthographic and perspective projection) ...
Definition: MyCameraWidget.h:52
int m_mouseMode
Definition: MyCameraWidget.h:128
void setProjection(int proj)
Definition: MyCameraWidget.h:79