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