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