Developer Documentation

FilePolyLine.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 "FilePolyLine.hh"
45
46 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
47 #include <OpenFlipper/common/GlobalOptions.hh>
48
49 #include <OpenMesh/Core/IO/IOManager.hh>
50
51 #include <ObjectTypes/PolyLine/PolyLineObjectSerializer.hh>
52
53
54 //-----------------------------------------------------------------------------
55
56 void FilePolyLinePlugin::initializePlugin() {
57 // Data type has already been added by polyline type plugin
58 }
59
60 QString FilePolyLinePlugin::getLoadFilters() {
61 return QString( tr("Poly-Line files ( *.pol )" ));
62 };
63
64 QString FilePolyLinePlugin::getSaveFilters() {
65 return QString( tr("Poly-Line files ( *.pol )" ));
66 };
67
68 DataType FilePolyLinePlugin::supportedType() {
69 DataType type = DATA_POLY_LINE;
70 return type;
71 }
72
73 int FilePolyLinePlugin::loadObject(QString _filename)
74 {
75 int id = -1;
76 emit addEmptyObject( DATA_POLY_LINE, id );
77
78 PolyLineObject* pol(0);
79 if(PluginFunctions::getObject( id, pol))
80 {
81 std::ifstream fin(_filename.toLatin1(), std::ios::in);
82 PolyLineObjectSerializer serializer(pol);
83 serializer.deserialize(fin);
84 fin.close();
85
86 pol->lineNode()->drawMode(ACG::SceneGraph::DrawModes::WIREFRAME |
87 ACG::SceneGraph::DrawModes::POINTS);
88 pol->setFromFileName(_filename);
89 pol->setName(QFileInfo(_filename).fileName());
90 }
91
92 emit openedFile( pol->id() );
93
94 return id;
95 };
96
97 bool FilePolyLinePlugin::saveObject(int _id, QString _filename)
98 {
99 BaseObjectData* obj(0);
100 if(PluginFunctions::getObject( _id, obj))
101 {
102 PolyLineObject* pol = PluginFunctions::polyLineObject(obj);
103 if( pol)
104 {
105 std::cerr << "call Line Function\n";
106 std::cerr << (const char*) _filename.toLatin1() << std::endl;
107
108 obj->setName(_filename.section(OpenFlipper::Options::dirSeparator(),-1));
109 obj->setPath(_filename.section(OpenFlipper::Options::dirSeparator(),0,-2) );
110
111 std::ofstream fout(_filename.toLatin1(), std::ios::out);
112 PolyLineObjectSerializer serializer(pol);
113 serializer.serialize(fout);
114 fout.close();
115 return true;
116 } else {
117 return false;
118 }
119 } else {
120 emit log(LOGERR, tr("saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
121 return false;
122 }
123
124 return true;
125 }
126
127 void FilePolyLinePlugin::loadIniFileLast( INIFile& _ini ,int _id ) {
128 BaseObjectData* baseObject;
129 if ( !PluginFunctions::getObject(_id,baseObject) ) {
130 emit log(LOGERR,tr("Cannot find object for id %1 in saveFile!").arg(_id));
131 return;
132 }
133
134 PolyLineObject* object = PluginFunctions::polyLineObject(baseObject);
135
136 if ( object ) {
137 ACG::Vec4f col(0.0,0.0,0.0,0.0);
138
139 if ( _ini.get_entryVecf( col, object->name() , "BaseColor" ) )
140 object->materialNode()->set_base_color(col);
141 }
142
143 }
144
145 void FilePolyLinePlugin::saveIniFile( INIFile& _ini ,int _id) {
146 BaseObjectData* baseObject;
147 if ( !PluginFunctions::getObject(_id,baseObject) ) {
148 emit log(LOGERR,tr("Cannot find object for id %1 in saveFile!").arg(_id) );
149 return;
150 }
151
152 PolyLineObject* object = PluginFunctions::polyLineObject(baseObject);
153
154 if ( object ) {
155 _ini.add_entryVec( object->name() ,
156 "BaseColor" ,
157 object->materialNode()->base_color() ) ;
158 }
159 }
160
161
LOGERR
Definition: LoggingInterface.hh:96
BaseObject::setPath
void setPath(const QString &_path)
set the path to the object.
Definition: BaseObject.cc:738
BaseObjectData::setName
virtual void setName(QString _name) override
path to the file from which the object is loaded ( defaults to "." )
Definition: BaseObjectData.cc:355
INIFile::get_entryVecf
bool get_entryVecf(VectorT &_val, const QString &_section, const QString &_key) const
Get a Vec_n_i (int)
Definition: INIFileT_impl.hh:163
PluginFunctions::polyLineObject
PolyLineObject * polyLineObject(BaseObjectData *_object)
Cast an BaseObject to a PolyLineObject if possible.
Definition: PluginFunctionsPolyLine.cc:142
PolyLineObject::setName
void setName(QString _name)
Set the name of the Object.
Definition: PolyLineObject.cc:185
PluginFunctions::getObject
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Definition: PluginFunctions.cc:296
FilePolyLinePlugin::saveIniFile
void saveIniFile(INIFile &_ini, int _id)
Save per object settings.
Definition: FilePolyLine.cc:145
GlobalOptions.hh
OpenMesh::VectorT
Definition: Vector11T.hh:83
DataType
Predefined datatypes.
Definition: DataTypes.hh:83
PluginFunctions.hh
FilePolyLinePlugin::supportedType
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
Definition: FilePolyLine.cc:68
PolyLineObject
Definition: PolyLineObject.hh:76
PolyLineObjectSerializer.hh
BaseObject::id
int id() const
Definition: BaseObject.cc:190
FilePolyLinePlugin::getLoadFilters
QString getLoadFilters()
Definition: FilePolyLine.cc:60
PolyLineObjectSerializer
Definition: PolyLineObjectSerializer.hh:63
DATA_POLY_LINE
#define DATA_POLY_LINE
Definition: PolyLine.hh:64
FilePolyLinePlugin::initializePlugin
void initializePlugin()
Initialize Plugin.
Definition: FilePolyLine.cc:56
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::DrawModes::POINTS
DrawMode POINTS
draw unlighted points using the default base color
Definition: DrawModes.cc:73
INIFile::add_entryVec
void add_entryVec(const QString &_section, const QString &_key, const VectorT &_value)
Addition of a Vec_n_something.
Definition: INIFileT_impl.hh:205
ACG::SceneGraph::DrawModes::WIREFRAME
DrawMode WIREFRAME
draw wireframe
Definition: DrawModes.cc:78
INIFile
Class for the handling of simple configuration files.
Definition: INIFile.hh:99
PolyLineObject::lineNode
ACG::SceneGraph::PolyLineNodeT< PolyLine > * lineNode()
Get the scenegraph Node.
Definition: PolyLineObject.cc:212
FilePolyLinePlugin::getSaveFilters
QString getSaveFilters()
Definition: FilePolyLine.cc:64
BaseObject::setFromFileName
void setFromFileName(const QString &_filename)
Definition: BaseObject.cc:716