0032099: Visualization - define OSD_FileSystem class managing opening of file streams
[occt.git] / src / RWGltf / RWGltf_PrimitiveArrayReader.hxx
1 // Author: Kirill Gavrilov
2 // Copyright (c) 2019 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #ifndef _RWGltf_PrimitiveArrayReader_HeaderFile
16 #define _RWGltf_PrimitiveArrayReader_HeaderFile
17
18 #include <Poly_Triangulation.hxx>
19 #include <RWMesh_CoordinateSystemConverter.hxx>
20 #include <RWGltf_GltfAccessor.hxx>
21 #include <RWGltf_GltfArrayType.hxx>
22 #include <RWGltf_GltfPrimitiveMode.hxx>
23 #include <TCollection_AsciiString.hxx>
24
25 class RWGltf_GltfLatePrimitiveArray;
26 class OSD_FileSystem;
27
28 //! Interface for reading primitive array from glTF buffer.
29 class RWGltf_PrimitiveArrayReader : public Standard_Transient
30 {
31   DEFINE_STANDARD_RTTIEXT(RWGltf_PrimitiveArrayReader, Standard_Transient)
32 public:
33
34   //! Constructor.
35   RWGltf_PrimitiveArrayReader() {}
36
37   //! Return prefix for reporting issues.
38   const TCollection_AsciiString& ErrorPrefix() const { return myErrorPrefix; }
39
40   //! Set prefix for reporting issues.
41   void SetErrorPrefix (const TCollection_AsciiString& theErrPrefix) { myErrorPrefix = theErrPrefix; }
42
43   //! Return transformation from glTF to OCCT coordinate system.
44   const RWMesh_CoordinateSystemConverter& CoordinateSystemConverter() const { return myCoordSysConverter; }
45
46   //! Set transformation from glTF to OCCT coordinate system.
47   void SetCoordinateSystemConverter (const RWMesh_CoordinateSystemConverter& theConverter) { myCoordSysConverter = theConverter; }
48
49   //! Load primitive array.
50   Handle(Poly_Triangulation) Load (const Handle(RWGltf_GltfLatePrimitiveArray)& theMesh,
51                                    const Handle(OSD_FileSystem)& theFileSystem)
52   {
53     if (load (theMesh, theFileSystem))
54     {
55       return result();
56     }
57     return Handle(Poly_Triangulation)();
58   }
59
60 protected:
61
62   //! Reset cache before loading primitive array.
63   Standard_EXPORT virtual void reset() = 0;
64
65   //! Load primitive array.
66   Standard_EXPORT virtual bool load (const Handle(RWGltf_GltfLatePrimitiveArray)& theMesh,
67                                      const Handle(OSD_FileSystem)& theFileSystem);
68
69   //! Return result primitive array.
70   Standard_EXPORT virtual Handle(Poly_Triangulation) result() = 0;
71
72   //! Read primitive array data.
73   //! @param theStream   input stream to read from
74   //! @param theName     entity name for logging errors
75   //! @param theAccessor buffer accessor
76   //! @param theType     array type
77   //! @param theMode     primitive mode
78   //! @return FALSE on error
79   Standard_EXPORT virtual bool readBuffer (std::istream& theStream,
80                                            const TCollection_AsciiString& theName,
81                                            const RWGltf_GltfAccessor& theAccessor,
82                                            RWGltf_GltfArrayType theType,
83                                            RWGltf_GltfPrimitiveMode theMode) = 0;
84
85   //! Report error.
86   Standard_EXPORT virtual void reportError (const TCollection_AsciiString& theText);
87
88 protected:
89
90   TCollection_AsciiString          myErrorPrefix;
91   RWMesh_CoordinateSystemConverter myCoordSysConverter;
92
93 };
94
95 #endif // _RWGltf_PrimitiveArrayReader_HeaderFile