0028036: Visualization, AIS_ColoredShape - handle correctly nested compounds within...
[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   //! Sets the material aspect.
79   Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& theAspect) Standard_OVERRIDE;
80
81 protected: //! @name override presentation computation
82
83   Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
84                                         const Handle(Prs3d_Presentation)&           thePrs,
85                                         const Standard_Integer                      theMode) Standard_OVERRIDE;
86
87 protected:
88
89   typedef NCollection_IndexedDataMap<Handle(AIS_ColoredDrawer), TopoDS_Compound, TColStd_MapTransientHasher> DataMapOfDrawerCompd;
90
91 protected:
92
93   //! Recursive function to map shapes.
94   //! @param theParentDrawer   the drawer to be used for undetailed shapes (default colors)
95   //! @param theShapeToParse   the subshape to be recursively parsed
96   //! @param theShapeDrawerMap shapes map Subshape (in the base shape) -> Drawer
97   //! @param theParentType     the parent subshape type
98   //! @param theIsParentClosed flag indicating that specified shape is part of closed Solid
99   //! @param theDrawerOpenedShapePerType the array of shape types to fill
100   //! @param theDrawerClosedFaces        the map for closed faces
101   Standard_EXPORT static Standard_Boolean dispatchColors (const Handle(AIS_ColoredDrawer)& theParentDrawer,
102                                                           const TopoDS_Shape& theShapeToParse,
103                                                           const AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
104                                                           const TopAbs_ShapeEnum theParentType,
105                                                           const Standard_Boolean theIsParentClosed,
106                                                           DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
107                                                           DataMapOfDrawerCompd& theDrawerClosedFaces);
108 protected:
109
110   //! Add shape to presentation
111   //! @param thePrs the presentation
112   //! @param theDrawerOpenedShapePerType the shapes map with unique attributes
113   //! @param theDrawerClosedFaces the map of attributes for closed faces
114   //! @param theMode display mode
115   Standard_EXPORT void addShapesWithCustomProps (const Handle(Prs3d_Presentation)& thePrs,
116                                                  const DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
117                                                  const DataMapOfDrawerCompd& theDrawerClosedFaces,
118                                                  const Standard_Integer theMode);
119
120   //! Check all shapes from myShapeColorsfor visibility
121   Standard_EXPORT Standard_Boolean isShapeEntirelyVisible() const;
122
123   //! Resolve (parse) theKeyShape into subshapes, search in they for theBaseShape,
124   //! bind all resolved subshapes with theOriginKeyShape and store all binds in theShapeDrawerMap
125   //! @param theShapeDrawerMap shapes map: resolved and found theBaseShape subshape -> theOriginKeyShape
126   //! @param theKeyShape       a shape to be resolved (parse) into smaller (in topological sense)
127   //!                          subshapes for new bind cycle
128   //! @param theDrawer         assigned drawer
129   Standard_EXPORT void bindSubShapes (AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
130                                       const TopoDS_Shape& theKeyShape,
131                                       const Handle(AIS_ColoredDrawer)& theDrawer);
132
133 protected:
134
135   AIS_DataMapOfShapeDrawer myShapeColors;
136
137 public:
138
139   DEFINE_STANDARD_RTTIEXT(AIS_ColoredShape,AIS_Shape)
140
141 };
142
143 DEFINE_STANDARD_HANDLE(AIS_ColoredShape, AIS_Shape)
144
145 #endif // _AIS_ColoredShape_HeaderFile