0027670: Visualization - avoid duplication of structures defining primitive array...
[occt.git] / src / Graphic3d / Graphic3d_Group.hxx
1 // Created on: 1991-09-06
2 // Created by: NW,JPB,CAL
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _Graphic3d_Group_HeaderFile
18 #define _Graphic3d_Group_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
22
23 #include <Graphic3d_CBitFields4.hxx>
24 #include <Graphic3d_StructurePtr.hxx>
25 #include <Graphic3d_BndBox4f.hxx>
26 #include <Standard_Boolean.hxx>
27 #include <Graphic3d_AspectLine3d.hxx>
28 #include <Graphic3d_AspectFillArea3d.hxx>
29 #include <Graphic3d_AspectText3d.hxx>
30 #include <Graphic3d_AspectMarker3d.hxx>
31 #include <MMgt_TShared.hxx>
32 #include <Standard_Real.hxx>
33 #include <Standard_CString.hxx>
34 #include <Graphic3d_Vertex.hxx>
35 #include <Quantity_PlaneAngle.hxx>
36 #include <Graphic3d_TextPath.hxx>
37 #include <Graphic3d_HorizontalTextAlignment.hxx>
38 #include <Graphic3d_VerticalTextAlignment.hxx>
39 #include <Graphic3d_TypeOfPrimitiveArray.hxx>
40 #include <Graphic3d_IndexBuffer.hxx>
41 #include <Graphic3d_Buffer.hxx>
42 #include <Graphic3d_BoundBuffer.hxx>
43 #include <Standard_Address.hxx>
44 #include <Graphic3d_GroupAspect.hxx>
45 #include <gp_Ax2.hxx>
46 #include <TCollection_ExtendedString.hxx>
47
48 class Graphic3d_Structure;
49 class Graphic3d_GroupDefinitionError;
50 class Standard_OutOfRange;
51 class Graphic3d_ArrayOfPrimitives;
52
53
54 class Graphic3d_Group;
55 DEFINE_STANDARD_HANDLE(Graphic3d_Group, MMgt_TShared)
56
57 //! This class allows the definition of groups
58 //! of primitives inside of graphic objects (presentations).
59 //! A group contains the primitives and attributes
60 //! for which the range is limited to this group.
61 //! The primitives of a group can be globally suppressed.
62 //!
63 //! There are two main group usage models:
64 //!
65 //! 1) Non-modifiable, or unbounded, group ('black box').
66 //! Developers can repeat a sequence of
67 //! SetPrimitivesAspect() with AddPrimitiveArray() methods arbitrary number of times
68 //! to define arbitrary number of primitive "blocks" each having individual apect values.
69 //! Any modification of such a group is forbidden, as aspects and primitives are mixed
70 //! in memory without any high-level logical structure, and any modification is very likely to result
71 //! in corruption of the group internal data.
72 //! It is necessary to recreate such a group as a whole when some attribute should be changed.
73 //! (for example, in terms of AIS it is necessary to re-Compute() the whole presentation each time).
74 //! 2) Bounded group. Developers should specify the necessary group aspects with help of
75 //! SetGroupPrimitivesAspect() and then add primitives to the group.
76 //! Such a group have simplified organization in memory (a single block of attributes
77 //! followed by a block of primitives) and therefore it can be modified, if it is necessary to
78 //! change parameters of some aspect that has already been set, using methods:
79 //! IsGroupPrimitivesAspectSet() to detect which aspect was set for primitives;
80 //! GroupPrimitivesAspect() to read current aspect values
81 //! and SetGroupPrimitivesAspect() to set new values.
82 //!
83 //! Developers are strongly recommended to take all the above into account when filling Graphic3d_Group
84 //! with aspects and primitives and choose the group usage model beforehand out of application needs.
85 //! Note that some Graphic3d_Group class virtual methods contain only base implementation
86 //! that is extended by the descendant class in OpenGl package.
87 class Graphic3d_Group : public MMgt_TShared
88 {
89
90 public:
91
92
93   //! Supress all primitives and attributes of <me>.
94   //! To clear group without update in Graphic3d_StructureManager
95   //! pass Standard_False as <theUpdateStructureMgr>. This
96   //! used on context and viewer destruction, when the pointer
97   //! to structure manager in Graphic3d_Structure could be
98   //! already released (pointers are used here to avoid handle
99   //! cross-reference);
100   Standard_EXPORT virtual void Clear (const Standard_Boolean theUpdateStructureMgr = Standard_True);
101
102   //! Supress the group <me> in the structure.
103   Standard_EXPORT void Destroy();
104 ~Graphic3d_Group()
105 {
106   Destroy();
107 }
108
109   //! Supress the group <me> in the structure.
110   //! Warning: No more graphic operations in <me> after this call.
111   //! Modifies the current modelling transform persistence (pan, zoom or rotate)
112   //! Get the current modelling transform persistence (pan, zoom or rotate)
113   Standard_EXPORT void Remove();
114
115   //! Return line aspect.
116   virtual Handle(Graphic3d_AspectLine3d) LineAspect() const = 0;
117
118   //! Assign line aspect to the group.
119   virtual void SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspect) = 0;
120
121   //! Return fill area aspect.
122   virtual Handle(Graphic3d_AspectFillArea3d) FillAreaAspect() const = 0;
123
124   //! Modifies the context for all the face primitives of the group.
125   virtual void SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect) = 0;
126
127   //! Return text aspect.
128   virtual Handle(Graphic3d_AspectText3d) TextAspect() const = 0;
129
130   //! Modifies the context for all the text primitives of the group.
131   virtual void SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& theAspect) = 0;
132
133   //! Return marker aspect.
134   virtual Handle(Graphic3d_AspectMarker3d) MarkerAspect() const = 0;
135
136   //! Modifies the context for all the marker primitives of the group.
137   virtual void SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& theAspect) = 0;
138
139   //! Modifies the current context of the group to give
140   //! another aspect for all the line primitives created
141   //! after this call in the group.
142   virtual void SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspect) = 0;
143
144   //! Modifies the current context of the group to give
145   //! another aspect for all the face primitives created
146   //! after this call in the group.
147   virtual void SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect) = 0;
148
149   //! Modifies the current context of the group to give
150   //! another aspect for all the text primitives created
151   //! after this call in the group.
152   virtual void SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& theAspect) = 0;
153
154   //! Modifies the current context of the group to give
155   //! another aspect for all the marker primitives created
156   //! after this call in the group.
157   virtual void SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& theAspect) = 0;
158
159   //! Sets the coordinates of the boundary box of the
160   //! group <me>.
161   Standard_EXPORT void SetMinMaxValues (const Standard_Real XMin, const Standard_Real YMin, const Standard_Real ZMin, const Standard_Real XMax, const Standard_Real YMax, const Standard_Real ZMax);
162
163   //! Creates the string <AText> at position <APoint>.
164   //! The 3D point of attachment is projected. The text is
165   //! written in the plane of projection.
166   //! The attributes are given with respect to the plane of
167   //! projection.
168   //! AHeight : Height of text.
169   //! (Relative to the Normalized Projection
170   //! Coordinates (NPC) Space).
171   //! AAngle  : Orientation of the text
172   //! (with respect to the horizontal).
173   Standard_EXPORT virtual void Text (const Standard_CString AText, const Graphic3d_Vertex& APoint, const Standard_Real AHeight, const Quantity_PlaneAngle AAngle, const Graphic3d_TextPath ATp, const Graphic3d_HorizontalTextAlignment AHta, const Graphic3d_VerticalTextAlignment AVta, const Standard_Boolean EvalMinMax = Standard_True);
174
175   //! Creates the string <AText> at position <APoint>.
176   //! The 3D point of attachment is projected. The text is
177   //! written in the plane of projection.
178   //! The attributes are given with respect to the plane of
179   //! projection.
180   //! AHeight : Height of text.
181   //! (Relative to the Normalized Projection
182   //! Coordinates (NPC) Space).
183   //! The other attributes have the following default values:
184   //! AAngle  : PI / 2.
185   //! ATp     : TP_RIGHT
186   //! AHta    : HTA_LEFT
187   //! AVta    : VTA_BOTTOM
188   Standard_EXPORT void Text (const Standard_CString AText, const Graphic3d_Vertex& APoint, const Standard_Real AHeight, const Standard_Boolean EvalMinMax = Standard_True);
189
190   //! Creates the string <AText> at position <APoint>.
191   //! The 3D point of attachment is projected. The text is
192   //! written in the plane of projection.
193   //! The attributes are given with respect to the plane of
194   //! projection.
195   //! AHeight : Height of text.
196   //! (Relative to the Normalized Projection
197   //! Coordinates (NPC) Space).
198   //! AAngle  : Orientation of the text
199   //! (with respect to the horizontal).
200   Standard_EXPORT void Text (const TCollection_ExtendedString& AText, const Graphic3d_Vertex& APoint, const Standard_Real AHeight, const Quantity_PlaneAngle AAngle, const Graphic3d_TextPath ATp, const Graphic3d_HorizontalTextAlignment AHta, const Graphic3d_VerticalTextAlignment AVta, const Standard_Boolean EvalMinMax = Standard_True);
201
202   //! Creates the string <AText> at position <APoint>.
203   //! The 3D point of attachment is projected. The text is
204   //! written in the plane of projection.
205   //! The attributes are given with respect to the plane of
206   //! projection.
207   //! AHeight : Height of text.
208   //! (Relative to the Normalized Projection
209   //! Coordinates (NPC) Space).
210   //! The other attributes have the following default values:
211   //! AAngle  : PI / 2.
212   //! ATp     : TP_RIGHT
213   //! AHta    : HTA_LEFT
214   //! AVta    : VTA_BOTTOM
215   Standard_EXPORT void Text (const TCollection_ExtendedString& AText, const Graphic3d_Vertex& APoint, const Standard_Real AHeight, const Standard_Boolean EvalMinMax = Standard_True);
216
217   //! Creates the string <theText> at orientation <theOrientation> in 3D space.
218   Standard_EXPORT virtual void Text (const Standard_CString                  theTextUtf,
219                                      const gp_Ax2&                           theOrientation,
220                                      const Standard_Real                     theHeight,
221                                      const Quantity_PlaneAngle               theAngle,
222                                      const Graphic3d_TextPath                theTp,
223                                      const Graphic3d_HorizontalTextAlignment theHTA,
224                                      const Graphic3d_VerticalTextAlignment   theVTA,
225                                      const Standard_Boolean                  theToEvalMinMax = Standard_True,
226                                      const Standard_Boolean                  theHasOwnAnchor = Standard_True);
227
228   //! Creates the string <theText> at orientation <theOrientation> in 3D space.
229   Standard_EXPORT virtual void Text (const TCollection_ExtendedString&       theText,
230                                      const gp_Ax2&                           theOrientation,
231                                      const Standard_Real                     theHeight,
232                                      const Quantity_PlaneAngle               theAngle,
233                                      const Graphic3d_TextPath                theTp,
234                                      const Graphic3d_HorizontalTextAlignment theHTA,
235                                      const Graphic3d_VerticalTextAlignment   theVTA,
236                                      const Standard_Boolean                  theToEvalMinMax = Standard_True,
237                                      const Standard_Boolean                  theHasOwnAnchor = Standard_True);
238
239
240   //! Adds an array of primitives for display
241   Standard_EXPORT virtual void AddPrimitiveArray (const Graphic3d_TypeOfPrimitiveArray theType, const Handle(Graphic3d_IndexBuffer)& theIndices, const Handle(Graphic3d_Buffer)& theAttribs, const Handle(Graphic3d_BoundBuffer)& theBounds, const Standard_Boolean theToEvalMinMax = Standard_True);
242
243   //! Adds an array of primitives for display
244   Standard_EXPORT void AddPrimitiveArray (const Handle(Graphic3d_ArrayOfPrimitives)& thePrim, const Standard_Boolean theToEvalMinMax = Standard_True);
245
246   //! Creates a primitive array with single marker using AddPrimitiveArray().
247   Standard_EXPORT void Marker (const Graphic3d_Vertex& thePoint, const Standard_Boolean theToEvalMinMax = Standard_True);
248
249   //! sets the stencil test to theIsEnabled state;
250   Standard_EXPORT virtual void SetStencilTestOptions (const Standard_Boolean theIsEnabled) = 0;
251
252   //! sets the flipping to theIsEnabled state.
253   Standard_EXPORT virtual void SetFlippingOptions (const Standard_Boolean theIsEnabled, const gp_Ax2& theRefPlane) = 0;
254
255   //! Returns TRUE if aspect is set for the group.
256   Standard_EXPORT Standard_Boolean IsGroupPrimitivesAspectSet (const Graphic3d_GroupAspect theAspect) const;
257
258   //! Returns the context of all the primitives of the group.
259   Standard_EXPORT void GroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTXL, const Handle(Graphic3d_AspectText3d)& CTXT, const Handle(Graphic3d_AspectMarker3d)& CTXM, const Handle(Graphic3d_AspectFillArea3d)& CTXF) const;
260
261   //! Returns the last inserted context in the group <me>
262   //! foreach kind of primitives.
263   Standard_EXPORT void PrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTXL, const Handle(Graphic3d_AspectText3d)& CTXT, const Handle(Graphic3d_AspectMarker3d)& CTXM, const Handle(Graphic3d_AspectFillArea3d)& CTXF) const;
264
265   //! Returns Standard_True if the group <me> contains
266   //! Polygons, Triangles or Quadrangles.
267   Standard_EXPORT Standard_Boolean ContainsFacet() const;
268
269   //! Returns Standard_True if the group <me> is deleted.
270   //! <me> is deleted after the call Remove (me) or the
271   //! associated structure is deleted.
272   Standard_EXPORT Standard_Boolean IsDeleted() const;
273
274   //! Returns Standard_True if the group <me> is empty.
275   Standard_EXPORT Standard_Boolean IsEmpty() const;
276
277   //! Returns the coordinates of the boundary box of the
278   //! group <me>.
279   Standard_EXPORT void MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const;
280
281   //! Returns boundary box of the group <me> without transformation applied,
282   const Graphic3d_BndBox4f& BoundingBox() const { return myBounds; }
283
284   //! Returns non-const boundary box of the group <me> without transformation applied,
285   Graphic3d_BndBox4f& ChangeBoundingBox() { return myBounds; }
286
287   //! Returns the structure containing the group <me>.
288   Standard_EXPORT Handle(Graphic3d_Structure) Structure() const;
289
290   //! Changes property shown that primitive arrays within this group form closed volume (do no contain open shells).
291   void SetClosed (const bool theIsClosed) { myIsClosed = theIsClosed; }
292
293   //! Return true if primitive arrays within this graphic group form closed volume (do no contain open shells).
294   bool IsClosed() const { return myIsClosed; }
295
296 friend class Graphic3d_Structure;
297
298
299   DEFINE_STANDARD_RTTIEXT(Graphic3d_Group,MMgt_TShared)
300
301 protected:
302
303
304   //! Creates a group in the structure <AStructure>.
305   Standard_EXPORT Graphic3d_Group(const Handle(Graphic3d_Structure)& theStructure);
306
307   Graphic3d_CBitFields4 myCBitFields;
308   Graphic3d_StructurePtr myStructure;
309   Graphic3d_BndBox4f myBounds;
310   bool myIsClosed;
311
312 protected:
313
314
315   //! Returns the extreme coordinates found in the group.
316   Standard_EXPORT void MinMaxCoord (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const;
317
318   //! Calls the Update method of the StructureManager which
319   //! contains the associated Structure of the Group <me>.
320   Standard_EXPORT void Update() const;
321
322
323
324 };
325
326
327
328
329
330
331
332 #endif // _Graphic3d_Group_HeaderFile