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