1 // Created on: 2014-04-24
2 // Created by: Kirill Gavrilov
3 // Copyright (c) 2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _AIS_ColoredShape_HeaderFile
17 #define _AIS_ColoredShape_HeaderFile
19 #include <AIS_Drawer.hxx>
20 #include <AIS_Shape.hxx>
22 #include <NCollection_DataMap.hxx>
23 #include <NCollection_IndexedDataMap.hxx>
24 #include <TopTools_ShapeMapHasher.hxx>
25 #include <TopoDS_Compound.hxx>
27 //! Customizable properties.
28 class AIS_ColoredDrawer : public AIS_Drawer
32 AIS_ColoredDrawer (const Handle(AIS_Drawer)& theLink)
33 : myIsHidden (Standard_False),
34 myHasOwnColor (Standard_False),
35 myHasOwnWidth (Standard_False)
40 Standard_Boolean IsHidden() const { return myIsHidden; }
41 void SetHidden (const Standard_Boolean theToHide) { myIsHidden = theToHide; }
42 Standard_Boolean HasOwnColor() const { return myHasOwnColor; }
43 void UnsetOwnColor() { myHasOwnColor = Standard_False; }
44 void SetOwnColor (const Quantity_Color& /*theColor*/) { myHasOwnColor = Standard_True; }
45 Standard_Boolean HasOwnWidth() const { return myHasOwnWidth; }
46 void UnsetOwnWidth() { myHasOwnWidth = Standard_False; }
47 void SetOwnWidth (const Standard_Real /*theWidth*/) { myHasOwnWidth = Standard_True; }
49 public: //! @name list of overridden properties
51 Standard_Boolean myIsHidden;
52 Standard_Boolean myHasOwnColor;
53 Standard_Boolean myHasOwnWidth;
56 DEFINE_STANDARD_RTTI(AIS_ColoredDrawer);
60 DEFINE_STANDARD_HANDLE(AIS_ColoredDrawer, AIS_Drawer)
62 //! Presentation of the shape with customizable sub-shapes properties.
63 class AIS_ColoredShape : public AIS_Shape
67 //! Default constructor
68 Standard_EXPORT AIS_ColoredShape (const TopoDS_Shape& theShape);
71 Standard_EXPORT AIS_ColoredShape (const Handle(AIS_Shape)& theShape);
73 public: //! @name sub-shape aspects
75 //! Customize properties of specified sub-shape.
76 //! The shape will be stored in the map but ignored, if it is not sub-shape of main Shape!
77 //! This method can be used to mark sub-shapes with customizable properties.
78 Standard_EXPORT Handle(AIS_ColoredDrawer) CustomAspects (const TopoDS_Shape& theShape);
80 //! Reset the map of custom sub-shape aspects.
81 Standard_EXPORT void ClearCustomAspects();
83 //! Reset custom properties of specified sub-shape.
84 //! @param theToUnregister unregister or not sub-shape from the map
85 Standard_EXPORT void UnsetCustomAspects (const TopoDS_Shape& theShape,
86 const Standard_Boolean theToUnregister = Standard_False);
88 //! Customize color of specified sub-shape
89 Standard_EXPORT void SetCustomColor (const TopoDS_Shape& theShape,
90 const Quantity_Color& theColor);
92 //! Customize line width of specified sub-shape
93 Standard_EXPORT void SetCustomWidth (const TopoDS_Shape& theShape,
94 const Standard_Real theLineWidth);
96 public: //! @name global aspects
98 //! Setup color of entire shape.
99 Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
101 //! Setup line width of entire shape.
102 Standard_EXPORT virtual void SetWidth (const Standard_Real theLineWidth) Standard_OVERRIDE;
104 //! Sets transparency value.
105 Standard_EXPORT virtual void SetTransparency (const Standard_Real theValue) Standard_OVERRIDE;
107 //! Sets the material aspect.
108 Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& theAspect) Standard_OVERRIDE;
110 protected: //! @name override presentation computation
112 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
113 const Handle(Prs3d_Presentation)& thePrs,
114 const Standard_Integer theMode) Standard_OVERRIDE;
118 typedef NCollection_DataMap<TopoDS_Shape, Handle(AIS_ColoredDrawer), TopTools_ShapeMapHasher> DataMapOfShapeColor;
119 typedef NCollection_DataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher> DataMapOfShapeShape;
120 typedef NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Compound, TopTools_ShapeMapHasher> DataMapOfShapeCompd;
124 //! Recursive function to map shapes.
125 //! @param theBaseKey the key to be used for undetailed shapes (default colors)
126 //! @param theSubshapeToParse the subshape to be parsed
127 //! @param theSubshapeKeyshapeMap shapes map Subshape (in the base shape) -> Keyshape (detailed shape)
128 //! @param theParentType the parent subshape type
129 //! @param theTypeKeyshapeDrawshapeArray the array of shape types to fill
130 Standard_EXPORT static Standard_Boolean dispatchColors (const TopoDS_Shape& theBaseKey,
131 const TopoDS_Shape& theSubshapeToParse,
132 const DataMapOfShapeShape& theSubshapeKeyshapeMap,
133 const TopAbs_ShapeEnum theParentType,
134 DataMapOfShapeCompd* theTypeKeyshapeDrawshapeArray);
136 Standard_EXPORT static void dispatchColors (const TopoDS_Shape& theBaseShape,
137 const DataMapOfShapeColor& theKeyshapeColorMap,
138 DataMapOfShapeCompd* theTypeKeyshapeDrawshapeArray);
142 DataMapOfShapeColor myShapeColors;
146 DEFINE_STANDARD_RTTI(AIS_ColoredShape);
150 DEFINE_STANDARD_HANDLE(AIS_ColoredShape, AIS_Shape)
152 #endif // _AIS_ColoredShape_HeaderFile