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