0024023: Revamp the OCCT Handle -- ambiguity
[occt.git] / src / AIS / AIS_InteractiveContext.cxx
CommitLineData
b311480e 1// Created on: 1997-01-17
2// Created by: Robert COUBLANC
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
7fd59977 17// Modified by XAB & Serguei Dec 97 (angle &deviation coeffts)
7fd59977 18
7fd59977 19#include <AIS_InteractiveContext.ixx>
20
21//#include <AIS_DataMapIteratorOfDataMapOfInteractiveInteger.hxx>
22#include <TColStd_ListIteratorOfListOfInteger.hxx>
23#include <TColStd_MapIteratorOfMapOfTransient.hxx>
24#include <AIS_LocalContext.hxx>
25#include <AIS_LocalStatus.hxx>
26#include <Precision.hxx>
27#include <AIS_Selection.hxx>
28#include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
0717ddc1 29#include <AIS_ConnectedInteractive.hxx>
30#include <AIS_MultipleConnectedInteractive.hxx>
7fd59977 31#include <AIS_DataMapIteratorOfDataMapOfILC.hxx>
32#include <AIS_GlobalStatus.hxx>
33#include <AIS_MapIteratorOfMapOfInteractive.hxx>
34#include <PrsMgr_ModedPresentation.hxx>
35#include <Visual3d_ViewManager.hxx>
a1954302 36#include <Visual3d_View.hxx>
7fd59977 37#include <Prs3d_ShadingAspect.hxx>
38#include <AIS_Shape.hxx>
39#include <Graphic3d_AspectFillArea3d.hxx>
40#include <HLRBRep.hxx>
41#include <Prs3d_IsoAspect.hxx>
42#include <Prs3d_DatumAspect.hxx>
43#include <Prs3d_PlaneAspect.hxx>
44#include <PrsMgr_PresentableObject.hxx>
e33e7e78 45#include <Standard_Atomic.hxx>
f751596e 46#include <StdSelect_ViewerSelector3d.hxx>
7fd59977 47#include <UnitsAPI.hxx>
48
49#include <AIS_Trihedron.hxx>
50#include <Geom_Axis2Placement.hxx>
51#include <OSD_Environment.hxx>
52
53#include <AIS_ListIteratorOfListOfInteractive.hxx>
ec357c5c 54#include <AIS_InteractiveObject.hxx>
55#include <SelectMgr_EntityOwner.hxx>
7fd59977 56
e33e7e78 57namespace
7fd59977 58{
e33e7e78
RK
59 static volatile Standard_Integer THE_AIS_INDEX_SEL = 0;
60 static volatile Standard_Integer THE_AIS_INDEX_CUR = 0;
7fd59977 61
e33e7e78
RK
62 static TCollection_AsciiString AIS_Context_NewSelName()
63 {
64 return TCollection_AsciiString ("AIS_SelContext_")
65 + TCollection_AsciiString (Standard_Atomic_Increment (&THE_AIS_INDEX_SEL));
66 }
7fd59977 67
e33e7e78
RK
68 static TCollection_AsciiString AIS_Context_NewCurName()
69 {
70 return TCollection_AsciiString ("AIS_CurContext_")
71 + TCollection_AsciiString (Standard_Atomic_Increment (&THE_AIS_INDEX_CUR));
72 }
b586500b 73
74 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)> AIS_MapOfObjectOwners;
75 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)>::Iterator AIS_MapIteratorOfMapOfObjectOwners;
2195ab96 76}
7fd59977 77
78//=======================================================================
79//function : AIS_InteractiveContext
80//purpose :
81//=======================================================================
82
83AIS_InteractiveContext::AIS_InteractiveContext(const Handle(V3d_Viewer)& MainViewer):
84mgrSelector(new SelectMgr_SelectionManager()),
85myMainPM(new PrsMgr_PresentationManager3d(MainViewer->Viewer())),
86myMainVwr(MainViewer),
87myMainSel(new StdSelect_ViewerSelector3d()),
cbff1e55 88myWasLastMain(Standard_False),
89myCurrentTouched(Standard_False),
90mySelectedTouched(Standard_False),
91myToHilightSelected(Standard_True),
7fd59977 92myFilters(new SelectMgr_OrFilter()),
93myDefaultDrawer(new Prs3d_Drawer()),
94myDefaultColor(Quantity_NOC_GOLDENROD),
95myHilightColor(Quantity_NOC_CYAN1),
96mySelectionColor(Quantity_NOC_GRAY80),
97myPreselectionColor(Quantity_NOC_GREEN),
98mySubIntensity(Quantity_NOC_GRAY40),
99myDisplayMode(0),
100myCurLocalIndex(0),
cbff1e55 101myAISCurDetected(0),
7fd59977 102myZDetectionFlag(0),
7fd59977 103myIsAutoActivateSelMode( Standard_True )
104{
105 InitAttributes();
106}
107
7fd59977 108void AIS_InteractiveContext::Delete() const
109{
2195ab96 110 // clear the static current selection
30bf45dc 111 AIS_Selection::ClearCurrentSelection();
2195ab96 112
7fd59977 113 // to avoid an exception
2195ab96 114 if (AIS_Selection::Find (mySelectionName.ToCString()))
115 {
116 AIS_Selection::Remove (mySelectionName.ToCString());
117 }
7fd59977 118
119 // to avoid an exception
2195ab96 120 if (AIS_Selection::Find (myCurrentName.ToCString()))
121 {
122 AIS_Selection::Remove (myCurrentName.ToCString());
123 }
7fd59977 124
125 // let's remove one reference explicitly. this operation's supposed to
126 // be performed when mgrSelector will be destroyed but anyway...
543a9964 127 const Handle(SelectMgr_ViewerSelector)& aSelector = myMainSel; // to avoid ambiguity
128 mgrSelector->Remove (aSelector);
2195ab96 129
da0e82aa 130 Handle(AIS_InteractiveContext) aNullContext;
2195ab96 131 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
da0e82aa 132 {
2195ab96 133 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
134 anObj->SetContext (aNullContext);
da0e82aa 135 }
7fd59977 136 MMgt_TShared::Delete();
137}
138
139//=======================================================================
140//function : AIS_SelectionName
141//purpose :
142//=======================================================================
143const TCollection_AsciiString& AIS_InteractiveContext::SelectionName() const
144{
145 if(!HasOpenedContext())
146 return mySelectionName;
147 return myLocalContexts(myCurLocalIndex)->SelectionName();
148
149}
150
151
152
153//=======================================================================
154//function : UpdateCurrentViewer
155//purpose :
156//=======================================================================
157
158void AIS_InteractiveContext::UpdateCurrentViewer()
159{
160 if (!myMainVwr.IsNull())
161 myMainVwr->Update();
162}
163
7fd59977 164
165//=======================================================================
166//function : DomainOfMainViewer
167//purpose :
168//=======================================================================
169
170Standard_CString AIS_InteractiveContext::DomainOfMainViewer() const
171{
172 return myMainVwr->Domain();
173
174}
175
176//=======================================================================
177//function : DisplayedObjects
2195ab96 178//purpose :
7fd59977 179//=======================================================================
2195ab96 180void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO,
181 const Standard_Boolean theOnlyFromNeutral) const
7fd59977 182{
2195ab96 183 if (!HasOpenedContext()
184 || theOnlyFromNeutral)
185 {
186 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
187 {
188 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
189 {
190 theListOfIO.Append (anObjIter.Key());
191 }
7fd59977 192 }
2195ab96 193 return;
7fd59977 194 }
7fd59977 195
2195ab96 196 // neutral point
197 TColStd_MapOfTransient aDispMap;
198 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
199 {
200 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
201 {
202 aDispMap.Add (anObjIter.Key());
7fd59977 203 }
2195ab96 204 }
205
206 // parse all local contexts...
207 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
208 {
209 const Handle(AIS_LocalContext)& aLocCtx = aCtxIter.Value();
210 aLocCtx->DisplayedObjects (aDispMap);
211 }
212
213 Handle(AIS_InteractiveObject) anObj;
214 for (TColStd_MapIteratorOfMapOfTransient aDispMapIter (aDispMap); aDispMapIter.More(); aDispMapIter.Next())
215 {
216 const Handle(Standard_Transient)& aTransient = aDispMapIter.Key();
c5f3a425 217 anObj = Handle(AIS_InteractiveObject)::DownCast (aTransient);
2195ab96 218 theListOfIO.Append (anObj);
219 }
7fd59977 220}
2195ab96 221
7fd59977 222//=======================================================================
223//function : DisplayedObjects
2195ab96 224//purpose :
7fd59977 225//=======================================================================
2195ab96 226void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
227 const Standard_Integer theSign,
228 AIS_ListOfInteractive& theListOfIO,
229 const Standard_Boolean /*OnlyFromNeutral*/) const
7fd59977 230{
2195ab96 231 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Displayed, theListOfIO);
7fd59977 232}
233
234//=======================================================================
7fd59977 235//function : ErasedObjects
2195ab96 236//purpose :
7fd59977 237//=======================================================================
2195ab96 238void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
7fd59977 239{
2195ab96 240 ObjectsByDisplayStatus (AIS_DS_Erased, theListOfIO);
7fd59977 241}
242
243//=======================================================================
244//function : ErasedObjects
2195ab96 245//purpose :
7fd59977 246//=======================================================================
2195ab96 247void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
248 const Standard_Integer theSign,
249 AIS_ListOfInteractive& theListOfIO) const
7fd59977 250{
2195ab96 251 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Erased, theListOfIO);
7fd59977 252}
253
254//=======================================================================
255//function : ObjectsByDisplayStatus
2195ab96 256//purpose :
7fd59977 257//=======================================================================
2195ab96 258void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_DisplayStatus theStatus,
259 AIS_ListOfInteractive& theListOfIO) const
7fd59977 260{
2195ab96 261 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
262 {
263 if (anObjIter.Value()->GraphicStatus() == theStatus)
264 {
265 theListOfIO.Append (anObjIter.Key());
266 }
7fd59977 267 }
268}
269
270//=======================================================================
271//function : ObjectsByDisplayStatus
2195ab96 272//purpose :
7fd59977 273//=======================================================================
2195ab96 274void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
275 const Standard_Integer theSign,
276 const AIS_DisplayStatus theStatus,
277 AIS_ListOfInteractive& theListOfIO) const
278{
279 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
280 {
a1954302 281 if (theStatus != AIS_DS_None
282 && anObjIter.Value()->GraphicStatus() != theStatus)
283 {
284 continue;
285 }
286 else if (anObjIter.Key()->Type() != theKind)
2195ab96 287 {
288 continue;
289 }
7fd59977 290
2195ab96 291 if (theSign == -1
292 || anObjIter.Key()->Signature() == theSign)
293 {
294 theListOfIO.Append (anObjIter.Key());
7fd59977 295 }
296 }
297}
298
299//=======================================================================
300//function : ObjectsInside
2195ab96 301//purpose :
7fd59977 302//=======================================================================
2195ab96 303void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive& theListOfIO,
304 const AIS_KindOfInteractive theKind,
305 const Standard_Integer theSign) const
7fd59977 306{
2195ab96 307 if (theKind == AIS_KOI_None
308 && theSign == -1)
309 {
310 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
311 {
312 theListOfIO.Append (anObjIter.Key());
7fd59977 313 }
2195ab96 314 return;
7fd59977 315 }
2195ab96 316
317 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
318 {
319 if (anObjIter.Key()->Type() != theKind)
320 {
321 continue;
322 }
323
324 if (theSign == -1
325 || anObjIter.Key()->Signature() == theSign)
326 {
327 theListOfIO.Append (anObjIter.Key());
7fd59977 328 }
329 }
330}
331
332//=======================================================================
a272ed94 333//function : ObjectsForView
334//purpose :
335//=======================================================================
336void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive& theListOfIO,
337 const Handle(V3d_View)& theView,
338 const Standard_Boolean theIsVisibleInView,
339 const AIS_DisplayStatus theStatus) const
340{
341 const Graphic3d_CView* aCView = reinterpret_cast<const Graphic3d_CView* >(theView->View()->CView());
342 const Standard_Integer aViewId = aCView->ViewId;
343 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
344 {
345 if (theStatus != AIS_DS_None
346 && anObjIter.Value()->GraphicStatus() != theStatus)
347 {
348 theListOfIO.Append (anObjIter.Key());
349 continue;
350 }
351
352 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->Viewer()->ObjectAffinity (anObjIter.Key());
353 const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
354 if (isVisible == theIsVisibleInView)
355 {
356 theListOfIO.Append (anObjIter.Key());
357 }
358 }
359}
360
361//=======================================================================
7fd59977 362//function : Display
2195ab96 363//purpose :
7fd59977 364//=======================================================================
2195ab96 365void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
366 const Standard_Boolean theToUpdateViewer)
367{
368 if (theIObj.IsNull())
369 {
370 return;
371 }
372
373 Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
374 GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
375
376 Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1,
377 theToUpdateViewer, theIObj->AcceptShapeDecomposition());
378}
7fd59977 379
2195ab96 380//=======================================================================
a272ed94 381//function : SetViewAffinity
382//purpose :
383//=======================================================================
384void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject)& theIObj,
385 const Handle(V3d_View)& theView,
386 const Standard_Boolean theIsVisible)
387{
388 if (theIObj.IsNull()
389 || !myObjects.IsBound (theIObj))
390 {
391 return;
392 }
393
394 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->Viewer()->ObjectAffinity (theIObj);
395 const Graphic3d_CView* aCView = reinterpret_cast<const Graphic3d_CView* >(theView->View()->CView());
396 anAffinity->SetVisible (aCView->ViewId, theIsVisible == Standard_True);
397 if (theIsVisible)
398 {
c04c30b3 399 theView->View()->ChangeHiddenObjects()->Remove (theIObj.get());
a272ed94 400 }
401 else
402 {
c04c30b3 403 theView->View()->ChangeHiddenObjects()->Add (theIObj.get());
a272ed94 404 }
405}
406
407//=======================================================================
2195ab96 408//function : Display
409//purpose :
410//=======================================================================
411void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
412 const Standard_Integer theDispMode,
413 const Standard_Integer theSelectionMode,
414 const Standard_Boolean theToUpdateViewer,
a1954302 415 const Standard_Boolean theToAllowDecomposition,
416 const AIS_DisplayStatus theDispStatus)
7fd59977 417{
2195ab96 418 if (theIObj.IsNull())
419 {
420 return;
421 }
7fd59977 422
a1954302 423 if (theDispStatus == AIS_DS_Erased)
424 {
425 Erase (theIObj, theToUpdateViewer);
426 Load (theIObj, theSelectionMode, theToAllowDecomposition);
427 return;
428 }
429
2195ab96 430 if (!theIObj->HasInteractiveContext())
431 {
432 theIObj->SetContext (this);
433 }
7fd59977 434
a1954302 435 if (theDispStatus == AIS_DS_Temporary
436 && !HasOpenedContext())
2195ab96 437 {
a1954302 438 return;
439 }
440 else if (HasOpenedContext())
441 {
442 if (theDispStatus == AIS_DS_None
443 || theDispStatus == AIS_DS_Temporary)
2195ab96 444 {
a1954302 445 myLocalContexts (myCurLocalIndex)->Display (theIObj, theDispMode, theToAllowDecomposition, theSelectionMode);
446 if (theToUpdateViewer)
447 {
448 myMainVwr->Update();
449 }
450 return;
2195ab96 451 }
2195ab96 452 }
7fd59977 453
2195ab96 454 if (!myObjects.IsBound (theIObj))
455 {
456 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
457 myObjects.Bind (theIObj, aStatus);
a272ed94 458 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->Viewer()->RegisterObject (theIObj);
2195ab96 459 myMainPM->Display(theIObj, theDispMode);
460 if (theSelectionMode != -1)
461 {
543a9964 462 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
463 if (!mgrSelector->Contains (anObj))
2195ab96 464 {
465 mgrSelector->Load (theIObj);
7fd59977 466 }
2195ab96 467 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
468 }
7fd59977 469 }
7fd59977 470 else
471 {
2195ab96 472 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
a1954302 473 if (aStatus->GraphicStatus() == AIS_DS_Temporary)
2195ab96 474 {
475 return;
476 }
a6964ce6 477
2195ab96 478 // Erase presentations for all display modes different from aDispMode.
479 // Then make sure aDispMode is displayed and maybe highlighted.
480 // Finally, activate selection mode <SelMode> if not yet activated.
481 TColStd_ListOfInteger aModesToRemove;
482 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
483 {
484 const Standard_Integer anOldMode = aDispModeIter.Value();
485 if (anOldMode != theDispMode)
486 {
487 aModesToRemove.Append (anOldMode);
488 if(myMainPM->IsHighlighted (theIObj, anOldMode))
489 {
490 myMainPM->Unhighlight (theIObj, anOldMode);
491 }
492 myMainPM->Erase (theIObj, anOldMode);
493 }
494 }
7fd59977 495
2195ab96 496 for (TColStd_ListIteratorOfListOfInteger aRemModeIter (aModesToRemove); aRemModeIter.More(); aRemModeIter.Next())
497 {
498 aStatus->RemoveDisplayMode (aRemModeIter.Value());
499 }
7fd59977 500
2195ab96 501 if (!aStatus->IsDModeIn (theDispMode))
502 {
503 aStatus->AddDisplayMode (theDispMode);
504 }
7fd59977 505
2195ab96 506 myMainPM->Display (theIObj, theDispMode);
a1954302 507 aStatus->SetGraphicStatus (AIS_DS_Displayed);
2195ab96 508 if (aStatus->IsHilighted())
509 {
510 const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
511 myMainPM->Highlight (theIObj, aHiMod);
512 }
513 if (theSelectionMode != -1)
514 {
543a9964 515 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
516 if (!mgrSelector->Contains (anObj))
2195ab96 517 {
518 mgrSelector->Load (theIObj);
7fd59977 519 }
2195ab96 520 if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
521 {
522 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
7fd59977 523 }
7fd59977 524 }
525 }
7fd59977 526
2195ab96 527 if (theToUpdateViewer)
528 {
529 myMainVwr->Update();
530 }
531}
7fd59977 532
533//=======================================================================
534//function : Load
2195ab96 535//purpose :
7fd59977 536//=======================================================================
2195ab96 537void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
538 const Standard_Integer theSelMode,
539 const Standard_Boolean theToAllowDecomposition)
7fd59977 540{
2195ab96 541 if (theIObj.IsNull())
542 {
543 return;
544 }
7fd59977 545
2195ab96 546 if (!theIObj->HasInteractiveContext())
547 {
548 theIObj->SetContext (this);
549 }
550
551 if (HasOpenedContext())
552 {
553 myLocalContexts (myCurLocalIndex)->Load (theIObj, theToAllowDecomposition, theSelMode);
554 return;
7fd59977 555 }
7fd59977 556
2195ab96 557 if (theSelMode == -1
89cc29b0 558 && !theToAllowDecomposition)
2195ab96 559 {
89cc29b0 560 if (!myObjects.IsBound (theIObj))
561 {
562 Standard_Integer aDispMode, aHiMod, aSelModeDef;
563 GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
564 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Erased, aDispMode, aSelModeDef);
565 myObjects.Bind (theIObj, aStatus);
566 }
567
568 // Register theIObj in the selection manager to prepare further activation of selection
543a9964 569 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
570 if (!mgrSelector->Contains (anObj))
89cc29b0 571 {
572 mgrSelector->Load (theIObj);
573 }
2195ab96 574 }
575}
7fd59977 576
577//=======================================================================
578//function : Erase
2195ab96 579//purpose :
7fd59977 580//=======================================================================
2195ab96 581void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
582 const Standard_Boolean theToUpdateViewer)
7fd59977 583{
2195ab96 584 if (theIObj.IsNull())
585 {
586 return;
587 }
7fd59977 588
2195ab96 589 if (!theIObj->IsAutoHilight())
590 {
591 theIObj->ClearSelected();
7fd59977 592 }
2195ab96 593
594 Standard_Boolean wasInCtx = Standard_False;
595 if (HasOpenedContext())
596 {
597 // First it is checked if it is possible to remove in the current local context
598 // then one tries to remove in other local contexts, if they allow it...
599 wasInCtx = myLocalContexts (myCurLocalIndex)->Erase (theIObj);
600 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
7fd59977 601 {
2195ab96 602 if (aCtxIter.Value()->AcceptErase())
603 {
604 wasInCtx = aCtxIter.Value()->Erase (theIObj) || wasInCtx;
7fd59977 605 }
7fd59977 606 }
2195ab96 607 }
608
609 if (!wasInCtx)
610 {
611 EraseGlobal (theIObj, Standard_False);
612 }
613
614 if (theToUpdateViewer)
615 {
616 myMainVwr->Update();
617 }
7fd59977 618}
7fd59977 619
620//=======================================================================
621//function : EraseAll
2195ab96 622//purpose :
7fd59977 623//=======================================================================
2195ab96 624void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
7fd59977 625{
2195ab96 626 if (HasOpenedContext())
eb4320f2 627 {
2195ab96 628 return;
629 }
630
631 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
632 {
633 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
eb4320f2 634 {
2195ab96 635 Erase (anObjIter.Key(), Standard_False);
7fd59977 636 }
637 }
2195ab96 638
639 if (theToUpdateViewer)
640 {
641 myMainVwr->Update();
642 }
7fd59977 643}
644
645//=======================================================================
646//function : DisplayAll
2195ab96 647//purpose :
7fd59977 648//=======================================================================
2195ab96 649void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
7fd59977 650{
2195ab96 651 if (HasOpenedContext())
652 {
653 return;
654 }
eb4320f2 655
2195ab96 656 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
657 {
658 const AIS_DisplayStatus aStatus = anObjIter.Value()->GraphicStatus();
659 if (aStatus == AIS_DS_Erased)
eb4320f2 660 {
2195ab96 661 Display (anObjIter.Key(), Standard_False);
7fd59977 662 }
663 }
2195ab96 664
665 if (theToUpdateViewer)
666 {
667 myMainVwr->Update();
668 }
7fd59977 669}
670
671//=======================================================================
672//function : DisplaySelected
2195ab96 673//purpose :
7fd59977 674//=======================================================================
2195ab96 675void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
7fd59977 676{
2195ab96 677 if (HasOpenedContext())
eb4320f2 678 {
2195ab96 679 return;
7fd59977 680 }
7fd59977 681
2195ab96 682 Standard_Boolean isFound = Standard_False;
683 Handle(AIS_Selection) aSelIter = AIS_Selection::Selection (myCurrentName.ToCString());
684 for (aSelIter->Init(); aSelIter->More(); aSelIter->Next())
685 {
686 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter->Value());
687 Display (anObj, Standard_False);
688 isFound = Standard_True;
689 }
7fd59977 690
2195ab96 691 if (isFound && theToUpdateViewer)
692 {
693 myMainVwr->Update();
694 }
695}
7fd59977 696
2195ab96 697//=======================================================================
698//function : EraseSelected
699//purpose :
700//=======================================================================
701void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
7fd59977 702{
2195ab96 703 if (HasOpenedContext())
eb4320f2 704 {
2195ab96 705 return;
706 }
707
708 Standard_Boolean isFound = Standard_False;
709 Handle(AIS_Selection) aSelIter = AIS_Selection::Selection(myCurrentName.ToCString());
710 for (aSelIter->Init(); aSelIter->More(); aSelIter->Next())
711 {
712 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter->Value());
713 Erase (anObj, Standard_False);
714 isFound = Standard_True;
715 }
716
717 if (isFound && theToUpdateViewer)
718 {
719 myMainVwr->Update();
7fd59977 720 }
721}
2195ab96 722
7fd59977 723//=======================================================================
724//function :
725//purpose :
726//=======================================================================
727
728Standard_Boolean AIS_InteractiveContext::KeepTemporary(const Handle(AIS_InteractiveObject)& anIObj,
729 const Standard_Integer WhichContext)
730{
731 if(anIObj.IsNull()) return Standard_False;
732
733 if(!HasOpenedContext()) return Standard_False;
734 if(myObjects.IsBound(anIObj)) return Standard_False;
735 if(WhichContext!=-1 && !myLocalContexts.IsBound(WhichContext)) return Standard_False;
736
81bba717 737 // Protection : if one tries to preserve a temporary object
738 // which is not in the local active context... rob 11-06-97
7fd59977 739
740 Standard_Integer IsItInLocal = myCurLocalIndex;
741 Standard_Boolean Found(Standard_False);
742
743 while(IsItInLocal>0 && !Found){
744 if(!myLocalContexts.IsBound(IsItInLocal))
745 IsItInLocal--;
746 else if(myLocalContexts(IsItInLocal)->IsIn(anIObj))
747 Found = Standard_True;
748 else
749 IsItInLocal--;
750 }
751
752 if(!Found) return Standard_False;
753
754
755// const Handle(AIS_LocalStatus)& LS = (WhichContext== -1) ?
756// myLocalContexts(IsItInLocal)->Status(anIObj):myLocalContexts(WhichContext)->Status(anIObj);
757 // CLE
758 // const Handle(AIS_LocalStatus)& LS = myLocalContexts(IsItInLocal)->Status(anIObj);
759 Handle(AIS_LocalStatus) LS = myLocalContexts(IsItInLocal)->Status(anIObj);
760 // ENDCLE
761
762
763 if(LS->IsTemporary()){
764 Standard_Integer DM,HM,SM;
765 GetDefModes(anIObj,DM,HM,SM);
766
767 SM = LS->SelectionModes().IsEmpty() ? SM : LS->SelectionModes().First();
768 if(LS->DisplayMode()!= DM ){
769 Standard_Integer LSM = LS->SelectionModes().IsEmpty() ? -1 : LS->SelectionModes().First();
770 myLocalContexts(IsItInLocal)->Display(anIObj,DM,LS->Decomposed(),LSM);
771 }
772
773 Handle (AIS_GlobalStatus) GS = new AIS_GlobalStatus(AIS_DS_Displayed,
774 DM,
775 SM,
776 Standard_False);
777// GS->SubIntensityOn();
778 myObjects.Bind(anIObj,GS);
779 mgrSelector->Load(anIObj);
780 mgrSelector->Activate(anIObj,SM,myMainSel);
781
782 LS->SetTemporary(Standard_False);
783 }
784 return Standard_True;
785}
786
7fd59977 787//=======================================================================
2195ab96 788//function : DisplayStatus
789//purpose :
7fd59977 790//=======================================================================
2195ab96 791AIS_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 792{
2195ab96 793 if (theIObj.IsNull())
794 {
795 return AIS_DS_None;
796 }
797 else if (myObjects.IsBound (theIObj))
798 {
799 return myObjects (theIObj)->GraphicStatus();
800 }
7fd59977 801
2195ab96 802 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
803 {
804 if (aCtxIter.Value()->IsIn (theIObj))
805 {
7fd59977 806 return AIS_DS_Temporary;
2195ab96 807 }
7fd59977 808 }
7fd59977 809 return AIS_DS_None;
7fd59977 810}
811
7fd59977 812//=======================================================================
813//function : DisplayedModes
2195ab96 814//purpose :
7fd59977 815//=======================================================================
2195ab96 816const TColStd_ListOfInteger& AIS_InteractiveContext::DisplayedModes (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 817{
2195ab96 818 return myObjects (theIObj)->DisplayedModes();
7fd59977 819}
820
7fd59977 821//=======================================================================
822//function : Remove
2195ab96 823//purpose :
7fd59977 824//=======================================================================
2195ab96 825void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
826 const Standard_Boolean theToUpdateViewer)
7fd59977 827{
2195ab96 828 if (theIObj.IsNull())
829 {
830 return;
7fd59977 831 }
2195ab96 832
833 if (HasOpenedContext())
834 {
835 myLocalContexts (myCurLocalIndex)->Remove (theIObj);
836 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
7fd59977 837 {
2195ab96 838 if (aCtxIter.Value()->AcceptErase())
839 {
840 aCtxIter.Value()->Remove (theIObj);
7fd59977 841 }
7fd59977 842 }
2195ab96 843 }
844
845 ClearGlobal (theIObj, theToUpdateViewer);
7fd59977 846}
847
848//=======================================================================
849//function : RemoveAll
2195ab96 850//purpose :
7fd59977 851//=======================================================================
2195ab96 852void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
7fd59977 853{
854 AIS_ListOfInteractive aList;
2195ab96 855 ObjectsInside (aList);
856 for (AIS_ListIteratorOfListOfInteractive aListIterator (aList); aListIterator.More(); aListIterator.Next())
857 {
858 Remove (aListIterator.Value(), Standard_False);
7fd59977 859 }
7fd59977 860
2195ab96 861 if (theToUpdateViewer)
862 {
863 myMainVwr->Update();
7fd59977 864 }
7fd59977 865}
866
7fd59977 867//=======================================================================
868//function : ClearPrs
2195ab96 869//purpose :
7fd59977 870//=======================================================================
2195ab96 871void AIS_InteractiveContext::ClearPrs (const Handle(AIS_InteractiveObject)& theIObj,
872 const Standard_Integer theMode,
873 const Standard_Boolean theToUpdateViewer)
7fd59977 874{
2195ab96 875 if (theIObj.IsNull())
876 {
877 return;
878 }
7fd59977 879
2195ab96 880 if (!HasOpenedContext())
881 {
882 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
883 return;
7fd59977 884 }
2195ab96 885
886 Standard_Boolean wasInCtx = myLocalContexts (myCurLocalIndex)->ClearPrs (theIObj, theMode);
887 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
888 {
889 if (aCtxIter.Value()->AcceptErase())
7fd59977 890 {
2195ab96 891 wasInCtx = aCtxIter.Value()->ClearPrs (theIObj, theMode) || wasInCtx;
7fd59977 892 }
2195ab96 893 }
894 if (!wasInCtx)
895 {
896 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
897 }
898 else if (theToUpdateViewer)
899 {
900 myMainVwr->Update();
901 }
7fd59977 902}
903
904//=======================================================================
905//function : Hilight
2195ab96 906//purpose :
7fd59977 907//=======================================================================
2195ab96 908void AIS_InteractiveContext::Hilight (const Handle(AIS_InteractiveObject)& theIObj,
909 const Standard_Boolean theToUpdateViewer)
7fd59977 910{
2195ab96 911 if (theIObj.IsNull())
912 {
913 return;
914 }
7fd59977 915
2195ab96 916 if (!theIObj->HasInteractiveContext())
917 {
918 theIObj->SetContext (this);
919 }
7fd59977 920 if (!HasOpenedContext())
eb4320f2 921 {
2195ab96 922 if (!myObjects.IsBound (theIObj))
923 {
924 return;
925 }
eb4320f2 926
2195ab96 927 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
928 aStatus->SetHilightStatus (Standard_True);
929 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
eb4320f2 930 {
2195ab96 931 Standard_Integer aHilightMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
932 myMainPM->Highlight (theIObj, aHilightMode);
7fd59977 933 }
eb4320f2 934 }
7fd59977 935 else
eb4320f2 936 {
2195ab96 937 myLocalContexts (myCurLocalIndex)->Hilight (theIObj);
eb4320f2 938 }
939
2195ab96 940 if (theToUpdateViewer)
941 {
942 myMainVwr->Update();
943 }
7fd59977 944}
945//=======================================================================
946//function : Hilight
947//purpose :
948//=======================================================================
949
950void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& anIObj,
951 const Quantity_NameOfColor aCol,
952 const Standard_Boolean updateviewer)
953{
954 if(anIObj.IsNull()) return;
955
956 if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
957
958 if (!HasOpenedContext())
eb4320f2 959 {
960 if(!myObjects.IsBound(anIObj)) return;
7fd59977 961
a1954302 962 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
963 aStatus->SetHilightStatus (Standard_True);
eb4320f2 964
a1954302 965 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
eb4320f2 966 {
a1954302 967 const Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
eb4320f2 968 myMainPM->Color (anIObj, aCol, aHilightMode);
a1954302 969 aStatus->SetHilightColor (aCol);
7fd59977 970 }
eb4320f2 971 }
7fd59977 972 else
eb4320f2 973 {
7fd59977 974 myLocalContexts(myCurLocalIndex)->Hilight(anIObj,aCol);
eb4320f2 975 }
7fd59977 976 if(updateviewer) myMainVwr->Update();
977}
978
979//=======================================================================
980//function : Unhilight
981//purpose :
982//=======================================================================
983
984void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
985{
986 if(anIObj.IsNull()) return;
987
988 if (!HasOpenedContext())
eb4320f2 989 {
990 if(!myObjects.IsBound(anIObj)) return;
7fd59977 991
a1954302 992 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
993 aStatus->SetHilightStatus (Standard_False);
994 aStatus->SetHilightColor(Quantity_NOC_WHITE);
eb4320f2 995
a1954302 996 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
eb4320f2 997 {
998 Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
999 myMainPM->Unhighlight (anIObj, aHilightMode);
7fd59977 1000 }
eb4320f2 1001 }
7fd59977 1002 else
eb4320f2 1003 {
7fd59977 1004 myLocalContexts(myCurLocalIndex)->Unhilight(anIObj);
eb4320f2 1005 }
7fd59977 1006 if(updateviewer) myMainVwr->Update();
1007}
1008
1009//=======================================================================
1010//function : IsHilighted
1011//purpose :
1012//=======================================================================
1013
1014Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj) const
1015{
1016 if(anIObj.IsNull()) return Standard_False;
1017
1018 if (!HasOpenedContext()){
1019 if(!myObjects.IsBound(anIObj))
1020 return Standard_False;
1021 return myObjects(anIObj)->IsHilighted();
1022 }
1023 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1024 for(;ItM.More();ItM.Next()){
1025 if(ItM.Value()->IsHilighted(anIObj))
1026 return Standard_True;
1027 }
1028 return Standard_False;
1029}
1030
1031Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj,
1032 Standard_Boolean& WithColor,
1033 Quantity_NameOfColor& TheHiCol) const
1034{
1035 if(!HasOpenedContext()){
1036 if(myObjects.IsBound(anIObj)){
1037 const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
1038 if(STAT->IsHilighted()){
1039 if(STAT->HilightColor()!=Quantity_NOC_WHITE){
1040 WithColor=Standard_True;
1041 TheHiCol = STAT->HilightColor();
1042 }
1043 else
1044 WithColor = Standard_False;
1045 return Standard_True;
1046 }
1047 }
1048 return Standard_False;
1049 }
1050 Standard_Integer MaxIndex = HighestIndex();
1051 for(Standard_Integer i=MaxIndex;i>=1 ; i--){
1052 if(myLocalContexts.IsBound(i)){
1053 if(myLocalContexts(i)->IsHilighted(anIObj,WithColor,TheHiCol))
1054 return Standard_True;
1055 }
1056
1057 }
1058 return Standard_False;
1059}
1060
1061
1062
1063//=======================================================================
1064//function : IsDisplayed
1065//purpose :
1066//=======================================================================
1067
1068Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anIObj) const
1069{
1070 if(anIObj.IsNull()) return Standard_False;
1071
1072
1073 if(myObjects.IsBound(anIObj))
1074 if(myObjects(anIObj)->GraphicStatus()==AIS_DS_Displayed)
1075 return Standard_True;
1076
1077 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1078 for(;ItM.More();ItM.Next()){
1079 if(ItM.Value()->IsDisplayed(anIObj))
1080 return Standard_True;
1081 }
1082 return Standard_False;
1083
1084}
7fd59977 1085
1086//=======================================================================
1087//function : IsDisplayed
2195ab96 1088//purpose :
7fd59977 1089//=======================================================================
2195ab96 1090Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
1091 const Standard_Integer theMode) const
7fd59977 1092{
2195ab96 1093 if (theIObj.IsNull())
1094 {
1095 return Standard_False;
1096 }
1097
1098 if (myObjects.IsBound (theIObj))
1099 {
1100 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1101 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1102 && aStatus->IsDModeIn (theMode))
1103 {
7fd59977 1104 return Standard_True;
2195ab96 1105 }
7fd59977 1106 }
2195ab96 1107
1108 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
1109 {
1110 if (aCtxIter.Value()->IsDisplayed (theIObj, theMode))
1111 {
7fd59977 1112 return Standard_True;
2195ab96 1113 }
7fd59977 1114 }
1115 return Standard_False;
1116}
1117
7fd59977 1118//=======================================================================
1119//function : DisplayPriority
2195ab96 1120//purpose :
7fd59977 1121//=======================================================================
2195ab96 1122Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 1123{
2195ab96 1124 if (theIObj.IsNull())
1125 {
1126 return -1;
1127 }
1128 else if (!myObjects.IsBound (theIObj))
1129 {
1130 return 0;
1131 }
eb4320f2 1132
2195ab96 1133 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1134 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1135 || aStatus->GraphicStatus() == AIS_DS_Erased)
eb4320f2 1136 {
2195ab96 1137 Standard_Integer aDispMode = theIObj->HasDisplayMode()
1138 ? theIObj->DisplayMode()
1139 : (theIObj->AcceptDisplayMode (myDisplayMode)
1140 ? myDisplayMode
1141 : 0);
1142 return myMainPM->DisplayPriority (theIObj, aDispMode);
7fd59977 1143 }
1144 return 0;
1145}
2195ab96 1146
7fd59977 1147//=======================================================================
1148//function : SetDisplayPriority
2195ab96 1149//purpose :
7fd59977 1150//=======================================================================
2195ab96 1151void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
1152 const Standard_Integer thePriority)
7fd59977 1153{
2195ab96 1154 if (theIObj.IsNull())
1155 {
7fd59977 1156 return;
2195ab96 1157 }
1158
1159 if (!theIObj->HasInteractiveContext())
eb4320f2 1160 {
2195ab96 1161 theIObj->SetContext (this);
1162 }
eb4320f2 1163
2195ab96 1164 if (myObjects.IsBound (theIObj))
1165 {
1166 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1167 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1168 || aStatus->GraphicStatus() == AIS_DS_Erased)
eb4320f2 1169 {
2195ab96 1170 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
1171 ? theIObj->DisplayMode()
1172 : (theIObj->AcceptDisplayMode (myDisplayMode)
1173 ? myDisplayMode
1174 : 0);
1175 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
7fd59977 1176 }
1177 }
1178 else if (HasOpenedContext())
eb4320f2 1179 {
2195ab96 1180 myLocalContexts (myCurLocalIndex)->SetDisplayPriority (theIObj, thePriority);
eb4320f2 1181 }
7fd59977 1182}
1183
1184//=======================================================================
1185//function : Redisplay
2195ab96 1186//purpose :
7fd59977 1187//=======================================================================
2195ab96 1188void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
1189 const Standard_Boolean theToUpdateViewer,
1190 const Standard_Boolean theAllModes)
7fd59977 1191{
2195ab96 1192 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
1193 RecomputeSelectionOnly (theIObj);
7fd59977 1194}
1195
1196//=======================================================================
1197//function : Redisplay
2195ab96 1198//purpose :
7fd59977 1199//=======================================================================
2195ab96 1200void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
1201 const Standard_Integer /*theSign*/,
1202 const Standard_Boolean theToUpdateViewer)
1203{
1204 Standard_Boolean isRedisplayed = Standard_False;
1205 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1206 {
1207 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1208 if (anObj->Type() != theKOI)
1209 {
1210 continue;
7fd59977 1211 }
2195ab96 1212
1213 Redisplay (anObj, Standard_False);
1214 isRedisplayed = anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed
1215 || isRedisplayed;
7fd59977 1216 }
2195ab96 1217
1218 if (theToUpdateViewer
1219 && isRedisplayed)
eb4320f2 1220 {
1221 myMainVwr->Update();
7fd59977 1222 }
1223}
1224
7fd59977 1225//=======================================================================
1226//function : RecomputePrsOnly
2195ab96 1227//purpose :
7fd59977 1228//=======================================================================
2195ab96 1229void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
1230 const Standard_Boolean theToUpdateViewer,
1231 const Standard_Boolean theAllModes)
7fd59977 1232{
2195ab96 1233 if (theIObj.IsNull())
1234 {
1235 return;
1236 }
eb4320f2 1237
2195ab96 1238 theIObj->Update (theAllModes);
1239 if (!theToUpdateViewer)
eb4320f2 1240 {
1241 return;
1242 }
1243
2195ab96 1244 if (HasOpenedContext()
1245 || (myObjects.IsBound (theIObj)
1246 && myObjects (theIObj)->GraphicStatus() == AIS_DS_Displayed))
eb4320f2 1247 {
1248 myMainVwr->Update();
7fd59977 1249 }
1250}
1251//=======================================================================
1252//function : RecomputeSelectionOnly
1253//purpose :
1254//=======================================================================
bc677575 1255void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
7fd59977 1256{
bc677575 1257 if (theIO.IsNull())
1258 {
1259 return;
1260 }
7fd59977 1261
bc677575 1262 mgrSelector->RecomputeSelection (theIO);
0d969553 1263
bc677575 1264 if (HasOpenedContext())
1265 {
1266 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
eb4320f2 1267 {
bc677575 1268 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIO, Standard_False);
eb4320f2 1269 }
bc677575 1270 return;
1271 }
1272
1273 if (!myObjects.IsBound (theIO) ||
1274 myObjects (theIO)->GraphicStatus() != AIS_DS_Displayed)
1275 {
1276 return;
1277 }
1278
1279 TColStd_ListOfInteger aModes;
1280 ActivatedModes (theIO, aModes);
1281 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1282 for (; aModesIter.More(); aModesIter.Next())
1283 {
1284 mgrSelector->Activate (theIO, aModesIter.Value(), myMainSel);
7fd59977 1285 }
1286}
1287
1288//=======================================================================
1289//function : Update
2195ab96 1290//purpose :
7fd59977 1291//=======================================================================
f3889691 1292void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
2195ab96 1293 const Standard_Boolean theUpdateViewer)
7fd59977 1294{
f3889691 1295 if (theIObj.IsNull())
1296 {
1297 return;
1298 }
7fd59977 1299
2195ab96 1300 TColStd_ListOfInteger aPrsModes;
1301 theIObj->ToBeUpdated (aPrsModes);
1302 for (TColStd_ListIteratorOfListOfInteger aPrsModesIt (aPrsModes); aPrsModesIt.More(); aPrsModesIt.Next())
f3889691 1303 {
1304 theIObj->Update (aPrsModesIt.Value(), Standard_False);
7fd59977 1305 }
f3889691 1306
1307 mgrSelector->Update(theIObj);
1308
bc677575 1309 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1310 {
1311 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIObj, Standard_False);
1312 }
1313
f3889691 1314 if (theUpdateViewer)
1315 {
1316 if (!myObjects.IsBound (theIObj))
1317 {
1318 return;
1319 }
1320
1321 switch (myObjects (theIObj)->GraphicStatus())
1322 {
1323 case AIS_DS_Displayed:
1324 case AIS_DS_Temporary:
1325 myMainVwr->Update();
1326 break;
1327 default:
1328 break;
7fd59977 1329 }
1330 }
1331}
1332
7fd59977 1333//=======================================================================
1334//function : SetLocation
2195ab96 1335//purpose :
7fd59977 1336//=======================================================================
2195ab96 1337void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1338 const TopLoc_Location& theLoc)
7fd59977 1339{
2195ab96 1340 if (theIObj.IsNull())
1341 {
1342 return;
1343 }
7fd59977 1344
2195ab96 1345 if (theIObj->HasTransformation()
1346 && theLoc.IsIdentity())
1347 {
1348 theIObj->ResetTransformation();
1349 mgrSelector->Update (theIObj, Standard_False);
1350 return;
1351 }
1352 else if (theLoc.IsIdentity())
1353 {
7fd59977 1354 return;
1355 }
7fd59977 1356
0d969553 1357 // first reset the previous location to properly clean everything...
2195ab96 1358 if (theIObj->HasTransformation())
1359 {
1360 theIObj->ResetTransformation();
1361 }
7fd59977 1362
2195ab96 1363 theIObj->SetLocalTransformation (theLoc.Transformation());
7fd59977 1364
2195ab96 1365 if (!HasOpenedContext())
1366 {
1367 mgrSelector->Update (theIObj, Standard_False);
1368 }
7fd59977 1369 else
2195ab96 1370 {
1371 Handle(StdSelect_ViewerSelector3d) aTempSel = myLocalContexts (myCurLocalIndex)->MainSelector();
1372 mgrSelector->Update (theIObj, aTempSel, Standard_False);
1373 }
7fd59977 1374}
2195ab96 1375
7fd59977 1376//=======================================================================
1377//function : ResetLocation
2195ab96 1378//purpose :
7fd59977 1379//=======================================================================
2195ab96 1380void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
7fd59977 1381{
2195ab96 1382 if (theIObj.IsNull())
1383 {
1384 return;
1385 }
7fd59977 1386
2195ab96 1387 theIObj->ResetTransformation();
1388 mgrSelector->Update (theIObj, Standard_False);
7fd59977 1389}
1390
1391//=======================================================================
1392//function : HasLocation
2195ab96 1393//purpose :
7fd59977 1394//=======================================================================
2195ab96 1395Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 1396{
2195ab96 1397 return !theIObj.IsNull()
1398 && theIObj->HasTransformation();
7fd59977 1399}
1400
2195ab96 1401//=======================================================================
1402//function : Location
1403//purpose :
1404//=======================================================================
1405TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 1406{
2195ab96 1407 return theIObj->Transformation();
7fd59977 1408}
1409
1410//=======================================================================
1411//function : SetDeviationCoefficient
2195ab96 1412//purpose :
7fd59977 1413//=======================================================================
2195ab96 1414void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
7fd59977 1415{
2195ab96 1416 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
7fd59977 1417}
2195ab96 1418
7fd59977 1419//=======================================================================
1420//function : SetDeviationAngle
2195ab96 1421//purpose :
7fd59977 1422//=======================================================================
2195ab96 1423void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
7fd59977 1424{
2195ab96 1425 myDefaultDrawer->SetDeviationCoefficient (theAngle);
7fd59977 1426}
1427
1428//=======================================================================
1429//function : DeviationAngle
1430//purpose : Gets deviationAngle
1431//=======================================================================
7fd59977 1432Standard_Real AIS_InteractiveContext::DeviationAngle() const
1433{
2195ab96 1434 return myDefaultDrawer->DeviationAngle();
7fd59977 1435}
1436
1437//=======================================================================
1438//function : DeviationCoefficient
2195ab96 1439//purpose :
7fd59977 1440//=======================================================================
2195ab96 1441Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
7fd59977 1442{
1443 return myDefaultDrawer->DeviationCoefficient();
1444}
2195ab96 1445
7fd59977 1446//=======================================================================
1447//function : SetHLRDeviationCoefficient
2195ab96 1448//purpose :
7fd59977 1449//=======================================================================
2195ab96 1450void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
7fd59977 1451{
2195ab96 1452 myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
7fd59977 1453}
1454
1455//=======================================================================
1456//function : HLRDeviationCoefficient
2195ab96 1457//purpose :
7fd59977 1458//=======================================================================
2195ab96 1459Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
7fd59977 1460{
1461 return myDefaultDrawer->HLRDeviationCoefficient();
1462}
1463
1464//=======================================================================
1465//function : SetHLRAngle
2195ab96 1466//purpose :
7fd59977 1467//=======================================================================
2195ab96 1468void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
7fd59977 1469{
2195ab96 1470 myDefaultDrawer->SetHLRAngle (theAngle);
7fd59977 1471}
1472
1473//=======================================================================
1474//function : SetHLRAngleAndDeviation
1475//purpose : compute with anangle a HLRAngle and a HLRDeviationCoefficient
1476// and set them in myHLRAngle and in myHLRDeviationCoefficient
1477// of myDefaultDrawer
1478//=======================================================================
2195ab96 1479void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
7fd59977 1480{
2195ab96 1481 Standard_Real anOutAngl, anOutDefl;
1482 HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
7fd59977 1483
2195ab96 1484 myDefaultDrawer->SetHLRAngle (anOutAngl);
1485 myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
7fd59977 1486}
1487
1488//=======================================================================
1489//function : HLRAngle
2195ab96 1490//purpose :
7fd59977 1491//=======================================================================
7fd59977 1492Standard_Real AIS_InteractiveContext::HLRAngle() const
1493{
1494 return myDefaultDrawer->HLRAngle();
1495}
1496
1497//=======================================================================
1498//function : SetDisplayMode
2195ab96 1499//purpose :
7fd59977 1500//=======================================================================
2195ab96 1501void AIS_InteractiveContext::SetDisplayMode (const AIS_DisplayMode theMode,
1502 const Standard_Boolean theToUpdateViewer)
7fd59977 1503{
2195ab96 1504 if (theMode == myDisplayMode)
1505 {
1506 return;
1507 }
7fd59977 1508
2195ab96 1509 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1510 {
1511 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1512 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1513 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1514 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
7fd59977 1515
2195ab96 1516 if (!toProcess
1517 || anObj->HasDisplayMode()
1518 || !anObj->AcceptDisplayMode (theMode))
1519 {
1520 continue;
1521 }
1522
1523 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1524 if (aStatus->IsDModeIn (myDisplayMode))
1525 {
1526 aStatus->RemoveDisplayMode (myDisplayMode);
1527 }
1528
1529 aStatus->AddDisplayMode (theMode);
1530 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1531 {
2195ab96 1532 myMainPM->Display (anObj, theMode);
1533 if (aStatus->IsSubIntensityOn())
7fd59977 1534 {
2195ab96 1535 myMainPM->Color (anObj, mySubIntensity, theMode);
7fd59977 1536 }
a1954302 1537 myMainPM->SetVisibility (anObj, myDisplayMode, Standard_False);
2195ab96 1538 }
1539 }
1540
1541 myDisplayMode = theMode;
1542 if (theToUpdateViewer)
1543 {
1544 myMainVwr->Update();
1545 }
7fd59977 1546}
1547
1548//=======================================================================
1549//function : SetDisplayMode
2195ab96 1550//purpose :
7fd59977 1551//=======================================================================
2195ab96 1552void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1553 const Standard_Integer theMode,
1554 const Standard_Boolean theToUpdateViewer)
7fd59977 1555{
2195ab96 1556 if (!theIObj->HasInteractiveContext())
1557 {
1558 theIObj->SetContext(this);
1559 }
7fd59977 1560
2195ab96 1561 if (!myObjects.IsBound (theIObj))
1562 {
1563 theIObj->SetDisplayMode (theMode);
1564 return;
1565 }
1566 else if (!theIObj->AcceptDisplayMode (theMode))
1567 {
1568 return;
1569 }
eb4320f2 1570
2195ab96 1571 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1572 if (aStatus->GraphicStatus() != AIS_DS_Displayed)
1573 {
1574 theIObj->SetDisplayMode (theMode);
1575 return;
1576 }
a6964ce6 1577
2195ab96 1578 // erase presentations for all display modes different from <aMode>
1579 TColStd_ListOfInteger aModesToRemove;
1580 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
1581 {
1582 const Standard_Integer anOldMode = aDispModeIter.Value();
1583 if (anOldMode != theMode)
1584 {
1585 aModesToRemove.Append (anOldMode);
1586 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1587 {
1588 myMainPM->Unhighlight (theIObj, anOldMode);
7fd59977 1589 }
2195ab96 1590 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
7fd59977 1591 }
1592 }
2195ab96 1593
1594 for (TColStd_ListIteratorOfListOfInteger aRemModeIter (aModesToRemove); aRemModeIter.More(); aRemModeIter.Next())
1595 {
1596 aStatus->RemoveDisplayMode (aRemModeIter.Value());
1597 }
1598
1599 if (!aStatus->IsDModeIn (theMode))
1600 {
1601 aStatus->AddDisplayMode (theMode);
1602 }
1603
1604 myMainPM->Display (theIObj, theMode);
1605 Standard_Integer aDispMode, aHiMode, aSelMode;
1606 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1607 if (aStatus->IsHilighted())
1608 {
1609 myMainPM->Highlight (theIObj, aHiMode);
1610 }
1611 if (aStatus->IsSubIntensityOn())
1612 {
1613 myMainPM->Color (theIObj, mySubIntensity, theMode);
1614 }
1615
1616 if (theToUpdateViewer)
1617 {
1618 myMainVwr->Update();
1619 }
1620 theIObj->SetDisplayMode (theMode);
7fd59977 1621}
1622
1623//=======================================================================
1624//function : UnsetDisplayMode
2195ab96 1625//purpose :
7fd59977 1626//=======================================================================
2195ab96 1627void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1628 const Standard_Boolean theToUpdateViewer)
7fd59977 1629{
2195ab96 1630 if (theIObj.IsNull()
1631 || !theIObj->HasDisplayMode())
1632 {
1633 return;
1634 }
1635
1636 if (!myObjects.IsBound (theIObj))
1637 {
1638 theIObj->UnsetDisplayMode();
1639 return;
1640 }
1641
1642 const Standard_Integer anOldMode = theIObj->DisplayMode();
1643 if (myDisplayMode == anOldMode)
1644 {
1645 return;
1646 }
1647
1648 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1649 aStatus->RemoveDisplayMode (anOldMode);
1650 if (!aStatus->IsDModeIn(myDisplayMode))
1651 {
1652 aStatus->AddDisplayMode (myDisplayMode);
1653 }
1654
1655 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1656 {
1657 if (myMainPM->IsHighlighted (theIObj, anOldMode))
7fd59977 1658 {
2195ab96 1659 myMainPM->Unhighlight (theIObj, anOldMode);
1660 }
1661 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1662 myMainPM->Display (theIObj, myDisplayMode);
1663
1664 Standard_Integer aDispMode, aHiMode, aSelMode;
1665 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1666 if (aStatus->IsHilighted())
1667 {
1668 myMainPM->Highlight (theIObj, aHiMode);
1669 }
1670 if (aStatus->IsSubIntensityOn())
1671 {
1672 myMainPM->Color (theIObj, mySubIntensity, myDisplayMode);
7fd59977 1673 }
2195ab96 1674
1675 if (theToUpdateViewer)
1676 {
1677 myMainVwr->Update();
1678 }
1679 }
1680
1681 theIObj->UnsetDisplayMode();
7fd59977 1682}
1683
1684//=======================================================================
1685//function : SetCurrentFacingModel
2195ab96 1686//purpose :
7fd59977 1687//=======================================================================
2195ab96 1688void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1689 const Aspect_TypeOfFacingModel theModel)
b8ddfc2f 1690{
2195ab96 1691 if (!theIObj.IsNull())
1692 {
1693 theIObj->SetCurrentFacingModel (theModel);
1694 }
7fd59977 1695}
7fd59977 1696
1697//=======================================================================
2195ab96 1698//function : redisplayPrsRecModes
1699//purpose :
7fd59977 1700//=======================================================================
2195ab96 1701void AIS_InteractiveContext::redisplayPrsRecModes (const Handle(AIS_InteractiveObject)& theIObj,
1702 const Standard_Boolean theToUpdateViewer)
7fd59977 1703{
2195ab96 1704 if (theIObj->RecomputeEveryPrs())
1705 {
36132a2e 1706 theIObj->Update (Standard_True);
1707 theIObj->UpdateSelection();
2195ab96 1708 }
1709 else
1710 {
1711 for (TColStd_ListIteratorOfListOfInteger aModes (theIObj->ListOfRecomputeModes()); aModes.More(); aModes.Next())
1712 {
1713 theIObj->Update (aModes.Value(), Standard_False);
1714 }
28ee613b 1715 theIObj->UpdateSelection();
2195ab96 1716 theIObj->SetRecomputeOk();
1717 }
1718
1719 if (theToUpdateViewer)
1720 {
1721 UpdateCurrentViewer();
1722 }
7fd59977 1723}
1724
2195ab96 1725//=======================================================================
1726//function : redisplayPrsModes
1727//purpose :
1728//=======================================================================
1729void AIS_InteractiveContext::redisplayPrsModes (const Handle(AIS_InteractiveObject)& theIObj,
1730 const Standard_Boolean theToUpdateViewer)
7fd59977 1731{
2195ab96 1732 if (theIObj->RecomputeEveryPrs())
1733 {
36132a2e 1734 theIObj->Update (Standard_True);
1735 theIObj->UpdateSelection();
2195ab96 1736 }
7fd59977 1737 else
2195ab96 1738 {
1739 TColStd_ListOfInteger aModes;
1740 theIObj->ToBeUpdated (aModes);
1741 for (TColStd_ListIteratorOfListOfInteger aModeIter (aModes); aModeIter.More(); aModeIter.Next())
7fd59977 1742 {
2195ab96 1743 theIObj->Update (aModeIter.Value(), Standard_False);
7fd59977 1744 }
2195ab96 1745 theIObj->SetRecomputeOk();
1746 }
7fd59977 1747
2195ab96 1748 if (theToUpdateViewer)
1749 {
1750 UpdateCurrentViewer();
1751 }
7fd59977 1752}
1753
1754//=======================================================================
2195ab96 1755//function : SetColor
1756//purpose :
7fd59977 1757//=======================================================================
2195ab96 1758void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1759 const Quantity_NameOfColor theColor,
1760 const Standard_Boolean theToUpdateViewer)
1761{
1762 SetColor (theIObj, Quantity_Color(theColor), theToUpdateViewer);
1763}
7fd59977 1764
2195ab96 1765//=======================================================================
1766//function : SetColor
1767//purpose :
1768//=======================================================================
1769void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1770 const Quantity_Color& theColor,
1771 const Standard_Boolean theToUpdateViewer)
7fd59977 1772{
2195ab96 1773 if (theIObj.IsNull())
1774 {
1775 return;
1776 }
7fd59977 1777
2195ab96 1778 if (!theIObj->HasInteractiveContext())
1779 {
1780 theIObj->SetContext (this);
1781 }
1782 theIObj->SetColor (theColor);
1783 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1784}
7fd59977 1785
2195ab96 1786//=======================================================================
1787//function : SetDeviationCoefficient
1788//purpose :
1789//=======================================================================
1790void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1791 const Standard_Real theCoefficient,
1792 const Standard_Boolean theToUpdateViewer)
1793{
1794 if (theIObj.IsNull())
1795 {
1796 return;
1797 }
7fd59977 1798
2195ab96 1799 if (!theIObj->HasInteractiveContext())
1800 {
1801 theIObj->SetContext (this);
1802 }
7fd59977 1803
2195ab96 1804 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1805 if (theIObj->Type() != AIS_KOI_Object
1806 && theIObj->Type() != AIS_KOI_Shape)
1807 {
1808 return;
1809 }
1810 else if (theIObj->Signature() != 0)
1811 {
1812 return;
1813 }
1814
1815 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1816 aShape->SetOwnDeviationCoefficient (theCoefficient);
1817 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1818}
1819
1820//=======================================================================
1821//function : SetHLRDeviationCoefficient
2195ab96 1822//purpose :
7fd59977 1823//=======================================================================
2195ab96 1824void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1825 const Standard_Real theCoefficient,
1826 const Standard_Boolean theToUpdateViewer)
7fd59977 1827{
2195ab96 1828 if (theIObj.IsNull())
1829 {
1830 return;
1831 }
1832
1833 if (!theIObj->HasInteractiveContext())
1834 {
1835 theIObj->SetContext (this);
1836 }
7fd59977 1837
81bba717 1838 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2195ab96 1839 if (theIObj->Type() != AIS_KOI_Object
1840 && theIObj->Type() != AIS_KOI_Shape)
1841 {
1842 return;
1843 }
1844 else if (theIObj->Signature() != 0)
1845 {
1846 return;
1847 }
7fd59977 1848
2195ab96 1849 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1850 aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1851 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1852}
1853
7fd59977 1854//=======================================================================
1855//function : SetDeviationAngle
2195ab96 1856//purpose :
7fd59977 1857//=======================================================================
2195ab96 1858void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1859 const Standard_Real theAngle,
1860 const Standard_Boolean theToUpdateViewer)
7fd59977 1861{
2195ab96 1862 if (theIObj.IsNull())
1863 {
1864 return;
1865 }
1866
1867 if (!theIObj->HasInteractiveContext())
1868 {
1869 theIObj->SetContext (this);
1870 }
7fd59977 1871
e33e7e78 1872 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2195ab96 1873 if (theIObj->Type() != AIS_KOI_Shape)
1874 {
1875 return;
1876 }
1877 else if (theIObj->Signature() != 0)
1878 {
1879 return;
1880 }
7fd59977 1881
2195ab96 1882 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1883 aShape->SetOwnDeviationAngle (theAngle);
1884 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1885}
2195ab96 1886
7fd59977 1887//=======================================================================
2195ab96 1888//function : SetAngleAndDeviation
1889//purpose :
7fd59977 1890//=======================================================================
2195ab96 1891void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1892 const Standard_Real theAngle,
1893 const Standard_Boolean theToUpdateViewer)
7fd59977 1894{
2195ab96 1895 if (theIObj.IsNull())
1896 {
1897 return;
1898 }
1899
1900 if (!theIObj->HasInteractiveContext())
1901 {
1902 theIObj->SetContext (this);
1903 }
7fd59977 1904
e33e7e78 1905 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2195ab96 1906 if (theIObj->Type() != AIS_KOI_Shape)
1907 {
1908 return;
1909 }
1910 if (theIObj->Signature() != 0)
1911 {
1912 return;
1913 }
7fd59977 1914
2195ab96 1915 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1916 aShape->SetAngleAndDeviation (theAngle);
7fd59977 1917
2195ab96 1918 if (theIObj->RecomputeEveryPrs())
1919 {
36132a2e 1920 theIObj->Update (Standard_True);
1921 theIObj->UpdateSelection();
2195ab96 1922 }
7fd59977 1923 else
2195ab96 1924 {
1925 Update (theIObj, theToUpdateViewer);
1926 }
7fd59977 1927}
1928
1929//=======================================================================
2195ab96 1930//function : SetHLRAngleAndDeviation
1931//purpose :
7fd59977 1932//=======================================================================
2195ab96 1933void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1934 const Standard_Real theAngle,
1935 const Standard_Boolean theToUpdateViewer)
7fd59977 1936{
2195ab96 1937 if (theIObj.IsNull())
1938 {
1939 return;
1940 }
7fd59977 1941
2195ab96 1942 if (!theIObj->HasInteractiveContext())
1943 {
1944 theIObj->SetContext (this);
1945 }
7fd59977 1946
e33e7e78 1947 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2195ab96 1948 if (theIObj->Type() != AIS_KOI_Shape)
1949 {
1950 return;
1951 }
1952 if (theIObj->Signature() != 0)
1953 {
1954 return;
1955 }
1956 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1957 aShape->SetHLRAngleAndDeviation (theAngle);
1958 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1959}
1960
1961//=======================================================================
1962//function : SetHLRDeviationAngle
2195ab96 1963//purpose :
7fd59977 1964//=======================================================================
2195ab96 1965void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1966 const Standard_Real theAngle,
1967 const Standard_Boolean theToUpdateViewer)
7fd59977 1968{
2195ab96 1969 if (theIObj.IsNull())
1970 {
1971 return;
1972 }
7fd59977 1973
2195ab96 1974 if (!theIObj->HasInteractiveContext())
1975 {
1976 theIObj->SetContext (this);
1977 }
7fd59977 1978
2195ab96 1979 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1980 if (theIObj->Type() != AIS_KOI_Shape)
1981 {
1982 return;
1983 }
1984 if (theIObj->Signature() != 0)
1985 {
1986 return;
1987 }
1988 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1989 aShape->SetOwnHLRDeviationAngle (theAngle);
1990 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1991}
1992
1993//=======================================================================
1994//function : UnsetColor
2195ab96 1995//purpose :
7fd59977 1996//=======================================================================
2195ab96 1997void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
1998 const Standard_Boolean theToUpdateViewer)
7fd59977 1999{
2195ab96 2000 if (theIObj.IsNull())
2001 {
2002 return;
2003 }
2004
2005 theIObj->UnsetColor();
2006 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2007}
2008
2009//=======================================================================
2010//function : HasColor
2195ab96 2011//purpose :
7fd59977 2012//=======================================================================
2195ab96 2013Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 2014{
2195ab96 2015 return theIObj->HasColor();
7fd59977 2016}
2017
2018//=======================================================================
2019//function : Color
2195ab96 2020//purpose :
7fd59977 2021//=======================================================================
2195ab96 2022Quantity_NameOfColor AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 2023{
2195ab96 2024 return theIObj->Color();
7fd59977 2025}
2026
2195ab96 2027//=======================================================================
2028//function : Color
2029//purpose :
2030//=======================================================================
2031void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
2032 Quantity_Color& theColor) const
7fd59977 2033{
2195ab96 2034 theIObj->Color (theColor);
7fd59977 2035}
7fd59977 2036
2037//=======================================================================
2038//function : Width
2195ab96 2039//purpose :
7fd59977 2040//=======================================================================
2195ab96 2041Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 2042{
2195ab96 2043 return theIObj->Width();
7fd59977 2044}
2045
2046//=======================================================================
2047//function : SetWidth
2195ab96 2048//purpose :
7fd59977 2049//=======================================================================
2195ab96 2050void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2051 const Standard_Real theWidth,
2052 const Standard_Boolean theToUpdateViewer)
7fd59977 2053{
2195ab96 2054 if (theIObj.IsNull())
2055 {
2056 return;
2057 }
2058
2059 if (!theIObj->HasInteractiveContext())
2060 {
2061 theIObj->SetContext (this);
2062 }
2063
2064 theIObj->SetWidth (theWidth);
2065 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2066}
2067
2068//=======================================================================
2069//function : UnsetWidth
2195ab96 2070//purpose :
7fd59977 2071//=======================================================================
2195ab96 2072void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2073 const Standard_Boolean theToUpdateViewer)
7fd59977 2074{
2195ab96 2075 if (theIObj.IsNull())
2076 {
2077 return;
2078 }
2079
2080 theIObj->UnsetWidth();
2081 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2082}
2083
2084//=======================================================================
2085//function : SetMaterial
2195ab96 2086//purpose :
7fd59977 2087//=======================================================================
2195ab96 2088void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2089 const Graphic3d_NameOfMaterial theName,
2090 const Standard_Boolean theToUpdateViewer)
7fd59977 2091{
2195ab96 2092 if (theIObj.IsNull())
2093 {
2094 return;
2095 }
2096
2097 if (!theIObj->HasInteractiveContext())
2098 {
2099 theIObj->SetContext (this);
2100 }
7fd59977 2101
2195ab96 2102 theIObj->SetMaterial (theName);
2103 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2104}
2105
2106//=======================================================================
2107//function : UnsetMaterial
2195ab96 2108//purpose :
7fd59977 2109//=======================================================================
2195ab96 2110void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2111 const Standard_Boolean theToUpdateViewer)
7fd59977 2112{
2195ab96 2113 if (theIObj.IsNull())
2114 {
2115 return;
2116 }
2117 theIObj->UnsetMaterial();
2118 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2119}
2120
2121//=======================================================================
2122//function : SetTransparency
2195ab96 2123//purpose :
7fd59977 2124//=======================================================================
2195ab96 2125void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2126 const Standard_Real theValue,
2127 const Standard_Boolean theToUpdateViewer)
7fd59977 2128{
2195ab96 2129 if (theIObj.IsNull())
2130 {
2131 return;
2132 }
2133
2134 if (!theIObj->HasInteractiveContext())
2135 {
2136 theIObj->SetContext (this);
2137 }
7fd59977 2138
2195ab96 2139 if (!theIObj->IsTransparent()
2140 && theValue <= 0.05)
a6964ce6 2141 {
2142 return;
2143 }
2144
2195ab96 2145 if (theValue <= 0.05)
2146 {
2147 UnsetTransparency (theIObj, theToUpdateViewer);
7fd59977 2148 return;
2149 }
a6964ce6 2150
2195ab96 2151 theIObj->SetTransparency (theValue);
2152 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2153}
2154
2155//=======================================================================
2156//function : UnsetTransparency
2195ab96 2157//purpose :
7fd59977 2158//=======================================================================
2195ab96 2159void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2160 const Standard_Boolean theToUpdateViewer)
7fd59977 2161{
2195ab96 2162 if (theIObj.IsNull())
2163 {
2164 return;
2165 }
7fd59977 2166
2195ab96 2167 theIObj->UnsetTransparency();
2168 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2169}
2170
2195ab96 2171//=======================================================================
2172//function : SetSelectedAspect
2173//purpose :
2174//=======================================================================
2175void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
2176 const Standard_Boolean theIsGlobalChange,
2177 const Standard_Boolean theToUpdateViewer)
2178{
2179 if (HasOpenedContext())
2180 {
2181 return;
2182 }
2183
2184 Standard_Boolean isFound = Standard_False;
2185 Handle(AIS_Selection) aSelIter = AIS_Selection::Selection (myCurrentName.ToCString());
2186 for (aSelIter->Init(); aSelIter->More(); aSelIter->Next())
2187 {
2188 isFound = Standard_True;
2189 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter->Value());
2190 anObj->SetAspect (theAspect, theIsGlobalChange);
2191 }
2192
2193 if (isFound
2194 && theToUpdateViewer)
2195 {
2196 myMainVwr->Update();
7fd59977 2197 }
2198}
7fd59977 2199
2200//=======================================================================
2201//function : SetLocalAttributes
2195ab96 2202//purpose :
7fd59977 2203//=======================================================================
2195ab96 2204void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
6262338c 2205 const Handle(Prs3d_Drawer)& theDrawer,
2195ab96 2206 const Standard_Boolean theToUpdateViewer)
7fd59977 2207{
2195ab96 2208 if (theIObj.IsNull())
2209 {
2210 return;
2211 }
2212
2213 if (!theIObj->HasInteractiveContext())
2214 {
2215 theIObj->SetContext (this);
2216 }
2217
2218 theIObj->SetAttributes (theDrawer);
2219 Update (theIObj, theToUpdateViewer);
7fd59977 2220}
2221
2222//=======================================================================
2223//function : UnsetLocalAttributes
2195ab96 2224//purpose :
7fd59977 2225//=======================================================================
2195ab96 2226void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2227 const Standard_Boolean theToUpdateViewer)
7fd59977 2228{
2195ab96 2229 if (theIObj.IsNull())
2230 {
2231 return;
2232 }
7fd59977 2233
2195ab96 2234 if (!theIObj->HasInteractiveContext())
2235 {
2236 theIObj->SetContext (this);
2237 }
2238 theIObj->UnsetAttributes();
2239 Update (theIObj, theToUpdateViewer);
2240}
7fd59977 2241
2242//=======================================================================
2243//function : Status
2195ab96 2244//purpose :
7fd59977 2245//=======================================================================
2195ab96 2246void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
2247 TCollection_ExtendedString& theStatus) const
7fd59977 2248{
2195ab96 2249 theStatus = "";
2250 if (theIObj.IsNull()
2251 || !myObjects.IsBound (theIObj))
2252 {
2253 return;
2254 }
7fd59977 2255
2195ab96 2256 theStatus += "\t ____________________________________________";
2257 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
2258 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2259 switch (aStatus->GraphicStatus())
2260 {
7fd59977 2261 case AIS_DS_Displayed:
2195ab96 2262 {
2263 theStatus += "\t| -->Displayed\n";
7fd59977 2264 break;
2265 }
2195ab96 2266 case AIS_DS_Erased:
2267 {
2268 theStatus += "\t| -->Erased\n";
2269 break;
7fd59977 2270 }
2195ab96 2271 default:
2272 break;
2273 }
2274
2275 theStatus += "\t| Active Display Modes in the MainViewer :\n";
2276 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2277 {
2278 theStatus += "\t|\t Mode ";
2279 theStatus += TCollection_AsciiString (aDispModeIter.Value());
2280 theStatus += "\n";
2281 }
2282 if (IsCurrent (theIObj)) theStatus +="\t| Current\n";
2283 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
7fd59977 2284
2195ab96 2285 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
2286 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2287 {
2288 theStatus += "\t\t Mode ";
2289 theStatus += TCollection_AsciiString (aSelModeIter.Value());
2290 theStatus += "\n";
2291 }
2292 theStatus += "\t ____________________________________________";
2293}
7fd59977 2294
2295//=======================================================================
2296//function : GetDefModes
2195ab96 2297//purpose :
7fd59977 2298//=======================================================================
2195ab96 2299void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
2300 Standard_Integer& theDispMode,
2301 Standard_Integer& theHiMode,
2302 Standard_Integer& theSelMode) const
7fd59977 2303{
2195ab96 2304 if (theIObj.IsNull())
2305 {
2306 return;
2307 }
7fd59977 2308
2195ab96 2309 theDispMode = theIObj->HasDisplayMode()
2310 ? theIObj->DisplayMode()
2311 : (theIObj->AcceptDisplayMode (myDisplayMode)
2312 ? myDisplayMode
2313 : 0);
2314 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
2315 theSelMode = theIObj->HasSelectionMode() ? theIObj->SelectionMode() : -1;
2316}
7fd59977 2317
2318//=======================================================================
2319//function : EraseGlobal
2195ab96 2320//purpose :
7fd59977 2321//=======================================================================
2195ab96 2322void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2323 const Standard_Boolean theToUpdateviewer)
7fd59977 2324{
2195ab96 2325 if (theIObj.IsNull()
2326 || !myObjects.IsBound (theIObj))
2327 {
2328 return;
2329 }
7fd59977 2330
2195ab96 2331 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2332
a1954302 2333 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2334 if (aStatus->GraphicStatus() == AIS_DS_Temporary
2335 || aStatus->GraphicStatus() == AIS_DS_Erased)
2195ab96 2336 {
a1954302 2337 return;
2338 }
2195ab96 2339
a1954302 2340 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2341 {
c3ec36b6 2342 if (aStatus->IsHilighted())
2195ab96 2343 {
c3ec36b6 2344 if (IsCurrent (theIObj))
2345 {
2346 AddOrRemoveCurrentObject (theIObj, Standard_False);
2347 }
2348 else if (myMainPM->IsHighlighted (theIObj, aDispModeIter.Value()))
2349 {
2350 myMainPM->Unhighlight (theIObj, aDispModeIter.Value());
2351 }
2195ab96 2352 }
2353
a1954302 2354 myMainPM->SetVisibility (theIObj, aDispModeIter.Value(), Standard_False);
2355 }
2195ab96 2356
a1954302 2357 if (IsCurrent (theIObj)
2358 && !aStatus->IsDModeIn (aDispMode))
2359 {
2360 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
2361 }
2362
2363 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2364 {
2365 mgrSelector->Deactivate (theIObj, aSelModeIter.Value(), myMainSel);
7fd59977 2366 }
2195ab96 2367 aStatus->SetGraphicStatus (AIS_DS_Erased);
a1954302 2368
2369 if (theToUpdateviewer)
2370 {
2371 myMainVwr->Update();
2372 }
7fd59977 2373}
2374
2375//=======================================================================
2376//function : ClearGlobal
2195ab96 2377//purpose :
7fd59977 2378//=======================================================================
2195ab96 2379void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2380 const Standard_Boolean theToUpdateviewer)
7fd59977 2381{
2195ab96 2382 if (theIObj.IsNull()
2383 || !myObjects.IsBound (theIObj))
2384 {
f751596e 2385 // for cases when reference shape of connected interactives was not displayed
2386 // but its selection primitives were calculated
543a9964 2387 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2388 mgrSelector->Remove (anObj);
2195ab96 2389 return;
2390 }
2391
2392 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2393 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2394 {
2395 if (aStatus->IsHilighted())
2396 {
2397 if (IsCurrent (theIObj))
2398 {
2399 AddOrRemoveCurrentObject (theIObj, theToUpdateviewer);
2400 }
2401 else if (myMainPM->IsHighlighted (theIObj, aDispModeIter.Value()))
2402 {
2403 myMainPM->Unhighlight (theIObj, aDispModeIter.Value());
2404 }
2405 }
2406 myMainPM->Erase (theIObj, aDispModeIter.Value());
2407 myMainPM->Clear (theIObj, aDispModeIter.Value());
2408 if (theIObj->HasHilightMode())
2409 {
2410 Standard_Integer im = theIObj->HilightMode();
2411 myMainPM->Unhighlight (theIObj, im);
2412 myMainPM->Erase (theIObj, im);
2413 }
2414 }
7fd59977 2415
2195ab96 2416 // Object removes from Detected sequence
2417 for(Standard_Integer aDetIter = 1; aDetIter < myAISDetectedSeq.Length(); ++aDetIter)
7fd59977 2418 {
2419 Handle(AIS_InteractiveObject) anObj = DetectedCurrentObject();
2195ab96 2420 if (!anObj.IsNull()
2421 && anObj != theIObj)
2422 {
2423 myAISDetectedSeq.Remove (aDetIter);
2424 }
7fd59977 2425 }
2426
2195ab96 2427 if (myLastinMain == theIObj)
2428 {
44d9ae89 2429 myLastinMain.Nullify();
2195ab96 2430 }
2431 if (myLastPicked == theIObj)
2432 {
7fd59977 2433 myLastPicked.Nullify();
2195ab96 2434 }
2435
2436 // remove IO from the selection manager to avoid memory leaks
543a9964 2437 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2438 mgrSelector->Remove (anObj);
7fd59977 2439
2195ab96 2440 myObjects.UnBind (theIObj);
a272ed94 2441 myMainVwr->Viewer()->UnregisterObject (theIObj);
2442 for (myMainVwr->InitDefinedViews(); myMainVwr->MoreDefinedViews(); myMainVwr->NextDefinedViews())
2443 {
c04c30b3 2444 myMainVwr->DefinedView()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
a272ed94 2445 }
7fd59977 2446
2195ab96 2447 if (theToUpdateviewer
2448 && aStatus->GraphicStatus() == AIS_DS_Displayed)
eb4320f2 2449 {
2450 myMainVwr->Update();
2451 }
7fd59977 2452}
2453
2454//=======================================================================
2455//function : ClearGlobalPrs
2195ab96 2456//purpose :
7fd59977 2457//=======================================================================
2195ab96 2458void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2459 const Standard_Integer theMode,
2460 const Standard_Boolean theToUpdateViewer)
7fd59977 2461{
2195ab96 2462 if (theIObj.IsNull()
2463 || !myObjects.IsBound (theIObj))
2464 {
2465 return;
2466 }
2467
2468 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2469 if (aStatus->IsDModeIn (theMode))
2470 {
2471 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2472 if (aDispMode == theMode
2473 && myMainPM->IsHighlighted (theIObj, theMode))
2474 {
2475 myMainPM->Unhighlight (theIObj, theMode);
2476 }
2477
2478 myMainPM->Erase (theIObj, theMode);
2479 myMainPM->Clear (theIObj, theMode);
7fd59977 2480 }
eb4320f2 2481
2195ab96 2482 if (aStatus->GraphicStatus() == AIS_DS_Displayed
2483 && theToUpdateViewer)
2484 {
7fd59977 2485 myMainVwr->Update();
2195ab96 2486 }
7fd59977 2487}
2488
2489//=======================================================================
2490//function : DrawHiddenLine
2195ab96 2491//purpose :
7fd59977 2492//=======================================================================
2195ab96 2493Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2494{
7fd59977 2495 return myDefaultDrawer->DrawHiddenLine();
2496}
2497
2498//=======================================================================
2499//function : EnableDrawHiddenLine
2195ab96 2500//purpose :
7fd59977 2501//=======================================================================
2195ab96 2502void AIS_InteractiveContext::EnableDrawHiddenLine() const
2503{
7fd59977 2504 myDefaultDrawer->EnableDrawHiddenLine();
2505}
2506
2507//=======================================================================
2508//function : DisableDrawHiddenLine
2195ab96 2509//purpose :
7fd59977 2510//=======================================================================
2195ab96 2511void AIS_InteractiveContext::DisableDrawHiddenLine() const
2512{
7fd59977 2513 myDefaultDrawer->DisableDrawHiddenLine();
2514}
2515
2516//=======================================================================
2517//function : HiddenLineAspect
2195ab96 2518//purpose :
7fd59977 2519//=======================================================================
2195ab96 2520Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2521{
7fd59977 2522 return myDefaultDrawer->HiddenLineAspect();
2523}
2524
2525//=======================================================================
2526//function : SetHiddenLineAspect
2195ab96 2527//purpose :
7fd59977 2528//=======================================================================
2195ab96 2529void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2530{
2531 myDefaultDrawer->SetHiddenLineAspect (theAspect);
7fd59977 2532}
2533
2534//=======================================================================
2535//function : SetIsoNumber
2195ab96 2536//purpose :
7fd59977 2537//=======================================================================
2195ab96 2538void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2539 const AIS_TypeOfIso theType)
7fd59977 2540{
2195ab96 2541 switch (theType)
2542 {
2543 case AIS_TOI_IsoU:
2544 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2545 break;
2546 case AIS_TOI_IsoV:
2547 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2548 break;
2549 case AIS_TOI_Both:
2550 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2551 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2552 break;
7fd59977 2553 }
2554}
2195ab96 2555
7fd59977 2556//=======================================================================
2557//function : IsoNumber
2195ab96 2558//purpose :
7fd59977 2559//=======================================================================
2195ab96 2560Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
7fd59977 2561{
2195ab96 2562 switch (theType)
2563 {
2564 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2565 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2566 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2567 ? myDefaultDrawer->UIsoAspect()->Number()
2568 : -1;
7fd59977 2569 }
2570 return 0;
2571}
2572
2573//=======================================================================
2574//function : IsoOnPlane
2195ab96 2575//purpose :
7fd59977 2576//=======================================================================
2195ab96 2577void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
7fd59977 2578{
2195ab96 2579 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
7fd59977 2580}
2581
2582//=======================================================================
2583//function : IsoOnPlane
2195ab96 2584//purpose :
7fd59977 2585//=======================================================================
2195ab96 2586Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
7fd59977 2587{
2588 return myDefaultDrawer->IsoOnPlane();
2589}
2590
2591//=======================================================================
2592//function : SetSelectionMode
2195ab96 2593//purpose :
7fd59977 2594//=======================================================================
2195ab96 2595void AIS_InteractiveContext::SetSelectionMode (const Handle(AIS_InteractiveObject)& ,
2596 const Standard_Integer )
7fd59977 2597{
2195ab96 2598 //
7fd59977 2599}
2600
2601//=======================================================================
2602//function : UnsetSelectionMode
2195ab96 2603//purpose :
7fd59977 2604//=======================================================================
2195ab96 2605void AIS_InteractiveContext::UnsetSelectionMode (const Handle(AIS_InteractiveObject)& )
7fd59977 2606{
2195ab96 2607 //
7fd59977 2608}
2609
3c982548 2610//=======================================================================
3c982548 2611//function : SetPixelTolerance
28ee613b 2612//purpose : Disables the mechanism of adaptive tolerance calculation in
2613// SelectMgr_ViewerSelector and sets the given tolerance for ALL
2614// sensitive entities activated. For more information, see
2615// SelectMgr_ViewerSelector.hxx
3c982548 2616//=======================================================================
f751596e 2617void AIS_InteractiveContext::SetPixelTolerance (const Standard_Real thePrecision)
2195ab96 2618{
2619 if (HasOpenedContext())
2620 {
2621 myLocalContexts (myCurLocalIndex)->SetPixelTolerance (thePrecision);
2622 }
2623 else
2624 {
2625 myMainSel->SetPixelTolerance (thePrecision);
7fd59977 2626 }
2627}
3c982548 2628
2629//=======================================================================
2630//function : PixelTolerance
2195ab96 2631//purpose :
3c982548 2632//=======================================================================
f751596e 2633Standard_Real AIS_InteractiveContext::PixelTolerance() const
2195ab96 2634{
2635 return HasOpenedContext()
2636 ? myLocalContexts (myCurLocalIndex)->PixelTolerance()
2637 : myMainSel->PixelTolerance();
3c982548 2638}
7fd59977 2639
2640//=======================================================================
2641//function : IsInLocal
2195ab96 2642//purpose :
7fd59977 2643//=======================================================================
2195ab96 2644Standard_Boolean AIS_InteractiveContext::IsInLocal (const Handle(AIS_InteractiveObject)& theIObj,
2645 Standard_Integer& theIndex) const
7fd59977 2646{
2195ab96 2647 if (theIObj.IsNull())
2648 {
2649 return Standard_False;
2650 }
2651
81bba717 2652 // if it exists at neutral point 0 index is returned
2195ab96 2653 if (myObjects.IsBound (theIObj))
2654 {
2655 theIndex = 0;
7fd59977 2656 return Standard_False;
2657 }
2195ab96 2658
2659 for (Standard_Integer aCtxIter = 1; aCtxIter <= myLocalContexts.Extent(); ++aCtxIter)
2660 {
2661 if (myLocalContexts.IsBound (aCtxIter))
2662 {
2663 if(myLocalContexts (aCtxIter)->IsIn (theIObj))
2664 {
2665 theIndex = aCtxIter;
7fd59977 2666 return Standard_True;
7fd59977 2667 }
2668 }
2669 }
2195ab96 2670 theIndex = -1;
7fd59977 2671 return Standard_False;
2195ab96 2672}
2673
7fd59977 2674//=======================================================================
2675//function : InitAttributes
2195ab96 2676//purpose :
7fd59977 2677//=======================================================================
7fd59977 2678void AIS_InteractiveContext::InitAttributes()
2679{
2195ab96 2680 mgrSelector->Add (myMainSel);
7fd59977 2681 myCurrentName = AIS_Context_NewCurName();
2682 mySelectionName = AIS_Context_NewSelName();
2683
2195ab96 2684 AIS_Selection::CreateSelection (mySelectionName.ToCString());
2685 AIS_Selection::CreateSelection (myCurrentName.ToCString());
7fd59977 2686
2195ab96 2687 myDefaultDrawer->SetShadingAspectGlobal (Standard_False);
2688 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2689 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
7fd59977 2690
2691// myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2195ab96 2692 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2693 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2694 aLineAspect->SetWidth (1.0);
2695 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
7fd59977 2696
28ee613b 2697 // tolerance to 2 pixels...
2698 SetPixelTolerance (2.0);
7fd59977 2699
2700 // Customizing the drawer for trihedrons and planes...
2195ab96 2701 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2702 const Standard_Real aLength = 100.0;
2703 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2704 const Quantity_NameOfColor aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2705 aTrihAspect->FirstAxisAspect() ->SetColor (aColor);
2706 aTrihAspect->SecondAxisAspect()->SetColor (aColor);
2707 aTrihAspect->ThirdAxisAspect() ->SetColor (aColor);
7fd59977 2708
2195ab96 2709 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2710 const Standard_Real aPlaneLength = 200.0;
2711 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2712 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
7fd59977 2713}
2714
7fd59977 2715//=======================================================================
2716//function : TrihedronSize
2195ab96 2717//purpose :
7fd59977 2718//=======================================================================
2719Standard_Real AIS_InteractiveContext::TrihedronSize() const
2720{
2721 return myDefaultDrawer->DatumAspect()->FirstAxisLength();
2722}
2195ab96 2723
7fd59977 2724//=======================================================================
2725//function : SetTrihedronSize
2195ab96 2726//purpose :
7fd59977 2727//=======================================================================
2195ab96 2728void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2729 const Standard_Boolean /*updateviewer*/)
7fd59977 2730{
2195ab96 2731 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2732 Redisplay (AIS_KOI_Datum, 3, Standard_False);
2733 Redisplay (AIS_KOI_Datum, 4, Standard_True);
7fd59977 2734}
2735
7fd59977 2736//=======================================================================
2737//function : SetPlaneSize
2195ab96 2738//purpose :
7fd59977 2739//=======================================================================
2195ab96 2740void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2741 const Standard_Real theValY,
7fd59977 2742 const Standard_Boolean /*updateviewer*/)
2743{
2195ab96 2744 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2745 Redisplay (AIS_KOI_Datum, 7);
7fd59977 2746}
2747
2748//=======================================================================
2749//function : SetPlaneSize
2195ab96 2750//purpose :
7fd59977 2751//=======================================================================
2195ab96 2752void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2753 const Standard_Boolean theToUpdateViewer)
7fd59977 2754{
2195ab96 2755 SetPlaneSize (theVal, theVal, theToUpdateViewer);
7fd59977 2756}
2757
2758//=======================================================================
2759//function : PlaneSize
2195ab96 2760//purpose :
7fd59977 2761//=======================================================================
2195ab96 2762Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2763 Standard_Real& theY) const
7fd59977 2764{
2195ab96 2765 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2766 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2767 return (Abs (theX - theY) <= Precision::Confusion());
7fd59977 2768}
2769
7fd59977 2770//=======================================================================
2195ab96 2771//function : SetAutoActivateSelection
2772//purpose :
7fd59977 2773//=======================================================================
2195ab96 2774void AIS_InteractiveContext::SetAutoActivateSelection (const Standard_Boolean theIsAuto)
7fd59977 2775{
2195ab96 2776 myIsAutoActivateSelMode = theIsAuto;
7fd59977 2777}
2778
2779//=======================================================================
2195ab96 2780//function : GetAutoActivateSelection
2781//purpose :
7fd59977 2782//=======================================================================
2783Standard_Boolean AIS_InteractiveContext::GetAutoActivateSelection() const
2784{
2785 return myIsAutoActivateSelMode;
2786}
59f45b7c 2787
2788//=======================================================================
2789//function : SetZLayer
2195ab96 2790//purpose :
59f45b7c 2791//=======================================================================
59f45b7c 2792void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2793 const Standard_Integer theLayerId)
2794{
2195ab96 2795 if (theIObj.IsNull())
59f45b7c 2796 return;
2797
a1954302 2798 theIObj->SetZLayer (theLayerId);
59f45b7c 2799}
2800
2801//=======================================================================
2802//function : GetZLayer
2195ab96 2803//purpose :
59f45b7c 2804//=======================================================================
59f45b7c 2805Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2806{
a1954302 2807 return !theIObj.IsNull()
2808 ? theIObj->ZLayer()
2809 : Graphic3d_ZLayerId_UNKNOWN;
59f45b7c 2810}
f751596e 2811
2812//=======================================================================
2813//function : RebuildSelectionStructs
2814//purpose : Rebuilds 1st level of BVH selection forcibly
2815//=======================================================================
2816void AIS_InteractiveContext::RebuildSelectionStructs()
2817{
2818 myMainSel->RebuildObjectsTree (Standard_True);
2819}
2820
2821//=======================================================================
2822//function : Disconnect
2823//purpose : Disconnects selectable object from an assembly and updates selection structures
2824//=======================================================================
2825void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2826 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2827{
2828 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2829 {
c5f3a425 2830 Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
f751596e 2831 theObj->Disconnect (theObjToDisconnect);
543a9964 2832 const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2833 mgrSelector->Remove (anObj);
f751596e 2834 }
c04c30b3 2835 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
f751596e 2836 {
c5f3a425 2837 Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
f751596e 2838 theObj->Disconnect();
543a9964 2839 const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2840 mgrSelector->Remove (anObj);
f751596e 2841 }
2842 else
2843 return;
2844}
b586500b 2845
2846//=======================================================================
2847//function : FitSelected
2848//purpose : Fits the view corresponding to the bounds of selected objects
2849//=======================================================================
2850void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2851 const Standard_Real theMargin,
2852 const Standard_Boolean theToUpdate)
2853{
2854 Standard_CString aSelName = HasOpenedContext() ?
2855 myLocalContexts (myCurLocalIndex)->SelectionName().ToCString()
2856 : myCurrentName.ToCString();
2857
2858 Bnd_Box aBndSelected;
2859
2860 const Handle(AIS_Selection)& aSelection = AIS_Selection::Selection (aSelName);
2861 AIS_MapOfObjectOwners anObjectOwnerMap;
2862 for (aSelection->Init(); aSelection->More(); aSelection->Next())
2863 {
c5f3a425 2864 Handle(AIS_InteractiveObject) anObj (Handle(AIS_InteractiveObject)::DownCast (aSelection->Value()));
b586500b 2865 if (!anObj.IsNull())
2866 {
2867 if (anObj->IsInfinite())
2868 continue;
2869
2870 Bnd_Box aTmpBnd;
2871 anObj->BoundingBox (aTmpBnd);
2872 aBndSelected.Add (aTmpBnd);
2873 }
2874 else
2875 {
c5f3a425 2876 Handle(SelectMgr_EntityOwner) anOwner (Handle(SelectMgr_EntityOwner)::DownCast (aSelection->Value()));
b586500b 2877 if (anOwner.IsNull())
2878 continue;
2879
2880 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2881 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2882 {
2883 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2884 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2885 }
2886
2887 anOwnerMap->Add (anOwner);
2888 }
2889 }
2890
2891 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2892 {
2893 const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2894 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2895 aBndSelected.Add (aTmpBox);
2896 }
2897
2898 anObjectOwnerMap.Clear();
2899
2900 if (aBndSelected.IsVoid())
2901 return;
2902
2903 theView->FitAll (aBndSelected, theMargin, theToUpdate);
2904}