Developer Documentation

FileSPH.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 "FileSPH.hh"
45
46 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
47 #include <OpenFlipper/common/GlobalOptions.hh>
48
49 #include <QtWidgets>
50
51
52 void FileSPHPlugin::initializePlugin() {
53 }
54
55 QString FileSPHPlugin::getLoadFilters() {
56 return QString( tr("Sphere definition files ( *.sph )") );
57 };
58
59 QString FileSPHPlugin::getSaveFilters() {
60 return QString( tr("Sphere definition files ( *.sph )") );
61 };
62
63 DataType FileSPHPlugin::supportedType() {
64 DataType type = DATA_SPHERE;
65 return type;
66 }
67
68 int FileSPHPlugin::loadObject(QString _filename)
69 {
70 int id = -1;
71 emit addEmptyObject( DATA_SPHERE, id );
72
73 SphereObject* sphereObject = 0;
74 if(PluginFunctions::getObject( id, sphereObject))
75 {
76 if( sphereObject )
77 {
78
79 QFileInfo fi(_filename);
80
81 if ( fi.exists() ){
82 SphereNode* sphere = PluginFunctions::sphereNode(sphereObject);
83
84 QString name = sphereObject->name();
85
86 QSettings settings(_filename, QSettings::IniFormat);
87 settings.beginGroup("SPHERE");
88
89 if ( settings.contains("Name") ) {
90
91 QString name = settings.value("Name").toString();
92
93 sphereObject->setName( name );
94 } else {
95 sphereObject->setFromFileName(_filename);
96 }
97
98
99
100 if ( settings.contains("PositionX") ) {
101
102 ACG::Vec3d position;
103 position[0] = settings.value("PositionX").toDouble();
104 position[1] = settings.value("PositionY").toDouble();
105 position[2] = settings.value("PositionZ").toDouble();
106
107 sphere->get_primitive(0).position = position;
108 }
109
110 if ( settings.contains("Size") ){
111
112 double size = settings.value("Size").toDouble();
113
114 sphere->get_primitive(0).size = size;
115 }
116
117 if ( settings.contains("Slices") ){
118
119 int slices = settings.value("Slices").toDouble();
120
121 sphere->get_primitive(0).slices = slices;
122 }
123
124 if ( settings.contains("Stacks") ){
125
126 int stacks = settings.value("Stacks").toDouble();
127
128 sphere->get_primitive(0).stacks = stacks;
129 }
130
131 settings.endGroup();
132 }
133
134 emit updatedObject( sphereObject->id(), UPDATE_ALL );
135 emit openedFile( sphereObject->id() );
136
137 }
138
139
140 }
141
142 return id;
143 };
144
145
146 bool FileSPHPlugin::saveObject(int _id, QString _filename)
147 {
148
149 BaseObjectData* obj(0);
150 if(PluginFunctions::getObject( _id, obj))
151 {
152 SphereObject* sphereObject = PluginFunctions::sphereObject(obj);
153 if( sphereObject )
154 {
155 SphereNode* sphere = PluginFunctions::sphereNode(sphereObject);
156
157 QSettings settings(_filename, QSettings::IniFormat);
158 settings.beginGroup("SPHERE");
159
160 settings.setValue("Name",sphereObject->name());
161
162 settings.setValue("PositionX", sphere->get_primitive(0).position[0]);
163 settings.setValue("PositionY", sphere->get_primitive(0).position[1]);
164 settings.setValue("PositionZ", sphere->get_primitive(0).position[2]);
165
166 settings.setValue("Size", sphere->get_primitive(0).size);
167 settings.setValue("Slices", sphere->get_primitive(0).slices);
168 settings.setValue("Stacks", sphere->get_primitive(0).stacks);
169
170 settings.endGroup();
171
172 obj->setFromFileName(_filename);
173 obj->setName(obj->filename());
174 }
175 } else {
176 emit log(LOGERR, tr("saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
177 return false;
178 }
179
180 return true;
181 }
182
183
184
LOGERR
Definition: LoggingInterface.hh:96
SphereObject::setName
void setName(QString _name)
Set the name of the Object.
Definition: SphereObject.cc:169
BaseObjectData::setName
virtual void setName(QString _name) override
path to the file from which the object is loaded ( defaults to "." )
Definition: BaseObjectData.cc:355
UPDATE_ALL
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
ACG::SceneGraph::GlutPrimitiveNode
Definition: GlutPrimitiveNode.hh:82
FileSPHPlugin::supportedType
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
Definition: FileSPH.cc:63
FileSPHPlugin::getSaveFilters
QString getSaveFilters()
Definition: FileSPH.cc:59
FileSPHPlugin::name
QString name()
Return a name for the plugin.
Definition: FileSPH.hh:90
PluginFunctions::getObject
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Definition: PluginFunctions.cc:296
GlobalOptions.hh
OpenMesh::VectorT
Definition: Vector11T.hh:83
DataType
Predefined datatypes.
Definition: DataTypes.hh:83
PluginFunctions.hh
BaseObject::filename
QString filename() const
return the filename of the object
Definition: BaseObject.cc:706
BaseObject::id
int id() const
Definition: BaseObject.cc:190
PluginFunctions::sphereObject
SphereObject * sphereObject(int _objectId)
Get a SphereObject from id if possible.
Definition: PluginFunctionsSphere.cc:79
FileSPHPlugin::getLoadFilters
QString getLoadFilters()
Definition: FileSPH.cc:55
FileSPHPlugin::initializePlugin
void initializePlugin()
Initialize Plugin.
Definition: FileSPH.cc:52
PluginFunctions::sphereNode
SphereNode * sphereNode(BaseObjectData *_object)
Get a SphereNode from an object.
Definition: PluginFunctionsSphere.cc:99
BaseObject::name
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
BaseObjectData
Definition: BaseObjectData.hh:102
ACG::SceneGraph::GlutPrimitiveNode::get_primitive
Primitive & get_primitive(int _idx)
get a primitive
Definition: GlutPrimitiveNode.hh:203
SphereObject
Definition: SphereObject.hh:73
DATA_SPHERE
#define DATA_SPHERE
Definition: Sphere.hh:58
BaseObject::setFromFileName
void setFromFileName(const QString &_filename)
Definition: BaseObject.cc:716