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