0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / AIS / AIS_Shape.hxx
CommitLineData
42cf5bc1 1// Created on: 1996-12-20
2// Created by: Robert COUBLANC
3// Copyright (c) 1996-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 _AIS_Shape_HeaderFile
18#define _AIS_Shape_HeaderFile
19
42cf5bc1 20#include <AIS_InteractiveObject.hxx>
87432b82 21#include <Bnd_Box.hxx>
87432b82 22#include <TopoDS_Shape.hxx>
42cf5bc1 23#include <Prs3d_Drawer.hxx>
87432b82 24#include <Prs3d_TypeOfHLR.hxx>
25
42cf5bc1 26//! A framework to manage presentation and selection of shapes.
27//! AIS_Shape is the interactive object which is used the
28//! most by applications. There are standard functions
29//! available which allow you to prepare selection
30//! operations on the constituent elements of shapes -
31//! vertices, edges, faces etc - in an open local context.
32//! The selection modes specific to "Shape" type objects
33//! are referred to as Standard Activation Mode. These
34//! modes are only taken into account in open local
35//! context and only act on Interactive Objects which
36//! have redefined the virtual method
37//! AcceptShapeDecomposition so that it returns true.
38//! Several advanced functions are also available. These
39//! include functions to manage deviation angle and
40//! deviation coefficient - both HLR and non-HLR - of
41//! an inheriting shape class. These services allow you to
42//! select one type of shape interactive object for higher
43//! precision drawing. When you do this, the
44//! Prs3d_Drawer::IsOwn... functions corresponding to the
45//! above deviation angle and coefficient functions return
46//! true indicating that there is a local setting available
47//! for the specific object.
a6dee93d 48//!
49//! This class allows to map textures on shapes using native UV parametric space of underlying surface of each Face
50//! (this means that texture will be visually duplicated on all Faces).
51//! To generate texture coordinates, appropriate shading attribute should be set before computing presentation in AIS_Shaded display mode:
52//! @code
53//! Handle(AIS_Shape) aPrs = new AIS_Shape();
2a332745 54//! aPrs->Attributes()->SetupOwnShadingAspect();
a6dee93d 55//! aPrs->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
56//! aPrs->Attributes()->ShadingAspect()->Aspect()->SetTextureMap (new Graphic3d_Texture2Dmanual (Graphic3d_NOT_2D_ALUMINUM));
57//! @endcode
58//! The texture itself is parametrized in (0,1)x(0,1).
42cf5bc1 59class AIS_Shape : public AIS_InteractiveObject
60{
87432b82 61 DEFINE_STANDARD_RTTIEXT(AIS_Shape, AIS_InteractiveObject)
42cf5bc1 62public:
63
42cf5bc1 64 //! Initializes construction of the shape shap from wires,
65 //! edges and vertices.
66 Standard_EXPORT AIS_Shape(const TopoDS_Shape& shap);
f8e0c6c4 67
42cf5bc1 68 //! Returns index 0. This value refers to SHAPE from TopAbs_ShapeEnum
f8e0c6c4 69 virtual Standard_Integer Signature() const Standard_OVERRIDE { return 0; }
70
42cf5bc1 71 //! Returns Object as the type of Interactive Object.
f8e0c6c4 72 virtual AIS_KindOfInteractive Type() const Standard_OVERRIDE { return AIS_KOI_Shape; }
73
42cf5bc1 74 //! Returns true if the Interactive Object accepts shape decomposition.
f8e0c6c4 75 virtual Standard_Boolean AcceptShapeDecomposition() const Standard_OVERRIDE { return Standard_True; }
76
77 //! Return true if specified display mode is supported.
78 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode >= 0 && theMode <= 2; }
79
80 //! Returns this shape object.
81 const TopoDS_Shape& Shape() const { return myshape; }
82
87432b82 83 //! Constructs an instance of the shape object theShape.
f8e0c6c4 84 void SetShape (const TopoDS_Shape& theShape)
87432b82 85 {
86 myshape = theShape;
87 myCompBB = Standard_True;
88 }
89
f8e0c6c4 90 //! Alias for ::SetShape().
91 void Set (const TopoDS_Shape& theShape) { SetShape (theShape); }
87432b82 92
42cf5bc1 93 //! Sets a local value for deviation coefficient for this specific shape.
94 Standard_EXPORT Standard_Boolean SetOwnDeviationCoefficient();
67441d0c 95
42cf5bc1 96 //! Sets a local value for deviation angle for this specific shape.
97 Standard_EXPORT Standard_Boolean SetOwnDeviationAngle();
98
42cf5bc1 99 //! Sets a local value for deviation coefficient for this specific shape.
100 Standard_EXPORT void SetOwnDeviationCoefficient (const Standard_Real aCoefficient);
67441d0c 101
42cf5bc1 102 //! this compute a new angle and Deviation from the value anAngle
103 //! and set the values stored in myDrawer with these that become local to the shape
104 Standard_EXPORT void SetAngleAndDeviation (const Standard_Real anAngle);
105
106 //! gives back the angle initial value put by the User.
107 Standard_EXPORT Standard_Real UserAngle() const;
108
109 //! sets myOwnDeviationAngle field in Prs3d_Drawer & recomputes presentation
110 Standard_EXPORT void SetOwnDeviationAngle (const Standard_Real anAngle);
111
42cf5bc1 112 //! Returns true and the values of the deviation
113 //! coefficient aCoefficient and the previous deviation
114 //! coefficient aPreviousCoefficient. If these values are
115 //! not already set, false is returned.
116 Standard_EXPORT Standard_Boolean OwnDeviationCoefficient (Standard_Real& aCoefficient, Standard_Real& aPreviousCoefficient) const;
117
42cf5bc1 118 //! Returns true and the values of the deviation angle
119 //! anAngle and the previous deviation angle aPreviousAngle.
120 //! If these values are not already set, false is returned.
121 Standard_EXPORT Standard_Boolean OwnDeviationAngle (Standard_Real& anAngle, Standard_Real& aPreviousAngle) const;
122
42cf5bc1 123 //! Sets the type of HLR algorithm used by the shape
87432b82 124 void SetTypeOfHLR (const Prs3d_TypeOfHLR theTypeOfHLR) { myDrawer->SetTypeOfHLR (theTypeOfHLR); }
125
42cf5bc1 126 //! Gets the type of HLR algorithm
87432b82 127 Prs3d_TypeOfHLR TypeOfHLR() const { return myDrawer->TypeOfHLR(); }
128
42cf5bc1 129 //! Sets the color aColor in the reconstructed
130 //! compound shape. Acts via the Drawer methods below on the appearance of:
131 //! - free boundaries:
132 //! Prs3d_Drawer_FreeBoundaryAspect,
133 //! - isos: Prs3d_Drawer_UIsoAspect,
134 //! Prs3dDrawer_VIsoAspect,
135 //! - shared boundaries:
136 //! Prs3d_Drawer_UnFreeBoundaryAspect,
137 //! - shading: Prs3d_Drawer_ShadingAspect,
138 //! - visible line color in hidden line mode:
139 //! Prs3d_Drawer_SeenLineAspect
140 //! - hidden line color in hidden line mode:
141 //! Prs3d_Drawer_HiddenLineAspect.
87432b82 142 Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
143
42cf5bc1 144 //! Removes settings for color in the reconstructed compound shape.
145 Standard_EXPORT virtual void UnsetColor() Standard_OVERRIDE;
146
147 //! Sets the value aValue for line width in the reconstructed compound shape.
7604a153 148 //! Changes line aspects for lines presentation.
42cf5bc1 149 Standard_EXPORT virtual void SetWidth (const Standard_Real aValue) Standard_OVERRIDE;
150
151 //! Removes the setting for line width in the reconstructed compound shape.
152 Standard_EXPORT virtual void UnsetWidth() Standard_OVERRIDE;
87432b82 153
42cf5bc1 154 //! Allows you to provide settings for the material aName
155 //! in the reconstructed compound shape.
156 Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& aName) Standard_OVERRIDE;
157
158 //! Removes settings for material in the reconstructed compound shape.
159 Standard_EXPORT virtual void UnsetMaterial() Standard_OVERRIDE;
160
161 //! Sets the value aValue for transparency in the reconstructed compound shape.
162 Standard_EXPORT virtual void SetTransparency (const Standard_Real aValue = 0.6) Standard_OVERRIDE;
163
164 //! Removes the setting for transparency in the reconstructed compound shape.
165 Standard_EXPORT virtual void UnsetTransparency() Standard_OVERRIDE;
166
167 //! Constructs a bounding box with which to reconstruct
168 //! compound topological shapes for presentation.
169 Standard_EXPORT virtual const Bnd_Box& BoundingBox();
170
201c2208 171 //! AIS_InteractiveObject defines another virtual method BoundingBox,
172 //! which is not the same as above; keep it visible.
173 using AIS_InteractiveObject::BoundingBox;
174
42cf5bc1 175 //! Returns the Color attributes of the shape accordingly to
176 //! the current facing model;
177 Standard_EXPORT virtual void Color (Quantity_Color& aColor) const Standard_OVERRIDE;
178
179 //! Returns the NameOfMaterial attributes of the shape accordingly to
180 //! the current facing model;
181 Standard_EXPORT virtual Graphic3d_NameOfMaterial Material() const Standard_OVERRIDE;
182
183 //! Returns the transparency attributes of the shape accordingly to
184 //! the current facing model;
185 Standard_EXPORT virtual Standard_Real Transparency() const Standard_OVERRIDE;
c7ba4578 186
187 //! Return shape type for specified selection mode.
188 static TopAbs_ShapeEnum SelectionType (const Standard_Integer theSelMode)
189 {
190 switch (theSelMode)
191 {
192 case 1: return TopAbs_VERTEX;
193 case 2: return TopAbs_EDGE;
194 case 3: return TopAbs_WIRE;
195 case 4: return TopAbs_FACE;
196 case 5: return TopAbs_SHELL;
197 case 6: return TopAbs_SOLID;
198 case 7: return TopAbs_COMPSOLID;
199 case 8: return TopAbs_COMPOUND;
200 case 0: return TopAbs_SHAPE;
201 }
202 return TopAbs_SHAPE;
203 }
204
205 //! Return selection mode for specified shape type.
206 static Standard_Integer SelectionMode (const TopAbs_ShapeEnum theShapeType)
207 {
208 switch (theShapeType)
209 {
210 case TopAbs_VERTEX: return 1;
211 case TopAbs_EDGE: return 2;
212 case TopAbs_WIRE: return 3;
213 case TopAbs_FACE: return 4;
214 case TopAbs_SHELL: return 5;
215 case TopAbs_SOLID: return 6;
216 case TopAbs_COMPSOLID: return 7;
217 case TopAbs_COMPOUND: return 8;
218 case TopAbs_SHAPE: return 0;
219 }
220 return 0;
221 }
42cf5bc1 222
a6dee93d 223public: //! @name methods to alter texture mapping properties
224
225 //! Return texture repeat UV values; (1, 1) by default.
226 const gp_Pnt2d& TextureRepeatUV() const { return myUVRepeat; }
227
228 //! Sets the number of occurrences of the texture on each face. The texture itself is parameterized in (0,1) by (0,1).
229 //! Each face of the shape to be textured is parameterized in UV space (Umin,Umax) by (Vmin,Vmax).
230 void SetTextureRepeatUV (const gp_Pnt2d& theRepeatUV) { myUVRepeat = theRepeatUV; }
231
232 //! Return texture origin UV position; (0, 0) by default.
233 const gp_Pnt2d& TextureOriginUV() const { return myUVOrigin; }
234
235 //! Use this method to change the origin of the texture.
236 //! The texel (0,0) will be mapped to the surface (myUVOrigin.X(), myUVOrigin.Y()).
237 void SetTextureOriginUV (const gp_Pnt2d& theOriginUV) { myUVOrigin = theOriginUV; }
238
239 //! Return scale factor for UV coordinates; (1, 1) by default.
240 const gp_Pnt2d& TextureScaleUV() const { return myUVScale; }
241
242 //! Use this method to scale the texture (percent of the face).
243 //! You can specify a scale factor for both U and V.
244 //! Example: if you set ScaleU and ScaleV to 0.5 and you enable texture repeat,
245 //! the texture will appear twice on the face in each direction.
246 void SetTextureScaleUV (const gp_Pnt2d& theScaleUV) { myUVScale = theScaleUV; }
247
42cf5bc1 248protected:
249
c7ba4578 250 //! Compute normal presentation.
251 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
252 const Handle(Prs3d_Presentation)& thePrs,
253 const Standard_Integer theMode) Standard_OVERRIDE;
254
255 //! Compute projected presentation.
b5163d2f 256 virtual void computeHLR (const Handle(Graphic3d_Camera)& theProjector,
7f24b768 257 const Handle(TopLoc_Datum3D)& theTrsf,
b5163d2f 258 const Handle(Prs3d_Presentation)& thePrs) Standard_OVERRIDE
c7ba4578 259 {
b5163d2f 260 if (!theTrsf.IsNull()
261 && theTrsf->Form() != gp_Identity)
262 {
263 const TopLoc_Location& aLoc = myshape.Location();
264 const TopoDS_Shape aShape = myshape.Located (TopLoc_Location (theTrsf->Trsf()) * aLoc);
265 computeHlrPresentation (theProjector, thePrs, aShape, myDrawer);
266 }
267 else
268 {
269 computeHlrPresentation (theProjector, thePrs, myshape, myDrawer);
270 }
c7ba4578 271 }
272
273 //! Compute selection.
274 Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
275 const Standard_Integer theMode) Standard_OVERRIDE;
42cf5bc1 276
7604a153 277 //! Create own aspects (if they do not exist) and set color to them.
278 //! @return TRUE if new aspects have been created
279 Standard_EXPORT bool setColor (const Handle(Prs3d_Drawer)& theDrawer, const Quantity_Color& theColor) const;
42cf5bc1 280
7604a153 281 //! Create own aspects (if they do not exist) and set width to them.
282 //! @return TRUE if new aspects have been created
283 Standard_EXPORT bool setWidth (const Handle(Prs3d_Drawer)& theDrawer, const Standard_Real theWidth) const;
42cf5bc1 284
285 Standard_EXPORT void setTransparency (const Handle(Prs3d_Drawer)& theDrawer, const Standard_Real theValue) const;
286
287 Standard_EXPORT void setMaterial (const Handle(Prs3d_Drawer)& theDrawer, const Graphic3d_MaterialAspect& theMaterial, const Standard_Boolean theToKeepColor, const Standard_Boolean theToKeepTransp) const;
288
bf5f0ca2 289 //! Replace aspects of already computed groups from drawer link by the new own value.
290 Standard_EXPORT void replaceWithNewOwnAspects();
291
c7ba4578 292public:
a6dee93d 293
c7ba4578 294 //! Compute HLR presentation for specified shape.
b5163d2f 295 Standard_EXPORT static void computeHlrPresentation (const Handle(Graphic3d_Camera)& theProjector,
c7ba4578 296 const Handle(Prs3d_Presentation)& thePrs,
297 const TopoDS_Shape& theShape,
298 const Handle(Prs3d_Drawer)& theDrawer);
42cf5bc1 299
bc73b006 300 //! Dumps the content of me into the stream
301 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
302
a6dee93d 303protected:
42cf5bc1 304
a6dee93d 305 TopoDS_Shape myshape; //!< shape to display
306 Bnd_Box myBB; //!< cached bounding box of the shape
307 gp_Pnt2d myUVOrigin; //!< UV origin vector for generating texture coordinates
308 gp_Pnt2d myUVRepeat; //!< UV repeat vector for generating texture coordinates
309 gp_Pnt2d myUVScale; //!< UV scale vector for generating texture coordinates
310 Standard_Real myInitAng;
311 Standard_Boolean myCompBB; //!< if TRUE, then bounding box should be recomputed
42cf5bc1 312
313};
314
87432b82 315DEFINE_STANDARD_HANDLE(AIS_Shape, AIS_InteractiveObject)
42cf5bc1 316
317#endif // _AIS_Shape_HeaderFile