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