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