Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
FilePla.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 "FilePla.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("Plane files ( *.pla )") );
67 };
68 
70  return QString( tr("Plane files ( *.pla )") );
71 };
72 
74  DataType type = DATA_PLANE;
75  return type;
76 }
77 
78 int FilePlaPlugin::loadObject(QString _filename)
79 {
80  int id = -1;
81  emit addEmptyObject( DATA_PLANE, id );
82 
83  PlaneObject* plane = 0;
84  if(PluginFunctions::getObject( id, plane))
85  {
86  if( plane )
87  {
88 
89  QFileInfo fi(_filename);
90 
91  if ( fi.exists() ){
92 
93  ACG::Vec3d position;
94  ACG::Vec3d xDirection;
95  ACG::Vec3d yDirection;
96 
97  QSettings settings(_filename, QSettings::IniFormat);
98  settings.beginGroup("PLANE");
99 
100  if ( settings.contains("Position0") ){
101 
102  position[0] = settings.value("Position0").toDouble();
103  position[1] = settings.value("Position1").toDouble();
104  position[2] = settings.value("Position2").toDouble();
105  xDirection[0] = settings.value("XDirection0").toDouble();
106  xDirection[1] = settings.value("XDirection1").toDouble();
107  xDirection[2] = settings.value("XDirection2").toDouble();
108  yDirection[0] = settings.value("YDirection0").toDouble();
109  yDirection[1] = settings.value("YDirection1").toDouble();
110  yDirection[2] = settings.value("YDirection2").toDouble();
111  settings.endGroup();
112 
113  plane->plane().setPlane(position, xDirection, yDirection);
114 
115  plane->setFromFileName(_filename);
116  }
117  }
118 
119  emit updatedObject( plane->id(), UPDATE_ALL );
120 
121  }
122 
123  }
124 
125  return id;
126 };
127 
128 bool FilePlaPlugin::saveObject(int _id, QString _filename)
129 {
130 
131  BaseObjectData* obj(0);
132  if(PluginFunctions::getObject( _id, obj))
133  {
135  if( plane )
136  {
137 
138  obj->setFromFileName(_filename);
139  obj->setName(obj->filename());
140 
141  QSettings settings(_filename, QSettings::IniFormat);
142  settings.beginGroup("PLANE");
143  settings.setValue("Position0", plane->planeNode()->position()[0]);
144  settings.setValue("Position1", plane->planeNode()->position()[1]);
145  settings.setValue("Position2", plane->planeNode()->position()[2]);
146  settings.setValue("XDirection0", plane->planeNode()->xDirection()[0]);
147  settings.setValue("XDirection1", plane->planeNode()->xDirection()[1]);
148  settings.setValue("XDirection2", plane->planeNode()->xDirection()[2]);
149  settings.setValue("YDirection0", plane->planeNode()->yDirection()[0]);
150  settings.setValue("YDirection1", plane->planeNode()->yDirection()[1]);
151  settings.setValue("YDirection2", plane->planeNode()->yDirection()[2]);
152  settings.endGroup();
153  }
154  } else {
155  emit log(LOGERR, tr("saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
156  return false;
157  }
158 
159  return true;
160 }
161 #if QT_VERSION < 0x050000
162  Q_EXPORT_PLUGIN2( fileplaplugin , FilePlaPlugin );
163 #endif
164 
165 
void initializePlugin()
Initialize Plugin.
Definition: FilePla.cc:62
#define DATA_PLANE
Definition: Plane.hh:64
ACG::Vec3d position()
get center position of the plane
Definition: PlaneNode.cc:258
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
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
Definition: FilePla.cc:73
ACG::Vec3d xDirection()
local x direction (multiplied with width)
Definition: PlaneNode.cc:272
PlaneNode * planeNode()
Get the scenegraph Node.
Definition: PlaneObject.cc:177
QString getSaveFilters()
Definition: FilePla.cc:69
void setPlane(const ACG::Vec3d &_position, const ACG::Vec3d &_xDirection, const ACG::Vec3d &)
Set plane.
Definition: PlaneType.cc:56
QString getLoadFilters()
Definition: FilePla.cc:65
ACG::Vec3d yDirection()
local y direction (multiplied with height)
Definition: PlaneNode.cc:279
Predefined datatypes.
Definition: DataTypes.hh:96
PlaneObject * planeObject(BaseObjectData *_object)
Cast an BaseObject to a PlaneObject if possible.
int id() const
Definition: BaseObject.cc:201