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