Developer Documentation
FileOBJ.hh
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 #pragma once
45 
46 #include <QObject>
47 #include <QCheckBox>
48 #include <QLabel>
49 #include <QSpinBox>
50 #include <QPushButton>
51 #include <QComboBox>
52 
62 #include <OpenFlipper/BasePlugin/TextureInterface.hh>
63 
66 
67 #ifdef ENABLE_BSPLINECURVE_SUPPORT
69 #endif
70 
71 #ifdef ENABLE_BSPLINESURFACE_SUPPORT
73 #endif
74 
75 #include "OBJImporter.hh"
76 #include "Material.hh"
77 
78 #include <map>
79 
80 enum ReaderMode
81 {
82  NONE = 0,
83  CURVE = 1,
84  SURFACE = 1 << 1
85 };
86 
89 {
90  Q_OBJECT
91  Q_INTERFACES(FileInterface)
92  Q_INTERFACES(LoadSaveInterface)
93  Q_INTERFACES(LoggingInterface)
94  Q_INTERFACES(BaseInterface)
95  Q_INTERFACES(ScriptInterface)
96  Q_INTERFACES(StatusbarInterface)
97  Q_INTERFACES(RPCInterface)
98  Q_INTERFACES(TextureInterface)
99  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-FileOBJ")
100  signals:
101  void openedFile( int _id );
102  void addEmptyObject( DataType _type, int& _id);
103  void load(QString _filename, DataType _type, int& _id);
104  void save(int _id , QString _filename );
105  void log(Logtype _type, QString _message);
106  void log(QString _message);
107  void updateView();
108  void updatedObject(int _identifier, const UpdateType& _type);
109 
110  void deleteObject( int _id );
111 
112  // StatusbarInterface
113  void showStatusMessage(QString _message, int _timeout = 0);
114  void setStatus( ApplicationStatus::applicationStatus _status);
115 
116  //RPCInterface
117  void pluginExists( QString _pluginName , bool& _exists );
118 
119  //TextureInterface
120  void setTextureMode(QString _textureName, QString _mode, int _id );
121  void switchTexture( QString _textureName, int _id );
122  void addMultiTexture( QString _textureGroup, QString _name, QString _filename, int _id, int& _textureId);
123  void textureFilename( int /*_id*/, QString /*_textureName*/, QString& /*_textureFilename*/ );
124  void textureIndex(QString _name,int _id, int& _index);
125  void getCurrentTexture(int /*_id*/, QString& /*_name*/);
126  void textureName (int, int, QString &);
127  void getSubTextures (int, QString, QStringList &);
128  void textureIndexPropertyName(int, QString&);
129 
130  private slots:
131 
132  void fileOpened( int /*_id*/ ){};
133 
134  void noguiSupported( ) {} ;
135 
136  void initializePlugin();
137 
139  void slotLoadDefault();
140 
142  void slotSaveDefault();
143 
144  void slotHandleCheckBoxes(bool _checked);
145 
146  void handleTrimeshDialog();
147 
148  public :
149 
150  FileOBJPlugin();
151 
152  ~FileOBJPlugin() {};
153 
154  QString name() { return (QString("FileOBJ")); };
155  QString description( ) { return (QString(tr("Load/Save OBJ-Files"))); };
156 
158 
159  QString getSaveFilters();
160  QString getLoadFilters();
161 
162  QWidget* saveOptionsWidget(QString /*_currentFilter*/);
163  QWidget* loadOptionsWidget(QString /*_currentFilter*/);
164 
165  public slots:
166 
168  int loadObject(QString _filename);
169 
171  int loadObject(QString _filename, DataType _type);
172 
173  bool saveObject(int _id, QString _filename);
174 
175  QString version() { return QString("1.0"); };
176 
177  private:
178 
180  void checkTypes(QByteArray& _bufferedFile, QString _filename, OBJImporter& _importer, QStringList& _includes);
181 
182  bool readMaterial(QString _filename, OBJImporter& _importer);
183  void readOBJFile(QByteArray& _bufferedFile, QString _filename, OBJImporter& _importer);
184  void createAllGroupObjects(OBJImporter& _importer);
185  //void addNewObject(OBJImporter& _importer, QString _name );
186  template <class MeshT>
187  void backupTextureCoordinates(MeshT& _mesh);
188  void addTextures(OBJImporter& _importer, int _objectID );
189 
191  void convertToOBJName(QString& _name);
192 
193  private :
194 
196  MaterialList materials_;
197 
198  template< class MeshT >
199  Material& getMaterial(MeshT& _mesh, const OpenMesh::FaceHandle& _fh, int _objId);
200 
202  template< class MeshT >
203  bool writeMaterial(QString _filename, MeshT& _mesh, int _objId );
204 
205  template< class MeshT >
206  bool writeMesh(std::ostream& _out, QString _filename, MeshT& _mesh, int _objId);
207 
208  #ifdef ENABLE_BSPLINECURVE_SUPPORT
209  bool writeCurve(std::ostream& _out, QString _filename, BSplineCurve* _curve );
210  #endif
211 
212  #ifdef ENABLE_BSPLINESURFACE_SUPPORT
213  bool writeSurface(std::ostream& _out, QString _filename, BSplineSurface* _surface );
214  #endif
215 
216 
217  private:
218 
219  //Option Widgets
220  QWidget* loadOptions_;
221  QWidget* saveOptions_;
222 
223  QCheckBox* saveBinary_;
224  QCheckBox* saveVertexColor_;
225  QCheckBox* saveFaceColor_;
226  QCheckBox* saveAlpha_;
227  QCheckBox* saveNormals_;
228  QCheckBox* saveTexCoords_;
229  QCheckBox* saveTextures_;
230  QCheckBox* saveCopyTextures_;
231  QCheckBox* saveCreateTexFolder_;
232  QLabel* savePrecisionLabel_;
233  QSpinBox* savePrecision_;
234  QPushButton* saveDefaultButton_;
235 
236 
237  QComboBox* triMeshHandling_;
238  QCheckBox* loadVertexColor_;
239  QCheckBox* loadFaceColor_;
240  QCheckBox* loadAlpha_;
241  QCheckBox* loadNormals_;
242  QCheckBox* loadTexCoords_;
243  QCheckBox* loadTextures_;
244  QPushButton* loadDefaultButton_;
245 
246  bool forceTriangleMesh_;
247  bool forcePolyMesh_;
248 
249  QString textureIndexPropertyName_;
250  bool textureIndexPropFetched_;
251  std::map<int,QString> texIndexFileMap_;
252  OBJImporter::ObjectOptionsE trimeshOptions_;
253 };
254 
255 
256 #if defined(INCLUDE_TEMPLATES) && !defined(FILEOBJPLUGIN_C)
257 #define FILEOBJPLUGIN_TEMPLATES
258 #include "FileOBJT_impl.hh"
259 #endif
260 
261 
QString name()
Return a name for the plugin.
Definition: FileOBJ.hh:154
FileOBJPlugin()
Constructor.
Definition: FileOBJ.cc:82
Update type class.
Definition: UpdateType.hh:60
Interface to call functions across plugins.
Definition: RPCInterface.hh:61
void slotLoadDefault()
Slot called when user wants to save the given Load options as default.
Definition: FileOBJ.cc:2348
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
Definition: FileOBJ.cc:131
Logtype
Log types for Message Window.
Interface for all plugins which want to Load or Save files and create Objects.
Control OpenFlippers status bar.
Interface for all Plugins which provide scriptable Functions.
int loadObject(QString _filename)
Loads Object and converts it to a triangle mesh if possible.
Definition: FileOBJ.cc:1817
void noguiSupported()
Definition: FileOBJ.hh:134
bool writeMaterial(QString _filename, MeshT &_mesh, int _objId)
writer functions
Provide texture support for a plugin.
void slotSaveDefault()
Slot called when user wants to save the given Save options as default.
Definition: FileOBJ.cc:2359
void checkTypes(QByteArray &_bufferedFile, QString _filename, OBJImporter &_importer, QStringList &_includes)
Reader functions.
Definition: FileOBJ.cc:1297
void backupTextureCoordinates(MeshT &_mesh)
creates a backup of the original per vertex/face texture coordinates
Definition: FileOBJ.cc:437
Interface for all Plugins which do logging to the logging window of the framework.
QString getLoadFilters()
Definition: FileOBJ.cc:119
applicationStatus
Enum for the statusBar Status Icon.
DrawMode NONE
not a valid draw mode
Definition: DrawModes.cc:71
Handle for a face entity.
Definition: Handles.hh:141
Interface class from which all plugins have to be created.
void convertToOBJName(QString &_name)
Convert non-valid filenames (e.g. of groups that end with .jpg) to valid .objs.
Definition: FileOBJ.cc:426
Predefined datatypes.
Definition: DataTypes.hh:83
Interface class for file handling.
MaterialList materials_
List that contains the material properties.
Definition: FileOBJ.hh:196
QString description()
Return a description of what the plugin is doing.
Definition: FileOBJ.hh:155
void initializePlugin()
Initialize Plugin.
Definition: FileOBJ.cc:114
QWidget * saveOptionsWidget(QString)
Definition: FileOBJ.cc:2235
QString getSaveFilters()
Definition: FileOBJ.cc:125
QWidget * loadOptionsWidget(QString)
Definition: FileOBJ.cc:2297