0028047: Visualization - support objects with customized highlighting in AIS_Interact...
[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>
22#include <AIS_LocalContext.hxx>
23#include <AIS_MapIteratorOfMapOfInteractive.hxx>
24#include <AIS_MapOfInteractive.hxx>
25#include <AIS_Selection.hxx>
7fd59977 26#include <AIS_Shape.hxx>
42cf5bc1 27#include <AIS_StatusOfDetection.hxx>
28#include <AIS_StatusOfPick.hxx>
679ecdee 29#include <Aspect_Grid.hxx>
42cf5bc1 30#include <Prs3d_BasicAspect.hxx>
31#include <Prs3d_LineAspect.hxx>
32#include <Prs3d_Presentation.hxx>
33#include <Quantity_Color.hxx>
34#include <SelectBasics_SensitiveEntity.hxx>
35#include <SelectMgr_EntityOwner.hxx>
36#include <SelectMgr_Filter.hxx>
37#include <SelectMgr_OrFilter.hxx>
38#include <SelectMgr_Selection.hxx>
39#include <SelectMgr_SelectionManager.hxx>
40#include <Standard_Transient.hxx>
c3282ec1 41#include <StdSelect_BRepOwner.hxx>
42cf5bc1 42#include <StdSelect_ViewerSelector3d.hxx>
43#include <TCollection_AsciiString.hxx>
44#include <TCollection_ExtendedString.hxx>
45#include <TColStd_ListIteratorOfListOfInteger.hxx>
46#include <TopLoc_Location.hxx>
42cf5bc1 47#include <V3d_AmbientLight.hxx>
48#include <V3d_DirectionalLight.hxx>
7fd59977 49#include <V3d_Light.hxx>
50#include <V3d_PositionalLight.hxx>
51#include <V3d_SpotLight.hxx>
42cf5bc1 52#include <V3d_View.hxx>
53#include <V3d_Viewer.hxx>
7fd59977 54
c3282ec1 55typedef NCollection_DataMap<Handle(AIS_InteractiveObject), NCollection_Handle<SelectMgr_SequenceOfOwner> > AIS_MapOfObjSelectedOwners;
56
016e5959 57namespace
58{
59 TopoDS_Shape AIS_myDummyShape;
60}
61
c3282ec1 62//=======================================================================
63//function : highlightWithColor
64//purpose :
65//=======================================================================
66void AIS_InteractiveContext::highlightWithColor (const Handle(SelectMgr_EntityOwner)& theOwner,
c3282ec1 67 const Handle(V3d_Viewer)& theViewer)
68{
f838dac4 69 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
c3282ec1 70 if (anObj.IsNull())
f838dac4 71 {
c3282ec1 72 return;
f838dac4 73 }
74
75 const Handle(Prs3d_Drawer)& aStyle = getHiStyle (anObj, theOwner);
76 const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1);
c3282ec1 77
78 myMainPM->BeginImmediateDraw();
f838dac4 79 theOwner->HilightWithColor (myMainPM, aStyle, aHiMode);
c3282ec1 80 myMainPM->EndImmediateDraw (theViewer.IsNull() ? myMainVwr : theViewer);
81}
82
83//=======================================================================
84//function : highlightSelected
85//purpose :
86//=======================================================================
8e5fb5ea 87void AIS_InteractiveContext::highlightSelected (const Handle(SelectMgr_EntityOwner)& theOwner)
c3282ec1 88{
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 {
102 aSeq.Append (aSelIter.Value());
103 }
c3282ec1 104 }
105 anObj->HilightSelected (myMainPM, aSeq);
106 }
107 else
108 {
f838dac4 109 const Handle(Prs3d_Drawer)& aStyle = getSelStyle (anObj, theOwner);
110 const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1);
111 theOwner->HilightWithColor (myMainPM, aStyle, aHiMode);
8e5fb5ea 112 }
113}
114
115//=======================================================================
116//function : highlightGlobal
117//purpose :
118//=======================================================================
119void AIS_InteractiveContext::highlightGlobal (const Handle(AIS_InteractiveObject)& theObj,
f838dac4 120 const Handle(Prs3d_Drawer)& theStyle,
121 const Standard_Integer theDispMode) const
8e5fb5ea 122{
123 if (theObj.IsNull())
f838dac4 124 {
8e5fb5ea 125 return;
f838dac4 126 }
127
128 const Standard_Integer aHiMode = getHilightMode (theObj, theStyle, theDispMode);
8e5fb5ea 129 const Handle(SelectMgr_EntityOwner)& aGlobOwner = theObj->GlobalSelOwner();
130
131 if (aGlobOwner.IsNull())
132 {
f838dac4 133 myMainPM->Color (theObj, theStyle, aHiMode);
8e5fb5ea 134 return;
135 }
136
137 if (!aGlobOwner->IsAutoHilight())
138 {
139 SelectMgr_SequenceOfOwner aSeq;
140 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
141 {
142 if (aSelIter.Value()->IsSameSelectable (theObj))
143 {
144 aSeq.Append (aSelIter.Value());
145 }
146 }
147 theObj->HilightSelected (myMainPM, aSeq);
148 }
149 else
150 {
f838dac4 151 aGlobOwner->HilightWithColor (myMainPM, theStyle, aHiMode);
c3282ec1 152 }
153}
154
7fd59977 155//=======================================================================
b4006117 156//function : unhighlightSelected
157//purpose :
158//=======================================================================
159void AIS_InteractiveContext::unhighlightSelected (const Standard_Boolean theIsToHilightSubIntensity)
160{
b4006117 161 NCollection_IndexedMap<Handle(AIS_InteractiveObject)> anObjToClear;
02974a19 162 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
b4006117 163 {
02974a19 164 const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value();
165 const Handle(AIS_InteractiveObject) anInteractive = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
f838dac4 166 Handle(AIS_GlobalStatus) aStatus;
167 if (!myObjects.Find (anInteractive, aStatus))
168 {
169 continue;
170 }
171
b4006117 172 if (anOwner->IsAutoHilight())
173 {
f838dac4 174 anOwner->Unhilight (myMainPM);
b4006117 175 if (theIsToHilightSubIntensity)
176 {
f838dac4 177 if (aStatus->IsSubIntensityOn())
b4006117 178 {
f838dac4 179 const Standard_Integer aHiMode = getHilightMode (anInteractive, aStatus->HilightStyle(), aStatus->DisplayMode());
8e5fb5ea 180 highlightWithSubintensity (anOwner, aHiMode);
b4006117 181 }
182 }
183 }
184 else
185 {
f838dac4 186 anObjToClear.Add (anInteractive);
b4006117 187 }
f838dac4 188 anOwner->SetSelected (Standard_False);
b4006117 189 if (anOwner == anInteractive->GlobalSelOwner())
190 {
191 myObjects.ChangeFind (anInteractive)->SetHilightStatus (Standard_False);
192 }
193 }
194 for (NCollection_IndexedMap<Handle(AIS_InteractiveObject)>::Iterator anIter (anObjToClear); anIter.More(); anIter.Next())
195 {
196 const Handle(AIS_InteractiveObject)& anObj = anIter.Value();
f838dac4 197 myMainPM->Unhighlight (anObj);
b4006117 198 anObj->ClearSelected();
199 }
200}
201
202//=======================================================================
8e5fb5ea 203//function : unhighlightGlobal
204//purpose :
205//=======================================================================
f838dac4 206void AIS_InteractiveContext::unhighlightGlobal (const Handle(AIS_InteractiveObject)& theObj) const
8e5fb5ea 207{
208 if (theObj.IsNull())
f838dac4 209 {
8e5fb5ea 210 return;
f838dac4 211 }
8e5fb5ea 212
f838dac4 213 const Handle(SelectMgr_EntityOwner)& aGlobOwner = theObj->GlobalSelOwner();
8e5fb5ea 214 if (aGlobOwner.IsNull())
215 {
f838dac4 216 myMainPM->Unhighlight (theObj);
8e5fb5ea 217 return;
218 }
219
220 if (aGlobOwner->IsAutoHilight())
221 {
f838dac4 222 aGlobOwner->Unhilight (myMainPM);
8e5fb5ea 223 }
224 else
225 {
f838dac4 226 myMainPM->Unhighlight (theObj);
8e5fb5ea 227 theObj->ClearSelected();
228 }
229}
230
231//=======================================================================
232//function : turnOnSubintensity
233//purpose :
234//=======================================================================
235void AIS_InteractiveContext::turnOnSubintensity (const Handle(AIS_InteractiveObject)& theObject,
236 const Standard_Integer theDispMode,
237 const Standard_Boolean theIsDisplayedOnly) const
238{
f838dac4 239 // the only differ with selection highlight is color, so sync transparency values
240 const Handle(Prs3d_Drawer)& aSubStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity];
241 aSubStyle->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
8e5fb5ea 242
243 if (theObject.IsNull())
244 {
245 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjsIter (myObjects); anObjsIter.More(); anObjsIter.Next())
246 {
247 const Handle(AIS_GlobalStatus)& aStatus = anObjsIter.Value();
248 if (aStatus->GraphicStatus() != AIS_DS_Displayed && theIsDisplayedOnly)
249 continue;
250
251 aStatus->SubIntensityOn();
f838dac4 252 myMainPM->Color (anObjsIter.Key(), aSubStyle, theDispMode != -1 ? theDispMode : aStatus->DisplayMode());
8e5fb5ea 253 }
254 }
255 else
256 {
257 Handle(AIS_GlobalStatus) aStatus;
258 if (!myObjects.Find (theObject, aStatus))
259 return;
260
261 if (aStatus->GraphicStatus() != AIS_DS_Displayed && theIsDisplayedOnly)
f838dac4 262 return;
8e5fb5ea 263
264 aStatus->SubIntensityOn();
f838dac4 265 myMainPM->Color (theObject, aSubStyle, theDispMode != -1 ? theDispMode : aStatus->DisplayMode());
8e5fb5ea 266 }
267}
268
269//=======================================================================
270//function : highlightWithSubintensity
271//purpose :
272//=======================================================================
273void AIS_InteractiveContext::highlightWithSubintensity (const Handle(AIS_InteractiveObject)& theObject,
274 const Standard_Integer theMode) const
275{
276 // the only differ with selection highlight is color, so
277 // sync transparency values
f838dac4 278 myStyles[Prs3d_TypeOfHighlight_SubIntensity]->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
8e5fb5ea 279
f838dac4 280 myMainPM->Color (theObject, myStyles[Prs3d_TypeOfHighlight_SubIntensity], theMode);
8e5fb5ea 281}
282
283//=======================================================================
284//function : highlightWithSubintensity
285//purpose :
286//=======================================================================
287void AIS_InteractiveContext::highlightWithSubintensity (const Handle(SelectMgr_EntityOwner)& theOwner,
288 const Standard_Integer theMode) const
289{
290 // the only differ with selection highlight is color, so
291 // sync transparency values
f838dac4 292 myStyles[Prs3d_TypeOfHighlight_SubIntensity]->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
8e5fb5ea 293
f838dac4 294 theOwner->HilightWithColor (myMainPM, myStyles[Prs3d_TypeOfHighlight_SubIntensity], theMode);
8e5fb5ea 295}
296
297//=======================================================================
7fd59977 298//function : MoveTo
679ecdee 299//purpose :
7fd59977 300//=======================================================================
679ecdee 301AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const Standard_Integer theXPix,
302 const Standard_Integer theYPix,
303 const Handle(V3d_View)& theView,
304 const Standard_Boolean theToRedrawOnUpdate)
7fd59977 305{
679ecdee 306 if (HasOpenedContext())
307 {
7fd59977 308 myWasLastMain = Standard_True;
679ecdee 309 return myLocalContexts (myCurLocalIndex)->MoveTo (theXPix, theYPix, theView, theToRedrawOnUpdate);
7fd59977 310 }
311
f0cddd16 312 myCurDetected = 0;
313 myCurHighlighted = 0;
314 myDetectedSeq.Clear();
7fd59977 315
679ecdee 316 if (theView->Viewer() != myMainVwr)
317 {
7fd59977 318 return AIS_SOD_Error;
679ecdee 319 }
320
321 // preliminaires
322 myLastPicked = myLastinMain;
323 myWasLastMain = Standard_True;
324 AIS_StatusOfDetection aStatus = AIS_SOD_Nothing;
325 Standard_Boolean toUpdateViewer = Standard_False;
326
a272ed94 327 myFilters->SetDisabledObjects (theView->View()->HiddenObjects());
679ecdee 328 myMainSel->Pick (theXPix, theYPix, theView);
329
330 // filling of myAISDetectedSeq sequence storing information about detected AIS objects
331 // (the objects must be AIS_Shapes)
332 const Standard_Integer aDetectedNb = myMainSel->NbPicked();
54a16ee4 333 Standard_Integer aNewDetected = 0;
679ecdee 334 for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
7fd59977 335 {
679ecdee 336 Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aDetIter);
337 if (anOwner.IsNull()
338 || !myFilters->IsOk (anOwner))
339 {
340 continue;
341 }
342
54a16ee4 343 if (aNewDetected < 1)
344 {
345 aNewDetected = aDetIter;
346 }
f0cddd16 347
348 myDetectedSeq.Append (aDetIter);
7fd59977 349 }
7fd59977 350
54a16ee4 351 if (aNewDetected >= 1)
7fd59977 352 {
f0cddd16 353 myCurHighlighted = myDetectedSeq.Lower();
354
29627b4c 355 // Does nothing if previously detected object is equal to the current one.
356 // However in advanced selection modes the owners comparison
357 // is not effective because in that case only one owner manage the
358 // selection in current selection mode. It is necessary to check the current detected
359 // entity and hilight it only if the detected entity is not the same as
360 // previous detected (IsForcedHilight call)
54a16ee4 361 Handle(SelectMgr_EntityOwner) aNewPickedOwner = myMainSel->Picked (aNewDetected);
29627b4c 362 if (aNewPickedOwner == myLastPicked && !aNewPickedOwner->IsForcedHilight())
eafb234b 363 {
c3282ec1 364 return myLastPicked->IsSelected()
8abada55 365 ? AIS_SOD_Selected
366 : AIS_SOD_OnlyOneDetected;
679ecdee 367 }
81bba717 368
7fd59977 369 // Previously detected object is unhilighted if it is not selected or hilighted
370 // with selection color if it is selected. Such highlighting with selection color
371 // is needed only if myToHilightSelected flag is true. In this case previously detected
372 // object has been already highlighted with myHilightColor during previous MoveTo()
373 // method call. As result it is necessary to rehighligt it with mySelectionColor.
c3282ec1 374 if (!myLastPicked.IsNull() && myLastPicked->HasSelectable())
7fd59977 375 {
731c9b5b 376 clearDynamicHighlight();
377 toUpdateViewer = Standard_True;
7fd59977 378 }
be6e564e 379
679ecdee 380 // initialize myLastPicked field with currently detected object
c3282ec1 381 myLastPicked = aNewPickedOwner;
679ecdee 382 myLastinMain = myLastPicked;
be6e564e 383
679ecdee 384 // highlight detected object if it is not selected or myToHilightSelected flag is true
c3282ec1 385 if (myLastPicked->HasSelectable())
7fd59977 386 {
c3282ec1 387 if (!myLastPicked->IsSelected() || myToHilightSelected)
679ecdee 388 {
8e5fb5ea 389 highlightWithColor (myLastPicked, theView->Viewer());
679ecdee 390 toUpdateViewer = Standard_True;
391 }
be6e564e 392
c3282ec1 393 aStatus = myLastPicked->IsSelected()
8abada55 394 ? AIS_SOD_Selected
395 : AIS_SOD_OnlyOneDetected;
be6e564e 396 }
7fd59977 397 }
c3282ec1 398 else
7fd59977 399 {
679ecdee 400 // previously detected object is unhilighted if it is not selected or hilighted
401 // with selection color if it is selected
402 aStatus = AIS_SOD_Nothing;
c3282ec1 403 if (!myLastPicked.IsNull() && myLastPicked->HasSelectable())
7fd59977 404 {
731c9b5b 405 clearDynamicHighlight();
406 toUpdateViewer = Standard_True;
7fd59977 407 }
be6e564e 408
679ecdee 409 myLastinMain.Nullify();
8abada55 410 myLastPicked.Nullify();
7fd59977 411 }
679ecdee 412
2eea6525 413 if (toUpdateViewer
414 && theToRedrawOnUpdate)
679ecdee 415 {
2eea6525 416 theView->Viewer()->Update();
679ecdee 417 }
418
679ecdee 419 mylastmoveview = theView;
420 return aStatus;
7fd59977 421}
422
423//=======================================================================
016e5959 424//function : AddSelect
425//purpose :
426//=======================================================================
02974a19 427AIS_StatusOfPick AIS_InteractiveContext::AddSelect (const Handle(SelectMgr_EntityOwner)& theObject)
016e5959 428{
429 if (HasOpenedContext())
430 {
431 return myLocalContexts(myCurLocalIndex)->AddSelect (theObject);
432 }
433 mySelection->AddSelect (theObject);
434
435 Standard_Integer aSelNum = NbSelected();
436 return (aSelNum == 0) ? AIS_SOP_NothingSelected
437 : (aSelNum == 1) ? AIS_SOP_OneSelected
438 : AIS_SOP_SeveralSelected;
439}
440
441//=======================================================================
7fd59977 442//function : Select
443//purpose :
444//=======================================================================
c398b00e 445AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Integer theXPMin,
446 const Standard_Integer theYPMin,
447 const Standard_Integer theXPMax,
448 const Standard_Integer theYPMax,
449 const Handle(V3d_View)& theView,
450 const Standard_Boolean toUpdateViewer)
7fd59977 451{
81bba717 452 // all objects detected by the selector are taken, previous current objects are emptied,
453 // new objects are put...
7fd59977 454
c398b00e 455 if (HasOpenedContext())
456 {
457 return myLocalContexts(myCurLocalIndex)->Select (theXPMin, theYPMin,
458 theXPMax, theYPMax,
459 theView, toUpdateViewer);
460 }
7fd59977 461
c3282ec1 462 ClearSelected (Standard_False);
eb4320f2 463
c398b00e 464 Handle(StdSelect_ViewerSelector3d) aSelector;
7fd59977 465
c398b00e 466 if (theView->Viewer() == myMainVwr)
7fd59977 467 {
c398b00e 468 aSelector = myMainSel;
469 myWasLastMain = Standard_True;
7fd59977 470 }
c398b00e 471
472 aSelector->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
aa75c0cf 473 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
7fd59977 474 {
aa75c0cf 475 const Handle(SelectMgr_EntityOwner)& aCurOwner = aSelector->Picked (aPickIter);
c3282ec1 476 if (aCurOwner.IsNull() || !aCurOwner->HasSelectable() || !myFilters->IsOk (aCurOwner))
477 continue;
7fd59977 478
016e5959 479 mySelection->Select (aCurOwner);
f838dac4 480 aCurOwner->SetSelected (Standard_True);
c398b00e 481 }
482
c3282ec1 483 HilightSelected (toUpdateViewer);
c398b00e 484
c3282ec1 485 Standard_Integer aSelNum = NbSelected();
c398b00e 486
487 return (aSelNum == 0) ? AIS_SOP_NothingSelected
488 : (aSelNum == 1) ? AIS_SOP_OneSelected
489 : AIS_SOP_SeveralSelected;
7fd59977 490
491}
492
493//=======================================================================
494//function : Select
495//purpose : Selection by polyline
496//=======================================================================
c398b00e 497AIS_StatusOfPick AIS_InteractiveContext::Select (const TColgp_Array1OfPnt2d& thePolyline,
498 const Handle(V3d_View)& theView,
499 const Standard_Boolean toUpdateViewer)
7fd59977 500{
81bba717 501 // all objects detected by the selector are taken, previous current objects are emptied,
502 // new objects are put...
7fd59977 503
c398b00e 504 if (HasOpenedContext())
505 {
506 return myLocalContexts(myCurLocalIndex)->Select (thePolyline, theView, toUpdateViewer);
507 }
eb4320f2 508
c3282ec1 509 ClearSelected (Standard_False);
7fd59977 510
c398b00e 511 Handle(StdSelect_ViewerSelector3d) aSelector;
7fd59977 512
c398b00e 513 if (theView->Viewer() == myMainVwr)
7fd59977 514 {
c398b00e 515 aSelector = myMainSel;
516 myWasLastMain = Standard_True;
7fd59977 517 }
c398b00e 518
519 aSelector->Pick (thePolyline, theView);
aa75c0cf 520 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
7fd59977 521 {
aa75c0cf 522 const Handle(SelectMgr_EntityOwner) anOwner = aSelector->Picked (aPickIter);
c3282ec1 523 if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner))
524 continue;
c398b00e 525
016e5959 526 mySelection->Select (anOwner);
f838dac4 527 anOwner->SetSelected (Standard_True);
c398b00e 528 }
529
c3282ec1 530 HilightSelected (toUpdateViewer);
c398b00e 531
c3282ec1 532 Standard_Integer aSelNum = NbSelected();
c398b00e 533
534 return (aSelNum == 0) ? AIS_SOP_NothingSelected
535 : (aSelNum == 1) ? AIS_SOP_OneSelected
536 : AIS_SOP_SeveralSelected;
7fd59977 537
538}
539
540//=======================================================================
541//function : Select
542//purpose :
543//=======================================================================
c398b00e 544AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean toUpdateViewer)
7fd59977 545{
c398b00e 546 if (HasOpenedContext())
547 {
7fd59977 548 if(myWasLastMain)
c398b00e 549 {
550 return myLocalContexts(myCurLocalIndex)->Select (toUpdateViewer);
551 }
7fd59977 552 else
c398b00e 553 {
c3282ec1 554 myLocalContexts(myCurLocalIndex)->SetSelected (Handle(AIS_InteractiveObject)::DownCast (myLastPicked->Selectable()), toUpdateViewer);
c398b00e 555 return AIS_SOP_OneSelected;
556 }
557 }
558
731c9b5b 559 clearDynamicHighlight();
c398b00e 560 if (myWasLastMain && !myLastinMain.IsNull())
561 {
731c9b5b 562 if (!myLastinMain->IsSelected() || myLastinMain->IsForcedHilight())
c398b00e 563 {
c3282ec1 564 SetSelected (myLastinMain, Standard_False);
c398b00e 565 if(toUpdateViewer)
7fd59977 566 {
c398b00e 567 UpdateCurrentViewer();
7fd59977 568 }
c398b00e 569 }
7fd59977 570 }
c398b00e 571 else
572 {
b4006117 573 unhighlightSelected (Standard_True);
c398b00e 574
02974a19 575 mySelection->Clear();
c398b00e 576 if (toUpdateViewer && myWasLastMain)
577 {
eb4320f2 578 UpdateCurrentViewer();
7fd59977 579 }
580 }
c398b00e 581
c3282ec1 582 Standard_Integer aSelNum = NbSelected();
c398b00e 583
584 return (aSelNum == 0) ? AIS_SOP_NothingSelected
585 : (aSelNum == 1) ? AIS_SOP_OneSelected
586 : AIS_SOP_SeveralSelected;
7fd59977 587}
588
589//=======================================================================
590//function : ShiftSelect
591//purpose :
592//=======================================================================
c398b00e 593AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Boolean toUpdateViewer)
7fd59977 594{
c398b00e 595 if (HasOpenedContext())
596 {
7fd59977 597 if(myWasLastMain)
c398b00e 598 {
599 return myLocalContexts (myCurLocalIndex)->ShiftSelect (toUpdateViewer);
600 }
601 else
602 {
603 myLocalContexts (myCurLocalIndex)->AddOrRemoveSelected (myLastPicked, toUpdateViewer);
604
605 Standard_Integer aSelNum = NbSelected();
606 return (aSelNum == 0) ? AIS_SOP_NothingSelected
607 : (aSelNum == 1) ? AIS_SOP_OneSelected
608 : AIS_SOP_SeveralSelected;
7fd59977 609 }
610 }
eb4320f2 611
731c9b5b 612 clearDynamicHighlight();
c398b00e 613 if (myWasLastMain && !myLastinMain.IsNull())
614 {
c3282ec1 615 AddOrRemoveSelected (myLastinMain, toUpdateViewer);
c398b00e 616 }
7fd59977 617
c3282ec1 618 Standard_Integer aSelNum = NbSelected();
c398b00e 619
c3282ec1 620 return (aSelNum == 0) ? AIS_SOP_NothingSelected
621 : (aSelNum == 1) ? AIS_SOP_OneSelected
622 : AIS_SOP_SeveralSelected;
c398b00e 623}
7fd59977 624
625//=======================================================================
626//function : ShiftSelect
627//purpose :
628//=======================================================================
c398b00e 629AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Integer theXPMin,
630 const Standard_Integer theYPMin,
631 const Standard_Integer theXPMax,
632 const Standard_Integer theYPMax,
633 const Handle(V3d_View)& theView,
634 const Standard_Boolean toUpdateViewer)
7fd59977 635{
c398b00e 636 if (HasOpenedContext())
637 {
638 return myLocalContexts(myCurLocalIndex)->ShiftSelect (theXPMin, theYPMin, theXPMax, theYPMax,
639 theView, toUpdateViewer);
640 }
641
c3282ec1 642 UnhilightSelected (Standard_False);
c398b00e 643
644 Handle(StdSelect_ViewerSelector3d) aSelector;
645 if (theView->Viewer() == myMainVwr)
646 {
647 aSelector = myMainSel;
648 myWasLastMain = Standard_True;
649 }
7fd59977 650 else
c398b00e 651 {
7fd59977 652 return AIS_SOP_NothingSelected;
c398b00e 653 }
654
655 aSelector->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
aa75c0cf 656 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
c398b00e 657 {
aa75c0cf 658 const Handle(SelectMgr_EntityOwner) anOwner = aSelector->Picked (aPickIter);
c3282ec1 659 if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner))
660 continue;
661
016e5959 662 AIS_SelectStatus aSelStatus = mySelection->Select (anOwner);
f838dac4 663 anOwner->SetSelected (aSelStatus == AIS_SS_Added);
7fd59977 664 }
c398b00e 665
c3282ec1 666 HilightSelected (toUpdateViewer);
c398b00e 667
c3282ec1 668 Standard_Integer aSelNum = NbSelected();
c398b00e 669
670 return (aSelNum == 0) ? AIS_SOP_NothingSelected
671 : (aSelNum == 1) ? AIS_SOP_OneSelected
672 : AIS_SOP_SeveralSelected;
673
7fd59977 674}
675
676//=======================================================================
677//function : ShiftSelect
678//purpose :
679//=======================================================================
c398b00e 680AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline,
681 const Handle(V3d_View)& theView,
682 const Standard_Boolean toUpdateViewer)
7fd59977 683{
c398b00e 684 if (HasOpenedContext())
685 {
686 return myLocalContexts(myCurLocalIndex)->ShiftSelect (thePolyline, theView, toUpdateViewer);
687 }
7fd59977 688
c3282ec1 689 UnhilightSelected (Standard_False);
c398b00e 690
691 Handle(StdSelect_ViewerSelector3d) aSelector;
692
693 if (theView->Viewer() == myMainVwr)
694 {
695 aSelector= myMainSel;
696 myWasLastMain = Standard_True;
697 }
698 else
699 {
700 return AIS_SOP_NothingSelected;
701 }
702
703 aSelector->Pick (thePolyline, theView);
aa75c0cf 704 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
c398b00e 705 {
aa75c0cf 706 const Handle(SelectMgr_EntityOwner) anOwner = aSelector->Picked (aPickIter);
c3282ec1 707 if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner))
708 continue;
709
016e5959 710 AIS_SelectStatus aSelStatus = mySelection->Select (anOwner);
f838dac4 711 anOwner->SetSelected (aSelStatus == AIS_SS_Added);
c398b00e 712 }
713
c3282ec1 714 HilightSelected (toUpdateViewer);
c398b00e 715
c3282ec1 716 Standard_Integer aSelNum = NbSelected();
c398b00e 717
718 return (aSelNum == 0) ? AIS_SOP_NothingSelected
719 : (aSelNum == 1) ? AIS_SOP_OneSelected
720 : AIS_SOP_SeveralSelected;
7fd59977 721}
722
723//=======================================================================
724//function : SetCurrentObject
c3282ec1 725//purpose : OBSOLETE, please use SetSelected() instead
726//TODO : Remove in process of local context deletion
7fd59977 727//=======================================================================
c3282ec1 728void AIS_InteractiveContext::SetCurrentObject (const Handle(AIS_InteractiveObject)& theObject,
729 const Standard_Boolean theToUpdateViewer)
7fd59977 730{
c3282ec1 731 if (HasOpenedContext())
7fd59977 732 return;
7fd59977 733
c3282ec1 734 SetSelected (theObject, theToUpdateViewer);
7fd59977 735}
736
737//=======================================================================
738//function : AddOrRemoveCurrentObject
c3282ec1 739//purpose : OBSOLETE, please use AddOrRemoveSelected() instead
740//TODO : Remove in process of local context deletion
7fd59977 741//=======================================================================
c3282ec1 742void AIS_InteractiveContext::AddOrRemoveCurrentObject (const Handle(AIS_InteractiveObject)& theObj,
743 const Standard_Boolean theIsToUpdateViewer)
7fd59977 744{
c3282ec1 745 if (HasOpenedContext())
746 return;
7fd59977 747
c3282ec1 748 AddOrRemoveSelected (theObj, theIsToUpdateViewer);
7fd59977 749}
750//=======================================================================
751//function : UpdateCurrent
c3282ec1 752//purpose : OBSOLETE, please use UpdateSelected() instead
753//TODO : Remove in process of local context deletion
7fd59977 754//=======================================================================
7fd59977 755void AIS_InteractiveContext::UpdateCurrent()
756{
c3282ec1 757 UpdateSelected();
7fd59977 758}
759
760//=======================================================================
761//function : IsCurrent
c3282ec1 762//purpose : OBSOLETE, please use IsSelected() instead
763//TODO : Remove in process of local context deletion
7fd59977 764//=======================================================================
c3282ec1 765Standard_Boolean AIS_InteractiveContext::IsCurrent (const Handle(AIS_InteractiveObject)& theObject) const
7fd59977 766{
c3282ec1 767 return IsSelected (theObject);
7fd59977 768}
769
770//=======================================================================
771//function : InitCurrent
c3282ec1 772//purpose : OBSOLETE, please use InitSelected() instead
773//TODO : Remove in process of local context deletion
7fd59977 774//=======================================================================
7fd59977 775void AIS_InteractiveContext::InitCurrent()
776{
c3282ec1 777 if (HasOpenedContext())
778 return;
779
780 InitSelected();
7fd59977 781}
782
783//=======================================================================
784//function : MoreCurrent
c3282ec1 785//purpose : OBSOLETE, please use MoreSelected() instead
786//TODO : Remove in process of local context deletion
7fd59977 787//=======================================================================
7fd59977 788Standard_Boolean AIS_InteractiveContext::MoreCurrent() const
789{
c3282ec1 790 return !HasOpenedContext() && MoreSelected();
7fd59977 791}
792
793//=======================================================================
794//function : NextCurrent
c3282ec1 795//purpose : OBSOLETE, please use NextSelected() instead
796//TODO : Remove in process of local context deletion
7fd59977 797//=======================================================================
7fd59977 798void AIS_InteractiveContext::NextCurrent()
799{
c3282ec1 800 if (HasOpenedContext())
801 return;
802
803 NextSelected();
7fd59977 804}
805
806//=======================================================================
807//function : Current
c3282ec1 808//purpose : OBSOLETE, please use SelectedInteractive() instead
809//TODO : Remove in process of local context deletion
7fd59977 810//=======================================================================
7fd59977 811Handle(AIS_InteractiveObject) AIS_InteractiveContext::Current() const
812{
c3282ec1 813 return HasOpenedContext() ? NULL : SelectedInteractive();
7fd59977 814}
815
816//=======================================================================
817//function : NbCurrents
c3282ec1 818//purpose : OBSOLETE, please use NbSelected() instead
819//TODO : Remove in process of local context deletion
7fd59977 820//=======================================================================
821Standard_Integer AIS_InteractiveContext::NbCurrents()
822{
c3282ec1 823 return HasOpenedContext() ? -1 : NbSelected();
7fd59977 824}
825
826//=======================================================================
827//function : HilightCurrents
c3282ec1 828//purpose : OBSOLETE, please use HilightSelected() instead
829//TODO : Remove in process of local context deletion
7fd59977 830//=======================================================================
c3282ec1 831void AIS_InteractiveContext::HilightCurrents (const Standard_Boolean theToUpdateViewer)
7fd59977 832{
c3282ec1 833 if (HasOpenedContext())
834 return;
835
836 HilightSelected (theToUpdateViewer);
7fd59977 837}
838
839//=======================================================================
840//function : UnhilightCurrents
c3282ec1 841//purpose : OBSOLETE, please use UnhilightSelected() instead
842//TODO : Remove in process of local context deletion
7fd59977 843//=======================================================================
c3282ec1 844void AIS_InteractiveContext::UnhilightCurrents (const Standard_Boolean theToUpdateViewer)
7fd59977 845{
c3282ec1 846 if (HasOpenedContext())
847 return;
848
849 UnhilightSelected (theToUpdateViewer);
7fd59977 850}
851
852//=======================================================================
853//function : ClearCurrents
c3282ec1 854//purpose : OBSOLETE, please use ClearCurrents() instead
855//TODO : Remove in process of local context deletion
7fd59977 856//=======================================================================
c3282ec1 857void AIS_InteractiveContext::ClearCurrents(const Standard_Boolean theToUpdateViewer)
7fd59977 858{
c3282ec1 859 if (HasOpenedContext())
860 return;
861
862 ClearSelected (theToUpdateViewer);
7fd59977 863}
864
865
866//=======================================================================
867//function : HilightSelected
c3282ec1 868//purpose :
7fd59977 869//=======================================================================
c3282ec1 870void AIS_InteractiveContext::HilightSelected (const Standard_Boolean theToUpdateViewer)
7fd59977 871{
c3282ec1 872 if (HasOpenedContext())
873 {
874 return myLocalContexts (myCurLocalIndex)->HilightPicked (theToUpdateViewer);
875 }
876
877 // In case of selection without using local context
731c9b5b 878 clearDynamicHighlight();
c3282ec1 879 AIS_MapOfObjSelectedOwners anObjOwnerMap;
02974a19 880 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
c3282ec1 881 {
02974a19 882 const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value();
883 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
f838dac4 884 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObj, anOwner);
885 Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind(anObj);
02974a19 886 if (anOwner == anObj->GlobalSelOwner())
c3282ec1 887 {
02974a19 888 aState->SetHilightStatus (Standard_True);
8e5fb5ea 889 aState->SetHilightStyle (anObjSelStyle);
02974a19 890 }
f838dac4 891 anOwner->SetSelected (Standard_True);
02974a19 892 if (!anOwner->IsAutoHilight())
893 {
894 NCollection_Handle<SelectMgr_SequenceOfOwner> aSeq;
895 if (anObjOwnerMap.Find (anObj, aSeq))
c3282ec1 896 {
02974a19 897 aSeq->Append (anOwner);
c3282ec1 898 }
899 else
900 {
02974a19 901 aSeq = new SelectMgr_SequenceOfOwner();
902 aSeq->Append (anOwner);
903 anObjOwnerMap.Bind (anObj, aSeq);
c3282ec1 904 }
7fd59977 905 }
02974a19 906 else
907 {
f838dac4 908 const Standard_Integer aHiMode = getHilightMode (anObj, anObjSelStyle, aState->DisplayMode());
8e5fb5ea 909 anOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode);
02974a19 910 }
7fd59977 911 }
c3282ec1 912
913 if (!anObjOwnerMap.IsEmpty())
914 {
915 for (AIS_MapOfObjSelectedOwners::Iterator anIter (anObjOwnerMap); anIter.More(); anIter.Next())
7fd59977 916 {
c3282ec1 917 anIter.Key()->HilightSelected (myMainPM, *anIter.Value());
7fd59977 918 }
c3282ec1 919 anObjOwnerMap.Clear();
920 }
921
922 if (theToUpdateViewer)
7fd59977 923 UpdateCurrentViewer();
924}
925
926//=======================================================================
927//function : UnhilightSelected
c3282ec1 928//purpose :
7fd59977 929//=======================================================================
c3282ec1 930void AIS_InteractiveContext::UnhilightSelected (const Standard_Boolean theToUpdateViewer)
7fd59977 931{
c3282ec1 932 if (HasOpenedContext())
933 {
934 return myLocalContexts (myCurLocalIndex)->UnhilightPicked (theToUpdateViewer);
7fd59977 935 }
c3282ec1 936
02974a19 937 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
c3282ec1 938 {
02974a19 939 const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value();
940 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
941 if (anOwner == anObj->GlobalSelOwner())
7fd59977 942 {
02974a19 943 myObjects.ChangeFind (anObj)->SetHilightStatus (Standard_False);
7fd59977 944 }
02974a19 945
f838dac4 946 anOwner->SetSelected (Standard_False);
947 anOwner->Unhilight (myMainPM);
c3282ec1 948 }
949
950 if (theToUpdateViewer)
951 UpdateCurrentViewer();
7fd59977 952}
953
954
955//=======================================================================
956//function : ClearSelected
c3282ec1 957//purpose :
7fd59977 958//=======================================================================
c3282ec1 959void AIS_InteractiveContext::ClearSelected (const Standard_Boolean theToUpdateViewer)
7fd59977 960{
c3282ec1 961 if (HasOpenedContext())
962 return myLocalContexts (myCurLocalIndex)->ClearSelected (theToUpdateViewer);
7fd59977 963
c3282ec1 964 if (NbSelected() == 0)
965 return;
7fd59977 966
b4006117 967 unhighlightSelected();
7fd59977 968
02974a19 969 mySelection->Clear();
731c9b5b 970 clearDynamicHighlight();
7fd59977 971
c3282ec1 972 if (theToUpdateViewer)
973 UpdateCurrentViewer();
7fd59977 974}
975
976//=======================================================================
c3282ec1 977//function : UpdateSelected
978//purpose :
7fd59977 979//=======================================================================
c3282ec1 980void AIS_InteractiveContext::UpdateSelected (const Standard_Boolean theToUpdateViewer)
981{
982 if (HasOpenedContext())
983 {
984 return myLocalContexts(myCurLocalIndex)->UpdateSelected (theToUpdateViewer);
985 }
7fd59977 986
c3282ec1 987 HilightSelected (theToUpdateViewer);
988}
989
990//=======================================================================
991//function : SetSelected
992//purpose : Sets the whole object as selected and highlights it with selection color
993//=======================================================================
994void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& theObject,
995 const Standard_Boolean theToUpdateViewer)
7fd59977 996{
f838dac4 997 if (HasOpenedContext())
c3282ec1 998 {
999 return myLocalContexts (myCurLocalIndex)->SetSelected (theObject, theToUpdateViewer);
1000 }
1001
1002 if (theObject.IsNull())
f838dac4 1003 {
7fd59977 1004 return;
f838dac4 1005 }
1006
1007 if (!myObjects.IsBound (theObject))
1008 {
c3282ec1 1009 Display (theObject, Standard_False);
f838dac4 1010 }
0d5880e1 1011 if (!theObject->HasSelection (theObject->GlobalSelectionMode()))
f838dac4 1012 {
c3282ec1 1013 return;
f838dac4 1014 }
1015 Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
1016 if (anOwner.IsNull())
1017 {
1018 return;
1019 }
c3282ec1 1020
f838dac4 1021 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (theObject, anOwner);
e1b01c73 1022 if (NbSelected() == 1 && myObjects (theObject)->IsHilighted())
c3282ec1 1023 {
f838dac4 1024 Handle(Prs3d_Drawer) aCustomStyle;
8e5fb5ea 1025 if (HighlightStyle (theObject, aCustomStyle))
c3282ec1 1026 {
8e5fb5ea 1027 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
c3282ec1 1028 {
8e5fb5ea 1029 HilightWithColor (theObject, anObjSelStyle, theToUpdateViewer);
c3282ec1 1030 }
1031 }
1032 return;
1033 }
1034
016e5959 1035 for (mySelection->Init(); mySelection->More(); mySelection->Next())
c3282ec1 1036 {
f838dac4 1037 const Handle(SelectMgr_EntityOwner) aSelOwner = mySelection->Value();
1038 if (!myFilters->IsOk (aSelOwner))
02974a19 1039 {
c3282ec1 1040 continue;
02974a19 1041 }
c3282ec1 1042
f838dac4 1043 Handle(AIS_InteractiveObject) aSelectable = Handle(AIS_InteractiveObject)::DownCast (aSelOwner->Selectable());
c3282ec1 1044 Unhilight (aSelectable, Standard_False);
f838dac4 1045 aSelOwner->SetSelected (Standard_False);
1046 if (aSelOwner == aSelectable->GlobalSelOwner())
e1b01c73 1047 {
1048 myObjects.ChangeFind (aSelectable)->SetHilightStatus (Standard_False);
1049 }
c3282ec1 1050 }
1051
1052 // added to avoid untimely viewer update...
016e5959 1053 mySelection->ClearAndSelect (anOwner);
0d5880e1 1054
f838dac4 1055 Handle(Prs3d_Drawer) aCustomStyle;
8e5fb5ea 1056 if (HighlightStyle (theObject, aCustomStyle))
c3282ec1 1057 {
8e5fb5ea 1058 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
c3282ec1 1059 {
8e5fb5ea 1060 HilightWithColor (theObject, anObjSelStyle, Standard_False);
c3282ec1 1061 }
7fd59977 1062 }
c3282ec1 1063 else
1064 {
8e5fb5ea 1065 HilightWithColor (theObject, anObjSelStyle, Standard_False);
c3282ec1 1066 }
f838dac4 1067 anOwner->SetSelected (Standard_True);
c3282ec1 1068
1069 if (theToUpdateViewer)
1070 UpdateCurrentViewer();
7fd59977 1071}
1072
1073//=======================================================================
c3282ec1 1074//function : SetSelected
1075//purpose : Sets the whole object as selected and highlights it with selection color
7fd59977 1076//=======================================================================
c3282ec1 1077void AIS_InteractiveContext::SetSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
1078 const Standard_Boolean theToUpdateViewer)
7fd59977 1079{
b4006117 1080 if (theOwner.IsNull() || !theOwner->HasSelectable() || !myFilters->IsOk (theOwner))
c3282ec1 1081 return;
1082
f838dac4 1083 const Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1084 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObject, theOwner);
731c9b5b 1085 if (NbSelected() == 1 && theOwner->IsSelected() && !theOwner->IsForcedHilight())
c3282ec1 1086 {
f838dac4 1087 Handle(Prs3d_Drawer) aCustomStyle;
8e5fb5ea 1088 if (HighlightStyle (theOwner, aCustomStyle))
c3282ec1 1089 {
8e5fb5ea 1090 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
c3282ec1 1091 {
1092 const Standard_Integer aHiMode = anObject->HasHilightMode() ? anObject->HilightMode() : 0;
8e5fb5ea 1093 theOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode);
c3282ec1 1094 }
1095 }
1096 return;
1097 }
1098
1099 if (!myObjects.IsBound (anObject))
1100 Display (anObject, Standard_False);
1101
b4006117 1102 unhighlightSelected();
c3282ec1 1103
016e5959 1104 mySelection->ClearAndSelect (theOwner);
f838dac4 1105 Handle(Prs3d_Drawer) aCustomStyle;
8e5fb5ea 1106 if (!HighlightStyle (theOwner, aCustomStyle) ||
1107 (!aCustomStyle.IsNull() && aCustomStyle != anObjSelStyle))
c3282ec1 1108 {
f838dac4 1109 theOwner->SetSelected (Standard_True);
8e5fb5ea 1110 highlightSelected (theOwner);
c3282ec1 1111 }
1112
f838dac4 1113 theOwner->SetSelected (Standard_True);
e1b01c73 1114 if (theOwner == anObject->GlobalSelOwner())
1115 {
1116 Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind (anObject);
1117 aState->SetHilightStatus (Standard_True);
8e5fb5ea 1118 aState->SetHilightStyle (anObjSelStyle);
e1b01c73 1119 }
1120
c3282ec1 1121 if (theToUpdateViewer)
1122 UpdateCurrentViewer();
7fd59977 1123}
1124
1125//=======================================================================
1126//function : AddOrRemoveSelected
c3282ec1 1127//purpose : Adds or removes current object from AIS selection and highlights/unhighlights it.
1128// Since this method makes sence only for neutral point selection of a whole object,
1129// if 0 selection of the object is empty this method simply does nothing.
7fd59977 1130//=======================================================================
c3282ec1 1131void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(AIS_InteractiveObject)& theObject,
1132 const Standard_Boolean theToUpdateViewer)
7fd59977 1133{
95081657 1134 if (theObject.IsNull())
1135 return;
c3282ec1 1136
1137 if (HasOpenedContext())
1138 return myLocalContexts (myCurLocalIndex)->AddOrRemoveSelected (theObject, theToUpdateViewer);
1139
95081657 1140 const Standard_Integer aGlobalSelMode = theObject->GlobalSelectionMode();
1141 if (!myObjects.IsBound (theObject) || !theObject->HasSelection (aGlobalSelMode))
c3282ec1 1142 return;
1143
2ec85268 1144 setContextToObject (theObject);
7411850a 1145 const Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
c3282ec1 1146
1147 if (anOwner.IsNull() || !anOwner->HasSelectable())
1148 return;
1149
1150 AddOrRemoveSelected (anOwner, theToUpdateViewer);
7fd59977 1151}
1152//=======================================================================
1153//function : AddOrRemoveSelected
1154//purpose :
1155//=======================================================================
1156
c3282ec1 1157void AIS_InteractiveContext::AddOrRemoveSelected (const TopoDS_Shape& aShap,
7fd59977 1158 const Standard_Boolean updateviewer)
1159{
1160 if(!HasOpenedContext()) {
0797d9d3 1161#ifdef OCCT_DEBUG
7fd59977 1162 cout<<" Attempt to remove a selected shape with no opened local context"<<endl;
1163#endif
1164 return;
1165 }
1166
1167 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(aShap,updateviewer);
1168 if(updateviewer) UpdateCurrentViewer();
1169
1170}
c3282ec1 1171
7fd59977 1172//=======================================================================
1173//function : AddOrRemoveSelected
c3282ec1 1174//purpose : Allows to highlight or unhighlight the owner given depending on
1175// its selection status
7fd59977 1176//=======================================================================
c3282ec1 1177void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
1178 const Standard_Boolean theToUpdateViewer)
1179{
1180 if (HasOpenedContext())
1181 return myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected (theOwner, theToUpdateViewer);
7fd59977 1182
c3282ec1 1183 if (theOwner.IsNull() || !theOwner->HasSelectable())
7fd59977 1184 return;
c3282ec1 1185
016e5959 1186 AIS_SelectStatus aSelStat = mySelection->Select (theOwner);
f838dac4 1187 theOwner->SetSelected (aSelStat == AIS_SS_Added);
c3282ec1 1188 const Handle(AIS_InteractiveObject) anObj =
1189 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1190 const Standard_Boolean isGlobal = anObj->GlobalSelOwner() == theOwner;
e1b01c73 1191 Handle(AIS_GlobalStatus)& aStatus = myObjects.ChangeFind (anObj);
f838dac4 1192 if (theOwner->IsSelected())
c3282ec1 1193 {
8e5fb5ea 1194 highlightSelected (theOwner);
c3282ec1 1195 if (isGlobal)
1196 {
1197 aStatus->SetHilightStatus (Standard_True);
f838dac4 1198 aStatus->SetHilightStyle (getSelStyle (anObj, theOwner));
c3282ec1 1199 }
1200 }
1201 else
1202 {
1203 if (theOwner->IsAutoHilight())
f838dac4 1204 {
1205 theOwner->Unhilight (myMainPM);
1206 }
c3282ec1 1207 else
f838dac4 1208 {
c3282ec1 1209 anObj->ClearSelected();
f838dac4 1210 }
c3282ec1 1211 aStatus->SetHilightStatus (Standard_False);
f838dac4 1212 aStatus->SetHilightStyle (Handle(Prs3d_Drawer)());
7fd59977 1213 }
7fd59977 1214
c3282ec1 1215 if (theToUpdateViewer)
1216 UpdateCurrentViewer();
1217}
7fd59977 1218
1219
1220//=======================================================================
1221//function : IsSelected
c3282ec1 1222//purpose :
7fd59977 1223//=======================================================================
c3282ec1 1224Standard_Boolean AIS_InteractiveContext::IsSelected (const Handle(AIS_InteractiveObject)& theObj) const
7fd59977 1225{
c3282ec1 1226 if(HasOpenedContext())
1227 return myLocalContexts(myCurLocalIndex)->IsSelected (theObj);
1228
1229 if (theObj.IsNull() || !myObjects.IsBound (theObj))
1230 return Standard_False;
1231
1232 const Standard_Integer aGlobalSelMode = theObj->GlobalSelectionMode();
1233 const TColStd_ListOfInteger& anActivatedModes = myObjects (theObj)->SelectionModes();
1234 Standard_Boolean isGlobalModeActivated = Standard_False;
1235 for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next())
1236 {
1237 if (aModeIter.Value() == aGlobalSelMode)
1238 {
1239 isGlobalModeActivated = Standard_True;
1240 break;
1241 }
1242 }
95081657 1243 if (!theObj->HasSelection (aGlobalSelMode) || !isGlobalModeActivated || theObj->GlobalSelOwner().IsNull())
c3282ec1 1244 return Standard_False;
1245
f838dac4 1246 return theObj->GlobalSelOwner()->IsSelected();
7fd59977 1247}
1248
c3282ec1 1249//=======================================================================
1250//function : IsSelected
1251//purpose : Returns true is the owner given is selected
1252//=======================================================================
1253Standard_Boolean AIS_InteractiveContext::IsSelected (const Handle(SelectMgr_EntityOwner)& theOwner) const
1254{
1255 if (HasOpenedContext())
1256 return myLocalContexts(myCurLocalIndex)->IsSelected (theOwner);
1257
1258 if (theOwner.IsNull())
1259 return Standard_False;
1260
1261 return theOwner->IsSelected();
1262}
7fd59977 1263
1264//=======================================================================
1265//function : InitSelected
c3282ec1 1266//purpose :
7fd59977 1267//=======================================================================
7fd59977 1268void AIS_InteractiveContext::InitSelected()
1269{
c3282ec1 1270 if (HasOpenedContext())
1271 {
1272 myLocalContexts (myCurLocalIndex)->InitSelected();
1273 return;
1274 }
1275
016e5959 1276 mySelection->Init();
7fd59977 1277}
1278
1279//=======================================================================
1280//function : MoreSelected
c3282ec1 1281//purpose :
7fd59977 1282//=======================================================================
c3282ec1 1283Standard_Boolean AIS_InteractiveContext::MoreSelected() const
7fd59977 1284{
c3282ec1 1285 if (HasOpenedContext())
1286 return myLocalContexts (myCurLocalIndex)->MoreSelected();
1287
016e5959 1288 return mySelection->More();
7fd59977 1289}
1290
1291//=======================================================================
1292//function : NextSelected
c3282ec1 1293//purpose :
7fd59977 1294//=======================================================================
7fd59977 1295void AIS_InteractiveContext::NextSelected()
1296{
c3282ec1 1297 if(HasOpenedContext())
1298 {
1299 return myLocalContexts (myCurLocalIndex)->NextSelected();
c3282ec1 1300 }
1301
016e5959 1302 mySelection->Next();
7fd59977 1303}
1304
1305//=======================================================================
1306//function : HasSelectedShape
c3282ec1 1307//purpose :
7fd59977 1308//=======================================================================
c3282ec1 1309Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
7fd59977 1310{
c3282ec1 1311 if(HasOpenedContext())
1312 {
1313 return myLocalContexts(myCurLocalIndex)->HasSelectedShape();
7fd59977 1314 }
4aaadad7
SS
1315 if (!mySelection->More())
1316 return Standard_False;
1317
1318 const Handle(StdSelect_BRepOwner) anOwner =
1319 Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
c3282ec1 1320
4aaadad7 1321 return !anOwner.IsNull() && anOwner->HasShape();
7fd59977 1322}
1323
1324//=======================================================================
1325//function : SelectedShape
c3282ec1 1326//purpose :
7fd59977 1327//=======================================================================
c3282ec1 1328TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
7fd59977 1329{
c3282ec1 1330 if (HasOpenedContext())
0717ddc1 1331 {
1332 return myLocalContexts (myCurLocalIndex)->SelectedShape();
1333 }
7fd59977 1334
02974a19 1335 if (!mySelection->More())
c3282ec1 1336 return TopoDS_Shape();
7fd59977 1337
c3282ec1 1338 const Handle(StdSelect_BRepOwner) anOwner =
016e5959 1339 Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
3475df12 1340 if (anOwner.IsNull() || !anOwner->HasSelectable())
c3282ec1 1341 return TopoDS_Shape();
1342
1343 return anOwner->Shape().Located (anOwner->Location() * anOwner->Shape().Location());
7fd59977 1344}
1345
c3282ec1 1346//=======================================================================
1347//function : SelectedInteractive
1348//purpose :
1349//=======================================================================
7fd59977 1350Handle(AIS_InteractiveObject) AIS_InteractiveContext::SelectedInteractive() const
1351{
c3282ec1 1352 if (HasOpenedContext())
1353 {
1354 return myLocalContexts(myCurLocalIndex)->SelectedInteractive();
1355 }
1356
02974a19 1357 return !mySelection->More()
1358 ? Handle(AIS_InteractiveObject)()
1359 : Handle(AIS_InteractiveObject)::DownCast (mySelection->Value()->Selectable());
7fd59977 1360}
1361//=======================================================================
c3282ec1 1362//function : SelectedOwner
1363//purpose :
7fd59977 1364//=======================================================================
c3282ec1 1365Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const
7fd59977 1366{
c3282ec1 1367 if(HasOpenedContext())
1368 {
1369 return myLocalContexts(myCurLocalIndex)->SelectedOwner();
7fd59977 1370 }
c3282ec1 1371
02974a19 1372 return !mySelection->More()
1373 ? Handle(SelectMgr_EntityOwner)()
1374 : mySelection->Value();
7fd59977 1375}
1376
1377//=======================================================================
1378//function : EntityOwners
1379//purpose :
1380//=======================================================================
b586500b 1381void AIS_InteractiveContext::EntityOwners(Handle(SelectMgr_IndexedMapOfOwner)& theOwners,
7fd59977 1382 const Handle(AIS_InteractiveObject)& theIObj,
1383 const Standard_Integer theMode) const
1384{
1385 if ( theIObj.IsNull() )
1386 return;
1387
1388 TColStd_ListOfInteger aModes;
1389 if ( theMode == -1 )
1390 ActivatedModes( theIObj, aModes );
1391 else
1392 aModes.Append( theMode );
1393
b586500b 1394 if (theOwners.IsNull())
1395 theOwners = new SelectMgr_IndexedMapOfOwner();
1396
7fd59977 1397 TColStd_ListIteratorOfListOfInteger anItr( aModes );
1398 for (; anItr.More(); anItr.Next() )
1399 {
1400 int aMode = anItr.Value();
1401 if ( !theIObj->HasSelection( aMode ) )
1402 continue;
1403
f751596e 1404 Handle(SelectMgr_Selection) aSel = theIObj->Selection(aMode);
7fd59977 1405
1406 for ( aSel->Init(); aSel->More(); aSel->Next() )
1407 {
f751596e 1408 Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive()->BaseSensitive();
7fd59977 1409 if ( aEntity.IsNull() )
1410 continue;
1411
1412 Handle(SelectMgr_EntityOwner) aOwner =
1413 Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId());
1414 if ( !aOwner.IsNull() )
b586500b 1415 theOwners->Add( aOwner );
7fd59977 1416 }
1417 }
1418}
1419
c3282ec1 1420//=======================================================================
1421//function : NbSelected
1422//purpose :
1423//=======================================================================
1424Standard_Integer AIS_InteractiveContext::NbSelected()
7fd59977 1425{
c3282ec1 1426 Standard_Integer aNbSelected = 0;
1427 for (InitSelected(); MoreSelected(); NextSelected())
1428 {
1429 aNbSelected++;
1430 }
1431
1432 return aNbSelected;
7fd59977 1433}
1434
1435//=======================================================================
1436//function : HasApplicative
c3282ec1 1437//purpose :
7fd59977 1438//=======================================================================
7fd59977 1439 Standard_Boolean AIS_InteractiveContext::HasApplicative() const
1440{
c3282ec1 1441 return SelectedInteractive()->HasOwner();
7fd59977 1442}
1443
1444//=======================================================================
1445//function : Applicative
c3282ec1 1446//purpose :
7fd59977 1447//=======================================================================
7fd59977 1448Handle(Standard_Transient) AIS_InteractiveContext::Applicative() const
1449{
c3282ec1 1450 return SelectedInteractive()->GetOwner();
7fd59977 1451}
1452
7fd59977 1453//==================================================
c3282ec1 1454// Function: HasDetected
7fd59977 1455// Purpose :
1456//==================================================
c3282ec1 1457Standard_Boolean AIS_InteractiveContext::HasDetected() const
7fd59977 1458{
1459 if(HasOpenedContext())
1460 return myLocalContexts(myCurLocalIndex)->HasDetected();
c3282ec1 1461
1462 return !myLastPicked.IsNull();
7fd59977 1463}
1464
1465//=======================================================================
1466//function : HasDetectedShape
1467//purpose :
1468//=======================================================================
1469
1470Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
1471{
1472 if(HasOpenedContext())
1473 return myLocalContexts(myCurLocalIndex)->HasDetectedShape();
1474 return Standard_False;
1475}
1476
1477//=======================================================================
1478//function : DetectedShape
1479//purpose :
1480//=======================================================================
1481
1482const TopoDS_Shape&
1483AIS_InteractiveContext::DetectedShape() const
1484{
1485 return myLocalContexts(myCurLocalIndex)->DetectedShape();
1486}
1487
1488//=======================================================================
1489//function : DetectedInteractive
c3282ec1 1490//purpose :
7fd59977 1491//=======================================================================
c3282ec1 1492Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedInteractive() const
7fd59977 1493{
c3282ec1 1494 if (HasOpenedContext())
7fd59977 1495 return myLocalContexts(myCurLocalIndex)->DetectedInteractive();
c3282ec1 1496
1497 return Handle(AIS_InteractiveObject)::DownCast (myLastPicked->Selectable());
7fd59977 1498}
1499
f0cddd16 1500//=======================================================================
1501//function : HasNextDetected
1502//purpose :
1503//=======================================================================
7fd59977 1504Standard_Boolean AIS_InteractiveContext::HasNextDetected() const
1505{
f0cddd16 1506 if (HasOpenedContext())
1507 {
7fd59977 1508 return myLocalContexts(myCurLocalIndex)->HasNextDetected();
f0cddd16 1509 }
1510
1511 return !myDetectedSeq.IsEmpty() && myCurHighlighted <= myDetectedSeq.Upper();
7fd59977 1512}
1513
1514
1515//=======================================================================
1516//function : DetectedOwner
1517//purpose :
1518//=======================================================================
1519Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedOwner() const
1520{
c3282ec1 1521 if (HasOpenedContext())
7fd59977 1522 return myLocalContexts(myCurLocalIndex)->DetectedOwner();
7fd59977 1523
c3282ec1 1524 return myLastPicked;
1525}
7fd59977 1526
1527//=======================================================================
1528//function : HilightNextDetected
679ecdee 1529//purpose :
7fd59977 1530//=======================================================================
679ecdee 1531Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView,
1532 const Standard_Boolean theToRedrawImmediate)
7fd59977 1533{
f0cddd16 1534 if (HasOpenedContext())
1535 {
1536 return myLocalContexts (myCurLocalIndex)->HilightNextDetected (theView, theToRedrawImmediate);
1537 }
1538
1539 myMainPM->ClearImmediateDraw();
1540 if (myDetectedSeq.IsEmpty())
1541 {
1542 return 0;
1543 }
1544
1545 if (++myCurHighlighted > myDetectedSeq.Upper())
1546 {
1547 myCurHighlighted = myDetectedSeq.Lower();
1548 }
1549 const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted));
1550 if (anOwner.IsNull())
1551 {
1552 return 0;
1553 }
1554
1555 highlightWithColor (anOwner, theView->Viewer());
1556 myLastPicked = anOwner;
1557 myLastinMain = myLastPicked;
1558
1559 if (theToRedrawImmediate)
1560 {
1561 myMainPM->RedrawImmediate (theView->Viewer());
1562 myMainVwr->RedrawImmediate();
1563 }
1564
1565 return myCurHighlighted;
7fd59977 1566}
1567
1568//=======================================================================
f0cddd16 1569//function : HilightPreviousDetected
679ecdee 1570//purpose :
7fd59977 1571//=======================================================================
679ecdee 1572Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1573 const Standard_Boolean theToRedrawImmediate)
7fd59977 1574{
f0cddd16 1575 if (HasOpenedContext())
1576 {
1577 return myLocalContexts (myCurLocalIndex)->HilightPreviousDetected (theView, theToRedrawImmediate);
1578 }
1579
1580 myMainPM->ClearImmediateDraw();
1581 if (myDetectedSeq.IsEmpty())
1582 {
1583 return 0;
1584 }
1585
1586 if (--myCurHighlighted < myDetectedSeq.Lower())
1587 {
1588 myCurHighlighted = myDetectedSeq.Upper();
1589 }
1590 const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted));
1591 if (anOwner.IsNull())
1592 {
1593 return 0;
1594 }
1595
1596 highlightWithColor (anOwner, theView->Viewer());
1597 myLastPicked = anOwner;
1598 myLastinMain = myLastPicked;
1599
1600 if (theToRedrawImmediate)
1601 {
1602 myMainPM->RedrawImmediate (theView->Viewer());
1603 myMainVwr->RedrawImmediate();
1604 }
1605
1606 return myCurHighlighted;
7fd59977 1607}
1608
7fd59977 1609//=======================================================================
1610//function : InitDetected
1611//purpose :
1612//=======================================================================
1613void AIS_InteractiveContext::InitDetected()
1614{
57ad5cbd 1615 if (HasOpenedContext())
7fd59977 1616 {
f0cddd16 1617 myLocalContexts (myCurLocalIndex)->InitDetected();
7fd59977 1618 return;
1619 }
1620
f0cddd16 1621 if (!myDetectedSeq.IsEmpty())
57ad5cbd 1622 {
f0cddd16 1623 myCurDetected = myDetectedSeq.Lower();
57ad5cbd 1624 }
7fd59977 1625}
1626
1627//=======================================================================
1628//function : MoreDetected
1629//purpose :
1630//=======================================================================
1631Standard_Boolean AIS_InteractiveContext::MoreDetected() const
1632{
57ad5cbd 1633 if (HasOpenedContext())
1634 {
f0cddd16 1635 return myLocalContexts (myCurLocalIndex)->MoreDetected();
57ad5cbd 1636 }
7fd59977 1637
f0cddd16 1638 return myCurDetected >= myDetectedSeq.Lower() && myCurDetected <= myDetectedSeq.Upper();
7fd59977 1639}
1640
1641//=======================================================================
1642//function : NextDetected
1643//purpose :
1644//=======================================================================
1645void AIS_InteractiveContext::NextDetected()
1646{
f0cddd16 1647 if (HasOpenedContext())
7fd59977 1648 {
f0cddd16 1649 myLocalContexts (myCurLocalIndex)->NextDetected();
7fd59977 1650 return;
1651 }
1652
f0cddd16 1653 myCurDetected++;
7fd59977 1654}
1655
1656//=======================================================================
1657//function : DetectedCurrentShape
1658//purpose :
1659//=======================================================================
7fd59977 1660const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
1661{
57ad5cbd 1662 if (HasOpenedContext())
1663 {
7fd59977 1664 return myLocalContexts(myCurLocalIndex)->DetectedCurrentShape();
57ad5cbd 1665 }
7fd59977 1666
404c8936 1667 Standard_DISABLE_DEPRECATION_WARNINGS
57ad5cbd 1668 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
404c8936 1669 Standard_ENABLE_DEPRECATION_WARNINGS
57ad5cbd 1670
1671 if (aCurrentShape.IsNull())
1672 {
016e5959 1673 return AIS_myDummyShape;
57ad5cbd 1674 }
1675
1676 return aCurrentShape->Shape();
7fd59977 1677}
1678
1679//=======================================================================
1680//function : DetectedCurrentObject
1681//purpose :
1682//=======================================================================
57ad5cbd 1683Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const
1684{
1685 if (HasOpenedContext())
1686 {
7fd59977 1687 return myLocalContexts(myCurLocalIndex)->DetectedCurrentObject();
57ad5cbd 1688 }
7fd59977 1689
f0cddd16 1690 return MoreDetected()
1691 ? Handle(AIS_InteractiveObject)::DownCast (myMainSel->Picked (myDetectedSeq (myCurDetected))->Selectable())
1692 : NULL;
7fd59977 1693}
c3282ec1 1694
1695//=======================================================================
1696//function : FirstSelectedObject
1697//purpose :
1698//=======================================================================
1699Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstSelectedObject()
1700{
1701 Handle(AIS_InteractiveObject) anObject;
1702
1703 if (HasOpenedContext())
1704 return anObject;
1705
1706 InitSelected();
1707 if (MoreSelected())
1708 {
1709 return SelectedInteractive();
1710 }
1711 return anObject;
1712}
1713
1714//=======================================================================
1715//function : RedrawImmediate
1716//purpose : Redisplays immediate strucures of the viewer given according to their visibility
1717//=======================================================================
1718void AIS_InteractiveContext::RedrawImmediate (const Handle(V3d_Viewer)& theViewer)
1719{
1720 myMainPM->RedrawImmediate (theViewer);
1721}