Developer Documentation
simpleViewer.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 //=============================================================================
54 //
55 // CLASS SimpleViewer - IMPLEMENTATION
56 //
57 //=============================================================================
58 
59 //== INCLUDES =================================================================
60 
63 #include <OpenFlipper/widgets/glWidget/QtBaseViewer.hh>
65 #include "simpleGLGraphicsScene.hh"
66 
67 
68 #include "simpleViewer.hh"
69 
70 //== NAMESPACES ===============================================================
71 
72 
73 //== CLASS DEFINITION =========================================================
74 
75 
76 SimpleViewer::SimpleViewer(QWidget* _parent, bool useDefaultSceneGraph) :
77  QGraphicsView (_parent),
78  props_(-1),
79  actionMode_ (Viewer::ExamineMode)
80 {
81  QGLWidget *share = PluginFunctions::shareGLWidget ();
82  if (!share)
83  initialize (QGLFormat::defaultFormat (), 0, useDefaultSceneGraph);
84  else
85  initialize (share->format(), share, useDefaultSceneGraph);
86 }
87 
89 {
90 }
91 
92 void SimpleViewer::resizeEvent(QResizeEvent *_event) {
93  QGraphicsView::resizeEvent(_event);
94  if (scene())
95  {
96  scene()->setSceneRect(QRect(QPoint(0, 0), _event->size()));
97  mainWidget_->setGeometry (QRect(QPoint(0, 0), _event->size()));
98  }
99 
100 }
101 
102 
103 //=============================================================================
104 //=============================================================================
105 
106 void SimpleViewer::initialize (const QGLFormat & _format, QGLWidget *_shareWidget, bool useDefaultSceneGraph)
107 {
108 
109  connect (&props_, SIGNAL( getPickMode(std::string&) ),
110  this, SLOT( getPickMode(std::string&) ),Qt::DirectConnection );
111  connect (&props_, SIGNAL( getActionMode(Viewer::ActionMode&) ),
112  this, SLOT( getActionMode(Viewer::ActionMode&) ),Qt::DirectConnection );
113  connect (&props_, SIGNAL( setActionMode(const Viewer::ActionMode) ),
114  this, SLOT( setActionMode(const Viewer::ActionMode)), Qt::DirectConnection );
115 
116  glWidget_ = new QGLWidget (_format, 0, _shareWidget);
117 
118  setFocusPolicy (Qt::StrongFocus);
119  setAcceptDrops (true);
120  setViewport(glWidget_);
121  setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
122 
123  scene_ = new SimpleGLGraphicsScene ();
124 
125  setScene (scene_);
126 
127  mainWidget_ = new glViewer (scene_, glWidget_, props_);
128 
129  scene_->addItem (mainWidget_);
130  scene_->setView (mainWidget_);
131  mainWidget_->setGeometry (QRect(QPoint(0, 0), size()));
132  setFrameStyle(QFrame::NoFrame);
133 
134  if (useDefaultSceneGraph)
136 
137  props_.drawMode (OpenFlipper::Options::defaultDrawMode(0));
138 }
139 
140 void SimpleViewer::setSceneGraph(ACG::SceneGraph::BaseNode *rootNode) {
141  unsigned int maxPases = 1;
142  ACG::Vec3d bbmin,bbmax;
143  ACG::SceneGraph::analyzeSceneGraph(rootNode, maxPases, bbmin, bbmax);
144 
145  mainWidget_->sceneGraph(rootNode, maxPases, bbmin, bbmax, true);
146 }
147 
148 void SimpleViewer::setActionMode(const Viewer::ActionMode _am)
149 {
150  actionMode_ = _am;
151 }
152 
153 void SimpleViewer::getActionMode(Viewer::ActionMode & _am)
154 {
155  _am = actionMode_;
156 }
157 
158 void SimpleViewer::getPickMode(std::string & _name)
159 {
160  _name = "SimpleViewer";
161 }
162 
164 {
165  return props_;
166 }
167 
169 {
170  return mainWidget_;
171 }
172 
void sceneGraph(ACG::SceneGraph::BaseNode *_root, unsigned int _maxPasses, ACG::Vec3d _bbmin, ACG::Vec3d _bbmax, const bool _resetTrackBall=false)
Viewer::ViewerProperties & properties()
Viewer properties.
~SimpleViewer()
Destructor.
Definition: simpleViewer.cc:88
void shareGLWidget(QGLWidget *_widget)
Sets the main QGLWidget for gl data sharing.
SimpleViewer(QWidget *_parent=NULL, bool useDefaultSceneGraph=true)
Constructor.
Definition: simpleViewer.cc:76
void analyzeSceneGraph(ACG::SceneGraph::BaseNode *_root, unsigned int &_maxPasses, ACG::Vec3d &_bbmin, ACG::Vec3d &_bbmax)
Analyze the SceneGraph <ACG/Scenegraph/SceneGraphAnalysis.hh>
ActionMode
Enum listing action modes of the viewers.
void drawMode(ACG::SceneGraph::DrawModes::DrawMode _mode)
set draw mode (No test if this mode is available!)
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node
glViewer * viewer()
Viewer.