0024023: Revamp the OCCT Handle -- general
[occt.git] / src / VrmlData / VrmlData_ShapeConvert.hxx
1 // Created on: 2007-08-04
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
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 VrmlData_ShapeConvert_HeaderFile
17 #define VrmlData_ShapeConvert_HeaderFile
18
19 #include <VrmlData_Geometry.hxx>
20 #include <VrmlData_Appearance.hxx>
21 #include <NCollection_List.hxx>
22 #include <TopoDS_Shape.hxx>
23
24 class VrmlData_Scene;
25 class VrmlData_Coordinate;
26 class TopoDS_Face;
27 class Poly_Polygon3D;
28 class Poly_Triangulation;
29
30 /**
31  * Algorithm converting one shape or a set of shapes to VrmlData_Scene.
32  */
33
34 class VrmlData_ShapeConvert 
35 {
36  public:
37
38   typedef struct {
39     TCollection_AsciiString Name;
40     TopoDS_Shape            Shape;
41     Handle(VrmlData_Node)   Node;
42   } ShapeData;
43
44   // ---------- PUBLIC METHODS ----------
45
46
47   /**
48    * Constructor.
49    * @param theScene
50    *   Scene receiving all Vrml data.
51    * @param theScale
52    *   Scale factor, considering that VRML standard specifies coordinates in
53    *   meters. So if your data are in mm, you should provide theScale=0.001
54    */
55   inline VrmlData_ShapeConvert (VrmlData_Scene&     theScene,
56                                 const Standard_Real theScale = 1.)
57     : myScene (theScene),
58       myScale (theScale)
59   {}
60
61   /**
62    * Add one shape to the internal list, may be called several times with
63    * different shapes.
64    */
65   Standard_EXPORT void AddShape (const TopoDS_Shape& theShape,
66                                  const char *        theName = 0L);
67
68   /**
69    * Convert all accumulated shapes and store them in myScene.
70    * The internal data structures are cleared in the end of convertion.
71    * @param theExtractFaces
72    *   If True,  converter extracst faces from the shapes. 
73    * @param theExtractEdges
74    *   If True,  converter extracts edges from the shapes.
75    * @param theDeflection 
76    *   Deflection for tessellation of geometrical lines/surfaces. Existing mesh
77    *   is used if its deflection is smaller than the one given by this
78    *   parameter.
79    * @param theDeflAngle 
80    *   Angular deflection for tessellation of geometrical lines. 
81    */
82   Standard_EXPORT void Convert (const Standard_Boolean theExtractFaces,
83                                 const Standard_Boolean theExtractEdges,
84                                 const Standard_Real    theDeflection = 0.01,
85                                 const Standard_Real    theDeflAngle = 20.*M_PI/180.);
86                                 //this value of theDeflAngle is used by default 
87                                 //for tesselation while shading (Drawer->HLRAngle())
88  protected:
89   // ---------- PROTECTED METHODS ----------
90
91   Handle(VrmlData_Geometry) triToIndexedFaceSet
92                                 (const Handle(Poly_Triangulation)&,
93                                  const TopoDS_Face&,
94                                  const Handle(VrmlData_Coordinate)&);
95
96   Handle(VrmlData_Geometry) polToIndexedLineSet
97                                 (const Handle(Poly_Polygon3D)&);
98
99   Handle(VrmlData_Appearance) defaultMaterialFace () const;
100
101   Handle(VrmlData_Appearance) defaultMaterialEdge () const;
102
103  private:
104   // ---------- PRIVATE FIELDS ----------
105
106   VrmlData_Scene&                       myScene;
107   Standard_Real                         myScale;
108   NCollection_List <ShapeData>          myShapes;
109   // ---------- PRIVATE METHODS ----------
110   void operator= (const VrmlData_ShapeConvert&);
111 };
112
113 #endif