Developer Documentation
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 #include "FilePla.hh"
45 
48 
49  #include <QtWidgets>
50 
51 
53 }
54 
56  return QString( tr("Plane files ( *.pla )") );
57 };
58 
60  return QString( tr("Plane files ( *.pla )") );
61 };
62 
64  DataType type = DATA_PLANE;
65  return type;
66 }
67 
68 int FilePlaPlugin::loadObject(QString _filename)
69 {
70  int id = -1;
71  emit addEmptyObject( DATA_PLANE, id );
72 
73  PlaneObject* plane = 0;
74  if(PluginFunctions::getObject( id, plane))
75  {
76  if( plane )
77  {
78 
79  QFileInfo fi(_filename);
80 
81  if ( fi.exists() ){
82 
83  ACG::Vec3d position;
84  ACG::Vec3d xDirection;
85  ACG::Vec3d yDirection;
86 
87  QSettings settings(_filename, QSettings::IniFormat);
88  settings.beginGroup("PLANE");
89 
90  if ( settings.contains("Position0") ){
91 
92  position[0] = settings.value("Position0").toDouble();
93  position[1] = settings.value("Position1").toDouble();
94  position[2] = settings.value("Position2").toDouble();
95  xDirection[0] = settings.value("XDirection0").toDouble();
96  xDirection[1] = settings.value("XDirection1").toDouble();
97  xDirection[2] = settings.value("XDirection2").toDouble();
98  yDirection[0] = settings.value("YDirection0").toDouble();
99  yDirection[1] = settings.value("YDirection1").toDouble();
100  yDirection[2] = settings.value("YDirection2").toDouble();
101  settings.endGroup();
102 
103  plane->plane().setPlane(position, xDirection, yDirection);
104 
105  plane->setFromFileName(_filename);
106  }
107  }
108 
109  emit updatedObject( plane->id(), UPDATE_ALL );
110 
111  }
112 
113  }
114 
115  return id;
116 };
117 
118 bool FilePlaPlugin::saveObject(int _id, QString _filename)
119 {
120 
121  BaseObjectData* obj(0);
122  if(PluginFunctions::getObject( _id, obj))
123  {
125  if( plane )
126  {
127 
128  obj->setFromFileName(_filename);
129  obj->setName(obj->filename());
130 
131  QSettings settings(_filename, QSettings::IniFormat);
132  settings.beginGroup("PLANE");
133  settings.setValue("Position0", plane->planeNode()->position()[0]);
134  settings.setValue("Position1", plane->planeNode()->position()[1]);
135  settings.setValue("Position2", plane->planeNode()->position()[2]);
136  settings.setValue("XDirection0", plane->planeNode()->xDirection()[0]);
137  settings.setValue("XDirection1", plane->planeNode()->xDirection()[1]);
138  settings.setValue("XDirection2", plane->planeNode()->xDirection()[2]);
139  settings.setValue("YDirection0", plane->planeNode()->yDirection()[0]);
140  settings.setValue("YDirection1", plane->planeNode()->yDirection()[1]);
141  settings.setValue("YDirection2", plane->planeNode()->yDirection()[2]);
142  settings.endGroup();
143  }
144  } else {
145  emit log(LOGERR, tr("saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
146  return false;
147  }
148 
149  return true;
150 }
151 
152 
virtual void setName(QString _name) override
path to the file from which the object is loaded ( defaults to "." )
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
void initializePlugin()
Initialize Plugin.
Definition: FilePla.cc:52
ACG::Vec3d yDirection()
local y direction (multiplied with height)
Definition: PlaneNode.cc:428
QString getLoadFilters()
Definition: FilePla.cc:55
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
PlaneNode * planeNode()
Get the scenegraph Node.
Definition: PlaneObject.cc:181
ACG::Vec3d xDirection()
local x direction (multiplied with width)
Definition: PlaneNode.cc:424
Predefined datatypes.
Definition: DataTypes.hh:83
QString filename() const
return the filename of the object
Definition: BaseObject.cc:706
int id() const
Definition: BaseObject.cc:190
void setPlane(const ACG::Vec3d &_position, const ACG::Vec3d &_xDirection, const ACG::Vec3d &)
Set plane.
Definition: PlaneType.cc:48
ACG::Vec3d position()
get center position of the plane
Definition: PlaneNode.cc:416
PlaneObject * planeObject(BaseObjectData *_object)
Cast an BaseObject to a PlaneObject if possible.
QString getSaveFilters()
Definition: FilePla.cc:59
#define DATA_PLANE
Definition: Plane.hh:58
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
Definition: FilePla.cc:63
void setFromFileName(const QString &_filename)
Definition: BaseObject.cc:716