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