0024965: Problem in local selection mode with selected objects staying in the viewer
[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
19#include <AIS_Drawer.hxx>
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>
26
27//! Customizable properties.
28class AIS_ColoredDrawer : public AIS_Drawer
29{
30public:
31
32 AIS_ColoredDrawer (const Handle(AIS_Drawer)& theLink)
33 : myHasOwnColor (Standard_False),
34 myHasOwnWidth (Standard_False)
35 {
36 Link (theLink);
37 }
38
39 Standard_Boolean HasOwnColor() const { return myHasOwnColor; }
40 void UnsetOwnColor() { myHasOwnColor = Standard_False; }
41 void SetOwnColor (const Quantity_Color& /*theColor*/) { myHasOwnColor = Standard_True; }
42 Standard_Boolean HasOwnWidth() const { return myHasOwnWidth; }
43 void UnsetOwnWidth() { myHasOwnWidth = Standard_False; }
44 void SetOwnWidth (const Standard_Real /*theWidth*/) { myHasOwnWidth = Standard_True; }
45
46public: //! @name list of overridden properties
47
48 Standard_Boolean myHasOwnColor;
49 Standard_Boolean myHasOwnWidth;
50
51public:
52 DEFINE_STANDARD_RTTI(AIS_ColoredDrawer);
53
54};
55
56DEFINE_STANDARD_HANDLE(AIS_ColoredDrawer, AIS_Drawer)
57
58//! Presentation of the shape with customizable sub-shapes properties.
59class AIS_ColoredShape : public AIS_Shape
60{
61public:
62
63 //! Default constructor
64 Standard_EXPORT AIS_ColoredShape (const TopoDS_Shape& theShape);
65
66 //! Copy constructor
67 Standard_EXPORT AIS_ColoredShape (const Handle(AIS_Shape)& theShape);
68
69public: //! @name sub-shape aspects
70
71 //! Customize properties of specified sub-shape.
72 //! The shape will be stored in the map but ignored, if it is not sub-shape of main Shape!
73 //! This method can be used to mark sub-shapes with customizable properties.
74 Standard_EXPORT Handle(AIS_ColoredDrawer) CustomAspects (const TopoDS_Shape& theShape);
75
76 //! Reset the map of custom sub-shape aspects.
77 Standard_EXPORT void ClearCustomAspects();
78
79 //! Reset custom properties of specified sub-shape.
80 //! @param theToUnregister unregister or not sub-shape from the map
81 Standard_EXPORT void UnsetCustomAspects (const TopoDS_Shape& theShape,
82 const Standard_Boolean theToUnregister = Standard_False);
83
84 //! Customize color of specified sub-shape
85 Standard_EXPORT void SetCustomColor (const TopoDS_Shape& theShape,
86 const Quantity_Color& theColor);
87
88 //! Customize line width of specified sub-shape
89 Standard_EXPORT void SetCustomWidth (const TopoDS_Shape& theShape,
90 const Standard_Real theLineWidth);
91
92public: //! @name global aspects
93
94 //! Setup color of entire shape.
a3157439 95 Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
ad3217cd 96
97 //! Setup line width of entire shape.
a3157439 98 Standard_EXPORT virtual void SetWidth (const Standard_Real theLineWidth) Standard_OVERRIDE;
ad3217cd 99
100 //! Sets transparency value.
a3157439 101 Standard_EXPORT virtual void SetTransparency (const Standard_Real theValue) Standard_OVERRIDE;
ad3217cd 102
103protected: //! @name override presentation computation
104
105 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
106 const Handle(Prs3d_Presentation)& thePrs,
a3157439 107 const Standard_Integer theMode) Standard_OVERRIDE;
ad3217cd 108
109protected:
110
111 typedef NCollection_DataMap<TopoDS_Shape, Handle(AIS_ColoredDrawer), TopTools_ShapeMapHasher> DataMapOfShapeColor;
112 typedef NCollection_DataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher> DataMapOfShapeShape;
113 typedef NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Compound, TopTools_ShapeMapHasher> DataMapOfShapeCompd;
114
115protected:
116
117 //! Recursive function to map shapes.
118 //! @param theBaseKey the key to be used for undetailed shapes (default colors)
119 //! @param theSubshapeToParse the subshape to be parsed
120 //! @param theSubshapeKeyshapeMap shapes map Subshape (in the base shape) -> Keyshape (detailed shape)
121 //! @param theParentType the parent subshape type
122 //! @param theTypeKeyshapeDrawshapeArray the array of shape types to fill
123 Standard_EXPORT static Standard_Boolean dispatchColors (const TopoDS_Shape& theBaseKey,
124 const TopoDS_Shape& theSubshapeToParse,
125 const DataMapOfShapeShape& theSubshapeKeyshapeMap,
126 const TopAbs_ShapeEnum theParentType,
127 DataMapOfShapeCompd* theTypeKeyshapeDrawshapeArray);
128
129 Standard_EXPORT static void dispatchColors (const TopoDS_Shape& theBaseShape,
130 const DataMapOfShapeColor& theKeyshapeColorMap,
131 DataMapOfShapeCompd* theTypeKeyshapeDrawshapeArray);
132
133protected:
134
135 DataMapOfShapeColor myShapeColors;
136
137public:
138
139 DEFINE_STANDARD_RTTI(AIS_ColoredShape);
140
141};
142
143DEFINE_STANDARD_HANDLE(AIS_ColoredShape, AIS_Shape)
144
145#endif // _AIS_ColoredShape_HeaderFile