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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _Graphic3d_Group_HeaderFile
18 #define _Graphic3d_Group_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
23 #include <Graphic3d_CBitFields4.hxx>
24 #include <Graphic3d_StructurePtr.hxx>
25 #include <Graphic3d_BndBox4f.hxx>
26 #include <Standard_Boolean.hxx>
27 #include <Graphic3d_CAspectLine.hxx>
28 #include <Graphic3d_CAspectFillArea.hxx>
29 #include <Graphic3d_CAspectMarker.hxx>
30 #include <Graphic3d_CAspectText.hxx>
31 #include <Graphic3d_AspectLine3d.hxx>
32 #include <Graphic3d_AspectFillArea3d.hxx>
33 #include <Graphic3d_AspectText3d.hxx>
34 #include <Graphic3d_AspectMarker3d.hxx>
35 #include <MMgt_TShared.hxx>
36 #include <Standard_Real.hxx>
37 #include <Standard_CString.hxx>
38 #include <Graphic3d_Vertex.hxx>
39 #include <Quantity_PlaneAngle.hxx>
40 #include <Graphic3d_TextPath.hxx>
41 #include <Graphic3d_HorizontalTextAlignment.hxx>
42 #include <Graphic3d_VerticalTextAlignment.hxx>
43 #include <Graphic3d_TypeOfPrimitiveArray.hxx>
44 #include <Graphic3d_IndexBuffer.hxx>
45 #include <Graphic3d_Buffer.hxx>
46 #include <Graphic3d_BoundBuffer.hxx>
47 #include <Standard_Address.hxx>
48 #include <Graphic3d_GroupAspect.hxx>
50 #include <TCollection_ExtendedString.hxx>
52 class Graphic3d_Structure;
53 class Graphic3d_GroupDefinitionError;
54 class Standard_OutOfRange;
55 class Graphic3d_ArrayOfPrimitives;
58 class Graphic3d_Group;
59 DEFINE_STANDARD_HANDLE(Graphic3d_Group, MMgt_TShared)
61 //! This class allows the definition of groups
62 //! of primitives inside of graphic objects (presentations).
63 //! A group contains the primitives and attributes
64 //! for which the range is limited to this group.
65 //! The primitives of a group can be globally suppressed.
67 //! There are two main group usage models:
69 //! 1) Non-modifiable, or unbounded, group ('black box').
70 //! Developers can repeat a sequence of
71 //! SetPrimitivesAspect() with AddPrimitiveArray() methods arbitrary number of times
72 //! to define arbitrary number of primitive "blocks" each having individual apect values.
73 //! Any modification of such a group is forbidden, as aspects and primitives are mixed
74 //! in memory without any high-level logical structure, and any modification is very likely to result
75 //! in corruption of the group internal data.
76 //! It is necessary to recreate such a group as a whole when some attribute should be changed.
77 //! (for example, in terms of AIS it is necessary to re-Compute() the whole presentation each time).
78 //! 2) Bounded group. Developers should specify the necessary group aspects with help of
79 //! SetGroupPrimitivesAspect() and then add primitives to the group.
80 //! Such a group have simplified organization in memory (a single block of attributes
81 //! followed by a block of primitives) and therefore it can be modified, if it is necessary to
82 //! change parameters of some aspect that has already been set, using methods:
83 //! IsGroupPrimitivesAspectSet() to detect which aspect was set for primitives;
84 //! GroupPrimitivesAspect() to read current aspect values
85 //! and SetGroupPrimitivesAspect() to set new values.
87 //! Developers are strongly recommended to take all the above into account when filling Graphic3d_Group
88 //! with aspects and primitives and choose the group usage model beforehand out of application needs.
89 //! Note that some Graphic3d_Group class virtual methods contain only base implementation
90 //! that is extended by the descendant class in OpenGl package.
91 class Graphic3d_Group : public MMgt_TShared
97 //! Supress all primitives and attributes of <me>.
98 //! To clear group without update in Graphic3d_StructureManager
99 //! pass Standard_False as <theUpdateStructureMgr>. This
100 //! used on context and viewer destruction, when the pointer
101 //! to structure manager in Graphic3d_Structure could be
102 //! already released (pointers are used here to avoid handle
103 //! cross-reference);
104 Standard_EXPORT virtual void Clear (const Standard_Boolean theUpdateStructureMgr = Standard_True);
106 Standard_EXPORT virtual void UpdateAspectLine (const Standard_Boolean theIsGlobal) = 0;
108 Standard_EXPORT virtual void UpdateAspectFace (const Standard_Boolean theIsGlobal) = 0;
110 Standard_EXPORT virtual void UpdateAspectMarker (const Standard_Boolean theIsGlobal) = 0;
112 Standard_EXPORT virtual void UpdateAspectText (const Standard_Boolean theIsGlobal) = 0;
114 //! Supress the group <me> in the structure.
115 Standard_EXPORT void Destroy();
121 //! Supress the group <me> in the structure.
122 //! Warning: No more graphic operations in <me> after this call.
123 //! Modifies the current modelling transform persistence (pan, zoom or rotate)
124 //! Get the current modelling transform persistence (pan, zoom or rotate)
125 Standard_EXPORT void Remove();
127 //! Modifies the context for all the line primitives
129 Standard_EXPORT void SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTX);
131 //! Modifies the context for all the face primitives
133 Standard_EXPORT void SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& CTX);
135 //! Modifies the context for all the text primitives
137 Standard_EXPORT void SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& CTX);
139 //! Modifies the context for all the marker primitives
141 Standard_EXPORT void SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& CTX);
143 //! Modifies the current context of the group to give
144 //! another aspect for all the line primitives created
145 //! after this call in the group.
146 Standard_EXPORT void SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTX);
148 //! Modifies the current context of the group to give
149 //! another aspect for all the face primitives created
150 //! after this call in the group.
151 Standard_EXPORT void SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& CTX);
153 //! Modifies the current context of the group to give
154 //! another aspect for all the text primitives created
155 //! after this call in the group.
156 Standard_EXPORT void SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& CTX);
158 //! Modifies the current context of the group to give
159 //! another aspect for all the marker primitives created
160 //! after this call in the group.
161 Standard_EXPORT void SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& CTX);
163 //! Sets the coordinates of the boundary box of the
165 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);
167 //! Creates the string <AText> at position <APoint>.
168 //! The 3D point of attachment is projected. The text is
169 //! written in the plane of projection.
170 //! The attributes are given with respect to the plane of
172 //! AHeight : Height of text.
173 //! (Relative to the Normalized Projection
174 //! Coordinates (NPC) Space).
175 //! AAngle : Orientation of the text
176 //! (with respect to the horizontal).
177 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);
179 //! Creates the string <AText> at position <APoint>.
180 //! The 3D point of attachment is projected. The text is
181 //! written in the plane of projection.
182 //! The attributes are given with respect to the plane of
184 //! AHeight : Height of text.
185 //! (Relative to the Normalized Projection
186 //! Coordinates (NPC) Space).
187 //! The other attributes have the following default values:
191 //! AVta : VTA_BOTTOM
192 Standard_EXPORT void Text (const Standard_CString AText, const Graphic3d_Vertex& APoint, const Standard_Real AHeight, const Standard_Boolean EvalMinMax = Standard_True);
194 //! Creates the string <AText> at position <APoint>.
195 //! The 3D point of attachment is projected. The text is
196 //! written in the plane of projection.
197 //! The attributes are given with respect to the plane of
199 //! AHeight : Height of text.
200 //! (Relative to the Normalized Projection
201 //! Coordinates (NPC) Space).
202 //! AAngle : Orientation of the text
203 //! (with respect to the horizontal).
204 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);
206 //! Creates the string <AText> at position <APoint>.
207 //! The 3D point of attachment is projected. The text is
208 //! written in the plane of projection.
209 //! The attributes are given with respect to the plane of
211 //! AHeight : Height of text.
212 //! (Relative to the Normalized Projection
213 //! Coordinates (NPC) Space).
214 //! The other attributes have the following default values:
218 //! AVta : VTA_BOTTOM
219 Standard_EXPORT void Text (const TCollection_ExtendedString& AText, const Graphic3d_Vertex& APoint, const Standard_Real AHeight, const Standard_Boolean EvalMinMax = Standard_True);
221 //! Creates the string <theText> at orientation <theOrientation> in 3D space.
222 Standard_EXPORT virtual void Text (const Standard_CString theTextUtf,
223 const gp_Ax2& theOrientation,
224 const Standard_Real theHeight,
225 const Quantity_PlaneAngle theAngle,
226 const Graphic3d_TextPath theTp,
227 const Graphic3d_HorizontalTextAlignment theHTA,
228 const Graphic3d_VerticalTextAlignment theVTA,
229 const Standard_Boolean theToEvalMinMax = Standard_True);
231 //! Creates the string <theText> at orientation <theOrientation> in 3D space.
232 Standard_EXPORT virtual void Text (const TCollection_ExtendedString& theText,
233 const gp_Ax2& theOrientation,
234 const Standard_Real theHeight,
235 const Quantity_PlaneAngle theAngle,
236 const Graphic3d_TextPath theTp,
237 const Graphic3d_HorizontalTextAlignment theHTA,
238 const Graphic3d_VerticalTextAlignment theVTA,
239 const Standard_Boolean theToEvalMinMax = Standard_True);
242 //! Adds an array of primitives for display
243 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);
245 //! Adds an array of primitives for display
246 Standard_EXPORT void AddPrimitiveArray (const Handle(Graphic3d_ArrayOfPrimitives)& thePrim, const Standard_Boolean theToEvalMinMax = Standard_True);
248 //! Creates a primitive array with single marker using AddPrimitiveArray().
249 Standard_EXPORT void Marker (const Graphic3d_Vertex& thePoint, const Standard_Boolean theToEvalMinMax = Standard_True);
251 //! sets the stencil test to theIsEnabled state;
252 Standard_EXPORT virtual void SetStencilTestOptions (const Standard_Boolean theIsEnabled) = 0;
254 //! sets the flipping to theIsEnabled state.
255 Standard_EXPORT virtual void SetFlippingOptions (const Standard_Boolean theIsEnabled, const gp_Ax2& theRefPlane) = 0;
257 //! Returns TRUE if aspect is set for the group.
258 Standard_EXPORT Standard_Boolean IsGroupPrimitivesAspectSet (const Graphic3d_GroupAspect theAspect) const;
260 //! Returns the context of all the primitives of the group.
261 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;
263 //! Returns the last inserted context in the group <me>
264 //! foreach kind of primitives.
265 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;
267 //! Returns Standard_True if the group <me> contains
268 //! Polygons, Triangles or Quadrangles.
269 Standard_EXPORT Standard_Boolean ContainsFacet() const;
271 //! Returns Standard_True if the group <me> is deleted.
272 //! <me> is deleted after the call Remove (me) or the
273 //! associated structure is deleted.
274 Standard_EXPORT Standard_Boolean IsDeleted() const;
276 //! Returns Standard_True if the group <me> is empty.
277 Standard_EXPORT Standard_Boolean IsEmpty() const;
279 //! Returns the coordinates of the boundary box of the
281 Standard_EXPORT void MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const;
283 //! Returns boundary box of the group <me> without transformation applied,
284 Standard_EXPORT const Graphic3d_BndBox4f& BoundingBox() const;
286 //! Returns non-const boundary box of the group <me> without transformation applied,
287 Standard_EXPORT Graphic3d_BndBox4f& ChangeBoundingBox();
289 //! Returns the structure containing the group <me>.
290 Standard_EXPORT Handle(Graphic3d_Structure) Structure() const;
292 //! Changes property shown that primitive arrays within this group form closed volume (do no contain open shells).
293 Standard_EXPORT void SetClosed (const Standard_Boolean theIsClosed);
295 //! Return true if primitive arrays within this graphic group form closed volume (do no contain open shells).
296 Standard_EXPORT Standard_Boolean IsClosed() const;
298 friend class Graphic3d_Structure;
301 DEFINE_STANDARD_RTTIEXT(Graphic3d_Group,MMgt_TShared)
306 //! Creates a group in the structure <AStructure>.
307 Standard_EXPORT Graphic3d_Group(const Handle(Graphic3d_Structure)& theStructure);
309 Graphic3d_CBitFields4 myCBitFields;
310 Graphic3d_StructurePtr myStructure;
311 Graphic3d_BndBox4f myBounds;
312 Standard_Boolean myIsClosed;
313 Graphic3d_CAspectLine ContextLine;
314 Graphic3d_CAspectFillArea ContextFillArea;
315 Graphic3d_CAspectMarker ContextMarker;
316 Graphic3d_CAspectText ContextText;
322 //! Returns the extreme coordinates found in the group.
323 Standard_EXPORT void MinMaxCoord (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const;
325 //! Calls the Update method of the StructureManager which
326 //! contains the associated Structure of the Group <me>.
327 Standard_EXPORT void Update() const;
339 #endif // _Graphic3d_Group_HeaderFile