1 // Created on: 2007-07-07
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2007-2012 OPEN CASCADE SAS
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.
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.
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.
22 #include <NIS_InteractiveObject.hxx>
23 #include <NIS_InteractiveContext.hxx>
24 #include <Standard_NullValue.hxx>
26 IMPLEMENT_STANDARD_HANDLE (NIS_InteractiveObject, Standard_Transient)
27 IMPLEMENT_STANDARD_RTTIEXT (NIS_InteractiveObject, Standard_Transient)
29 //=======================================================================
30 //function : ~NIS_InteractiveObject()
31 //purpose : Destructor
32 //=======================================================================
34 NIS_InteractiveObject::~NIS_InteractiveObject ( )
36 if (myID != 0 && myDrawer.IsNull() == Standard_False)
37 myDrawer->removeObject( this, Standard_False);
40 //=======================================================================
41 //function : SetDrawer
43 //=======================================================================
45 const Handle_NIS_Drawer& NIS_InteractiveObject::SetDrawer
46 (const Handle(NIS_Drawer)& theDrawer,
47 const Standard_Boolean setUpdated)
49 NIS_InteractiveContext * aCtx = theDrawer->GetContext();
50 if (myDrawer.IsNull() == Standard_False)
53 aCtx = myDrawer->GetContext();
54 theDrawer->myCtx = aCtx;
58 Standard_NullValue_Raise_if
59 (myDrawer->GetContext() != 0L && aCtx != myDrawer->GetContext(),
60 "NIS_InteractiveObject::SetDrawer: different drawer context");
63 Standard_NullValue_Raise_if
64 (aCtx == 0L, "NIS_InteractiveObject::SetDrawer: NULL drawer context");
65 // Add (if necessary) the new drawer to the Context
66 if (theDrawer->myIniId == 0)
67 theDrawer->myIniId = myID;
68 const Handle(NIS_Drawer)& aDrawer = aCtx->myDrawers.Added (theDrawer);
69 if (myDrawer != aDrawer)
71 // Move the Object from the old drawer to the new one.
72 if (myDrawer.IsNull() == Standard_False)
73 myDrawer->removeObject(this, Standard_True);
76 myDrawer->addObject(this, aCtx->myIsShareDrawList, Standard_True);
79 myDrawer->SetUpdated (NIS_Drawer::Draw_Normal,
81 NIS_Drawer::Draw_Transparent,
82 NIS_Drawer::Draw_Hilighted);
86 //=======================================================================
87 //function : SetTransparency
89 //=======================================================================
91 void NIS_InteractiveObject::SetTransparency (const Standard_Real theValue)
93 Standard_Integer aValue =
94 static_cast<Standard_Integer> (theValue * MaxTransparency);
95 if (aValue != static_cast<Standard_Integer>(myTransparency))
99 else if (aValue >= 1000)
100 myTransparency = 1000u;
102 myTransparency = static_cast<unsigned int> (aValue);
104 if (myDrawer.IsNull() == Standard_False && myID != 0) {
105 const Handle(NIS_Drawer) aDrawer = DefaultDrawer(0L);
106 aDrawer->Assign (GetDrawer());
107 aDrawer->myTransparency = Transparency();
108 SetDrawer (aDrawer, Standard_False);
110 NIS_InteractiveContext * aCtx = myDrawer->GetContext();
111 Standard_NullValue_Raise_if
112 (aCtx == 0L, "NIS_InteractiveObject::SetTransparency: "
113 "NULL drawer context");
114 if (IsTransparent()) {
115 if (myDrawType == NIS_Drawer::Draw_Normal) {
116 aCtx->myMapObjects[NIS_Drawer::Draw_Transparent].Add(myID);
117 aCtx->myMapObjects[NIS_Drawer::Draw_Normal].Remove(myID);
118 myDrawType = NIS_Drawer::Draw_Transparent;
120 myDrawer->SetUpdated (NIS_Drawer::Draw_Normal);
122 if (myDrawType == NIS_Drawer::Draw_Transparent) {
123 aCtx->myMapObjects[NIS_Drawer::Draw_Normal].Add(myID);
124 aCtx->myMapObjects[NIS_Drawer::Draw_Transparent].Remove(myID);
125 myDrawType = NIS_Drawer::Draw_Normal;
127 myDrawer->SetUpdated (NIS_Drawer::Draw_Transparent);
134 //=======================================================================
137 //=======================================================================
139 const Bnd_B3f& NIS_InteractiveObject::GetBox ()
143 myIsUpdateBox = Standard_False;
149 //=======================================================================
152 //=======================================================================
154 void NIS_InteractiveObject::Clone (const Handle_NCollection_BaseAllocator&,
155 Handle_NIS_InteractiveObject& theDest) const
157 if (theDest.IsNull() == Standard_False)
160 theDest->myDrawer = myDrawer;
161 theDest->myDrawType = myDrawType;
162 theDest->myBaseType = myBaseType;
163 theDest->myIsHidden = myIsHidden;
164 theDest->myIsDynHilighted = myIsDynHilighted;
165 theDest->myIsUpdateBox = myIsUpdateBox;
166 theDest->myTransparency = myTransparency;
167 if (myIsUpdateBox == Standard_False)
168 theDest->myBox = myBox;
169 theDest->myAttributePtr = myAttributePtr;
173 //=======================================================================
174 //function : CloneWithID
176 //=======================================================================
178 void NIS_InteractiveObject::CloneWithID
179 (const Handle_NCollection_BaseAllocator& theAlloc,
180 Handle_NIS_InteractiveObject& theDest)
182 Clone(theAlloc, theDest);
183 theDest->myID = myID;
187 //=======================================================================
188 //function : Intersect
190 //=======================================================================
192 Standard_Boolean NIS_InteractiveObject::Intersect (const Bnd_B3f&,
194 const Standard_Boolean) const
196 return Standard_True;
199 //=======================================================================
200 //function : Intersect
202 //=======================================================================
204 Standard_Boolean NIS_InteractiveObject::Intersect
205 (const NCollection_List<gp_XY> &thePolygon,
206 const gp_Trsf &theTrf,
207 const Standard_Boolean isFull) const
209 return Standard_True;
212 //=======================================================================
213 //function : IsSelectable
214 //purpose : Query if the Object is selectable.
215 //=======================================================================
217 Standard_Boolean NIS_InteractiveObject::IsSelectable () const
219 Standard_Boolean aResult(Standard_False);
220 if (myDrawer.IsNull() == Standard_False)
221 aResult = myDrawer->GetContext()->IsSelectable (myID);
225 //=======================================================================
226 //function : SetSelectable
227 //purpose : Set or change the selectable state of the Object.
228 //=======================================================================
230 void NIS_InteractiveObject::SetSelectable (const Standard_Boolean isSel) const
232 if (myDrawer.IsNull() == Standard_False) {
233 NIS_InteractiveContext * aCtx = myDrawer->GetContext();
235 aCtx->myMapNonSelectableObjects.Remove (myID);
237 aCtx->myMapNonSelectableObjects.Add (myID);
238 if (myDrawType == NIS_Drawer::Draw_Hilighted)
240 aCtx->myMapObjects[NIS_Drawer::Draw_Hilighted].Remove(myID);
241 aCtx->deselectObj (this, myID);