0030450: Visualization - AIS_InteractiveContext::MoveTo() never uses V3d_View::Immedi...
[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
7fd59977 154//=======================================================================
b4006117 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
201//=======================================================================
8e5fb5ea 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
296//=======================================================================
7fd59977 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 {
be3d8cbc 386 if (myAutoHilight
387 && (!myLastPicked->IsSelected()
388 || myToHilightSelected))
679ecdee 389 {
8e5fb5ea 390 highlightWithColor (myLastPicked, theView->Viewer());
679ecdee 391 toUpdateViewer = Standard_True;
392 }
be6e564e 393
c3282ec1 394 aStatus = myLastPicked->IsSelected()
8abada55 395 ? AIS_SOD_Selected
396 : AIS_SOD_OnlyOneDetected;
be6e564e 397 }
7fd59977 398 }
c3282ec1 399 else
7fd59977 400 {
679ecdee 401 // previously detected object is unhilighted if it is not selected or hilighted
402 // with selection color if it is selected
403 aStatus = AIS_SOD_Nothing;
be3d8cbc 404 if (myAutoHilight
405 && !myLastPicked.IsNull()
406 && myLastPicked->HasSelectable())
7fd59977 407 {
731c9b5b 408 clearDynamicHighlight();
409 toUpdateViewer = Standard_True;
7fd59977 410 }
be6e564e 411
679ecdee 412 myLastinMain.Nullify();
8abada55 413 myLastPicked.Nullify();
7fd59977 414 }
679ecdee 415
2eea6525 416 if (toUpdateViewer
417 && theToRedrawOnUpdate)
679ecdee 418 {
c29c0ad0 419 if (theView->ComputedMode())
420 {
421 theView->Viewer()->Update();
422 }
423 else
424 {
425 theView->Viewer()->RedrawImmediate();
426 }
679ecdee 427 }
428
679ecdee 429 return aStatus;
7fd59977 430}
431
432//=======================================================================
016e5959 433//function : AddSelect
434//purpose :
435//=======================================================================
02974a19 436AIS_StatusOfPick AIS_InteractiveContext::AddSelect (const Handle(SelectMgr_EntityOwner)& theObject)
016e5959 437{
016e5959 438 mySelection->AddSelect (theObject);
439
440 Standard_Integer aSelNum = NbSelected();
441 return (aSelNum == 0) ? AIS_SOP_NothingSelected
442 : (aSelNum == 1) ? AIS_SOP_OneSelected
443 : AIS_SOP_SeveralSelected;
444}
445
446//=======================================================================
7fd59977 447//function : Select
448//purpose :
449//=======================================================================
c398b00e 450AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Integer theXPMin,
451 const Standard_Integer theYPMin,
452 const Standard_Integer theXPMax,
453 const Standard_Integer theYPMax,
454 const Handle(V3d_View)& theView,
455 const Standard_Boolean toUpdateViewer)
7fd59977 456{
8c088c52 457 if (theView->Viewer() != myMainVwr)
458 {
459 throw Standard_ProgramError ("AIS_InteractiveContext::Select() - invalid argument");
460 }
461
81bba717 462 // all objects detected by the selector are taken, previous current objects are emptied,
463 // new objects are put...
c3282ec1 464 ClearSelected (Standard_False);
8c088c52 465 myWasLastMain = Standard_True;
466 myMainSel->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
467 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
7fd59977 468 {
8c088c52 469 const Handle(SelectMgr_EntityOwner)& aCurOwner = myMainSel->Picked (aPickIter);
c3282ec1 470 if (aCurOwner.IsNull() || !aCurOwner->HasSelectable() || !myFilters->IsOk (aCurOwner))
471 continue;
7fd59977 472
016e5959 473 mySelection->Select (aCurOwner);
f838dac4 474 aCurOwner->SetSelected (Standard_True);
c398b00e 475 }
476
68dcee02 477 if (myAutoHilight)
478 {
479 HilightSelected (toUpdateViewer);
480 }
c398b00e 481
c3282ec1 482 Standard_Integer aSelNum = NbSelected();
c398b00e 483
484 return (aSelNum == 0) ? AIS_SOP_NothingSelected
485 : (aSelNum == 1) ? AIS_SOP_OneSelected
486 : AIS_SOP_SeveralSelected;
7fd59977 487
488}
489
490//=======================================================================
491//function : Select
492//purpose : Selection by polyline
493//=======================================================================
c398b00e 494AIS_StatusOfPick AIS_InteractiveContext::Select (const TColgp_Array1OfPnt2d& thePolyline,
495 const Handle(V3d_View)& theView,
496 const Standard_Boolean toUpdateViewer)
7fd59977 497{
8c088c52 498 if (theView->Viewer() != myMainVwr)
499 {
500 throw Standard_ProgramError ("AIS_InteractiveContext::Select() - invalid argument");
501 }
502
81bba717 503 // all objects detected by the selector are taken, previous current objects are emptied,
504 // new objects are put...
c3282ec1 505 ClearSelected (Standard_False);
8c088c52 506 myWasLastMain = Standard_True;
507 myMainSel->Pick (thePolyline, theView);
508 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
7fd59977 509 {
8c088c52 510 const Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aPickIter);
c3282ec1 511 if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner))
512 continue;
c398b00e 513
016e5959 514 mySelection->Select (anOwner);
f838dac4 515 anOwner->SetSelected (Standard_True);
c398b00e 516 }
517
68dcee02 518 if (myAutoHilight)
519 {
520 HilightSelected (toUpdateViewer);
521 }
c398b00e 522
c3282ec1 523 Standard_Integer aSelNum = NbSelected();
c398b00e 524
525 return (aSelNum == 0) ? AIS_SOP_NothingSelected
526 : (aSelNum == 1) ? AIS_SOP_OneSelected
527 : AIS_SOP_SeveralSelected;
7fd59977 528
529}
530
531//=======================================================================
532//function : Select
533//purpose :
534//=======================================================================
c398b00e 535AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean toUpdateViewer)
7fd59977 536{
c398b00e 537 if (myWasLastMain && !myLastinMain.IsNull())
538 {
be3d8cbc 539 if (myAutoHilight)
540 {
541 clearDynamicHighlight();
542 }
780ee4e2 543 if (!myLastinMain->IsSelected()
544 || myLastinMain->IsForcedHilight()
545 || NbSelected() > 1)
c398b00e 546 {
c3282ec1 547 SetSelected (myLastinMain, Standard_False);
c398b00e 548 if(toUpdateViewer)
7fd59977 549 {
c398b00e 550 UpdateCurrentViewer();
7fd59977 551 }
c398b00e 552 }
7fd59977 553 }
c398b00e 554 else
555 {
be3d8cbc 556 ClearSelected (toUpdateViewer);
7fd59977 557 }
c398b00e 558
c3282ec1 559 Standard_Integer aSelNum = NbSelected();
c398b00e 560
561 return (aSelNum == 0) ? AIS_SOP_NothingSelected
562 : (aSelNum == 1) ? AIS_SOP_OneSelected
563 : AIS_SOP_SeveralSelected;
7fd59977 564}
565
566//=======================================================================
567//function : ShiftSelect
568//purpose :
569//=======================================================================
c398b00e 570AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Boolean toUpdateViewer)
7fd59977 571{
68dcee02 572 if (myAutoHilight)
c398b00e 573 {
68dcee02 574 clearDynamicHighlight();
7fd59977 575 }
c398b00e 576 if (myWasLastMain && !myLastinMain.IsNull())
577 {
c3282ec1 578 AddOrRemoveSelected (myLastinMain, toUpdateViewer);
c398b00e 579 }
7fd59977 580
c3282ec1 581 Standard_Integer aSelNum = NbSelected();
c398b00e 582
c3282ec1 583 return (aSelNum == 0) ? AIS_SOP_NothingSelected
584 : (aSelNum == 1) ? AIS_SOP_OneSelected
585 : AIS_SOP_SeveralSelected;
c398b00e 586}
7fd59977 587
588//=======================================================================
589//function : ShiftSelect
590//purpose :
591//=======================================================================
c398b00e 592AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Integer theXPMin,
593 const Standard_Integer theYPMin,
594 const Standard_Integer theXPMax,
595 const Standard_Integer theYPMax,
596 const Handle(V3d_View)& theView,
597 const Standard_Boolean toUpdateViewer)
7fd59977 598{
8c088c52 599 if (theView->Viewer() != myMainVwr)
600 {
601 throw Standard_ProgramError ("AIS_InteractiveContext::ShiftSelect() - invalid argument");
602 }
603
68dcee02 604 if (myAutoHilight)
c398b00e 605 {
68dcee02 606 UnhilightSelected (Standard_False);
c398b00e 607 }
8c088c52 608 myWasLastMain = Standard_True;
609 myMainSel->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
610 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
c398b00e 611 {
8c088c52 612 const Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aPickIter);
c3282ec1 613 if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner))
614 continue;
615
016e5959 616 AIS_SelectStatus aSelStatus = mySelection->Select (anOwner);
f838dac4 617 anOwner->SetSelected (aSelStatus == AIS_SS_Added);
7fd59977 618 }
c398b00e 619
68dcee02 620 if (myAutoHilight)
621 {
622 HilightSelected (toUpdateViewer);
623 }
c398b00e 624
c3282ec1 625 Standard_Integer aSelNum = NbSelected();
c398b00e 626
627 return (aSelNum == 0) ? AIS_SOP_NothingSelected
628 : (aSelNum == 1) ? AIS_SOP_OneSelected
629 : AIS_SOP_SeveralSelected;
630
7fd59977 631}
632
633//=======================================================================
634//function : ShiftSelect
635//purpose :
636//=======================================================================
c398b00e 637AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline,
638 const Handle(V3d_View)& theView,
639 const Standard_Boolean toUpdateViewer)
7fd59977 640{
8c088c52 641 if (theView->Viewer() != myMainVwr)
642 {
643 throw Standard_ProgramError ("AIS_InteractiveContext::ShiftSelect() - invalid argument");
644 }
645
68dcee02 646 if (myAutoHilight)
c398b00e 647 {
68dcee02 648 UnhilightSelected (Standard_False);
c398b00e 649 }
8c088c52 650 myWasLastMain = Standard_True;
651 myMainSel->Pick (thePolyline, theView);
652 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
c398b00e 653 {
8c088c52 654 const Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aPickIter);
c3282ec1 655 if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner))
656 continue;
657
016e5959 658 AIS_SelectStatus aSelStatus = mySelection->Select (anOwner);
f838dac4 659 anOwner->SetSelected (aSelStatus == AIS_SS_Added);
c398b00e 660 }
661
68dcee02 662 if (myAutoHilight)
663 {
664 HilightSelected (toUpdateViewer);
665 }
c398b00e 666
c3282ec1 667 Standard_Integer aSelNum = NbSelected();
c398b00e 668
669 return (aSelNum == 0) ? AIS_SOP_NothingSelected
670 : (aSelNum == 1) ? AIS_SOP_OneSelected
671 : AIS_SOP_SeveralSelected;
7fd59977 672}
673
674//=======================================================================
7fd59977 675//function : HilightSelected
c3282ec1 676//purpose :
7fd59977 677//=======================================================================
c3282ec1 678void AIS_InteractiveContext::HilightSelected (const Standard_Boolean theToUpdateViewer)
7fd59977 679{
c3282ec1 680 // In case of selection without using local context
731c9b5b 681 clearDynamicHighlight();
c3282ec1 682 AIS_MapOfObjSelectedOwners anObjOwnerMap;
02974a19 683 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
c3282ec1 684 {
02974a19 685 const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value();
686 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
f838dac4 687 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObj, anOwner);
688 Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind(anObj);
02974a19 689 if (anOwner == anObj->GlobalSelOwner())
c3282ec1 690 {
02974a19 691 aState->SetHilightStatus (Standard_True);
8e5fb5ea 692 aState->SetHilightStyle (anObjSelStyle);
02974a19 693 }
f838dac4 694 anOwner->SetSelected (Standard_True);
02974a19 695 if (!anOwner->IsAutoHilight())
696 {
697 NCollection_Handle<SelectMgr_SequenceOfOwner> aSeq;
698 if (anObjOwnerMap.Find (anObj, aSeq))
c3282ec1 699 {
02974a19 700 aSeq->Append (anOwner);
c3282ec1 701 }
702 else
703 {
02974a19 704 aSeq = new SelectMgr_SequenceOfOwner();
705 aSeq->Append (anOwner);
706 anObjOwnerMap.Bind (anObj, aSeq);
c3282ec1 707 }
7fd59977 708 }
02974a19 709 else
710 {
f838dac4 711 const Standard_Integer aHiMode = getHilightMode (anObj, anObjSelStyle, aState->DisplayMode());
8e5fb5ea 712 anOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode);
02974a19 713 }
7fd59977 714 }
c3282ec1 715
716 if (!anObjOwnerMap.IsEmpty())
717 {
718 for (AIS_MapOfObjSelectedOwners::Iterator anIter (anObjOwnerMap); anIter.More(); anIter.Next())
7fd59977 719 {
c3282ec1 720 anIter.Key()->HilightSelected (myMainPM, *anIter.Value());
7fd59977 721 }
c3282ec1 722 anObjOwnerMap.Clear();
723 }
724
725 if (theToUpdateViewer)
7fd59977 726 UpdateCurrentViewer();
727}
728
729//=======================================================================
730//function : UnhilightSelected
c3282ec1 731//purpose :
7fd59977 732//=======================================================================
c3282ec1 733void AIS_InteractiveContext::UnhilightSelected (const Standard_Boolean theToUpdateViewer)
7fd59977 734{
02974a19 735 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
c3282ec1 736 {
02974a19 737 const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value();
738 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
739 if (anOwner == anObj->GlobalSelOwner())
7fd59977 740 {
02974a19 741 myObjects.ChangeFind (anObj)->SetHilightStatus (Standard_False);
7fd59977 742 }
02974a19 743
f838dac4 744 anOwner->SetSelected (Standard_False);
745 anOwner->Unhilight (myMainPM);
c3282ec1 746 }
747
748 if (theToUpdateViewer)
749 UpdateCurrentViewer();
7fd59977 750}
751
752
753//=======================================================================
754//function : ClearSelected
c3282ec1 755//purpose :
7fd59977 756//=======================================================================
c3282ec1 757void AIS_InteractiveContext::ClearSelected (const Standard_Boolean theToUpdateViewer)
7fd59977 758{
c3282ec1 759 if (NbSelected() == 0)
760 return;
7fd59977 761
68dcee02 762 if (myAutoHilight)
763 {
764 unhighlightSelected();
765 }
be3d8cbc 766 else
767 {
768 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
769 {
770 aSelIter.Value()->SetSelected (Standard_False);
771 }
772 }
7fd59977 773
02974a19 774 mySelection->Clear();
68dcee02 775 if (myAutoHilight)
c3282ec1 776 {
68dcee02 777 clearDynamicHighlight();
c3282ec1 778 }
7fd59977 779
68dcee02 780 if (theToUpdateViewer)
781 UpdateCurrentViewer();
c3282ec1 782}
783
784//=======================================================================
785//function : SetSelected
786//purpose : Sets the whole object as selected and highlights it with selection color
787//=======================================================================
788void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& theObject,
789 const Standard_Boolean theToUpdateViewer)
7fd59977 790{
c3282ec1 791 if (theObject.IsNull())
f838dac4 792 {
7fd59977 793 return;
f838dac4 794 }
795
796 if (!myObjects.IsBound (theObject))
797 {
c3282ec1 798 Display (theObject, Standard_False);
f838dac4 799 }
b5cce1ab 800
f838dac4 801 Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
802 if (anOwner.IsNull())
803 {
804 return;
805 }
c3282ec1 806
f838dac4 807 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (theObject, anOwner);
68dcee02 808 if (NbSelected() == 1 && myObjects (theObject)->IsHilighted() && myAutoHilight)
c3282ec1 809 {
f838dac4 810 Handle(Prs3d_Drawer) aCustomStyle;
8e5fb5ea 811 if (HighlightStyle (theObject, aCustomStyle))
c3282ec1 812 {
8e5fb5ea 813 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
c3282ec1 814 {
8e5fb5ea 815 HilightWithColor (theObject, anObjSelStyle, theToUpdateViewer);
c3282ec1 816 }
817 }
818 return;
819 }
820
b5cce1ab 821 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
c3282ec1 822 {
b5cce1ab 823 const Handle(SelectMgr_EntityOwner)& aSelOwner = aSelIter.Value();
f838dac4 824 if (!myFilters->IsOk (aSelOwner))
02974a19 825 {
c3282ec1 826 continue;
02974a19 827 }
c3282ec1 828
f838dac4 829 Handle(AIS_InteractiveObject) aSelectable = Handle(AIS_InteractiveObject)::DownCast (aSelOwner->Selectable());
68dcee02 830 if (myAutoHilight)
831 {
832 Unhilight (aSelectable, Standard_False);
833 }
f838dac4 834 aSelOwner->SetSelected (Standard_False);
835 if (aSelOwner == aSelectable->GlobalSelOwner())
e1b01c73 836 {
837 myObjects.ChangeFind (aSelectable)->SetHilightStatus (Standard_False);
838 }
c3282ec1 839 }
840
841 // added to avoid untimely viewer update...
016e5959 842 mySelection->ClearAndSelect (anOwner);
0d5880e1 843
68dcee02 844 if (myAutoHilight)
c3282ec1 845 {
68dcee02 846 Handle(Prs3d_Drawer) aCustomStyle;
847 if (HighlightStyle (theObject, aCustomStyle))
848 {
849 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
850 {
851 HilightWithColor (theObject, anObjSelStyle, Standard_False);
852 }
853 }
854 else
c3282ec1 855 {
8e5fb5ea 856 HilightWithColor (theObject, anObjSelStyle, Standard_False);
c3282ec1 857 }
7fd59977 858 }
f838dac4 859 anOwner->SetSelected (Standard_True);
c3282ec1 860
861 if (theToUpdateViewer)
862 UpdateCurrentViewer();
7fd59977 863}
864
865//=======================================================================
c3282ec1 866//function : SetSelected
867//purpose : Sets the whole object as selected and highlights it with selection color
7fd59977 868//=======================================================================
c3282ec1 869void AIS_InteractiveContext::SetSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
870 const Standard_Boolean theToUpdateViewer)
7fd59977 871{
b4006117 872 if (theOwner.IsNull() || !theOwner->HasSelectable() || !myFilters->IsOk (theOwner))
c3282ec1 873 return;
874
f838dac4 875 const Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
876 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObject, theOwner);
731c9b5b 877 if (NbSelected() == 1 && theOwner->IsSelected() && !theOwner->IsForcedHilight())
c3282ec1 878 {
f838dac4 879 Handle(Prs3d_Drawer) aCustomStyle;
68dcee02 880 if (myAutoHilight && HighlightStyle (theOwner, aCustomStyle))
c3282ec1 881 {
8e5fb5ea 882 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
c3282ec1 883 {
884 const Standard_Integer aHiMode = anObject->HasHilightMode() ? anObject->HilightMode() : 0;
8e5fb5ea 885 theOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode);
c3282ec1 886 }
887 }
888 return;
889 }
890
891 if (!myObjects.IsBound (anObject))
892 Display (anObject, Standard_False);
893
68dcee02 894 if (myAutoHilight)
895 {
896 unhighlightSelected();
897 }
c3282ec1 898
016e5959 899 mySelection->ClearAndSelect (theOwner);
68dcee02 900 if (myAutoHilight)
c3282ec1 901 {
68dcee02 902 Handle(Prs3d_Drawer) aCustomStyle;
903 if (!HighlightStyle (theOwner, aCustomStyle) ||
904 (!aCustomStyle.IsNull() && aCustomStyle != anObjSelStyle))
905 {
906 theOwner->SetSelected (Standard_True);
907 highlightSelected (theOwner);
908 }
c3282ec1 909 }
910
f838dac4 911 theOwner->SetSelected (Standard_True);
68dcee02 912 if (myAutoHilight && theOwner == anObject->GlobalSelOwner())
e1b01c73 913 {
914 Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind (anObject);
915 aState->SetHilightStatus (Standard_True);
8e5fb5ea 916 aState->SetHilightStyle (anObjSelStyle);
e1b01c73 917 }
918
c3282ec1 919 if (theToUpdateViewer)
920 UpdateCurrentViewer();
7fd59977 921}
922
923//=======================================================================
924//function : AddOrRemoveSelected
c3282ec1 925//purpose : Adds or removes current object from AIS selection and highlights/unhighlights it.
926// Since this method makes sence only for neutral point selection of a whole object,
927// if 0 selection of the object is empty this method simply does nothing.
7fd59977 928//=======================================================================
c3282ec1 929void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(AIS_InteractiveObject)& theObject,
930 const Standard_Boolean theToUpdateViewer)
7fd59977 931{
68dcee02 932 if (theObject.IsNull()
933 || !myObjects.IsBound (theObject))
b5cce1ab 934 {
c3282ec1 935 return;
b5cce1ab 936 }
c3282ec1 937
7411850a 938 const Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
b5cce1ab 939 if (!anOwner.IsNull()
940 && anOwner->HasSelectable())
941 {
942 AddOrRemoveSelected (anOwner, theToUpdateViewer);
943 }
7fd59977 944}
c3282ec1 945
7fd59977 946//=======================================================================
947//function : AddOrRemoveSelected
c3282ec1 948//purpose : Allows to highlight or unhighlight the owner given depending on
949// its selection status
7fd59977 950//=======================================================================
c3282ec1 951void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
952 const Standard_Boolean theToUpdateViewer)
953{
c3282ec1 954 if (theOwner.IsNull() || !theOwner->HasSelectable())
7fd59977 955 return;
c3282ec1 956
4d901cde 957 if (!myFilters->IsOk(theOwner) && !theOwner->IsSelected())
958 return;
959
016e5959 960 AIS_SelectStatus aSelStat = mySelection->Select (theOwner);
f838dac4 961 theOwner->SetSelected (aSelStat == AIS_SS_Added);
68dcee02 962
963 if (myAutoHilight)
c3282ec1 964 {
68dcee02 965 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
966 const Standard_Boolean isGlobal = anObj->GlobalSelOwner() == theOwner;
967 Handle(AIS_GlobalStatus)& aStatus = myObjects.ChangeFind (anObj);
968 if (theOwner->IsSelected())
f838dac4 969 {
68dcee02 970 highlightSelected (theOwner);
971 if (isGlobal)
972 {
973 aStatus->SetHilightStatus (Standard_True);
974 aStatus->SetHilightStyle (getSelStyle (anObj, theOwner));
975 }
f838dac4 976 }
c3282ec1 977 else
f838dac4 978 {
68dcee02 979 if (theOwner->IsAutoHilight())
980 {
981 theOwner->Unhilight (myMainPM);
982 }
983 else
984 {
985 anObj->ClearSelected();
986 }
987 aStatus->SetHilightStatus (Standard_False);
988 aStatus->SetHilightStyle (Handle(Prs3d_Drawer)());
f838dac4 989 }
7fd59977 990 }
7fd59977 991
c3282ec1 992 if (theToUpdateViewer)
993 UpdateCurrentViewer();
994}
7fd59977 995
996
997//=======================================================================
998//function : IsSelected
c3282ec1 999//purpose :
7fd59977 1000//=======================================================================
c3282ec1 1001Standard_Boolean AIS_InteractiveContext::IsSelected (const Handle(AIS_InteractiveObject)& theObj) const
7fd59977 1002{
68dcee02 1003 if (theObj.IsNull())
1004 {
1005 return Standard_False;
1006 }
c3282ec1 1007
68dcee02 1008 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
1009 if (aStatus == NULL)
1010 {
c3282ec1 1011 return Standard_False;
68dcee02 1012 }
c3282ec1 1013
1014 const Standard_Integer aGlobalSelMode = theObj->GlobalSelectionMode();
68dcee02 1015 const TColStd_ListOfInteger& anActivatedModes = (*aStatus)->SelectionModes();
c3282ec1 1016 for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next())
1017 {
1018 if (aModeIter.Value() == aGlobalSelMode)
1019 {
b5cce1ab 1020 if (Handle(SelectMgr_EntityOwner) aGlobOwner = theObj->GlobalSelOwner())
1021 {
1022 return aGlobOwner->IsSelected();
1023 }
1024 return Standard_False;
c3282ec1 1025 }
1026 }
b5cce1ab 1027 return Standard_False;
7fd59977 1028}
1029
c3282ec1 1030//=======================================================================
68dcee02 1031//function : FirstSelectedObject
c3282ec1 1032//purpose :
7fd59977 1033//=======================================================================
68dcee02 1034Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstSelectedObject() const
7fd59977 1035{
68dcee02 1036 return !mySelection->Objects().IsEmpty()
1037 ? Handle(AIS_InteractiveObject)::DownCast (mySelection->Objects().First()->Selectable())
1038 : Handle(AIS_InteractiveObject)();
7fd59977 1039}
1040
1041//=======================================================================
1042//function : HasSelectedShape
c3282ec1 1043//purpose :
7fd59977 1044//=======================================================================
c3282ec1 1045Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
7fd59977 1046{
4aaadad7
SS
1047 if (!mySelection->More())
1048 return Standard_False;
1049
68dcee02 1050 const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
4aaadad7 1051 return !anOwner.IsNull() && anOwner->HasShape();
7fd59977 1052}
1053
1054//=======================================================================
1055//function : SelectedShape
c3282ec1 1056//purpose :
7fd59977 1057//=======================================================================
c3282ec1 1058TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
7fd59977 1059{
02974a19 1060 if (!mySelection->More())
c3282ec1 1061 return TopoDS_Shape();
7fd59977 1062
68dcee02 1063 const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
3475df12 1064 if (anOwner.IsNull() || !anOwner->HasSelectable())
c3282ec1 1065 return TopoDS_Shape();
1066
1067 return anOwner->Shape().Located (anOwner->Location() * anOwner->Shape().Location());
7fd59977 1068}
1069
c3282ec1 1070//=======================================================================
7fd59977 1071//function : EntityOwners
1072//purpose :
1073//=======================================================================
b586500b 1074void AIS_InteractiveContext::EntityOwners(Handle(SelectMgr_IndexedMapOfOwner)& theOwners,
7fd59977 1075 const Handle(AIS_InteractiveObject)& theIObj,
1076 const Standard_Integer theMode) const
1077{
b5cce1ab 1078 if (theIObj.IsNull())
1079 {
1080 return;
1081 }
7fd59977 1082
1083 TColStd_ListOfInteger aModes;
b5cce1ab 1084 if (theMode == -1)
1085 {
1086 ActivatedModes (theIObj, aModes);
1087 }
7fd59977 1088 else
b5cce1ab 1089 {
1090 aModes.Append (theMode);
1091 }
7fd59977 1092
b586500b 1093 if (theOwners.IsNull())
b5cce1ab 1094 {
b586500b 1095 theOwners = new SelectMgr_IndexedMapOfOwner();
b5cce1ab 1096 }
b586500b 1097
b5cce1ab 1098 for (TColStd_ListIteratorOfListOfInteger anItr (aModes); anItr.More(); anItr.Next())
7fd59977 1099 {
b5cce1ab 1100 const int aMode = anItr.Value();
1101 const Handle(SelectMgr_Selection)& aSel = theIObj->Selection (aMode);
1102 if (aSel.IsNull())
1103 {
7fd59977 1104 continue;
b5cce1ab 1105 }
7fd59977 1106
b5cce1ab 1107 for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (aSel->Entities()); aSelEntIter.More(); aSelEntIter.Next())
7fd59977 1108 {
b5cce1ab 1109 if (Handle(SelectBasics_SensitiveEntity) aEntity = aSelEntIter.Value()->BaseSensitive())
1110 {
1111 if (Handle(SelectMgr_EntityOwner) aOwner = Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId()))
1112 {
1113 theOwners->Add (aOwner);
1114 }
1115 }
7fd59977 1116 }
1117 }
1118}
1119
c3282ec1 1120//=======================================================================
7fd59977 1121//function : HasDetectedShape
1122//purpose :
1123//=======================================================================
7fd59977 1124Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
1125{
8c088c52 1126 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked);
1127 return !anOwner.IsNull()
1128 && anOwner->HasShape();
7fd59977 1129}
1130
1131//=======================================================================
1132//function : DetectedShape
1133//purpose :
1134//=======================================================================
8c088c52 1135const TopoDS_Shape& AIS_InteractiveContext::DetectedShape() const
7fd59977 1136{
8c088c52 1137 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked);
1138 return anOwner->Shape();
1139}
7fd59977 1140
1141//=======================================================================
7fd59977 1142//function : HilightNextDetected
679ecdee 1143//purpose :
7fd59977 1144//=======================================================================
679ecdee 1145Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView,
1146 const Standard_Boolean theToRedrawImmediate)
7fd59977 1147{
f0cddd16 1148 myMainPM->ClearImmediateDraw();
1149 if (myDetectedSeq.IsEmpty())
1150 {
1151 return 0;
1152 }
1153
1154 if (++myCurHighlighted > myDetectedSeq.Upper())
1155 {
1156 myCurHighlighted = myDetectedSeq.Lower();
1157 }
1158 const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted));
1159 if (anOwner.IsNull())
1160 {
1161 return 0;
1162 }
1163
1164 highlightWithColor (anOwner, theView->Viewer());
1165 myLastPicked = anOwner;
1166 myLastinMain = myLastPicked;
1167
1168 if (theToRedrawImmediate)
1169 {
1170 myMainPM->RedrawImmediate (theView->Viewer());
1171 myMainVwr->RedrawImmediate();
1172 }
1173
1174 return myCurHighlighted;
7fd59977 1175}
1176
1177//=======================================================================
f0cddd16 1178//function : HilightPreviousDetected
679ecdee 1179//purpose :
7fd59977 1180//=======================================================================
679ecdee 1181Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1182 const Standard_Boolean theToRedrawImmediate)
7fd59977 1183{
f0cddd16 1184 myMainPM->ClearImmediateDraw();
1185 if (myDetectedSeq.IsEmpty())
1186 {
1187 return 0;
1188 }
1189
1190 if (--myCurHighlighted < myDetectedSeq.Lower())
1191 {
1192 myCurHighlighted = myDetectedSeq.Upper();
1193 }
1194 const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted));
1195 if (anOwner.IsNull())
1196 {
1197 return 0;
1198 }
1199
1200 highlightWithColor (anOwner, theView->Viewer());
1201 myLastPicked = anOwner;
1202 myLastinMain = myLastPicked;
1203
1204 if (theToRedrawImmediate)
1205 {
1206 myMainPM->RedrawImmediate (theView->Viewer());
1207 myMainVwr->RedrawImmediate();
1208 }
1209
1210 return myCurHighlighted;
7fd59977 1211}
1212
7fd59977 1213//=======================================================================
d21ddc4f 1214//function : DetectedCurrentOwner
1215//purpose :
1216//=======================================================================
1217Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedCurrentOwner() const
1218{
d21ddc4f 1219 return MoreDetected()
1220 ? myMainSel->Picked (myDetectedSeq (myCurDetected))
1221 : Handle(SelectMgr_EntityOwner)();
1222}
1223
1224//=======================================================================
7fd59977 1225//function : DetectedCurrentShape
1226//purpose :
1227//=======================================================================
7fd59977 1228const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
1229{
404c8936 1230 Standard_DISABLE_DEPRECATION_WARNINGS
57ad5cbd 1231 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
404c8936 1232 Standard_ENABLE_DEPRECATION_WARNINGS
8c088c52 1233 return !aCurrentShape.IsNull()
1234 ? aCurrentShape->Shape()
1235 : AIS_InteractiveContext_myDummyShape;
7fd59977 1236}
1237
1238//=======================================================================
1239//function : DetectedCurrentObject
1240//purpose :
1241//=======================================================================
57ad5cbd 1242Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const
1243{
f0cddd16 1244 return MoreDetected()
8c088c52 1245 ? Handle(AIS_InteractiveObject)::DownCast (myMainSel->Picked (myDetectedSeq (myCurDetected))->Selectable())
1246 : Handle(AIS_InteractiveObject)();
7fd59977 1247}