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 
48 
49 #include <OpenMesh/Core/IO/IOManager.hh>
50 
52 
53 
54 //-----------------------------------------------------------------------------
55 
57  // Data type has already been added by polyline type plugin
58 }
59 
61  return QString( tr("Poly-Line files ( *.pol )" ));
62 };
63 
65  return QString( tr("Poly-Line files ( *.pol )" ));
66 };
67 
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 
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  {
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 
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 
DrawMode WIREFRAME
draw wireframe
Definition: DrawModes.cc:78
int id() const
Definition: BaseObject.cc:190
QString getSaveFilters()
Definition: FilePolyLine.cc:64
void setFromFileName(const QString &_filename)
Definition: BaseObject.cc:716
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
bool get_entryVecf(VectorT &_val, const QString &_section, const QString &_key) const
Get a Vec_n_i (int)
QString getLoadFilters()
Definition: FilePolyLine.cc:60
ACG::SceneGraph::PolyLineNodeT< PolyLine > * lineNode()
Get the scenegraph Node.
#define DATA_POLY_LINE
Definition: PolyLine.hh:64
void initializePlugin()
Initialize Plugin.
Definition: FilePolyLine.cc:56
Predefined datatypes.
Definition: DataTypes.hh:83
void setPath(const QString &_path)
set the path to the object.
Definition: BaseObject.cc:738
void setName(QString _name)
Set the name of the Object.
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
Definition: FilePolyLine.cc:68
void add_entryVec(const QString &_section, const QString &_key, const VectorT &_value)
Addition of a Vec_n_something.
void saveIniFile(INIFile &_ini, int _id)
Save per object settings.
PolyLineObject * polyLineObject(BaseObjectData *_object)
Cast an BaseObject to a PolyLineObject if possible.
DrawMode POINTS
draw unlighted points using the default base color
Definition: DrawModes.cc:73
Class for the handling of simple configuration files.
Definition: INIFile.hh:99