0028036: Visualization, AIS_ColoredShape - handle correctly nested compounds within...
[occt.git] / src / AIS / AIS_ColoredShape.hxx
CommitLineData
ad3217cd 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
fb66bb28 19#include <AIS_DataMapOfShapeDrawer.hxx>
ad3217cd 20#include <AIS_Shape.hxx>
ad3217cd 21#include <NCollection_IndexedDataMap.hxx>
5bffb882 22#include <StdPrs_Volume.hxx>
fb66bb28 23#include <TopoDS_Compound.hxx>
9c86076b 24#include <TopTools_MapOfShape.hxx>
25#include <TColStd_MapTransientHasher.hxx>
ad3217cd 26
27//! Presentation of the shape with customizable sub-shapes properties.
28class AIS_ColoredShape : public AIS_Shape
29{
30public:
31
32 //! Default constructor
33 Standard_EXPORT AIS_ColoredShape (const TopoDS_Shape& theShape);
34
35 //! Copy constructor
36 Standard_EXPORT AIS_ColoredShape (const Handle(AIS_Shape)& theShape);
37
38public: //! @name sub-shape aspects
39
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.
e5b8456d 43 Standard_EXPORT virtual Handle(AIS_ColoredDrawer) CustomAspects (const TopoDS_Shape& theShape);
ad3217cd 44
45 //! Reset the map of custom sub-shape aspects.
e5b8456d 46 Standard_EXPORT virtual void ClearCustomAspects();
ad3217cd 47
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);
52
53 //! Customize color of specified sub-shape
54 Standard_EXPORT void SetCustomColor (const TopoDS_Shape& theShape,
55 const Quantity_Color& theColor);
56
57 //! Customize line width of specified sub-shape
58 Standard_EXPORT void SetCustomWidth (const TopoDS_Shape& theShape,
59 const Standard_Real theLineWidth);
60
fb66bb28 61 //! Return the map of custom aspects.
62 const AIS_DataMapOfShapeDrawer& CustomAspectsMap() const { return myShapeColors; }
63
64 //! Return the map of custom aspects.
65 AIS_DataMapOfShapeDrawer& ChangeCustomAspectsMap() { return myShapeColors; }
66
ad3217cd 67public: //! @name global aspects
68
69 //! Setup color of entire shape.
a3157439 70 Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
ad3217cd 71
72 //! Setup line width of entire shape.
a3157439 73 Standard_EXPORT virtual void SetWidth (const Standard_Real theLineWidth) Standard_OVERRIDE;
ad3217cd 74
75 //! Sets transparency value.
a3157439 76 Standard_EXPORT virtual void SetTransparency (const Standard_Real theValue) Standard_OVERRIDE;
ad3217cd 77
e0608a8d 78 //! Sets the material aspect.
79 Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& theAspect) Standard_OVERRIDE;
80
ad3217cd 81protected: //! @name override presentation computation
82
83 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
84 const Handle(Prs3d_Presentation)& thePrs,
a3157439 85 const Standard_Integer theMode) Standard_OVERRIDE;
ad3217cd 86
87protected:
88
9c86076b 89 typedef NCollection_IndexedDataMap<Handle(AIS_ColoredDrawer), TopoDS_Compound, TColStd_MapTransientHasher> DataMapOfDrawerCompd;
ad3217cd 90
91protected:
92
93 //! Recursive function to map shapes.
9c86076b 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);
ad3217cd 108protected:
109
5bffb882 110 //! Add shape to presentation
9c86076b 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
5bffb882 115 Standard_EXPORT void addShapesWithCustomProps (const Handle(Prs3d_Presentation)& thePrs,
9c86076b 116 const DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
117 const DataMapOfDrawerCompd& theDrawerClosedFaces,
118 const Standard_Integer theMode);
5bffb882 119
120 //! Check all shapes from myShapeColorsfor visibility
121 Standard_EXPORT Standard_Boolean isShapeEntirelyVisible() const;
122
5bffb882 123 //! Resolve (parse) theKeyShape into subshapes, search in they for theBaseShape,
9c86076b 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);
5bffb882 132
133protected:
134
fb66bb28 135 AIS_DataMapOfShapeDrawer myShapeColors;
ad3217cd 136
137public:
138
a3f6f591 139 DEFINE_STANDARD_RTTIEXT(AIS_ColoredShape,AIS_Shape)
ad3217cd 140
141};
142
143DEFINE_STANDARD_HANDLE(AIS_ColoredShape, AIS_Shape)
144
145#endif // _AIS_ColoredShape_HeaderFile