Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:43

0001 // Copyright (c) 2015-2021 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _RWObj_ObjWriterContext_HeaderFiler
0015 #define _RWObj_ObjWriterContext_HeaderFiler
0016 
0017 #include <Graphic3d_Vec.hxx>
0018 #include <TCollection_AsciiString.hxx>
0019 #include <TColStd_IndexedDataMapOfStringString.hxx>
0020 
0021 //! Auxiliary low-level tool writing OBJ file.
0022 class RWObj_ObjWriterContext
0023 {
0024 public:
0025 
0026   //! Main constructor.
0027   Standard_EXPORT RWObj_ObjWriterContext (const TCollection_AsciiString& theName);
0028 
0029   //! Destructor, will emit error message if file was not closed.
0030   Standard_EXPORT ~RWObj_ObjWriterContext();
0031 
0032   //! Return true if file has been opened.
0033   bool IsOpened() const { return myFile != NULL; }
0034 
0035   //! Correctly close the file.
0036   Standard_EXPORT bool Close();
0037 
0038   //! Return true if normals are defined.
0039   bool HasNormals() const { return myHasNormals; }
0040 
0041   //! Set if normals are defined.
0042   void SetNormals (const bool theHasNormals) { myHasNormals = theHasNormals; }
0043 
0044   //! Return true if normals are defined.
0045   bool HasTexCoords() const { return myHasTexCoords; }
0046 
0047   //! Set if normals are defined.
0048   void SetTexCoords (const bool theHasTexCoords) { myHasTexCoords = theHasTexCoords; }
0049 
0050   //! Write the header.
0051   Standard_EXPORT bool WriteHeader (const Standard_Integer theNbNodes,
0052                                     const Standard_Integer theNbElems,
0053                                     const TCollection_AsciiString& theMatLib,
0054                                     const TColStd_IndexedDataMapOfStringString& theFileInfo);
0055 
0056   //! Return active material or empty string if not set.
0057   const TCollection_AsciiString& ActiveMaterial() const { return myActiveMaterial; }
0058 
0059   //! Set active material.
0060   Standard_EXPORT bool WriteActiveMaterial (const TCollection_AsciiString& theMaterial);
0061 
0062   //! Writing a triangle
0063   Standard_EXPORT bool WriteTriangle (const Graphic3d_Vec3i& theTri);
0064 
0065   //! Writing a quad
0066   Standard_EXPORT bool WriteQuad (const Graphic3d_Vec4i& theQuad);
0067 
0068   //! Writing a vector
0069   Standard_EXPORT bool WriteVertex (const Graphic3d_Vec3& theValue);
0070 
0071   //! Writing a vector
0072   Standard_EXPORT bool WriteNormal (const Graphic3d_Vec3& theValue);
0073 
0074   //! Writing a vector
0075   Standard_EXPORT bool WriteTexCoord (const Graphic3d_Vec2& theValue);
0076 
0077   //! Writing a group name
0078   Standard_EXPORT bool WriteGroup (const TCollection_AsciiString& theValue);
0079 
0080   //! Increment indices shift.
0081   Standard_EXPORT void FlushFace (Standard_Integer theNbNodes);
0082 
0083 public:
0084 
0085   Standard_Integer NbFaces;
0086 
0087 private:
0088 
0089   FILE* myFile;
0090   TCollection_AsciiString myName;
0091   TCollection_AsciiString myActiveMaterial;
0092   Graphic3d_Vec4i myElemPosFirst;
0093   Graphic3d_Vec4i myElemNormFirst;
0094   Graphic3d_Vec4i myElemUVFirst;
0095   bool myHasNormals;
0096   bool myHasTexCoords;
0097 
0098 };
0099 
0100 #endif // _RWObj_ObjWriterContext_HeaderFiler