0027915: Foundation Classes - remove the class NCollection_QuickSort
[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
7fd59977 127//=======================================================================
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
7fd59977 196//=======================================================================
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
a272ed94 294//=======================================================================
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
7fd59977 323//=======================================================================
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
a272ed94 342//=======================================================================
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
2195ab96 369//=======================================================================
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//=======================================================================
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
b2bafb33 1061 && aStatus->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 {
b2bafb33 1544 aStatus->SetDisplayMode (theMode);
2195ab96 1545 theIObj->SetDisplayMode (theMode);
1546 return;
1547 }
a6964ce6 1548
2195ab96 1549 // erase presentations for all display modes different from <aMode>
3db69e41 1550 const Standard_Integer anOldMode = aStatus->DisplayMode();
1551 if (anOldMode != theMode)
2195ab96 1552 {
3db69e41 1553 if (myMainPM->IsHighlighted (theIObj, anOldMode))
2195ab96 1554 {
8e5fb5ea 1555 unhighlightGlobal (theIObj, anOldMode);
7fd59977 1556 }
3db69e41 1557 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
7fd59977 1558 }
2195ab96 1559
3db69e41 1560 aStatus->SetDisplayMode (theMode);
2195ab96 1561
1562 myMainPM->Display (theIObj, theMode);
1563 Standard_Integer aDispMode, aHiMode, aSelMode;
1564 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1565 if (aStatus->IsHilighted())
1566 {
8e5fb5ea 1567 highlightGlobal (theIObj, getSelStyle (theIObj), aHiMode);
2195ab96 1568 }
1569 if (aStatus->IsSubIntensityOn())
1570 {
8e5fb5ea 1571 highlightWithSubintensity (theIObj, theMode);
2195ab96 1572 }
1573
1574 if (theToUpdateViewer)
1575 {
1576 myMainVwr->Update();
1577 }
1578 theIObj->SetDisplayMode (theMode);
7fd59977 1579}
1580
1581//=======================================================================
1582//function : UnsetDisplayMode
2195ab96 1583//purpose :
7fd59977 1584//=======================================================================
2195ab96 1585void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1586 const Standard_Boolean theToUpdateViewer)
7fd59977 1587{
2195ab96 1588 if (theIObj.IsNull()
1589 || !theIObj->HasDisplayMode())
1590 {
1591 return;
1592 }
1593
1594 if (!myObjects.IsBound (theIObj))
1595 {
1596 theIObj->UnsetDisplayMode();
1597 return;
1598 }
1599
1600 const Standard_Integer anOldMode = theIObj->DisplayMode();
1601 if (myDisplayMode == anOldMode)
1602 {
1603 return;
1604 }
1605
1606 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
3db69e41 1607 aStatus->SetDisplayMode (myDisplayMode);
2195ab96 1608
1609 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1610 {
1611 if (myMainPM->IsHighlighted (theIObj, anOldMode))
7fd59977 1612 {
8e5fb5ea 1613 unhighlightGlobal (theIObj, anOldMode);
2195ab96 1614 }
1615 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1616 myMainPM->Display (theIObj, myDisplayMode);
1617
1618 Standard_Integer aDispMode, aHiMode, aSelMode;
1619 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1620 if (aStatus->IsHilighted())
1621 {
8e5fb5ea 1622 highlightSelected (theIObj->GlobalSelOwner());
2195ab96 1623 }
1624 if (aStatus->IsSubIntensityOn())
1625 {
8e5fb5ea 1626 highlightWithSubintensity (theIObj, myDisplayMode);
7fd59977 1627 }
2195ab96 1628
1629 if (theToUpdateViewer)
1630 {
1631 myMainVwr->Update();
1632 }
1633 }
1634
1635 theIObj->UnsetDisplayMode();
7fd59977 1636}
1637
1638//=======================================================================
1639//function : SetCurrentFacingModel
2195ab96 1640//purpose :
7fd59977 1641//=======================================================================
2195ab96 1642void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1643 const Aspect_TypeOfFacingModel theModel)
b8ddfc2f 1644{
2195ab96 1645 if (!theIObj.IsNull())
1646 {
1647 theIObj->SetCurrentFacingModel (theModel);
1648 }
7fd59977 1649}
7fd59977 1650
1651//=======================================================================
2195ab96 1652//function : redisplayPrsRecModes
1653//purpose :
7fd59977 1654//=======================================================================
2195ab96 1655void AIS_InteractiveContext::redisplayPrsRecModes (const Handle(AIS_InteractiveObject)& theIObj,
1656 const Standard_Boolean theToUpdateViewer)
7fd59977 1657{
2195ab96 1658 if (theIObj->RecomputeEveryPrs())
1659 {
36132a2e 1660 theIObj->Update (Standard_True);
1661 theIObj->UpdateSelection();
2195ab96 1662 }
1663 else
1664 {
1665 for (TColStd_ListIteratorOfListOfInteger aModes (theIObj->ListOfRecomputeModes()); aModes.More(); aModes.Next())
1666 {
1667 theIObj->Update (aModes.Value(), Standard_False);
1668 }
28ee613b 1669 theIObj->UpdateSelection();
2195ab96 1670 theIObj->SetRecomputeOk();
1671 }
1672
1673 if (theToUpdateViewer)
1674 {
1675 UpdateCurrentViewer();
1676 }
7fd59977 1677}
1678
2195ab96 1679//=======================================================================
1680//function : redisplayPrsModes
1681//purpose :
1682//=======================================================================
1683void AIS_InteractiveContext::redisplayPrsModes (const Handle(AIS_InteractiveObject)& theIObj,
1684 const Standard_Boolean theToUpdateViewer)
7fd59977 1685{
2195ab96 1686 if (theIObj->RecomputeEveryPrs())
1687 {
36132a2e 1688 theIObj->Update (Standard_True);
1689 theIObj->UpdateSelection();
2195ab96 1690 }
7fd59977 1691 else
2195ab96 1692 {
1693 TColStd_ListOfInteger aModes;
1694 theIObj->ToBeUpdated (aModes);
1695 for (TColStd_ListIteratorOfListOfInteger aModeIter (aModes); aModeIter.More(); aModeIter.Next())
7fd59977 1696 {
2195ab96 1697 theIObj->Update (aModeIter.Value(), Standard_False);
7fd59977 1698 }
2195ab96 1699 theIObj->SetRecomputeOk();
1700 }
7fd59977 1701
2195ab96 1702 if (theToUpdateViewer)
1703 {
1704 UpdateCurrentViewer();
1705 }
7fd59977 1706}
1707
1708//=======================================================================
2195ab96 1709//function : SetColor
1710//purpose :
7fd59977 1711//=======================================================================
2195ab96 1712void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1713 const Quantity_NameOfColor theColor,
1714 const Standard_Boolean theToUpdateViewer)
1715{
1716 SetColor (theIObj, Quantity_Color(theColor), theToUpdateViewer);
1717}
7fd59977 1718
2195ab96 1719//=======================================================================
1720//function : SetColor
1721//purpose :
1722//=======================================================================
1723void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1724 const Quantity_Color& theColor,
1725 const Standard_Boolean theToUpdateViewer)
7fd59977 1726{
2195ab96 1727 if (theIObj.IsNull())
1728 {
1729 return;
1730 }
7fd59977 1731
2195ab96 1732 if (!theIObj->HasInteractiveContext())
1733 {
1734 theIObj->SetContext (this);
1735 }
1736 theIObj->SetColor (theColor);
1737 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1738}
7fd59977 1739
5ad8c033 1740//=======================================================================
1741//function : SetIsoOnTriangulation
1742//purpose :
1743//=======================================================================
1744void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1745 const Handle(AIS_InteractiveObject)& theObject)
1746{
1747 if (theObject.IsNull())
1748 {
1749 return;
1750 }
1751
1752 theObject->SetIsoOnTriangulation (theIsEnabled);
1753}
1754
2195ab96 1755//=======================================================================
1756//function : SetDeviationCoefficient
1757//purpose :
1758//=======================================================================
1759void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1760 const Standard_Real theCoefficient,
1761 const Standard_Boolean theToUpdateViewer)
1762{
1763 if (theIObj.IsNull())
1764 {
1765 return;
1766 }
7fd59977 1767
2195ab96 1768 if (!theIObj->HasInteractiveContext())
1769 {
1770 theIObj->SetContext (this);
1771 }
7fd59977 1772
2195ab96 1773 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1774 if (theIObj->Type() != AIS_KOI_Object
1775 && theIObj->Type() != AIS_KOI_Shape)
1776 {
1777 return;
1778 }
1779 else if (theIObj->Signature() != 0)
1780 {
1781 return;
1782 }
1783
1784 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1785 aShape->SetOwnDeviationCoefficient (theCoefficient);
1786 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1787}
1788
1789//=======================================================================
1790//function : SetHLRDeviationCoefficient
2195ab96 1791//purpose :
7fd59977 1792//=======================================================================
2195ab96 1793void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1794 const Standard_Real theCoefficient,
1795 const Standard_Boolean theToUpdateViewer)
7fd59977 1796{
2195ab96 1797 if (theIObj.IsNull())
1798 {
1799 return;
1800 }
1801
1802 if (!theIObj->HasInteractiveContext())
1803 {
1804 theIObj->SetContext (this);
1805 }
7fd59977 1806
81bba717 1807 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2195ab96 1808 if (theIObj->Type() != AIS_KOI_Object
1809 && theIObj->Type() != AIS_KOI_Shape)
1810 {
1811 return;
1812 }
1813 else if (theIObj->Signature() != 0)
1814 {
1815 return;
1816 }
7fd59977 1817
2195ab96 1818 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1819 aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1820 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1821}
1822
7fd59977 1823//=======================================================================
1824//function : SetDeviationAngle
2195ab96 1825//purpose :
7fd59977 1826//=======================================================================
2195ab96 1827void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1828 const Standard_Real theAngle,
1829 const Standard_Boolean theToUpdateViewer)
7fd59977 1830{
2195ab96 1831 if (theIObj.IsNull())
1832 {
1833 return;
1834 }
1835
1836 if (!theIObj->HasInteractiveContext())
1837 {
1838 theIObj->SetContext (this);
1839 }
7fd59977 1840
e33e7e78 1841 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2195ab96 1842 if (theIObj->Type() != AIS_KOI_Shape)
1843 {
1844 return;
1845 }
1846 else if (theIObj->Signature() != 0)
1847 {
1848 return;
1849 }
7fd59977 1850
2195ab96 1851 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1852 aShape->SetOwnDeviationAngle (theAngle);
1853 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1854}
2195ab96 1855
7fd59977 1856//=======================================================================
2195ab96 1857//function : SetAngleAndDeviation
1858//purpose :
7fd59977 1859//=======================================================================
2195ab96 1860void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1861 const Standard_Real theAngle,
1862 const Standard_Boolean theToUpdateViewer)
7fd59977 1863{
2195ab96 1864 if (theIObj.IsNull())
1865 {
1866 return;
1867 }
1868
1869 if (!theIObj->HasInteractiveContext())
1870 {
1871 theIObj->SetContext (this);
1872 }
7fd59977 1873
e33e7e78 1874 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2195ab96 1875 if (theIObj->Type() != AIS_KOI_Shape)
1876 {
1877 return;
1878 }
1879 if (theIObj->Signature() != 0)
1880 {
1881 return;
1882 }
7fd59977 1883
2195ab96 1884 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1885 aShape->SetAngleAndDeviation (theAngle);
7fd59977 1886
2195ab96 1887 if (theIObj->RecomputeEveryPrs())
1888 {
36132a2e 1889 theIObj->Update (Standard_True);
1890 theIObj->UpdateSelection();
2195ab96 1891 }
7fd59977 1892 else
2195ab96 1893 {
1894 Update (theIObj, theToUpdateViewer);
1895 }
7fd59977 1896}
1897
1898//=======================================================================
2195ab96 1899//function : SetHLRAngleAndDeviation
1900//purpose :
7fd59977 1901//=======================================================================
2195ab96 1902void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1903 const Standard_Real theAngle,
1904 const Standard_Boolean theToUpdateViewer)
7fd59977 1905{
2195ab96 1906 if (theIObj.IsNull())
1907 {
1908 return;
1909 }
7fd59977 1910
2195ab96 1911 if (!theIObj->HasInteractiveContext())
1912 {
1913 theIObj->SetContext (this);
1914 }
7fd59977 1915
e33e7e78 1916 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2195ab96 1917 if (theIObj->Type() != AIS_KOI_Shape)
1918 {
1919 return;
1920 }
1921 if (theIObj->Signature() != 0)
1922 {
1923 return;
1924 }
1925 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1926 aShape->SetHLRAngleAndDeviation (theAngle);
1927 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1928}
1929
1930//=======================================================================
1931//function : SetHLRDeviationAngle
2195ab96 1932//purpose :
7fd59977 1933//=======================================================================
2195ab96 1934void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1935 const Standard_Real theAngle,
1936 const Standard_Boolean theToUpdateViewer)
7fd59977 1937{
2195ab96 1938 if (theIObj.IsNull())
1939 {
1940 return;
1941 }
7fd59977 1942
2195ab96 1943 if (!theIObj->HasInteractiveContext())
1944 {
1945 theIObj->SetContext (this);
1946 }
7fd59977 1947
2195ab96 1948 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1949 if (theIObj->Type() != AIS_KOI_Shape)
1950 {
1951 return;
1952 }
1953 if (theIObj->Signature() != 0)
1954 {
1955 return;
1956 }
1957 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1958 aShape->SetOwnHLRDeviationAngle (theAngle);
1959 redisplayPrsModes (theIObj, theToUpdateViewer);
7fd59977 1960}
1961
1962//=======================================================================
1963//function : UnsetColor
2195ab96 1964//purpose :
7fd59977 1965//=======================================================================
2195ab96 1966void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
1967 const Standard_Boolean theToUpdateViewer)
7fd59977 1968{
2195ab96 1969 if (theIObj.IsNull())
1970 {
1971 return;
1972 }
1973
1974 theIObj->UnsetColor();
1975 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 1976}
1977
1978//=======================================================================
1979//function : HasColor
2195ab96 1980//purpose :
7fd59977 1981//=======================================================================
2195ab96 1982Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 1983{
2195ab96 1984 return theIObj->HasColor();
7fd59977 1985}
1986
1987//=======================================================================
1988//function : Color
2195ab96 1989//purpose :
7fd59977 1990//=======================================================================
2195ab96 1991Quantity_NameOfColor AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 1992{
2195ab96 1993 return theIObj->Color();
7fd59977 1994}
1995
2195ab96 1996//=======================================================================
1997//function : Color
1998//purpose :
1999//=======================================================================
2000void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
2001 Quantity_Color& theColor) const
7fd59977 2002{
2195ab96 2003 theIObj->Color (theColor);
7fd59977 2004}
7fd59977 2005
2006//=======================================================================
2007//function : Width
2195ab96 2008//purpose :
7fd59977 2009//=======================================================================
2195ab96 2010Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
7fd59977 2011{
2195ab96 2012 return theIObj->Width();
7fd59977 2013}
2014
2015//=======================================================================
2016//function : SetWidth
2195ab96 2017//purpose :
7fd59977 2018//=======================================================================
2195ab96 2019void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2020 const Standard_Real theWidth,
2021 const Standard_Boolean theToUpdateViewer)
7fd59977 2022{
2195ab96 2023 if (theIObj.IsNull())
2024 {
2025 return;
2026 }
2027
2028 if (!theIObj->HasInteractiveContext())
2029 {
2030 theIObj->SetContext (this);
2031 }
2032
2033 theIObj->SetWidth (theWidth);
2034 redisplayPrsRecModes (theIObj, theToUpdateViewer);
8e5fb5ea 2035 if (!myLastinMain.IsNull() && myLastinMain->IsSameSelectable (theIObj))
c3282ec1 2036 {
2037 if (myLastinMain->IsAutoHilight())
2038 {
2039 const Standard_Integer aHiMode =
2040 theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
8e5fb5ea 2041 myLastinMain->HilightWithColor (myMainPM,
2042 myLastinMain->IsSelected() ? getSelStyle (theIObj) : getHiStyle (theIObj),
2043 aHiMode);
c3282ec1 2044 }
2045 else
2046 {
8e5fb5ea 2047 theIObj->HilightOwnerWithColor (myMainPM,
2048 myLastinMain->IsSelected() ? getSelStyle (theIObj) : getHiStyle (theIObj),
2049 myLastinMain);
c3282ec1 2050 }
2051 }
7fd59977 2052}
2053
2054//=======================================================================
2055//function : UnsetWidth
2195ab96 2056//purpose :
7fd59977 2057//=======================================================================
2195ab96 2058void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2059 const Standard_Boolean theToUpdateViewer)
7fd59977 2060{
2195ab96 2061 if (theIObj.IsNull())
2062 {
2063 return;
2064 }
2065
2066 theIObj->UnsetWidth();
2067 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2068}
2069
2070//=======================================================================
2071//function : SetMaterial
2195ab96 2072//purpose :
7fd59977 2073//=======================================================================
2195ab96 2074void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2075 const Graphic3d_NameOfMaterial theName,
2076 const Standard_Boolean theToUpdateViewer)
7fd59977 2077{
2195ab96 2078 if (theIObj.IsNull())
2079 {
2080 return;
2081 }
2082
2083 if (!theIObj->HasInteractiveContext())
2084 {
2085 theIObj->SetContext (this);
2086 }
7fd59977 2087
2195ab96 2088 theIObj->SetMaterial (theName);
2089 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2090}
2091
2092//=======================================================================
2093//function : UnsetMaterial
2195ab96 2094//purpose :
7fd59977 2095//=======================================================================
2195ab96 2096void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2097 const Standard_Boolean theToUpdateViewer)
7fd59977 2098{
2195ab96 2099 if (theIObj.IsNull())
2100 {
2101 return;
2102 }
2103 theIObj->UnsetMaterial();
2104 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2105}
2106
2107//=======================================================================
2108//function : SetTransparency
2195ab96 2109//purpose :
7fd59977 2110//=======================================================================
2195ab96 2111void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2112 const Standard_Real theValue,
2113 const Standard_Boolean theToUpdateViewer)
7fd59977 2114{
2195ab96 2115 if (theIObj.IsNull())
2116 {
2117 return;
2118 }
2119
2120 if (!theIObj->HasInteractiveContext())
2121 {
2122 theIObj->SetContext (this);
2123 }
7fd59977 2124
2195ab96 2125 if (!theIObj->IsTransparent()
2126 && theValue <= 0.05)
a6964ce6 2127 {
2128 return;
2129 }
2130
2195ab96 2131 if (theValue <= 0.05)
2132 {
2133 UnsetTransparency (theIObj, theToUpdateViewer);
7fd59977 2134 return;
2135 }
a6964ce6 2136
2195ab96 2137 theIObj->SetTransparency (theValue);
2138 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2139}
2140
2141//=======================================================================
2142//function : UnsetTransparency
2195ab96 2143//purpose :
7fd59977 2144//=======================================================================
2195ab96 2145void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2146 const Standard_Boolean theToUpdateViewer)
7fd59977 2147{
2195ab96 2148 if (theIObj.IsNull())
2149 {
2150 return;
2151 }
7fd59977 2152
2195ab96 2153 theIObj->UnsetTransparency();
2154 redisplayPrsRecModes (theIObj, theToUpdateViewer);
7fd59977 2155}
2156
2195ab96 2157//=======================================================================
2158//function : SetSelectedAspect
2159//purpose :
2160//=======================================================================
2161void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
2831708b 2162 const Standard_Boolean ,
2195ab96 2163 const Standard_Boolean theToUpdateViewer)
2164{
2165 if (HasOpenedContext())
2166 {
2167 return;
2168 }
2169
2170 Standard_Boolean isFound = Standard_False;
02974a19 2171 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2195ab96 2172 {
2173 isFound = Standard_True;
02974a19 2174 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
2831708b 2175 anObj->SetAspect (theAspect);
2195ab96 2176 }
2177
016e5959 2178 if (isFound && theToUpdateViewer)
2195ab96 2179 {
2180 myMainVwr->Update();
7fd59977 2181 }
2182}
7fd59977 2183
2184//=======================================================================
2185//function : SetLocalAttributes
2195ab96 2186//purpose :
7fd59977 2187//=======================================================================
2195ab96 2188void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
6262338c 2189 const Handle(Prs3d_Drawer)& theDrawer,
2195ab96 2190 const Standard_Boolean theToUpdateViewer)
7fd59977 2191{
2195ab96 2192 if (theIObj.IsNull())
2193 {
2194 return;
2195 }
2196
2197 if (!theIObj->HasInteractiveContext())
2198 {
2199 theIObj->SetContext (this);
2200 }
2201
2202 theIObj->SetAttributes (theDrawer);
2203 Update (theIObj, theToUpdateViewer);
7fd59977 2204}
2205
2206//=======================================================================
2207//function : UnsetLocalAttributes
2195ab96 2208//purpose :
7fd59977 2209//=======================================================================
2195ab96 2210void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2211 const Standard_Boolean theToUpdateViewer)
7fd59977 2212{
2195ab96 2213 if (theIObj.IsNull())
2214 {
2215 return;
2216 }
7fd59977 2217
2195ab96 2218 if (!theIObj->HasInteractiveContext())
2219 {
2220 theIObj->SetContext (this);
2221 }
2222 theIObj->UnsetAttributes();
2223 Update (theIObj, theToUpdateViewer);
2224}
7fd59977 2225
2226//=======================================================================
2227//function : Status
2195ab96 2228//purpose :
7fd59977 2229//=======================================================================
2195ab96 2230void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
2231 TCollection_ExtendedString& theStatus) const
7fd59977 2232{
2195ab96 2233 theStatus = "";
2234 if (theIObj.IsNull()
2235 || !myObjects.IsBound (theIObj))
2236 {
2237 return;
2238 }
7fd59977 2239
2195ab96 2240 theStatus += "\t ____________________________________________";
2241 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
2242 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2243 switch (aStatus->GraphicStatus())
2244 {
7fd59977 2245 case AIS_DS_Displayed:
2195ab96 2246 {
2247 theStatus += "\t| -->Displayed\n";
7fd59977 2248 break;
2249 }
2195ab96 2250 case AIS_DS_Erased:
2251 {
2252 theStatus += "\t| -->Erased\n";
2253 break;
7fd59977 2254 }
2195ab96 2255 default:
2256 break;
2257 }
2258
2259 theStatus += "\t| Active Display Modes in the MainViewer :\n";
3db69e41 2260 theStatus += "\t|\t Mode ";
2261 theStatus += TCollection_AsciiString (aStatus->DisplayMode());
2262 theStatus += "\n";
2263
2195ab96 2264 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
7fd59977 2265
2195ab96 2266 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
2267 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2268 {
2269 theStatus += "\t\t Mode ";
2270 theStatus += TCollection_AsciiString (aSelModeIter.Value());
2271 theStatus += "\n";
2272 }
2273 theStatus += "\t ____________________________________________";
2274}
7fd59977 2275
2276//=======================================================================
2277//function : GetDefModes
2195ab96 2278//purpose :
7fd59977 2279//=======================================================================
2195ab96 2280void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
2281 Standard_Integer& theDispMode,
2282 Standard_Integer& theHiMode,
2283 Standard_Integer& theSelMode) const
7fd59977 2284{
2195ab96 2285 if (theIObj.IsNull())
2286 {
2287 return;
2288 }
7fd59977 2289
2195ab96 2290 theDispMode = theIObj->HasDisplayMode()
2291 ? theIObj->DisplayMode()
2292 : (theIObj->AcceptDisplayMode (myDisplayMode)
2293 ? myDisplayMode
2294 : 0);
2295 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
c3282ec1 2296 theSelMode = theIObj->GlobalSelectionMode();
2195ab96 2297}
7fd59977 2298
2299//=======================================================================
2300//function : EraseGlobal
2195ab96 2301//purpose :
7fd59977 2302//=======================================================================
2195ab96 2303void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2304 const Standard_Boolean theToUpdateviewer)
7fd59977 2305{
2195ab96 2306 if (theIObj.IsNull()
2307 || !myObjects.IsBound (theIObj))
2308 {
2309 return;
2310 }
7fd59977 2311
2195ab96 2312 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2313
a1954302 2314 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2315 if (aStatus->GraphicStatus() == AIS_DS_Temporary
2316 || aStatus->GraphicStatus() == AIS_DS_Erased)
2195ab96 2317 {
a1954302 2318 return;
2319 }
2195ab96 2320
3db69e41 2321 if (aStatus->IsHilighted())
a1954302 2322 {
3db69e41 2323 if (IsCurrent (theIObj))
2195ab96 2324 {
3db69e41 2325 AddOrRemoveCurrentObject (theIObj, Standard_False);
2326 }
2327 else if (myMainPM->IsHighlighted (theIObj, aStatus->DisplayMode()))
2328 {
8e5fb5ea 2329 unhighlightGlobal (theIObj, aStatus->DisplayMode());
2195ab96 2330 }
a1954302 2331 }
2195ab96 2332
3db69e41 2333 myMainPM->SetVisibility (theIObj, aStatus->DisplayMode(), Standard_False);
2334
4f51d9d7 2335 if (aStatus->IsHilighted()
2336 && theIObj->HasHilightMode())
2337 {
8e5fb5ea 2338 unhighlightGlobal (theIObj, aDispMode);
4f51d9d7 2339 }
2340
2341 if (!myLastPicked.IsNull()
8e5fb5ea 2342 && myLastPicked->IsSameSelectable (theIObj))
4f51d9d7 2343 {
2344 myMainPM->ClearImmediateDraw();
2345 }
2346
c3282ec1 2347 if (IsSelected (theIObj)
3db69e41 2348 && aStatus->DisplayMode() != aDispMode)
a1954302 2349 {
2350 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
2351 }
2352
2353 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2354 {
2355 mgrSelector->Deactivate (theIObj, aSelModeIter.Value(), myMainSel);
7fd59977 2356 }
c3282ec1 2357 aStatus->ClearSelectionModes();
2195ab96 2358 aStatus->SetGraphicStatus (AIS_DS_Erased);
a1954302 2359
2360 if (theToUpdateviewer)
2361 {
2362 myMainVwr->Update();
2363 }
7fd59977 2364}
2365
c3282ec1 2366//=======================================================================
2367//function : unhighlightOwners
2368//purpose :
2369//=======================================================================
2370void AIS_InteractiveContext::unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject)
2371{
02974a19 2372 SelectMgr_SequenceOfOwner aSeq;
2373 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
c3282ec1 2374 {
8e5fb5ea 2375 if (aSelIter.Value()->IsSameSelectable (theObject)
02974a19 2376 && aSelIter.Value()->IsSelected())
c3282ec1 2377 {
02974a19 2378 aSeq.Append (aSelIter.Value());
c3282ec1 2379 }
02974a19 2380 }
2381 for (SelectMgr_SequenceOfOwner::Iterator aDelIter (aSeq); aDelIter.More(); aDelIter.Next())
2382 {
2383 AddOrRemoveSelected (aDelIter.Value(), Standard_False);
c3282ec1 2384 }
2385}
2386
7fd59977 2387//=======================================================================
2388//function : ClearGlobal
2195ab96 2389//purpose :
7fd59977 2390//=======================================================================
2195ab96 2391void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2392 const Standard_Boolean theToUpdateviewer)
7fd59977 2393{
2195ab96 2394 if (theIObj.IsNull()
2395 || !myObjects.IsBound (theIObj))
2396 {
f751596e 2397 // for cases when reference shape of connected interactives was not displayed
2398 // but its selection primitives were calculated
543a9964 2399 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2400 mgrSelector->Remove (anObj);
2195ab96 2401 return;
2402 }
2403
2404 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
c3282ec1 2405 unhighlightOwners (theIObj);
7fd59977 2406
e2d7642f 2407 myMainPM->Erase (theIObj, -1);
4f51d9d7 2408
2195ab96 2409 // Object removes from Detected sequence
2410 for(Standard_Integer aDetIter = 1; aDetIter < myAISDetectedSeq.Length(); ++aDetIter)
7fd59977 2411 {
2412 Handle(AIS_InteractiveObject) anObj = DetectedCurrentObject();
2195ab96 2413 if (!anObj.IsNull()
2414 && anObj != theIObj)
2415 {
2416 myAISDetectedSeq.Remove (aDetIter);
2417 }
7fd59977 2418 }
2419
2195ab96 2420 // remove IO from the selection manager to avoid memory leaks
543a9964 2421 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2422 mgrSelector->Remove (anObj);
7fd59977 2423
2195ab96 2424 myObjects.UnBind (theIObj);
c357e426 2425 myMainVwr->StructureManager()->UnregisterObject (theIObj);
6a24c6de 2426
2427 for (V3d_ListOfViewIterator aDefViewIter (myMainVwr->DefinedViewIterator()); aDefViewIter.More(); aDefViewIter.Next())
a272ed94 2428 {
6a24c6de 2429 aDefViewIter.Value()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
a272ed94 2430 }
7fd59977 2431
8e5fb5ea 2432 if (!myLastinMain.IsNull() && myLastinMain->IsSameSelectable (theIObj))
c3282ec1 2433 myLastinMain.Nullify();
8e5fb5ea 2434 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
c3282ec1 2435 myLastPicked.Nullify();
2436 myMainPM->ClearImmediateDraw();
2437
2438 if (theToUpdateviewer && aStatus->GraphicStatus() == AIS_DS_Displayed)
eb4320f2 2439 {
2440 myMainVwr->Update();
2441 }
7fd59977 2442}
2443
2444//=======================================================================
2445//function : ClearGlobalPrs
2195ab96 2446//purpose :
7fd59977 2447//=======================================================================
2195ab96 2448void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2449 const Standard_Integer theMode,
2450 const Standard_Boolean theToUpdateViewer)
7fd59977 2451{
2195ab96 2452 if (theIObj.IsNull()
2453 || !myObjects.IsBound (theIObj))
2454 {
2455 return;
2456 }
2457
2458 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
3db69e41 2459 if (aStatus->DisplayMode() == theMode)
2195ab96 2460 {
2461 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2462 if (aDispMode == theMode
2463 && myMainPM->IsHighlighted (theIObj, theMode))
2464 {
8e5fb5ea 2465 unhighlightGlobal (theIObj, theMode);
2195ab96 2466 }
2467
2468 myMainPM->Erase (theIObj, theMode);
7fd59977 2469 }
eb4320f2 2470
2195ab96 2471 if (aStatus->GraphicStatus() == AIS_DS_Displayed
2472 && theToUpdateViewer)
2473 {
7fd59977 2474 myMainVwr->Update();
2195ab96 2475 }
7fd59977 2476}
2477
2478//=======================================================================
2479//function : DrawHiddenLine
2195ab96 2480//purpose :
7fd59977 2481//=======================================================================
2195ab96 2482Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2483{
7fd59977 2484 return myDefaultDrawer->DrawHiddenLine();
2485}
2486
2487//=======================================================================
2488//function : EnableDrawHiddenLine
2195ab96 2489//purpose :
7fd59977 2490//=======================================================================
2195ab96 2491void AIS_InteractiveContext::EnableDrawHiddenLine() const
2492{
7fd59977 2493 myDefaultDrawer->EnableDrawHiddenLine();
2494}
2495
2496//=======================================================================
2497//function : DisableDrawHiddenLine
2195ab96 2498//purpose :
7fd59977 2499//=======================================================================
2195ab96 2500void AIS_InteractiveContext::DisableDrawHiddenLine() const
2501{
7fd59977 2502 myDefaultDrawer->DisableDrawHiddenLine();
2503}
2504
2505//=======================================================================
2506//function : HiddenLineAspect
2195ab96 2507//purpose :
7fd59977 2508//=======================================================================
2195ab96 2509Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2510{
7fd59977 2511 return myDefaultDrawer->HiddenLineAspect();
2512}
2513
2514//=======================================================================
2515//function : SetHiddenLineAspect
2195ab96 2516//purpose :
7fd59977 2517//=======================================================================
2195ab96 2518void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2519{
2520 myDefaultDrawer->SetHiddenLineAspect (theAspect);
7fd59977 2521}
2522
2523//=======================================================================
2524//function : SetIsoNumber
2195ab96 2525//purpose :
7fd59977 2526//=======================================================================
2195ab96 2527void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2528 const AIS_TypeOfIso theType)
7fd59977 2529{
2195ab96 2530 switch (theType)
2531 {
2532 case AIS_TOI_IsoU:
2533 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2534 break;
2535 case AIS_TOI_IsoV:
2536 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2537 break;
2538 case AIS_TOI_Both:
2539 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2540 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2541 break;
7fd59977 2542 }
2543}
2195ab96 2544
7fd59977 2545//=======================================================================
2546//function : IsoNumber
2195ab96 2547//purpose :
7fd59977 2548//=======================================================================
2195ab96 2549Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
7fd59977 2550{
2195ab96 2551 switch (theType)
2552 {
2553 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2554 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2555 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2556 ? myDefaultDrawer->UIsoAspect()->Number()
2557 : -1;
7fd59977 2558 }
2559 return 0;
2560}
2561
2562//=======================================================================
2563//function : IsoOnPlane
2195ab96 2564//purpose :
7fd59977 2565//=======================================================================
2195ab96 2566void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
7fd59977 2567{
2195ab96 2568 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
7fd59977 2569}
2570
2571//=======================================================================
2572//function : IsoOnPlane
2195ab96 2573//purpose :
7fd59977 2574//=======================================================================
2195ab96 2575Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
7fd59977 2576{
2577 return myDefaultDrawer->IsoOnPlane();
2578}
2579
3c982548 2580//=======================================================================
5ad8c033 2581//function : IsoOnTriangulation
2582//purpose :
2583//=======================================================================
2584void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theToSwitchOn)
2585{
2586 myDefaultDrawer->SetIsoOnTriangulation (theToSwitchOn);
2587}
2588
2589//=======================================================================
2590//function : IsoOnTriangulation
2591//purpose :
2592//=======================================================================
2593Standard_Boolean AIS_InteractiveContext::IsoOnTriangulation() const
2594{
2595 return myDefaultDrawer->IsoOnTriangulation();
2596}
2597
3c982548 2598//function : SetPixelTolerance
28ee613b 2599//purpose : Disables the mechanism of adaptive tolerance calculation in
2600// SelectMgr_ViewerSelector and sets the given tolerance for ALL
2601// sensitive entities activated. For more information, see
2602// SelectMgr_ViewerSelector.hxx
3c982548 2603//=======================================================================
3bf9a45f 2604void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2195ab96 2605{
2606 if (HasOpenedContext())
2607 {
2608 myLocalContexts (myCurLocalIndex)->SetPixelTolerance (thePrecision);
2609 }
2610 else
2611 {
2612 myMainSel->SetPixelTolerance (thePrecision);
7fd59977 2613 }
2614}
3c982548 2615
2616//=======================================================================
2617//function : PixelTolerance
2195ab96 2618//purpose :
3c982548 2619//=======================================================================
3bf9a45f 2620Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2195ab96 2621{
2622 return HasOpenedContext()
2623 ? myLocalContexts (myCurLocalIndex)->PixelTolerance()
2624 : myMainSel->PixelTolerance();
3c982548 2625}
7fd59977 2626
8a1170ad 2627//=======================================================================
2628//function : SetSelectionSensitivity
2629//purpose : Allows to manage sensitivity of a particular selection of interactive object theObject
2630//=======================================================================
2631void AIS_InteractiveContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
2632 const Standard_Integer theMode,
2633 const Standard_Integer theNewSensitivity)
2634{
2635 if (HasOpenedContext())
2636 {
2637 myLocalContexts (myCurLocalIndex)->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2638 return;
2639 }
2640
2641 mgrSelector->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2642}
2643
7fd59977 2644//=======================================================================
2645//function : IsInLocal
2195ab96 2646//purpose :
7fd59977 2647//=======================================================================
2195ab96 2648Standard_Boolean AIS_InteractiveContext::IsInLocal (const Handle(AIS_InteractiveObject)& theIObj,
2649 Standard_Integer& theIndex) const
7fd59977 2650{
2195ab96 2651 if (theIObj.IsNull())
2652 {
2653 return Standard_False;
2654 }
2655
81bba717 2656 // if it exists at neutral point 0 index is returned
2195ab96 2657 if (myObjects.IsBound (theIObj))
2658 {
2659 theIndex = 0;
7fd59977 2660 return Standard_False;
2661 }
2195ab96 2662
2663 for (Standard_Integer aCtxIter = 1; aCtxIter <= myLocalContexts.Extent(); ++aCtxIter)
2664 {
2665 if (myLocalContexts.IsBound (aCtxIter))
2666 {
2667 if(myLocalContexts (aCtxIter)->IsIn (theIObj))
2668 {
2669 theIndex = aCtxIter;
7fd59977 2670 return Standard_True;
7fd59977 2671 }
2672 }
2673 }
2195ab96 2674 theIndex = -1;
7fd59977 2675 return Standard_False;
2195ab96 2676}
2677
7fd59977 2678//=======================================================================
2679//function : InitAttributes
2195ab96 2680//purpose :
7fd59977 2681//=======================================================================
7fd59977 2682void AIS_InteractiveContext::InitAttributes()
2683{
2195ab96 2684 mgrSelector->Add (myMainSel);
7fd59977 2685
2195ab96 2686 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2687 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
7fd59977 2688
2689// myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2195ab96 2690 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2691 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2692 aLineAspect->SetWidth (1.0);
2693 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
7fd59977 2694
28ee613b 2695 // tolerance to 2 pixels...
3bf9a45f 2696 SetPixelTolerance (2);
7fd59977 2697
2698 // Customizing the drawer for trihedrons and planes...
2195ab96 2699 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2700 const Standard_Real aLength = 100.0;
2701 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2702 const Quantity_NameOfColor aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2703 aTrihAspect->FirstAxisAspect() ->SetColor (aColor);
2704 aTrihAspect->SecondAxisAspect()->SetColor (aColor);
2705 aTrihAspect->ThirdAxisAspect() ->SetColor (aColor);
7fd59977 2706
2195ab96 2707 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2708 const Standard_Real aPlaneLength = 200.0;
2709 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2710 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
7fd59977 2711}
2712
7fd59977 2713//=======================================================================
2714//function : TrihedronSize
2195ab96 2715//purpose :
7fd59977 2716//=======================================================================
2717Standard_Real AIS_InteractiveContext::TrihedronSize() const
2718{
2719 return myDefaultDrawer->DatumAspect()->FirstAxisLength();
2720}
2195ab96 2721
7fd59977 2722//=======================================================================
2723//function : SetTrihedronSize
2195ab96 2724//purpose :
7fd59977 2725//=======================================================================
2195ab96 2726void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2727 const Standard_Boolean /*updateviewer*/)
7fd59977 2728{
2195ab96 2729 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2730 Redisplay (AIS_KOI_Datum, 3, Standard_False);
2731 Redisplay (AIS_KOI_Datum, 4, Standard_True);
7fd59977 2732}
2733
7fd59977 2734//=======================================================================
2735//function : SetPlaneSize
2195ab96 2736//purpose :
7fd59977 2737//=======================================================================
2195ab96 2738void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2739 const Standard_Real theValY,
7fd59977 2740 const Standard_Boolean /*updateviewer*/)
2741{
2195ab96 2742 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2743 Redisplay (AIS_KOI_Datum, 7);
7fd59977 2744}
2745
2746//=======================================================================
2747//function : SetPlaneSize
2195ab96 2748//purpose :
7fd59977 2749//=======================================================================
2195ab96 2750void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2751 const Standard_Boolean theToUpdateViewer)
7fd59977 2752{
2195ab96 2753 SetPlaneSize (theVal, theVal, theToUpdateViewer);
7fd59977 2754}
2755
2756//=======================================================================
2757//function : PlaneSize
2195ab96 2758//purpose :
7fd59977 2759//=======================================================================
2195ab96 2760Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2761 Standard_Real& theY) const
7fd59977 2762{
2195ab96 2763 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2764 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2765 return (Abs (theX - theY) <= Precision::Confusion());
7fd59977 2766}
2767
7fd59977 2768//=======================================================================
2195ab96 2769//function : SetAutoActivateSelection
2770//purpose :
7fd59977 2771//=======================================================================
2195ab96 2772void AIS_InteractiveContext::SetAutoActivateSelection (const Standard_Boolean theIsAuto)
7fd59977 2773{
2195ab96 2774 myIsAutoActivateSelMode = theIsAuto;
7fd59977 2775}
2776
2777//=======================================================================
2195ab96 2778//function : GetAutoActivateSelection
2779//purpose :
7fd59977 2780//=======================================================================
2781Standard_Boolean AIS_InteractiveContext::GetAutoActivateSelection() const
2782{
2783 return myIsAutoActivateSelMode;
2784}
59f45b7c 2785
2786//=======================================================================
2787//function : SetZLayer
2195ab96 2788//purpose :
59f45b7c 2789//=======================================================================
59f45b7c 2790void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2791 const Standard_Integer theLayerId)
2792{
2195ab96 2793 if (theIObj.IsNull())
59f45b7c 2794 return;
2795
a1954302 2796 theIObj->SetZLayer (theLayerId);
59f45b7c 2797}
2798
2799//=======================================================================
2800//function : GetZLayer
2195ab96 2801//purpose :
59f45b7c 2802//=======================================================================
59f45b7c 2803Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2804{
a1954302 2805 return !theIObj.IsNull()
2806 ? theIObj->ZLayer()
2807 : Graphic3d_ZLayerId_UNKNOWN;
59f45b7c 2808}
f751596e 2809
2810//=======================================================================
2811//function : RebuildSelectionStructs
2812//purpose : Rebuilds 1st level of BVH selection forcibly
2813//=======================================================================
2814void AIS_InteractiveContext::RebuildSelectionStructs()
2815{
2816 myMainSel->RebuildObjectsTree (Standard_True);
2817}
2818
2819//=======================================================================
2820//function : Disconnect
2821//purpose : Disconnects selectable object from an assembly and updates selection structures
2822//=======================================================================
2823void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2824 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2825{
2826 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2827 {
c5f3a425 2828 Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
f751596e 2829 theObj->Disconnect (theObjToDisconnect);
543a9964 2830 const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2831 mgrSelector->Remove (anObj);
f751596e 2832 }
c04c30b3 2833 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
f751596e 2834 {
c5f3a425 2835 Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
f751596e 2836 theObj->Disconnect();
543a9964 2837 const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2838 mgrSelector->Remove (anObj);
f751596e 2839 }
2840 else
2841 return;
2842}
b586500b 2843
2844//=======================================================================
2845//function : FitSelected
2846//purpose : Fits the view corresponding to the bounds of selected objects
2847//=======================================================================
2848void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2849 const Standard_Real theMargin,
2850 const Standard_Boolean theToUpdate)
2851{
016e5959 2852 const Handle(AIS_Selection)& aSelection = HasOpenedContext() ?
2853 myLocalContexts(myCurLocalIndex)->Selection() : mySelection;
b586500b 2854
2855 Bnd_Box aBndSelected;
2856
b586500b 2857 AIS_MapOfObjectOwners anObjectOwnerMap;
2858 for (aSelection->Init(); aSelection->More(); aSelection->Next())
2859 {
02974a19 2860 const Handle(SelectMgr_EntityOwner)& anOwner = aSelection->Value();
2861 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
2862 if (anObj->IsInfinite())
b586500b 2863 {
02974a19 2864 continue;
2865 }
b586500b 2866
02974a19 2867 if (anOwner == anObj->GlobalSelOwner())
2868 {
b586500b 2869 Bnd_Box aTmpBnd;
2870 anObj->BoundingBox (aTmpBnd);
2871 aBndSelected.Add (aTmpBnd);
2872 }
2873 else
2874 {
b586500b 2875 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2876 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2877 {
2878 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2879 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2880 }
2881
2882 anOwnerMap->Add (anOwner);
2883 }
2884 }
2885
2886 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2887 {
2888 const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2889 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2890 aBndSelected.Add (aTmpBox);
2891 }
2892
2893 anObjectOwnerMap.Clear();
2894
2895 if (aBndSelected.IsVoid())
2896 return;
2897
2898 theView->FitAll (aBndSelected, theMargin, theToUpdate);
2899}
1d92133e 2900
2901//=======================================================================
2902//function : SetTransformPersistence
2903//purpose :
2904//=======================================================================
2905void AIS_InteractiveContext::SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObject,
778cd667 2906 const Handle(Graphic3d_TransformPers)& theTrsfPers)
1d92133e 2907{
778cd667 2908 theObject->SetTransformPersistence (theTrsfPers);
1d92133e 2909 if (!myObjects.IsBound (theObject))
2910 {
2911 return;
2912 }
2913
2914 mgrSelector->UpdateSelection (theObject);
2915
2916 const Standard_Integer aLayerId = myObjects.Find (theObject)->GetLayerIndex();
2917 const Handle(V3d_Viewer)& aCurViewer = CurrentViewer();
6a24c6de 2918 for (V3d_ListOfViewIterator anActiveViewIter (aCurViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
1d92133e 2919 {
6a24c6de 2920 anActiveViewIter.Value()->View()->InvalidateBVHData (aLayerId);
2921 anActiveViewIter.Value()->View()->InvalidateZLayerBoundingBox (aLayerId);
1d92133e 2922 }
2923}