0030452: Visualization - SelectMgr_ViewerSelector::Deactivate() raises exception...
[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
6985e642 27class StdSelect_BRepOwner;
28
ad3217cd 29//! Presentation of the shape with customizable sub-shapes properties.
30class AIS_ColoredShape : public AIS_Shape
31{
32public:
33
34 //! Default constructor
35 Standard_EXPORT AIS_ColoredShape (const TopoDS_Shape& theShape);
36
37 //! Copy constructor
38 Standard_EXPORT AIS_ColoredShape (const Handle(AIS_Shape)& theShape);
39
40public: //! @name sub-shape aspects
41
42 //! Customize properties of specified sub-shape.
43 //! The shape will be stored in the map but ignored, if it is not sub-shape of main Shape!
44 //! This method can be used to mark sub-shapes with customizable properties.
e5b8456d 45 Standard_EXPORT virtual Handle(AIS_ColoredDrawer) CustomAspects (const TopoDS_Shape& theShape);
ad3217cd 46
47 //! Reset the map of custom sub-shape aspects.
e5b8456d 48 Standard_EXPORT virtual void ClearCustomAspects();
ad3217cd 49
50 //! Reset custom properties of specified sub-shape.
51 //! @param theToUnregister unregister or not sub-shape from the map
52 Standard_EXPORT void UnsetCustomAspects (const TopoDS_Shape& theShape,
53 const Standard_Boolean theToUnregister = Standard_False);
54
55 //! Customize color of specified sub-shape
56 Standard_EXPORT void SetCustomColor (const TopoDS_Shape& theShape,
57 const Quantity_Color& theColor);
58
59 //! Customize line width of specified sub-shape
60 Standard_EXPORT void SetCustomWidth (const TopoDS_Shape& theShape,
61 const Standard_Real theLineWidth);
62
fb66bb28 63 //! Return the map of custom aspects.
64 const AIS_DataMapOfShapeDrawer& CustomAspectsMap() const { return myShapeColors; }
65
66 //! Return the map of custom aspects.
67 AIS_DataMapOfShapeDrawer& ChangeCustomAspectsMap() { return myShapeColors; }
68
ad3217cd 69public: //! @name global aspects
70
71 //! Setup color of entire shape.
a3157439 72 Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
ad3217cd 73
74 //! Setup line width of entire shape.
a3157439 75 Standard_EXPORT virtual void SetWidth (const Standard_Real theLineWidth) Standard_OVERRIDE;
ad3217cd 76
77 //! Sets transparency value.
a3157439 78 Standard_EXPORT virtual void SetTransparency (const Standard_Real theValue) Standard_OVERRIDE;
ad3217cd 79
f6d4c5cf 80 //! Removes the setting for transparency in the reconstructed compound shape.
81 Standard_EXPORT virtual void UnsetTransparency() Standard_OVERRIDE;
82
e0608a8d 83 //! Sets the material aspect.
84 Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& theAspect) Standard_OVERRIDE;
85
ad3217cd 86protected: //! @name override presentation computation
87
6985e642 88 //! Compute presentation considering sub-shape color map.
ad3217cd 89 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
90 const Handle(Prs3d_Presentation)& thePrs,
a3157439 91 const Standard_Integer theMode) Standard_OVERRIDE;
ad3217cd 92
6985e642 93 //! Compute selection considering sub-shape hidden state.
94 Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
95 const Standard_Integer theMode) Standard_OVERRIDE;
96
ad3217cd 97protected:
98
9c86076b 99 typedef NCollection_IndexedDataMap<Handle(AIS_ColoredDrawer), TopoDS_Compound, TColStd_MapTransientHasher> DataMapOfDrawerCompd;
ad3217cd 100
101protected:
102
103 //! Recursive function to map shapes.
9c86076b 104 //! @param theParentDrawer the drawer to be used for undetailed shapes (default colors)
105 //! @param theShapeToParse the subshape to be recursively parsed
106 //! @param theShapeDrawerMap shapes map Subshape (in the base shape) -> Drawer
107 //! @param theParentType the parent subshape type
108 //! @param theIsParentClosed flag indicating that specified shape is part of closed Solid
109 //! @param theDrawerOpenedShapePerType the array of shape types to fill
110 //! @param theDrawerClosedFaces the map for closed faces
111 Standard_EXPORT static Standard_Boolean dispatchColors (const Handle(AIS_ColoredDrawer)& theParentDrawer,
112 const TopoDS_Shape& theShapeToParse,
113 const AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
114 const TopAbs_ShapeEnum theParentType,
115 const Standard_Boolean theIsParentClosed,
116 DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
117 DataMapOfDrawerCompd& theDrawerClosedFaces);
ad3217cd 118protected:
119
6985e642 120 //! Extract myShapeColors map (KeyshapeColored -> Color) to subshapes map (Subshape -> Color).
121 //! This needed when colored shape is not part of BaseShape (but subshapes are) and actually container for subshapes.
122 Standard_EXPORT void fillSubshapeDrawerMap (AIS_DataMapOfShapeDrawer& theSubshapeDrawerMap) const;
123
5bffb882 124 //! Add shape to presentation
9c86076b 125 //! @param thePrs the presentation
126 //! @param theDrawerOpenedShapePerType the shapes map with unique attributes
127 //! @param theDrawerClosedFaces the map of attributes for closed faces
128 //! @param theMode display mode
5bffb882 129 Standard_EXPORT void addShapesWithCustomProps (const Handle(Prs3d_Presentation)& thePrs,
9c86076b 130 const DataMapOfDrawerCompd* theDrawerOpenedShapePerType,
131 const DataMapOfDrawerCompd& theDrawerClosedFaces,
132 const Standard_Integer theMode);
5bffb882 133
134 //! Check all shapes from myShapeColorsfor visibility
135 Standard_EXPORT Standard_Boolean isShapeEntirelyVisible() const;
136
5bffb882 137 //! Resolve (parse) theKeyShape into subshapes, search in they for theBaseShape,
9c86076b 138 //! bind all resolved subshapes with theOriginKeyShape and store all binds in theShapeDrawerMap
139 //! @param theShapeDrawerMap shapes map: resolved and found theBaseShape subshape -> theOriginKeyShape
140 //! @param theKeyShape a shape to be resolved (parse) into smaller (in topological sense)
141 //! subshapes for new bind cycle
142 //! @param theDrawer assigned drawer
143 Standard_EXPORT void bindSubShapes (AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
144 const TopoDS_Shape& theKeyShape,
6985e642 145 const Handle(AIS_ColoredDrawer)& theDrawer) const;
146
147 //! Add sub-shape to selection considering hidden state (recursively).
148 //! @param theParentDrawer drawer of parent shape
149 //! @param theShapeDrawerMap shapes map
150 //! @param theShape shape to compute sensitive entities
151 //! @param theOwner selectable owner object
152 //! @param theSelection selection to append new sensitive entities
153 //! @param theTypOfSel type of selection
154 //! @param theDeflection linear deflection
155 //! @param theDeflAngle angular deflection
156 Standard_EXPORT void computeSubshapeSelection (const Handle(AIS_ColoredDrawer)& theParentDrawer,
157 const AIS_DataMapOfShapeDrawer& theShapeDrawerMap,
158 const TopoDS_Shape& theShape,
159 const Handle(StdSelect_BRepOwner)& theOwner,
160 const Handle(SelectMgr_Selection)& theSelection,
161 const TopAbs_ShapeEnum theTypOfSel,
162 const Standard_Integer thePriority,
163 const Standard_Real theDeflection,
164 const Standard_Real theDeflAngle);
5bffb882 165
166protected:
167
fb66bb28 168 AIS_DataMapOfShapeDrawer myShapeColors;
ad3217cd 169
170public:
171
a3f6f591 172 DEFINE_STANDARD_RTTIEXT(AIS_ColoredShape,AIS_Shape)
ad3217cd 173
174};
175
176DEFINE_STANDARD_HANDLE(AIS_ColoredShape, AIS_Shape)
177
178#endif // _AIS_ColoredShape_HeaderFile