0027818: Visualization - provide an interface to define highlight presentation properties
[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),
8e5fb5ea 91myHiStyle(new Graphic3d_HighlightStyle (Aspect_TOHM_COLOR, Quantity_NOC_CYAN1)),
92mySelStyle(new Graphic3d_HighlightStyle (Aspect_TOHM_COLOR, Quantity_NOC_GRAY80)),
7fd59977 93myPreselectionColor(Quantity_NOC_GREEN),
8e5fb5ea 94mySubintStyle(new Graphic3d_HighlightStyle (Aspect_TOHM_COLOR, Quantity_NOC_GRAY40)),
7fd59977 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 {
8e5fb5ea 448 unhighlightGlobal (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;
8e5fb5ea 460 highlightGlobal (theIObj, aStatus->HilightStyle(), 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//=======================================================================
8e5fb5ea 850//function : HilightWithColor
851//purpose :
7fd59977 852//=======================================================================
8e5fb5ea 853void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& theObj,
854 const Handle(Graphic3d_HighlightStyle)& theStyle,
855 const Standard_Boolean theIsToUpdate)
7fd59977 856{
8e5fb5ea 857 if (theObj.IsNull())
2195ab96 858 return;
7fd59977 859
8e5fb5ea 860 if (!theObj->HasInteractiveContext())
861 theObj->SetContext (this);
862
7fd59977 863 if (!HasOpenedContext())
eb4320f2 864 {
8e5fb5ea 865 if (!myObjects.IsBound (theObj))
2195ab96 866 return;
eb4320f2 867
8e5fb5ea 868 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theObj);
2195ab96 869 aStatus->SetHilightStatus (Standard_True);
8e5fb5ea 870
2195ab96 871 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
eb4320f2 872 {
8e5fb5ea 873 const Standard_Integer aHilightMode = theObj->HasHilightMode() ? theObj->HilightMode() : 0;
874 highlightGlobal (theObj, theStyle, aHilightMode);
875 aStatus->SetHilightStyle (theStyle);
7fd59977 876 }
eb4320f2 877 }
7fd59977 878 else
eb4320f2 879 {
8e5fb5ea 880 myLocalContexts (myCurLocalIndex)->Hilight (theObj, theStyle);
eb4320f2 881 }
882
8e5fb5ea 883 if (theIsToUpdate)
2195ab96 884 myMainVwr->Update();
7fd59977 885}
886
887//=======================================================================
888//function : Unhilight
889//purpose :
890//=======================================================================
7fd59977 891void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
892{
893 if(anIObj.IsNull()) return;
894
895 if (!HasOpenedContext())
eb4320f2 896 {
897 if(!myObjects.IsBound(anIObj)) return;
7fd59977 898
a1954302 899 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
900 aStatus->SetHilightStatus (Standard_False);
8e5fb5ea 901 aStatus->SetHilightStyle (new Graphic3d_HighlightStyle());
eb4320f2 902
a1954302 903 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
eb4320f2 904 {
905 Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
8e5fb5ea 906 unhighlightGlobal (anIObj, aHilightMode);
7fd59977 907 }
eb4320f2 908 }
7fd59977 909 else
eb4320f2 910 {
7fd59977 911 myLocalContexts(myCurLocalIndex)->Unhilight(anIObj);
eb4320f2 912 }
7fd59977 913 if(updateviewer) myMainVwr->Update();
914}
915
916//=======================================================================
917//function : IsHilighted
8e5fb5ea 918//purpose : Returns true if the objects global status is set to highlighted.
7fd59977 919//=======================================================================
8e5fb5ea 920Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(AIS_InteractiveObject)& theObj) const
7fd59977 921{
8e5fb5ea 922 if (!HasOpenedContext())
923 {
924 if (!myObjects.IsBound (theObj))
7fd59977 925 return Standard_False;
7fd59977 926
8e5fb5ea 927 return myObjects (theObj)->IsHilighted();
7fd59977 928 }
8e5fb5ea 929
930 for (Standard_Integer aCtxIdx = HighestIndex(); aCtxIdx >= 1; aCtxIdx--)
931 {
932 if (myLocalContexts.IsBound (aCtxIdx))
933 {
934 if (myLocalContexts (aCtxIdx)->IsHilighted (theObj))
7fd59977 935 return Standard_True;
936 }
7fd59977 937 }
8e5fb5ea 938
7fd59977 939 return Standard_False;
940}
941
c3282ec1 942//=======================================================================
943//function : IsHilighted
8e5fb5ea 944//purpose : Returns true if the owner is highlighted with selection style.
c3282ec1 945//=======================================================================
8e5fb5ea 946Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner) const
c3282ec1 947{
948 if (theOwner.IsNull() || !theOwner->HasSelectable())
949 return Standard_False;
950
951 const Handle(AIS_InteractiveObject) anObj =
952 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
953
8e5fb5ea 954 if (anObj->GlobalSelOwner() == theOwner)
955 {
956 if (!myObjects.IsBound (anObj))
957 return Standard_False;
958
959 return myObjects (anObj)->IsHilighted();
960 }
961
962 return theOwner->IsSelected();
963}
964
965//=======================================================================
966//function : HighlightStyle
967//purpose :
968//=======================================================================
969Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(AIS_InteractiveObject)& theObj,
970 Handle(Graphic3d_HighlightStyle)& theStyle) const
971{
972 if (HasOpenedContext())
973 myLocalContexts (myCurLocalIndex)->HighlightStyle (theObj, theStyle);
974
975 if (IsHilighted (theObj))
976 {
977 theStyle = myObjects (theObj)->HilightStyle();
978 return Standard_True;
979 }
980 else
981 {
982 theStyle.Nullify();
c3282ec1 983 return Standard_False;
8e5fb5ea 984 }
985}
c3282ec1 986
8e5fb5ea 987//=======================================================================
988//function : HighlightStyle
989//purpose :
990//=======================================================================
991Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(SelectMgr_EntityOwner)& theOwner,
992 Handle(Graphic3d_HighlightStyle)& theStyle) const
993{
994 if (theOwner.IsNull() || !theOwner->HasSelectable())
995 return Standard_False;
996
997 if (IsHilighted (theOwner))
c3282ec1 998 {
8e5fb5ea 999 const Handle(AIS_InteractiveObject) anObj =
1000 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1001 if (anObj->GlobalSelOwner() == theOwner)
c3282ec1 1002 {
8e5fb5ea 1003 theStyle = myObjects (anObj)->HilightStyle();
c3282ec1 1004 }
1005 else
1006 {
8e5fb5ea 1007 // since part selection style is not stored in global status,
1008 // check if the object has own selection style. If not, it can
1009 // only be highlighted with default selection style (because
1010 // sub-intensity does not modify any selection states)
1011 theStyle = getSelStyle (anObj);
c3282ec1 1012 }
c3282ec1 1013 return Standard_True;
1014 }
8e5fb5ea 1015 else
1016 {
1017 theStyle.Nullify();
1018 return Standard_False;
1019 }
c3282ec1 1020}
7fd59977 1021
1022//=======================================================================
1023//function : IsDisplayed
1024//purpose :
1025//=======================================================================
1026
1027Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anIObj) const
1028{
1029 if(anIObj.IsNull()) return Standard_False;
1030
1031
1032 if(myObjects.IsBound(anIObj))
1033 if(myObjects(anIObj)->GraphicStatus()==AIS_DS_Displayed)
1034 return Standard_True;
1035
1036 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1037 for(;ItM.More();ItM.Next()){
1038 if(ItM.Value()->IsDisplayed(anIObj))
1039 return Standard_True;
1040 }
1041 return Standard_False;
1042
1043}
7fd59977 1044
1045//=======================================================================
1046//function : IsDisplayed
2195ab96 1047//purpose :
7fd59977 1048//=======================================================================
2195ab96 1049Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
1050 const Standard_Integer theMode) const
7fd59977 1051{
2195ab96 1052 if (theIObj.IsNull())
1053 {
1054 return Standard_False;
1055 }
1056
1057 if (myObjects.IsBound (theIObj))
1058 {
1059 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1060 if (aStatus->GraphicStatus() == AIS_DS_Displayed
3db69e41 1061 && theIObj->DisplayMode() == theMode)
2195ab96 1062 {
7fd59977 1063 return Standard_True;
2195ab96 1064 }
7fd59977 1065 }
2195ab96 1066
1067 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
1068 {
1069 if (aCtxIter.Value()->IsDisplayed (theIObj, theMode))
1070 {
7fd59977 1071 return Standard_True;
2195ab96 1072 }
7fd59977 1073 }
1074 return Standard_False;
1075}
1076
7fd59977 1077//=======================================================================
1078//function : DisplayPriority
2195ab96 1079//purpose :
7fd59977 1080//=======================================================================
2195ab96 1081Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 1082{
2195ab96 1083 if (theIObj.IsNull())
1084 {
1085 return -1;
1086 }
1087 else if (!myObjects.IsBound (theIObj))
1088 {
1089 return 0;
1090 }
eb4320f2 1091
2195ab96 1092 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1093 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1094 || aStatus->GraphicStatus() == AIS_DS_Erased)
eb4320f2 1095 {
2195ab96 1096 Standard_Integer aDispMode = theIObj->HasDisplayMode()
1097 ? theIObj->DisplayMode()
1098 : (theIObj->AcceptDisplayMode (myDisplayMode)
1099 ? myDisplayMode
1100 : 0);
1101 return myMainPM->DisplayPriority (theIObj, aDispMode);
7fd59977 1102 }
1103 return 0;
1104}
2195ab96 1105
7fd59977 1106//=======================================================================
1107//function : SetDisplayPriority
2195ab96 1108//purpose :
7fd59977 1109//=======================================================================
2195ab96 1110void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
1111 const Standard_Integer thePriority)
7fd59977 1112{
2195ab96 1113 if (theIObj.IsNull())
1114 {
7fd59977 1115 return;
2195ab96 1116 }
1117
1118 if (!theIObj->HasInteractiveContext())
eb4320f2 1119 {
2195ab96 1120 theIObj->SetContext (this);
1121 }
eb4320f2 1122
2195ab96 1123 if (myObjects.IsBound (theIObj))
1124 {
1125 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1126 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1127 || aStatus->GraphicStatus() == AIS_DS_Erased)
eb4320f2 1128 {
2195ab96 1129 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
1130 ? theIObj->DisplayMode()
1131 : (theIObj->AcceptDisplayMode (myDisplayMode)
1132 ? myDisplayMode
1133 : 0);
1134 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
7fd59977 1135 }
1136 }
1137 else if (HasOpenedContext())
eb4320f2 1138 {
2195ab96 1139 myLocalContexts (myCurLocalIndex)->SetDisplayPriority (theIObj, thePriority);
eb4320f2 1140 }
7fd59977 1141}
1142
1143//=======================================================================
1144//function : Redisplay
2195ab96 1145//purpose :
7fd59977 1146//=======================================================================
2195ab96 1147void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
1148 const Standard_Boolean theToUpdateViewer,
1149 const Standard_Boolean theAllModes)
7fd59977 1150{
2195ab96 1151 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
1152 RecomputeSelectionOnly (theIObj);
7fd59977 1153}
1154
1155//=======================================================================
1156//function : Redisplay
2195ab96 1157//purpose :
7fd59977 1158//=======================================================================
2195ab96 1159void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
1160 const Standard_Integer /*theSign*/,
1161 const Standard_Boolean theToUpdateViewer)
1162{
1163 Standard_Boolean isRedisplayed = Standard_False;
1164 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1165 {
1166 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1167 if (anObj->Type() != theKOI)
1168 {
1169 continue;
7fd59977 1170 }
2195ab96 1171
1172 Redisplay (anObj, Standard_False);
1173 isRedisplayed = anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed
1174 || isRedisplayed;
7fd59977 1175 }
2195ab96 1176
1177 if (theToUpdateViewer
1178 && isRedisplayed)
eb4320f2 1179 {
1180 myMainVwr->Update();
7fd59977 1181 }
1182}
1183
7fd59977 1184//=======================================================================
1185//function : RecomputePrsOnly
2195ab96 1186//purpose :
7fd59977 1187//=======================================================================
2195ab96 1188void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
1189 const Standard_Boolean theToUpdateViewer,
1190 const Standard_Boolean theAllModes)
7fd59977 1191{
2195ab96 1192 if (theIObj.IsNull())
1193 {
1194 return;
1195 }
eb4320f2 1196
2195ab96 1197 theIObj->Update (theAllModes);
1198 if (!theToUpdateViewer)
eb4320f2 1199 {
1200 return;
1201 }
1202
2195ab96 1203 if (HasOpenedContext()
1204 || (myObjects.IsBound (theIObj)
1205 && myObjects (theIObj)->GraphicStatus() == AIS_DS_Displayed))
eb4320f2 1206 {
1207 myMainVwr->Update();
7fd59977 1208 }
1209}
1210//=======================================================================
1211//function : RecomputeSelectionOnly
1212//purpose :
1213//=======================================================================
bc677575 1214void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
7fd59977 1215{
bc677575 1216 if (theIO.IsNull())
1217 {
1218 return;
1219 }
7fd59977 1220
bc677575 1221 mgrSelector->RecomputeSelection (theIO);
0d969553 1222
bc677575 1223 if (HasOpenedContext())
1224 {
1225 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
eb4320f2 1226 {
bc677575 1227 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIO, Standard_False);
eb4320f2 1228 }
bc677575 1229 return;
1230 }
1231
1232 if (!myObjects.IsBound (theIO) ||
1233 myObjects (theIO)->GraphicStatus() != AIS_DS_Displayed)
1234 {
1235 return;
1236 }
1237
1238 TColStd_ListOfInteger aModes;
1239 ActivatedModes (theIO, aModes);
1240 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1241 for (; aModesIter.More(); aModesIter.Next())
1242 {
1243 mgrSelector->Activate (theIO, aModesIter.Value(), myMainSel);
7fd59977 1244 }
1245}
1246
1247//=======================================================================
1248//function : Update
2195ab96 1249//purpose :
7fd59977 1250//=======================================================================
f3889691 1251void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
2195ab96 1252 const Standard_Boolean theUpdateViewer)
7fd59977 1253{
f3889691 1254 if (theIObj.IsNull())
1255 {
1256 return;
1257 }
7fd59977 1258
2195ab96 1259 TColStd_ListOfInteger aPrsModes;
1260 theIObj->ToBeUpdated (aPrsModes);
1261 for (TColStd_ListIteratorOfListOfInteger aPrsModesIt (aPrsModes); aPrsModesIt.More(); aPrsModesIt.Next())
f3889691 1262 {
1263 theIObj->Update (aPrsModesIt.Value(), Standard_False);
7fd59977 1264 }
f3889691 1265
1266 mgrSelector->Update(theIObj);
1267
bc677575 1268 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1269 {
1270 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIObj, Standard_False);
1271 }
1272
f3889691 1273 if (theUpdateViewer)
1274 {
1275 if (!myObjects.IsBound (theIObj))
1276 {
1277 return;
1278 }
1279
1280 switch (myObjects (theIObj)->GraphicStatus())
1281 {
1282 case AIS_DS_Displayed:
1283 case AIS_DS_Temporary:
1284 myMainVwr->Update();
1285 break;
1286 default:
1287 break;
7fd59977 1288 }
1289 }
1290}
1291
7fd59977 1292//=======================================================================
1293//function : SetLocation
2195ab96 1294//purpose :
7fd59977 1295//=======================================================================
2195ab96 1296void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1297 const TopLoc_Location& theLoc)
7fd59977 1298{
2195ab96 1299 if (theIObj.IsNull())
1300 {
1301 return;
1302 }
7fd59977 1303
2195ab96 1304 if (theIObj->HasTransformation()
1305 && theLoc.IsIdentity())
1306 {
1307 theIObj->ResetTransformation();
1308 mgrSelector->Update (theIObj, Standard_False);
1309 return;
1310 }
1311 else if (theLoc.IsIdentity())
1312 {
7fd59977 1313 return;
1314 }
7fd59977 1315
0d969553 1316 // first reset the previous location to properly clean everything...
2195ab96 1317 if (theIObj->HasTransformation())
1318 {
1319 theIObj->ResetTransformation();
1320 }
7fd59977 1321
2195ab96 1322 theIObj->SetLocalTransformation (theLoc.Transformation());
7fd59977 1323
2195ab96 1324 if (!HasOpenedContext())
1325 {
1326 mgrSelector->Update (theIObj, Standard_False);
1327 }
7fd59977 1328 else
2195ab96 1329 {
1330 Handle(StdSelect_ViewerSelector3d) aTempSel = myLocalContexts (myCurLocalIndex)->MainSelector();
1331 mgrSelector->Update (theIObj, aTempSel, Standard_False);
1332 }
5396886c 1333
1334 // if the object or its part is highlighted dynamically, it is necessary to apply location transformation
1335 // to its highlight structure immediately
8e5fb5ea 1336 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
5396886c 1337 {
1338 myLastPicked->UpdateHighlightTrsf (myMainVwr,
1339 myMainPM,
1340 theIObj->HasDisplayMode() ? theIObj->DisplayMode() : 0);
1341 }
7fd59977 1342}
2195ab96 1343
7fd59977 1344//=======================================================================
1345//function : ResetLocation
2195ab96 1346//purpose :
7fd59977 1347//=======================================================================
2195ab96 1348void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
7fd59977 1349{
2195ab96 1350 if (theIObj.IsNull())
1351 {
1352 return;
1353 }
7fd59977 1354
2195ab96 1355 theIObj->ResetTransformation();
1356 mgrSelector->Update (theIObj, Standard_False);
7fd59977 1357}
1358
1359//=======================================================================
1360//function : HasLocation
2195ab96 1361//purpose :
7fd59977 1362//=======================================================================
2195ab96 1363Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 1364{
2195ab96 1365 return !theIObj.IsNull()
1366 && theIObj->HasTransformation();
7fd59977 1367}
1368
2195ab96 1369//=======================================================================
1370//function : Location
1371//purpose :
1372//=======================================================================
1373TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 1374{
2195ab96 1375 return theIObj->Transformation();
7fd59977 1376}
1377
1378//=======================================================================
1379//function : SetDeviationCoefficient
2195ab96 1380//purpose :
7fd59977 1381//=======================================================================
2195ab96 1382void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
7fd59977 1383{
2195ab96 1384 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
7fd59977 1385}
2195ab96 1386
7fd59977 1387//=======================================================================
1388//function : SetDeviationAngle
2195ab96 1389//purpose :
7fd59977 1390//=======================================================================
2195ab96 1391void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
7fd59977 1392{
e19792fa 1393 myDefaultDrawer->SetDeviationAngle (theAngle);
7fd59977 1394}
1395
1396//=======================================================================
1397//function : DeviationAngle
1398//purpose : Gets deviationAngle
1399//=======================================================================
7fd59977 1400Standard_Real AIS_InteractiveContext::DeviationAngle() const
1401{
2195ab96 1402 return myDefaultDrawer->DeviationAngle();
7fd59977 1403}
1404
1405//=======================================================================
1406//function : DeviationCoefficient
2195ab96 1407//purpose :
7fd59977 1408//=======================================================================
2195ab96 1409Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
7fd59977 1410{
1411 return myDefaultDrawer->DeviationCoefficient();
1412}
2195ab96 1413
7fd59977 1414//=======================================================================
1415//function : SetHLRDeviationCoefficient
2195ab96 1416//purpose :
7fd59977 1417//=======================================================================
2195ab96 1418void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
7fd59977 1419{
2195ab96 1420 myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
7fd59977 1421}
1422
1423//=======================================================================
1424//function : HLRDeviationCoefficient
2195ab96 1425//purpose :
7fd59977 1426//=======================================================================
2195ab96 1427Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
7fd59977 1428{
1429 return myDefaultDrawer->HLRDeviationCoefficient();
1430}
1431
1432//=======================================================================
1433//function : SetHLRAngle
2195ab96 1434//purpose :
7fd59977 1435//=======================================================================
2195ab96 1436void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
7fd59977 1437{
2195ab96 1438 myDefaultDrawer->SetHLRAngle (theAngle);
7fd59977 1439}
1440
1441//=======================================================================
1442//function : SetHLRAngleAndDeviation
1443//purpose : compute with anangle a HLRAngle and a HLRDeviationCoefficient
1444// and set them in myHLRAngle and in myHLRDeviationCoefficient
1445// of myDefaultDrawer
1446//=======================================================================
2195ab96 1447void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
7fd59977 1448{
2195ab96 1449 Standard_Real anOutAngl, anOutDefl;
1450 HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
7fd59977 1451
2195ab96 1452 myDefaultDrawer->SetHLRAngle (anOutAngl);
1453 myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
7fd59977 1454}
1455
1456//=======================================================================
1457//function : HLRAngle
2195ab96 1458//purpose :
7fd59977 1459//=======================================================================
7fd59977 1460Standard_Real AIS_InteractiveContext::HLRAngle() const
1461{
1462 return myDefaultDrawer->HLRAngle();
1463}
1464
1465//=======================================================================
1466//function : SetDisplayMode
2195ab96 1467//purpose :
7fd59977 1468//=======================================================================
e5d7e249 1469void AIS_InteractiveContext::SetDisplayMode(const Standard_Integer theMode,
1470 const Standard_Boolean theToUpdateViewer)
7fd59977 1471{
2195ab96 1472 if (theMode == myDisplayMode)
1473 {
1474 return;
1475 }
7fd59977 1476
2195ab96 1477 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1478 {
1479 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1480 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1481 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1482 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
7fd59977 1483
2195ab96 1484 if (!toProcess
1485 || anObj->HasDisplayMode()
1486 || !anObj->AcceptDisplayMode (theMode))
1487 {
1488 continue;
1489 }
1490
1491 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
3db69e41 1492 aStatus->SetDisplayMode (theMode);
2195ab96 1493
2195ab96 1494 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1495 {
2195ab96 1496 myMainPM->Display (anObj, theMode);
8e5fb5ea 1497 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (anObj))
c3282ec1 1498 {
1499 myMainPM->BeginImmediateDraw();
8e5fb5ea 1500 unhighlightGlobal (anObj, myDisplayMode);
c3282ec1 1501 myMainPM->EndImmediateDraw (myMainVwr);
1502 }
2195ab96 1503 if (aStatus->IsSubIntensityOn())
7fd59977 1504 {
8e5fb5ea 1505 highlightWithSubintensity (anObj, theMode);
7fd59977 1506 }
a1954302 1507 myMainPM->SetVisibility (anObj, myDisplayMode, Standard_False);
2195ab96 1508 }
1509 }
1510
1511 myDisplayMode = theMode;
1512 if (theToUpdateViewer)
1513 {
1514 myMainVwr->Update();
1515 }
7fd59977 1516}
1517
1518//=======================================================================
1519//function : SetDisplayMode
2195ab96 1520//purpose :
7fd59977 1521//=======================================================================
2195ab96 1522void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1523 const Standard_Integer theMode,
1524 const Standard_Boolean theToUpdateViewer)
7fd59977 1525{
2195ab96 1526 if (!theIObj->HasInteractiveContext())
1527 {
1528 theIObj->SetContext(this);
1529 }
7fd59977 1530
2195ab96 1531 if (!myObjects.IsBound (theIObj))
1532 {
1533 theIObj->SetDisplayMode (theMode);
1534 return;
1535 }
1536 else if (!theIObj->AcceptDisplayMode (theMode))
1537 {
1538 return;
1539 }
eb4320f2 1540
2195ab96 1541 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1542 if (aStatus->GraphicStatus() != AIS_DS_Displayed)
1543 {
1544 theIObj->SetDisplayMode (theMode);
1545 return;
1546 }
a6964ce6 1547
2195ab96 1548 // erase presentations for all display modes different from <aMode>
3db69e41 1549 const Standard_Integer anOldMode = aStatus->DisplayMode();
1550 if (anOldMode != theMode)
2195ab96 1551 {
3db69e41 1552 if (myMainPM->IsHighlighted (theIObj, anOldMode))
2195ab96 1553 {
8e5fb5ea 1554 unhighlightGlobal (theIObj, anOldMode);
7fd59977 1555 }
3db69e41 1556 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
7fd59977 1557 }
2195ab96 1558
3db69e41 1559 aStatus->SetDisplayMode (theMode);
2195ab96 1560
1561 myMainPM->Display (theIObj, theMode);
1562 Standard_Integer aDispMode, aHiMode, aSelMode;
1563 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1564 if (aStatus->IsHilighted())
1565 {
8e5fb5ea 1566 highlightGlobal (theIObj, getSelStyle (theIObj), aHiMode);
2195ab96 1567 }
1568 if (aStatus->IsSubIntensityOn())
1569 {
8e5fb5ea 1570 highlightWithSubintensity (theIObj, theMode);
2195ab96 1571 }
1572
1573 if (theToUpdateViewer)
1574 {
1575 myMainVwr->Update();
1576 }
1577 theIObj->SetDisplayMode (theMode);
7fd59977 1578}
1579
1580//=======================================================================
1581//function : UnsetDisplayMode
2195ab96 1582//purpose :
7fd59977 1583//=======================================================================
2195ab96 1584void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1585 const Standard_Boolean theToUpdateViewer)
7fd59977 1586{
2195ab96 1587 if (theIObj.IsNull()
1588 || !theIObj->HasDisplayMode())
1589 {
1590 return;
1591 }
1592
1593 if (!myObjects.IsBound (theIObj))
1594 {
1595 theIObj->UnsetDisplayMode();
1596 return;
1597 }
1598
1599 const Standard_Integer anOldMode = theIObj->DisplayMode();
1600 if (myDisplayMode == anOldMode)
1601 {
1602 return;
1603 }
1604
1605 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
3db69e41 1606 aStatus->SetDisplayMode (myDisplayMode);
2195ab96 1607
1608 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1609 {
1610 if (myMainPM->IsHighlighted (theIObj, anOldMode))
7fd59977 1611 {
8e5fb5ea 1612 unhighlightGlobal (theIObj, anOldMode);
2195ab96 1613 }
1614 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1615 myMainPM->Display (theIObj, myDisplayMode);
1616
1617 Standard_Integer aDispMode, aHiMode, aSelMode;
1618 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1619 if (aStatus->IsHilighted())
1620 {
8e5fb5ea 1621 highlightSelected (theIObj->GlobalSelOwner());
2195ab96 1622 }
1623 if (aStatus->IsSubIntensityOn())
1624 {
8e5fb5ea 1625 highlightWithSubintensity (theIObj, myDisplayMode);
7fd59977 1626 }
2195ab96 1627
1628 if (theToUpdateViewer)
1629 {
1630 myMainVwr->Update();
1631 }
1632 }
1633
1634 theIObj->UnsetDisplayMode();
7fd59977 1635}
1636
1637//=======================================================================
1638//function : SetCurrentFacingModel
2195ab96 1639//purpose :
7fd59977 1640//=======================================================================
2195ab96 1641void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1642 const Aspect_TypeOfFacingModel theModel)
b8ddfc2f 1643{
2195ab96 1644 if (!theIObj.IsNull())
1645 {
1646 theIObj->SetCurrentFacingModel (theModel);
1647 }
7fd59977 1648}
7fd59977 1649
1650//=======================================================================
2195ab96 1651//function : redisplayPrsRecModes
1652//purpose :
7fd59977 1653//=======================================================================
2195ab96 1654void AIS_InteractiveContext::redisplayPrsRecModes (const Handle(AIS_InteractiveObject)& theIObj,
1655 const Standard_Boolean theToUpdateViewer)
7fd59977 1656{
2195ab96 1657 if (theIObj->RecomputeEveryPrs())
1658 {
36132a2e 1659 theIObj->Update (Standard_True);
1660 theIObj->UpdateSelection();
2195ab96 1661 }
1662 else
1663 {
1664 for (TColStd_ListIteratorOfListOfInteger aModes (theIObj->ListOfRecomputeModes()); aModes.More(); aModes.Next())
1665 {
1666 theIObj->Update (aModes.Value(), Standard_False);
1667 }
28ee613b 1668 theIObj->UpdateSelection();
2195ab96 1669 theIObj->SetRecomputeOk();
1670 }
1671
1672 if (theToUpdateViewer)
1673 {
1674 UpdateCurrentViewer();
1675 }
7fd59977 1676}
1677
2195ab96 1678//=======================================================================
1679//function : redisplayPrsModes
1680//purpose :
1681//=======================================================================
1682void AIS_InteractiveContext::redisplayPrsModes (const Handle(AIS_InteractiveObject)& theIObj,
1683 const Standard_Boolean theToUpdateViewer)
7fd59977 1684{
2195ab96 1685 if (theIObj->RecomputeEveryPrs())
1686 {
36132a2e 1687 theIObj->Update (Standard_True);
1688 theIObj->UpdateSelection();
2195ab96 1689 }
7fd59977 1690 else
2195ab96 1691 {
1692 TColStd_ListOfInteger aModes;
1693 theIObj->ToBeUpdated (aModes);
1694 for (TColStd_ListIteratorOfListOfInteger aModeIter (aModes); aModeIter.More(); aModeIter.Next())
7fd59977 1695 {
2195ab96 1696 theIObj->Update (aModeIter.Value(), Standard_False);
7fd59977 1697 }
2195ab96 1698 theIObj->SetRecomputeOk();
1699 }
7fd59977 1700
2195ab96 1701 if (theToUpdateViewer)
1702 {
1703 UpdateCurrentViewer();
1704 }
7fd59977 1705}
1706
1707//=======================================================================
2195ab96 1708//function : SetColor
1709//purpose :
7fd59977 1710//=======================================================================
2195ab96 1711void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1712 const Quantity_NameOfColor theColor,
1713 const Standard_Boolean theToUpdateViewer)
1714{
1715 SetColor (theIObj, Quantity_Color(theColor), theToUpdateViewer);
1716}
7fd59977 1717
2195ab96 1718//=======================================================================
1719//function : SetColor
1720//purpose :
1721//=======================================================================
1722void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1723 const Quantity_Color& theColor,
1724 const Standard_Boolean theToUpdateViewer)
7fd59977 1725{
2195ab96 1726 if (theIObj.IsNull())
1727 {
1728 return;
1729 }
7fd59977 1730
2195ab96 1731 if (!theIObj->HasInteractiveContext())
1732 {
1733 theIObj->SetContext (this);
1734 }
1735 theIObj->SetColor (theColor);
1736 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1737}
7fd59977 1738
2195ab96 1739//=======================================================================
5ad8c033 1740//function : SetIsoOnTriangulation
1741//purpose :
1742//=======================================================================
1743void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1744 const Handle(AIS_InteractiveObject)& theObject)
1745{
1746 if (theObject.IsNull())
1747 {
1748 return;
1749 }
1750
1751 theObject->SetIsoOnTriangulation (theIsEnabled);
1752}
1753
1754//=======================================================================
2195ab96 1755//function : SetDeviationCoefficient
1756//purpose :
1757//=======================================================================
1758void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1759 const Standard_Real theCoefficient,
1760 const Standard_Boolean theToUpdateViewer)
1761{
1762 if (theIObj.IsNull())
1763 {
1764 return;
1765 }
7fd59977 1766
2195ab96 1767 if (!theIObj->HasInteractiveContext())
1768 {
1769 theIObj->SetContext (this);
1770 }
7fd59977 1771
2195ab96 1772 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1773 if (theIObj->Type() != AIS_KOI_Object
1774 && theIObj->Type() != AIS_KOI_Shape)
1775 {
1776 return;
1777 }
1778 else if (theIObj->Signature() != 0)
1779 {
1780 return;
1781 }
1782
1783 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1784 aShape->SetOwnDeviationCoefficient (theCoefficient);
1785 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1786}
1787
1788//=======================================================================
1789//function : SetHLRDeviationCoefficient
2195ab96 1790//purpose :
7fd59977 1791//=======================================================================
2195ab96 1792void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1793 const Standard_Real theCoefficient,
1794 const Standard_Boolean theToUpdateViewer)
7fd59977 1795{
2195ab96 1796 if (theIObj.IsNull())
1797 {
1798 return;
1799 }
1800
1801 if (!theIObj->HasInteractiveContext())
1802 {
1803 theIObj->SetContext (this);
1804 }
7fd59977 1805
81bba717 1806 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2195ab96 1807 if (theIObj->Type() != AIS_KOI_Object
1808 && theIObj->Type() != AIS_KOI_Shape)
1809 {
1810 return;
1811 }
1812 else if (theIObj->Signature() != 0)
1813 {
1814 return;
1815 }
7fd59977 1816
2195ab96 1817 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1818 aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1819 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1820}
1821
7fd59977 1822//=======================================================================
1823//function : SetDeviationAngle
2195ab96 1824//purpose :
7fd59977 1825//=======================================================================
2195ab96 1826void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1827 const Standard_Real theAngle,
1828 const Standard_Boolean theToUpdateViewer)
7fd59977 1829{
2195ab96 1830 if (theIObj.IsNull())
1831 {
1832 return;
1833 }
1834
1835 if (!theIObj->HasInteractiveContext())
1836 {
1837 theIObj->SetContext (this);
1838 }
7fd59977 1839
e33e7e78 1840 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2195ab96 1841 if (theIObj->Type() != AIS_KOI_Shape)
1842 {
1843 return;
1844 }
1845 else if (theIObj->Signature() != 0)
1846 {
1847 return;
1848 }
7fd59977 1849
2195ab96 1850 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1851 aShape->SetOwnDeviationAngle (theAngle);
1852 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1853}
2195ab96 1854
7fd59977 1855//=======================================================================
2195ab96 1856//function : SetAngleAndDeviation
1857//purpose :
7fd59977 1858//=======================================================================
2195ab96 1859void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1860 const Standard_Real theAngle,
1861 const Standard_Boolean theToUpdateViewer)
7fd59977 1862{
2195ab96 1863 if (theIObj.IsNull())
1864 {
1865 return;
1866 }
1867
1868 if (!theIObj->HasInteractiveContext())
1869 {
1870 theIObj->SetContext (this);
1871 }
7fd59977 1872
e33e7e78 1873 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2195ab96 1874 if (theIObj->Type() != AIS_KOI_Shape)
1875 {
1876 return;
1877 }
1878 if (theIObj->Signature() != 0)
1879 {
1880 return;
1881 }
7fd59977 1882
2195ab96 1883 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1884 aShape->SetAngleAndDeviation (theAngle);
7fd59977 1885
2195ab96 1886 if (theIObj->RecomputeEveryPrs())
1887 {
36132a2e 1888 theIObj->Update (Standard_True);
1889 theIObj->UpdateSelection();
2195ab96 1890 }
7fd59977 1891 else
2195ab96 1892 {
1893 Update (theIObj, theToUpdateViewer);
1894 }
7fd59977 1895}
1896
1897//=======================================================================
2195ab96 1898//function : SetHLRAngleAndDeviation
1899//purpose :
7fd59977 1900//=======================================================================
2195ab96 1901void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1902 const Standard_Real theAngle,
1903 const Standard_Boolean theToUpdateViewer)
7fd59977 1904{
2195ab96 1905 if (theIObj.IsNull())
1906 {
1907 return;
1908 }
7fd59977 1909
2195ab96 1910 if (!theIObj->HasInteractiveContext())
1911 {
1912 theIObj->SetContext (this);
1913 }
7fd59977 1914
e33e7e78 1915 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2195ab96 1916 if (theIObj->Type() != AIS_KOI_Shape)
1917 {
1918 return;
1919 }
1920 if (theIObj->Signature() != 0)
1921 {
1922 return;
1923 }
1924 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1925 aShape->SetHLRAngleAndDeviation (theAngle);
1926 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1927}
1928
1929//=======================================================================
1930//function : SetHLRDeviationAngle
2195ab96 1931//purpose :
7fd59977 1932//=======================================================================
2195ab96 1933void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1934 const Standard_Real theAngle,
1935 const Standard_Boolean theToUpdateViewer)
7fd59977 1936{
2195ab96 1937 if (theIObj.IsNull())
1938 {
1939 return;
1940 }
7fd59977 1941
2195ab96 1942 if (!theIObj->HasInteractiveContext())
1943 {
1944 theIObj->SetContext (this);
1945 }
7fd59977 1946
2195ab96 1947 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1948 if (theIObj->Type() != AIS_KOI_Shape)
1949 {
1950 return;
1951 }
1952 if (theIObj->Signature() != 0)
1953 {
1954 return;
1955 }
1956 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1957 aShape->SetOwnHLRDeviationAngle (theAngle);
1958 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1959}
1960
1961//=======================================================================
1962//function : UnsetColor
2195ab96 1963//purpose :
7fd59977 1964//=======================================================================
2195ab96 1965void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
1966 const Standard_Boolean theToUpdateViewer)
7fd59977 1967{
2195ab96 1968 if (theIObj.IsNull())
1969 {
1970 return;
1971 }
1972
1973 theIObj->UnsetColor();
1974 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 1975}
1976
1977//=======================================================================
1978//function : HasColor
2195ab96 1979//purpose :
7fd59977 1980//=======================================================================
2195ab96 1981Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 1982{
2195ab96 1983 return theIObj->HasColor();
7fd59977 1984}
1985
1986//=======================================================================
1987//function : Color
2195ab96 1988//purpose :
7fd59977 1989//=======================================================================
2195ab96 1990Quantity_NameOfColor AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 1991{
2195ab96 1992 return theIObj->Color();
7fd59977 1993}
1994
2195ab96 1995//=======================================================================
1996//function : Color
1997//purpose :
1998//=======================================================================
1999void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
2000 Quantity_Color& theColor) const
7fd59977 2001{
2195ab96 2002 theIObj->Color (theColor);
7fd59977 2003}
7fd59977 2004
2005//=======================================================================
2006//function : Width
2195ab96 2007//purpose :
7fd59977 2008//=======================================================================
2195ab96 2009Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 2010{
2195ab96 2011 return theIObj->Width();
7fd59977 2012}
2013
2014//=======================================================================
2015//function : SetWidth
2195ab96 2016//purpose :
7fd59977 2017//=======================================================================
2195ab96 2018void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2019 const Standard_Real theWidth,
2020 const Standard_Boolean theToUpdateViewer)
7fd59977 2021{
2195ab96 2022 if (theIObj.IsNull())
2023 {
2024 return;
2025 }
2026
2027 if (!theIObj->HasInteractiveContext())
2028 {
2029 theIObj->SetContext (this);
2030 }
2031
2032 theIObj->SetWidth (theWidth);
2033 redisplayPrsRecModes (theIObj, theToUpdateViewer);
8e5fb5ea 2034 if (!myLastinMain.IsNull() && myLastinMain->IsSameSelectable (theIObj))
c3282ec1 2035 {
2036 if (myLastinMain->IsAutoHilight())
2037 {
2038 const Standard_Integer aHiMode =
2039 theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
8e5fb5ea 2040 myLastinMain->HilightWithColor (myMainPM,
2041 myLastinMain->IsSelected() ? getSelStyle (theIObj) : getHiStyle (theIObj),
2042 aHiMode);
c3282ec1 2043 }
2044 else
2045 {
8e5fb5ea 2046 theIObj->HilightOwnerWithColor (myMainPM,
2047 myLastinMain->IsSelected() ? getSelStyle (theIObj) : getHiStyle (theIObj),
2048 myLastinMain);
c3282ec1 2049 }
2050 }
7fd59977 2051}
2052
2053//=======================================================================
2054//function : UnsetWidth
2195ab96 2055//purpose :
7fd59977 2056//=======================================================================
2195ab96 2057void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2058 const Standard_Boolean theToUpdateViewer)
7fd59977 2059{
2195ab96 2060 if (theIObj.IsNull())
2061 {
2062 return;
2063 }
2064
2065 theIObj->UnsetWidth();
2066 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2067}
2068
2069//=======================================================================
2070//function : SetMaterial
2195ab96 2071//purpose :
7fd59977 2072//=======================================================================
2195ab96 2073void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2074 const Graphic3d_NameOfMaterial theName,
2075 const Standard_Boolean theToUpdateViewer)
7fd59977 2076{
2195ab96 2077 if (theIObj.IsNull())
2078 {
2079 return;
2080 }
2081
2082 if (!theIObj->HasInteractiveContext())
2083 {
2084 theIObj->SetContext (this);
2085 }
7fd59977 2086
2195ab96 2087 theIObj->SetMaterial (theName);
2088 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2089}
2090
2091//=======================================================================
2092//function : UnsetMaterial
2195ab96 2093//purpose :
7fd59977 2094//=======================================================================
2195ab96 2095void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2096 const Standard_Boolean theToUpdateViewer)
7fd59977 2097{
2195ab96 2098 if (theIObj.IsNull())
2099 {
2100 return;
2101 }
2102 theIObj->UnsetMaterial();
2103 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2104}
2105
2106//=======================================================================
2107//function : SetTransparency
2195ab96 2108//purpose :
7fd59977 2109//=======================================================================
2195ab96 2110void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2111 const Standard_Real theValue,
2112 const Standard_Boolean theToUpdateViewer)
7fd59977 2113{
2195ab96 2114 if (theIObj.IsNull())
2115 {
2116 return;
2117 }
2118
2119 if (!theIObj->HasInteractiveContext())
2120 {
2121 theIObj->SetContext (this);
2122 }
7fd59977 2123
2195ab96 2124 if (!theIObj->IsTransparent()
2125 && theValue <= 0.05)
a6964ce6 2126 {
2127 return;
2128 }
2129
2195ab96 2130 if (theValue <= 0.05)
2131 {
2132 UnsetTransparency (theIObj, theToUpdateViewer);
7fd59977 2133 return;
2134 }
a6964ce6 2135
2195ab96 2136 theIObj->SetTransparency (theValue);
2137 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2138}
2139
2140//=======================================================================
2141//function : UnsetTransparency
2195ab96 2142//purpose :
7fd59977 2143//=======================================================================
2195ab96 2144void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2145 const Standard_Boolean theToUpdateViewer)
7fd59977 2146{
2195ab96 2147 if (theIObj.IsNull())
2148 {
2149 return;
2150 }
7fd59977 2151
2195ab96 2152 theIObj->UnsetTransparency();
2153 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2154}
2155
2195ab96 2156//=======================================================================
2157//function : SetSelectedAspect
2158//purpose :
2159//=======================================================================
2160void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
2831708b 2161 const Standard_Boolean ,
2195ab96 2162 const Standard_Boolean theToUpdateViewer)
2163{
2164 if (HasOpenedContext())
2165 {
2166 return;
2167 }
2168
2169 Standard_Boolean isFound = Standard_False;
02974a19 2170 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2195ab96 2171 {
2172 isFound = Standard_True;
02974a19 2173 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
2831708b 2174 anObj->SetAspect (theAspect);
2195ab96 2175 }
2176
016e5959 2177 if (isFound && theToUpdateViewer)
2195ab96 2178 {
2179 myMainVwr->Update();
7fd59977 2180 }
2181}
7fd59977 2182
2183//=======================================================================
2184//function : SetLocalAttributes
2195ab96 2185//purpose :
7fd59977 2186//=======================================================================
2195ab96 2187void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
6262338c 2188 const Handle(Prs3d_Drawer)& theDrawer,
2195ab96 2189 const Standard_Boolean theToUpdateViewer)
7fd59977 2190{
2195ab96 2191 if (theIObj.IsNull())
2192 {
2193 return;
2194 }
2195
2196 if (!theIObj->HasInteractiveContext())
2197 {
2198 theIObj->SetContext (this);
2199 }
2200
2201 theIObj->SetAttributes (theDrawer);
2202 Update (theIObj, theToUpdateViewer);
7fd59977 2203}
2204
2205//=======================================================================
2206//function : UnsetLocalAttributes
2195ab96 2207//purpose :
7fd59977 2208//=======================================================================
2195ab96 2209void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2210 const Standard_Boolean theToUpdateViewer)
7fd59977 2211{
2195ab96 2212 if (theIObj.IsNull())
2213 {
2214 return;
2215 }
7fd59977 2216
2195ab96 2217 if (!theIObj->HasInteractiveContext())
2218 {
2219 theIObj->SetContext (this);
2220 }
2221 theIObj->UnsetAttributes();
2222 Update (theIObj, theToUpdateViewer);
2223}
7fd59977 2224
2225//=======================================================================
2226//function : Status
2195ab96 2227//purpose :
7fd59977 2228//=======================================================================
2195ab96 2229void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
2230 TCollection_ExtendedString& theStatus) const
7fd59977 2231{
2195ab96 2232 theStatus = "";
2233 if (theIObj.IsNull()
2234 || !myObjects.IsBound (theIObj))
2235 {
2236 return;
2237 }
7fd59977 2238
2195ab96 2239 theStatus += "\t ____________________________________________";
2240 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
2241 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2242 switch (aStatus->GraphicStatus())
2243 {
7fd59977 2244 case AIS_DS_Displayed:
2195ab96 2245 {
2246 theStatus += "\t| -->Displayed\n";
7fd59977 2247 break;
2248 }
2195ab96 2249 case AIS_DS_Erased:
2250 {
2251 theStatus += "\t| -->Erased\n";
2252 break;
7fd59977 2253 }
2195ab96 2254 default:
2255 break;
2256 }
2257
2258 theStatus += "\t| Active Display Modes in the MainViewer :\n";
3db69e41 2259 theStatus += "\t|\t Mode ";
2260 theStatus += TCollection_AsciiString (aStatus->DisplayMode());
2261 theStatus += "\n";
2262
2195ab96 2263 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
7fd59977 2264
2195ab96 2265 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
2266 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2267 {
2268 theStatus += "\t\t Mode ";
2269 theStatus += TCollection_AsciiString (aSelModeIter.Value());
2270 theStatus += "\n";
2271 }
2272 theStatus += "\t ____________________________________________";
2273}
7fd59977 2274
2275//=======================================================================
2276//function : GetDefModes
2195ab96 2277//purpose :
7fd59977 2278//=======================================================================
2195ab96 2279void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
2280 Standard_Integer& theDispMode,
2281 Standard_Integer& theHiMode,
2282 Standard_Integer& theSelMode) const
7fd59977 2283{
2195ab96 2284 if (theIObj.IsNull())
2285 {
2286 return;
2287 }
7fd59977 2288
2195ab96 2289 theDispMode = theIObj->HasDisplayMode()
2290 ? theIObj->DisplayMode()
2291 : (theIObj->AcceptDisplayMode (myDisplayMode)
2292 ? myDisplayMode
2293 : 0);
2294 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
c3282ec1 2295 theSelMode = theIObj->GlobalSelectionMode();
2195ab96 2296}
7fd59977 2297
2298//=======================================================================
2299//function : EraseGlobal
2195ab96 2300//purpose :
7fd59977 2301//=======================================================================
2195ab96 2302void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2303 const Standard_Boolean theToUpdateviewer)
7fd59977 2304{
2195ab96 2305 if (theIObj.IsNull()
2306 || !myObjects.IsBound (theIObj))
2307 {
2308 return;
2309 }
7fd59977 2310
2195ab96 2311 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2312
a1954302 2313 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2314 if (aStatus->GraphicStatus() == AIS_DS_Temporary
2315 || aStatus->GraphicStatus() == AIS_DS_Erased)
2195ab96 2316 {
a1954302 2317 return;
2318 }
2195ab96 2319
3db69e41 2320 if (aStatus->IsHilighted())
a1954302 2321 {
3db69e41 2322 if (IsCurrent (theIObj))
2195ab96 2323 {
3db69e41 2324 AddOrRemoveCurrentObject (theIObj, Standard_False);
2325 }
2326 else if (myMainPM->IsHighlighted (theIObj, aStatus->DisplayMode()))
2327 {
8e5fb5ea 2328 unhighlightGlobal (theIObj, aStatus->DisplayMode());
2195ab96 2329 }
a1954302 2330 }
2195ab96 2331
3db69e41 2332 myMainPM->SetVisibility (theIObj, aStatus->DisplayMode(), Standard_False);
2333
4f51d9d7 2334 if (aStatus->IsHilighted()
2335 && theIObj->HasHilightMode())
2336 {
8e5fb5ea 2337 unhighlightGlobal (theIObj, aDispMode);
4f51d9d7 2338 }
2339
2340 if (!myLastPicked.IsNull()
8e5fb5ea 2341 && myLastPicked->IsSameSelectable (theIObj))
4f51d9d7 2342 {
2343 myMainPM->ClearImmediateDraw();
2344 }
2345
c3282ec1 2346 if (IsSelected (theIObj)
3db69e41 2347 && aStatus->DisplayMode() != aDispMode)
a1954302 2348 {
2349 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
2350 }
2351
2352 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2353 {
2354 mgrSelector->Deactivate (theIObj, aSelModeIter.Value(), myMainSel);
7fd59977 2355 }
c3282ec1 2356 aStatus->ClearSelectionModes();
2195ab96 2357 aStatus->SetGraphicStatus (AIS_DS_Erased);
a1954302 2358
2359 if (theToUpdateviewer)
2360 {
2361 myMainVwr->Update();
2362 }
7fd59977 2363}
2364
2365//=======================================================================
c3282ec1 2366//function : unhighlightOwners
2367//purpose :
2368//=======================================================================
2369void AIS_InteractiveContext::unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject)
2370{
02974a19 2371 SelectMgr_SequenceOfOwner aSeq;
2372 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
c3282ec1 2373 {
8e5fb5ea 2374 if (aSelIter.Value()->IsSameSelectable (theObject)
02974a19 2375 && aSelIter.Value()->IsSelected())
c3282ec1 2376 {
02974a19 2377 aSeq.Append (aSelIter.Value());
c3282ec1 2378 }
02974a19 2379 }
2380 for (SelectMgr_SequenceOfOwner::Iterator aDelIter (aSeq); aDelIter.More(); aDelIter.Next())
2381 {
2382 AddOrRemoveSelected (aDelIter.Value(), Standard_False);
c3282ec1 2383 }
2384}
2385
2386//=======================================================================
7fd59977 2387//function : ClearGlobal
2195ab96 2388//purpose :
7fd59977 2389//=======================================================================
2195ab96 2390void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2391 const Standard_Boolean theToUpdateviewer)
7fd59977 2392{
2195ab96 2393 if (theIObj.IsNull()
2394 || !myObjects.IsBound (theIObj))
2395 {
f751596e 2396 // for cases when reference shape of connected interactives was not displayed
2397 // but its selection primitives were calculated
543a9964 2398 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2399 mgrSelector->Remove (anObj);
2195ab96 2400 return;
2401 }
2402
2403 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
c3282ec1 2404 unhighlightOwners (theIObj);
7fd59977 2405
e2d7642f 2406 myMainPM->Erase (theIObj, -1);
4f51d9d7 2407
2195ab96 2408 // Object removes from Detected sequence
2409 for(Standard_Integer aDetIter = 1; aDetIter < myAISDetectedSeq.Length(); ++aDetIter)
7fd59977 2410 {
2411 Handle(AIS_InteractiveObject) anObj = DetectedCurrentObject();
2195ab96 2412 if (!anObj.IsNull()
2413 && anObj != theIObj)
2414 {
2415 myAISDetectedSeq.Remove (aDetIter);
2416 }
7fd59977 2417 }
2418
2195ab96 2419 // remove IO from the selection manager to avoid memory leaks
543a9964 2420 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2421 mgrSelector->Remove (anObj);
7fd59977 2422
2195ab96 2423 myObjects.UnBind (theIObj);
c357e426 2424 myMainVwr->StructureManager()->UnregisterObject (theIObj);
6a24c6de 2425
2426 for (V3d_ListOfViewIterator aDefViewIter (myMainVwr->DefinedViewIterator()); aDefViewIter.More(); aDefViewIter.Next())
a272ed94 2427 {
6a24c6de 2428 aDefViewIter.Value()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
a272ed94 2429 }
7fd59977 2430
8e5fb5ea 2431 if (!myLastinMain.IsNull() && myLastinMain->IsSameSelectable (theIObj))
c3282ec1 2432 myLastinMain.Nullify();
8e5fb5ea 2433 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
c3282ec1 2434 myLastPicked.Nullify();
2435 myMainPM->ClearImmediateDraw();
2436
2437 if (theToUpdateviewer && aStatus->GraphicStatus() == AIS_DS_Displayed)
eb4320f2 2438 {
2439 myMainVwr->Update();
2440 }
7fd59977 2441}
2442
2443//=======================================================================
2444//function : ClearGlobalPrs
2195ab96 2445//purpose :
7fd59977 2446//=======================================================================
2195ab96 2447void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2448 const Standard_Integer theMode,
2449 const Standard_Boolean theToUpdateViewer)
7fd59977 2450{
2195ab96 2451 if (theIObj.IsNull()
2452 || !myObjects.IsBound (theIObj))
2453 {
2454 return;
2455 }
2456
2457 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
3db69e41 2458 if (aStatus->DisplayMode() == theMode)
2195ab96 2459 {
2460 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2461 if (aDispMode == theMode
2462 && myMainPM->IsHighlighted (theIObj, theMode))
2463 {
8e5fb5ea 2464 unhighlightGlobal (theIObj, theMode);
2195ab96 2465 }
2466
2467 myMainPM->Erase (theIObj, theMode);
7fd59977 2468 }
eb4320f2 2469
2195ab96 2470 if (aStatus->GraphicStatus() == AIS_DS_Displayed
2471 && theToUpdateViewer)
2472 {
7fd59977 2473 myMainVwr->Update();
2195ab96 2474 }
7fd59977 2475}
2476
2477//=======================================================================
2478//function : DrawHiddenLine
2195ab96 2479//purpose :
7fd59977 2480//=======================================================================
2195ab96 2481Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2482{
7fd59977 2483 return myDefaultDrawer->DrawHiddenLine();
2484}
2485
2486//=======================================================================
2487//function : EnableDrawHiddenLine
2195ab96 2488//purpose :
7fd59977 2489//=======================================================================
2195ab96 2490void AIS_InteractiveContext::EnableDrawHiddenLine() const
2491{
7fd59977 2492 myDefaultDrawer->EnableDrawHiddenLine();
2493}
2494
2495//=======================================================================
2496//function : DisableDrawHiddenLine
2195ab96 2497//purpose :
7fd59977 2498//=======================================================================
2195ab96 2499void AIS_InteractiveContext::DisableDrawHiddenLine() const
2500{
7fd59977 2501 myDefaultDrawer->DisableDrawHiddenLine();
2502}
2503
2504//=======================================================================
2505//function : HiddenLineAspect
2195ab96 2506//purpose :
7fd59977 2507//=======================================================================
2195ab96 2508Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2509{
7fd59977 2510 return myDefaultDrawer->HiddenLineAspect();
2511}
2512
2513//=======================================================================
2514//function : SetHiddenLineAspect
2195ab96 2515//purpose :
7fd59977 2516//=======================================================================
2195ab96 2517void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2518{
2519 myDefaultDrawer->SetHiddenLineAspect (theAspect);
7fd59977 2520}
2521
2522//=======================================================================
2523//function : SetIsoNumber
2195ab96 2524//purpose :
7fd59977 2525//=======================================================================
2195ab96 2526void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2527 const AIS_TypeOfIso theType)
7fd59977 2528{
2195ab96 2529 switch (theType)
2530 {
2531 case AIS_TOI_IsoU:
2532 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2533 break;
2534 case AIS_TOI_IsoV:
2535 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2536 break;
2537 case AIS_TOI_Both:
2538 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2539 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2540 break;
7fd59977 2541 }
2542}
2195ab96 2543
7fd59977 2544//=======================================================================
2545//function : IsoNumber
2195ab96 2546//purpose :
7fd59977 2547//=======================================================================
2195ab96 2548Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
7fd59977 2549{
2195ab96 2550 switch (theType)
2551 {
2552 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2553 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2554 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2555 ? myDefaultDrawer->UIsoAspect()->Number()
2556 : -1;
7fd59977 2557 }
2558 return 0;
2559}
2560
2561//=======================================================================
2562//function : IsoOnPlane
2195ab96 2563//purpose :
7fd59977 2564//=======================================================================
2195ab96 2565void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
7fd59977 2566{
2195ab96 2567 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
7fd59977 2568}
2569
2570//=======================================================================
2571//function : IsoOnPlane
2195ab96 2572//purpose :
7fd59977 2573//=======================================================================
2195ab96 2574Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
7fd59977 2575{
2576 return myDefaultDrawer->IsoOnPlane();
2577}
2578
2579//=======================================================================
5ad8c033 2580//function : IsoOnTriangulation
2581//purpose :
2582//=======================================================================
2583void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theToSwitchOn)
2584{
2585 myDefaultDrawer->SetIsoOnTriangulation (theToSwitchOn);
2586}
2587
2588//=======================================================================
2589//function : IsoOnTriangulation
2590//purpose :
2591//=======================================================================
2592Standard_Boolean AIS_InteractiveContext::IsoOnTriangulation() const
2593{
2594 return myDefaultDrawer->IsoOnTriangulation();
2595}
2596
3c982548 2597//function : SetPixelTolerance
28ee613b 2598//purpose : Disables the mechanism of adaptive tolerance calculation in
2599// SelectMgr_ViewerSelector and sets the given tolerance for ALL
2600// sensitive entities activated. For more information, see
2601// SelectMgr_ViewerSelector.hxx
3c982548 2602//=======================================================================
3bf9a45f 2603void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2195ab96 2604{
2605 if (HasOpenedContext())
2606 {
2607 myLocalContexts (myCurLocalIndex)->SetPixelTolerance (thePrecision);
2608 }
2609 else
2610 {
2611 myMainSel->SetPixelTolerance (thePrecision);
7fd59977 2612 }
2613}
3c982548 2614
2615//=======================================================================
2616//function : PixelTolerance
2195ab96 2617//purpose :
3c982548 2618//=======================================================================
3bf9a45f 2619Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2195ab96 2620{
2621 return HasOpenedContext()
2622 ? myLocalContexts (myCurLocalIndex)->PixelTolerance()
2623 : myMainSel->PixelTolerance();
3c982548 2624}
7fd59977 2625
2626//=======================================================================
8a1170ad 2627//function : SetSelectionSensitivity
2628//purpose : Allows to manage sensitivity of a particular selection of interactive object theObject
2629//=======================================================================
2630void AIS_InteractiveContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
2631 const Standard_Integer theMode,
2632 const Standard_Integer theNewSensitivity)
2633{
2634 if (HasOpenedContext())
2635 {
2636 myLocalContexts (myCurLocalIndex)->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2637 return;
2638 }
2639
2640 mgrSelector->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2641}
2642
2643//=======================================================================
7fd59977 2644//function : IsInLocal
2195ab96 2645//purpose :
7fd59977 2646//=======================================================================
2195ab96 2647Standard_Boolean AIS_InteractiveContext::IsInLocal (const Handle(AIS_InteractiveObject)& theIObj,
2648 Standard_Integer& theIndex) const
7fd59977 2649{
2195ab96 2650 if (theIObj.IsNull())
2651 {
2652 return Standard_False;
2653 }
2654
81bba717 2655 // if it exists at neutral point 0 index is returned
2195ab96 2656 if (myObjects.IsBound (theIObj))
2657 {
2658 theIndex = 0;
7fd59977 2659 return Standard_False;
2660 }
2195ab96 2661
2662 for (Standard_Integer aCtxIter = 1; aCtxIter <= myLocalContexts.Extent(); ++aCtxIter)
2663 {
2664 if (myLocalContexts.IsBound (aCtxIter))
2665 {
2666 if(myLocalContexts (aCtxIter)->IsIn (theIObj))
2667 {
2668 theIndex = aCtxIter;
7fd59977 2669 return Standard_True;
7fd59977 2670 }
2671 }
2672 }
2195ab96 2673 theIndex = -1;
7fd59977 2674 return Standard_False;
2195ab96 2675}
2676
7fd59977 2677//=======================================================================
2678//function : InitAttributes
2195ab96 2679//purpose :
7fd59977 2680//=======================================================================
7fd59977 2681void AIS_InteractiveContext::InitAttributes()
2682{
2195ab96 2683 mgrSelector->Add (myMainSel);
7fd59977 2684
2195ab96 2685 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2686 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
7fd59977 2687
2688// myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2195ab96 2689 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2690 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2691 aLineAspect->SetWidth (1.0);
2692 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
7fd59977 2693
28ee613b 2694 // tolerance to 2 pixels...
3bf9a45f 2695 SetPixelTolerance (2);
7fd59977 2696
2697 // Customizing the drawer for trihedrons and planes...
2195ab96 2698 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2699 const Standard_Real aLength = 100.0;
2700 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2701 const Quantity_NameOfColor aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2702 aTrihAspect->FirstAxisAspect() ->SetColor (aColor);
2703 aTrihAspect->SecondAxisAspect()->SetColor (aColor);
2704 aTrihAspect->ThirdAxisAspect() ->SetColor (aColor);
7fd59977 2705
2195ab96 2706 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2707 const Standard_Real aPlaneLength = 200.0;
2708 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2709 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
7fd59977 2710}
2711
7fd59977 2712//=======================================================================
2713//function : TrihedronSize
2195ab96 2714//purpose :
7fd59977 2715//=======================================================================
2716Standard_Real AIS_InteractiveContext::TrihedronSize() const
2717{
2718 return myDefaultDrawer->DatumAspect()->FirstAxisLength();
2719}
2195ab96 2720
7fd59977 2721//=======================================================================
2722//function : SetTrihedronSize
2195ab96 2723//purpose :
7fd59977 2724//=======================================================================
2195ab96 2725void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2726 const Standard_Boolean /*updateviewer*/)
7fd59977 2727{
2195ab96 2728 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2729 Redisplay (AIS_KOI_Datum, 3, Standard_False);
2730 Redisplay (AIS_KOI_Datum, 4, Standard_True);
7fd59977 2731}
2732
7fd59977 2733//=======================================================================
2734//function : SetPlaneSize
2195ab96 2735//purpose :
7fd59977 2736//=======================================================================
2195ab96 2737void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2738 const Standard_Real theValY,
7fd59977 2739 const Standard_Boolean /*updateviewer*/)
2740{
2195ab96 2741 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2742 Redisplay (AIS_KOI_Datum, 7);
7fd59977 2743}
2744
2745//=======================================================================
2746//function : SetPlaneSize
2195ab96 2747//purpose :
7fd59977 2748//=======================================================================
2195ab96 2749void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2750 const Standard_Boolean theToUpdateViewer)
7fd59977 2751{
2195ab96 2752 SetPlaneSize (theVal, theVal, theToUpdateViewer);
7fd59977 2753}
2754
2755//=======================================================================
2756//function : PlaneSize
2195ab96 2757//purpose :
7fd59977 2758//=======================================================================
2195ab96 2759Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2760 Standard_Real& theY) const
7fd59977 2761{
2195ab96 2762 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2763 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2764 return (Abs (theX - theY) <= Precision::Confusion());
7fd59977 2765}
2766
7fd59977 2767//=======================================================================
2195ab96 2768//function : SetAutoActivateSelection
2769//purpose :
7fd59977 2770//=======================================================================
2195ab96 2771void AIS_InteractiveContext::SetAutoActivateSelection (const Standard_Boolean theIsAuto)
7fd59977 2772{
2195ab96 2773 myIsAutoActivateSelMode = theIsAuto;
7fd59977 2774}
2775
2776//=======================================================================
2195ab96 2777//function : GetAutoActivateSelection
2778//purpose :
7fd59977 2779//=======================================================================
2780Standard_Boolean AIS_InteractiveContext::GetAutoActivateSelection() const
2781{
2782 return myIsAutoActivateSelMode;
2783}
59f45b7c 2784
2785//=======================================================================
2786//function : SetZLayer
2195ab96 2787//purpose :
59f45b7c 2788//=======================================================================
59f45b7c 2789void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2790 const Standard_Integer theLayerId)
2791{
2195ab96 2792 if (theIObj.IsNull())
59f45b7c 2793 return;
2794
a1954302 2795 theIObj->SetZLayer (theLayerId);
59f45b7c 2796}
2797
2798//=======================================================================
2799//function : GetZLayer
2195ab96 2800//purpose :
59f45b7c 2801//=======================================================================
59f45b7c 2802Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2803{
a1954302 2804 return !theIObj.IsNull()
2805 ? theIObj->ZLayer()
2806 : Graphic3d_ZLayerId_UNKNOWN;
59f45b7c 2807}
f751596e 2808
2809//=======================================================================
2810//function : RebuildSelectionStructs
2811//purpose : Rebuilds 1st level of BVH selection forcibly
2812//=======================================================================
2813void AIS_InteractiveContext::RebuildSelectionStructs()
2814{
2815 myMainSel->RebuildObjectsTree (Standard_True);
2816}
2817
2818//=======================================================================
2819//function : Disconnect
2820//purpose : Disconnects selectable object from an assembly and updates selection structures
2821//=======================================================================
2822void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2823 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2824{
2825 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2826 {
c5f3a425 2827 Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
f751596e 2828 theObj->Disconnect (theObjToDisconnect);
543a9964 2829 const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2830 mgrSelector->Remove (anObj);
f751596e 2831 }
c04c30b3 2832 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
f751596e 2833 {
c5f3a425 2834 Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
f751596e 2835 theObj->Disconnect();
543a9964 2836 const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2837 mgrSelector->Remove (anObj);
f751596e 2838 }
2839 else
2840 return;
2841}
b586500b 2842
2843//=======================================================================
2844//function : FitSelected
2845//purpose : Fits the view corresponding to the bounds of selected objects
2846//=======================================================================
2847void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2848 const Standard_Real theMargin,
2849 const Standard_Boolean theToUpdate)
2850{
016e5959 2851 const Handle(AIS_Selection)& aSelection = HasOpenedContext() ?
2852 myLocalContexts(myCurLocalIndex)->Selection() : mySelection;
b586500b 2853
2854 Bnd_Box aBndSelected;
2855
b586500b 2856 AIS_MapOfObjectOwners anObjectOwnerMap;
2857 for (aSelection->Init(); aSelection->More(); aSelection->Next())
2858 {
02974a19 2859 const Handle(SelectMgr_EntityOwner)& anOwner = aSelection->Value();
2860 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
2861 if (anObj->IsInfinite())
b586500b 2862 {
02974a19 2863 continue;
2864 }
b586500b 2865
02974a19 2866 if (anOwner == anObj->GlobalSelOwner())
2867 {
b586500b 2868 Bnd_Box aTmpBnd;
2869 anObj->BoundingBox (aTmpBnd);
2870 aBndSelected.Add (aTmpBnd);
2871 }
2872 else
2873 {
b586500b 2874 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2875 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2876 {
2877 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2878 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2879 }
2880
2881 anOwnerMap->Add (anOwner);
2882 }
2883 }
2884
2885 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2886 {
2887 const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2888 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2889 aBndSelected.Add (aTmpBox);
2890 }
2891
2892 anObjectOwnerMap.Clear();
2893
2894 if (aBndSelected.IsVoid())
2895 return;
2896
2897 theView->FitAll (aBndSelected, theMargin, theToUpdate);
2898}
1d92133e 2899
2900//=======================================================================
2901//function : SetTransformPersistence
2902//purpose :
2903//=======================================================================
2904void AIS_InteractiveContext::SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObject,
778cd667 2905 const Handle(Graphic3d_TransformPers)& theTrsfPers)
1d92133e 2906{
778cd667 2907 theObject->SetTransformPersistence (theTrsfPers);
1d92133e 2908 if (!myObjects.IsBound (theObject))
2909 {
2910 return;
2911 }
2912
2913 mgrSelector->UpdateSelection (theObject);
2914
2915 const Standard_Integer aLayerId = myObjects.Find (theObject)->GetLayerIndex();
2916 const Handle(V3d_Viewer)& aCurViewer = CurrentViewer();
6a24c6de 2917 for (V3d_ListOfViewIterator anActiveViewIter (aCurViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
1d92133e 2918 {
6a24c6de 2919 anActiveViewIter.Value()->View()->InvalidateBVHData (aLayerId);
2920 anActiveViewIter.Value()->View()->InvalidateZLayerBoundingBox (aLayerId);
1d92133e 2921 }
2922}