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