0028811: Visualization - merge texturing support into AIS_Shape class and get rid...
[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>
42cf5bc1 22#include <TopAbs_ShapeEnum.hxx>
87432b82 23#include <TopoDS_Shape.hxx>
42cf5bc1 24#include <Prs3d_Drawer.hxx>
87432b82 25#include <Prs3d_TypeOfHLR.hxx>
26
42cf5bc1 27class TopoDS_Shape;
42cf5bc1 28class Bnd_Box;
29
42cf5bc1 30//! A framework to manage presentation and selection of shapes.
31//! AIS_Shape is the interactive object which is used the
32//! most by applications. There are standard functions
33//! available which allow you to prepare selection
34//! operations on the constituent elements of shapes -
35//! vertices, edges, faces etc - in an open local context.
36//! The selection modes specific to "Shape" type objects
37//! are referred to as Standard Activation Mode. These
38//! modes are only taken into account in open local
39//! context and only act on Interactive Objects which
40//! have redefined the virtual method
41//! AcceptShapeDecomposition so that it returns true.
42//! Several advanced functions are also available. These
43//! include functions to manage deviation angle and
44//! deviation coefficient - both HLR and non-HLR - of
45//! an inheriting shape class. These services allow you to
46//! select one type of shape interactive object for higher
47//! precision drawing. When you do this, the
48//! Prs3d_Drawer::IsOwn... functions corresponding to the
49//! above deviation angle and coefficient functions return
50//! true indicating that there is a local setting available
51//! for the specific object.
a6dee93d 52//!
53//! This class allows to map textures on shapes using native UV parametric space of underlying surface of each Face
54//! (this means that texture will be visually duplicated on all Faces).
55//! To generate texture coordinates, appropriate shading attribute should be set before computing presentation in AIS_Shaded display mode:
56//! @code
57//! Handle(AIS_Shape) aPrs = new AIS_Shape();
58//! aPrs->Attributes()->SetShadingAspect (new Prs3d_ShadingAspect());
59//! aPrs->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
60//! aPrs->Attributes()->ShadingAspect()->Aspect()->SetTextureMap (new Graphic3d_Texture2Dmanual (Graphic3d_NOT_2D_ALUMINUM));
61//! @endcode
62//! The texture itself is parametrized in (0,1)x(0,1).
42cf5bc1 63class AIS_Shape : public AIS_InteractiveObject
64{
87432b82 65 DEFINE_STANDARD_RTTIEXT(AIS_Shape, AIS_InteractiveObject)
42cf5bc1 66public:
67
42cf5bc1 68 //! Initializes construction of the shape shap from wires,
69 //! edges and vertices.
70 Standard_EXPORT AIS_Shape(const TopoDS_Shape& shap);
71
72 //! Returns index 0. This value refers to SHAPE from TopAbs_ShapeEnum
73 Standard_EXPORT virtual Standard_Integer Signature() const Standard_OVERRIDE;
74
75 //! Returns Object as the type of Interactive Object.
76 Standard_EXPORT virtual AIS_KindOfInteractive Type() const Standard_OVERRIDE;
77
78 //! Returns true if the Interactive Object accepts shape decomposition.
79 Standard_EXPORT virtual Standard_Boolean AcceptShapeDecomposition() const Standard_OVERRIDE;
80
87432b82 81 //! Constructs an instance of the shape object theShape.
82 void Set (const TopoDS_Shape& theShape)
83 {
84 myshape = theShape;
85 myCompBB = Standard_True;
86 }
87
42cf5bc1 88 //! Returns this shape object.
87432b82 89 const TopoDS_Shape& Shape() const { return myshape; }
90
42cf5bc1 91 //! Sets a local value for deviation coefficient for this specific shape.
92 Standard_EXPORT Standard_Boolean SetOwnDeviationCoefficient();
93
94 //! Sets a local value for HLR deviation coefficient for this specific shape.
95 Standard_EXPORT Standard_Boolean SetOwnHLRDeviationCoefficient();
96
97 //! Sets a local value for deviation angle for this specific shape.
98 Standard_EXPORT Standard_Boolean SetOwnDeviationAngle();
99
100 //! Sets a local value for HLR deviation angle for this specific shape.
101 Standard_EXPORT Standard_Boolean SetOwnHLRDeviationAngle();
102
103 //! Sets a local value for deviation coefficient for this specific shape.
104 Standard_EXPORT void SetOwnDeviationCoefficient (const Standard_Real aCoefficient);
105
106 //! sets myOwnHLRDeviationCoefficient field in Prs3d_Drawer &
107 //! recomputes presentation
108 Standard_EXPORT void SetOwnHLRDeviationCoefficient (const Standard_Real aCoefficient);
109
110 //! this compute a new angle and Deviation from the value anAngle
111 //! and set the values stored in myDrawer with these that become local to the shape
112 Standard_EXPORT void SetAngleAndDeviation (const Standard_Real anAngle);
113
114 //! gives back the angle initial value put by the User.
115 Standard_EXPORT Standard_Real UserAngle() const;
116
117 //! sets myOwnDeviationAngle field in Prs3d_Drawer & recomputes presentation
118 Standard_EXPORT void SetOwnDeviationAngle (const Standard_Real anAngle);
119
120 //! this compute a new Angle and Deviation from the value anAngle for HLR
121 //! and set the values stored in myDrawer for with these that become local to the shape
122 Standard_EXPORT void SetHLRAngleAndDeviation (const Standard_Real anAngle);
123
124 //! sets myOwnHLRDeviationAngle field in Prs3d_Drawer & recomputes presentation
125 Standard_EXPORT void SetOwnHLRDeviationAngle (const Standard_Real anAngle);
126
127 //! Returns true and the values of the deviation
128 //! coefficient aCoefficient and the previous deviation
129 //! coefficient aPreviousCoefficient. If these values are
130 //! not already set, false is returned.
131 Standard_EXPORT Standard_Boolean OwnDeviationCoefficient (Standard_Real& aCoefficient, Standard_Real& aPreviousCoefficient) const;
132
133 //! Returns true and the values of the HLR deviation
134 //! coefficient aCoefficient and the previous HLR
135 //! deviation coefficient aPreviousCoefficient. If these
136 //! values are not already set, false is returned.
137 Standard_EXPORT Standard_Boolean OwnHLRDeviationCoefficient (Standard_Real& aCoefficient, Standard_Real& aPreviousCoefficient) const;
138
139 //! Returns true and the values of the deviation angle
140 //! anAngle and the previous deviation angle aPreviousAngle.
141 //! If these values are not already set, false is returned.
142 Standard_EXPORT Standard_Boolean OwnDeviationAngle (Standard_Real& anAngle, Standard_Real& aPreviousAngle) const;
143
144 //! Returns true and the values of the HLR deviation
145 //! angle anAngle and of the previous HLR deviation
146 //! angle aPreviousAngle. If these values are not
147 //! already set, false is returned.
148 Standard_EXPORT Standard_Boolean OwnHLRDeviationAngle (Standard_Real& anAngle, Standard_Real& aPreviousAngle) const;
149
150 //! Sets the type of HLR algorithm used by the shape
87432b82 151 void SetTypeOfHLR (const Prs3d_TypeOfHLR theTypeOfHLR) { myDrawer->SetTypeOfHLR (theTypeOfHLR); }
152
42cf5bc1 153 //! Gets the type of HLR algorithm
87432b82 154 Prs3d_TypeOfHLR TypeOfHLR() const { return myDrawer->TypeOfHLR(); }
155
42cf5bc1 156 //! Sets the color aColor in the reconstructed
157 //! compound shape. Acts via the Drawer methods below on the appearance of:
158 //! - free boundaries:
159 //! Prs3d_Drawer_FreeBoundaryAspect,
160 //! - isos: Prs3d_Drawer_UIsoAspect,
161 //! Prs3dDrawer_VIsoAspect,
162 //! - shared boundaries:
163 //! Prs3d_Drawer_UnFreeBoundaryAspect,
164 //! - shading: Prs3d_Drawer_ShadingAspect,
165 //! - visible line color in hidden line mode:
166 //! Prs3d_Drawer_SeenLineAspect
167 //! - hidden line color in hidden line mode:
168 //! Prs3d_Drawer_HiddenLineAspect.
87432b82 169 Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
170
42cf5bc1 171 //! Removes settings for color in the reconstructed compound shape.
172 Standard_EXPORT virtual void UnsetColor() Standard_OVERRIDE;
173
174 //! Sets the value aValue for line width in the reconstructed compound shape.
175 //! Changes line aspects for lines-only presentation modes like Wireframe and Bounding Box.
176 //! Doesn't change face boundary line aspect.
177 Standard_EXPORT virtual void SetWidth (const Standard_Real aValue) Standard_OVERRIDE;
178
179 //! Removes the setting for line width in the reconstructed compound shape.
180 Standard_EXPORT virtual void UnsetWidth() Standard_OVERRIDE;
87432b82 181
42cf5bc1 182 //! Allows you to provide settings for the material aName
183 //! in the reconstructed compound shape.
184 Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& aName) Standard_OVERRIDE;
185
186 //! Removes settings for material in the reconstructed compound shape.
187 Standard_EXPORT virtual void UnsetMaterial() Standard_OVERRIDE;
188
189 //! Sets the value aValue for transparency in the reconstructed compound shape.
190 Standard_EXPORT virtual void SetTransparency (const Standard_Real aValue = 0.6) Standard_OVERRIDE;
191
192 //! Removes the setting for transparency in the reconstructed compound shape.
193 Standard_EXPORT virtual void UnsetTransparency() Standard_OVERRIDE;
194
195 //! Constructs a bounding box with which to reconstruct
196 //! compound topological shapes for presentation.
197 Standard_EXPORT virtual const Bnd_Box& BoundingBox();
198
201c2208 199 //! AIS_InteractiveObject defines another virtual method BoundingBox,
200 //! which is not the same as above; keep it visible.
201 using AIS_InteractiveObject::BoundingBox;
202
42cf5bc1 203 //! Returns the Color attributes of the shape accordingly to
204 //! the current facing model;
205 Standard_EXPORT virtual void Color (Quantity_Color& aColor) const Standard_OVERRIDE;
206
207 //! Returns the NameOfMaterial attributes of the shape accordingly to
208 //! the current facing model;
209 Standard_EXPORT virtual Graphic3d_NameOfMaterial Material() const Standard_OVERRIDE;
210
211 //! Returns the transparency attributes of the shape accordingly to
212 //! the current facing model;
213 Standard_EXPORT virtual Standard_Real Transparency() const Standard_OVERRIDE;
214
215 //! Activates the same TopAbs shape enumerations as
216 //! those used by SelectionMode assigning a type to the mode aDecompositionMode.
217 Standard_EXPORT static TopAbs_ShapeEnum SelectionType (const Standard_Integer aDecompositionMode);
218
219 //! Establishes an equivalence between a mode and the
220 //! type, aShapeType, of selection. The correspondences are as follows:
221 //! - mode 0 - Shape
222 //! - mode 1 - Vertex
223 //! - mode 2 - Edge
224 //! - mode 3 - Wire
225 //! - mode 4 - Face
226 //! - mode 5 - Shell
227 //! - mode 6 - Solid
228 //! - mode 7 - Compsolid
229 //! - mode 8 - Compound
230 Standard_EXPORT static Standard_Integer SelectionMode (const TopAbs_ShapeEnum aShapeType);
231
a6dee93d 232public: //! @name methods to alter texture mapping properties
233
234 //! Return texture repeat UV values; (1, 1) by default.
235 const gp_Pnt2d& TextureRepeatUV() const { return myUVRepeat; }
236
237 //! Sets the number of occurrences of the texture on each face. The texture itself is parameterized in (0,1) by (0,1).
238 //! Each face of the shape to be textured is parameterized in UV space (Umin,Umax) by (Vmin,Vmax).
239 void SetTextureRepeatUV (const gp_Pnt2d& theRepeatUV) { myUVRepeat = theRepeatUV; }
240
241 //! Return texture origin UV position; (0, 0) by default.
242 const gp_Pnt2d& TextureOriginUV() const { return myUVOrigin; }
243
244 //! Use this method to change the origin of the texture.
245 //! The texel (0,0) will be mapped to the surface (myUVOrigin.X(), myUVOrigin.Y()).
246 void SetTextureOriginUV (const gp_Pnt2d& theOriginUV) { myUVOrigin = theOriginUV; }
247
248 //! Return scale factor for UV coordinates; (1, 1) by default.
249 const gp_Pnt2d& TextureScaleUV() const { return myUVScale; }
250
251 //! Use this method to scale the texture (percent of the face).
252 //! You can specify a scale factor for both U and V.
253 //! Example: if you set ScaleU and ScaleV to 0.5 and you enable texture repeat,
254 //! the texture will appear twice on the face in each direction.
255 void SetTextureScaleUV (const gp_Pnt2d& theScaleUV) { myUVScale = theScaleUV; }
256
42cf5bc1 257protected:
258
42cf5bc1 259 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, const Handle(Prs3d_Presentation)& aPresentation, const Standard_Integer aMode = 0) Standard_OVERRIDE;
260
261 Standard_EXPORT virtual void Compute (const Handle(Prs3d_Projector)& aProjector, const Handle(Prs3d_Presentation)& aPresentation) Standard_OVERRIDE;
262
263 Standard_EXPORT virtual void Compute (const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTrsf, const Handle(Prs3d_Presentation)& aPresentation) Standard_OVERRIDE;
264
265 Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer aMode) Standard_OVERRIDE;
266
267 Standard_EXPORT void LoadRecomputable (const Standard_Integer TheMode);
268
269 Standard_EXPORT void setColor (const Handle(Prs3d_Drawer)& theDrawer, const Quantity_Color& theColor) const;
270
271 Standard_EXPORT void setWidth (const Handle(Prs3d_Drawer)& theDrawer, const Standard_Real theWidth) const;
272
273 Standard_EXPORT void setTransparency (const Handle(Prs3d_Drawer)& theDrawer, const Standard_Real theValue) const;
274
275 Standard_EXPORT void setMaterial (const Handle(Prs3d_Drawer)& theDrawer, const Graphic3d_MaterialAspect& theMaterial, const Standard_Boolean theToKeepColor, const Standard_Boolean theToKeepTransp) const;
276
42cf5bc1 277private:
a6dee93d 278
42cf5bc1 279 Standard_EXPORT void Compute (const Handle(Prs3d_Projector)& aProjector, const Handle(Prs3d_Presentation)& aPresentation, const TopoDS_Shape& ashape);
280
a6dee93d 281protected:
42cf5bc1 282
a6dee93d 283 TopoDS_Shape myshape; //!< shape to display
284 Bnd_Box myBB; //!< cached bounding box of the shape
285 gp_Pnt2d myUVOrigin; //!< UV origin vector for generating texture coordinates
286 gp_Pnt2d myUVRepeat; //!< UV repeat vector for generating texture coordinates
287 gp_Pnt2d myUVScale; //!< UV scale vector for generating texture coordinates
288 Standard_Real myInitAng;
289 Standard_Boolean myCompBB; //!< if TRUE, then bounding box should be recomputed
42cf5bc1 290
291};
292
87432b82 293DEFINE_STANDARD_HANDLE(AIS_Shape, AIS_InteractiveObject)
42cf5bc1 294
295#endif // _AIS_Shape_HeaderFile