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