0fedcf8d205fdca63ba159a013f6aad2f02fac14
[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_Drawer.hxx>
20 #include <AIS_Shape.hxx>
21
22 #include <NCollection_DataMap.hxx>
23 #include <NCollection_IndexedDataMap.hxx>
24 #include <TopTools_ShapeMapHasher.hxx>
25 #include <TopoDS_Compound.hxx>
26
27 //! Customizable properties.
28 class AIS_ColoredDrawer : public AIS_Drawer
29 {
30 public:
31
32   AIS_ColoredDrawer (const Handle(AIS_Drawer)& theLink)
33   : myHasOwnColor (Standard_False),
34     myHasOwnWidth (Standard_False)
35   {
36     Link (theLink);
37   }
38
39   Standard_Boolean HasOwnColor() const                              { return myHasOwnColor; }
40   void             UnsetOwnColor()                                  { myHasOwnColor = Standard_False; }
41   void             SetOwnColor (const Quantity_Color& /*theColor*/) { myHasOwnColor = Standard_True;  }
42   Standard_Boolean HasOwnWidth() const                              { return myHasOwnWidth; }
43   void             UnsetOwnWidth()                                  { myHasOwnWidth = Standard_False; }
44   void             SetOwnWidth (const Standard_Real /*theWidth*/)   { myHasOwnWidth = Standard_True;  }
45
46 public:  //! @name list of overridden properties
47
48   Standard_Boolean myHasOwnColor;
49   Standard_Boolean myHasOwnWidth;
50
51 public:
52   DEFINE_STANDARD_RTTI(AIS_ColoredDrawer);
53
54 };
55
56 DEFINE_STANDARD_HANDLE(AIS_ColoredDrawer, AIS_Drawer)
57
58 //! Presentation of the shape with customizable sub-shapes properties.
59 class AIS_ColoredShape : public AIS_Shape
60 {
61 public:
62
63   //! Default constructor
64   Standard_EXPORT AIS_ColoredShape (const TopoDS_Shape& theShape);
65
66   //! Copy constructor
67   Standard_EXPORT AIS_ColoredShape (const Handle(AIS_Shape)& theShape);
68
69 public: //! @name sub-shape aspects
70
71   //! Customize properties of specified sub-shape.
72   //! The shape will be stored in the map but ignored, if it is not sub-shape of main Shape!
73   //! This method can be used to mark sub-shapes with customizable properties.
74   Standard_EXPORT Handle(AIS_ColoredDrawer) CustomAspects (const TopoDS_Shape& theShape);
75
76   //! Reset the map of custom sub-shape aspects.
77   Standard_EXPORT void ClearCustomAspects();
78
79   //! Reset custom properties of specified sub-shape.
80   //! @param theToUnregister unregister or not sub-shape from the map
81   Standard_EXPORT void UnsetCustomAspects (const TopoDS_Shape&    theShape,
82                                            const Standard_Boolean theToUnregister = Standard_False);
83
84   //! Customize color of specified sub-shape
85   Standard_EXPORT void SetCustomColor (const TopoDS_Shape&   theShape,
86                                        const Quantity_Color& theColor);
87
88   //! Customize line width of specified sub-shape
89   Standard_EXPORT void SetCustomWidth (const TopoDS_Shape& theShape,
90                                        const Standard_Real theLineWidth);
91
92 public: //! @name global aspects
93
94   //! Setup color of entire shape.
95   Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor);
96
97   //! Setup line width of entire shape.
98   Standard_EXPORT virtual void SetWidth (const Standard_Real theLineWidth);
99
100   //! Sets transparency value.
101   Standard_EXPORT virtual void SetTransparency (const Standard_Real theValue);
102
103 protected: //! @name override presentation computation
104
105   Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
106                                         const Handle(Prs3d_Presentation)&           thePrs,
107                                         const Standard_Integer                      theMode);
108
109 protected:
110
111   typedef NCollection_DataMap<TopoDS_Shape, Handle(AIS_ColoredDrawer), TopTools_ShapeMapHasher> DataMapOfShapeColor;
112   typedef NCollection_DataMap<TopoDS_Shape, TopoDS_Shape,              TopTools_ShapeMapHasher> DataMapOfShapeShape;
113   typedef NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Compound,    TopTools_ShapeMapHasher> DataMapOfShapeCompd;
114
115 protected:
116
117   //! Recursive function to map shapes.
118   //! @param theBaseKey                    the key to be used for undetailed shapes (default colors)
119   //! @param theSubshapeToParse            the subshape to be parsed
120   //! @param theSubshapeKeyshapeMap        shapes map Subshape (in the base shape) -> Keyshape (detailed shape)
121   //! @param theParentType                 the parent subshape type
122   //! @param theTypeKeyshapeDrawshapeArray the array of shape types to fill
123   Standard_EXPORT static Standard_Boolean dispatchColors (const TopoDS_Shape&        theBaseKey,
124                                                           const TopoDS_Shape&        theSubshapeToParse,
125                                                           const DataMapOfShapeShape& theSubshapeKeyshapeMap,
126                                                           const TopAbs_ShapeEnum     theParentType,
127                                                           DataMapOfShapeCompd*       theTypeKeyshapeDrawshapeArray);
128
129   Standard_EXPORT static void dispatchColors (const TopoDS_Shape&        theBaseShape,
130                                               const DataMapOfShapeColor& theKeyshapeColorMap,
131                                               DataMapOfShapeCompd*       theTypeKeyshapeDrawshapeArray);
132
133 protected:
134
135   DataMapOfShapeColor myShapeColors;
136
137 public:
138
139   DEFINE_STANDARD_RTTI(AIS_ColoredShape);
140
141 };
142
143 DEFINE_STANDARD_HANDLE(AIS_ColoredShape, AIS_Shape)
144
145 #endif // _AIS_ColoredShape_HeaderFile