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