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
45
46
47 //=============================================================================
48 //
49 // CLASS SimpleViewer - IMPLEMENTATION
50 //
51 //=============================================================================
52
53 //== INCLUDES =================================================================
54
55 #include <OpenFlipper/common/GlobalOptions.hh>
56 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
57 #include <OpenFlipper/widgets/glWidget/QtBaseViewer.hh>
58 #include <ACG/Scenegraph/SceneGraphAnalysis.hh>
59 #include "simpleGLGraphicsScene.hh"
60
61
62 #include "simpleViewer.hh"
63
64 #include <QOpenGLWidget>
65
66
67 //== NAMESPACES ===============================================================
68
69
70 //== CLASS DEFINITION =========================================================
71
72
73 SimpleViewer::SimpleViewer(QWidget* _parent, bool useDefaultSceneGraph) :
74 QGraphicsView (_parent),
75 props_(-1),
76 actionMode_ (Viewer::ExamineMode)
77 {
78 OFGLWidget *share = PluginFunctions::shareGLWidget ();
79 if (!share)
80 initialize (OFGLFormat::defaultFormat (), 0, useDefaultSceneGraph);
81 else
82 initialize (share->format(), share, useDefaultSceneGraph);
83 }
84
85 SimpleViewer::~SimpleViewer()
86 {
87 }
88
89 void SimpleViewer::resizeEvent(QResizeEvent *_event) {
90 QGraphicsView::resizeEvent(_event);
91 if (scene())
92 {
93 scene()->setSceneRect(QRect(QPoint(0, 0), _event->size()));
94 mainWidget_->setGeometry (QRect(QPoint(0, 0), _event->size()));
95 }
96
97 }
98
99
100 //=============================================================================
101 //=============================================================================
102
103 void SimpleViewer::initialize(const OFGLFormat & _format, OFGLWidget *_shareWidget, bool useDefaultSceneGraph)
104 {
105
106 connect (&props_, SIGNAL( getPickMode(std::string&) ),
107 this, SLOT( getPickMode(std::string&) ),Qt::DirectConnection );
108 connect (&props_, SIGNAL( getActionMode(Viewer::ActionMode&) ),
109 this, SLOT( getActionMode(Viewer::ActionMode&) ),Qt::DirectConnection );
110 connect (&props_, SIGNAL( setActionMode(const Viewer::ActionMode) ),
111 this, SLOT( setActionMode(const Viewer::ActionMode)), Qt::DirectConnection );
112
113 glWidget_ = new OFGLWidget();
114 glWidget_->setFormat(_format);
115
116 setFocusPolicy (Qt::StrongFocus);
117 setAcceptDrops (true);
118 setViewport(glWidget_);
119 setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
120
121 scene_ = new SimpleGLGraphicsScene ();
122
123 setScene (scene_);
124
125 mainWidget_ = new glViewer (scene_, glWidget_, props_);
126
127 scene_->addItem (mainWidget_);
128 scene_->setView (mainWidget_);
129 mainWidget_->setGeometry (QRect(QPoint(0, 0), size()));
130 setFrameStyle(QFrame::NoFrame);
131
132 if (useDefaultSceneGraph)
133 setSceneGraph(PluginFunctions::getSceneGraphRootNode());
134
135 props_.drawMode (OpenFlipper::Options::defaultDrawMode(0));
136 }
137
138 void SimpleViewer::setSceneGraph(ACG::SceneGraph::BaseNode *rootNode) {
139 unsigned int maxPases = 1;
140 ACG::Vec3d bbmin,bbmax;
141 ACG::SceneGraph::analyzeSceneGraph(rootNode, maxPases, bbmin, bbmax);
142
143 mainWidget_->sceneGraph(rootNode, maxPases, bbmin, bbmax, true);
144 }
145
146 void SimpleViewer::setActionMode(const Viewer::ActionMode _am)
147 {
148 actionMode_ = _am;
149 }
150
151 void SimpleViewer::getActionMode(Viewer::ActionMode & _am)
152 {
153 _am = actionMode_;
154 }
155
156 void SimpleViewer::getPickMode(std::string & _name)
157 {
158 _name = "SimpleViewer";
159 }
160
161 Viewer::ViewerProperties & SimpleViewer::properties()
162 {
163 return props_;
164 }
165
166 glViewer * SimpleViewer::viewer()
167 {
168 return mainWidget_;
169 }
170
PluginFunctions::shareGLWidget
void shareGLWidget(OFGLWidget *_widget)
Sets the main QGLWidget for gl data sharing.
Definition: PluginFunctions.cc:597
Viewer::ViewerProperties
Definition: ViewerProperties.hh:107
SimpleViewer::viewer
glViewer * viewer()
Viewer.
Definition: simpleViewer.cc:166
SimpleViewer::SimpleViewer
SimpleViewer(QWidget *_parent=NULL, bool useDefaultSceneGraph=true)
Constructor.
Definition: simpleViewer.cc:73
Viewer::ActionMode
ActionMode
Enum listing action modes of the viewers.
Definition: ViewerProperties.hh:75
GlobalOptions.hh
PluginFunctions::getSceneGraphRootNode
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node
Definition: PluginFunctions.cc:959
Viewer::ViewerProperties::drawMode
void drawMode(ACG::SceneGraph::DrawModes::DrawMode _mode)
set draw mode (No test if this mode is available!)
Definition: ViewerProperties.cc:151
SimpleViewer::~SimpleViewer
~SimpleViewer()
Destructor.
Definition: simpleViewer.cc:85
SimpleGLGraphicsScene
Definition: simpleGLGraphicsScene.hh:77
OpenMesh::VectorT
Definition: Vector11T.hh:83
PluginFunctions.hh
ACG::SceneGraph::analyzeSceneGraph
void analyzeSceneGraph(ACG::SceneGraph::BaseNode *_root, unsigned int &_maxPasses, ACG::Vec3d &_bbmin, ACG::Vec3d &_bbmax)
Analyze the SceneGraph <ACG/Scenegraph/SceneGraphAnalysis.hh>
Definition: SceneGraphAnalysis.cc:56
SceneGraphAnalysis.hh
ACG::SceneGraph::BaseNode
Definition: BaseNode.hh:104
glViewer
Definition: QtBaseViewer.hh:126
SimpleViewer::properties
Viewer::ViewerProperties & properties()
Viewer properties.
Definition: simpleViewer.cc:161
Viewer
Definition: ViewerProperties.cc:51
glViewer::sceneGraph
void sceneGraph(ACG::SceneGraph::BaseNode *_root, unsigned int _maxPasses, ACG::Vec3d _bbmin, ACG::Vec3d _bbmax, const bool _resetTrackBall=false)
Definition: QtBaseViewer.cc:248