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