Developer Documentation
TypeLight.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 
43 
44 
45 
46 
47 #ifndef TYPELIGHTPLUGIN_HH
48 #define TYPELIGHTPLUGIN_HH
49 
50 #include <QObject>
51 
62 
65 {
66  Q_OBJECT
67  Q_INTERFACES(BaseInterface)
68  Q_INTERFACES(LoadSaveInterface)
69  Q_INTERFACES(LoggingInterface)
70  Q_INTERFACES(TypeInterface)
71  Q_INTERFACES(MouseInterface)
72  Q_INTERFACES(ToolbarInterface)
73  Q_INTERFACES(PickingInterface)
74  Q_INTERFACES(PythonInterface)
75 
76  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-TypeLight")
77 
78  signals:
79  // Logging interface
80  void log(Logtype _type, QString _message);
81  void log(QString _message);
82 
83  // LoadSave Interface
84  void addEmptyObject(DataType _type, int& _id);
85  void emptyObjectAdded( int _id );
86  void deleteObject(int _id);
87 
88  // BaseInterface
89  void updatedObject(int _id, const UpdateType& _type);
90  void updateView();
91 
92  // ToolbarInterface
93  void getToolBar( QString _name, QToolBar*& _toolbar );
94 
95  // PickingInterface
96  void addPickMode(const std::string& _mode);
97  void addHiddenPickMode(const std::string& _mode);
98  void setPickModeMouseTracking (const std::string& _mode, bool _mouseTracking);
99  void setPickModeToolbar(const std::string& _mode, QToolBar * _toolbar);
100 
101  private slots:
102 
103  // BaseInterface
104  void noguiSupported( ) {};
105 
106  // PickingInterface
107  void slotPickModeChanged (const std::string& _pickMode);
108 
109  // Is called whenever the scene is cleared
110  void slotAllCleared();
111 
112  // Adds three default light sources to scene
113  void addDefaultLights();
114  // ... and removes them
115  void removeDefaultLights();
116 
117  // Load/Save Interface
118  void addedEmptyObject(int _id);
119  void objectDeleted(int _id);
120 
121  // MouseInterface
122  //void slotMouseEventLight( QMouseEvent* _event);
123  void slotMouseEventLight( QMouseEvent* _event );
124 
125  private:
126 
128  void rotateLights(ACG::Vec3d& _axis, double _angle);
129 
131  void rotateLightDirection(ACG::Vec3d& _axis, double _angle);
132 
134  void updateLights();
135 
140  bool computeClickOnTrackball(const QPoint& _v2D, ACG::Vec3d& _clickOnSphere, ACG::GLState& _state);
141 
146  bool computeClickOnLightTrackball(const QPoint& _v2D, ACG::Vec3d& _clickOnSphere, ACG::GLState& _state);
147 
148  public:
149 
150  ~TypeLightPlugin() {};
151  TypeLightPlugin();
152 
153  QString name() { return (QString("TypeLight")); };
154  QString description( ) { return (QString(tr("Register Light type"))); };
155 
156  bool registerType();
157 
158  public slots:
159 
160  // Base Interface
161  QString version() { return QString("1.0"); };
162 
163  // Type Interface
164  int addEmpty();
166 
167  void pluginsInitialized();
168 
169  // Add default light
170  int addDefaultLight(QString _name);
171 
172  void showReducedUi(bool reduced);
173 
174  private slots:
175 
176  void slotLightModeRequest(bool _checked);
177  void slotPickModeRequest(QAction* _action);
178 
179  void slotSetAllOrTarget(bool _checked);
180 
181  private:
182 
184  float findDepth();
185 
186  // Find distance of farthest light source from trackball center
187  double getFarthestRadius();
188 
190  void addAssistLines();
191 
193  std::vector<int> lightSources_;
194 
195  bool defaultLights_;
196 
197  // Matrix for rotating light position
198  ACG::GLMatrixd light_matrix_;
199 
200  // Toolbar for light mode
201  QToolBar* toolbar_;
202 
203  // Toolbar that show detailed options for light mode
204  QToolBar* lightOptions_;
205 
206  // GUI elements
207  QAction* lightAction_;
208 
209  QAction* moveMode_;
210  QAction* translateMode_;
211  QAction* rotateMode_;
212 
213  QAction* allLightsMode_;
214  QAction* viewerToolbarAction_;
215 
216  // True if only target lights should be transformed
217  bool onlyTargets_;
218 
219  // Mouse interactions
220  QPoint lastPoint2D_;
221  ACG::Vec3d lastPoint3D_;
222  //bool lastPoint_hitSphere_;
223  // depth of plane olong which objects are translated
224  // if middle mouse button is pressed
225  float planeDepth_;
226  ACG::Vec3d transVec_;
227  bool rotation_;
228 
229  // Radius of trackball for most distant light source
230  double radius_;
231 
232  // Depth of light source that is closest to camera
233  float depth_;
234 
235  // Picked light stuff
236  ACG::Vec3d lightCenter_;
237  double lightRadius_;
238  int lightId_;
239 
240  bool hitLightTrackball_;
241  bool hitTrackball_;
242 
243 };
244 
245 #endif //TYPELIGHTPLUGIN_HH
QString name()
Return a name for the plugin.
Definition: TypeLight.hh:153
Interface class for type definitions.
Interface class for exporting functions to python.
void addedEmptyObject(int _id)
An empty object has been added.
Definition: TypeLight.cc:392
Add a toolbox to OpenFlipper.
std::vector< int > lightSources_
Count light sources in scene.
Definition: TypeLight.hh:193
Interface class for receiving mouse events.
int addEmpty()
Create an empty object.
Definition: TypeLight.cc:368
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
Definition: TypeLight.hh:165
void slotMouseEventLight(QMouseEvent *_event)
Mouse Event from main application ( Light Mode )
Definition: TypeLight.cc:482
void objectDeleted(int _id)
An object was deleted.
Definition: TypeLight.cc:411
Logtype
Log types for Message Window.
Predefined datatypes.
Definition: DataTypes.hh:83
Interface for all Plugins which do logging to the logging window of the framework.
void rotateLights(ACG::Vec3d &_axis, double _angle)
Rotate light sources.
Definition: TypeLight.cc:729
void rotateLightDirection(ACG::Vec3d &_axis, double _angle)
Rotate spot light direction.
Definition: TypeLight.cc:738
void addAssistLines()
Get number of non-directional light sources.
bool computeClickOnTrackball(const QPoint &_v2D, ACG::Vec3d &_clickOnSphere, ACG::GLState &_state)
Compute click on trackball containing the light source.
Definition: TypeLight.cc:667
void updateLights()
Update light sources&#39; positions.
Definition: TypeLight.cc:766
void pluginsInitialized()
Initialize Plugin step 2.
Definition: TypeLight.cc:194
float findDepth()
Find depth of nearest light source.
Definition: TypeLight.cc:423
Update type class.
Definition: UpdateType.hh:60
QString description()
Return a description of what the plugin is doing.
Definition: TypeLight.hh:154
#define DATA_LIGHT
Definition: Light.hh:58
void slotPickModeChanged(const std::string &_pickMode)
The pickingMode has changed.
Definition: TypeLight.cc:294
void slotAllCleared()
Called if the whole scene is cleared.
Definition: TypeLight.cc:84
Interface class from which all plugins have to be created.
Allow access to picking functions.
Interface for all plugins which want to Load or Save files and create Objects.
bool computeClickOnLightTrackball(const QPoint &_v2D, ACG::Vec3d &_clickOnSphere, ACG::GLState &_state)
Compute click on trackball of light source.
Definition: TypeLight.cc:698