Developer Documentation
FileLgt.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 #include "FileLgt.hh"
51 
52 #if QT_VERSION >= 0x050000
53  #include <QtWidgets>
54 #else
55  #include <QtGui>
56 #endif
57 
59 }
60 
62  return QString( tr("Light definition files ( *.lgt )") );
63 };
64 
66  return QString( tr("Light definition files ( *.lgt )") );
67 };
68 
70  DataType type = DATA_LIGHT;
71  return type;
72 }
73 
74 int FileLightPlugin::loadObject(QString _filename)
75 {
76  int id = -1;
77  emit addEmptyObject( DATA_LIGHT, id );
78 
79  LightObject* lightObject = 0;
80  if(PluginFunctions::getObject( id, lightObject))
81  {
82  if( lightObject )
83  {
84 
85  QFileInfo fi(_filename);
86 
87  if ( fi.exists() ){
88  LightSource* light = PluginFunctions::lightSource(lightObject);
89 
90  QString name = lightObject->name();
91 
92  QSettings settings(_filename, QSettings::IniFormat);
93  settings.beginGroup("LIGHT");
94 
95  if ( settings.contains("Name") ) {
96 
97  QString name = settings.value("Name").toString();
98 
99  lightObject->setName( name );
100  } else {
101  lightObject->setFromFileName(_filename);
102  }
103 
104  if (settings.contains("PositionX")) {
105  ACG::Vec3d position;
106  position[0] = settings.value("PositionX").toDouble();
107  position[1] = settings.value("PositionY").toDouble();
108  position[2] = settings.value("PositionZ").toDouble();
109 
110  light->position(position);
111  }
112 
113  if (settings.contains("DirectionX")) {
114  ACG::Vec3d direction;
115  direction[0] = settings.value("DirectionX").toDouble();
116  direction[1] = settings.value("DirectionY").toDouble();
117  direction[2] = settings.value("DirectionZ").toDouble();
118 
119  light->direction(direction);
120  }
121 
122  if (settings.contains("SpotDirectionX")) {
123  ACG::Vec3d spotDirection;
124  spotDirection[0] = settings.value("SpotDirectionX").toDouble();
125  spotDirection[1] = settings.value("SpotDirectionY").toDouble();
126  spotDirection[2] = settings.value("SpotDirectionZ").toDouble();
127 
128  light->spotDirection(spotDirection);
129  }
130 
131  if (settings.contains("AmbientColorR")) {
132  ACG::Vec4f ambientColor;
133  ambientColor[0] = settings.value("AmbientColorR").toDouble();
134  ambientColor[1] = settings.value("AmbientColorG").toDouble();
135  ambientColor[2] = settings.value("AmbientColorB").toDouble();
136  if (settings.contains("AmbientColorA"))
137  ambientColor[3] = settings.value("AmbientColorA").toDouble();
138  else
139  ambientColor[3] = 1.0f;
140 
141  light->ambientColor(ambientColor);
142  }
143 
144  if (settings.contains("DiffuseColorR")) {
145  ACG::Vec4f diffuseColor;
146  diffuseColor[0] = settings.value("DiffuseColorR").toDouble();
147  diffuseColor[1] = settings.value("DiffuseColorG").toDouble();
148  diffuseColor[2] = settings.value("DiffuseColorB").toDouble();
149  if (settings.contains("DiffuseColorA"))
150  diffuseColor[3] = settings.value("DiffuseColorA").toDouble();
151  else
152  diffuseColor[3] = 1.0f;
153 
154  light->diffuseColor(diffuseColor);
155  }
156 
157  if (settings.contains("SpecularColorR")) {
158  ACG::Vec4f specularColor;
159  specularColor[0] = settings.value("SpecularColorR").toDouble();
160  specularColor[1] = settings.value("SpecularColorG").toDouble();
161  specularColor[2] = settings.value("SpecularColorB").toDouble();
162  if (settings.contains("SpecularColorA"))
163  specularColor[3] = settings.value("SpecularColorA").toDouble();
164  else
165  specularColor[3] = 1.0f;
166 
167  light->specularColor(specularColor);
168  }
169 
170  if (settings.contains("FixedPosition")) {
171 
172  bool fixedPosition = settings.value("FixedPosition").toBool();
173 
174  light->fixedPosition(fixedPosition);
175  }
176 
177  if (settings.contains("SpotExponent")) {
178 
179  float spotExponent = settings.value("SpotExponent").toDouble();
180 
181  light->spotExponent(spotExponent);
182  }
183 
184  if (settings.contains("SpotCutOff")) {
185 
186  float spotCutOff = settings.value("SpotCutOff").toDouble();
187 
188  light->spotCutoff(spotCutOff);
189  }
190 
191  if (settings.contains("ConstantAttenuation")) {
192 
193  float cAttenuation = settings.value("ConstantAttenuation").toDouble();
194 
195  light->constantAttenuation(cAttenuation);
196  }
197 
198  if (settings.contains("LinearAttenuation")) {
199 
200  float lAttenuation = settings.value("LinearAttenuation").toDouble();
201 
202  light->linearAttenuation(lAttenuation);
203  }
204 
205  if (settings.contains("QuadraticAttenuation")) {
206 
207  float qAttenuation = settings.value("QuadraticAttenuation").toDouble();
208 
209  light->quadraticAttenuation(qAttenuation);
210  }
211 
212  if (settings.contains("Radius")) {
213 
214  float radius = settings.value("Radius").toDouble();
215 
216  light->radius(radius);
217  }
218 
219  if (settings.contains("Enabled")) {
220 
221  bool enabled = settings.value("Enabled").toBool();
222 
223  enabled ? light->enable() : light->disable();
224  }
225 
226  settings.endGroup();
227  }
228 
229  emit updatedObject( lightObject->id(), UPDATE_ALL );
230  emit openedFile( lightObject->id() );
231 
232  }
233 
234  }
235 
236  return id;
237 };
238 
239 bool FileLightPlugin::saveObject(int _id, QString _filename)
240 {
241 
242  BaseObjectData* obj(0);
243  if(PluginFunctions::getObject( _id, obj))
244  {
245  LightObject* lightObject = PluginFunctions::lightObject(obj);
246  if( lightObject )
247  {
248  LightSource* light = PluginFunctions::lightSource(lightObject);
249 
250  QSettings settings(_filename, QSettings::IniFormat);
251  settings.beginGroup("LIGHT");
252 
253  settings.setValue("Name",lightObject->name());
254 
255  if(!light->directional()) {
256  settings.setValue("PositionX", light->position()[0]);
257  settings.setValue("PositionY", light->position()[1]);
258  settings.setValue("PositionZ", light->position()[2]);
259  } else {
260  settings.setValue("DirectionX", light->direction()[0]);
261  settings.setValue("DirectionY", light->direction()[1]);
262  settings.setValue("DirectionZ", light->direction()[2]);
263  }
264 
265  settings.setValue("SpotDirectionX", light->spotDirection()[0]);
266  settings.setValue("SpotDirectionY", light->spotDirection()[1]);
267  settings.setValue("SpotDirectionZ", light->spotDirection()[2]);
268 
269  settings.setValue("AmbientColorR", light->ambientColor()[0]);
270  settings.setValue("AmbientColorG", light->ambientColor()[1]);
271  settings.setValue("AmbientColorB", light->ambientColor()[2]);
272  settings.setValue("AmbientColorA", light->ambientColor()[3]);
273 
274  settings.setValue("DiffuseColorR", light->diffuseColor()[0]);
275  settings.setValue("DiffuseColorG", light->diffuseColor()[1]);
276  settings.setValue("DiffuseColorB", light->diffuseColor()[2]);
277  settings.setValue("DiffuseColorA", light->diffuseColor()[3]);
278 
279  settings.setValue("SpecularColorR", light->specularColor()[0]);
280  settings.setValue("SpecularColorG", light->specularColor()[1]);
281  settings.setValue("SpecularColorB", light->specularColor()[2]);
282  settings.setValue("SpecularColorA", light->specularColor()[3]);
283 
284  settings.setValue("FixedPosition", light->fixedPosition());
285 
286  settings.setValue("SpotExponent", light->spotExponent());
287 
288  settings.setValue("SpotCutOff", light->spotCutoff());
289 
290  settings.setValue("ConstantAttenuation", light->constantAttenuation());
291 
292  settings.setValue("LinearAttenuation", light->linearAttenuation());
293 
294  settings.setValue("QuadraticAttenuation", light->quadraticAttenuation());
295 
296  settings.setValue("Radius", light->radius());
297 
298  settings.setValue("Enabled", light->enabled());
299 
300  settings.endGroup();
301 
302  obj->setFromFileName(_filename);
303  obj->setName(obj->filename());
304  }
305  }
306 
307  return true;
308 }
309 #if QT_VERSION < 0x050000
310  Q_EXPORT_PLUGIN2( filelightplugin , FileLightPlugin );
311 #endif
312 
313 
void ambientColor(Vec4f _color)
set Ambient color for LightSource
Definition: LightNode.cc:154
LightObject * lightObject(BaseObjectData *_object)
Cast an BaseObject to a LightObject if possible.
void fixedPosition(bool _state)
make LightSource fixed or moveable with ModelViewMatrix
Definition: LightNode.cc:178
Predefined datatypes.
Definition: DataTypes.hh:96
void enable()
enable LightSource
Definition: LightNode.cc:137
void spotDirection(Vec3d _pos)
Set spot direction.
Definition: LightNode.cc:147
float radius() const
Get light source radius.
Definition: LightNode.hh:212
QString getLoadFilters()
Definition: FileLgt.cc:61
QString filename() const
return the filename of the object
Definition: BaseObject.cc:717
bool getObject(int _identifier, BSplineCurveObject *&_object)
void setName(QString _name)
Set the name of the Object.
Definition: LightObject.cc:215
int id() const
Definition: BaseObject.cc:201
void setFromFileName(const QString &_filename)
Definition: BaseObject.cc:727
void specularColor(Vec4f _color)
set Specular color for LightSource
Definition: LightNode.cc:166
LightSource * lightSource(BaseObjectData *_object)
Get the lightSource in this Object.
#define DATA_LIGHT
Definition: Light.hh:64
void disable()
disable LightSource
Definition: LightNode.cc:140
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
void diffuseColor(Vec4f _color)
set Diffuse color for LightSource
Definition: LightNode.cc:160
bool directional() const
Check if the light source is a directional light source.
Definition: LightNode.cc:133
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
Definition: FileLgt.cc:69
QString name()
Return a name for the plugin.
Definition: FileLgt.hh:96
QString getSaveFilters()
Definition: FileLgt.cc:65
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:741
void position(Vec3d _pos)
Set position for LightSource.
Definition: LightNode.cc:114
Vec3d direction() const
Get direction of the light source.
Definition: LightNode.cc:129
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
void initializePlugin()
Initialize Plugin.
Definition: FileLgt.cc:58
bool enabled() const
Get light source status.
Definition: LightNode.cc:143
Structure to hold options for one LightSource.
Definition: LightNode.hh:91