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