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
47 #include <ObjectTypes/PolyMesh/PolyMesh.hh>
48 #include <ObjectTypes/Light/Light.hh>
49 #include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
50
52 INIPlugin::INIPlugin() {
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
LOGERR
Definition: LoggingInterface.hh:96
DATA_TRIANGLE_MESH
#define DATA_TRIANGLE_MESH
Definition: TriangleMesh.hh:60
PluginFunctions::lightObject
LightObject * lightObject(BaseObjectData *_object)
Cast an BaseObject to a LightObject if possible.
Definition: PluginFunctionsLight.cc:94
DATA_POLY_MESH
#define DATA_POLY_MESH
Definition: PolyMesh.hh:59
INIFile::get_entryVecf
bool get_entryVecf(VectorT &_val, const QString &_section, const QString &_key) const
Get a Vec_n_i (int)
Definition: INIFileT_impl.hh:163
ACG::SceneGraph::MaterialNode::set_specular_color
void set_specular_color(const Vec4f &_s)
set the specular color
Definition: MaterialNode.hh:441
PolyMeshObject
Type for a Meshobject containing a poly mesh.
Definition: PolyMesh.hh:65
ACG::SceneGraph::MaterialNode::ambient_color
const Vec4f & ambient_color() const
get the ambient color.
Definition: MaterialNode.hh:433
ACG::SceneGraph::ACG::SceneGraph::BaseNode::drawMode
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
Definition: MeshNode2T_impl.hh:430
ACG::SceneGraph::MaterialNode::set_overlay_color
void set_overlay_color(const Vec4f &_s)
set the overlay color
Definition: MaterialNode.hh:446
INIFile::add_entry
void add_entry(const QString &_section, const QString &_key, const QString &_value)
Addition / modification of a string entry.
Definition: INIFile.cc:257
ACG::SceneGraph::MaterialNode::set_refractive
void set_refractive(bool _r)
set refractive flag
Definition: MaterialNode.hh:475
ACG::SceneGraph::MaterialNode::indexOfRefraction
double indexOfRefraction() const
get index of refraction
Definition: MaterialNode.hh:472
PluginFunctions::getObject
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Definition: PluginFunctions.cc:296
ACG::SceneGraph::MaterialNode::specular_color
const Vec4f & specular_color() const
get the specular color
Definition: MaterialNode.hh:443
ACG::SceneGraph::MaterialNode::set_ambient_color
void set_ambient_color(const Vec4f &_a)
set the ambient color.
Definition: MaterialNode.hh:431
Light.hh
ACG::SceneGraph::MaterialNode::set_line_width
void set_line_width(float _sz)
set line width (default: 1.0)
Definition: MaterialNode.hh:491
OpenMesh::VectorT
Definition: Vector11T.hh:83
ACG::SceneGraph::MaterialNode::shininess
float shininess() const
get shininess
Definition: MaterialNode.hh:462
INIFile::get_entry
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
Definition: INIFile.cc:433
ACG::SceneGraph::MaterialNode::set_shininess
void set_shininess(float _s)
set shininess
Definition: MaterialNode.hh:460
ACG::SceneGraph::MaterialNode::diffuse_color
const Vec4f & diffuse_color() const
get the diffuse color.
Definition: MaterialNode.hh:438
ACG::SceneGraph::MaterialNode::isRefractive
bool isRefractive() const
get refractive flag
Definition: MaterialNode.hh:477
ACG::SceneGraph::MaterialNode::set_diffuse_color
void set_diffuse_color(const Vec4f &_d)
set the diffuse color.
Definition: MaterialNode.hh:436
LightObject
Definition: LightObject.hh:72
BaseObject::dataType
bool dataType(DataType _type) const
Definition: BaseObject.cc:221
ACG::SceneGraph::MaterialNode::line_width
float line_width() const
get line width
Definition: MaterialNode.hh:493
TriangleMesh.hh
ACG::SceneGraph::MaterialNode::overlay_color
const Vec4f & overlay_color() const
get the overlay color
Definition: MaterialNode.hh:448
BaseObject::name
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
PluginFunctions::polyMeshObject
PolyMeshObject * polyMeshObject(BaseObjectData *_object)
Cast an BaseObject to a PolyMeshObject if possible.
Definition: PluginFunctionsPolyMesh.cc:149
ACG::SceneGraph::MaterialNode::point_size
float point_size() const
get point size
Definition: MaterialNode.hh:488
PluginFunctions::triMeshObject
TriMeshObject * triMeshObject(BaseObjectData *_object)
Cast an BaseObject to a TriMeshObject if possible.
Definition: PluginFunctionsTriangleMesh.cc:156
TriMeshObject
Type for a MeshObject containing a triangle mesh.
Definition: TriangleMesh.hh:67
BaseObjectData
Definition: BaseObjectData.hh:102
PolyMesh.hh
ACG::SceneGraph::MaterialNode::base_color
const Vec4f & base_color() const
get the base color ( same as emission() )
Definition: MaterialNode.hh:423
ACG::SceneGraph::MaterialNode::set_reflectance
void set_reflectance(double _m)
set reflectance
Definition: MaterialNode.hh:465
BaseObjectData::materialNode
MaterialNode * materialNode()
get a pointer to the materialnode
Definition: BaseObjectData.cc:263
INIFile::add_entryVec
void add_entryVec(const QString &_section, const QString &_key, const VectorT &_value)
Addition of a Vec_n_something.
Definition: INIFileT_impl.hh:205
ACG::SceneGraph::MaterialNode::set_indexOfRefraction
void set_indexOfRefraction(double _m)
set index of refraction
Definition: MaterialNode.hh:470
INIPlugin::INIPlugin
INIPlugin()
Constructor.
Definition: iniPlugin.cc:52
INIFile
Class for the handling of simple configuration files.
Definition: INIFile.hh:99
ACG::SceneGraph::MaterialNode::set_base_color
void set_base_color(const Vec4f &_c)
set the base color ( Same as set_emission(const Vec4f& _c) )
Definition: MaterialNode.hh:421
DATA_LIGHT
#define DATA_LIGHT
Definition: Light.hh:58
ACG::SceneGraph::MaterialNode::reflectance
double reflectance() const
get reflectance
Definition: MaterialNode.hh:467
ACG::SceneGraph::MaterialNode::set_point_size
void set_point_size(float _sz)
set point size (default: 1.0)
Definition: MaterialNode.hh:486
BaseObjectData::visible
virtual bool visible() override
return visiblity
Definition: BaseObjectData.cc:206