Developer Documentation

ViewControlPlugin.hh
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 #pragma once
43
44 #include <QObject>
45 #include <QMenuBar>
46 #include <QGroupBox>
47 #include <QCheckBox>
48
49 #include <OpenFlipper/BasePlugin/BaseInterface.hh>
50 #include <OpenFlipper/BasePlugin/LoggingInterface.hh>
51 #include <OpenFlipper/BasePlugin/PickingInterface.hh>
52 #include <OpenFlipper/BasePlugin/PythonInterface.hh>
53 #include <OpenFlipper/BasePlugin/ToolbarInterface.hh>
54 #include <OpenFlipper/BasePlugin/ContextMenuInterface.hh>
55 #include <OpenFlipper/common/Types.hh>
56 #include <ObjectTypes/PolyMesh/PolyMesh.hh>
57 #include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
58 #include "shaderWidget.hh"
59
60 struct ShaderInfo {
61 QString name;
62 QString description;
63 QString details;
64 QString version;
65 QString example;
66
67 QString directory;
68
69 QString vertexShader;
70 QString fragmentShader;
71
72 QString pickVertexShader;
73 QString pickFragmentShader;
74
75 bool hasUniforms;
76 QStringList uniforms;
77 QStringList uniformTypes;
78 QStringList uniformsDefault;
79 QStringList uniformsMax;
80 QStringList uniformsMin;
81 };
82
83 class ViewControlPlugin : public QObject, BaseInterface , PickingInterface, LoggingInterface, ToolbarInterface, ContextMenuInterface, PythonInterface
84 {
85 Q_OBJECT
86 Q_INTERFACES(BaseInterface)
87 Q_INTERFACES(PickingInterface)
88 Q_INTERFACES(LoggingInterface)
89 Q_INTERFACES(ToolbarInterface)
90 Q_INTERFACES(ContextMenuInterface)
91 Q_INTERFACES(PythonInterface)
92
93 Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-ViewControl")
94
95 signals:
96 //BaseInterface
97 void updateView();
98
99 //PickingInterface
100 void addHiddenPickMode( const std::string& _mode );
101
102 //LoggingInterface
103 void log(Logtype _type, QString _message);
104 void log(QString _message);
105
106 //ToolbarInterface
107 void addToolbar(QToolBar* _toolbar);
108 void getToolBar(QString _name, QToolBar*& _toolbar);
109
110 // ContextMenuInterface
111 void addContextMenuItem(QAction* _action , ContextMenuType _type);
112 void addContextMenuItem(QAction* _action , DataType _objectType , ContextMenuType _type );
113 void hideContextMenu();
114
115 void setSlotDescription(QString _slotName, QString _slotDescription,
116 QStringList _parameters, QStringList _descriptions);
117
118 private slots:
119
120 void pluginsInitialized();
121
122 void contextMenuTriggered(QAction* _action);
123
124 void slotUpdateContextMenu( int _objectId );
125
126 public :
127
128 ViewControlPlugin();
129 ~ViewControlPlugin() {};
130
131
132 QString name() { return (QString("ViewControl")); };
133 QString description( ) { return (QString("Control the current or global visualization settings")); };
134
135
136 private:
137 QMenu* viewControlMenu_;
138
141 int lastObjectId_;
142
145 ACG::SceneGraph::DrawModes::DrawMode activeDrawModes_;
146
149 ACG::SceneGraph::DrawModes::DrawMode availDrawModes_;
150
151 ShaderWidget* shaderWidget_;
152
155 std::vector <ShaderInfo> shaderList_;
156
157 QToolBar* toolbar_;
158 QActionGroup* toolbarViewingDirections_;
159 QAction* viewTop_;
160 QAction* viewBottom_;
161 QAction* viewLeft_;
162 QAction* viewRight_;
163 QAction* viewFront_;
164 QAction* viewBack_;
165
166 std::map<QCheckBox*, ACG::SceneGraph::DrawModes::DrawMode> activeCheckboxes;
167
168 private slots:
169 QString version() { return QString("1.0"); };
170
171 // This slot is called when a custom draw mode is selected from the context menu
172 void slotDrawModeSelected( QAction * _action );
173
174 // This slot is called when the user clicks on an item in the shaderWidget
175 void slotShaderClicked( QListWidgetItem * _item );
176
177 // This slot is called when the user doubleclicks on an item in the shaderWidget
178 void slotShaderDoubleClicked( QListWidgetItem * _item );
179
180 // slot for setting a shader from the widget
181 void slotSetShader();
182
183 // slot is called when the data of the uniforms-table changes
184 void itemChanged(QTableWidgetItem* item);
185
186 // Set the view to one of the six possible look-at directions
187 void setView(int _mode, int _viewer = PluginFunctions::ACTIVE_VIEWER );
188
189 // Set the view mode using the defined actions
190 void setView(QAction* _action);
191
192 private:
193 // Update the list of available shaders
194 void updateShaderList();
195
196 // initialize the shader Widget
197 void initShaderWidget();
198
199 // Announce local slots
200 void setDescriptions();
201
208 bool areasVisible( StatusBits _bits, int _id );
209
216 void showAreas( StatusBits _bits, int _id , bool _state );
217
218
219 public slots:
221 bool selectionVisible( int _id );
222
224 void showSelection( int _id , bool _state );
225
227 bool modelingAreasVisible( int _id );
228
230 void showModelingAreas( int _id , bool _state );
231
239 void disableShader(int _objectId, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ShaderInfo* _shader=0);
240
246 void setShader(int _id, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ShaderInfo _shader);
247
258 void setShader(int _id, QString _drawMode, QString _name );
259
261 QStringList getUniforms(QString _shader);
262
263 QString getUniformType(QString _shader, QString _uniform );
264 QString getUniformDefault(QString _shader, QString _uniform );
265 QString getUniformMin(QString _shader, QString _uniform );
266 QString getUniformMax(QString _shader, QString _uniform );
267
269 void setUniform(int _objID, ACG::SceneGraph::DrawModes::DrawMode _drawMode, QString _shader, QString _uniform, QString _value );
270
271
273 void setViewingDirection( Vector _direction, Vector _upvector , int _viewer = PluginFunctions::ALL_VIEWERS );
274
276 void setSceneRadius( double _radius , int _viewer = PluginFunctions::ALL_VIEWERS );
277
279 void rotate( Vector _axis, double _angle, Vector _center , int _viewer = PluginFunctions::ALL_VIEWERS );
280
282 void translate( Vector _vec , int _viewer = PluginFunctions::ALL_VIEWERS );
283
285 void setDrawMode(QString _mode, int _viewer = PluginFunctions::ALL_VIEWERS );
286
295 void setObjectDrawMode(QString _mode, int _objectID , bool _force = true );
296
298 Vector viewingDirection( int _viewer = PluginFunctions::ACTIVE_VIEWER );
299
301 Vector upVector( int _viewer = PluginFunctions::ACTIVE_VIEWER );
302
304 Vector eyePosition( int _viewer = PluginFunctions::ACTIVE_VIEWER );
305
307 Vector sceneCenter( int _viewer = PluginFunctions::ACTIVE_VIEWER );
308
310 void setSceneCenter( Vector _center, int _viewer = PluginFunctions::ALL_VIEWERS );
311
313 void enableBackfaceCulling( bool _state , int _viewer = PluginFunctions::ALL_VIEWERS );
314
315
316 void setEyePosition(Vector _eye);
317
319 void viewAll();
320
322 void viewAll(int _viewer);
323
325 void viewHome();
326
328 void viewHome(int _viewer);
329
330
331
333 void orthographicProjection();
334
336 void orthographicProjection(int _viewer);
337
338
339
341 void perspectiveProjection();
342
344 void perspectiveProjection(int _viewer);
345
347 void setFOVY( double _fovy );
348
351 void setCoordsysProjection(bool _orthogonal);
352
353 void setTwoSidedLighting(bool _enabled);
354
356 ACG::Vec3d project(ACG::Vec3d _point, int _viewerId = 0);
357
358 };
359
360
ShaderInfo
Definition: ViewControlPlugin.hh:60
PythonInterface
Interface class for exporting functions to python.
Definition: PythonInterface.hh:58
ToolbarInterface
Add a toolbox to OpenFlipper.
Definition: ToolbarInterface.hh:62
Logtype
Logtype
Log types for Message Window.
Definition: LoggingInterface.hh:92
OpenMesh::VectorT
Definition: Vector11T.hh:83
ViewControlPlugin::activeDrawModes_
ACG::SceneGraph::DrawModes::DrawMode activeDrawModes_
Definition: ViewControlPlugin.hh:145
DataType
Predefined datatypes.
Definition: DataTypes.hh:83
PickingInterface.hh
LoggingInterface
Interface for all Plugins which do logging to the logging window of the framework.
Definition: LoggingInterface.hh:112
LoggingInterface.hh
ToolbarInterface.hh
TriangleMesh.hh
ViewControlPlugin::shaderList_
std::vector< ShaderInfo > shaderList_
Definition: ViewControlPlugin.hh:155
ContextMenuType
ContextMenuType
Definition: ContextMenuInterface.hh:56
ViewControlPlugin::description
QString description()
Return a description of what the plugin is doing.
Definition: ViewControlPlugin.hh:133
ShaderWidget
Definition: shaderWidget.hh:48
PolyMesh.hh
ViewControlPlugin
Definition: ViewControlPlugin.hh:83
ViewControlPlugin::availDrawModes_
ACG::SceneGraph::DrawModes::DrawMode availDrawModes_
Definition: ViewControlPlugin.hh:149
ACG::SceneGraph::DrawModes::DrawMode
Specifies a DrawMode.
Definition: DrawModes.hh:288
ViewControlPlugin::name
QString name()
Return a name for the plugin.
Definition: ViewControlPlugin.hh:132
Types.hh
ViewControlPlugin::lastObjectId_
int lastObjectId_
Definition: ViewControlPlugin.hh:141
ContextMenuInterface.hh
ContextMenuInterface
Interface class for creating custom context menus.
Definition: ContextMenuInterface.hh:85
BaseInterface
Interface class from which all plugins have to be created.
Definition: BaseInterface.hh:65
BaseInterface.hh
PickingInterface
Allow access to picking functions.
Definition: PickingInterface.hh:62
PythonInterface.hh