Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 #include "FilePolyLine.hh"
51 
54 
55 #include <OpenMesh/Core/IO/IOManager.hh>
56 
58 
59 #if QT_VERSION >= 0x050000
60 #else
61  #include <QtGui>
62 #endif
63 
64 //-----------------------------------------------------------------------------
65 
67  // Data type has already been added by polyline type plugin
68 }
69 
71  return QString( tr("Poly-Line files ( *.pol )" ));
72 };
73 
75  return QString( tr("Poly-Line files ( *.pol )" ));
76 };
77 
79  DataType type = DATA_POLY_LINE;
80  return type;
81 }
82 
83 int FilePolyLinePlugin::loadObject(QString _filename)
84 {
85  int id = -1;
86  emit addEmptyObject( DATA_POLY_LINE, id );
87 
88  PolyLineObject* pol(0);
89  if(PluginFunctions::getObject( id, pol))
90  {
91  std::ifstream fin(_filename.toLatin1(), std::ios::in);
92  PolyLineObjectSerializer serializer(pol);
93  serializer.deserialize(fin);
94  fin.close();
95 
96  pol->lineNode()->drawMode(ACG::SceneGraph::DrawModes::WIREFRAME |
98  pol->setFromFileName(_filename);
99  pol->setName(QFileInfo(_filename).fileName());
100  }
101 
102  emit openedFile( pol->id() );
103 
104  return id;
105 };
106 
107 bool FilePolyLinePlugin::saveObject(int _id, QString _filename)
108 {
109  BaseObjectData* obj(0);
110  if(PluginFunctions::getObject( _id, obj))
111  {
113  if( pol)
114  {
115  std::cerr << "call Line Function\n";
116  std::cerr << (const char*) _filename.toLatin1() << std::endl;
117 
118  obj->setName(_filename.section(OpenFlipper::Options::dirSeparator(),-1));
119  obj->setPath(_filename.section(OpenFlipper::Options::dirSeparator(),0,-2) );
120 
121  std::ofstream fout(_filename.toLatin1(), std::ios::out);
122  PolyLineObjectSerializer serializer(pol);
123  serializer.serialize(fout);
124  fout.close();
125  return true;
126  } else {
127  return false;
128  }
129  } else {
130  emit log(LOGERR, tr("saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
131  return false;
132  }
133 
134  return true;
135 }
136 
137 void FilePolyLinePlugin::loadIniFileLast( INIFile& _ini ,int _id ) {
138  BaseObjectData* baseObject;
139  if ( !PluginFunctions::getObject(_id,baseObject) ) {
140  emit log(LOGERR,tr("Cannot find object for id %1 in saveFile!").arg(_id));
141  return;
142  }
143 
144  PolyLineObject* object = PluginFunctions::polyLineObject(baseObject);
145 
146  if ( object ) {
147  ACG::Vec4f col(0.0,0.0,0.0,0.0);
148 
149  if ( _ini.get_entryVecf( col, object->name() , "BaseColor" ) )
150  object->materialNode()->set_base_color(col);
151  }
152 
153 }
154 
156  BaseObjectData* baseObject;
157  if ( !PluginFunctions::getObject(_id,baseObject) ) {
158  emit log(LOGERR,tr("Cannot find object for id %1 in saveFile!").arg(_id) );
159  return;
160  }
161 
162  PolyLineObject* object = PluginFunctions::polyLineObject(baseObject);
163 
164  if ( object ) {
165  _ini.add_entryVec( object->name() ,
166  "BaseColor" ,
167  object->materialNode()->base_color() ) ;
168  }
169 }
170 #if QT_VERSION < 0x050000
171  Q_EXPORT_PLUGIN2( filepolylineplugin , FilePolyLinePlugin );
172 #endif
173 
174 
#define DATA_POLY_LINE
Definition: PolyLine.hh:70
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:741
PolyLineObject * polyLineObject(BaseObjectData *_object)
Cast an BaseObject to a PolyLineObject if possible.
bool getObject(int _identifier, BSplineCurveObject *&_object)
void initializePlugin()
Initialize Plugin.
Definition: FilePolyLine.cc:66
void add_entryVec(const QString &_section, const QString &_key, const VectorT &_value)
Addition of a Vec_n_something.
Definition: INIFileT.cc:211
QString getSaveFilters()
Definition: FilePolyLine.cc:74
Class for the handling of simple configuration files.
Definition: INIFile.hh:105
DrawMode POINTS
draw unlighted points using the default base color
Definition: DrawModes.cc:79
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
Definition: FilePolyLine.cc:78
DrawMode WIREFRAME
draw wireframe
Definition: DrawModes.cc:84
Predefined datatypes.
Definition: DataTypes.hh:96
QString getLoadFilters()
Definition: FilePolyLine.cc:70
void saveIniFile(INIFile &_ini, int _id)
Save per object settings.
bool get_entryVecf(VectorT &_val, const QString &_section, const QString &_key) const
Get a Vec_n_i (int)
Definition: INIFileT.cc:169