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