fb6748302edb32fa49a0635d5c12d3e911357c76
[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 <Graphic3d_BndBox4f.hxx>
21 #include <Graphic3d_AspectLine3d.hxx>
22 #include <Graphic3d_AspectFillArea3d.hxx>
23 #include <Graphic3d_AspectText3d.hxx>
24 #include <Graphic3d_AspectMarker3d.hxx>
25 #include <Graphic3d_MapOfAspectsToAspects.hxx>
26 #include <Standard_CString.hxx>
27 #include <Graphic3d_Vertex.hxx>
28 #include <Graphic3d_TextPath.hxx>
29 #include <Graphic3d_HorizontalTextAlignment.hxx>
30 #include <Graphic3d_VerticalTextAlignment.hxx>
31 #include <Graphic3d_TypeOfPrimitiveArray.hxx>
32 #include <Graphic3d_IndexBuffer.hxx>
33 #include <Graphic3d_Buffer.hxx>
34 #include <Graphic3d_BoundBuffer.hxx>
35 #include <gp_Ax2.hxx>
36 #include <TCollection_ExtendedString.hxx>
37
38 class Graphic3d_Structure;
39 class Graphic3d_ArrayOfPrimitives;
40 class Graphic3d_Text;
41
42 //! This class allows the definition of groups
43 //! of primitives inside of graphic objects (presentations).
44 //! A group contains the primitives and attributes
45 //! for which the range is limited to this group.
46 //! The primitives of a group can be globally suppressed.
47 //!
48 //! There are two main group usage models:
49 //!
50 //! 1) Non-modifiable, or unbounded, group ('black box').
51 //! Developers can repeat a sequence of
52 //! SetPrimitivesAspect() with AddPrimitiveArray() methods arbitrary number of times
53 //! to define arbitrary number of primitive "blocks" each having individual apect values.
54 //! Any modification of such a group is forbidden, as aspects and primitives are mixed
55 //! in memory without any high-level logical structure, and any modification is very likely to result
56 //! in corruption of the group internal data.
57 //! It is necessary to recreate such a group as a whole when some attribute should be changed.
58 //! (for example, in terms of AIS it is necessary to re-Compute() the whole presentation each time).
59 //! 2) Bounded group. Developers should specify the necessary group aspects with help of
60 //! SetGroupPrimitivesAspect() and then add primitives to the group.
61 //! Such a group have simplified organization in memory (a single block of attributes
62 //! followed by a block of primitives) and therefore it can be modified, if it is necessary to
63 //! change parameters of some aspect that has already been set, using methods:
64 //! IsGroupPrimitivesAspectSet() to detect which aspect was set for primitives;
65 //! GroupPrimitivesAspect() to read current aspect values
66 //! and SetGroupPrimitivesAspect() to set new values.
67 //!
68 //! Developers are strongly recommended to take all the above into account when filling Graphic3d_Group
69 //! with aspects and primitives and choose the group usage model beforehand out of application needs.
70 //! Note that some Graphic3d_Group class virtual methods contain only base implementation
71 //! that is extended by the descendant class in OpenGl package.
72 class Graphic3d_Group : public Standard_Transient
73 {
74   friend class Graphic3d_Structure;
75   DEFINE_STANDARD_RTTIEXT(Graphic3d_Group,Standard_Transient)
76
77 public:
78
79   //! Supress all primitives and attributes of <me>.
80   //! To clear group without update in Graphic3d_StructureManager
81   //! pass Standard_False as <theUpdateStructureMgr>. This
82   //! used on context and viewer destruction, when the pointer
83   //! to structure manager in Graphic3d_Structure could be
84   //! already released (pointers are used here to avoid handle
85   //! cross-reference);
86   Standard_EXPORT virtual void Clear (const Standard_Boolean theUpdateStructureMgr = Standard_True);
87
88   //! Supress the group <me> in the structure.
89   Standard_EXPORT virtual ~Graphic3d_Group();
90
91   //! Supress the group <me> in the structure.
92   //! Warning: No more graphic operations in <me> after this call.
93   //! Modifies the current modelling transform persistence (pan, zoom or rotate)
94   //! Get the current modelling transform persistence (pan, zoom or rotate)
95   Standard_EXPORT void Remove();
96
97 public:
98
99   //! Return fill area aspect.
100   virtual Handle(Graphic3d_Aspects) Aspects() const = 0;
101
102   //! Modifies the context for all the face primitives of the group.
103   virtual void SetGroupPrimitivesAspect (const Handle(Graphic3d_Aspects)& theAspect) = 0;
104
105   //! Modifies the current context of the group to give another aspect for all the primitives created after this call in the group.
106   virtual void SetPrimitivesAspect (const Handle(Graphic3d_Aspects)& theAspect) = 0;
107
108   //! Update presentation aspects after their modification.
109   virtual void SynchronizeAspects() = 0;
110
111   //! Replace aspects specified in the replacement map.
112   virtual void ReplaceAspects (const Graphic3d_MapOfAspectsToAspects& theMap) = 0;
113
114   //! Adds a text for display
115   Standard_EXPORT virtual void AddText (const Handle(Graphic3d_Text)& theTextParams,
116                                         const Standard_Boolean theToEvalMinMax = Standard_True);
117
118   //! Adds an array of primitives for display
119   Standard_EXPORT virtual void AddPrimitiveArray (const Graphic3d_TypeOfPrimitiveArray theType,
120                                                   const Handle(Graphic3d_IndexBuffer)& theIndices,
121                                                   const Handle(Graphic3d_Buffer)& theAttribs,
122                                                   const Handle(Graphic3d_BoundBuffer)& theBounds,
123                                                   const Standard_Boolean theToEvalMinMax = Standard_True);
124
125   //! Adds an array of primitives for display
126   Standard_EXPORT void AddPrimitiveArray (const Handle(Graphic3d_ArrayOfPrimitives)& thePrim, const Standard_Boolean theToEvalMinMax = Standard_True);
127
128   //! Creates a primitive array with single marker using AddPrimitiveArray().
129   Standard_EXPORT void Marker (const Graphic3d_Vertex& thePoint, const Standard_Boolean theToEvalMinMax = Standard_True);
130
131 public:
132
133   //! sets the stencil test to theIsEnabled state;
134   Standard_EXPORT virtual void SetStencilTestOptions (const Standard_Boolean theIsEnabled) = 0;
135
136   //! sets the flipping to theIsEnabled state.
137   Standard_EXPORT virtual void SetFlippingOptions (const Standard_Boolean theIsEnabled, const gp_Ax2& theRefPlane) = 0;
138
139   //! Returns true if the group contains Polygons, Triangles or Quadrangles.
140   bool ContainsFacet() const { return myContainsFacet; }
141
142   //! Returns Standard_True if the group <me> is deleted.
143   //! <me> is deleted after the call Remove (me) or the
144   //! associated structure is deleted.
145   Standard_EXPORT Standard_Boolean IsDeleted() const;
146
147   //! Returns Standard_True if the group <me> is empty.
148   Standard_EXPORT Standard_Boolean IsEmpty() const;
149
150   //! Returns the coordinates of the boundary box of the group.
151   Standard_EXPORT void MinMaxValues (Standard_Real& theXMin, Standard_Real& theYMin, Standard_Real& theZMin,
152                                      Standard_Real& theXMax, Standard_Real& theYMax, Standard_Real& theZMax) const;
153
154   //! Sets the coordinates of the boundary box of the group.
155   Standard_EXPORT void SetMinMaxValues (const Standard_Real theXMin, const Standard_Real theYMin, const Standard_Real theZMin,
156                                         const Standard_Real theXMax, const Standard_Real theYMax, const Standard_Real theZMax);
157
158   //! Returns boundary box of the group <me> without transformation applied,
159   const Graphic3d_BndBox4f& BoundingBox() const { return myBounds; }
160
161   //! Returns non-const boundary box of the group <me> without transformation applied,
162   Graphic3d_BndBox4f& ChangeBoundingBox() { return myBounds; }
163
164   //! Returns the structure containing the group <me>.
165   Standard_EXPORT Handle(Graphic3d_Structure) Structure() const;
166
167   //! Changes property shown that primitive arrays within this group form closed volume (do no contain open shells).
168   void SetClosed (const bool theIsClosed) { myIsClosed = theIsClosed; }
169
170   //! Return true if primitive arrays within this graphic group form closed volume (do no contain open shells).
171   bool IsClosed() const { return myIsClosed; }
172
173 //! @name obsolete methods
174 public:
175
176   //! Creates the string <AText> at position <APoint>.
177   //! The 3D point of attachment is projected. The text is
178   //! written in the plane of projection.
179   //! The attributes are given with respect to the plane of
180   //! projection.
181   //! AHeight : Height of text.
182   //! (Relative to the Normalized Projection
183   //! Coordinates (NPC) Space).
184   //! AAngle  : Orientation of the text
185   //! (with respect to the horizontal).
186   Standard_DEPRECATED("Deprecated method Text() with obsolete arguments, use AddText() instead of it")
187   Standard_EXPORT virtual void Text (const Standard_CString AText,
188                                      const Graphic3d_Vertex& APoint,
189                                      const Standard_Real AHeight,
190                                      const Standard_Real AAngle,
191                                      const Graphic3d_TextPath ATp,
192                                      const Graphic3d_HorizontalTextAlignment AHta,
193                                      const Graphic3d_VerticalTextAlignment AVta,
194                                      const Standard_Boolean EvalMinMax = Standard_True);
195
196   //! Creates the string <AText> at position <APoint>.
197   //! The 3D point of attachment is projected. The text is
198   //! written in the plane of projection.
199   //! The attributes are given with respect to the plane of
200   //! projection.
201   //! AHeight : Height of text.
202   //! (Relative to the Normalized Projection
203   //! Coordinates (NPC) Space).
204   //! The other attributes have the following default values:
205   //! AAngle  : PI / 2.
206   //! ATp     : TP_RIGHT
207   //! AHta    : HTA_LEFT
208   //! AVta    : VTA_BOTTOM
209   Standard_DEPRECATED("Deprecated method Text() with obsolete arguments, use AddText() instead of it")
210   Standard_EXPORT void Text (const Standard_CString AText,
211                              const Graphic3d_Vertex& APoint,
212                              const Standard_Real AHeight,
213                              const Standard_Boolean EvalMinMax = Standard_True);
214
215   //! Creates the string <AText> at position <APoint>.
216   //! The 3D point of attachment is projected. The text is
217   //! written in the plane of projection.
218   //! The attributes are given with respect to the plane of
219   //! projection.
220   //! AHeight : Height of text.
221   //! (Relative to the Normalized Projection
222   //! Coordinates (NPC) Space).
223   //! AAngle  : Orientation of the text
224   //! (with respect to the horizontal).
225   Standard_DEPRECATED("Deprecated method Text() with obsolete arguments, use AddText() instead of it")
226   Standard_EXPORT void Text (const TCollection_ExtendedString& AText,
227                              const Graphic3d_Vertex& APoint,
228                              const Standard_Real AHeight,
229                              const Standard_Real AAngle,
230                              const Graphic3d_TextPath ATp,
231                              const Graphic3d_HorizontalTextAlignment AHta,
232                              const Graphic3d_VerticalTextAlignment AVta,
233                              const Standard_Boolean EvalMinMax = Standard_True);
234
235   //! Creates the string <AText> at position <APoint>.
236   //! The 3D point of attachment is projected. The text is
237   //! written in the plane of projection.
238   //! The attributes are given with respect to the plane of
239   //! projection.
240   //! AHeight : Height of text.
241   //! (Relative to the Normalized Projection
242   //! Coordinates (NPC) Space).
243   //! The other attributes have the following default values:
244   //! AAngle  : PI / 2.
245   //! ATp     : TP_RIGHT
246   //! AHta    : HTA_LEFT
247   //! AVta    : VTA_BOTTOM
248   Standard_DEPRECATED("Deprecated method Text() with obsolete arguments, use AddText() instead of it")
249   Standard_EXPORT void Text (const TCollection_ExtendedString& AText,
250                              const Graphic3d_Vertex& APoint,
251                              const Standard_Real AHeight,
252                              const Standard_Boolean EvalMinMax = Standard_True);
253
254   //! Creates the string <theText> at orientation <theOrientation> in 3D space.
255   Standard_DEPRECATED("Deprecated method Text() with obsolete arguments, use AddText() instead of it")
256   Standard_EXPORT virtual void Text (const Standard_CString                  theTextUtf,
257                                      const gp_Ax2&                           theOrientation,
258                                      const Standard_Real                     theHeight,
259                                      const Standard_Real                     theAngle,
260                                      const Graphic3d_TextPath                theTp,
261                                      const Graphic3d_HorizontalTextAlignment theHTA,
262                                      const Graphic3d_VerticalTextAlignment   theVTA,
263                                      const Standard_Boolean                  theToEvalMinMax = Standard_True,
264                                      const Standard_Boolean                  theHasOwnAnchor = Standard_True);
265
266   //! Creates the string <theText> at orientation <theOrientation> in 3D space.
267   Standard_DEPRECATED("Deprecated method Text() with obsolete arguments, use AddText() instead of it")
268   Standard_EXPORT virtual void Text (const TCollection_ExtendedString&       theText,
269                                      const gp_Ax2&                           theOrientation,
270                                      const Standard_Real                     theHeight,
271                                      const Standard_Real                     theAngle,
272                                      const Graphic3d_TextPath                theTp,
273                                      const Graphic3d_HorizontalTextAlignment theHTA,
274                                      const Graphic3d_VerticalTextAlignment   theVTA,
275                                      const Standard_Boolean                  theToEvalMinMax = Standard_True,
276                                      const Standard_Boolean                  theHasOwnAnchor = Standard_True);
277
278
279   //! Dumps the content of me into the stream
280   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
281
282 protected:
283
284   //! Creates a group in the structure <AStructure>.
285   Standard_EXPORT Graphic3d_Group(const Handle(Graphic3d_Structure)& theStructure);
286
287   //! Calls the Update method of the StructureManager which
288   //! contains the associated Structure of the Group <me>.
289   Standard_EXPORT void Update() const;
290
291 protected:
292
293   Graphic3d_Structure* myStructure;     //!< pointer to the parent structure
294   Graphic3d_BndBox4f   myBounds;        //!< bounding box
295   bool                 myIsClosed;      //!< flag indicating closed volume
296   bool                 myContainsFacet; //!< flag indicating that this group contains face primitives
297
298 };
299
300 DEFINE_STANDARD_HANDLE(Graphic3d_Group, Standard_Transient)
301
302 #endif // _Graphic3d_Group_HeaderFile