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>
24 #include <TopTools_MapOfShape.hxx>
25 #include <TColStd_MapTransientHasher.hxx>
27 //! Presentation of the shape with customizable sub-shapes properties.
28 class AIS_ColoredShape : public AIS_Shape
32 //! Default constructor
33 Standard_EXPORT AIS_ColoredShape (const TopoDS_Shape& theShape);
36 Standard_EXPORT AIS_ColoredShape (const Handle(AIS_Shape)& theShape);
38 public: //! @name sub-shape aspects
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);
45 //! Reset the map of custom sub-shape aspects.
46 Standard_EXPORT virtual void ClearCustomAspects();
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);
53 //! Customize color of specified sub-shape
54 Standard_EXPORT void SetCustomColor (const TopoDS_Shape& theShape,
55 const Quantity_Color& theColor);
57 //! Customize line width of specified sub-shape
58 Standard_EXPORT void SetCustomWidth (const TopoDS_Shape& theShape,
59 const Standard_Real theLineWidth);
61 //! Return the map of custom aspects.
62 const AIS_DataMapOfShapeDrawer& CustomAspectsMap() const { return myShapeColors; }
64 //! Return the map of custom aspects.
65 AIS_DataMapOfShapeDrawer& ChangeCustomAspectsMap() { return myShapeColors; }
67 public: //! @name global aspects
69 //! Setup color of entire shape.
70 Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
72 //! Setup line width of entire shape.
73 Standard_EXPORT virtual void SetWidth (const Standard_Real theLineWidth) Standard_OVERRIDE;
75 //! Sets transparency value.
76 Standard_EXPORT virtual void SetTransparency (const Standard_Real theValue) Standard_OVERRIDE;
78 //! Sets the material aspect.
79 Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& theAspect) Standard_OVERRIDE;
81 protected: //! @name override presentation computation
83 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
84 const Handle(Prs3d_Presentation)& thePrs,
85 const Standard_Integer theMode) Standard_OVERRIDE;
89 typedef NCollection_IndexedDataMap<Handle(AIS_ColoredDrawer), TopoDS_Compound, TColStd_MapTransientHasher> DataMapOfDrawerCompd;
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);
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);
120 //! Check all shapes from myShapeColorsfor visibility
121 Standard_EXPORT Standard_Boolean isShapeEntirelyVisible() const;
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);
135 AIS_DataMapOfShapeDrawer myShapeColors;
139 DEFINE_STANDARD_RTTIEXT(AIS_ColoredShape,AIS_Shape)
143 DEFINE_STANDARD_HANDLE(AIS_ColoredShape, AIS_Shape)
145 #endif // _AIS_ColoredShape_HeaderFile