0029570: Visualization, Graphic3d_Aspect - merge Graphic3d_Group aspects
[occt.git] / src / OpenGl / OpenGl_Group.hxx
1 // Created on: 2011-08-01
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-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 _OpenGl_Group_Header
17 #define _OpenGl_Group_Header
18
19 #include <Graphic3d_Group.hxx>
20 #include <Graphic3d_Structure.hxx>
21
22 #include <NCollection_List.hxx>
23 #include <OpenGl_Aspects.hxx>
24 #include <OpenGl_Element.hxx>
25
26 class OpenGl_Group;
27 class OpenGl_Structure;
28
29 struct OpenGl_ElementNode
30 {
31   OpenGl_Element*     elem;
32   OpenGl_ElementNode* next;
33   DEFINE_STANDARD_ALLOC
34 };
35
36 //! Implementation of low-level graphic group.
37 class OpenGl_Group : public Graphic3d_Group
38 {
39 public:
40
41   //! Create empty group.
42   //! Will throw exception if not created by OpenGl_Structure.
43   Standard_EXPORT OpenGl_Group (const Handle(Graphic3d_Structure)& theStruct);
44
45   Standard_EXPORT virtual void Clear (const Standard_Boolean theToUpdateStructureMgr) Standard_OVERRIDE;
46
47   //! Return line aspect.
48   virtual Handle(Graphic3d_Aspects) Aspects() const Standard_OVERRIDE
49   {
50     return myAspects != NULL
51          ? myAspects->Aspect()
52          : Handle(Graphic3d_Aspects)();
53   }
54
55   //! Update aspect.
56   Standard_EXPORT virtual void SetGroupPrimitivesAspect (const Handle(Graphic3d_Aspects)& theAspect) Standard_OVERRIDE;
57
58   //! Append aspect as an element.
59   Standard_EXPORT virtual void SetPrimitivesAspect (const Handle(Graphic3d_Aspects)& theAspect) Standard_OVERRIDE;
60
61   //! Update presentation aspects after their modification.
62   Standard_EXPORT virtual void SynchronizeAspects() Standard_OVERRIDE;
63
64   //! Replace aspects specified in the replacement map.
65   Standard_EXPORT virtual void ReplaceAspects (const Graphic3d_MapOfAspectsToAspects& theMap) Standard_OVERRIDE;
66
67   //! Add primitive array element
68   Standard_EXPORT virtual void AddPrimitiveArray (const Graphic3d_TypeOfPrimitiveArray theType,
69                                                   const Handle(Graphic3d_IndexBuffer)& theIndices,
70                                                   const Handle(Graphic3d_Buffer)&      theAttribs,
71                                                   const Handle(Graphic3d_BoundBuffer)& theBounds,
72                                                   const Standard_Boolean               theToEvalMinMax) Standard_OVERRIDE;
73
74   //! Add text element
75   Standard_EXPORT virtual void Text (const Standard_CString                  theTextUtf,
76                                      const Graphic3d_Vertex&                 thePoint,
77                                      const Standard_Real                     theHeight,
78                                      const Standard_Real                     theAngle,
79                                      const Graphic3d_TextPath                theTp,
80                                      const Graphic3d_HorizontalTextAlignment theHta,
81                                      const Graphic3d_VerticalTextAlignment   theVta,
82                                      const Standard_Boolean                  theToEvalMinMax) Standard_OVERRIDE;
83
84   //! Add text element in 3D space.
85   Standard_EXPORT virtual void Text (const Standard_CString                  theTextUtf,
86                                      const gp_Ax2&                           theOrientation,
87                                      const Standard_Real                     theHeight,
88                                      const Standard_Real                     theAngle,
89                                      const Graphic3d_TextPath                theTp,
90                                      const Graphic3d_HorizontalTextAlignment theHTA,
91                                      const Graphic3d_VerticalTextAlignment   theVTA,
92                                      const Standard_Boolean                  theToEvalMinMax,
93                                      const Standard_Boolean                  theHasOwnAnchor = Standard_True) Standard_OVERRIDE;
94
95   //! Add flipping element
96   Standard_EXPORT virtual void SetFlippingOptions (const Standard_Boolean theIsEnabled,
97                                                    const gp_Ax2&          theRefPlane) Standard_OVERRIDE;
98
99   //! Add stencil test element
100   Standard_EXPORT virtual void SetStencilTestOptions (const Standard_Boolean theIsEnabled) Standard_OVERRIDE;
101
102 public:
103
104   OpenGl_Structure* GlStruct() const { return (OpenGl_Structure* )(myStructure->CStructure().operator->()); }
105
106   Standard_EXPORT void AddElement (OpenGl_Element* theElem);
107
108   Standard_EXPORT virtual void Render  (const Handle(OpenGl_Workspace)& theWorkspace) const;
109   Standard_EXPORT virtual void Release (const Handle(OpenGl_Context)&   theGlCtx);
110
111   //! Returns first OpenGL element node of the group.
112   const OpenGl_ElementNode* FirstNode() const { return myFirst; }
113
114   //! Returns OpenGL aspect.
115   const OpenGl_Aspects* GlAspects() const { return myAspects; }
116
117   //! Is the group ray-tracable (contains ray-tracable elements)?
118   Standard_Boolean IsRaytracable() const { return myIsRaytracable; }
119
120 protected:
121
122   Standard_EXPORT virtual ~OpenGl_Group();
123
124 protected:
125
126   OpenGl_Aspects*     myAspects;
127   OpenGl_ElementNode* myFirst;
128   OpenGl_ElementNode* myLast;
129   Standard_Boolean    myIsRaytracable;
130
131 public:
132
133   DEFINE_STANDARD_RTTIEXT(OpenGl_Group,Graphic3d_Group) // Type definition
134
135 };
136
137 DEFINE_STANDARD_HANDLE(OpenGl_Group, Graphic3d_Group)
138
139 #endif // _OpenGl_Group_Header