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