0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / SelectMgr / SelectMgr_EntityOwner.cxx
1 // Created on: 1995-05-23
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <SelectMgr_EntityOwner.hxx>
18
19 #include <PrsMgr_PresentationManager.hxx>
20 #include <Standard_NoSuchObject.hxx>
21 #include <Standard_Type.hxx>
22 #include <TopLoc_Location.hxx>
23
24 IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_EntityOwner,SelectBasics_EntityOwner)
25
26 //==================================================
27 // Function: SelectMgr_EntityOwner
28 // Purpose :
29 //==================================================
30 SelectMgr_EntityOwner::SelectMgr_EntityOwner (const Standard_Integer thePriority)
31 : SelectBasics_EntityOwner (thePriority),
32   mySelectable (NULL),
33   myIsSelected (Standard_False),
34   myFromDecomposition (Standard_False)
35 {
36   //
37 }
38
39 //==================================================
40 // Function: SelectMgr_EntityOwner
41 // Purpose :
42 //==================================================
43 SelectMgr_EntityOwner::SelectMgr_EntityOwner (const Handle(SelectMgr_SelectableObject)& theSelObj,
44                                               const Standard_Integer thePriority)
45 : SelectBasics_EntityOwner (thePriority),
46   mySelectable (theSelObj.operator->()),
47   myIsSelected (Standard_False),
48   myFromDecomposition (Standard_False)
49 {
50   //
51 }
52
53 //==================================================
54 // Function: SelectMgr_EntityOwner
55 // Purpose :
56 //==================================================
57 SelectMgr_EntityOwner::SelectMgr_EntityOwner (const Handle(SelectMgr_EntityOwner)& theOwner,
58                                               const Standard_Integer thePriority)
59 : SelectBasics_EntityOwner (thePriority),
60   mySelectable (theOwner->mySelectable),
61   myIsSelected (Standard_False),
62   myFromDecomposition (Standard_False)
63 {
64   //
65 }
66
67 //=======================================================================
68 //function : SetSelectable
69 //purpose  :
70 //=======================================================================
71 void SelectMgr_EntityOwner::SetSelectable (const Handle(SelectMgr_SelectableObject)& theSelObj)
72 {
73   mySelectable = theSelObj.operator->();
74 }
75
76 //=======================================================================
77 //function : Selectable
78 //purpose  :
79 //=======================================================================
80 Handle(SelectMgr_SelectableObject) SelectMgr_EntityOwner::Selectable() const
81 {  
82   return mySelectable;
83 }
84
85 //=======================================================================
86 //function : IsHilighted
87 //purpose  :
88 //=======================================================================
89 Standard_Boolean SelectMgr_EntityOwner::IsHilighted (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
90                                                      const Standard_Integer theMode) const
91 {
92   return mySelectable != NULL
93       && thePrsMgr->IsHighlighted (mySelectable, theMode);
94 }
95
96 void SelectMgr_EntityOwner::HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
97                                               const Handle(Prs3d_Drawer)& theStyle,
98                                               const Standard_Integer theMode)
99 {
100   if (!HasSelectable())
101   {
102     return;
103   }
104
105   if (IsAutoHilight())
106   {
107     const Graphic3d_ZLayerId aHiLayer = theStyle->ZLayer() != Graphic3d_ZLayerId_UNKNOWN ? theStyle->ZLayer() : mySelectable->ZLayer();
108     thePM->Color (mySelectable, theStyle, theMode, NULL, aHiLayer);
109   }
110   else
111   {
112     mySelectable->HilightOwnerWithColor (thePM, theStyle, this);
113   }
114 }
115
116 void SelectMgr_EntityOwner::Unhilight (const Handle(PrsMgr_PresentationManager)& thePrsMgr, const Standard_Integer )
117 {
118   if (HasSelectable())
119   {
120     thePrsMgr->Unhighlight (mySelectable);
121   }
122 }
123
124 void SelectMgr_EntityOwner::Clear(const Handle(PrsMgr_PresentationManager)&,
125                                   const Standard_Integer)
126 {
127 // nothing done on the selectable here...
128 }
129
130 //=======================================================================
131 //function : about Transformation
132 //purpose  : 
133 //=======================================================================
134
135 Standard_Boolean SelectMgr_EntityOwner::HasLocation() const
136 {
137   return (HasSelectable() && mySelectable->HasTransformation());
138 }
139
140 void SelectMgr_EntityOwner::SetLocation(const TopLoc_Location&)
141 {
142 }
143
144 TopLoc_Location SelectMgr_EntityOwner::Location() const
145 {
146   return !HasLocation() ? TopLoc_Location() : TopLoc_Location(mySelectable->Transformation());
147 }
148
149 void SelectMgr_EntityOwner::ResetLocation()
150 {
151 }
152
153 Standard_Boolean SelectMgr_EntityOwner::IsAutoHilight () const
154 {
155   return mySelectable == NULL
156       || mySelectable->IsAutoHilight();
157 }
158
159 Standard_Boolean SelectMgr_EntityOwner::IsForcedHilight () const
160 {
161   return Standard_False;
162 }
163
164 //=======================================================================
165 //function : SetZLayer
166 //purpose  :
167 //=======================================================================
168 void SelectMgr_EntityOwner::SetZLayer (const Standard_Integer )
169 {
170   //
171 }
172
173 //=======================================================================
174 //function : UpdateHighlightTrsf
175 //purpose  :
176 //=======================================================================
177 void SelectMgr_EntityOwner::UpdateHighlightTrsf (const Handle(V3d_Viewer)& theViewer,
178                                                  const Handle(PrsMgr_PresentationManager3d)& theManager,
179                                                  const Standard_Integer theDispMode)
180 {
181   if (mySelectable == NULL)
182     return;
183
184   theManager->UpdateHighlightTrsf (theViewer, mySelectable, theDispMode);
185 }