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