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