0029988: AIS_Shape - SetWidth() and SetColor() has no effect for FaceBoundary
[occt.git] / src / AIS / AIS_Shape.hxx
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
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>
25
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.
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();
54 //!   aPrs->Attributes()->SetShadingAspect (new Prs3d_ShadingAspect());
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).
59 class AIS_Shape : public AIS_InteractiveObject
60 {
61   DEFINE_STANDARD_RTTIEXT(AIS_Shape, AIS_InteractiveObject)
62 public:
63
64   //! Initializes construction of the shape shap from wires,
65   //! edges and vertices.
66   Standard_EXPORT AIS_Shape(const TopoDS_Shape& shap);
67
68   //! Returns index 0. This value refers to SHAPE from TopAbs_ShapeEnum
69   virtual Standard_Integer Signature() const Standard_OVERRIDE { return 0; }
70
71   //! Returns Object as the type of Interactive Object.
72   virtual AIS_KindOfInteractive Type() const Standard_OVERRIDE { return AIS_KOI_Shape; }
73
74   //! Returns true if the Interactive Object accepts shape decomposition.
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
83   //! Constructs an instance of the shape object theShape.
84   void SetShape (const TopoDS_Shape& theShape)
85   {
86     myshape  = theShape;
87     myCompBB = Standard_True;
88   }
89
90   //! Alias for ::SetShape().
91   void Set (const TopoDS_Shape& theShape) { SetShape (theShape); }
92
93   //! Sets a local value for deviation coefficient for this specific shape.
94   Standard_EXPORT Standard_Boolean SetOwnDeviationCoefficient();
95   
96   //! Sets a local value for HLR deviation coefficient for this specific shape.
97   Standard_EXPORT Standard_Boolean SetOwnHLRDeviationCoefficient();
98   
99   //! Sets a local value for deviation angle for this specific shape.
100   Standard_EXPORT Standard_Boolean SetOwnDeviationAngle();
101   
102   //! Sets a local value for HLR deviation angle for this specific shape.
103   Standard_EXPORT Standard_Boolean SetOwnHLRDeviationAngle();
104   
105   //! Sets a local value for deviation coefficient for this specific shape.
106   Standard_EXPORT void SetOwnDeviationCoefficient (const Standard_Real aCoefficient);
107   
108   //! sets myOwnHLRDeviationCoefficient field in Prs3d_Drawer &
109   //! recomputes presentation
110   Standard_EXPORT void SetOwnHLRDeviationCoefficient (const Standard_Real aCoefficient);
111   
112   //! this compute a new angle and Deviation from the value anAngle
113   //! and set the values stored in myDrawer with these that become local to the shape
114   Standard_EXPORT void SetAngleAndDeviation (const Standard_Real anAngle);
115   
116   //! gives back the angle initial value put by the User.
117   Standard_EXPORT Standard_Real UserAngle() const;
118   
119   //! sets myOwnDeviationAngle field in Prs3d_Drawer & recomputes presentation
120   Standard_EXPORT void SetOwnDeviationAngle (const Standard_Real anAngle);
121   
122   //! this compute a new Angle and Deviation from the value anAngle for HLR
123   //! and set the values stored in myDrawer for with these that become local to the shape
124   Standard_EXPORT void SetHLRAngleAndDeviation (const Standard_Real anAngle);
125   
126   //! sets myOwnHLRDeviationAngle field in Prs3d_Drawer & recomputes presentation
127   Standard_EXPORT void SetOwnHLRDeviationAngle (const Standard_Real anAngle);
128   
129   //! Returns true and the values of the deviation
130   //! coefficient aCoefficient and the previous deviation
131   //! coefficient aPreviousCoefficient. If these values are
132   //! not already set, false is returned.
133   Standard_EXPORT Standard_Boolean OwnDeviationCoefficient (Standard_Real& aCoefficient, Standard_Real& aPreviousCoefficient) const;
134   
135   //! Returns   true and the values of the HLR deviation
136   //! coefficient aCoefficient and the previous HLR
137   //! deviation coefficient aPreviousCoefficient. If these
138   //! values are not already set, false is returned.
139   Standard_EXPORT Standard_Boolean OwnHLRDeviationCoefficient (Standard_Real& aCoefficient, Standard_Real& aPreviousCoefficient) const;
140   
141   //! Returns true and the values of the deviation angle
142   //! anAngle and the previous deviation angle aPreviousAngle.
143   //! If these values are not already set, false is returned.
144   Standard_EXPORT Standard_Boolean OwnDeviationAngle (Standard_Real& anAngle, Standard_Real& aPreviousAngle) const;
145   
146   //! Returns true and the values   of the HLR deviation
147   //! angle anAngle and of the previous HLR deviation
148   //! angle aPreviousAngle. If these values are not
149   //! already set, false is returned.
150   Standard_EXPORT Standard_Boolean OwnHLRDeviationAngle (Standard_Real& anAngle, Standard_Real& aPreviousAngle) const;
151   
152   //! Sets the type of HLR algorithm used by the shape
153   void SetTypeOfHLR (const Prs3d_TypeOfHLR theTypeOfHLR) {  myDrawer->SetTypeOfHLR (theTypeOfHLR); }
154
155   //! Gets the type of HLR algorithm
156   Prs3d_TypeOfHLR TypeOfHLR() const { return myDrawer->TypeOfHLR(); }
157
158   //! Sets the color aColor in the reconstructed
159   //! compound shape. Acts via the Drawer methods below on the appearance of:
160   //! -   free boundaries:
161   //! Prs3d_Drawer_FreeBoundaryAspect,
162   //! -   isos: Prs3d_Drawer_UIsoAspect,
163   //! Prs3dDrawer_VIsoAspect,
164   //! -   shared boundaries:
165   //! Prs3d_Drawer_UnFreeBoundaryAspect,
166   //! -   shading: Prs3d_Drawer_ShadingAspect,
167   //! -   visible line color in hidden line mode:
168   //! Prs3d_Drawer_SeenLineAspect
169   //! -   hidden line color in hidden line mode:
170   //! Prs3d_Drawer_HiddenLineAspect.
171   Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
172
173   //! Removes settings for color in the reconstructed compound shape.
174   Standard_EXPORT virtual void UnsetColor() Standard_OVERRIDE;
175   
176   //! Sets the value aValue for line width in the reconstructed compound shape.
177   //! Changes line aspects for lines presentation.
178   Standard_EXPORT virtual void SetWidth (const Standard_Real aValue) Standard_OVERRIDE;
179   
180   //! Removes the setting for line width in the reconstructed compound shape.
181   Standard_EXPORT virtual void UnsetWidth() Standard_OVERRIDE;
182
183   //! Allows you to provide settings for the material aName
184   //! in the reconstructed compound shape.
185   Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& aName) Standard_OVERRIDE;
186   
187   //! Removes settings for material in the reconstructed compound shape.
188   Standard_EXPORT virtual void UnsetMaterial() Standard_OVERRIDE;
189   
190   //! Sets the value aValue for transparency in the reconstructed compound shape.
191   Standard_EXPORT virtual void SetTransparency (const Standard_Real aValue = 0.6) Standard_OVERRIDE;
192   
193   //! Removes the setting for transparency in the reconstructed compound shape.
194   Standard_EXPORT virtual void UnsetTransparency() Standard_OVERRIDE;
195   
196   //! Constructs a bounding box with which to reconstruct
197   //! compound topological shapes for presentation.
198   Standard_EXPORT virtual const Bnd_Box& BoundingBox();
199   
200   //! AIS_InteractiveObject defines another virtual method BoundingBox,
201   //! which is not the same as above; keep it visible.
202   using AIS_InteractiveObject::BoundingBox;
203
204   //! Returns the Color attributes of the shape accordingly to
205   //! the current facing model;
206   Standard_EXPORT virtual void Color (Quantity_Color& aColor) const Standard_OVERRIDE;
207   
208   //! Returns the NameOfMaterial attributes of the shape accordingly to
209   //! the current facing model;
210   Standard_EXPORT virtual Graphic3d_NameOfMaterial Material() const Standard_OVERRIDE;
211   
212   //! Returns the transparency attributes of the shape accordingly to
213   //! the current facing model;
214   Standard_EXPORT virtual Standard_Real Transparency() const Standard_OVERRIDE;
215
216   //! Return shape type for specified selection mode.
217   static TopAbs_ShapeEnum SelectionType (const Standard_Integer theSelMode)
218   {
219     switch (theSelMode)
220     {
221       case 1: return TopAbs_VERTEX;
222       case 2: return TopAbs_EDGE;
223       case 3: return TopAbs_WIRE;
224       case 4: return TopAbs_FACE;
225       case 5: return TopAbs_SHELL;
226       case 6: return TopAbs_SOLID;
227       case 7: return TopAbs_COMPSOLID;
228       case 8: return TopAbs_COMPOUND;
229       case 0: return TopAbs_SHAPE;
230     }
231     return TopAbs_SHAPE;
232   }
233
234   //! Return selection mode for specified shape type.
235   static Standard_Integer SelectionMode (const TopAbs_ShapeEnum theShapeType)
236   {
237     switch (theShapeType)
238     {
239       case TopAbs_VERTEX:    return 1;
240       case TopAbs_EDGE:      return 2;
241       case TopAbs_WIRE:      return 3;
242       case TopAbs_FACE:      return 4;
243       case TopAbs_SHELL:     return 5;
244       case TopAbs_SOLID:     return 6;
245       case TopAbs_COMPSOLID: return 7;
246       case TopAbs_COMPOUND:  return 8;
247       case TopAbs_SHAPE:     return 0;
248     }
249     return 0;
250   }
251
252 public: //! @name methods to alter texture mapping properties
253
254   //! Return texture repeat UV values; (1, 1) by default.
255   const gp_Pnt2d& TextureRepeatUV() const { return myUVRepeat; }
256
257   //! Sets the number of occurrences of the texture on each face. The texture itself is parameterized in (0,1) by (0,1).
258   //! Each face of the shape to be textured is parameterized in UV space (Umin,Umax) by (Vmin,Vmax).
259   void SetTextureRepeatUV (const gp_Pnt2d& theRepeatUV) { myUVRepeat = theRepeatUV; }
260
261   //! Return texture origin UV position; (0, 0) by default.
262   const gp_Pnt2d& TextureOriginUV() const { return myUVOrigin; }
263
264   //! Use this method to change the origin of the texture.
265   //! The texel (0,0) will be mapped to the surface (myUVOrigin.X(), myUVOrigin.Y()).
266   void SetTextureOriginUV (const gp_Pnt2d& theOriginUV) { myUVOrigin = theOriginUV; }
267
268   //! Return scale factor for UV coordinates; (1, 1) by default.
269   const gp_Pnt2d& TextureScaleUV() const { return myUVScale; }
270
271   //! Use this method to scale the texture (percent of the face).
272   //! You can specify a scale factor for both U and V.
273   //! Example: if you set ScaleU and ScaleV to 0.5 and you enable texture repeat,
274   //!          the texture will appear twice on the face in each direction.
275   void SetTextureScaleUV (const gp_Pnt2d& theScaleUV) { myUVScale = theScaleUV; }
276
277 protected:
278
279   //! Compute normal presentation.
280   Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
281                                         const Handle(Prs3d_Presentation)& thePrs,
282                                         const Standard_Integer theMode) Standard_OVERRIDE;
283
284   //! Compute projected presentation.
285   virtual void Compute (const Handle(Prs3d_Projector)& theProjector,
286                         const Handle(Prs3d_Presentation)& thePrs) Standard_OVERRIDE
287   {
288     computeHlrPresentation (theProjector, thePrs, myshape, myDrawer);
289   }
290
291   //! Compute projected presentation with transformation.
292   virtual void Compute (const Handle(Prs3d_Projector)& theProjector,
293                         const Handle(Geom_Transformation)& theTrsf,
294                         const Handle(Prs3d_Presentation)& thePrs) Standard_OVERRIDE
295   {
296     const TopLoc_Location& aLoc = myshape.Location();
297     const TopoDS_Shape aShape = myshape.Located (TopLoc_Location (theTrsf->Trsf()) * aLoc);
298     computeHlrPresentation (theProjector, thePrs, aShape, myDrawer);
299   }
300
301   //! Compute selection.
302   Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
303                                                  const Standard_Integer theMode) Standard_OVERRIDE;
304   
305   Standard_EXPORT void LoadRecomputable (const Standard_Integer TheMode);
306   
307   //! Create own aspects (if they do not exist) and set color to them.
308   //! @return TRUE if new aspects have been created
309   Standard_EXPORT bool setColor (const Handle(Prs3d_Drawer)& theDrawer, const Quantity_Color& theColor) const;
310   
311   //! Create own aspects (if they do not exist) and set width to them.
312   //! @return TRUE if new aspects have been created
313   Standard_EXPORT bool setWidth (const Handle(Prs3d_Drawer)& theDrawer, const Standard_Real theWidth) const;
314   
315   Standard_EXPORT void setTransparency (const Handle(Prs3d_Drawer)& theDrawer, const Standard_Real theValue) const;
316   
317   Standard_EXPORT void setMaterial (const Handle(Prs3d_Drawer)& theDrawer, const Graphic3d_MaterialAspect& theMaterial, const Standard_Boolean theToKeepColor, const Standard_Boolean theToKeepTransp) const;
318
319 public:
320
321   //! Compute HLR presentation for specified shape.
322   Standard_EXPORT static void computeHlrPresentation (const Handle(Prs3d_Projector)& theProjector,
323                                                       const Handle(Prs3d_Presentation)& thePrs,
324                                                       const TopoDS_Shape& theShape,
325                                                       const Handle(Prs3d_Drawer)& theDrawer);
326
327 protected:
328
329   TopoDS_Shape     myshape;    //!< shape to display
330   Bnd_Box          myBB;       //!< cached bounding box of the shape
331   gp_Pnt2d         myUVOrigin; //!< UV origin vector for generating texture coordinates
332   gp_Pnt2d         myUVRepeat; //!< UV repeat vector for generating texture coordinates
333   gp_Pnt2d         myUVScale;  //!< UV scale  vector for generating texture coordinates
334   Standard_Real    myInitAng;
335   Standard_Boolean myCompBB;   //!< if TRUE, then bounding box should be recomputed
336
337 };
338
339 DEFINE_STANDARD_HANDLE(AIS_Shape, AIS_InteractiveObject)
340
341 #endif // _AIS_Shape_HeaderFile