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