0029945: Export body of revolution to STEP breaks the shape
[occt.git] / src / AIS / AIS_InteractiveContext_1.cxx
CommitLineData
b311480e 1// Created on: 1997-01-29
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.
7fd59977 16
7fd59977 17
18#include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
7fd59977 19#include <AIS_GlobalStatus.hxx>
42cf5bc1 20#include <AIS_InteractiveContext.hxx>
21#include <AIS_InteractiveObject.hxx>
42cf5bc1 22#include <AIS_MapIteratorOfMapOfInteractive.hxx>
23#include <AIS_MapOfInteractive.hxx>
24#include <AIS_Selection.hxx>
7fd59977 25#include <AIS_Shape.hxx>
42cf5bc1 26#include <AIS_StatusOfDetection.hxx>
27#include <AIS_StatusOfPick.hxx>
679ecdee 28#include <Aspect_Grid.hxx>
42cf5bc1 29#include <Prs3d_BasicAspect.hxx>
30#include <Prs3d_LineAspect.hxx>
31#include <Prs3d_Presentation.hxx>
32#include <Quantity_Color.hxx>
33#include <SelectBasics_SensitiveEntity.hxx>
34#include <SelectMgr_EntityOwner.hxx>
35#include <SelectMgr_Filter.hxx>
36#include <SelectMgr_OrFilter.hxx>
37#include <SelectMgr_Selection.hxx>
38#include <SelectMgr_SelectionManager.hxx>
39#include <Standard_Transient.hxx>
c3282ec1 40#include <StdSelect_BRepOwner.hxx>
42cf5bc1 41#include <StdSelect_ViewerSelector3d.hxx>
42#include <TCollection_AsciiString.hxx>
43#include <TCollection_ExtendedString.hxx>
44#include <TColStd_ListIteratorOfListOfInteger.hxx>
45#include <TopLoc_Location.hxx>
42cf5bc1 46#include <V3d_AmbientLight.hxx>
47#include <V3d_DirectionalLight.hxx>
7fd59977 48#include <V3d_Light.hxx>
49#include <V3d_PositionalLight.hxx>
50#include <V3d_SpotLight.hxx>
42cf5bc1 51#include <V3d_View.hxx>
52#include <V3d_Viewer.hxx>
7fd59977 53
c3282ec1 54typedef NCollection_DataMap<Handle(AIS_InteractiveObject), NCollection_Handle<SelectMgr_SequenceOfOwner> > AIS_MapOfObjSelectedOwners;
55
016e5959 56namespace
57{
896faa72 58 TopoDS_Shape AIS_InteractiveContext_myDummyShape;
016e5959 59}
60
c3282ec1 61//=======================================================================
62//function : highlightWithColor
63//purpose :
64//=======================================================================
65void AIS_InteractiveContext::highlightWithColor (const Handle(SelectMgr_EntityOwner)& theOwner,
c3282ec1 66 const Handle(V3d_Viewer)& theViewer)
67{
f838dac4 68 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
c3282ec1 69 if (anObj.IsNull())
f838dac4 70 {
c3282ec1 71 return;
f838dac4 72 }
73
74 const Handle(Prs3d_Drawer)& aStyle = getHiStyle (anObj, theOwner);
75 const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1);
c3282ec1 76
77 myMainPM->BeginImmediateDraw();
f838dac4 78 theOwner->HilightWithColor (myMainPM, aStyle, aHiMode);
c3282ec1 79 myMainPM->EndImmediateDraw (theViewer.IsNull() ? myMainVwr : theViewer);
80}
81
82//=======================================================================
83//function : highlightSelected
84//purpose :
85//=======================================================================
8e5fb5ea 86void AIS_InteractiveContext::highlightSelected (const Handle(SelectMgr_EntityOwner)& theOwner)
c3282ec1 87{
f838dac4 88 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
c3282ec1 89 if (anObj.IsNull())
f838dac4 90 {
c3282ec1 91 return;
f838dac4 92 }
c3282ec1 93
94 if (!theOwner->IsAutoHilight())
95 {
c3282ec1 96 SelectMgr_SequenceOfOwner aSeq;
02974a19 97 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
c3282ec1 98 {
8e5fb5ea 99 if (aSelIter.Value()->IsSameSelectable (anObj))
02974a19 100 {
101 aSeq.Append (aSelIter.Value());
102 }
c3282ec1 103 }
104 anObj->HilightSelected (myMainPM, aSeq);
105 }
106 else
107 {
f838dac4 108 const Handle(Prs3d_Drawer)& aStyle = getSelStyle (anObj, theOwner);
109 const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1);
110 theOwner->HilightWithColor (myMainPM, aStyle, aHiMode);
8e5fb5ea 111 }
112}
113
114//=======================================================================
115//function : highlightGlobal
116//purpose :
117//=======================================================================
118void AIS_InteractiveContext::highlightGlobal (const Handle(AIS_InteractiveObject)& theObj,
f838dac4 119 const Handle(Prs3d_Drawer)& theStyle,
120 const Standard_Integer theDispMode) const
8e5fb5ea 121{
122 if (theObj.IsNull())
f838dac4 123 {
8e5fb5ea 124 return;
f838dac4 125 }
126
127 const Standard_Integer aHiMode = getHilightMode (theObj, theStyle, theDispMode);
8e5fb5ea 128 const Handle(SelectMgr_EntityOwner)& aGlobOwner = theObj->GlobalSelOwner();
129
130 if (aGlobOwner.IsNull())
131 {
f838dac4 132 myMainPM->Color (theObj, theStyle, aHiMode);
8e5fb5ea 133 return;
134 }
135
136 if (!aGlobOwner->IsAutoHilight())
137 {
138 SelectMgr_SequenceOfOwner aSeq;
139 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
140 {
141 if (aSelIter.Value()->IsSameSelectable (theObj))
142 {
143 aSeq.Append (aSelIter.Value());
144 }
145 }
146 theObj->HilightSelected (myMainPM, aSeq);
147 }
148 else
149 {
f838dac4 150 aGlobOwner->HilightWithColor (myMainPM, theStyle, aHiMode);
c3282ec1 151 }
152}
153
b4006117 154//=======================================================================
155//function : unhighlightSelected
156//purpose :
157//=======================================================================
158void AIS_InteractiveContext::unhighlightSelected (const Standard_Boolean theIsToHilightSubIntensity)
159{
b4006117 160 NCollection_IndexedMap<Handle(AIS_InteractiveObject)> anObjToClear;
02974a19 161 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
b4006117 162 {
02974a19 163 const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value();
164 const Handle(AIS_InteractiveObject) anInteractive = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
f838dac4 165 Handle(AIS_GlobalStatus) aStatus;
166 if (!myObjects.Find (anInteractive, aStatus))
167 {
168 continue;
169 }
170
b4006117 171 if (anOwner->IsAutoHilight())
172 {
f838dac4 173 anOwner->Unhilight (myMainPM);
b4006117 174 if (theIsToHilightSubIntensity)
175 {
f838dac4 176 if (aStatus->IsSubIntensityOn())
b4006117 177 {
f838dac4 178 const Standard_Integer aHiMode = getHilightMode (anInteractive, aStatus->HilightStyle(), aStatus->DisplayMode());
8e5fb5ea 179 highlightWithSubintensity (anOwner, aHiMode);
b4006117 180 }
181 }
182 }
183 else
184 {
f838dac4 185 anObjToClear.Add (anInteractive);
b4006117 186 }
f838dac4 187 anOwner->SetSelected (Standard_False);
b4006117 188 if (anOwner == anInteractive->GlobalSelOwner())
189 {
190 myObjects.ChangeFind (anInteractive)->SetHilightStatus (Standard_False);
191 }
192 }
193 for (NCollection_IndexedMap<Handle(AIS_InteractiveObject)>::Iterator anIter (anObjToClear); anIter.More(); anIter.Next())
194 {
195 const Handle(AIS_InteractiveObject)& anObj = anIter.Value();
f838dac4 196 myMainPM->Unhighlight (anObj);
b4006117 197 anObj->ClearSelected();
198 }
199}
200
8e5fb5ea 201//=======================================================================
202//function : unhighlightGlobal
203//purpose :
204//=======================================================================
f838dac4 205void AIS_InteractiveContext::unhighlightGlobal (const Handle(AIS_InteractiveObject)& theObj) const
8e5fb5ea 206{
207 if (theObj.IsNull())
f838dac4 208 {
8e5fb5ea 209 return;
f838dac4 210 }
8e5fb5ea 211
f838dac4 212 const Handle(SelectMgr_EntityOwner)& aGlobOwner = theObj->GlobalSelOwner();
8e5fb5ea 213 if (aGlobOwner.IsNull())
214 {
f838dac4 215 myMainPM->Unhighlight (theObj);
8e5fb5ea 216 return;
217 }
218
219 if (aGlobOwner->IsAutoHilight())
220 {
f838dac4 221 aGlobOwner->Unhilight (myMainPM);
8e5fb5ea 222 }
223 else
224 {
f838dac4 225 myMainPM->Unhighlight (theObj);
8e5fb5ea 226 theObj->ClearSelected();
227 }
228}
229
230//=======================================================================
231//function : turnOnSubintensity
232//purpose :
233//=======================================================================
234void AIS_InteractiveContext::turnOnSubintensity (const Handle(AIS_InteractiveObject)& theObject,
235 const Standard_Integer theDispMode,
236 const Standard_Boolean theIsDisplayedOnly) const
237{
f838dac4 238 // the only differ with selection highlight is color, so sync transparency values
239 const Handle(Prs3d_Drawer)& aSubStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity];
240 aSubStyle->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
8e5fb5ea 241
242 if (theObject.IsNull())
243 {
244 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjsIter (myObjects); anObjsIter.More(); anObjsIter.Next())
245 {
246 const Handle(AIS_GlobalStatus)& aStatus = anObjsIter.Value();
247 if (aStatus->GraphicStatus() != AIS_DS_Displayed && theIsDisplayedOnly)
248 continue;
249
250 aStatus->SubIntensityOn();
f838dac4 251 myMainPM->Color (anObjsIter.Key(), aSubStyle, theDispMode != -1 ? theDispMode : aStatus->DisplayMode());
8e5fb5ea 252 }
253 }
254 else
255 {
256 Handle(AIS_GlobalStatus) aStatus;
257 if (!myObjects.Find (theObject, aStatus))
258 return;
259
260 if (aStatus->GraphicStatus() != AIS_DS_Displayed && theIsDisplayedOnly)
f838dac4 261 return;
8e5fb5ea 262
263 aStatus->SubIntensityOn();
f838dac4 264 myMainPM->Color (theObject, aSubStyle, theDispMode != -1 ? theDispMode : aStatus->DisplayMode());
8e5fb5ea 265 }
266}
267
268//=======================================================================
269//function : highlightWithSubintensity
270//purpose :
271//=======================================================================
272void AIS_InteractiveContext::highlightWithSubintensity (const Handle(AIS_InteractiveObject)& theObject,
273 const Standard_Integer theMode) const
274{
275 // the only differ with selection highlight is color, so
276 // sync transparency values
f838dac4 277 myStyles[Prs3d_TypeOfHighlight_SubIntensity]->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
8e5fb5ea 278
f838dac4 279 myMainPM->Color (theObject, myStyles[Prs3d_TypeOfHighlight_SubIntensity], theMode);
8e5fb5ea 280}
281
282//=======================================================================
283//function : highlightWithSubintensity
284//purpose :
285//=======================================================================
286void AIS_InteractiveContext::highlightWithSubintensity (const Handle(SelectMgr_EntityOwner)& theOwner,
287 const Standard_Integer theMode) const
288{
289 // the only differ with selection highlight is color, so
290 // sync transparency values
f838dac4 291 myStyles[Prs3d_TypeOfHighlight_SubIntensity]->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
8e5fb5ea 292
f838dac4 293 theOwner->HilightWithColor (myMainPM, myStyles[Prs3d_TypeOfHighlight_SubIntensity], theMode);
8e5fb5ea 294}
295
7fd59977 296//=======================================================================
297//function : MoveTo
679ecdee 298//purpose :
7fd59977 299//=======================================================================
679ecdee 300AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const Standard_Integer theXPix,
301 const Standard_Integer theYPix,
302 const Handle(V3d_View)& theView,
303 const Standard_Boolean theToRedrawOnUpdate)
7fd59977 304{
8c088c52 305 if (theView->Viewer() != myMainVwr)
306 {
307 throw Standard_ProgramError ("AIS_InteractiveContext::MoveTo() - invalid argument");
308 }
309
f0cddd16 310 myCurDetected = 0;
311 myCurHighlighted = 0;
312 myDetectedSeq.Clear();
7fd59977 313
679ecdee 314 // preliminaires
315 myLastPicked = myLastinMain;
316 myWasLastMain = Standard_True;
317 AIS_StatusOfDetection aStatus = AIS_SOD_Nothing;
318 Standard_Boolean toUpdateViewer = Standard_False;
319
a272ed94 320 myFilters->SetDisabledObjects (theView->View()->HiddenObjects());
679ecdee 321 myMainSel->Pick (theXPix, theYPix, theView);
322
323 // filling of myAISDetectedSeq sequence storing information about detected AIS objects
324 // (the objects must be AIS_Shapes)
325 const Standard_Integer aDetectedNb = myMainSel->NbPicked();
54a16ee4 326 Standard_Integer aNewDetected = 0;
14c4193d 327 Standard_Boolean toIgnoreDetTop = Standard_False;
679ecdee 328 for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
7fd59977 329 {
679ecdee 330 Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aDetIter);
331 if (anOwner.IsNull()
332 || !myFilters->IsOk (anOwner))
333 {
14c4193d 334 if (myPickingStrategy == SelectMgr_PickingStrategy_OnlyTopmost)
335 {
336 toIgnoreDetTop = Standard_True;
337 }
679ecdee 338 continue;
339 }
340
14c4193d 341 if (aNewDetected < 1
342 && !toIgnoreDetTop)
54a16ee4 343 {
344 aNewDetected = aDetIter;
345 }
f0cddd16 346
347 myDetectedSeq.Append (aDetIter);
7fd59977 348 }
7fd59977 349
54a16ee4 350 if (aNewDetected >= 1)
7fd59977 351 {
f0cddd16 352 myCurHighlighted = myDetectedSeq.Lower();
353
29627b4c 354 // Does nothing if previously detected object is equal to the current one.
355 // However in advanced selection modes the owners comparison
356 // is not effective because in that case only one owner manage the
357 // selection in current selection mode. It is necessary to check the current detected
358 // entity and hilight it only if the detected entity is not the same as
359 // previous detected (IsForcedHilight call)
54a16ee4 360 Handle(SelectMgr_EntityOwner) aNewPickedOwner = myMainSel->Picked (aNewDetected);
29627b4c 361 if (aNewPickedOwner == myLastPicked && !aNewPickedOwner->IsForcedHilight())
eafb234b 362 {
c3282ec1 363 return myLastPicked->IsSelected()
8abada55 364 ? AIS_SOD_Selected
365 : AIS_SOD_OnlyOneDetected;
679ecdee 366 }
81bba717 367
7fd59977 368 // Previously detected object is unhilighted if it is not selected or hilighted
369 // with selection color if it is selected. Such highlighting with selection color
370 // is needed only if myToHilightSelected flag is true. In this case previously detected
371 // object has been already highlighted with myHilightColor during previous MoveTo()
372 // method call. As result it is necessary to rehighligt it with mySelectionColor.
c3282ec1 373 if (!myLastPicked.IsNull() && myLastPicked->HasSelectable())
7fd59977 374 {
731c9b5b 375 clearDynamicHighlight();
376 toUpdateViewer = Standard_True;
7fd59977 377 }
be6e564e 378
679ecdee 379 // initialize myLastPicked field with currently detected object
c3282ec1 380 myLastPicked = aNewPickedOwner;
679ecdee 381 myLastinMain = myLastPicked;
be6e564e 382
679ecdee 383 // highlight detected object if it is not selected or myToHilightSelected flag is true
c3282ec1 384 if (myLastPicked->HasSelectable())
7fd59977 385 {
c3282ec1 386 if (!myLastPicked->IsSelected() || myToHilightSelected)
679ecdee 387 {
8e5fb5ea 388 highlightWithColor (myLastPicked, theView->Viewer());
679ecdee 389 toUpdateViewer = Standard_True;
390 }
be6e564e 391
c3282ec1 392 aStatus = myLastPicked->IsSelected()
8abada55 393 ? AIS_SOD_Selected
394 : AIS_SOD_OnlyOneDetected;
be6e564e 395 }
7fd59977 396 }
c3282ec1 397 else
7fd59977 398 {
679ecdee 399 // previously detected object is unhilighted if it is not selected or hilighted
400 // with selection color if it is selected
401 aStatus = AIS_SOD_Nothing;
c3282ec1 402 if (!myLastPicked.IsNull() && myLastPicked->HasSelectable())
7fd59977 403 {
731c9b5b 404 clearDynamicHighlight();
405 toUpdateViewer = Standard_True;
7fd59977 406 }
be6e564e 407
679ecdee 408 myLastinMain.Nullify();
8abada55 409 myLastPicked.Nullify();
7fd59977 410 }
679ecdee 411
2eea6525 412 if (toUpdateViewer
413 && theToRedrawOnUpdate)
679ecdee 414 {
2eea6525 415 theView->Viewer()->Update();
679ecdee 416 }
417
679ecdee 418 return aStatus;
7fd59977 419}
420
016e5959 421//=======================================================================
422//function : AddSelect
423//purpose :
424//=======================================================================
02974a19 425AIS_StatusOfPick AIS_InteractiveContext::AddSelect (const Handle(SelectMgr_EntityOwner)& theObject)
016e5959 426{
016e5959 427 mySelection->AddSelect (theObject);
428
429 Standard_Integer aSelNum = NbSelected();
430 return (aSelNum == 0) ? AIS_SOP_NothingSelected
431 : (aSelNum == 1) ? AIS_SOP_OneSelected
432 : AIS_SOP_SeveralSelected;
433}
434
7fd59977 435//=======================================================================
436//function : Select
437//purpose :
438//=======================================================================
c398b00e 439AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Integer theXPMin,
440 const Standard_Integer theYPMin,
441 const Standard_Integer theXPMax,
442 const Standard_Integer theYPMax,
443 const Handle(V3d_View)& theView,
444 const Standard_Boolean toUpdateViewer)
7fd59977 445{
8c088c52 446 if (theView->Viewer() != myMainVwr)
447 {
448 throw Standard_ProgramError ("AIS_InteractiveContext::Select() - invalid argument");
449 }
450
81bba717 451 // all objects detected by the selector are taken, previous current objects are emptied,
452 // new objects are put...
c3282ec1 453 ClearSelected (Standard_False);
8c088c52 454 myWasLastMain = Standard_True;
455 myMainSel->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
456 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
7fd59977 457 {
8c088c52 458 const Handle(SelectMgr_EntityOwner)& aCurOwner = myMainSel->Picked (aPickIter);
c3282ec1 459 if (aCurOwner.IsNull() || !aCurOwner->HasSelectable() || !myFilters->IsOk (aCurOwner))
460 continue;
7fd59977 461
016e5959 462 mySelection->Select (aCurOwner);
f838dac4 463 aCurOwner->SetSelected (Standard_True);
c398b00e 464 }
465
68dcee02 466 if (myAutoHilight)
467 {
468 HilightSelected (toUpdateViewer);
469 }
c398b00e 470
c3282ec1 471 Standard_Integer aSelNum = NbSelected();
c398b00e 472
473 return (aSelNum == 0) ? AIS_SOP_NothingSelected
474 : (aSelNum == 1) ? AIS_SOP_OneSelected
475 : AIS_SOP_SeveralSelected;
7fd59977 476
477}
478
479//=======================================================================
480//function : Select
481//purpose : Selection by polyline
482//=======================================================================
c398b00e 483AIS_StatusOfPick AIS_InteractiveContext::Select (const TColgp_Array1OfPnt2d& thePolyline,
484 const Handle(V3d_View)& theView,
485 const Standard_Boolean toUpdateViewer)
7fd59977 486{
8c088c52 487 if (theView->Viewer() != myMainVwr)
488 {
489 throw Standard_ProgramError ("AIS_InteractiveContext::Select() - invalid argument");
490 }
491
81bba717 492 // all objects detected by the selector are taken, previous current objects are emptied,
493 // new objects are put...
c3282ec1 494 ClearSelected (Standard_False);
8c088c52 495 myWasLastMain = Standard_True;
496 myMainSel->Pick (thePolyline, theView);
497 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
7fd59977 498 {
8c088c52 499 const Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aPickIter);
c3282ec1 500 if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner))
501 continue;
c398b00e 502
016e5959 503 mySelection->Select (anOwner);
f838dac4 504 anOwner->SetSelected (Standard_True);
c398b00e 505 }
506
68dcee02 507 if (myAutoHilight)
508 {
509 HilightSelected (toUpdateViewer);
510 }
c398b00e 511
c3282ec1 512 Standard_Integer aSelNum = NbSelected();
c398b00e 513
514 return (aSelNum == 0) ? AIS_SOP_NothingSelected
515 : (aSelNum == 1) ? AIS_SOP_OneSelected
516 : AIS_SOP_SeveralSelected;
7fd59977 517
518}
519
520//=======================================================================
521//function : Select
522//purpose :
523//=======================================================================
c398b00e 524AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean toUpdateViewer)
7fd59977 525{
68dcee02 526 if (myAutoHilight)
c398b00e 527 {
68dcee02 528 clearDynamicHighlight();
c398b00e 529 }
c398b00e 530 if (myWasLastMain && !myLastinMain.IsNull())
531 {
780ee4e2 532 if (!myLastinMain->IsSelected()
533 || myLastinMain->IsForcedHilight()
534 || NbSelected() > 1)
c398b00e 535 {
c3282ec1 536 SetSelected (myLastinMain, Standard_False);
c398b00e 537 if(toUpdateViewer)
7fd59977 538 {
c398b00e 539 UpdateCurrentViewer();
7fd59977 540 }
c398b00e 541 }
7fd59977 542 }
c398b00e 543 else
544 {
68dcee02 545 if (myAutoHilight)
546 {
547 unhighlightSelected (Standard_True);
548 }
c398b00e 549
02974a19 550 mySelection->Clear();
c398b00e 551 if (toUpdateViewer && myWasLastMain)
552 {
eb4320f2 553 UpdateCurrentViewer();
7fd59977 554 }
555 }
c398b00e 556
c3282ec1 557 Standard_Integer aSelNum = NbSelected();
c398b00e 558
559 return (aSelNum == 0) ? AIS_SOP_NothingSelected
560 : (aSelNum == 1) ? AIS_SOP_OneSelected
561 : AIS_SOP_SeveralSelected;
7fd59977 562}
563
564//=======================================================================
565//function : ShiftSelect
566//purpose :
567//=======================================================================
c398b00e 568AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Boolean toUpdateViewer)
7fd59977 569{
68dcee02 570 if (myAutoHilight)
c398b00e 571 {
68dcee02 572 clearDynamicHighlight();
7fd59977 573 }
c398b00e 574 if (myWasLastMain && !myLastinMain.IsNull())
575 {
c3282ec1 576 AddOrRemoveSelected (myLastinMain, toUpdateViewer);
c398b00e 577 }
7fd59977 578
c3282ec1 579 Standard_Integer aSelNum = NbSelected();
c398b00e 580
c3282ec1 581 return (aSelNum == 0) ? AIS_SOP_NothingSelected
582 : (aSelNum == 1) ? AIS_SOP_OneSelected
583 : AIS_SOP_SeveralSelected;
c398b00e 584}
7fd59977 585
586//=======================================================================
587//function : ShiftSelect
588//purpose :
589//=======================================================================
c398b00e 590AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Integer theXPMin,
591 const Standard_Integer theYPMin,
592 const Standard_Integer theXPMax,
593 const Standard_Integer theYPMax,
594 const Handle(V3d_View)& theView,
595 const Standard_Boolean toUpdateViewer)
7fd59977 596{
8c088c52 597 if (theView->Viewer() != myMainVwr)
598 {
599 throw Standard_ProgramError ("AIS_InteractiveContext::ShiftSelect() - invalid argument");
600 }
601
68dcee02 602 if (myAutoHilight)
c398b00e 603 {
68dcee02 604 UnhilightSelected (Standard_False);
c398b00e 605 }
8c088c52 606 myWasLastMain = Standard_True;
607 myMainSel->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
608 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
c398b00e 609 {
8c088c52 610 const Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aPickIter);
c3282ec1 611 if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner))
612 continue;
613
016e5959 614 AIS_SelectStatus aSelStatus = mySelection->Select (anOwner);
f838dac4 615 anOwner->SetSelected (aSelStatus == AIS_SS_Added);
7fd59977 616 }
c398b00e 617
68dcee02 618 if (myAutoHilight)
619 {
620 HilightSelected (toUpdateViewer);
621 }
c398b00e 622
c3282ec1 623 Standard_Integer aSelNum = NbSelected();
c398b00e 624
625 return (aSelNum == 0) ? AIS_SOP_NothingSelected
626 : (aSelNum == 1) ? AIS_SOP_OneSelected
627 : AIS_SOP_SeveralSelected;
628
7fd59977 629}
630
631//=======================================================================
632//function : ShiftSelect
633//purpose :
634//=======================================================================
c398b00e 635AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline,
636 const Handle(V3d_View)& theView,
637 const Standard_Boolean toUpdateViewer)
7fd59977 638{
8c088c52 639 if (theView->Viewer() != myMainVwr)
640 {
641 throw Standard_ProgramError ("AIS_InteractiveContext::ShiftSelect() - invalid argument");
642 }
643
68dcee02 644 if (myAutoHilight)
c398b00e 645 {
68dcee02 646 UnhilightSelected (Standard_False);
c398b00e 647 }
8c088c52 648 myWasLastMain = Standard_True;
649 myMainSel->Pick (thePolyline, theView);
650 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
c398b00e 651 {
8c088c52 652 const Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aPickIter);
c3282ec1 653 if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner))
654 continue;
655
016e5959 656 AIS_SelectStatus aSelStatus = mySelection->Select (anOwner);
f838dac4 657 anOwner->SetSelected (aSelStatus == AIS_SS_Added);
c398b00e 658 }
659
68dcee02 660 if (myAutoHilight)
661 {
662 HilightSelected (toUpdateViewer);
663 }
c398b00e 664
c3282ec1 665 Standard_Integer aSelNum = NbSelected();
c398b00e 666
667 return (aSelNum == 0) ? AIS_SOP_NothingSelected
668 : (aSelNum == 1) ? AIS_SOP_OneSelected
669 : AIS_SOP_SeveralSelected;
7fd59977 670}
671
7fd59977 672//=======================================================================
673//function : HilightSelected
c3282ec1 674//purpose :
7fd59977 675//=======================================================================
c3282ec1 676void AIS_InteractiveContext::HilightSelected (const Standard_Boolean theToUpdateViewer)
7fd59977 677{
c3282ec1 678 // In case of selection without using local context
731c9b5b 679 clearDynamicHighlight();
c3282ec1 680 AIS_MapOfObjSelectedOwners anObjOwnerMap;
02974a19 681 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
c3282ec1 682 {
02974a19 683 const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value();
684 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
f838dac4 685 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObj, anOwner);
686 Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind(anObj);
02974a19 687 if (anOwner == anObj->GlobalSelOwner())
c3282ec1 688 {
02974a19 689 aState->SetHilightStatus (Standard_True);
8e5fb5ea 690 aState->SetHilightStyle (anObjSelStyle);
02974a19 691 }
f838dac4 692 anOwner->SetSelected (Standard_True);
02974a19 693 if (!anOwner->IsAutoHilight())
694 {
695 NCollection_Handle<SelectMgr_SequenceOfOwner> aSeq;
696 if (anObjOwnerMap.Find (anObj, aSeq))
c3282ec1 697 {
02974a19 698 aSeq->Append (anOwner);
c3282ec1 699 }
700 else
701 {
02974a19 702 aSeq = new SelectMgr_SequenceOfOwner();
703 aSeq->Append (anOwner);
704 anObjOwnerMap.Bind (anObj, aSeq);
c3282ec1 705 }
7fd59977 706 }
02974a19 707 else
708 {
f838dac4 709 const Standard_Integer aHiMode = getHilightMode (anObj, anObjSelStyle, aState->DisplayMode());
8e5fb5ea 710 anOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode);
02974a19 711 }
7fd59977 712 }
c3282ec1 713
714 if (!anObjOwnerMap.IsEmpty())
715 {
716 for (AIS_MapOfObjSelectedOwners::Iterator anIter (anObjOwnerMap); anIter.More(); anIter.Next())
7fd59977 717 {
c3282ec1 718 anIter.Key()->HilightSelected (myMainPM, *anIter.Value());
7fd59977 719 }
c3282ec1 720 anObjOwnerMap.Clear();
721 }
722
723 if (theToUpdateViewer)
7fd59977 724 UpdateCurrentViewer();
725}
726
727//=======================================================================
728//function : UnhilightSelected
c3282ec1 729//purpose :
7fd59977 730//=======================================================================
c3282ec1 731void AIS_InteractiveContext::UnhilightSelected (const Standard_Boolean theToUpdateViewer)
7fd59977 732{
02974a19 733 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
c3282ec1 734 {
02974a19 735 const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value();
736 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
737 if (anOwner == anObj->GlobalSelOwner())
7fd59977 738 {
02974a19 739 myObjects.ChangeFind (anObj)->SetHilightStatus (Standard_False);
7fd59977 740 }
02974a19 741
f838dac4 742 anOwner->SetSelected (Standard_False);
743 anOwner->Unhilight (myMainPM);
c3282ec1 744 }
745
746 if (theToUpdateViewer)
747 UpdateCurrentViewer();
7fd59977 748}
749
750
751//=======================================================================
752//function : ClearSelected
c3282ec1 753//purpose :
7fd59977 754//=======================================================================
c3282ec1 755void AIS_InteractiveContext::ClearSelected (const Standard_Boolean theToUpdateViewer)
7fd59977 756{
c3282ec1 757 if (NbSelected() == 0)
758 return;
7fd59977 759
68dcee02 760 if (myAutoHilight)
761 {
762 unhighlightSelected();
763 }
7fd59977 764
02974a19 765 mySelection->Clear();
68dcee02 766 if (myAutoHilight)
c3282ec1 767 {
68dcee02 768 clearDynamicHighlight();
c3282ec1 769 }
7fd59977 770
68dcee02 771 if (theToUpdateViewer)
772 UpdateCurrentViewer();
c3282ec1 773}
774
775//=======================================================================
776//function : SetSelected
777//purpose : Sets the whole object as selected and highlights it with selection color
778//=======================================================================
779void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& theObject,
780 const Standard_Boolean theToUpdateViewer)
7fd59977 781{
c3282ec1 782 if (theObject.IsNull())
f838dac4 783 {
7fd59977 784 return;
f838dac4 785 }
786
787 if (!myObjects.IsBound (theObject))
788 {
c3282ec1 789 Display (theObject, Standard_False);
f838dac4 790 }
b5cce1ab 791
f838dac4 792 Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
793 if (anOwner.IsNull())
794 {
795 return;
796 }
c3282ec1 797
f838dac4 798 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (theObject, anOwner);
68dcee02 799 if (NbSelected() == 1 && myObjects (theObject)->IsHilighted() && myAutoHilight)
c3282ec1 800 {
f838dac4 801 Handle(Prs3d_Drawer) aCustomStyle;
8e5fb5ea 802 if (HighlightStyle (theObject, aCustomStyle))
c3282ec1 803 {
8e5fb5ea 804 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
c3282ec1 805 {
8e5fb5ea 806 HilightWithColor (theObject, anObjSelStyle, theToUpdateViewer);
c3282ec1 807 }
808 }
809 return;
810 }
811
b5cce1ab 812 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
c3282ec1 813 {
b5cce1ab 814 const Handle(SelectMgr_EntityOwner)& aSelOwner = aSelIter.Value();
f838dac4 815 if (!myFilters->IsOk (aSelOwner))
02974a19 816 {
c3282ec1 817 continue;
02974a19 818 }
c3282ec1 819
f838dac4 820 Handle(AIS_InteractiveObject) aSelectable = Handle(AIS_InteractiveObject)::DownCast (aSelOwner->Selectable());
68dcee02 821 if (myAutoHilight)
822 {
823 Unhilight (aSelectable, Standard_False);
824 }
f838dac4 825 aSelOwner->SetSelected (Standard_False);
826 if (aSelOwner == aSelectable->GlobalSelOwner())
e1b01c73 827 {
828 myObjects.ChangeFind (aSelectable)->SetHilightStatus (Standard_False);
829 }
c3282ec1 830 }
831
832 // added to avoid untimely viewer update...
016e5959 833 mySelection->ClearAndSelect (anOwner);
0d5880e1 834
68dcee02 835 if (myAutoHilight)
c3282ec1 836 {
68dcee02 837 Handle(Prs3d_Drawer) aCustomStyle;
838 if (HighlightStyle (theObject, aCustomStyle))
839 {
840 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
841 {
842 HilightWithColor (theObject, anObjSelStyle, Standard_False);
843 }
844 }
845 else
c3282ec1 846 {
8e5fb5ea 847 HilightWithColor (theObject, anObjSelStyle, Standard_False);
c3282ec1 848 }
7fd59977 849 }
f838dac4 850 anOwner->SetSelected (Standard_True);
c3282ec1 851
852 if (theToUpdateViewer)
853 UpdateCurrentViewer();
7fd59977 854}
855
856//=======================================================================
c3282ec1 857//function : SetSelected
858//purpose : Sets the whole object as selected and highlights it with selection color
7fd59977 859//=======================================================================
c3282ec1 860void AIS_InteractiveContext::SetSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
861 const Standard_Boolean theToUpdateViewer)
7fd59977 862{
b4006117 863 if (theOwner.IsNull() || !theOwner->HasSelectable() || !myFilters->IsOk (theOwner))
c3282ec1 864 return;
865
f838dac4 866 const Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
867 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObject, theOwner);
731c9b5b 868 if (NbSelected() == 1 && theOwner->IsSelected() && !theOwner->IsForcedHilight())
c3282ec1 869 {
f838dac4 870 Handle(Prs3d_Drawer) aCustomStyle;
68dcee02 871 if (myAutoHilight && HighlightStyle (theOwner, aCustomStyle))
c3282ec1 872 {
8e5fb5ea 873 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
c3282ec1 874 {
875 const Standard_Integer aHiMode = anObject->HasHilightMode() ? anObject->HilightMode() : 0;
8e5fb5ea 876 theOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode);
c3282ec1 877 }
878 }
879 return;
880 }
881
882 if (!myObjects.IsBound (anObject))
883 Display (anObject, Standard_False);
884
68dcee02 885 if (myAutoHilight)
886 {
887 unhighlightSelected();
888 }
c3282ec1 889
016e5959 890 mySelection->ClearAndSelect (theOwner);
68dcee02 891 if (myAutoHilight)
c3282ec1 892 {
68dcee02 893 Handle(Prs3d_Drawer) aCustomStyle;
894 if (!HighlightStyle (theOwner, aCustomStyle) ||
895 (!aCustomStyle.IsNull() && aCustomStyle != anObjSelStyle))
896 {
897 theOwner->SetSelected (Standard_True);
898 highlightSelected (theOwner);
899 }
c3282ec1 900 }
901
f838dac4 902 theOwner->SetSelected (Standard_True);
68dcee02 903 if (myAutoHilight && theOwner == anObject->GlobalSelOwner())
e1b01c73 904 {
905 Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind (anObject);
906 aState->SetHilightStatus (Standard_True);
8e5fb5ea 907 aState->SetHilightStyle (anObjSelStyle);
e1b01c73 908 }
909
c3282ec1 910 if (theToUpdateViewer)
911 UpdateCurrentViewer();
7fd59977 912}
913
914//=======================================================================
915//function : AddOrRemoveSelected
c3282ec1 916//purpose : Adds or removes current object from AIS selection and highlights/unhighlights it.
917// Since this method makes sence only for neutral point selection of a whole object,
918// if 0 selection of the object is empty this method simply does nothing.
7fd59977 919//=======================================================================
c3282ec1 920void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(AIS_InteractiveObject)& theObject,
921 const Standard_Boolean theToUpdateViewer)
7fd59977 922{
68dcee02 923 if (theObject.IsNull()
924 || !myObjects.IsBound (theObject))
b5cce1ab 925 {
c3282ec1 926 return;
b5cce1ab 927 }
c3282ec1 928
7411850a 929 const Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
b5cce1ab 930 if (!anOwner.IsNull()
931 && anOwner->HasSelectable())
932 {
933 AddOrRemoveSelected (anOwner, theToUpdateViewer);
934 }
7fd59977 935}
c3282ec1 936
7fd59977 937//=======================================================================
938//function : AddOrRemoveSelected
c3282ec1 939//purpose : Allows to highlight or unhighlight the owner given depending on
940// its selection status
7fd59977 941//=======================================================================
c3282ec1 942void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
943 const Standard_Boolean theToUpdateViewer)
944{
c3282ec1 945 if (theOwner.IsNull() || !theOwner->HasSelectable())
7fd59977 946 return;
c3282ec1 947
4d901cde 948 if (!myFilters->IsOk(theOwner) && !theOwner->IsSelected())
949 return;
950
016e5959 951 AIS_SelectStatus aSelStat = mySelection->Select (theOwner);
f838dac4 952 theOwner->SetSelected (aSelStat == AIS_SS_Added);
68dcee02 953
954 if (myAutoHilight)
c3282ec1 955 {
68dcee02 956 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
957 const Standard_Boolean isGlobal = anObj->GlobalSelOwner() == theOwner;
958 Handle(AIS_GlobalStatus)& aStatus = myObjects.ChangeFind (anObj);
959 if (theOwner->IsSelected())
f838dac4 960 {
68dcee02 961 highlightSelected (theOwner);
962 if (isGlobal)
963 {
964 aStatus->SetHilightStatus (Standard_True);
965 aStatus->SetHilightStyle (getSelStyle (anObj, theOwner));
966 }
f838dac4 967 }
c3282ec1 968 else
f838dac4 969 {
68dcee02 970 if (theOwner->IsAutoHilight())
971 {
972 theOwner->Unhilight (myMainPM);
973 }
974 else
975 {
976 anObj->ClearSelected();
977 }
978 aStatus->SetHilightStatus (Standard_False);
979 aStatus->SetHilightStyle (Handle(Prs3d_Drawer)());
f838dac4 980 }
7fd59977 981 }
7fd59977 982
c3282ec1 983 if (theToUpdateViewer)
984 UpdateCurrentViewer();
985}
7fd59977 986
987
988//=======================================================================
989//function : IsSelected
c3282ec1 990//purpose :
7fd59977 991//=======================================================================
c3282ec1 992Standard_Boolean AIS_InteractiveContext::IsSelected (const Handle(AIS_InteractiveObject)& theObj) const
7fd59977 993{
68dcee02 994 if (theObj.IsNull())
995 {
996 return Standard_False;
997 }
c3282ec1 998
68dcee02 999 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
1000 if (aStatus == NULL)
1001 {
c3282ec1 1002 return Standard_False;
68dcee02 1003 }
c3282ec1 1004
1005 const Standard_Integer aGlobalSelMode = theObj->GlobalSelectionMode();
68dcee02 1006 const TColStd_ListOfInteger& anActivatedModes = (*aStatus)->SelectionModes();
c3282ec1 1007 for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next())
1008 {
1009 if (aModeIter.Value() == aGlobalSelMode)
1010 {
b5cce1ab 1011 if (Handle(SelectMgr_EntityOwner) aGlobOwner = theObj->GlobalSelOwner())
1012 {
1013 return aGlobOwner->IsSelected();
1014 }
1015 return Standard_False;
c3282ec1 1016 }
1017 }
b5cce1ab 1018 return Standard_False;
7fd59977 1019}
1020
c3282ec1 1021//=======================================================================
68dcee02 1022//function : FirstSelectedObject
c3282ec1 1023//purpose :
7fd59977 1024//=======================================================================
68dcee02 1025Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstSelectedObject() const
7fd59977 1026{
68dcee02 1027 return !mySelection->Objects().IsEmpty()
1028 ? Handle(AIS_InteractiveObject)::DownCast (mySelection->Objects().First()->Selectable())
1029 : Handle(AIS_InteractiveObject)();
7fd59977 1030}
1031
1032//=======================================================================
1033//function : HasSelectedShape
c3282ec1 1034//purpose :
7fd59977 1035//=======================================================================
c3282ec1 1036Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
7fd59977 1037{
4aaadad7
SS
1038 if (!mySelection->More())
1039 return Standard_False;
1040
68dcee02 1041 const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
4aaadad7 1042 return !anOwner.IsNull() && anOwner->HasShape();
7fd59977 1043}
1044
1045//=======================================================================
1046//function : SelectedShape
c3282ec1 1047//purpose :
7fd59977 1048//=======================================================================
c3282ec1 1049TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
7fd59977 1050{
02974a19 1051 if (!mySelection->More())
c3282ec1 1052 return TopoDS_Shape();
7fd59977 1053
68dcee02 1054 const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
3475df12 1055 if (anOwner.IsNull() || !anOwner->HasSelectable())
c3282ec1 1056 return TopoDS_Shape();
1057
1058 return anOwner->Shape().Located (anOwner->Location() * anOwner->Shape().Location());
7fd59977 1059}
1060
7fd59977 1061//=======================================================================
1062//function : EntityOwners
1063//purpose :
1064//=======================================================================
b586500b 1065void AIS_InteractiveContext::EntityOwners(Handle(SelectMgr_IndexedMapOfOwner)& theOwners,
7fd59977 1066 const Handle(AIS_InteractiveObject)& theIObj,
1067 const Standard_Integer theMode) const
1068{
b5cce1ab 1069 if (theIObj.IsNull())
1070 {
1071 return;
1072 }
7fd59977 1073
1074 TColStd_ListOfInteger aModes;
b5cce1ab 1075 if (theMode == -1)
1076 {
1077 ActivatedModes (theIObj, aModes);
1078 }
7fd59977 1079 else
b5cce1ab 1080 {
1081 aModes.Append (theMode);
1082 }
7fd59977 1083
b586500b 1084 if (theOwners.IsNull())
b5cce1ab 1085 {
b586500b 1086 theOwners = new SelectMgr_IndexedMapOfOwner();
b5cce1ab 1087 }
b586500b 1088
b5cce1ab 1089 for (TColStd_ListIteratorOfListOfInteger anItr (aModes); anItr.More(); anItr.Next())
7fd59977 1090 {
b5cce1ab 1091 const int aMode = anItr.Value();
1092 const Handle(SelectMgr_Selection)& aSel = theIObj->Selection (aMode);
1093 if (aSel.IsNull())
1094 {
7fd59977 1095 continue;
b5cce1ab 1096 }
7fd59977 1097
b5cce1ab 1098 for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (aSel->Entities()); aSelEntIter.More(); aSelEntIter.Next())
7fd59977 1099 {
b5cce1ab 1100 if (Handle(SelectBasics_SensitiveEntity) aEntity = aSelEntIter.Value()->BaseSensitive())
1101 {
1102 if (Handle(SelectMgr_EntityOwner) aOwner = Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId()))
1103 {
1104 theOwners->Add (aOwner);
1105 }
1106 }
7fd59977 1107 }
1108 }
1109}
1110
7fd59977 1111//=======================================================================
1112//function : HasDetectedShape
1113//purpose :
1114//=======================================================================
7fd59977 1115Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
1116{
8c088c52 1117 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked);
1118 return !anOwner.IsNull()
1119 && anOwner->HasShape();
7fd59977 1120}
1121
1122//=======================================================================
1123//function : DetectedShape
1124//purpose :
1125//=======================================================================
8c088c52 1126const TopoDS_Shape& AIS_InteractiveContext::DetectedShape() const
7fd59977 1127{
8c088c52 1128 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked);
1129 return anOwner->Shape();
1130}
7fd59977 1131
7fd59977 1132//=======================================================================
1133//function : HilightNextDetected
679ecdee 1134//purpose :
7fd59977 1135//=======================================================================
679ecdee 1136Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView,
1137 const Standard_Boolean theToRedrawImmediate)
7fd59977 1138{
f0cddd16 1139 myMainPM->ClearImmediateDraw();
1140 if (myDetectedSeq.IsEmpty())
1141 {
1142 return 0;
1143 }
1144
1145 if (++myCurHighlighted > myDetectedSeq.Upper())
1146 {
1147 myCurHighlighted = myDetectedSeq.Lower();
1148 }
1149 const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted));
1150 if (anOwner.IsNull())
1151 {
1152 return 0;
1153 }
1154
1155 highlightWithColor (anOwner, theView->Viewer());
1156 myLastPicked = anOwner;
1157 myLastinMain = myLastPicked;
1158
1159 if (theToRedrawImmediate)
1160 {
1161 myMainPM->RedrawImmediate (theView->Viewer());
1162 myMainVwr->RedrawImmediate();
1163 }
1164
1165 return myCurHighlighted;
7fd59977 1166}
1167
1168//=======================================================================
f0cddd16 1169//function : HilightPreviousDetected
679ecdee 1170//purpose :
7fd59977 1171//=======================================================================
679ecdee 1172Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1173 const Standard_Boolean theToRedrawImmediate)
7fd59977 1174{
f0cddd16 1175 myMainPM->ClearImmediateDraw();
1176 if (myDetectedSeq.IsEmpty())
1177 {
1178 return 0;
1179 }
1180
1181 if (--myCurHighlighted < myDetectedSeq.Lower())
1182 {
1183 myCurHighlighted = myDetectedSeq.Upper();
1184 }
1185 const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted));
1186 if (anOwner.IsNull())
1187 {
1188 return 0;
1189 }
1190
1191 highlightWithColor (anOwner, theView->Viewer());
1192 myLastPicked = anOwner;
1193 myLastinMain = myLastPicked;
1194
1195 if (theToRedrawImmediate)
1196 {
1197 myMainPM->RedrawImmediate (theView->Viewer());
1198 myMainVwr->RedrawImmediate();
1199 }
1200
1201 return myCurHighlighted;
7fd59977 1202}
1203
7fd59977 1204//=======================================================================
d21ddc4f 1205//function : DetectedCurrentOwner
1206//purpose :
1207//=======================================================================
1208Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedCurrentOwner() const
1209{
d21ddc4f 1210 return MoreDetected()
1211 ? myMainSel->Picked (myDetectedSeq (myCurDetected))
1212 : Handle(SelectMgr_EntityOwner)();
1213}
1214
1215//=======================================================================
7fd59977 1216//function : DetectedCurrentShape
1217//purpose :
1218//=======================================================================
7fd59977 1219const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
1220{
404c8936 1221 Standard_DISABLE_DEPRECATION_WARNINGS
57ad5cbd 1222 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
404c8936 1223 Standard_ENABLE_DEPRECATION_WARNINGS
8c088c52 1224 return !aCurrentShape.IsNull()
1225 ? aCurrentShape->Shape()
1226 : AIS_InteractiveContext_myDummyShape;
7fd59977 1227}
1228
1229//=======================================================================
1230//function : DetectedCurrentObject
1231//purpose :
1232//=======================================================================
57ad5cbd 1233Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const
1234{
f0cddd16 1235 return MoreDetected()
8c088c52 1236 ? Handle(AIS_InteractiveObject)::DownCast (myMainSel->Picked (myDetectedSeq (myCurDetected))->Selectable())
1237 : Handle(AIS_InteractiveObject)();
7fd59977 1238}