Developer Documentation
iniPlugin.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 // Includes
45 #include "iniPlugin.hh"
46 
50 
53 }
54 
55 
56 template <>
57 void INIPlugin::parseIniFileT(INIFile& _ini, LightObject* _object) {
58 
59  if ( _object ) {
60 
61  std::vector< QString > draw_modes;
62  if( _ini.get_entry(draw_modes, _object->name(), "MaterialDrawMode") )
63  _object->materialNode()->drawMode( listToDrawMode(draw_modes) );
64 
65  }
66 }
67 
68 
69 template <>
70 void INIPlugin::saveIniFileT(INIFile& _ini, LightObject* _object) {
71 
72  if ( _object ) {
73 
74  _ini.add_entry( _object->name() ,
75  "MaterialDrawMode" ,
76  drawModeToList( _object->materialNode()->drawMode()) );
77 
78  }
79 }
80 
81 void INIPlugin::parseIniFile(INIFile& _ini, BaseObjectData* _object) {
82 
83  if ( _object ) {
84  std::vector< QString > draw_modes;
85  if( _ini.get_entry(draw_modes, _object->name(), "MaterialDrawMode") )
86  _object->materialNode()->drawMode( listToDrawMode(draw_modes) );
87 
88  ACG::Vec4f col(0.0,0.0,0.0,0.0);
89 
90  if ( _ini.get_entryVecf( col, _object->name() , "BaseColor" ) )
91  _object->materialNode()->set_base_color(col);
92 
93  if ( _ini.get_entryVecf( col, _object->name() , "AmbientColor" ) )
94  _object->materialNode()->set_ambient_color(col);
95 
96  if ( _ini.get_entryVecf( col, _object->name() , "DiffuseColor" ) )
97  _object->materialNode()->set_diffuse_color(col);
98 
99  if ( _ini.get_entryVecf( col, _object->name() , "SpecularColor" ) )
100  _object->materialNode()->set_specular_color(col);
101 
102  if ( _ini.get_entryVecf( col, _object->name() , "OverlayColor" ) )
103  _object->materialNode()->set_overlay_color(col);
104 
105  double shininess;
106  if ( _ini.get_entry( shininess, _object->name() , "Shininess" ) )
107  _object->materialNode()->set_shininess(shininess);
108 
109  double reflectance;
110  if ( _ini.get_entry( reflectance, _object->name() , "Reflectance" ) ) {
111  _object->materialNode()->set_reflectance(reflectance);
112  }
113 
114  double indexOfRefraction;
115  if ( _ini.get_entry( indexOfRefraction, _object->name() , "IndexOfRefraction" ) ) {
116  _object->materialNode()->set_indexOfRefraction(indexOfRefraction);
117  }
118 
119  bool isRefractive;
120  if ( _ini.get_entry( isRefractive, _object->name() , "isRefractive" ) ) {
121  _object->materialNode()->set_refractive(isRefractive);
122  }
123 
124  bool visible;
125  if ( _ini.get_entry( visible, _object->name() , "Visible" ) ) {
126  _object->visible(visible);
127  }
128 
129  int size = 1;
130  if ( _ini.get_entry( size, _object->name() , "PointSize" ) )
131  _object->materialNode()->set_point_size(size);
132  if ( _ini.get_entry( size, _object->name() , "LineWidth" ) )
133  _object->materialNode()->set_line_width(size);
134  }
135 }
136 
137 
138 void INIPlugin::saveIniFile(INIFile& _ini, BaseObjectData* _object) {
139 
140  if ( _object ) {
141  _ini.add_entry( _object->name() ,
142  "MaterialDrawMode" ,
143  drawModeToList( _object->materialNode()->drawMode()) );
144  _ini.add_entryVec( _object->name() ,
145  "BaseColor" ,
146  _object->materialNode()->base_color()) ;
147  _ini.add_entryVec( _object->name() ,
148  "AmbientColor" ,
149  _object->materialNode()->ambient_color()) ;
150  _ini.add_entryVec( _object->name() ,
151  "DiffuseColor" ,
152  _object->materialNode()->diffuse_color());
153  _ini.add_entryVec( _object->name() ,
154  "SpecularColor" ,
155  _object->materialNode()->specular_color());
156  _ini.add_entryVec( _object->name() ,
157  "OverlayColor" ,
158  _object->materialNode()->overlay_color());
159  _ini.add_entry( _object->name() ,
160  "Shininess" ,
161  _object->materialNode()->shininess());
162  _ini.add_entry( _object->name() ,
163  "Reflectance" ,
164  _object->materialNode()->reflectance());
165  _ini.add_entry( _object->name() ,
166  "IndexOfRefraction" ,
167  _object->materialNode()->indexOfRefraction());
168  _ini.add_entry( _object->name() ,
169  "isRefractive" ,
170  _object->materialNode()->isRefractive());
171  _ini.add_entry( _object->name() ,
172  "Visible" ,
173  _object->visible() );
174  _ini.add_entry( _object->name() ,
175  "PointSize" ,
176  _object->materialNode()->point_size());
177  _ini.add_entry( _object->name() ,
178  "LineWidth" ,
179  _object->materialNode()->line_width());
180  }
181 
182 }
183 
184 void INIPlugin::loadIniFile( INIFile& _ini, int _id ) {
185 
186  BaseObjectData* baseObject;
187  if (!PluginFunctions::getObject(_id, baseObject)) {
188  emit log(LOGERR, tr("Cannot find object for id ") + QString::number(_id) + tr(" in saveFile"));
189  return;
190  }
191 
192  // Load all data from baseobjectdata part
193  parseIniFile(_ini, baseObject);
194 
195  if (baseObject->dataType() == DATA_POLY_MESH) {
196  PolyMeshObject* polyObject = PluginFunctions::polyMeshObject(baseObject);
197  parseIniFileT(_ini, polyObject);
198  } else if (baseObject->dataType() == DATA_TRIANGLE_MESH) {
199  TriMeshObject* triObject = PluginFunctions::triMeshObject(baseObject);
200  parseIniFileT(_ini, triObject);
201  } else if (baseObject->dataType() == DATA_LIGHT) {
202  LightObject* lightObject = PluginFunctions::lightObject(baseObject);
203  parseIniFileT(_ini, lightObject);
204  } else {
205  // Unhandled data type
206  emit log(LOGERR, tr("The specified data type is not supported, yet. Aborting!"));
207  }
208 }
209 
210 void INIPlugin::saveIniFile( INIFile& _ini, int _id) {
211 
212  BaseObjectData* baseObject;
213  if (!PluginFunctions::getObject(_id, baseObject)) {
214  emit log(LOGERR, tr("Cannot find object for id ") + QString::number(_id) + tr(" in saveFile"));
215  return;
216  }
217 
218  // Save all data from baseobjectdata part
219  saveIniFile(_ini, baseObject);
220 
221  if (baseObject->dataType() == DATA_POLY_MESH) {
222  PolyMeshObject* polyObject = PluginFunctions::polyMeshObject(baseObject);
223  saveIniFileT(_ini, polyObject);
224  } else if (baseObject->dataType() == DATA_TRIANGLE_MESH) {
225  TriMeshObject* triObject = PluginFunctions::triMeshObject(baseObject);
226  saveIniFileT(_ini, triObject);
227  } else if (baseObject->dataType() == DATA_LIGHT) {
228  LightObject* lightObject = PluginFunctions::lightObject(baseObject);
229  saveIniFileT(_ini, lightObject);
230  } else {
231  // Unhandled data type
232  emit log(LOGERR, tr("The specified data type is not supported, yet. Aborting!"));
233  }
234 
235 }
236 
237 
238 
void set_diffuse_color(const Vec4f &_d)
set the diffuse color.
#define DATA_POLY_MESH
Definition: PolyMesh.hh:59
void set_specular_color(const Vec4f &_s)
set the specular color
const Vec4f & diffuse_color() const
get the diffuse color.
MaterialNode * materialNode()
get a pointer to the materialnode
float line_width() const
get line width
PolyMeshObject * polyMeshObject(BaseObjectData *_object)
Cast an BaseObject to a PolyMeshObject if possible.
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
bool dataType(DataType _type) const
Definition: BaseObject.cc:221
TriMeshObject * triMeshObject(BaseObjectData *_object)
Cast an BaseObject to a TriMeshObject if possible.
double reflectance() const
get reflectance
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.
Type for a MeshObject containing a triangle mesh.
Definition: TriangleMesh.hh:67
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
bool get_entryVecf(VectorT &_val, const QString &_section, const QString &_key) const
Get a Vec_n_i (int)
void set_line_width(float _sz)
set line width (default: 1.0)
void set_indexOfRefraction(double _m)
set index of refraction
float shininess() const
get shininess
double indexOfRefraction() const
get index of refraction
void set_overlay_color(const Vec4f &_s)
set the overlay color
const Vec4f & ambient_color() const
get the ambient color.
#define DATA_LIGHT
Definition: Light.hh:58
void set_shininess(float _s)
set shininess
const Vec4f & specular_color() const
get the specular color
void set_refractive(bool _r)
set refractive flag
void set_ambient_color(const Vec4f &_a)
set the ambient color.
void set_point_size(float _sz)
set point size (default: 1.0)
void add_entry(const QString &_section, const QString &_key, const QString &_value)
Addition / modification of a string entry.
Definition: INIFile.cc:257
const Vec4f & base_color() const
get the base color ( same as emission() )
float point_size() const
get point size
bool isRefractive() const
get refractive flag
void set_reflectance(double _m)
set reflectance
void add_entryVec(const QString &_section, const QString &_key, const VectorT &_value)
Addition of a Vec_n_something.
virtual bool visible()
return visiblity
#define DATA_TRIANGLE_MESH
Definition: TriangleMesh.hh:60
INIPlugin()
Constructor.
Definition: iniPlugin.cc:52
void set_base_color(const Vec4f &_c)
set the base color ( Same as set_emission(const Vec4f& _c) )
Type for a Meshobject containing a poly mesh.
Definition: PolyMesh.hh:65
Class for the handling of simple configuration files.
Definition: INIFile.hh:99
const Vec4f & overlay_color() const
get the overlay color
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
Definition: INIFile.cc:433