0025773: Visualization - remove AIS_Drawer class and transfer its Link() logic to...
[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
6262338c 19#include <Prs3d_Drawer.hxx>
ad3217cd 20#include <AIS_Shape.hxx>
21
22#include <NCollection_DataMap.hxx>
23#include <NCollection_IndexedDataMap.hxx>
24#include <TopTools_ShapeMapHasher.hxx>
25#include <TopoDS_Compound.hxx>
5bffb882 26#include <StdPrs_Volume.hxx>
ad3217cd 27
28//! Customizable properties.
6262338c 29class AIS_ColoredDrawer : public Prs3d_Drawer
ad3217cd 30{
31public:
32
6262338c 33 AIS_ColoredDrawer (const Handle(Prs3d_Drawer)& theLink)
86766b0e 34 : myIsHidden (Standard_False),
35 myHasOwnColor (Standard_False),
ad3217cd 36 myHasOwnWidth (Standard_False)
37 {
38 Link (theLink);
39 }
40
86766b0e 41 Standard_Boolean IsHidden() const { return myIsHidden; }
42 void SetHidden (const Standard_Boolean theToHide) { myIsHidden = theToHide; }
ad3217cd 43 Standard_Boolean HasOwnColor() const { return myHasOwnColor; }
44 void UnsetOwnColor() { myHasOwnColor = Standard_False; }
45 void SetOwnColor (const Quantity_Color& /*theColor*/) { myHasOwnColor = Standard_True; }
46 Standard_Boolean HasOwnWidth() const { return myHasOwnWidth; }
47 void UnsetOwnWidth() { myHasOwnWidth = Standard_False; }
48 void SetOwnWidth (const Standard_Real /*theWidth*/) { myHasOwnWidth = Standard_True; }
49
50public: //! @name list of overridden properties
51
86766b0e 52 Standard_Boolean myIsHidden;
ad3217cd 53 Standard_Boolean myHasOwnColor;
54 Standard_Boolean myHasOwnWidth;
55
56public:
57 DEFINE_STANDARD_RTTI(AIS_ColoredDrawer);
58
59};
60
6262338c 61DEFINE_STANDARD_HANDLE(AIS_ColoredDrawer, Prs3d_Drawer)
ad3217cd 62
63//! Presentation of the shape with customizable sub-shapes properties.
64class AIS_ColoredShape : public AIS_Shape
65{
66public:
67
68 //! Default constructor
69 Standard_EXPORT AIS_ColoredShape (const TopoDS_Shape& theShape);
70
71 //! Copy constructor
72 Standard_EXPORT AIS_ColoredShape (const Handle(AIS_Shape)& theShape);
73
74public: //! @name sub-shape aspects
75
76 //! Customize properties of specified sub-shape.
77 //! The shape will be stored in the map but ignored, if it is not sub-shape of main Shape!
78 //! This method can be used to mark sub-shapes with customizable properties.
79 Standard_EXPORT Handle(AIS_ColoredDrawer) CustomAspects (const TopoDS_Shape& theShape);
80
81 //! Reset the map of custom sub-shape aspects.
82 Standard_EXPORT void ClearCustomAspects();
83
84 //! Reset custom properties of specified sub-shape.
85 //! @param theToUnregister unregister or not sub-shape from the map
86 Standard_EXPORT void UnsetCustomAspects (const TopoDS_Shape& theShape,
87 const Standard_Boolean theToUnregister = Standard_False);
88
89 //! Customize color of specified sub-shape
90 Standard_EXPORT void SetCustomColor (const TopoDS_Shape& theShape,
91 const Quantity_Color& theColor);
92
93 //! Customize line width of specified sub-shape
94 Standard_EXPORT void SetCustomWidth (const TopoDS_Shape& theShape,
95 const Standard_Real theLineWidth);
96
97public: //! @name global aspects
98
99 //! Setup color of entire shape.
a3157439 100 Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
ad3217cd 101
102 //! Setup line width of entire shape.
a3157439 103 Standard_EXPORT virtual void SetWidth (const Standard_Real theLineWidth) Standard_OVERRIDE;
ad3217cd 104
105 //! Sets transparency value.
a3157439 106 Standard_EXPORT virtual void SetTransparency (const Standard_Real theValue) Standard_OVERRIDE;
ad3217cd 107
e0608a8d 108 //! Sets the material aspect.
109 Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& theAspect) Standard_OVERRIDE;
110
ad3217cd 111protected: //! @name override presentation computation
112
113 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
114 const Handle(Prs3d_Presentation)& thePrs,
a3157439 115 const Standard_Integer theMode) Standard_OVERRIDE;
ad3217cd 116
117protected:
118
119 typedef NCollection_DataMap<TopoDS_Shape, Handle(AIS_ColoredDrawer), TopTools_ShapeMapHasher> DataMapOfShapeColor;
120 typedef NCollection_DataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher> DataMapOfShapeShape;
121 typedef NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Compound, TopTools_ShapeMapHasher> DataMapOfShapeCompd;
122
123protected:
124
125 //! Recursive function to map shapes.
126 //! @param theBaseKey the key to be used for undetailed shapes (default colors)
127 //! @param theSubshapeToParse the subshape to be parsed
128 //! @param theSubshapeKeyshapeMap shapes map Subshape (in the base shape) -> Keyshape (detailed shape)
129 //! @param theParentType the parent subshape type
130 //! @param theTypeKeyshapeDrawshapeArray the array of shape types to fill
131 Standard_EXPORT static Standard_Boolean dispatchColors (const TopoDS_Shape& theBaseKey,
132 const TopoDS_Shape& theSubshapeToParse,
133 const DataMapOfShapeShape& theSubshapeKeyshapeMap,
134 const TopAbs_ShapeEnum theParentType,
135 DataMapOfShapeCompd* theTypeKeyshapeDrawshapeArray);
136
137 Standard_EXPORT static void dispatchColors (const TopoDS_Shape& theBaseShape,
138 const DataMapOfShapeColor& theKeyshapeColorMap,
139 DataMapOfShapeCompd* theTypeKeyshapeDrawshapeArray);
140
141protected:
142
5bffb882 143 //! Add shape to presentation
144 //! @param thePrs the presentation
145 //! @param theDispatched the shapes map with unique attributes
146 //! @param theMode display mode
147 //! @param theVolume how to interpret theDispatched shapes - as Closed volumes, as Open volumes
148 //! or to perform Autodetection
149 Standard_EXPORT void addShapesWithCustomProps (const Handle(Prs3d_Presentation)& thePrs,
150 DataMapOfShapeCompd* theDispatched,
151 const Standard_Integer theMode,
152 const StdPrs_Volume theVolume);
153
154 //! Check all shapes from myShapeColorsfor visibility
155 Standard_EXPORT Standard_Boolean isShapeEntirelyVisible() const;
156
157 //! Check a shape with unique attributes for visibility of all 2d subshape
158 Standard_EXPORT Standard_Boolean isShapeEntirelyVisible (DataMapOfShapeCompd* theDispatched) const;
159
160 //! Resolve (parse) theKeyShape into subshapes, search in they for theBaseShape,
161 //! bind all resolved subshapes with theOriginKeyShape and store all binds in theSubshapeKeyshapeMap
162 //! @param theSubshapeKeyshapeMap shapes map: resolved and found theBaseShape subshape -> theOriginKeyShape
163 //! @param theBaseShape a shape to be sought
164 //! @param theBaseKey a shape to be resolved (parse) into smaller (in topological sense)
165 //! subshapes for new bind cycle
166 //! @param theOriginKeyShape the key to be used for undetailed shapes (default colors)
167 Standard_EXPORT static void bindSubShapes (DataMapOfShapeShape& theSubshapeKeyshapeMap,
168 const TopoDS_Shape& theBaseShape,
169 const TopoDS_Shape& theKeyShape,
170 const TopoDS_Shape& theOriginKeyShape);
171
172protected:
173
ad3217cd 174 DataMapOfShapeColor myShapeColors;
175
176public:
177
178 DEFINE_STANDARD_RTTI(AIS_ColoredShape);
179
180};
181
182DEFINE_STANDARD_HANDLE(AIS_ColoredShape, AIS_Shape)
183
184#endif // _AIS_ColoredShape_HeaderFile