1 // Created on: 2007-07-07
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <NIS_InteractiveObject.hxx>
17 #include <NIS_InteractiveContext.hxx>
18 #include <Standard_NullValue.hxx>
20 IMPLEMENT_STANDARD_HANDLE (NIS_InteractiveObject, Standard_Transient)
21 IMPLEMENT_STANDARD_RTTIEXT (NIS_InteractiveObject, Standard_Transient)
23 //=======================================================================
24 //function : ~NIS_InteractiveObject()
25 //purpose : Destructor
26 //=======================================================================
28 NIS_InteractiveObject::~NIS_InteractiveObject ( )
30 if (myID != 0 && myDrawer.IsNull() == Standard_False)
31 myDrawer->removeObject( this, Standard_False);
34 //=======================================================================
35 //function : SetDrawer
37 //=======================================================================
39 const Handle(NIS_Drawer)& NIS_InteractiveObject::SetDrawer
40 (const Handle(NIS_Drawer)& theDrawer,
41 const Standard_Boolean setUpdated)
43 NIS_InteractiveContext * aCtx = theDrawer->GetContext();
44 if (myDrawer.IsNull() == Standard_False) {
47 aCtx = myDrawer->GetContext();
48 theDrawer->myCtx = aCtx;
52 Standard_NullValue_Raise_if
53 (myDrawer->GetContext() != 0L && aCtx != myDrawer->GetContext(),
54 "NIS_InteractiveObject::SetDrawer: different drawer context");
58 Standard_NullValue_Raise_if
59 (aCtx == 0L, "NIS_InteractiveObject::SetDrawer: NULL drawer context");
60 // Add (if necessary) the new drawer to the Context
61 if (theDrawer->myIniId == 0)
62 theDrawer->myIniId = myID;
63 const Handle(NIS_Drawer)& aDrawer = aCtx->myDrawers.Added (theDrawer);
64 if (myDrawer != aDrawer)
66 // Move the Object from the old drawer to the new one.
67 if (myDrawer.IsNull() == Standard_False)
68 myDrawer->removeObject(this, Standard_True);
71 myDrawer->addObject(this, aCtx->myIsShareDrawList, Standard_True);
74 myDrawer->SetUpdated (NIS_Drawer::Draw_Normal,
76 NIS_Drawer::Draw_Transparent,
77 NIS_Drawer::Draw_Hilighted);
81 //=======================================================================
82 //function : SetTransparency
84 //=======================================================================
86 void NIS_InteractiveObject::SetTransparency (const Standard_Real theValue)
88 Standard_Integer aValue =
89 static_cast<Standard_Integer> (theValue * MaxTransparency);
90 if (aValue != static_cast<Standard_Integer>(myTransparency))
94 else if (aValue >= 1000)
95 myTransparency = 1000u;
97 myTransparency = static_cast<unsigned int> (aValue);
99 if (myDrawer.IsNull() == Standard_False && myID != 0) {
100 const Handle(NIS_Drawer) aDrawer = DefaultDrawer(0L);
101 aDrawer->Assign (GetDrawer());
102 aDrawer->myTransparency = Transparency();
103 SetDrawer (aDrawer, Standard_False);
105 NIS_InteractiveContext * aCtx = myDrawer->GetContext();
106 Standard_NullValue_Raise_if
107 (aCtx == 0L, "NIS_InteractiveObject::SetTransparency: "
108 "NULL drawer context");
109 if (IsTransparent()) {
110 if (myDrawType == NIS_Drawer::Draw_Normal) {
111 aCtx->myMapObjects[NIS_Drawer::Draw_Transparent].Add(myID);
112 aCtx->myMapObjects[NIS_Drawer::Draw_Normal].Remove(myID);
113 myDrawType = NIS_Drawer::Draw_Transparent;
115 myDrawer->SetUpdated (NIS_Drawer::Draw_Normal);
117 if (myDrawType == NIS_Drawer::Draw_Transparent) {
118 aCtx->myMapObjects[NIS_Drawer::Draw_Normal].Add(myID);
119 aCtx->myMapObjects[NIS_Drawer::Draw_Transparent].Remove(myID);
120 myDrawType = NIS_Drawer::Draw_Normal;
122 myDrawer->SetUpdated (NIS_Drawer::Draw_Transparent);
129 //=======================================================================
132 //=======================================================================
134 const Bnd_B3f& NIS_InteractiveObject::GetBox ()
138 myIsUpdateBox = Standard_False;
144 //=======================================================================
147 //=======================================================================
149 void NIS_InteractiveObject::Clone (const Handle(NCollection_BaseAllocator)&,
150 Handle(NIS_InteractiveObject)& theDest) const
152 if (theDest.IsNull() == Standard_False)
155 theDest->myDrawer = myDrawer;
156 theDest->myDrawType = myDrawType;
157 theDest->myBaseType = myBaseType;
158 theDest->myIsHidden = myIsHidden;
159 theDest->myIsDynHilighted = myIsDynHilighted;
160 theDest->myIsUpdateBox = myIsUpdateBox;
161 theDest->myTransparency = myTransparency;
162 if (myIsUpdateBox == Standard_False)
163 theDest->myBox = myBox;
164 theDest->myAttributePtr = myAttributePtr;
168 //=======================================================================
169 //function : CloneWithID
171 //=======================================================================
173 void NIS_InteractiveObject::CloneWithID
174 (const Handle(NCollection_BaseAllocator)& theAlloc,
175 Handle(NIS_InteractiveObject)& theDest)
177 Clone(theAlloc, theDest);
178 theDest->myID = myID;
182 //=======================================================================
183 //function : Intersect
185 //=======================================================================
187 Standard_Boolean NIS_InteractiveObject::Intersect (const Bnd_B3f&,
189 const Standard_Boolean) const
191 return Standard_True;
194 //=======================================================================
195 //function : Intersect
197 //=======================================================================
199 Standard_Boolean NIS_InteractiveObject::Intersect
200 (const NCollection_List<gp_XY>& ,
202 const Standard_Boolean ) const
204 return Standard_True;
207 //=======================================================================
208 //function : IsSelectable
209 //purpose : Query if the Object is selectable.
210 //=======================================================================
212 Standard_Boolean NIS_InteractiveObject::IsSelectable () const
214 Standard_Boolean aResult(Standard_False);
215 if (myDrawer.IsNull() == Standard_False)
216 aResult = myDrawer->GetContext()->IsSelectable (myID);
220 //=======================================================================
221 //function : SetSelectable
222 //purpose : Set or change the selectable state of the Object.
223 //=======================================================================
225 void NIS_InteractiveObject::SetSelectable (const Standard_Boolean isSel) const
227 if (myDrawer.IsNull() == Standard_False) {
228 NIS_InteractiveContext * aCtx = myDrawer->GetContext();
230 aCtx->myMapNonSelectableObjects.Remove (myID);
232 aCtx->myMapNonSelectableObjects.Add (myID);
233 if (myDrawType == NIS_Drawer::Draw_Hilighted)
235 aCtx->myMapObjects[NIS_Drawer::Draw_Hilighted].Remove(myID);
236 aCtx->deselectObj (this, myID);