0027682: Visualization - provide method Prs3d_Drawer::SetShaderProgram() for setting...
[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
25 //! Presentation of the shape with customizable sub-shapes properties.
26 class AIS_ColoredShape : public AIS_Shape
27 {
28 public:
29
30   //! Default constructor
31   Standard_EXPORT AIS_ColoredShape (const TopoDS_Shape& theShape);
32
33   //! Copy constructor
34   Standard_EXPORT AIS_ColoredShape (const Handle(AIS_Shape)& theShape);
35
36 public: //! @name sub-shape aspects
37
38   //! Customize properties of specified sub-shape.
39   //! The shape will be stored in the map but ignored, if it is not sub-shape of main Shape!
40   //! This method can be used to mark sub-shapes with customizable properties.
41   Standard_EXPORT Handle(AIS_ColoredDrawer) CustomAspects (const TopoDS_Shape& theShape);
42
43   //! Reset the map of custom sub-shape aspects.
44   Standard_EXPORT void ClearCustomAspects();
45
46   //! Reset custom properties of specified sub-shape.
47   //! @param theToUnregister unregister or not sub-shape from the map
48   Standard_EXPORT void UnsetCustomAspects (const TopoDS_Shape&    theShape,
49                                            const Standard_Boolean theToUnregister = Standard_False);
50
51   //! Customize color of specified sub-shape
52   Standard_EXPORT void SetCustomColor (const TopoDS_Shape&   theShape,
53                                        const Quantity_Color& theColor);
54
55   //! Customize line width of specified sub-shape
56   Standard_EXPORT void SetCustomWidth (const TopoDS_Shape& theShape,
57                                        const Standard_Real theLineWidth);
58
59   //! Return the map of custom aspects.
60   const AIS_DataMapOfShapeDrawer& CustomAspectsMap() const { return myShapeColors; }
61
62   //! Return the map of custom aspects.
63   AIS_DataMapOfShapeDrawer& ChangeCustomAspectsMap() { return myShapeColors; }
64
65 public: //! @name global aspects
66
67   //! Setup color of entire shape.
68   Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
69
70   //! Setup line width of entire shape.
71   Standard_EXPORT virtual void SetWidth (const Standard_Real theLineWidth) Standard_OVERRIDE;
72
73   //! Sets transparency value.
74   Standard_EXPORT virtual void SetTransparency (const Standard_Real theValue) Standard_OVERRIDE;
75
76   //! Sets the material aspect.
77   Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& theAspect) Standard_OVERRIDE;
78
79 protected: //! @name override presentation computation
80
81   Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
82                                         const Handle(Prs3d_Presentation)&           thePrs,
83                                         const Standard_Integer                      theMode) Standard_OVERRIDE;
84
85 protected:
86
87   typedef NCollection_DataMap<TopoDS_Shape, TopoDS_Shape,           TopTools_ShapeMapHasher> DataMapOfShapeShape;
88   typedef NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Compound, TopTools_ShapeMapHasher> DataMapOfShapeCompd;
89
90 protected:
91
92   //! Recursive function to map shapes.
93   //! @param theBaseKey                    the key to be used for undetailed shapes (default colors)
94   //! @param theSubshapeToParse            the subshape to be parsed
95   //! @param theSubshapeKeyshapeMap        shapes map Subshape (in the base shape) -> Keyshape (detailed shape)
96   //! @param theParentType                 the parent subshape type
97   //! @param theTypeKeyshapeDrawshapeArray the array of shape types to fill
98   Standard_EXPORT static Standard_Boolean dispatchColors (const TopoDS_Shape&        theBaseKey,
99                                                           const TopoDS_Shape&        theSubshapeToParse,
100                                                           const DataMapOfShapeShape& theSubshapeKeyshapeMap,
101                                                           const TopAbs_ShapeEnum     theParentType,
102                                                           DataMapOfShapeCompd*       theTypeKeyshapeDrawshapeArray);
103
104   Standard_EXPORT static void dispatchColors (const TopoDS_Shape&             theBaseShape,
105                                               const AIS_DataMapOfShapeDrawer& theKeyshapeColorMap,
106                                               DataMapOfShapeCompd*            theTypeKeyshapeDrawshapeArray);
107
108 protected:
109
110   //! Add shape to presentation
111   //! @param thePrs         the presentation
112   //! @param theDispatched  the shapes map with unique attributes
113   //! @param theMode        display mode
114   //! @param theVolume      how to interpret theDispatched shapes - as Closed volumes, as Open volumes
115   //!                       or to perform Autodetection
116   Standard_EXPORT void addShapesWithCustomProps (const Handle(Prs3d_Presentation)& thePrs,
117                                                  DataMapOfShapeCompd*              theDispatched,
118                                                  const Standard_Integer            theMode,
119                                                  const StdPrs_Volume               theVolume);
120
121   //! Check all shapes from myShapeColorsfor visibility
122   Standard_EXPORT Standard_Boolean isShapeEntirelyVisible() const;
123
124   //! Check a shape with unique attributes for visibility of all 2d subshape
125   Standard_EXPORT Standard_Boolean isShapeEntirelyVisible (DataMapOfShapeCompd* theDispatched) const;
126
127   //! Resolve (parse) theKeyShape into subshapes, search in they for theBaseShape,
128   //! bind all resolved subshapes with theOriginKeyShape and store all binds in theSubshapeKeyshapeMap
129   //! @param theSubshapeKeyshapeMap        shapes map: resolved and found theBaseShape subshape -> theOriginKeyShape 
130   //! @param theBaseShape                  a shape to be sought
131   //! @param theBaseKey                    a shape to be resolved (parse) into smaller (in topological sense)
132   //!                                      subshapes for new bind cycle
133   //! @param theOriginKeyShape             the key to be used for undetailed shapes (default colors)
134   Standard_EXPORT static void bindSubShapes (DataMapOfShapeShape& theSubshapeKeyshapeMap,
135                                              const TopoDS_Shape&  theBaseShape,
136                                              const TopoDS_Shape&  theKeyShape,
137                                              const TopoDS_Shape&  theOriginKeyShape);
138
139 protected:
140
141   AIS_DataMapOfShapeDrawer myShapeColors;
142
143 public:
144
145   DEFINE_STANDARD_RTTIEXT(AIS_ColoredShape,AIS_Shape)
146
147 };
148
149 DEFINE_STANDARD_HANDLE(AIS_ColoredShape, AIS_Shape)
150
151 #endif // _AIS_ColoredShape_HeaderFile