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
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 _AIS_Shape_HeaderFile
18 #define _AIS_Shape_HeaderFile
20 #include <AIS_InteractiveObject.hxx>
21 #include <Bnd_Box.hxx>
22 #include <TopoDS_Shape.hxx>
23 #include <Prs3d_Drawer.hxx>
24 #include <Prs3d_TypeOfHLR.hxx>
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.
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:
53 //! Handle(AIS_Shape) aPrs = new AIS_Shape();
54 //! aPrs->Attributes()->SetupOwnShadingAspect();
55 //! aPrs->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
56 //! aPrs->Attributes()->ShadingAspect()->Aspect()->SetTextureMap (new Graphic3d_Texture2Dmanual (Graphic3d_NOT_2D_ALUMINUM));
58 //! The texture itself is parametrized in (0,1)x(0,1).
59 class AIS_Shape : public AIS_InteractiveObject
61 DEFINE_STANDARD_RTTIEXT(AIS_Shape, AIS_InteractiveObject)
64 //! Initializes construction of the shape shap from wires,
65 //! edges and vertices.
66 Standard_EXPORT AIS_Shape(const TopoDS_Shape& shap);
68 //! Returns index 0. This value refers to SHAPE from TopAbs_ShapeEnum
69 virtual Standard_Integer Signature() const Standard_OVERRIDE { return 0; }
71 //! Returns Object as the type of Interactive Object.
72 virtual AIS_KindOfInteractive Type() const Standard_OVERRIDE { return AIS_KOI_Shape; }
74 //! Returns true if the Interactive Object accepts shape decomposition.
75 virtual Standard_Boolean AcceptShapeDecomposition() const Standard_OVERRIDE { return Standard_True; }
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; }
80 //! Returns this shape object.
81 const TopoDS_Shape& Shape() const { return myshape; }
83 //! Constructs an instance of the shape object theShape.
84 void SetShape (const TopoDS_Shape& theShape)
87 myCompBB = Standard_True;
90 //! Alias for ::SetShape().
91 void Set (const TopoDS_Shape& theShape) { SetShape (theShape); }
93 //! Sets a local value for deviation coefficient for this specific shape.
94 Standard_EXPORT Standard_Boolean SetOwnDeviationCoefficient();
96 //! Sets a local value for deviation angle for this specific shape.
97 Standard_EXPORT Standard_Boolean SetOwnDeviationAngle();
99 //! Sets a local value for deviation coefficient for this specific shape.
100 Standard_EXPORT void SetOwnDeviationCoefficient (const Standard_Real aCoefficient);
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);
106 //! gives back the angle initial value put by the User.
107 Standard_EXPORT Standard_Real UserAngle() const;
109 //! sets myOwnDeviationAngle field in Prs3d_Drawer & recomputes presentation
110 Standard_EXPORT void SetOwnDeviationAngle (const Standard_Real anAngle);
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;
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;
123 //! Sets the type of HLR algorithm used by the shape
124 void SetTypeOfHLR (const Prs3d_TypeOfHLR theTypeOfHLR) { myDrawer->SetTypeOfHLR (theTypeOfHLR); }
126 //! Gets the type of HLR algorithm
127 Prs3d_TypeOfHLR TypeOfHLR() const { return myDrawer->TypeOfHLR(); }
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.
142 Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
144 //! Removes settings for color in the reconstructed compound shape.
145 Standard_EXPORT virtual void UnsetColor() Standard_OVERRIDE;
147 //! Sets the value aValue for line width in the reconstructed compound shape.
148 //! Changes line aspects for lines presentation.
149 Standard_EXPORT virtual void SetWidth (const Standard_Real aValue) Standard_OVERRIDE;
151 //! Removes the setting for line width in the reconstructed compound shape.
152 Standard_EXPORT virtual void UnsetWidth() Standard_OVERRIDE;
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;
158 //! Removes settings for material in the reconstructed compound shape.
159 Standard_EXPORT virtual void UnsetMaterial() Standard_OVERRIDE;
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;
164 //! Removes the setting for transparency in the reconstructed compound shape.
165 Standard_EXPORT virtual void UnsetTransparency() Standard_OVERRIDE;
167 //! Constructs a bounding box with which to reconstruct
168 //! compound topological shapes for presentation.
169 Standard_EXPORT virtual const Bnd_Box& BoundingBox();
171 //! AIS_InteractiveObject defines another virtual method BoundingBox,
172 //! which is not the same as above; keep it visible.
173 using AIS_InteractiveObject::BoundingBox;
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;
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;
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;
187 //! Return shape type for specified selection mode.
188 static TopAbs_ShapeEnum SelectionType (const Standard_Integer theSelMode)
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;
205 //! Return selection mode for specified shape type.
206 static Standard_Integer SelectionMode (const TopAbs_ShapeEnum theShapeType)
208 switch (theShapeType)
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;
223 public: //! @name methods to alter texture mapping properties
225 //! Return texture repeat UV values; (1, 1) by default.
226 const gp_Pnt2d& TextureRepeatUV() const { return myUVRepeat; }
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; }
232 //! Return texture origin UV position; (0, 0) by default.
233 const gp_Pnt2d& TextureOriginUV() const { return myUVOrigin; }
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; }
239 //! Return scale factor for UV coordinates; (1, 1) by default.
240 const gp_Pnt2d& TextureScaleUV() const { return myUVScale; }
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; }
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;
255 //! Compute projected presentation.
256 virtual void computeHLR (const Handle(Graphic3d_Camera)& theProjector,
257 const Handle(Geom_Transformation)& theTrsf,
258 const Handle(Prs3d_Presentation)& thePrs) Standard_OVERRIDE
260 if (!theTrsf.IsNull()
261 && theTrsf->Form() != gp_Identity)
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);
269 computeHlrPresentation (theProjector, thePrs, myshape, myDrawer);
273 //! Compute selection.
274 Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
275 const Standard_Integer theMode) Standard_OVERRIDE;
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;
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;
285 Standard_EXPORT void setTransparency (const Handle(Prs3d_Drawer)& theDrawer, const Standard_Real theValue) const;
287 Standard_EXPORT void setMaterial (const Handle(Prs3d_Drawer)& theDrawer, const Graphic3d_MaterialAspect& theMaterial, const Standard_Boolean theToKeepColor, const Standard_Boolean theToKeepTransp) const;
289 //! Replace aspects of already computed groups from drawer link by the new own value.
290 Standard_EXPORT void replaceWithNewOwnAspects();
294 //! Compute HLR presentation for specified shape.
295 Standard_EXPORT static void computeHlrPresentation (const Handle(Graphic3d_Camera)& theProjector,
296 const Handle(Prs3d_Presentation)& thePrs,
297 const TopoDS_Shape& theShape,
298 const Handle(Prs3d_Drawer)& theDrawer);
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;
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
315 DEFINE_STANDARD_HANDLE(AIS_Shape, AIS_InteractiveObject)
317 #endif // _AIS_Shape_HeaderFile