0028621: Visualization - AIS_ColoredShape::UnsetTransparency() is not implemented
[occt.git] / src / AIS / AIS_ColoredShape.hxx
1 // Created on: 2014-04-24
2 // Created by: Kirill Gavrilov
3 // Copyright (c) 2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _AIS_ColoredShape_HeaderFile
17 #define _AIS_ColoredShape_HeaderFile
18
19 #include <AIS_DataMapOfShapeDrawer.hxx>
20 #include <AIS_Shape.hxx>
21 #include <NCollection_IndexedDataMap.hxx>
22 #include <StdPrs_Volume.hxx>
23 #include <TopoDS_Compound.hxx>
24 #include <TopTools_MapOfShape.hxx>
25 #include <TColStd_MapTransientHasher.hxx>
26
27 //! Presentation of the shape with customizable sub-shapes properties.
28 class AIS_ColoredShape : public AIS_Shape
29 {
30 public:
31
32   //! Default constructor
33   Standard_EXPORT AIS_ColoredShape (const TopoDS_Shape& theShape);
34
35   //! Copy constructor
36   Standard_EXPORT AIS_ColoredShape (const Handle(AIS_Shape)& theShape);
37
38 public: //! @name sub-shape aspects
39
40   //! Customize properties of specified sub-shape.
41   //! The shape will be stored in the map but ignored, if it is not sub-shape of main Shape!
42   //! This method can be used to mark sub-shapes with customizable properties.
43   Standard_EXPORT virtual Handle(AIS_ColoredDrawer) CustomAspects (const TopoDS_Shape& theShape);
44
45   //! Reset the map of custom sub-shape aspects.
46   Standard_EXPORT virtual void ClearCustomAspects();
47
48   //! Reset custom properties of specified sub-shape.
49   //! @param theToUnregister unregister or not sub-shape from the map
50   Standard_EXPORT void UnsetCustomAspects (const TopoDS_Shape&    theShape,
51                                            const Standard_Boolean theToUnregister = Standard_False);
52
53   //! Customize color of specified sub-shape
54   Standard_EXPORT void SetCustomColor (const TopoDS_Shape&   theShape,
55                                        const Quantity_Color& theColor);
56
57   //! Customize line width of specified sub-shape
58   Standard_EXPORT void SetCustomWidth (const TopoDS_Shape& theShape,
59                                        const Standard_Real theLineWidth);
60
61   //! Return the map of custom aspects.
62   const AIS_DataMapOfShapeDrawer& CustomAspectsMap() const { return myShapeColors; }
63
64   //! Return the map of custom aspects.
65   AIS_DataMapOfShapeDrawer& ChangeCustomAspectsMap() { return myShapeColors; }
66
67 public: //! @name global aspects
68
69   //! Setup color of entire shape.
70   Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
71
72   //! Setup line width of entire shape.
73   Standard_EXPORT virtual void SetWidth (const Standard_Real theLineWidth) Standard_OVERRIDE;
74
75   //! Sets transparency value.
76   Standard_EXPORT virtual void SetTransparency (const Standard_Real theValue) Standard_OVERRIDE;
77
78   //! Removes the setting for transparency in the reconstructed compound shape.
79   Standard_EXPORT virtual void UnsetTransparency() Standard_OVERRIDE;
80
81   //! Sets the material aspect.
82   Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& theAspect) Standard_OVERRIDE;
83
84 protected: //! @name override presentation computation
85
86   Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
87                                         const Handle(Prs3d_Presentation)&           thePrs,
88                                         const Standard_Integer                      theMode) Standard_OVERRIDE;
89
90 protected:
91
92   typedef NCollection_IndexedDataMap<Handle(AIS_ColoredDrawer), TopoDS_Compound, TColStd_MapTransientHasher> DataMapOfDrawerCompd;
93
94 protected:
95
96   //! Recursive function to map shapes.
97   //! @param theParentDrawer   the drawer to be used for undetailed shapes (default colors)
98   //! @param theShapeToParse   the subshape to be recursively parsed
99   //! @param theShapeDrawerMap shapes map Subshape (in the base shape) -> Drawer
100   //! @param theParentType     the parent subshape type
101   //! @param theIsParentClosed flag indicating that specified shape is part of closed Solid
102   //! @param theDrawerOpenedShapePerType the array of shape types to fill
103   //! @param theDrawerClosedFaces        the map for closed faces
104   Standard_EXPORT static Standard_Boolean dispatchColors (const Handle(AIS_ColoredDrawer)& theParentDrawer,
105                                                           const TopoDS_Shape& theShapeToParse,
106                                                           const AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
107                                                           const TopAbs_ShapeEnum theParentType,
108                                                           const Standard_Boolean theIsParentClosed,
109                                                           DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
110                                                           DataMapOfDrawerCompd& theDrawerClosedFaces);
111 protected:
112
113   //! Add shape to presentation
114   //! @param thePrs the presentation
115   //! @param theDrawerOpenedShapePerType the shapes map with unique attributes
116   //! @param theDrawerClosedFaces the map of attributes for closed faces
117   //! @param theMode display mode
118   Standard_EXPORT void addShapesWithCustomProps (const Handle(Prs3d_Presentation)& thePrs,
119                                                  const DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
120                                                  const DataMapOfDrawerCompd& theDrawerClosedFaces,
121                                                  const Standard_Integer theMode);
122
123   //! Check all shapes from myShapeColorsfor visibility
124   Standard_EXPORT Standard_Boolean isShapeEntirelyVisible() const;
125
126   //! Resolve (parse) theKeyShape into subshapes, search in they for theBaseShape,
127   //! bind all resolved subshapes with theOriginKeyShape and store all binds in theShapeDrawerMap
128   //! @param theShapeDrawerMap shapes map: resolved and found theBaseShape subshape -> theOriginKeyShape
129   //! @param theKeyShape       a shape to be resolved (parse) into smaller (in topological sense)
130   //!                          subshapes for new bind cycle
131   //! @param theDrawer         assigned drawer
132   Standard_EXPORT void bindSubShapes (AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
133                                       const TopoDS_Shape& theKeyShape,
134                                       const Handle(AIS_ColoredDrawer)& theDrawer);
135
136 protected:
137
138   AIS_DataMapOfShapeDrawer myShapeColors;
139
140 public:
141
142   DEFINE_STANDARD_RTTIEXT(AIS_ColoredShape,AIS_Shape)
143
144 };
145
146 DEFINE_STANDARD_HANDLE(AIS_ColoredShape, AIS_Shape)
147
148 #endif // _AIS_ColoredShape_HeaderFile