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_DataMapOfShapeDrawer.hxx>
20 #include <AIS_Shape.hxx>
21 #include <NCollection_IndexedDataMap.hxx>
22 #include <StdPrs_Volume.hxx>
23 #include <TopoDS_Compound.hxx>
25 //! Presentation of the shape with customizable sub-shapes properties.
26 class AIS_ColoredShape : public AIS_Shape
30 //! Default constructor
31 Standard_EXPORT AIS_ColoredShape (const TopoDS_Shape& theShape);
34 Standard_EXPORT AIS_ColoredShape (const Handle(AIS_Shape)& theShape);
36 public: //! @name sub-shape aspects
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 virtual Handle(AIS_ColoredDrawer) CustomAspects (const TopoDS_Shape& theShape);
43 //! Reset the map of custom sub-shape aspects.
44 Standard_EXPORT virtual void ClearCustomAspects();
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);
51 //! Customize color of specified sub-shape
52 Standard_EXPORT void SetCustomColor (const TopoDS_Shape& theShape,
53 const Quantity_Color& theColor);
55 //! Customize line width of specified sub-shape
56 Standard_EXPORT void SetCustomWidth (const TopoDS_Shape& theShape,
57 const Standard_Real theLineWidth);
59 //! Return the map of custom aspects.
60 const AIS_DataMapOfShapeDrawer& CustomAspectsMap() const { return myShapeColors; }
62 //! Return the map of custom aspects.
63 AIS_DataMapOfShapeDrawer& ChangeCustomAspectsMap() { return myShapeColors; }
65 public: //! @name global aspects
67 //! Setup color of entire shape.
68 Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
70 //! Setup line width of entire shape.
71 Standard_EXPORT virtual void SetWidth (const Standard_Real theLineWidth) Standard_OVERRIDE;
73 //! Sets transparency value.
74 Standard_EXPORT virtual void SetTransparency (const Standard_Real theValue) Standard_OVERRIDE;
76 //! Sets the material aspect.
77 Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& theAspect) Standard_OVERRIDE;
79 protected: //! @name override presentation computation
81 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
82 const Handle(Prs3d_Presentation)& thePrs,
83 const Standard_Integer theMode) Standard_OVERRIDE;
87 typedef NCollection_DataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher> DataMapOfShapeShape;
88 typedef NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Compound, TopTools_ShapeMapHasher> DataMapOfShapeCompd;
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);
104 Standard_EXPORT static void dispatchColors (const TopoDS_Shape& theBaseShape,
105 const AIS_DataMapOfShapeDrawer& theKeyshapeColorMap,
106 DataMapOfShapeCompd* theTypeKeyshapeDrawshapeArray);
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);
121 //! Check all shapes from myShapeColorsfor visibility
122 Standard_EXPORT Standard_Boolean isShapeEntirelyVisible() const;
124 //! Check a shape with unique attributes for visibility of all 2d subshape
125 Standard_EXPORT Standard_Boolean isShapeEntirelyVisible (DataMapOfShapeCompd* theDispatched) const;
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);
141 AIS_DataMapOfShapeDrawer myShapeColors;
145 DEFINE_STANDARD_RTTIEXT(AIS_ColoredShape,AIS_Shape)
149 DEFINE_STANDARD_HANDLE(AIS_ColoredShape, AIS_Shape)
151 #endif // _AIS_ColoredShape_HeaderFile