0024023: Revamp the OCCT Handle -- ambiguity
[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#include <AIS_InteractiveContext.jxx>
18#include <SelectMgr_EntityOwner.hxx>
f751596e 19#include <StdSelect_ViewerSelector3d.hxx>
7fd59977 20#include <AIS_Selection.hxx>
21#include <AIS_StatusOfDetection.hxx>
22#include <AIS_StatusOfPick.hxx>
23
24#include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
25#include <AIS_LocalContext.hxx>
26#include <AIS_GlobalStatus.hxx>
27#include <AIS_Shape.hxx>
28
679ecdee 29#include <Aspect_Grid.hxx>
30
7fd59977 31#include <V3d_Light.hxx>
32#include <V3d_PositionalLight.hxx>
33#include <V3d_SpotLight.hxx>
34#include <V3d_DirectionalLight.hxx>
35#include <V3d_AmbientLight.hxx>
a272ed94 36#include <Visual3d_View.hxx>
7fd59977 37
38#include <TColStd_ListIteratorOfListOfInteger.hxx>
39#include <SelectMgr_Selection.hxx>
40#include <SelectBasics_SensitiveEntity.hxx>
41
7fd59977 42#include <Prs3d_Presentation.hxx>
7fd59977 43
7fd59977 44#include <AIS_MapOfInteractive.hxx>
45#include <AIS_MapIteratorOfMapOfInteractive.hxx>
ec357c5c 46#include <AIS_InteractiveObject.hxx>
7fd59977 47
7fd59977 48//=======================================================================
49//function : MoveTo
679ecdee 50//purpose :
7fd59977 51//=======================================================================
679ecdee 52AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const Standard_Integer theXPix,
53 const Standard_Integer theYPix,
54 const Handle(V3d_View)& theView,
55 const Standard_Boolean theToRedrawOnUpdate)
7fd59977 56{
679ecdee 57 if (HasOpenedContext())
58 {
7fd59977 59 myWasLastMain = Standard_True;
679ecdee 60 return myLocalContexts (myCurLocalIndex)->MoveTo (theXPix, theYPix, theView, theToRedrawOnUpdate);
7fd59977 61 }
62
7fd59977 63 myAISCurDetected = 0;
64 myAISDetectedSeq.Clear();
7fd59977 65
679ecdee 66 if (theView->Viewer() != myMainVwr)
67 {
7fd59977 68 return AIS_SOD_Error;
679ecdee 69 }
70
71 // preliminaires
72 myLastPicked = myLastinMain;
73 myWasLastMain = Standard_True;
74 AIS_StatusOfDetection aStatus = AIS_SOD_Nothing;
75 Standard_Boolean toUpdateViewer = Standard_False;
76
a272ed94 77 myFilters->SetDisabledObjects (theView->View()->HiddenObjects());
679ecdee 78 myMainSel->Pick (theXPix, theYPix, theView);
79
80 // filling of myAISDetectedSeq sequence storing information about detected AIS objects
81 // (the objects must be AIS_Shapes)
82 const Standard_Integer aDetectedNb = myMainSel->NbPicked();
54a16ee4 83 Standard_Integer aNewDetected = 0;
679ecdee 84 for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
7fd59977 85 {
679ecdee 86 Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aDetIter);
87 if (anOwner.IsNull()
88 || !myFilters->IsOk (anOwner))
89 {
90 continue;
91 }
92
54a16ee4 93 if (aNewDetected < 1)
94 {
95 aNewDetected = aDetIter;
96 }
679ecdee 97 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
57ad5cbd 98 if (!anObj.IsNull())
679ecdee 99 {
100 myAISDetectedSeq.Append (anObj);
101 }
7fd59977 102 }
7fd59977 103
54a16ee4 104 if (aNewDetected >= 1)
7fd59977 105 {
679ecdee 106 // does nothing if previously detected object is equal to the current one
54a16ee4 107 Handle(SelectMgr_EntityOwner) aNewPickedOwner = myMainSel->Picked (aNewDetected);
108 if (aNewPickedOwner->Selectable() == myLastPicked)
eafb234b 109 {
8abada55 110 return myLastPicked->State() == 1
111 ? AIS_SOD_Selected
112 : AIS_SOD_OnlyOneDetected;
679ecdee 113 }
81bba717 114
7fd59977 115 // Previously detected object is unhilighted if it is not selected or hilighted
116 // with selection color if it is selected. Such highlighting with selection color
117 // is needed only if myToHilightSelected flag is true. In this case previously detected
118 // object has been already highlighted with myHilightColor during previous MoveTo()
119 // method call. As result it is necessary to rehighligt it with mySelectionColor.
be6e564e 120 if (!myLastPicked.IsNull())
7fd59977 121 {
679ecdee 122 const Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
be6e564e 123 if (myLastPicked->State() != 1)
7fd59977 124 {
679ecdee 125 myMainPM->Unhighlight (myLastPicked, aHiMod);
126 toUpdateViewer = Standard_True;
7fd59977 127 }
be6e564e 128 else if (myToHilightSelected)
7fd59977 129 {
679ecdee 130 myMainPM->Color (myLastPicked, mySelectionColor, aHiMod);
131 toUpdateViewer = Standard_True;
7fd59977 132 }
133 }
be6e564e 134
679ecdee 135 // initialize myLastPicked field with currently detected object
54a16ee4 136 myLastPicked = Handle(AIS_InteractiveObject)::DownCast (aNewPickedOwner->Selectable());
679ecdee 137 myLastinMain = myLastPicked;
be6e564e 138
679ecdee 139 // highlight detected object if it is not selected or myToHilightSelected flag is true
140 if (!myLastPicked.IsNull())
7fd59977 141 {
679ecdee 142 if (myLastPicked->State() != 1 || myToHilightSelected)
143 {
144 const Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
145 myMainPM->Color (myLastPicked, myHilightColor, aHiMod);
146 toUpdateViewer = Standard_True;
147 }
be6e564e 148
8abada55 149 aStatus = myLastPicked->State() == 1
150 ? AIS_SOD_Selected
151 : AIS_SOD_OnlyOneDetected;
be6e564e 152 }
7fd59977 153 }
154 else
155 {
679ecdee 156 // previously detected object is unhilighted if it is not selected or hilighted
157 // with selection color if it is selected
158 aStatus = AIS_SOD_Nothing;
be6e564e 159 if (!myLastPicked.IsNull())
7fd59977 160 {
be6e564e 161 Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
162 if (myLastPicked->State() != 1)
7fd59977 163 {
679ecdee 164 myMainPM->Unhighlight (myLastPicked, aHiMod);
165 toUpdateViewer = Standard_True;
7fd59977 166 }
be6e564e 167 else if (myToHilightSelected)
7fd59977 168 {
679ecdee 169 myMainPM->Color (myLastPicked, mySelectionColor, aHiMod);
170 toUpdateViewer = Standard_True;
7fd59977 171 }
172 }
be6e564e 173
679ecdee 174 myLastinMain.Nullify();
8abada55 175 myLastPicked.Nullify();
7fd59977 176 }
679ecdee 177
178 if (toUpdateViewer)
179 {
180 if (theToRedrawOnUpdate)
181 {
182 theView->Viewer()->Update();
183 }
184 else
185 {
186 theView->Viewer()->Invalidate();
187 }
188 }
189
679ecdee 190 mylastmoveview = theView;
191 return aStatus;
7fd59977 192}
193
194//=======================================================================
195//function : Select
196//purpose :
197//=======================================================================
c398b00e 198AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Integer theXPMin,
199 const Standard_Integer theYPMin,
200 const Standard_Integer theXPMax,
201 const Standard_Integer theYPMax,
202 const Handle(V3d_View)& theView,
203 const Standard_Boolean toUpdateViewer)
7fd59977 204{
81bba717 205 // all objects detected by the selector are taken, previous current objects are emptied,
206 // new objects are put...
7fd59977 207
c398b00e 208 if (HasOpenedContext())
209 {
210 return myLocalContexts(myCurLocalIndex)->Select (theXPMin, theYPMin,
211 theXPMax, theYPMax,
212 theView, toUpdateViewer);
213 }
7fd59977 214
c398b00e 215 ClearCurrents (Standard_False);
eb4320f2 216
c398b00e 217 Handle(StdSelect_ViewerSelector3d) aSelector;
7fd59977 218
c398b00e 219 if (theView->Viewer() == myMainVwr)
7fd59977 220 {
c398b00e 221 aSelector = myMainSel;
222 myWasLastMain = Standard_True;
7fd59977 223 }
c398b00e 224
225 aSelector->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
226 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
227
228 AIS_MapOfInteractive anObjectsToSelect;
229 for (aSelector->Init(); aSelector->More(); aSelector->Next())
7fd59977 230 {
c398b00e 231 Handle(AIS_InteractiveObject) anObj =
232 Handle(AIS_InteractiveObject)::DownCast (aSelector->Picked()->Selectable());
233 if (!anObj.IsNull())
234 {
235 anObjectsToSelect.Add (anObj);
7fd59977 236 }
237 }
238
c398b00e 239 AIS_MapIteratorOfMapOfInteractive anIt (anObjectsToSelect);
240 for ( ; anIt.More(); anIt.Next())
241 {
242 AIS_Selection::Select (anIt.Key());
243 anIt.Key()->State (1);
244 }
245
246 HilightCurrents (toUpdateViewer);
247
248 Standard_Integer aSelNum = NbCurrents();
249
250 return (aSelNum == 0) ? AIS_SOP_NothingSelected
251 : (aSelNum == 1) ? AIS_SOP_OneSelected
252 : AIS_SOP_SeveralSelected;
7fd59977 253
254}
255
256//=======================================================================
257//function : Select
258//purpose : Selection by polyline
259//=======================================================================
c398b00e 260AIS_StatusOfPick AIS_InteractiveContext::Select (const TColgp_Array1OfPnt2d& thePolyline,
261 const Handle(V3d_View)& theView,
262 const Standard_Boolean toUpdateViewer)
7fd59977 263{
81bba717 264 // all objects detected by the selector are taken, previous current objects are emptied,
265 // new objects are put...
7fd59977 266
c398b00e 267 if (HasOpenedContext())
268 {
269 return myLocalContexts(myCurLocalIndex)->Select (thePolyline, theView, toUpdateViewer);
270 }
eb4320f2 271
c398b00e 272 ClearCurrents (Standard_False);
7fd59977 273
c398b00e 274 Handle(StdSelect_ViewerSelector3d) aSelector;
7fd59977 275
c398b00e 276 if (theView->Viewer() == myMainVwr)
7fd59977 277 {
c398b00e 278 aSelector = myMainSel;
279 myWasLastMain = Standard_True;
7fd59977 280 }
c398b00e 281
282 aSelector->Pick (thePolyline, theView);
283 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
284
285 AIS_MapOfInteractive anObjectsToSelect;
286 for (aSelector->Init(); aSelector->More(); aSelector->Next())
7fd59977 287 {
c398b00e 288 Handle(AIS_InteractiveObject) anObj =
289 Handle( AIS_InteractiveObject )::DownCast (aSelector->Picked()->Selectable());
290 if (!anObj.IsNull())
291 {
292 anObjectsToSelect.Add (anObj);
7fd59977 293 }
294 }
c398b00e 295
296 AIS_MapIteratorOfMapOfInteractive anIt (anObjectsToSelect);
297 for ( ; anIt.More(); anIt.Next())
298 {
299 AIS_Selection::Select (anIt.Key());
300 anIt.Key()->State (1);
301 }
302
303 HilightCurrents (toUpdateViewer);
304
305 Standard_Integer aSelNum = NbCurrents();
306
307 return (aSelNum == 0) ? AIS_SOP_NothingSelected
308 : (aSelNum == 1) ? AIS_SOP_OneSelected
309 : AIS_SOP_SeveralSelected;
7fd59977 310
311}
312
313//=======================================================================
314//function : Select
315//purpose :
316//=======================================================================
c398b00e 317AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean toUpdateViewer)
7fd59977 318{
c398b00e 319 if (HasOpenedContext())
320 {
7fd59977 321 if(myWasLastMain)
c398b00e 322 {
323 return myLocalContexts(myCurLocalIndex)->Select (toUpdateViewer);
324 }
7fd59977 325 else
c398b00e 326 {
327 myLocalContexts(myCurLocalIndex)->SetSelected (myLastPicked, toUpdateViewer);
328 return AIS_SOP_OneSelected;
329 }
330 }
331
332 if (myWasLastMain && !myLastinMain.IsNull())
333 {
334 if(myLastinMain->State() != 1)
335 {
336 SetCurrentObject (myLastinMain,Standard_False);
337 if(toUpdateViewer)
7fd59977 338 {
c398b00e 339 UpdateCurrentViewer();
7fd59977 340 }
c398b00e 341 }
7fd59977 342 }
c398b00e 343 else
344 {
345 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
346 Handle(AIS_Selection) aSelection = AIS_Selection::CurrentSelection();
347 Handle(AIS_InteractiveObject) anObj;
348 for (aSelection->Init(); aSelection->More(); aSelection->Next())
349 {
350 anObj = Handle(AIS_InteractiveObject)::DownCast (aSelection->Value());
351 anObj->State (0);
352 Unhilight (anObj,Standard_False);
353 if (myObjects.IsBound (anObj) && myObjects(anObj)->IsSubIntensityOn())
354 {
355 HilightWithColor (anObj, mySubIntensity, Standard_False);
7fd59977 356 }
357 }
c398b00e 358
7fd59977 359 AIS_Selection::Select();
c398b00e 360 if (toUpdateViewer && myWasLastMain)
361 {
eb4320f2 362 UpdateCurrentViewer();
7fd59977 363 }
364 }
c398b00e 365
366 Standard_Integer aSelNum = NbCurrents();
367
368 return (aSelNum == 0) ? AIS_SOP_NothingSelected
369 : (aSelNum == 1) ? AIS_SOP_OneSelected
370 : AIS_SOP_SeveralSelected;
7fd59977 371}
372
373//=======================================================================
374//function : ShiftSelect
375//purpose :
376//=======================================================================
c398b00e 377AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Boolean toUpdateViewer)
7fd59977 378{
c398b00e 379 if (HasOpenedContext())
380 {
7fd59977 381 if(myWasLastMain)
c398b00e 382 {
383 return myLocalContexts (myCurLocalIndex)->ShiftSelect (toUpdateViewer);
384 }
385 else
386 {
387 myLocalContexts (myCurLocalIndex)->AddOrRemoveSelected (myLastPicked, toUpdateViewer);
388
389 Standard_Integer aSelNum = NbSelected();
390 return (aSelNum == 0) ? AIS_SOP_NothingSelected
391 : (aSelNum == 1) ? AIS_SOP_OneSelected
392 : AIS_SOP_SeveralSelected;
7fd59977 393 }
394 }
eb4320f2 395
c398b00e 396 if (myWasLastMain && !myLastinMain.IsNull())
397 {
398 AddOrRemoveCurrentObject (myLastinMain, toUpdateViewer);
399 }
7fd59977 400
c398b00e 401 Standard_Integer aCurrentSelNum = NbCurrents();
402
403 return (aCurrentSelNum == 0) ? AIS_SOP_NothingSelected
404 : (aCurrentSelNum == 1) ? AIS_SOP_OneSelected
405 : AIS_SOP_SeveralSelected;
406}
7fd59977 407
408//=======================================================================
409//function : ShiftSelect
410//purpose :
411//=======================================================================
c398b00e 412AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Integer theXPMin,
413 const Standard_Integer theYPMin,
414 const Standard_Integer theXPMax,
415 const Standard_Integer theYPMax,
416 const Handle(V3d_View)& theView,
417 const Standard_Boolean toUpdateViewer)
7fd59977 418{
c398b00e 419 if (HasOpenedContext())
420 {
421 return myLocalContexts(myCurLocalIndex)->ShiftSelect (theXPMin, theYPMin, theXPMax, theYPMax,
422 theView, toUpdateViewer);
423 }
424
425 UnhilightCurrents (Standard_False);
426
427 Handle(StdSelect_ViewerSelector3d) aSelector;
428 if (theView->Viewer() == myMainVwr)
429 {
430 aSelector = myMainSel;
431 myWasLastMain = Standard_True;
432 }
7fd59977 433 else
c398b00e 434 {
7fd59977 435 return AIS_SOP_NothingSelected;
c398b00e 436 }
437
438 aSelector->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
439 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
440 for (aSelector->Init(); aSelector->More(); aSelector->Next())
441 {
442 Handle(AIS_InteractiveObject) anObjToSelect = Handle(AIS_InteractiveObject)::DownCast (aSelector->Picked()->Selectable());
443 if (!anObjToSelect.IsNull())
444 {
445 AIS_SelectStatus aSelStatus = AIS_Selection::Select (anObjToSelect);
446 Standard_Integer aState = (aSelStatus == AIS_SS_Added) ? 1 : 0;
447 anObjToSelect->State (aState);
7fd59977 448 }
449 }
c398b00e 450
451 HilightCurrents (toUpdateViewer);
452
453 Standard_Integer aSelNum = NbCurrents();
454
455 return (aSelNum == 0) ? AIS_SOP_NothingSelected
456 : (aSelNum == 1) ? AIS_SOP_OneSelected
457 : AIS_SOP_SeveralSelected;
458
7fd59977 459}
460
461//=======================================================================
462//function : ShiftSelect
463//purpose :
464//=======================================================================
c398b00e 465AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline,
466 const Handle(V3d_View)& theView,
467 const Standard_Boolean toUpdateViewer)
7fd59977 468{
c398b00e 469 if (HasOpenedContext())
470 {
471 return myLocalContexts(myCurLocalIndex)->ShiftSelect (thePolyline, theView, toUpdateViewer);
472 }
7fd59977 473
c398b00e 474 UnhilightCurrents (Standard_False);
475
476 Handle(StdSelect_ViewerSelector3d) aSelector;
477
478 if (theView->Viewer() == myMainVwr)
479 {
480 aSelector= myMainSel;
481 myWasLastMain = Standard_True;
482 }
483 else
484 {
485 return AIS_SOP_NothingSelected;
486 }
487
488 aSelector->Pick (thePolyline, theView);
489
490 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
491 for (aSelector->Init(); aSelector->More(); aSelector->Next())
492 {
493 Handle(AIS_InteractiveObject) anObjToSelect = Handle(AIS_InteractiveObject)::DownCast (aSelector->Picked()->Selectable());
494 if (!anObjToSelect.IsNull())
495 {
496 AIS_SelectStatus aSelStatus = AIS_Selection::Select (anObjToSelect);
497 Standard_Integer aState = (aSelStatus == AIS_SS_Added ) ? 1 : 0;
498 anObjToSelect->State (aState);
7fd59977 499 }
c398b00e 500 }
501
502 HilightCurrents (toUpdateViewer);
503
504 Standard_Integer aSelNum = NbCurrents();
505
506 return (aSelNum == 0) ? AIS_SOP_NothingSelected
507 : (aSelNum == 1) ? AIS_SOP_OneSelected
508 : AIS_SOP_SeveralSelected;
7fd59977 509}
510
511//=======================================================================
512//function : SetCurrentObject
513//purpose :
514//=======================================================================
7fd59977 515void AIS_InteractiveContext::SetCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
516 const Standard_Boolean updateviewer)
517{
81bba717 518 // single case processing...
7fd59977 519 if(NbCurrents()==1 && anIObj->State()==1){
520 Quantity_NameOfColor HiCol;
521 Standard_Boolean HasHiCol;
522 if(IsHilighted(anIObj,HasHiCol,HiCol)){
523 if(HasHiCol && HiCol!= mySelectionColor) {
7fd59977 524 HilightWithColor(anIObj,mySelectionColor,updateviewer);
7fd59977 525 }
526 }
527 return;
528 }
529
530
531 //
532 if(!HasOpenedContext()) {
533 if(anIObj.IsNull()) return;
534 if(!myObjects.IsBound(anIObj))
535 Display(anIObj,Standard_False);
536
537 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
538 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
539 Handle(Standard_Transient) TR;
540 Handle(AIS_InteractiveObject) IO;
541 sel->Init();
542 while (sel->More()) {
543 TR = sel->Value();
c5f3a425 544 IO = Handle(AIS_InteractiveObject)::DownCast (TR);
7fd59977 545 Unhilight(IO,Standard_False);
546 IO->State(0);
547 sel->Next();
548 }
549
81bba717 550 // added to avoid untimely viewer update...
7fd59977 551 AIS_Selection::ClearAndSelect(anIObj);
552 anIObj->State(1);
553 Quantity_NameOfColor HiCol;
554 Standard_Boolean HasHiCol;
555 if(IsHilighted(anIObj,HasHiCol,HiCol)){
556 if(HasHiCol && HiCol!= mySelectionColor) {
7fd59977 557 HilightWithColor(anIObj,mySelectionColor,Standard_False);
7fd59977 558 }
559 }
560 else{
7fd59977 561 HilightWithColor(anIObj,mySelectionColor,Standard_False);
7fd59977 562 }
563 if (updateviewer)
564 UpdateCurrentViewer();
565 }
566 else{
0797d9d3 567#ifdef OCCT_DEBUG
7fd59977 568 cout<<"Nothing Done : Opened Local Context"<<endl;
569#endif
570 }
571}
572
573//=======================================================================
574//function : AddOrRemoveCurrentObject
575//purpose :
576//=======================================================================
577
578void AIS_InteractiveContext::
579AddOrRemoveCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
580 const Standard_Boolean updateviewer)
581{
582 if(anIObj.IsNull()) return;
583//OCC5682 to remove an object from neutral point even if Local Context is opened (Remove method)
584 if(!HasOpenedContext() /*OCC5682*/|| myObjects.IsBound(anIObj)) {
585
586 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
587 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
588
589 AIS_SelectStatus SelStat = AIS_Selection::Select(anIObj);
590
591 Standard_Integer mod = (SelStat==AIS_SS_Added) ? 1 : 0;
592 anIObj->State(mod);
593 if(mod==1)
7fd59977 594 HilightWithColor(anIObj,mySelectionColor,Standard_False);
7fd59977 595 else
596 Unhilight(anIObj,Standard_False);
597
598
599 if(updateviewer)
600 UpdateCurrentViewer();
601 }
602 else{
0797d9d3 603#ifdef OCCT_DEBUG
7fd59977 604 cout<<"Nothing Done : Opened Local Context"<<endl;
605#endif
606 }
607}
608//=======================================================================
609//function : UpdateCurrent
610//purpose :
611//=======================================================================
612
613void AIS_InteractiveContext::UpdateCurrent()
614{
615 HilightCurrents();
616}
617
618//=======================================================================
619//function : IsCurrent
620//purpose :
621//=======================================================================
622
623Standard_Boolean AIS_InteractiveContext::IsCurrent(const Handle(AIS_InteractiveObject)& anIObj) const
624{
625
626 if (anIObj.IsNull()) return Standard_False;
627 return (anIObj->State()==1);
628
629 // Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
630 // sel->Init();
631 // while (sel->More()) {
632 // if (anIObj == sel->Value()) return Standard_True;
633 // sel->Next();
634 // }
635 // return Standard_False;
636
637}
638
639//=======================================================================
640//function : InitCurrent
641//purpose :
642//=======================================================================
643
644void AIS_InteractiveContext::InitCurrent()
645{
646 AIS_Selection::Selection(myCurrentName.ToCString())->Init();
647}
648
649//=======================================================================
650//function : MoreCurrent
651//purpose :
652//=======================================================================
653
654Standard_Boolean AIS_InteractiveContext::MoreCurrent() const
655{
656 return AIS_Selection::Selection(myCurrentName.ToCString())->More();
657
658}
659
660//=======================================================================
661//function : NextCurrent
662//purpose :
663//=======================================================================
664
665void AIS_InteractiveContext::NextCurrent()
666{
667 AIS_Selection::Selection(myCurrentName.ToCString())->Next();
668}
669
670//=======================================================================
671//function : Current
672//purpose :
673//=======================================================================
674
675Handle(AIS_InteractiveObject) AIS_InteractiveContext::Current() const
676{
677 Handle(Standard_Transient) TR = AIS_Selection::Selection(myCurrentName.ToCString())->Value();
c5f3a425 678 Handle(AIS_InteractiveObject) IO = Handle(AIS_InteractiveObject)::DownCast (TR);
7fd59977 679 return IO;
680}
681
682//=======================================================================
683//function : FirstCurrentObject
684//purpose :
685//=======================================================================
686Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstCurrentObject()
687{
688 Handle(AIS_InteractiveObject) IO ;
689 InitCurrent();
690 if(MoreCurrent()){
691 return Current();
692 }
693 return IO;
694}
695
696//=======================================================================
697//function : NbCurrents
698//purpose :
699//=======================================================================
700Standard_Integer AIS_InteractiveContext::NbCurrents()
701{
702 Standard_Integer i(0);
703 for(InitCurrent();MoreCurrent();NextCurrent())
704 {i++;}
705 return i;
706}
707
708//=======================================================================
709//function : HilightCurrents
710//purpose :
711//=======================================================================
712void AIS_InteractiveContext::HilightCurrents(const Standard_Boolean updateviewer)
713{
714 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
715 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
716 Handle(Standard_Transient) TR;
717 Handle(AIS_InteractiveObject) IO;
718 sel->Init();
719 while (sel->More()) {
720 TR = sel->Value();
c5f3a425 721 IO = Handle(AIS_InteractiveObject)::DownCast (TR);
7fd59977 722 HilightWithColor(IO,mySelectionColor,Standard_False);
7fd59977 723 sel->Next();
724 }
725 if(updateviewer)
726 UpdateCurrentViewer();
727}
728
729//=======================================================================
730//function : UnhilightCurrents
731//purpose :
732//=======================================================================
733
734void AIS_InteractiveContext::UnhilightCurrents(const Standard_Boolean updateviewer)
735{
736 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
737 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
738 Handle(Standard_Transient) TR;
739 Handle(AIS_InteractiveObject) IO;
740 sel->Init();
741 while (sel->More()) {
742 TR = sel->Value();
c5f3a425 743 IO = Handle(AIS_InteractiveObject)::DownCast (TR);
7fd59977 744 Unhilight(IO,Standard_False);
745 sel->Next();
746 }
747 if(updateviewer)
748 UpdateCurrentViewer();
749}
750
751//=======================================================================
752//function : ClearCurrents
753//purpose :
754//=======================================================================
755
756void AIS_InteractiveContext::ClearCurrents(const Standard_Boolean updateviewer)
757{
758 if(NbCurrents()==0) return;
759 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
760 Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
761 Handle(Standard_Transient) Tr;
762 Handle(AIS_InteractiveObject) IO;
763 for(S->Init();S->More();S->Next()){
764 Tr = S->Value();
c5f3a425 765 IO = Handle(AIS_InteractiveObject)::DownCast (Tr);
7fd59977 766 IO->State(0);
767 Unhilight(IO,Standard_False);
768 }
769 AIS_Selection::Select();
770 if(updateviewer)
771 UpdateCurrentViewer();
772}
773
774
775//=======================================================================
776//function : HilightSelected
777//purpose :
778//=======================================================================
779
780void AIS_InteractiveContext::HilightSelected(const Standard_Boolean updateviewer)
781{
782 if(!HasOpenedContext()){
783 AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
784 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
785 Handle(Standard_Transient) TR;
786 Handle(AIS_InteractiveObject) IO;
787 sel->Init();
788 while (sel->More()) {
789 TR = sel->Value();
c5f3a425 790 IO = Handle(AIS_InteractiveObject)::DownCast (TR);
7fd59977 791 HilightWithColor(IO,mySelectionColor,Standard_False);
7fd59977 792 sel->Next();
793 }
794 }
795 else
796 {
797 myLocalContexts(myCurLocalIndex)->HilightPicked(updateviewer);
798 }
799 if(updateviewer)
800 UpdateCurrentViewer();
801}
802
803//=======================================================================
804//function : UnhilightSelected
805//purpose :
806//=======================================================================
807
808void AIS_InteractiveContext::UnhilightSelected(const Standard_Boolean updateviewer)
809{
810 if(!HasOpenedContext()){
811 AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
812 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
813 Handle(Standard_Transient) TR;
814 Handle(AIS_InteractiveObject) IO;
815 sel->Init();
816 while (sel->More()) {
817 TR = sel->Value();
c5f3a425 818 IO = Handle(AIS_InteractiveObject)::DownCast (TR);
7fd59977 819 Unhilight(IO,Standard_False);
820 sel->Next();
821 }
822 if(updateviewer)
823 UpdateCurrentViewer();
824 }
825 else
826 {
827 myLocalContexts(myCurLocalIndex)->UnhilightPicked(updateviewer);
828 }
829}
830
831
832//=======================================================================
833//function : ClearSelected
834//purpose :
835//=======================================================================
836
837void AIS_InteractiveContext::ClearSelected(const Standard_Boolean updateviewer)
838{
839 if(!HasOpenedContext())
840 ClearCurrents(updateviewer);
841 else
842 myLocalContexts(myCurLocalIndex)->ClearSelected(updateviewer);
843
844}
845
846
847//=======================================================================
848//function : SetSelectedCurrent
849//purpose :
850//=======================================================================
851
852void AIS_InteractiveContext::SetSelectedCurrent()
853{
854
855
0797d9d3 856#ifdef OCCT_DEBUG
7fd59977 857 cout<<"Not Yet Implemented"<<endl;
858#endif
859}
860
861//=======================================================================
862//function : UpdateSelection
863//purpose :
864//=======================================================================
865
866void AIS_InteractiveContext::UpdateSelected(const Standard_Boolean updateviewer)
867{
868 if(!HasOpenedContext()) {
869 HilightSelected();
870#ifndef BUG
871 return;
872#endif
873 }
874 myLocalContexts(myCurLocalIndex)->UpdateSelected(updateviewer);
875}
876
877//=======================================================================
878//function : SetCurrentObject
879//purpose :
880//=======================================================================
881void AIS_InteractiveContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,const Standard_Boolean updateviewer)
882{
883 if(!HasOpenedContext())
884 SetCurrentObject(anIObj,updateviewer);
885 else
886 myLocalContexts(myCurLocalIndex)->SetSelected(anIObj,updateviewer);
887}
888
889//=======================================================================
890//function : AddOrRemoveSelected
891//purpose :
892//=======================================================================
893
894void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj,
895 const Standard_Boolean updateviewer)
896{
897 if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
898 if(!HasOpenedContext())
899 AddOrRemoveCurrentObject(anIObj,updateviewer);
900 else
901 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(anIObj,updateviewer);
902
903}
904//=======================================================================
905//function : AddOrRemoveSelected
906//purpose :
907//=======================================================================
908
909void AIS_InteractiveContext::AddOrRemoveSelected(const TopoDS_Shape& aShap,
910 const Standard_Boolean updateviewer)
911{
912 if(!HasOpenedContext()) {
0797d9d3 913#ifdef OCCT_DEBUG
7fd59977 914 cout<<" Attempt to remove a selected shape with no opened local context"<<endl;
915#endif
916 return;
917 }
918
919 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(aShap,updateviewer);
920 if(updateviewer) UpdateCurrentViewer();
921
922}
923//=======================================================================
924//function : AddOrRemoveSelected
925//purpose :
926//=======================================================================
927
928void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(SelectMgr_EntityOwner)& Own,
929 const Standard_Boolean updateviewer)
930{
931 if(!HasOpenedContext()) {
0797d9d3 932#ifdef OCCT_DEBUG
7fd59977 933 cout<<" Attempt to remove a selected ownr with no opened local context"<<endl;
934#endif
935 return;
936 }
937
938 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(Own,Standard_False);
939 if(updateviewer) UpdateCurrentViewer();
940
941}
942
943
944
945//=======================================================================
946//function : IsSelected
947//purpose :
948//=======================================================================
949
950Standard_Boolean AIS_InteractiveContext::
951IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const
952{
953 if (anIObj.IsNull()) return Standard_False;
954
955 if(!HasOpenedContext())
956 return (anIObj->State()==1);
957 else
958 return myLocalContexts(myCurLocalIndex)->IsSelected(anIObj);
959}
960
961
962//=======================================================================
963//function : InitSelected
964//purpose :
965//=======================================================================
966
967void AIS_InteractiveContext::InitSelected()
968{
969 if(!HasOpenedContext())
970 AIS_Selection::Selection(myCurrentName.ToCString())->Init();
971 else
972 myLocalContexts(myCurLocalIndex)->InitSelected();
973}
974
975//=======================================================================
976//function : MoreSelected
977//purpose :
978//=======================================================================
979
980Standard_Boolean AIS_InteractiveContext::MoreSelected() const
981{
982 if(!HasOpenedContext())
983 return AIS_Selection::Selection(myCurrentName.ToCString())->More();
984 return myLocalContexts(myCurLocalIndex)->MoreSelected();
985}
986
987//=======================================================================
988//function : NextSelected
989//purpose :
990//=======================================================================
991
992void AIS_InteractiveContext::NextSelected()
993{
994 if(!HasOpenedContext())
995 AIS_Selection::Selection(myCurrentName.ToCString())->Next();
996 else
997 myLocalContexts(myCurLocalIndex)->NextSelected();
998}
999
1000//=======================================================================
1001//function : HasSelectedShape
1002//purpose :
1003//=======================================================================
1004
1005Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
1006{
1007 if(!HasOpenedContext()) {
7fd59977 1008 Handle(AIS_Shape) shape =
1009 Handle(AIS_Shape)::DownCast(SelectedInteractive());
1010 if( !shape.IsNull() ) return Standard_True;
7fd59977 1011 return Standard_False;
1012 }
51023771 1013 return myLocalContexts(myCurLocalIndex)->HasSelectedShape();
7fd59977 1014}
1015
1016//=======================================================================
1017//function : SelectedShape
1018//purpose :
1019//=======================================================================
1020
1021TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
1022{
0717ddc1 1023 if (!HasOpenedContext())
1024 {
d8110103 1025 TopoDS_Shape aResShape;
1026 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (SelectedInteractive());
1027 if (!aShape.IsNull())
1028 {
51023771 1029 TopLoc_Location aLocTrsf = SelectedInteractive()->Transformation().Form() == gp_Identity ?
1030 TopLoc_Location() : TopLoc_Location (SelectedInteractive()->Transformation());
1031 aResShape = aShape->Shape().Located (aLocTrsf * aShape->Shape().Location());
d8110103 1032 }
1033
1034 return aResShape;
0717ddc1 1035 }
1036 else
1037 {
1038 return myLocalContexts (myCurLocalIndex)->SelectedShape();
1039 }
7fd59977 1040}
1041
1042//=======================================================================
1043//function : Interactive
1044//purpose :
1045//=======================================================================
1046
1047Handle(AIS_InteractiveObject) AIS_InteractiveContext::Interactive() const
1048{
1049 return SelectedInteractive();
1050}
1051
1052Handle(AIS_InteractiveObject) AIS_InteractiveContext::SelectedInteractive() const
1053{
1054 if(!HasOpenedContext()){
51023771 1055 if (AIS_Selection::Selection(myCurrentName.ToCString())->Extent() == 0)
1056 return NULL;
7fd59977 1057 Handle(Standard_Transient) TR =AIS_Selection::Selection(myCurrentName.ToCString())->Value();
c5f3a425 1058 Handle(AIS_InteractiveObject) IO = Handle(AIS_InteractiveObject)::DownCast (TR);
7fd59977 1059 return IO;}
1060
1061 return myLocalContexts(myCurLocalIndex)->SelectedInteractive();
1062
1063}
1064//=======================================================================
1065//function : Interactive
1066//purpose :
1067//=======================================================================
1068
1069Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const
1070{
1071 if(!HasOpenedContext()){
1072 Handle(SelectMgr_EntityOwner) Ownr;
1073 return Ownr;
1074 }
1075 return myLocalContexts(myCurLocalIndex)->SelectedOwner();
1076
1077}
1078
1079//=======================================================================
1080//function : EntityOwners
1081//purpose :
1082//=======================================================================
b586500b 1083void AIS_InteractiveContext::EntityOwners(Handle(SelectMgr_IndexedMapOfOwner)& theOwners,
7fd59977 1084 const Handle(AIS_InteractiveObject)& theIObj,
1085 const Standard_Integer theMode) const
1086{
1087 if ( theIObj.IsNull() )
1088 return;
1089
1090 TColStd_ListOfInteger aModes;
1091 if ( theMode == -1 )
1092 ActivatedModes( theIObj, aModes );
1093 else
1094 aModes.Append( theMode );
1095
b586500b 1096 if (theOwners.IsNull())
1097 theOwners = new SelectMgr_IndexedMapOfOwner();
1098
7fd59977 1099 TColStd_ListIteratorOfListOfInteger anItr( aModes );
1100 for (; anItr.More(); anItr.Next() )
1101 {
1102 int aMode = anItr.Value();
1103 if ( !theIObj->HasSelection( aMode ) )
1104 continue;
1105
f751596e 1106 Handle(SelectMgr_Selection) aSel = theIObj->Selection(aMode);
7fd59977 1107
1108 for ( aSel->Init(); aSel->More(); aSel->Next() )
1109 {
f751596e 1110 Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive()->BaseSensitive();
7fd59977 1111 if ( aEntity.IsNull() )
1112 continue;
1113
1114 Handle(SelectMgr_EntityOwner) aOwner =
1115 Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId());
1116 if ( !aOwner.IsNull() )
b586500b 1117 theOwners->Add( aOwner );
7fd59977 1118 }
1119 }
1120}
1121
1122Standard_Integer AIS_InteractiveContext::NbSelected()
1123{
1124 Standard_Integer i(0);
1125 for(InitSelected();MoreSelected();NextSelected())
1126 {i++;}
1127 return i;
1128}
1129
1130//=======================================================================
1131//function : HasApplicative
1132//purpose :
1133//=======================================================================
1134
1135 Standard_Boolean AIS_InteractiveContext::HasApplicative() const
1136{
1137 return Interactive()->HasOwner();
1138}
1139
1140//=======================================================================
1141//function : Applicative
1142//purpose :
1143//=======================================================================
1144
1145Handle(Standard_Transient) AIS_InteractiveContext::Applicative() const
1146{
1147 return Interactive()->GetOwner();
1148}
1149
1150
1151
1152//==================================================
1153// Function:
1154// Purpose :
1155//==================================================
1156Standard_Boolean AIS_InteractiveContext::HasDetected() const
1157{
1158 if(HasOpenedContext())
1159 return myLocalContexts(myCurLocalIndex)->HasDetected();
1160 else
1161 return !myLastPicked.IsNull();
1162}
1163
1164//=======================================================================
1165//function : HasDetectedShape
1166//purpose :
1167//=======================================================================
1168
1169Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
1170{
1171 if(HasOpenedContext())
1172 return myLocalContexts(myCurLocalIndex)->HasDetectedShape();
1173 return Standard_False;
1174}
1175
1176//=======================================================================
1177//function : DetectedShape
1178//purpose :
1179//=======================================================================
1180
1181const TopoDS_Shape&
1182AIS_InteractiveContext::DetectedShape() const
1183{
1184 return myLocalContexts(myCurLocalIndex)->DetectedShape();
1185}
1186
1187//=======================================================================
1188//function : DetectedInteractive
1189//purpose :
1190//=======================================================================
1191
1192Handle(AIS_InteractiveObject)
1193AIS_InteractiveContext::DetectedInteractive() const
1194{
1195 if(HasOpenedContext())
1196 return myLocalContexts(myCurLocalIndex)->DetectedInteractive();
1197 return myLastPicked;
1198}
1199
1200
1201Standard_Boolean AIS_InteractiveContext::HasNextDetected() const
1202{
1203 if(!HasOpenedContext())
1204 return Standard_False; // temporaire
1205 else
1206 return myLocalContexts(myCurLocalIndex)->HasNextDetected();
1207
1208}
1209
1210
1211//=======================================================================
1212//function : DetectedOwner
1213//purpose :
1214//=======================================================================
1215Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedOwner() const
1216{
1217 if(HasOpenedContext())
1218 return myLocalContexts(myCurLocalIndex)->DetectedOwner();
1219 Handle(SelectMgr_EntityOwner) Ownr;
1220 return Ownr;
1221}
1222
1223
1224//=======================================================================
1225//function : HilightNextDetected
679ecdee 1226//purpose :
7fd59977 1227//=======================================================================
679ecdee 1228Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView,
1229 const Standard_Boolean theToRedrawImmediate)
7fd59977 1230{
679ecdee 1231 return HasOpenedContext()
1232 ? myLocalContexts (myCurLocalIndex)->HilightNextDetected (theView, theToRedrawImmediate)
1233 : 0;
7fd59977 1234
1235}
1236
1237//=======================================================================
1238//function : HilightNextDetected
679ecdee 1239//purpose :
7fd59977 1240//=======================================================================
679ecdee 1241Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1242 const Standard_Boolean theToRedrawImmediate)
7fd59977 1243{
679ecdee 1244 return HasOpenedContext()
1245 ? myLocalContexts (myCurLocalIndex)->HilightPreviousDetected (theView, theToRedrawImmediate)
1246 : 0;
7fd59977 1247
1248}
1249
7fd59977 1250//=======================================================================
1251//function : InitDetected
1252//purpose :
1253//=======================================================================
1254void AIS_InteractiveContext::InitDetected()
1255{
57ad5cbd 1256 if (HasOpenedContext())
7fd59977 1257 {
1258 myLocalContexts(myCurLocalIndex)->InitDetected();
1259 return;
1260 }
1261
1262 if(myAISDetectedSeq.Length() != 0)
57ad5cbd 1263 {
7fd59977 1264 myAISCurDetected = 1;
57ad5cbd 1265 }
7fd59977 1266}
1267
1268//=======================================================================
1269//function : MoreDetected
1270//purpose :
1271//=======================================================================
1272Standard_Boolean AIS_InteractiveContext::MoreDetected() const
1273{
57ad5cbd 1274 if (HasOpenedContext())
1275 {
7fd59977 1276 return myLocalContexts(myCurLocalIndex)->MoreDetected();
57ad5cbd 1277 }
7fd59977 1278
57ad5cbd 1279 return (myAISCurDetected > 0 && myAISCurDetected <= myAISDetectedSeq.Length()) ?
7fd59977 1280 Standard_True : Standard_False;
1281}
1282
1283//=======================================================================
1284//function : NextDetected
1285//purpose :
1286//=======================================================================
1287void AIS_InteractiveContext::NextDetected()
1288{
1289 if(HasOpenedContext())
1290 {
1291 myLocalContexts(myCurLocalIndex)->NextDetected();
1292 return;
1293 }
1294
1295 myAISCurDetected++;
1296}
1297
1298//=======================================================================
1299//function : DetectedCurrentShape
1300//purpose :
1301//=======================================================================
7fd59977 1302const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
1303{
57ad5cbd 1304 if (HasOpenedContext())
1305 {
7fd59977 1306 return myLocalContexts(myCurLocalIndex)->DetectedCurrentShape();
57ad5cbd 1307 }
7fd59977 1308
57ad5cbd 1309 static TopoDS_Shape aDummyShape;
1310
1311 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
1312
1313 if (aCurrentShape.IsNull())
1314 {
1315 return aDummyShape;
1316 }
1317
1318 return aCurrentShape->Shape();
7fd59977 1319}
1320
1321//=======================================================================
1322//function : DetectedCurrentObject
1323//purpose :
1324//=======================================================================
57ad5cbd 1325Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const
1326{
1327 if (HasOpenedContext())
1328 {
7fd59977 1329 return myLocalContexts(myCurLocalIndex)->DetectedCurrentObject();
57ad5cbd 1330 }
7fd59977 1331
57ad5cbd 1332 return MoreDetected() ? myAISDetectedSeq(myAISCurDetected) : NULL;
7fd59977 1333}