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