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
46 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
47 #include <OpenFlipper/common/GlobalOptions.hh>
48
49 #include <QtWidgets>
50
51
52 void FilePlaPlugin::initializePlugin() {
53 }
54
55 QString FilePlaPlugin::getLoadFilters() {
56 return QString( tr("Plane files ( *.pla )") );
57 };
58
59 QString FilePlaPlugin::getSaveFilters() {
60 return QString( tr("Plane files ( *.pla )") );
61 };
62
63 DataType FilePlaPlugin::supportedType() {
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 {
124 PlaneObject* plane = PluginFunctions::planeObject(obj);
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
LOGERR
Definition: LoggingInterface.hh:96
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.
FilePlaPlugin::initializePlugin
void initializePlugin()
Initialize Plugin.
Definition: FilePla.cc:52
PlaneNode::yDirection
ACG::Vec3d yDirection()
local y direction (multiplied with height)
Definition: PlaneNode.cc:279
FilePlaPlugin::getLoadFilters
QString getLoadFilters()
Definition: FilePla.cc:55
PluginFunctions::getObject
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Definition: PluginFunctions.cc:296
GlobalOptions.hh
PlaneObject::planeNode
PlaneNode * planeNode()
Get the scenegraph Node.
Definition: PlaneObject.cc:171
PlaneNode::xDirection
ACG::Vec3d xDirection()
local x direction (multiplied with width)
Definition: PlaneNode.cc:272
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
ACG::Geometry::Plane::setPlane
void setPlane(const ACG::Vec3d &_position, const ACG::Vec3d &_xDirection, const ACG::Vec3d &)
Set plane.
Definition: PlaneType.cc:48
PlaneNode::position
ACG::Vec3d position()
get center position of the plane
Definition: PlaneNode.cc:258
BaseObjectData
Definition: BaseObjectData.hh:102
PluginFunctions::planeObject
PlaneObject * planeObject(BaseObjectData *_object)
Cast an BaseObject to a PlaneObject if possible.
Definition: PluginFunctionsPlane.cc:100
FilePlaPlugin::getSaveFilters
QString getSaveFilters()
Definition: FilePla.cc:59
DATA_PLANE
#define DATA_PLANE
Definition: Plane.hh:58
PlaneObject
Definition: PlaneObject.hh:75
FilePlaPlugin::supportedType
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
Definition: FilePla.cc:63
BaseObject::setFromFileName
void setFromFileName(const QString &_filename)
Definition: BaseObject.cc:716