0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[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 class StdSelect_BRepOwner;
28
29 //! Presentation of the shape with customizable sub-shapes properties.
30 class AIS_ColoredShape : public AIS_Shape
31 {
32 public:
33
34   //! Default constructor
35   Standard_EXPORT AIS_ColoredShape (const TopoDS_Shape& theShape);
36
37   //! Copy constructor
38   Standard_EXPORT AIS_ColoredShape (const Handle(AIS_Shape)& theShape);
39
40 public: //! @name sub-shape aspects
41
42   //! Customize properties of specified sub-shape.
43   //! The shape will be stored in the map but ignored, if it is not sub-shape of main Shape!
44   //! This method can be used to mark sub-shapes with customizable properties.
45   Standard_EXPORT virtual Handle(AIS_ColoredDrawer) CustomAspects (const TopoDS_Shape& theShape);
46
47   //! Reset the map of custom sub-shape aspects.
48   Standard_EXPORT virtual void ClearCustomAspects();
49
50   //! Reset custom properties of specified sub-shape.
51   //! @param theToUnregister unregister or not sub-shape from the map
52   Standard_EXPORT void UnsetCustomAspects (const TopoDS_Shape&    theShape,
53                                            const Standard_Boolean theToUnregister = Standard_False);
54
55   //! Customize color of specified sub-shape
56   Standard_EXPORT void SetCustomColor (const TopoDS_Shape&   theShape,
57                                        const Quantity_Color& theColor);
58
59   //! Customize transparency of specified sub-shape
60   Standard_EXPORT void SetCustomTransparency (const TopoDS_Shape& theShape,
61                                               Standard_Real theTransparency);
62
63   //! Customize line width of specified sub-shape
64   Standard_EXPORT void SetCustomWidth (const TopoDS_Shape& theShape,
65                                        const Standard_Real theLineWidth);
66
67   //! Return the map of custom aspects.
68   const AIS_DataMapOfShapeDrawer& CustomAspectsMap() const { return myShapeColors; }
69
70   //! Return the map of custom aspects.
71   AIS_DataMapOfShapeDrawer& ChangeCustomAspectsMap() { return myShapeColors; }
72
73 public: //! @name global aspects
74
75   //! Setup color of entire shape.
76   Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
77
78   //! Setup line width of entire shape.
79   Standard_EXPORT virtual void SetWidth (const Standard_Real theLineWidth) Standard_OVERRIDE;
80
81   //! Sets transparency value.
82   Standard_EXPORT virtual void SetTransparency (const Standard_Real theValue) Standard_OVERRIDE;
83
84   //! Sets the material aspect.
85   Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& theAspect) Standard_OVERRIDE;
86
87 public:
88
89   //! Removes the setting for transparency in the reconstructed compound shape.
90   Standard_EXPORT virtual void UnsetTransparency() Standard_OVERRIDE;
91
92   //! Setup line width of entire shape.
93   Standard_EXPORT virtual void UnsetWidth() Standard_OVERRIDE;
94
95 protected: //! @name override presentation computation
96
97   //! Compute presentation considering sub-shape color map.
98   Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
99                                         const Handle(Prs3d_Presentation)&           thePrs,
100                                         const Standard_Integer                      theMode) Standard_OVERRIDE;
101
102   //! Compute selection considering sub-shape hidden state.
103   Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
104                                                  const Standard_Integer theMode) Standard_OVERRIDE;
105
106 protected:
107
108   typedef NCollection_IndexedDataMap<Handle(AIS_ColoredDrawer), TopoDS_Compound, TColStd_MapTransientHasher> DataMapOfDrawerCompd;
109
110 protected:
111
112   //! Recursive function to map shapes.
113   //! @param theParentDrawer   the drawer to be used for undetailed shapes (default colors)
114   //! @param theShapeToParse   the subshape to be recursively parsed
115   //! @param theShapeDrawerMap shapes map Subshape (in the base shape) -> Drawer
116   //! @param theParentType     the parent subshape type
117   //! @param theIsParentClosed flag indicating that specified shape is part of closed Solid
118   //! @param theDrawerOpenedShapePerType the array of shape types to fill
119   //! @param theDrawerClosedFaces        the map for closed faces
120   Standard_EXPORT static Standard_Boolean dispatchColors (const Handle(AIS_ColoredDrawer)& theParentDrawer,
121                                                           const TopoDS_Shape& theShapeToParse,
122                                                           const AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
123                                                           const TopAbs_ShapeEnum theParentType,
124                                                           const Standard_Boolean theIsParentClosed,
125                                                           DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
126                                                           DataMapOfDrawerCompd& theDrawerClosedFaces);
127 protected:
128
129   //! Extract myShapeColors map (KeyshapeColored -> Color) to subshapes map (Subshape -> Color).
130   //! This needed when colored shape is not part of BaseShape (but subshapes are) and actually container for subshapes.
131   Standard_EXPORT void fillSubshapeDrawerMap (AIS_DataMapOfShapeDrawer& theSubshapeDrawerMap) const;
132
133   //! Add shape to presentation
134   //! @param thePrs the presentation
135   //! @param theDrawerOpenedShapePerType the shapes map with unique attributes
136   //! @param theDrawerClosedFaces the map of attributes for closed faces
137   //! @param theMode display mode
138   Standard_EXPORT void addShapesWithCustomProps (const Handle(Prs3d_Presentation)& thePrs,
139                                                  const DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
140                                                  const DataMapOfDrawerCompd& theDrawerClosedFaces,
141                                                  const Standard_Integer theMode);
142
143   //! Check all shapes from myShapeColorsfor visibility
144   Standard_EXPORT Standard_Boolean isShapeEntirelyVisible() const;
145
146   //! Resolve (parse) theKeyShape into subshapes, search in they for theBaseShape,
147   //! bind all resolved subshapes with theOriginKeyShape and store all binds in theShapeDrawerMap
148   //! @param theShapeDrawerMap shapes map: resolved and found theBaseShape subshape -> theOriginKeyShape
149   //! @param theKeyShape       a shape to be resolved (parse) into smaller (in topological sense)
150   //!                          subshapes for new bind cycle
151   //! @param theDrawer         assigned drawer
152   Standard_EXPORT void bindSubShapes (AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
153                                       const TopoDS_Shape& theKeyShape,
154                                       const Handle(AIS_ColoredDrawer)& theDrawer) const;
155
156   //! Add sub-shape to selection considering hidden state (recursively).
157   //! @param theParentDrawer   drawer of parent shape
158   //! @param theShapeDrawerMap shapes map
159   //! @param theShape          shape to compute sensitive entities
160   //! @param theOwner          selectable owner object
161   //! @param theSelection      selection to append new sensitive entities
162   //! @param theTypOfSel       type of selection
163   //! @param theDeflection     linear deflection
164   //! @param theDeflAngle      angular deflection
165   Standard_EXPORT void computeSubshapeSelection (const Handle(AIS_ColoredDrawer)& theParentDrawer,
166                                                  const AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
167                                                  const TopoDS_Shape& theShape,
168                                                  const Handle(StdSelect_BRepOwner)& theOwner,
169                                                  const Handle(SelectMgr_Selection)& theSelection,
170                                                  const TopAbs_ShapeEnum theTypOfSel,
171                                                  const Standard_Integer thePriority,
172                                                  const Standard_Real theDeflection,
173                                                  const Standard_Real theDeflAngle);
174
175 protected:
176
177   AIS_DataMapOfShapeDrawer myShapeColors;
178
179 public:
180
181   DEFINE_STANDARD_RTTIEXT(AIS_ColoredShape,AIS_Shape)
182
183 };
184
185 DEFINE_STANDARD_HANDLE(AIS_ColoredShape, AIS_Shape)
186
187 #endif // _AIS_ColoredShape_HeaderFile