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