1 // Created on: 1997-01-29
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #define UKI60826 //GG_161199 Use the requested selection color instead of default
19 #define IMP280200 //GG Don't returns a NULL shape in SelectedShape()
20 // method when the current selected is a shape !
22 #define BUC60814 //GG_300101 Idem UKI60826
24 #define OCC138 //VTN Avoding infinit loop in AddOrRemoveCurrentObject method.
28 #include <AIS_InteractiveContext.jxx>
29 #include <SelectMgr_EntityOwner.hxx>
30 #include <AIS_Selection.hxx>
31 #include <AIS_StatusOfDetection.hxx>
32 #include <AIS_StatusOfPick.hxx>
34 #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
35 #include <AIS_LocalContext.hxx>
36 #include <AIS_GlobalStatus.hxx>
37 #include <AIS_Shape.hxx>
39 #include <Aspect_Grid.hxx>
41 #include <V3d_Light.hxx>
42 #include <V3d_PositionalLight.hxx>
43 #include <V3d_SpotLight.hxx>
44 #include <V3d_DirectionalLight.hxx>
45 #include <V3d_AmbientLight.hxx>
47 #include <TColStd_ListIteratorOfListOfInteger.hxx>
48 #include <SelectMgr_Selection.hxx>
49 #include <SelectBasics_SensitiveEntity.hxx>
51 #include <Prs3d_Presentation.hxx>
54 #include <AIS_MapOfInteractive.hxx>
55 #include <AIS_MapIteratorOfMapOfInteractive.hxx>
60 static void InfoOnLight(const Handle(V3d_View) aView)
62 Standard_Real V1=0.,V2=0.,V3=0.;
63 Standard_Integer IndexOfLit(0);
65 static Standard_Boolean FirstTime (Standard_True);
68 FirstTime = Standard_False;
69 for (aView->InitActiveLights();aView->MoreActiveLights();aView->NextActiveLights()){
71 cout<<"lumiere no "<<IndexOfLit<<"\n************\n\t";
72 Handle(V3d_Light) Li = aView->ActiveLight();
73 Quantity_NameOfColor Col;
75 cout<<"Color :"<<Standard_Integer(Col)<<"\n\t"<<endl;
82 // Handle(V3d_AmbientLight)::DownCast(Li)->DisplayPosition(V1,V2,V3);
83 cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl;
88 cout<<" DIRECTIONAL\n\t";
89 Handle(V3d_DirectionalLight)::DownCast(Li)->DisplayPosition(V1,V2,V3);
90 cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl;
91 Handle(V3d_DirectionalLight)::DownCast(Li)->Direction(V1,V2,V3);
92 cout<<"Direction : V1 = "<<V1<<" V2 = "<<V2<<" V3 = "<<V3<<endl;
98 cout<<" POSITIONAL\n\t";
99 Handle(V3d_PositionalLight)::DownCast(Li)->Position(V1,V2,V3);
100 cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl;
101 Handle(V3d_PositionalLight)::DownCast(Li)->Target(V1,V2,V3);
102 cout<<"Target : x1 = "<<V1<<" x2 = "<<V2<<" x3 = "<<V3<<endl;
108 cout<<" DIRECTIONAL\n\t";
109 Handle(V3d_SpotLight)::DownCast(Li)->Position(V1,V2,V3);
110 cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl;
111 Handle(V3d_SpotLight)::DownCast(Li)->Direction(V1,V2,V3);
112 cout<<"Direction : V1 = "<<V1<<" V2 = "<<V2<<" V3 = "<<V3<<endl;
113 Handle(V3d_PositionalLight)::DownCast(Li)->Target(V1,V2,V3);
114 cout<<"Target : x1 = "<<V1<<" x2 = "<<V2<<" x3 = "<<V3<<endl;
115 cout<<"\tAngle :"<<Handle(V3d_SpotLight)::DownCast(Li)->Angle()<<endl;
125 //=======================================================================
128 //=======================================================================
129 AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const Standard_Integer theXPix,
130 const Standard_Integer theYPix,
131 const Handle(V3d_View)& theView,
132 const Standard_Boolean theToRedrawOnUpdate)
134 if (HasOpenedContext())
136 myWasLastMain = Standard_True;
137 return myLocalContexts (myCurLocalIndex)->MoveTo (theXPix, theYPix, theView, theToRedrawOnUpdate);
140 myAISCurDetected = 0;
141 myAISDetectedSeq.Clear();
143 if (theView->Viewer() != myMainVwr)
145 return AIS_SOD_Error;
149 myLastPicked = myLastinMain;
150 myWasLastMain = Standard_True;
151 AIS_StatusOfDetection aStatus = AIS_SOD_Nothing;
152 Standard_Boolean toUpdateViewer = Standard_False;
155 myMainSel->Pick (theXPix, theYPix, theView);
157 // filling of myAISDetectedSeq sequence storing information about detected AIS objects
158 // (the objects must be AIS_Shapes)
159 const Standard_Integer aDetectedNb = myMainSel->NbPicked();
160 for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
162 Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aDetIter);
164 || !myFilters->IsOk (anOwner))
169 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
172 myAISDetectedSeq.Append (anObj);
177 if (myMainSel->More())
179 // does nothing if previously detected object is equal to the current one
180 if (myMainSel->OnePicked()->Selectable() == myLastPicked)
182 return myLastPicked->State() == 1
184 : AIS_SOD_OnlyOneDetected;
187 // Previously detected object is unhilighted if it is not selected or hilighted
188 // with selection color if it is selected. Such highlighting with selection color
189 // is needed only if myToHilightSelected flag is true. In this case previously detected
190 // object has been already highlighted with myHilightColor during previous MoveTo()
191 // method call. As result it is necessary to rehighligt it with mySelectionColor.
192 if (!myLastPicked.IsNull())
194 const Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
195 if (myLastPicked->State() != 1)
197 myMainPM->Unhighlight (myLastPicked, aHiMod);
198 toUpdateViewer = Standard_True;
200 else if (myToHilightSelected)
202 myMainPM->Color (myLastPicked, mySelectionColor, aHiMod);
203 toUpdateViewer = Standard_True;
207 // initialize myLastPicked field with currently detected object
208 myLastPicked = Handle(AIS_InteractiveObject)::DownCast (myMainSel->OnePicked()->Selectable());
209 myLastinMain = myLastPicked;
211 // highlight detected object if it is not selected or myToHilightSelected flag is true
212 if (!myLastPicked.IsNull())
214 if (myLastPicked->State() != 1 || myToHilightSelected)
216 const Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
217 myMainPM->Color (myLastPicked, myHilightColor, aHiMod);
218 toUpdateViewer = Standard_True;
221 aStatus = myLastPicked->State() == 1
223 : AIS_SOD_OnlyOneDetected;
228 // previously detected object is unhilighted if it is not selected or hilighted
229 // with selection color if it is selected
230 aStatus = AIS_SOD_Nothing;
231 if (!myLastPicked.IsNull())
233 Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
234 if (myLastPicked->State() != 1)
236 myMainPM->Unhighlight (myLastPicked, aHiMod);
237 toUpdateViewer = Standard_True;
239 else if (myToHilightSelected)
241 myMainPM->Color (myLastPicked, mySelectionColor, aHiMod);
242 toUpdateViewer = Standard_True;
246 myLastinMain.Nullify();
247 myLastPicked.Nullify();
252 if (theToRedrawOnUpdate)
254 theView->Viewer()->Update();
258 theView->Viewer()->Invalidate();
262 mylastmoveview = theView;
266 //=======================================================================
269 //=======================================================================
270 AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Integer theXPMin,
271 const Standard_Integer theYPMin,
272 const Standard_Integer theXPMax,
273 const Standard_Integer theYPMax,
274 const Handle(V3d_View)& theView,
275 const Standard_Boolean toUpdateViewer)
277 // all objects detected by the selector are taken, previous current objects are emptied,
278 // new objects are put...
280 if (HasOpenedContext())
282 return myLocalContexts(myCurLocalIndex)->Select (theXPMin, theYPMin,
284 theView, toUpdateViewer);
287 ClearCurrents (Standard_False);
289 Handle(StdSelect_ViewerSelector3d) aSelector;
291 if (theView->Viewer() == myMainVwr)
293 aSelector = myMainSel;
294 myWasLastMain = Standard_True;
297 aSelector->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
298 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
300 AIS_MapOfInteractive anObjectsToSelect;
301 for (aSelector->Init(); aSelector->More(); aSelector->Next())
303 Handle(AIS_InteractiveObject) anObj =
304 Handle(AIS_InteractiveObject)::DownCast (aSelector->Picked()->Selectable());
307 anObjectsToSelect.Add (anObj);
311 AIS_MapIteratorOfMapOfInteractive anIt (anObjectsToSelect);
312 for ( ; anIt.More(); anIt.Next())
314 AIS_Selection::Select (anIt.Key());
315 anIt.Key()->State (1);
318 HilightCurrents (toUpdateViewer);
320 Standard_Integer aSelNum = NbCurrents();
322 return (aSelNum == 0) ? AIS_SOP_NothingSelected
323 : (aSelNum == 1) ? AIS_SOP_OneSelected
324 : AIS_SOP_SeveralSelected;
328 //=======================================================================
330 //purpose : Selection by polyline
331 //=======================================================================
332 AIS_StatusOfPick AIS_InteractiveContext::Select (const TColgp_Array1OfPnt2d& thePolyline,
333 const Handle(V3d_View)& theView,
334 const Standard_Boolean toUpdateViewer)
336 // all objects detected by the selector are taken, previous current objects are emptied,
337 // new objects are put...
339 if (HasOpenedContext())
341 return myLocalContexts(myCurLocalIndex)->Select (thePolyline, theView, toUpdateViewer);
344 ClearCurrents (Standard_False);
346 Handle(StdSelect_ViewerSelector3d) aSelector;
348 if (theView->Viewer() == myMainVwr)
350 aSelector = myMainSel;
351 myWasLastMain = Standard_True;
354 aSelector->Pick (thePolyline, theView);
355 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
357 AIS_MapOfInteractive anObjectsToSelect;
358 for (aSelector->Init(); aSelector->More(); aSelector->Next())
360 Handle(AIS_InteractiveObject) anObj =
361 Handle( AIS_InteractiveObject )::DownCast (aSelector->Picked()->Selectable());
364 anObjectsToSelect.Add (anObj);
368 AIS_MapIteratorOfMapOfInteractive anIt (anObjectsToSelect);
369 for ( ; anIt.More(); anIt.Next())
371 AIS_Selection::Select (anIt.Key());
372 anIt.Key()->State (1);
375 HilightCurrents (toUpdateViewer);
377 Standard_Integer aSelNum = NbCurrents();
379 return (aSelNum == 0) ? AIS_SOP_NothingSelected
380 : (aSelNum == 1) ? AIS_SOP_OneSelected
381 : AIS_SOP_SeveralSelected;
385 //=======================================================================
388 //=======================================================================
389 AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean toUpdateViewer)
391 if (HasOpenedContext())
395 return myLocalContexts(myCurLocalIndex)->Select (toUpdateViewer);
399 myLocalContexts(myCurLocalIndex)->SetSelected (myLastPicked, toUpdateViewer);
400 return AIS_SOP_OneSelected;
404 if (myWasLastMain && !myLastinMain.IsNull())
406 if(myLastinMain->State() != 1)
408 SetCurrentObject (myLastinMain,Standard_False);
411 UpdateCurrentViewer();
417 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
418 Handle(AIS_Selection) aSelection = AIS_Selection::CurrentSelection();
419 Handle(AIS_InteractiveObject) anObj;
420 for (aSelection->Init(); aSelection->More(); aSelection->Next())
422 anObj = Handle(AIS_InteractiveObject)::DownCast (aSelection->Value());
424 Unhilight (anObj,Standard_False);
425 if (myObjects.IsBound (anObj) && myObjects(anObj)->IsSubIntensityOn())
427 HilightWithColor (anObj, mySubIntensity, Standard_False);
431 AIS_Selection::Select();
432 if (toUpdateViewer && myWasLastMain)
434 UpdateCurrentViewer();
438 Standard_Integer aSelNum = NbCurrents();
440 return (aSelNum == 0) ? AIS_SOP_NothingSelected
441 : (aSelNum == 1) ? AIS_SOP_OneSelected
442 : AIS_SOP_SeveralSelected;
445 //=======================================================================
446 //function : ShiftSelect
448 //=======================================================================
449 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Boolean toUpdateViewer)
451 if (HasOpenedContext())
455 return myLocalContexts (myCurLocalIndex)->ShiftSelect (toUpdateViewer);
459 myLocalContexts (myCurLocalIndex)->AddOrRemoveSelected (myLastPicked, toUpdateViewer);
461 Standard_Integer aSelNum = NbSelected();
462 return (aSelNum == 0) ? AIS_SOP_NothingSelected
463 : (aSelNum == 1) ? AIS_SOP_OneSelected
464 : AIS_SOP_SeveralSelected;
468 if (myWasLastMain && !myLastinMain.IsNull())
470 AddOrRemoveCurrentObject (myLastinMain, toUpdateViewer);
473 Standard_Integer aCurrentSelNum = NbCurrents();
475 return (aCurrentSelNum == 0) ? AIS_SOP_NothingSelected
476 : (aCurrentSelNum == 1) ? AIS_SOP_OneSelected
477 : AIS_SOP_SeveralSelected;
480 //=======================================================================
481 //function : ShiftSelect
483 //=======================================================================
484 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Integer theXPMin,
485 const Standard_Integer theYPMin,
486 const Standard_Integer theXPMax,
487 const Standard_Integer theYPMax,
488 const Handle(V3d_View)& theView,
489 const Standard_Boolean toUpdateViewer)
491 if (HasOpenedContext())
493 return myLocalContexts(myCurLocalIndex)->ShiftSelect (theXPMin, theYPMin, theXPMax, theYPMax,
494 theView, toUpdateViewer);
497 UnhilightCurrents (Standard_False);
499 Handle(StdSelect_ViewerSelector3d) aSelector;
500 if (theView->Viewer() == myMainVwr)
502 aSelector = myMainSel;
503 myWasLastMain = Standard_True;
507 return AIS_SOP_NothingSelected;
510 aSelector->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
511 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
512 for (aSelector->Init(); aSelector->More(); aSelector->Next())
514 Handle(AIS_InteractiveObject) anObjToSelect = Handle(AIS_InteractiveObject)::DownCast (aSelector->Picked()->Selectable());
515 if (!anObjToSelect.IsNull())
517 AIS_SelectStatus aSelStatus = AIS_Selection::Select (anObjToSelect);
518 Standard_Integer aState = (aSelStatus == AIS_SS_Added) ? 1 : 0;
519 anObjToSelect->State (aState);
523 HilightCurrents (toUpdateViewer);
525 Standard_Integer aSelNum = NbCurrents();
527 return (aSelNum == 0) ? AIS_SOP_NothingSelected
528 : (aSelNum == 1) ? AIS_SOP_OneSelected
529 : AIS_SOP_SeveralSelected;
533 //=======================================================================
534 //function : ShiftSelect
536 //=======================================================================
537 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline,
538 const Handle(V3d_View)& theView,
539 const Standard_Boolean toUpdateViewer)
541 if (HasOpenedContext())
543 return myLocalContexts(myCurLocalIndex)->ShiftSelect (thePolyline, theView, toUpdateViewer);
546 UnhilightCurrents (Standard_False);
548 Handle(StdSelect_ViewerSelector3d) aSelector;
550 if (theView->Viewer() == myMainVwr)
552 aSelector= myMainSel;
553 myWasLastMain = Standard_True;
557 return AIS_SOP_NothingSelected;
560 aSelector->Pick (thePolyline, theView);
562 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
563 for (aSelector->Init(); aSelector->More(); aSelector->Next())
565 Handle(AIS_InteractiveObject) anObjToSelect = Handle(AIS_InteractiveObject)::DownCast (aSelector->Picked()->Selectable());
566 if (!anObjToSelect.IsNull())
568 AIS_SelectStatus aSelStatus = AIS_Selection::Select (anObjToSelect);
569 Standard_Integer aState = (aSelStatus == AIS_SS_Added ) ? 1 : 0;
570 anObjToSelect->State (aState);
574 HilightCurrents (toUpdateViewer);
576 Standard_Integer aSelNum = NbCurrents();
578 return (aSelNum == 0) ? AIS_SOP_NothingSelected
579 : (aSelNum == 1) ? AIS_SOP_OneSelected
580 : AIS_SOP_SeveralSelected;
583 //=======================================================================
584 //function : SetCurrentObject
586 //=======================================================================
587 void AIS_InteractiveContext::SetCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
588 const Standard_Boolean updateviewer)
590 // single case processing...
591 if(NbCurrents()==1 && anIObj->State()==1){
592 Quantity_NameOfColor HiCol;
593 Standard_Boolean HasHiCol;
594 if(IsHilighted(anIObj,HasHiCol,HiCol)){
595 if(HasHiCol && HiCol!= mySelectionColor) {
597 HilightWithColor(anIObj,mySelectionColor,updateviewer);
599 Hilight(anIObj,updateviewer);
608 if(!HasOpenedContext()) {
609 if(anIObj.IsNull()) return;
610 if(!myObjects.IsBound(anIObj))
611 Display(anIObj,Standard_False);
613 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
614 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
615 Handle(Standard_Transient) TR;
616 Handle(AIS_InteractiveObject) IO;
618 while (sel->More()) {
620 IO = *((Handle(AIS_InteractiveObject)*)&TR);
621 Unhilight(IO,Standard_False);
626 // added to avoid untimely viewer update...
627 AIS_Selection::ClearAndSelect(anIObj);
629 Quantity_NameOfColor HiCol;
630 Standard_Boolean HasHiCol;
631 if(IsHilighted(anIObj,HasHiCol,HiCol)){
632 if(HasHiCol && HiCol!= mySelectionColor) {
634 HilightWithColor(anIObj,mySelectionColor,Standard_False);
636 Hilight(anIObj,Standard_False);
642 HilightWithColor(anIObj,mySelectionColor,Standard_False);
644 Hilight(anIObj,Standard_False);
648 UpdateCurrentViewer();
652 cout<<"Nothing Done : Opened Local Context"<<endl;
657 //=======================================================================
658 //function : AddOrRemoveCurrentObject
660 //=======================================================================
662 void AIS_InteractiveContext::
663 AddOrRemoveCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
664 const Standard_Boolean updateviewer)
666 if(anIObj.IsNull()) return;
667 //OCC5682 to remove an object from neutral point even if Local Context is opened (Remove method)
668 if(!HasOpenedContext() /*OCC5682*/|| myObjects.IsBound(anIObj)) {
670 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
671 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
673 AIS_SelectStatus SelStat = AIS_Selection::Select(anIObj);
675 Standard_Integer mod = (SelStat==AIS_SS_Added) ? 1 : 0;
679 HilightWithColor(anIObj,mySelectionColor,Standard_False);
681 Hilight(anIObj,Standard_False);
684 Unhilight(anIObj,Standard_False);
688 UpdateCurrentViewer();
692 cout<<"Nothing Done : Opened Local Context"<<endl;
696 //=======================================================================
697 //function : UpdateCurrent
699 //=======================================================================
701 void AIS_InteractiveContext::UpdateCurrent()
706 //=======================================================================
707 //function : IsCurrent
709 //=======================================================================
711 Standard_Boolean AIS_InteractiveContext::IsCurrent(const Handle(AIS_InteractiveObject)& anIObj) const
714 if (anIObj.IsNull()) return Standard_False;
715 return (anIObj->State()==1);
717 // Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
719 // while (sel->More()) {
720 // if (anIObj == sel->Value()) return Standard_True;
723 // return Standard_False;
727 //=======================================================================
728 //function : InitCurrent
730 //=======================================================================
732 void AIS_InteractiveContext::InitCurrent()
734 AIS_Selection::Selection(myCurrentName.ToCString())->Init();
737 //=======================================================================
738 //function : MoreCurrent
740 //=======================================================================
742 Standard_Boolean AIS_InteractiveContext::MoreCurrent() const
744 return AIS_Selection::Selection(myCurrentName.ToCString())->More();
748 //=======================================================================
749 //function : NextCurrent
751 //=======================================================================
753 void AIS_InteractiveContext::NextCurrent()
755 AIS_Selection::Selection(myCurrentName.ToCString())->Next();
758 //=======================================================================
761 //=======================================================================
763 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Current() const
765 Handle(Standard_Transient) TR = AIS_Selection::Selection(myCurrentName.ToCString())->Value();
766 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
770 //=======================================================================
771 //function : FirstCurrentObject
773 //=======================================================================
774 Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstCurrentObject()
776 Handle(AIS_InteractiveObject) IO ;
784 //=======================================================================
785 //function : NbCurrents
787 //=======================================================================
788 Standard_Integer AIS_InteractiveContext::NbCurrents()
790 Standard_Integer i(0);
791 for(InitCurrent();MoreCurrent();NextCurrent())
796 //=======================================================================
797 //function : HilightCurrents
799 //=======================================================================
800 void AIS_InteractiveContext::HilightCurrents(const Standard_Boolean updateviewer)
802 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
803 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
804 Handle(Standard_Transient) TR;
805 Handle(AIS_InteractiveObject) IO;
807 while (sel->More()) {
809 IO = *((Handle(AIS_InteractiveObject)*)&TR);
811 HilightWithColor(IO,mySelectionColor,Standard_False);
813 Hilight(IO,Standard_False);
818 UpdateCurrentViewer();
821 //=======================================================================
822 //function : UnhilightCurrents
824 //=======================================================================
826 void AIS_InteractiveContext::UnhilightCurrents(const Standard_Boolean updateviewer)
828 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
829 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
830 Handle(Standard_Transient) TR;
831 Handle(AIS_InteractiveObject) IO;
833 while (sel->More()) {
835 IO = *((Handle(AIS_InteractiveObject)*)&TR);
836 Unhilight(IO,Standard_False);
840 UpdateCurrentViewer();
843 //=======================================================================
844 //function : ClearCurrents
846 //=======================================================================
848 void AIS_InteractiveContext::ClearCurrents(const Standard_Boolean updateviewer)
850 if(NbCurrents()==0) return;
851 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
852 Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
853 Handle(Standard_Transient) Tr;
854 Handle(AIS_InteractiveObject) IO;
855 for(S->Init();S->More();S->Next()){
857 IO = (*((Handle(AIS_InteractiveObject)*)&Tr));
859 Unhilight(IO,Standard_False);
861 AIS_Selection::Select();
863 UpdateCurrentViewer();
867 //=======================================================================
868 //function : HilightSelected
870 //=======================================================================
872 void AIS_InteractiveContext::HilightSelected(const Standard_Boolean updateviewer)
874 if(!HasOpenedContext()){
875 AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
876 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
877 Handle(Standard_Transient) TR;
878 Handle(AIS_InteractiveObject) IO;
880 while (sel->More()) {
882 IO = *((Handle(AIS_InteractiveObject)*)&TR);
884 HilightWithColor(IO,mySelectionColor,Standard_False);
886 Hilight(IO,Standard_False);
893 myLocalContexts(myCurLocalIndex)->HilightPicked(updateviewer);
896 UpdateCurrentViewer();
899 //=======================================================================
900 //function : UnhilightSelected
902 //=======================================================================
904 void AIS_InteractiveContext::UnhilightSelected(const Standard_Boolean updateviewer)
906 if(!HasOpenedContext()){
907 AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
908 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
909 Handle(Standard_Transient) TR;
910 Handle(AIS_InteractiveObject) IO;
912 while (sel->More()) {
914 IO = *((Handle(AIS_InteractiveObject)*)&TR);
915 Unhilight(IO,Standard_False);
919 UpdateCurrentViewer();
923 myLocalContexts(myCurLocalIndex)->UnhilightPicked(updateviewer);
928 //=======================================================================
929 //function : ClearSelected
931 //=======================================================================
933 void AIS_InteractiveContext::ClearSelected(const Standard_Boolean updateviewer)
935 if(!HasOpenedContext())
936 ClearCurrents(updateviewer);
938 myLocalContexts(myCurLocalIndex)->ClearSelected(updateviewer);
943 //=======================================================================
944 //function : SetSelectedCurrent
946 //=======================================================================
948 void AIS_InteractiveContext::SetSelectedCurrent()
953 cout<<"Not Yet Implemented"<<endl;
957 //=======================================================================
958 //function : UpdateSelection
960 //=======================================================================
962 void AIS_InteractiveContext::UpdateSelected(const Standard_Boolean updateviewer)
964 if(!HasOpenedContext()) {
970 myLocalContexts(myCurLocalIndex)->UpdateSelected(updateviewer);
973 //=======================================================================
974 //function : SetCurrentObject
976 //=======================================================================
977 void AIS_InteractiveContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,const Standard_Boolean updateviewer)
979 if(!HasOpenedContext())
980 SetCurrentObject(anIObj,updateviewer);
982 myLocalContexts(myCurLocalIndex)->SetSelected(anIObj,updateviewer);
985 //=======================================================================
986 //function : AddOrRemoveSelected
988 //=======================================================================
990 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj,
991 const Standard_Boolean updateviewer)
993 if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
994 if(!HasOpenedContext())
995 AddOrRemoveCurrentObject(anIObj,updateviewer);
997 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(anIObj,updateviewer);
1000 //=======================================================================
1001 //function : AddOrRemoveSelected
1003 //=======================================================================
1005 void AIS_InteractiveContext::AddOrRemoveSelected(const TopoDS_Shape& aShap,
1006 const Standard_Boolean updateviewer)
1008 if(!HasOpenedContext()) {
1010 cout<<" Attempt to remove a selected shape with no opened local context"<<endl;
1015 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(aShap,updateviewer);
1016 if(updateviewer) UpdateCurrentViewer();
1019 //=======================================================================
1020 //function : AddOrRemoveSelected
1022 //=======================================================================
1024 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(SelectMgr_EntityOwner)& Own,
1025 const Standard_Boolean updateviewer)
1027 if(!HasOpenedContext()) {
1029 cout<<" Attempt to remove a selected ownr with no opened local context"<<endl;
1034 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(Own,Standard_False);
1035 if(updateviewer) UpdateCurrentViewer();
1041 //=======================================================================
1042 //function : IsSelected
1044 //=======================================================================
1046 Standard_Boolean AIS_InteractiveContext::
1047 IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const
1049 if (anIObj.IsNull()) return Standard_False;
1051 if(!HasOpenedContext())
1052 return (anIObj->State()==1);
1054 return myLocalContexts(myCurLocalIndex)->IsSelected(anIObj);
1058 //=======================================================================
1059 //function : InitSelected
1061 //=======================================================================
1063 void AIS_InteractiveContext::InitSelected()
1065 if(!HasOpenedContext())
1066 AIS_Selection::Selection(myCurrentName.ToCString())->Init();
1068 myLocalContexts(myCurLocalIndex)->InitSelected();
1071 //=======================================================================
1072 //function : MoreSelected
1074 //=======================================================================
1076 Standard_Boolean AIS_InteractiveContext::MoreSelected() const
1078 if(!HasOpenedContext())
1079 return AIS_Selection::Selection(myCurrentName.ToCString())->More();
1080 return myLocalContexts(myCurLocalIndex)->MoreSelected();
1083 //=======================================================================
1084 //function : NextSelected
1086 //=======================================================================
1088 void AIS_InteractiveContext::NextSelected()
1090 if(!HasOpenedContext())
1091 AIS_Selection::Selection(myCurrentName.ToCString())->Next();
1093 myLocalContexts(myCurLocalIndex)->NextSelected();
1096 //=======================================================================
1097 //function : HasSelectedShape
1099 //=======================================================================
1101 Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
1103 if(!HasOpenedContext()) {
1105 Handle(AIS_Shape) shape =
1106 Handle(AIS_Shape)::DownCast(SelectedInteractive());
1107 if( !shape.IsNull() ) return Standard_True;
1109 return Standard_False;
1111 return myLocalContexts(myCurLocalIndex)->HasShape();
1116 //=======================================================================
1117 //function : SelectedShape
1119 //=======================================================================
1121 TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
1123 if (!HasOpenedContext())
1125 TopoDS_Shape aResShape;
1126 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (SelectedInteractive());
1127 if (!aShape.IsNull())
1129 aResShape = aShape->Shape().Located (TopLoc_Location (SelectedInteractive()->Transformation()) * aShape->Shape().Location());
1136 return myLocalContexts (myCurLocalIndex)->SelectedShape();
1140 //=======================================================================
1141 //function : Interactive
1143 //=======================================================================
1145 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Interactive() const
1147 return SelectedInteractive();
1150 Handle(AIS_InteractiveObject) AIS_InteractiveContext::SelectedInteractive() const
1152 if(!HasOpenedContext()){
1153 Handle(Standard_Transient) TR =AIS_Selection::Selection(myCurrentName.ToCString())->Value();
1154 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
1157 return myLocalContexts(myCurLocalIndex)->SelectedInteractive();
1160 //=======================================================================
1161 //function : Interactive
1163 //=======================================================================
1165 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const
1167 if(!HasOpenedContext()){
1168 Handle(SelectMgr_EntityOwner) Ownr;
1171 return myLocalContexts(myCurLocalIndex)->SelectedOwner();
1175 //=======================================================================
1176 //function : EntityOwners
1178 //=======================================================================
1179 void AIS_InteractiveContext::EntityOwners(SelectMgr_IndexedMapOfOwner& theOwners,
1180 const Handle(AIS_InteractiveObject)& theIObj,
1181 const Standard_Integer theMode) const
1183 if ( theIObj.IsNull() )
1186 TColStd_ListOfInteger aModes;
1187 if ( theMode == -1 )
1188 ActivatedModes( theIObj, aModes );
1190 aModes.Append( theMode );
1192 TColStd_ListIteratorOfListOfInteger anItr( aModes );
1193 for (; anItr.More(); anItr.Next() )
1195 int aMode = anItr.Value();
1196 if ( !theIObj->HasSelection( aMode ) )
1199 Handle(SelectMgr_Selection) aSel = theIObj->Selection( aMode );
1201 for ( aSel->Init(); aSel->More(); aSel->Next() )
1203 Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive();
1204 if ( aEntity.IsNull() )
1207 Handle(SelectMgr_EntityOwner) aOwner =
1208 Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId());
1209 if ( !aOwner.IsNull() )
1210 theOwners.Add( aOwner );
1215 Standard_Integer AIS_InteractiveContext::NbSelected()
1217 Standard_Integer i(0);
1218 for(InitSelected();MoreSelected();NextSelected())
1223 //=======================================================================
1224 //function : HasApplicative
1226 //=======================================================================
1228 Standard_Boolean AIS_InteractiveContext::HasApplicative() const
1230 return Interactive()->HasOwner();
1233 //=======================================================================
1234 //function : Applicative
1236 //=======================================================================
1238 Handle(Standard_Transient) AIS_InteractiveContext::Applicative() const
1240 return Interactive()->GetOwner();
1245 //==================================================
1248 //==================================================
1249 Standard_Boolean AIS_InteractiveContext::HasDetected() const
1251 if(HasOpenedContext())
1252 return myLocalContexts(myCurLocalIndex)->HasDetected();
1254 return !myLastPicked.IsNull();
1257 //=======================================================================
1258 //function : HasDetectedShape
1260 //=======================================================================
1262 Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
1264 if(HasOpenedContext())
1265 return myLocalContexts(myCurLocalIndex)->HasDetectedShape();
1266 return Standard_False;
1269 //=======================================================================
1270 //function : DetectedShape
1272 //=======================================================================
1275 AIS_InteractiveContext::DetectedShape() const
1277 return myLocalContexts(myCurLocalIndex)->DetectedShape();
1280 //=======================================================================
1281 //function : DetectedInteractive
1283 //=======================================================================
1285 Handle(AIS_InteractiveObject)
1286 AIS_InteractiveContext::DetectedInteractive() const
1288 if(HasOpenedContext())
1289 return myLocalContexts(myCurLocalIndex)->DetectedInteractive();
1290 return myLastPicked;
1294 Standard_Boolean AIS_InteractiveContext::HasNextDetected() const
1296 if(!HasOpenedContext())
1297 return Standard_False; // temporaire
1299 return myLocalContexts(myCurLocalIndex)->HasNextDetected();
1304 //=======================================================================
1305 //function : DetectedOwner
1307 //=======================================================================
1308 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedOwner() const
1310 if(HasOpenedContext())
1311 return myLocalContexts(myCurLocalIndex)->DetectedOwner();
1312 Handle(SelectMgr_EntityOwner) Ownr;
1317 //=======================================================================
1318 //function : HilightNextDetected
1320 //=======================================================================
1321 Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView,
1322 const Standard_Boolean theToRedrawImmediate)
1324 return HasOpenedContext()
1325 ? myLocalContexts (myCurLocalIndex)->HilightNextDetected (theView, theToRedrawImmediate)
1330 //=======================================================================
1331 //function : HilightNextDetected
1333 //=======================================================================
1334 Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1335 const Standard_Boolean theToRedrawImmediate)
1337 return HasOpenedContext()
1338 ? myLocalContexts (myCurLocalIndex)->HilightPreviousDetected (theView, theToRedrawImmediate)
1343 //=======================================================================
1344 //function : InitDetected
1346 //=======================================================================
1347 void AIS_InteractiveContext::InitDetected()
1349 if (HasOpenedContext())
1351 myLocalContexts(myCurLocalIndex)->InitDetected();
1355 if(myAISDetectedSeq.Length() != 0)
1357 myAISCurDetected = 1;
1361 //=======================================================================
1362 //function : MoreDetected
1364 //=======================================================================
1365 Standard_Boolean AIS_InteractiveContext::MoreDetected() const
1367 if (HasOpenedContext())
1369 return myLocalContexts(myCurLocalIndex)->MoreDetected();
1372 return (myAISCurDetected > 0 && myAISCurDetected <= myAISDetectedSeq.Length()) ?
1373 Standard_True : Standard_False;
1376 //=======================================================================
1377 //function : NextDetected
1379 //=======================================================================
1380 void AIS_InteractiveContext::NextDetected()
1382 if(HasOpenedContext())
1384 myLocalContexts(myCurLocalIndex)->NextDetected();
1391 //=======================================================================
1392 //function : DetectedCurrentShape
1394 //=======================================================================
1395 const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
1397 if (HasOpenedContext())
1399 return myLocalContexts(myCurLocalIndex)->DetectedCurrentShape();
1402 static TopoDS_Shape aDummyShape;
1404 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
1406 if (aCurrentShape.IsNull())
1411 return aCurrentShape->Shape();
1414 //=======================================================================
1415 //function : DetectedCurrentObject
1417 //=======================================================================
1418 Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const
1420 if (HasOpenedContext())
1422 return myLocalContexts(myCurLocalIndex)->DetectedCurrentObject();
1425 return MoreDetected() ? myAISDetectedSeq(myAISCurDetected) : NULL;