Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/opencascade/RWObj_ObjWriterContext.hxx was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 <NCollection_Vec2.hxx>
0018 
0019 #include <Standard_TypeDef.hxx>
0020 
0021 #include <NCollection_Vec3.hxx>
0022 
0023 #include <NCollection_Vec4.hxx>
0024 
0025 #include <NCollection_Mat4.hxx>
0026 #include <TCollection_AsciiString.hxx>
0027 #include <NCollection_IndexedDataMap.hxx>
0028 
0029 //! Auxiliary low-level tool writing OBJ file.
0030 class RWObj_ObjWriterContext
0031 {
0032 public:
0033   //! Main constructor.
0034   Standard_EXPORT RWObj_ObjWriterContext(const TCollection_AsciiString& theName);
0035 
0036   //! Destructor, will emit error message if file was not closed.
0037   Standard_EXPORT ~RWObj_ObjWriterContext();
0038 
0039   //! Return true if file has been opened.
0040   bool IsOpened() const { return myFile != nullptr; }
0041 
0042   //! Correctly close the file.
0043   Standard_EXPORT bool Close();
0044 
0045   //! Return true if normals are defined.
0046   bool HasNormals() const { return myHasNormals; }
0047 
0048   //! Set if normals are defined.
0049   void SetNormals(const bool theHasNormals) { myHasNormals = theHasNormals; }
0050 
0051   //! Return true if normals are defined.
0052   bool HasTexCoords() const { return myHasTexCoords; }
0053 
0054   //! Set if normals are defined.
0055   void SetTexCoords(const bool theHasTexCoords) { myHasTexCoords = theHasTexCoords; }
0056 
0057   //! Write the header.
0058   Standard_EXPORT bool WriteHeader(
0059     const int                      theNbNodes,
0060     const int                      theNbElems,
0061     const TCollection_AsciiString& theMatLib,
0062     const NCollection_IndexedDataMap<TCollection_AsciiString, TCollection_AsciiString>&
0063       theFileInfo);
0064 
0065   //! Return active material or empty string if not set.
0066   const TCollection_AsciiString& ActiveMaterial() const { return myActiveMaterial; }
0067 
0068   //! Set active material.
0069   Standard_EXPORT bool WriteActiveMaterial(const TCollection_AsciiString& theMaterial);
0070 
0071   //! Writing a triangle
0072   Standard_EXPORT bool WriteTriangle(const NCollection_Vec3<int>& theTri);
0073 
0074   //! Writing a quad
0075   Standard_EXPORT bool WriteQuad(const NCollection_Vec4<int>& theQuad);
0076 
0077   //! Writing a vector
0078   Standard_EXPORT bool WriteVertex(const NCollection_Vec3<float>& theValue);
0079 
0080   //! Writing a vector
0081   Standard_EXPORT bool WriteNormal(const NCollection_Vec3<float>& theValue);
0082 
0083   //! Writing a vector
0084   Standard_EXPORT bool WriteTexCoord(const NCollection_Vec2<float>& theValue);
0085 
0086   //! Writing a group name
0087   Standard_EXPORT bool WriteGroup(const TCollection_AsciiString& theValue);
0088 
0089   //! Increment indices shift.
0090   Standard_EXPORT void FlushFace(int theNbNodes);
0091 
0092 public:
0093   int NbFaces;
0094 
0095 private:
0096   FILE*                   myFile;
0097   TCollection_AsciiString myName;
0098   TCollection_AsciiString myActiveMaterial;
0099   NCollection_Vec4<int>   myElemPosFirst;
0100   NCollection_Vec4<int>   myElemNormFirst;
0101   NCollection_Vec4<int>   myElemUVFirst;
0102   bool                    myHasNormals;
0103   bool                    myHasTexCoords;
0104 };
0105 
0106 #endif // _RWObj_ObjWriterContext_HeaderFiler