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