0024171: Eliminate CLang compiler warning -Wreorder
[occt.git] / src / NIS / NIS_InteractiveObject.cxx
CommitLineData
b311480e 1// Created on: 2007-07-07
2// Created by: Alexander GRIGORIEV
3// Copyright (c) 2007-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
21
22#include <NIS_InteractiveObject.hxx>
23#include <NIS_InteractiveContext.hxx>
24#include <Standard_NullValue.hxx>
25
26IMPLEMENT_STANDARD_HANDLE (NIS_InteractiveObject, Standard_Transient)
27IMPLEMENT_STANDARD_RTTIEXT (NIS_InteractiveObject, Standard_Transient)
28
29//=======================================================================
30//function : ~NIS_InteractiveObject()
31//purpose : Destructor
32//=======================================================================
33
34NIS_InteractiveObject::~NIS_InteractiveObject ( )
35{
36 if (myID != 0 && myDrawer.IsNull() == Standard_False)
37 myDrawer->removeObject( this, Standard_False);
38}
39
40//=======================================================================
41//function : SetDrawer
42//purpose :
43//=======================================================================
44
45const Handle_NIS_Drawer& NIS_InteractiveObject::SetDrawer
ffe2bea7
A
46 (const Handle(NIS_Drawer)& theDrawer,
47 const Standard_Boolean setUpdated)
7fd59977 48{
49 NIS_InteractiveContext * aCtx = theDrawer->GetContext();
eafb234b 50 if (myDrawer.IsNull() == Standard_False) {
7fd59977 51 if (aCtx == 0L)
52 {
53 aCtx = myDrawer->GetContext();
54 theDrawer->myCtx = aCtx;
55 }
56 else
57 {
58 Standard_NullValue_Raise_if
59 (myDrawer->GetContext() != 0L && aCtx != myDrawer->GetContext(),
60 "NIS_InteractiveObject::SetDrawer: different drawer context");
61 }
eafb234b 62 }
7fd59977 63
64 Standard_NullValue_Raise_if
65 (aCtx == 0L, "NIS_InteractiveObject::SetDrawer: NULL drawer context");
66 // Add (if necessary) the new drawer to the Context
ffe2bea7
A
67 if (theDrawer->myIniId == 0)
68 theDrawer->myIniId = myID;
7fd59977 69 const Handle(NIS_Drawer)& aDrawer = aCtx->myDrawers.Added (theDrawer);
70 if (myDrawer != aDrawer)
71 {
72 // Move the Object from the old drawer to the new one.
73 if (myDrawer.IsNull() == Standard_False)
74 myDrawer->removeObject(this, Standard_True);
75 myDrawer = aDrawer;
76
ffe2bea7 77 myDrawer->addObject(this, aCtx->myIsShareDrawList, Standard_True);
7fd59977 78 }
ffe2bea7
A
79 if (setUpdated)
80 myDrawer->SetUpdated (NIS_Drawer::Draw_Normal,
81 NIS_Drawer::Draw_Top,
82 NIS_Drawer::Draw_Transparent,
83 NIS_Drawer::Draw_Hilighted);
7fd59977 84 return aDrawer;
85}
86
87//=======================================================================
88//function : SetTransparency
89//purpose :
90//=======================================================================
91
92void NIS_InteractiveObject::SetTransparency (const Standard_Real theValue)
93{
ffe2bea7
A
94 Standard_Integer aValue =
95 static_cast<Standard_Integer> (theValue * MaxTransparency);
96 if (aValue != static_cast<Standard_Integer>(myTransparency))
97 {
98 if (aValue <= 0)
99 myTransparency = 0;
100 else if (aValue >= 1000)
101 myTransparency = 1000u;
7fd59977 102 else
ffe2bea7 103 myTransparency = static_cast<unsigned int> (aValue);
7fd59977 104
105 if (myDrawer.IsNull() == Standard_False && myID != 0) {
ffe2bea7
A
106 const Handle(NIS_Drawer) aDrawer = DefaultDrawer(0L);
107 aDrawer->Assign (GetDrawer());
108 aDrawer->myTransparency = Transparency();
109 SetDrawer (aDrawer, Standard_False);
110
7fd59977 111 NIS_InteractiveContext * aCtx = myDrawer->GetContext();
112 Standard_NullValue_Raise_if
113 (aCtx == 0L, "NIS_InteractiveObject::SetTransparency: "
114 "NULL drawer context");
115 if (IsTransparent()) {
116 if (myDrawType == NIS_Drawer::Draw_Normal) {
117 aCtx->myMapObjects[NIS_Drawer::Draw_Transparent].Add(myID);
118 aCtx->myMapObjects[NIS_Drawer::Draw_Normal].Remove(myID);
119 myDrawType = NIS_Drawer::Draw_Transparent;
120 }
121 myDrawer->SetUpdated (NIS_Drawer::Draw_Normal);
122 } else {
123 if (myDrawType == NIS_Drawer::Draw_Transparent) {
124 aCtx->myMapObjects[NIS_Drawer::Draw_Normal].Add(myID);
125 aCtx->myMapObjects[NIS_Drawer::Draw_Transparent].Remove(myID);
126 myDrawType = NIS_Drawer::Draw_Normal;
127 }
128 myDrawer->SetUpdated (NIS_Drawer::Draw_Transparent);
129 }
130 setDrawerUpdate();
131 }
132 }
133}
134
135//=======================================================================
136//function : GetBox
137//purpose :
138//=======================================================================
139
140const Bnd_B3f& NIS_InteractiveObject::GetBox ()
141{
142 if (myIsUpdateBox)
143 {
144 myIsUpdateBox = Standard_False;
145 computeBox();
146 }
147 return myBox;
148}
149
ffe2bea7
A
150//=======================================================================
151//function : Clone
152//purpose :
153//=======================================================================
154
155void NIS_InteractiveObject::Clone (const Handle_NCollection_BaseAllocator&,
156 Handle_NIS_InteractiveObject& theDest) const
157{
158 if (theDest.IsNull() == Standard_False)
159 {
160 theDest->myID = 0;
161 theDest->myDrawer = myDrawer;
162 theDest->myDrawType = myDrawType;
163 theDest->myBaseType = myBaseType;
164 theDest->myIsHidden = myIsHidden;
165 theDest->myIsDynHilighted = myIsDynHilighted;
166 theDest->myIsUpdateBox = myIsUpdateBox;
167 theDest->myTransparency = myTransparency;
168 if (myIsUpdateBox == Standard_False)
169 theDest->myBox = myBox;
170 theDest->myAttributePtr = myAttributePtr;
171 }
172}
173
174//=======================================================================
175//function : CloneWithID
176//purpose :
177//=======================================================================
178
179void NIS_InteractiveObject::CloneWithID
180 (const Handle_NCollection_BaseAllocator& theAlloc,
181 Handle_NIS_InteractiveObject& theDest)
182{
183 Clone(theAlloc, theDest);
184 theDest->myID = myID;
185 myDrawer.Nullify();
186}
187
7fd59977 188//=======================================================================
189//function : Intersect
190//purpose :
191//=======================================================================
192
193Standard_Boolean NIS_InteractiveObject::Intersect (const Bnd_B3f&,
194 const gp_Trsf&,
195 const Standard_Boolean) const
196{
197 return Standard_True;
198}
199
ffe2bea7
A
200//=======================================================================
201//function : Intersect
202//purpose :
203//=======================================================================
204
205Standard_Boolean NIS_InteractiveObject::Intersect
35e08fe8 206 (const NCollection_List<gp_XY>& ,
207 const gp_Trsf& ,
208 const Standard_Boolean ) const
ffe2bea7
A
209{
210 return Standard_True;
211}
212
7fd59977 213//=======================================================================
214//function : IsSelectable
215//purpose : Query if the Object is selectable.
216//=======================================================================
217
218Standard_Boolean NIS_InteractiveObject::IsSelectable () const
219{
220 Standard_Boolean aResult(Standard_False);
221 if (myDrawer.IsNull() == Standard_False)
222 aResult = myDrawer->GetContext()->IsSelectable (myID);
223 return aResult;
224}
225
226//=======================================================================
227//function : SetSelectable
228//purpose : Set or change the selectable state of the Object.
229//=======================================================================
230
231void NIS_InteractiveObject::SetSelectable (const Standard_Boolean isSel) const
232{
233 if (myDrawer.IsNull() == Standard_False) {
234 NIS_InteractiveContext * aCtx = myDrawer->GetContext();
235 if (isSel)
236 aCtx->myMapNonSelectableObjects.Remove (myID);
237 else {
238 aCtx->myMapNonSelectableObjects.Add (myID);
ffe2bea7 239 if (myDrawType == NIS_Drawer::Draw_Hilighted)
7fd59977 240 {
ffe2bea7
A
241 aCtx->myMapObjects[NIS_Drawer::Draw_Hilighted].Remove(myID);
242 aCtx->deselectObj (this, myID);
7fd59977 243 }
244 }
245 }
246}