0031213: Coding Rules, RWStl_Reader - misnamed variable THE_BUFFER
[occt.git] / src / RWStl / RWStl_Reader.hxx
1 // Created: 2016-05-01
2 // Author: Andrey Betenev
3 // Copyright: Open CASCADE 2016
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _RWStl_Reader_HeaderFile
17 #define _RWStl_Reader_HeaderFile
18
19 #include <gp_XYZ.hxx>
20 #include <Message_ProgressIndicator.hxx>
21 #include <Standard_ReadLineBuffer.hxx>
22
23 //! An abstract class implementing procedure to read STL file.
24 //!
25 //! This class is not bound to particular data structure and can be used to read the file directly into arbitrary data model.
26 //! To use it, create descendant class and implement methods addNode() and addTriangle().
27 //!
28 //! Call method Read() to read the file. In the process of reading, the tool will call methods addNode() and addTriangle() to fill the mesh data structure.
29 //!
30 //! The nodes with equal coordinates are merged automatically  on the fly.
31 class RWStl_Reader : public Standard_Transient
32 {
33   DEFINE_STANDARD_RTTIEXT(RWStl_Reader, Standard_Transient)
34 public:
35
36   //! Reads data from STL file (either binary or Ascii).
37   //! This function supports reading multi-domain STL files formed by concatenation of several "plain" files.
38   //! The mesh nodes are not merged between domains.
39   //! Unicode paths can be given in UTF-8 encoding.
40   //! Format is recognized automatically by analysis of the file header.
41   //! Returns true if success, false on error or user break.
42   Standard_EXPORT Standard_Boolean Read (const char* theFile,
43                                          const Handle(Message_ProgressIndicator)& theProgress);
44
45   //! Guess whether the stream is an Ascii STL file, by analysis of the first bytes (~200).
46   //! The function attempts to put back the read symbols to the stream which thus must support ungetc().
47   //! Returns true if the stream seems to contain Ascii STL.
48   Standard_EXPORT Standard_Boolean IsAscii (Standard_IStream& theStream);
49
50   //! Reads STL data from binary stream.
51   //! The stream must be opened in binary mode.
52   //! Stops after reading the number of triangles recorded in the file header.
53   //! Returns true if success, false on error or user break.
54   Standard_EXPORT Standard_Boolean ReadBinary (Standard_IStream& theStream,
55                                                const Handle(Message_ProgressIndicator)& theProgress);
56
57   //! Reads data from the stream assumed to contain Ascii STL data.
58   //! The stream can be opened either in binary or in Ascii mode.
59   //! Reading stops at the position specified by theUntilPos,
60   //! or end of file is reached, or when keyword "endsolid" is found.
61   //! Empty lines are not supported and will read to reading failure.
62   //! If theUntilPos is non-zero, reads not more than until that position.
63   //! Returns true if success, false on error or user break.
64   Standard_EXPORT Standard_Boolean ReadAscii (Standard_IStream& theStream,
65                                               Standard_ReadLineBuffer& theBuffer,
66                                               const std::streampos theUntilPos,
67                                               const Handle(Message_ProgressIndicator)& theProgress);
68
69 public:
70
71   //! Callback function to be implemented in descendant.
72   //! Should create new node with specified coordinates in the target model, and return its ID as integer.
73   virtual Standard_Integer AddNode (const gp_XYZ& thePnt) = 0;
74
75   //! Callback function to be implemented in descendant.
76   //! Should create new triangle built on specified nodes in the target model.
77   virtual void AddTriangle (Standard_Integer theN1, Standard_Integer theN2, Standard_Integer theN3) = 0;
78
79 };
80
81 #endif