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 Standard_Integer aNewDetected = 0;
161 for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
163 Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aDetIter);
165 || !myFilters->IsOk (anOwner))
170 if (aNewDetected < 1)
172 aNewDetected = aDetIter;
174 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
177 myAISDetectedSeq.Append (anObj);
181 if (aNewDetected >= 1)
183 // does nothing if previously detected object is equal to the current one
184 Handle(SelectMgr_EntityOwner) aNewPickedOwner = myMainSel->Picked (aNewDetected);
185 if (aNewPickedOwner->Selectable() == myLastPicked)
187 return myLastPicked->State() == 1
189 : AIS_SOD_OnlyOneDetected;
192 // Previously detected object is unhilighted if it is not selected or hilighted
193 // with selection color if it is selected. Such highlighting with selection color
194 // is needed only if myToHilightSelected flag is true. In this case previously detected
195 // object has been already highlighted with myHilightColor during previous MoveTo()
196 // method call. As result it is necessary to rehighligt it with mySelectionColor.
197 if (!myLastPicked.IsNull())
199 const Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
200 if (myLastPicked->State() != 1)
202 myMainPM->Unhighlight (myLastPicked, aHiMod);
203 toUpdateViewer = Standard_True;
205 else if (myToHilightSelected)
207 myMainPM->Color (myLastPicked, mySelectionColor, aHiMod);
208 toUpdateViewer = Standard_True;
212 // initialize myLastPicked field with currently detected object
213 myLastPicked = Handle(AIS_InteractiveObject)::DownCast (aNewPickedOwner->Selectable());
214 myLastinMain = myLastPicked;
216 // highlight detected object if it is not selected or myToHilightSelected flag is true
217 if (!myLastPicked.IsNull())
219 if (myLastPicked->State() != 1 || myToHilightSelected)
221 const Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
222 myMainPM->Color (myLastPicked, myHilightColor, aHiMod);
223 toUpdateViewer = Standard_True;
226 aStatus = myLastPicked->State() == 1
228 : AIS_SOD_OnlyOneDetected;
233 // previously detected object is unhilighted if it is not selected or hilighted
234 // with selection color if it is selected
235 aStatus = AIS_SOD_Nothing;
236 if (!myLastPicked.IsNull())
238 Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
239 if (myLastPicked->State() != 1)
241 myMainPM->Unhighlight (myLastPicked, aHiMod);
242 toUpdateViewer = Standard_True;
244 else if (myToHilightSelected)
246 myMainPM->Color (myLastPicked, mySelectionColor, aHiMod);
247 toUpdateViewer = Standard_True;
251 myLastinMain.Nullify();
252 myLastPicked.Nullify();
257 if (theToRedrawOnUpdate)
259 theView->Viewer()->Update();
263 theView->Viewer()->Invalidate();
267 mylastmoveview = theView;
271 //=======================================================================
274 //=======================================================================
275 AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Integer theXPMin,
276 const Standard_Integer theYPMin,
277 const Standard_Integer theXPMax,
278 const Standard_Integer theYPMax,
279 const Handle(V3d_View)& theView,
280 const Standard_Boolean toUpdateViewer)
282 // all objects detected by the selector are taken, previous current objects are emptied,
283 // new objects are put...
285 if (HasOpenedContext())
287 return myLocalContexts(myCurLocalIndex)->Select (theXPMin, theYPMin,
289 theView, toUpdateViewer);
292 ClearCurrents (Standard_False);
294 Handle(StdSelect_ViewerSelector3d) aSelector;
296 if (theView->Viewer() == myMainVwr)
298 aSelector = myMainSel;
299 myWasLastMain = Standard_True;
302 aSelector->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
303 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
305 AIS_MapOfInteractive anObjectsToSelect;
306 for (aSelector->Init(); aSelector->More(); aSelector->Next())
308 Handle(AIS_InteractiveObject) anObj =
309 Handle(AIS_InteractiveObject)::DownCast (aSelector->Picked()->Selectable());
312 anObjectsToSelect.Add (anObj);
316 AIS_MapIteratorOfMapOfInteractive anIt (anObjectsToSelect);
317 for ( ; anIt.More(); anIt.Next())
319 AIS_Selection::Select (anIt.Key());
320 anIt.Key()->State (1);
323 HilightCurrents (toUpdateViewer);
325 Standard_Integer aSelNum = NbCurrents();
327 return (aSelNum == 0) ? AIS_SOP_NothingSelected
328 : (aSelNum == 1) ? AIS_SOP_OneSelected
329 : AIS_SOP_SeveralSelected;
333 //=======================================================================
335 //purpose : Selection by polyline
336 //=======================================================================
337 AIS_StatusOfPick AIS_InteractiveContext::Select (const TColgp_Array1OfPnt2d& thePolyline,
338 const Handle(V3d_View)& theView,
339 const Standard_Boolean toUpdateViewer)
341 // all objects detected by the selector are taken, previous current objects are emptied,
342 // new objects are put...
344 if (HasOpenedContext())
346 return myLocalContexts(myCurLocalIndex)->Select (thePolyline, theView, toUpdateViewer);
349 ClearCurrents (Standard_False);
351 Handle(StdSelect_ViewerSelector3d) aSelector;
353 if (theView->Viewer() == myMainVwr)
355 aSelector = myMainSel;
356 myWasLastMain = Standard_True;
359 aSelector->Pick (thePolyline, theView);
360 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
362 AIS_MapOfInteractive anObjectsToSelect;
363 for (aSelector->Init(); aSelector->More(); aSelector->Next())
365 Handle(AIS_InteractiveObject) anObj =
366 Handle( AIS_InteractiveObject )::DownCast (aSelector->Picked()->Selectable());
369 anObjectsToSelect.Add (anObj);
373 AIS_MapIteratorOfMapOfInteractive anIt (anObjectsToSelect);
374 for ( ; anIt.More(); anIt.Next())
376 AIS_Selection::Select (anIt.Key());
377 anIt.Key()->State (1);
380 HilightCurrents (toUpdateViewer);
382 Standard_Integer aSelNum = NbCurrents();
384 return (aSelNum == 0) ? AIS_SOP_NothingSelected
385 : (aSelNum == 1) ? AIS_SOP_OneSelected
386 : AIS_SOP_SeveralSelected;
390 //=======================================================================
393 //=======================================================================
394 AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean toUpdateViewer)
396 if (HasOpenedContext())
400 return myLocalContexts(myCurLocalIndex)->Select (toUpdateViewer);
404 myLocalContexts(myCurLocalIndex)->SetSelected (myLastPicked, toUpdateViewer);
405 return AIS_SOP_OneSelected;
409 if (myWasLastMain && !myLastinMain.IsNull())
411 if(myLastinMain->State() != 1)
413 SetCurrentObject (myLastinMain,Standard_False);
416 UpdateCurrentViewer();
422 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
423 Handle(AIS_Selection) aSelection = AIS_Selection::CurrentSelection();
424 Handle(AIS_InteractiveObject) anObj;
425 for (aSelection->Init(); aSelection->More(); aSelection->Next())
427 anObj = Handle(AIS_InteractiveObject)::DownCast (aSelection->Value());
429 Unhilight (anObj,Standard_False);
430 if (myObjects.IsBound (anObj) && myObjects(anObj)->IsSubIntensityOn())
432 HilightWithColor (anObj, mySubIntensity, Standard_False);
436 AIS_Selection::Select();
437 if (toUpdateViewer && myWasLastMain)
439 UpdateCurrentViewer();
443 Standard_Integer aSelNum = NbCurrents();
445 return (aSelNum == 0) ? AIS_SOP_NothingSelected
446 : (aSelNum == 1) ? AIS_SOP_OneSelected
447 : AIS_SOP_SeveralSelected;
450 //=======================================================================
451 //function : ShiftSelect
453 //=======================================================================
454 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Boolean toUpdateViewer)
456 if (HasOpenedContext())
460 return myLocalContexts (myCurLocalIndex)->ShiftSelect (toUpdateViewer);
464 myLocalContexts (myCurLocalIndex)->AddOrRemoveSelected (myLastPicked, toUpdateViewer);
466 Standard_Integer aSelNum = NbSelected();
467 return (aSelNum == 0) ? AIS_SOP_NothingSelected
468 : (aSelNum == 1) ? AIS_SOP_OneSelected
469 : AIS_SOP_SeveralSelected;
473 if (myWasLastMain && !myLastinMain.IsNull())
475 AddOrRemoveCurrentObject (myLastinMain, toUpdateViewer);
478 Standard_Integer aCurrentSelNum = NbCurrents();
480 return (aCurrentSelNum == 0) ? AIS_SOP_NothingSelected
481 : (aCurrentSelNum == 1) ? AIS_SOP_OneSelected
482 : AIS_SOP_SeveralSelected;
485 //=======================================================================
486 //function : ShiftSelect
488 //=======================================================================
489 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Integer theXPMin,
490 const Standard_Integer theYPMin,
491 const Standard_Integer theXPMax,
492 const Standard_Integer theYPMax,
493 const Handle(V3d_View)& theView,
494 const Standard_Boolean toUpdateViewer)
496 if (HasOpenedContext())
498 return myLocalContexts(myCurLocalIndex)->ShiftSelect (theXPMin, theYPMin, theXPMax, theYPMax,
499 theView, toUpdateViewer);
502 UnhilightCurrents (Standard_False);
504 Handle(StdSelect_ViewerSelector3d) aSelector;
505 if (theView->Viewer() == myMainVwr)
507 aSelector = myMainSel;
508 myWasLastMain = Standard_True;
512 return AIS_SOP_NothingSelected;
515 aSelector->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
516 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
517 for (aSelector->Init(); aSelector->More(); aSelector->Next())
519 Handle(AIS_InteractiveObject) anObjToSelect = Handle(AIS_InteractiveObject)::DownCast (aSelector->Picked()->Selectable());
520 if (!anObjToSelect.IsNull())
522 AIS_SelectStatus aSelStatus = AIS_Selection::Select (anObjToSelect);
523 Standard_Integer aState = (aSelStatus == AIS_SS_Added) ? 1 : 0;
524 anObjToSelect->State (aState);
528 HilightCurrents (toUpdateViewer);
530 Standard_Integer aSelNum = NbCurrents();
532 return (aSelNum == 0) ? AIS_SOP_NothingSelected
533 : (aSelNum == 1) ? AIS_SOP_OneSelected
534 : AIS_SOP_SeveralSelected;
538 //=======================================================================
539 //function : ShiftSelect
541 //=======================================================================
542 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline,
543 const Handle(V3d_View)& theView,
544 const Standard_Boolean toUpdateViewer)
546 if (HasOpenedContext())
548 return myLocalContexts(myCurLocalIndex)->ShiftSelect (thePolyline, theView, toUpdateViewer);
551 UnhilightCurrents (Standard_False);
553 Handle(StdSelect_ViewerSelector3d) aSelector;
555 if (theView->Viewer() == myMainVwr)
557 aSelector= myMainSel;
558 myWasLastMain = Standard_True;
562 return AIS_SOP_NothingSelected;
565 aSelector->Pick (thePolyline, theView);
567 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
568 for (aSelector->Init(); aSelector->More(); aSelector->Next())
570 Handle(AIS_InteractiveObject) anObjToSelect = Handle(AIS_InteractiveObject)::DownCast (aSelector->Picked()->Selectable());
571 if (!anObjToSelect.IsNull())
573 AIS_SelectStatus aSelStatus = AIS_Selection::Select (anObjToSelect);
574 Standard_Integer aState = (aSelStatus == AIS_SS_Added ) ? 1 : 0;
575 anObjToSelect->State (aState);
579 HilightCurrents (toUpdateViewer);
581 Standard_Integer aSelNum = NbCurrents();
583 return (aSelNum == 0) ? AIS_SOP_NothingSelected
584 : (aSelNum == 1) ? AIS_SOP_OneSelected
585 : AIS_SOP_SeveralSelected;
588 //=======================================================================
589 //function : SetCurrentObject
591 //=======================================================================
592 void AIS_InteractiveContext::SetCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
593 const Standard_Boolean updateviewer)
595 // single case processing...
596 if(NbCurrents()==1 && anIObj->State()==1){
597 Quantity_NameOfColor HiCol;
598 Standard_Boolean HasHiCol;
599 if(IsHilighted(anIObj,HasHiCol,HiCol)){
600 if(HasHiCol && HiCol!= mySelectionColor) {
602 HilightWithColor(anIObj,mySelectionColor,updateviewer);
604 Hilight(anIObj,updateviewer);
613 if(!HasOpenedContext()) {
614 if(anIObj.IsNull()) return;
615 if(!myObjects.IsBound(anIObj))
616 Display(anIObj,Standard_False);
618 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
619 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
620 Handle(Standard_Transient) TR;
621 Handle(AIS_InteractiveObject) IO;
623 while (sel->More()) {
625 IO = *((Handle(AIS_InteractiveObject)*)&TR);
626 Unhilight(IO,Standard_False);
631 // added to avoid untimely viewer update...
632 AIS_Selection::ClearAndSelect(anIObj);
634 Quantity_NameOfColor HiCol;
635 Standard_Boolean HasHiCol;
636 if(IsHilighted(anIObj,HasHiCol,HiCol)){
637 if(HasHiCol && HiCol!= mySelectionColor) {
639 HilightWithColor(anIObj,mySelectionColor,Standard_False);
641 Hilight(anIObj,Standard_False);
647 HilightWithColor(anIObj,mySelectionColor,Standard_False);
649 Hilight(anIObj,Standard_False);
653 UpdateCurrentViewer();
657 cout<<"Nothing Done : Opened Local Context"<<endl;
662 //=======================================================================
663 //function : AddOrRemoveCurrentObject
665 //=======================================================================
667 void AIS_InteractiveContext::
668 AddOrRemoveCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
669 const Standard_Boolean updateviewer)
671 if(anIObj.IsNull()) return;
672 //OCC5682 to remove an object from neutral point even if Local Context is opened (Remove method)
673 if(!HasOpenedContext() /*OCC5682*/|| myObjects.IsBound(anIObj)) {
675 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
676 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
678 AIS_SelectStatus SelStat = AIS_Selection::Select(anIObj);
680 Standard_Integer mod = (SelStat==AIS_SS_Added) ? 1 : 0;
684 HilightWithColor(anIObj,mySelectionColor,Standard_False);
686 Hilight(anIObj,Standard_False);
689 Unhilight(anIObj,Standard_False);
693 UpdateCurrentViewer();
697 cout<<"Nothing Done : Opened Local Context"<<endl;
701 //=======================================================================
702 //function : UpdateCurrent
704 //=======================================================================
706 void AIS_InteractiveContext::UpdateCurrent()
711 //=======================================================================
712 //function : IsCurrent
714 //=======================================================================
716 Standard_Boolean AIS_InteractiveContext::IsCurrent(const Handle(AIS_InteractiveObject)& anIObj) const
719 if (anIObj.IsNull()) return Standard_False;
720 return (anIObj->State()==1);
722 // Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
724 // while (sel->More()) {
725 // if (anIObj == sel->Value()) return Standard_True;
728 // return Standard_False;
732 //=======================================================================
733 //function : InitCurrent
735 //=======================================================================
737 void AIS_InteractiveContext::InitCurrent()
739 AIS_Selection::Selection(myCurrentName.ToCString())->Init();
742 //=======================================================================
743 //function : MoreCurrent
745 //=======================================================================
747 Standard_Boolean AIS_InteractiveContext::MoreCurrent() const
749 return AIS_Selection::Selection(myCurrentName.ToCString())->More();
753 //=======================================================================
754 //function : NextCurrent
756 //=======================================================================
758 void AIS_InteractiveContext::NextCurrent()
760 AIS_Selection::Selection(myCurrentName.ToCString())->Next();
763 //=======================================================================
766 //=======================================================================
768 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Current() const
770 Handle(Standard_Transient) TR = AIS_Selection::Selection(myCurrentName.ToCString())->Value();
771 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
775 //=======================================================================
776 //function : FirstCurrentObject
778 //=======================================================================
779 Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstCurrentObject()
781 Handle(AIS_InteractiveObject) IO ;
789 //=======================================================================
790 //function : NbCurrents
792 //=======================================================================
793 Standard_Integer AIS_InteractiveContext::NbCurrents()
795 Standard_Integer i(0);
796 for(InitCurrent();MoreCurrent();NextCurrent())
801 //=======================================================================
802 //function : HilightCurrents
804 //=======================================================================
805 void AIS_InteractiveContext::HilightCurrents(const Standard_Boolean updateviewer)
807 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
808 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
809 Handle(Standard_Transient) TR;
810 Handle(AIS_InteractiveObject) IO;
812 while (sel->More()) {
814 IO = *((Handle(AIS_InteractiveObject)*)&TR);
816 HilightWithColor(IO,mySelectionColor,Standard_False);
818 Hilight(IO,Standard_False);
823 UpdateCurrentViewer();
826 //=======================================================================
827 //function : UnhilightCurrents
829 //=======================================================================
831 void AIS_InteractiveContext::UnhilightCurrents(const Standard_Boolean updateviewer)
833 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
834 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
835 Handle(Standard_Transient) TR;
836 Handle(AIS_InteractiveObject) IO;
838 while (sel->More()) {
840 IO = *((Handle(AIS_InteractiveObject)*)&TR);
841 Unhilight(IO,Standard_False);
845 UpdateCurrentViewer();
848 //=======================================================================
849 //function : ClearCurrents
851 //=======================================================================
853 void AIS_InteractiveContext::ClearCurrents(const Standard_Boolean updateviewer)
855 if(NbCurrents()==0) return;
856 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
857 Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
858 Handle(Standard_Transient) Tr;
859 Handle(AIS_InteractiveObject) IO;
860 for(S->Init();S->More();S->Next()){
862 IO = (*((Handle(AIS_InteractiveObject)*)&Tr));
864 Unhilight(IO,Standard_False);
866 AIS_Selection::Select();
868 UpdateCurrentViewer();
872 //=======================================================================
873 //function : HilightSelected
875 //=======================================================================
877 void AIS_InteractiveContext::HilightSelected(const Standard_Boolean updateviewer)
879 if(!HasOpenedContext()){
880 AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
881 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
882 Handle(Standard_Transient) TR;
883 Handle(AIS_InteractiveObject) IO;
885 while (sel->More()) {
887 IO = *((Handle(AIS_InteractiveObject)*)&TR);
889 HilightWithColor(IO,mySelectionColor,Standard_False);
891 Hilight(IO,Standard_False);
898 myLocalContexts(myCurLocalIndex)->HilightPicked(updateviewer);
901 UpdateCurrentViewer();
904 //=======================================================================
905 //function : UnhilightSelected
907 //=======================================================================
909 void AIS_InteractiveContext::UnhilightSelected(const Standard_Boolean updateviewer)
911 if(!HasOpenedContext()){
912 AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
913 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
914 Handle(Standard_Transient) TR;
915 Handle(AIS_InteractiveObject) IO;
917 while (sel->More()) {
919 IO = *((Handle(AIS_InteractiveObject)*)&TR);
920 Unhilight(IO,Standard_False);
924 UpdateCurrentViewer();
928 myLocalContexts(myCurLocalIndex)->UnhilightPicked(updateviewer);
933 //=======================================================================
934 //function : ClearSelected
936 //=======================================================================
938 void AIS_InteractiveContext::ClearSelected(const Standard_Boolean updateviewer)
940 if(!HasOpenedContext())
941 ClearCurrents(updateviewer);
943 myLocalContexts(myCurLocalIndex)->ClearSelected(updateviewer);
948 //=======================================================================
949 //function : SetSelectedCurrent
951 //=======================================================================
953 void AIS_InteractiveContext::SetSelectedCurrent()
958 cout<<"Not Yet Implemented"<<endl;
962 //=======================================================================
963 //function : UpdateSelection
965 //=======================================================================
967 void AIS_InteractiveContext::UpdateSelected(const Standard_Boolean updateviewer)
969 if(!HasOpenedContext()) {
975 myLocalContexts(myCurLocalIndex)->UpdateSelected(updateviewer);
978 //=======================================================================
979 //function : SetCurrentObject
981 //=======================================================================
982 void AIS_InteractiveContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,const Standard_Boolean updateviewer)
984 if(!HasOpenedContext())
985 SetCurrentObject(anIObj,updateviewer);
987 myLocalContexts(myCurLocalIndex)->SetSelected(anIObj,updateviewer);
990 //=======================================================================
991 //function : AddOrRemoveSelected
993 //=======================================================================
995 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj,
996 const Standard_Boolean updateviewer)
998 if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
999 if(!HasOpenedContext())
1000 AddOrRemoveCurrentObject(anIObj,updateviewer);
1002 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(anIObj,updateviewer);
1005 //=======================================================================
1006 //function : AddOrRemoveSelected
1008 //=======================================================================
1010 void AIS_InteractiveContext::AddOrRemoveSelected(const TopoDS_Shape& aShap,
1011 const Standard_Boolean updateviewer)
1013 if(!HasOpenedContext()) {
1015 cout<<" Attempt to remove a selected shape with no opened local context"<<endl;
1020 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(aShap,updateviewer);
1021 if(updateviewer) UpdateCurrentViewer();
1024 //=======================================================================
1025 //function : AddOrRemoveSelected
1027 //=======================================================================
1029 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(SelectMgr_EntityOwner)& Own,
1030 const Standard_Boolean updateviewer)
1032 if(!HasOpenedContext()) {
1034 cout<<" Attempt to remove a selected ownr with no opened local context"<<endl;
1039 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(Own,Standard_False);
1040 if(updateviewer) UpdateCurrentViewer();
1046 //=======================================================================
1047 //function : IsSelected
1049 //=======================================================================
1051 Standard_Boolean AIS_InteractiveContext::
1052 IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const
1054 if (anIObj.IsNull()) return Standard_False;
1056 if(!HasOpenedContext())
1057 return (anIObj->State()==1);
1059 return myLocalContexts(myCurLocalIndex)->IsSelected(anIObj);
1063 //=======================================================================
1064 //function : InitSelected
1066 //=======================================================================
1068 void AIS_InteractiveContext::InitSelected()
1070 if(!HasOpenedContext())
1071 AIS_Selection::Selection(myCurrentName.ToCString())->Init();
1073 myLocalContexts(myCurLocalIndex)->InitSelected();
1076 //=======================================================================
1077 //function : MoreSelected
1079 //=======================================================================
1081 Standard_Boolean AIS_InteractiveContext::MoreSelected() const
1083 if(!HasOpenedContext())
1084 return AIS_Selection::Selection(myCurrentName.ToCString())->More();
1085 return myLocalContexts(myCurLocalIndex)->MoreSelected();
1088 //=======================================================================
1089 //function : NextSelected
1091 //=======================================================================
1093 void AIS_InteractiveContext::NextSelected()
1095 if(!HasOpenedContext())
1096 AIS_Selection::Selection(myCurrentName.ToCString())->Next();
1098 myLocalContexts(myCurLocalIndex)->NextSelected();
1101 //=======================================================================
1102 //function : HasSelectedShape
1104 //=======================================================================
1106 Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
1108 if(!HasOpenedContext()) {
1110 Handle(AIS_Shape) shape =
1111 Handle(AIS_Shape)::DownCast(SelectedInteractive());
1112 if( !shape.IsNull() ) return Standard_True;
1114 return Standard_False;
1116 return myLocalContexts(myCurLocalIndex)->HasShape();
1121 //=======================================================================
1122 //function : SelectedShape
1124 //=======================================================================
1126 TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
1128 if (!HasOpenedContext())
1130 TopoDS_Shape aResShape;
1131 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (SelectedInteractive());
1132 if (!aShape.IsNull())
1134 aResShape = aShape->Shape().Located (TopLoc_Location (SelectedInteractive()->Transformation()) * aShape->Shape().Location());
1141 return myLocalContexts (myCurLocalIndex)->SelectedShape();
1145 //=======================================================================
1146 //function : Interactive
1148 //=======================================================================
1150 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Interactive() const
1152 return SelectedInteractive();
1155 Handle(AIS_InteractiveObject) AIS_InteractiveContext::SelectedInteractive() const
1157 if(!HasOpenedContext()){
1158 Handle(Standard_Transient) TR =AIS_Selection::Selection(myCurrentName.ToCString())->Value();
1159 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
1162 return myLocalContexts(myCurLocalIndex)->SelectedInteractive();
1165 //=======================================================================
1166 //function : Interactive
1168 //=======================================================================
1170 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const
1172 if(!HasOpenedContext()){
1173 Handle(SelectMgr_EntityOwner) Ownr;
1176 return myLocalContexts(myCurLocalIndex)->SelectedOwner();
1180 //=======================================================================
1181 //function : EntityOwners
1183 //=======================================================================
1184 void AIS_InteractiveContext::EntityOwners(SelectMgr_IndexedMapOfOwner& theOwners,
1185 const Handle(AIS_InteractiveObject)& theIObj,
1186 const Standard_Integer theMode) const
1188 if ( theIObj.IsNull() )
1191 TColStd_ListOfInteger aModes;
1192 if ( theMode == -1 )
1193 ActivatedModes( theIObj, aModes );
1195 aModes.Append( theMode );
1197 TColStd_ListIteratorOfListOfInteger anItr( aModes );
1198 for (; anItr.More(); anItr.Next() )
1200 int aMode = anItr.Value();
1201 if ( !theIObj->HasSelection( aMode ) )
1204 Handle(SelectMgr_Selection) aSel = theIObj->Selection( aMode );
1206 for ( aSel->Init(); aSel->More(); aSel->Next() )
1208 Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive();
1209 if ( aEntity.IsNull() )
1212 Handle(SelectMgr_EntityOwner) aOwner =
1213 Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId());
1214 if ( !aOwner.IsNull() )
1215 theOwners.Add( aOwner );
1220 Standard_Integer AIS_InteractiveContext::NbSelected()
1222 Standard_Integer i(0);
1223 for(InitSelected();MoreSelected();NextSelected())
1228 //=======================================================================
1229 //function : HasApplicative
1231 //=======================================================================
1233 Standard_Boolean AIS_InteractiveContext::HasApplicative() const
1235 return Interactive()->HasOwner();
1238 //=======================================================================
1239 //function : Applicative
1241 //=======================================================================
1243 Handle(Standard_Transient) AIS_InteractiveContext::Applicative() const
1245 return Interactive()->GetOwner();
1250 //==================================================
1253 //==================================================
1254 Standard_Boolean AIS_InteractiveContext::HasDetected() const
1256 if(HasOpenedContext())
1257 return myLocalContexts(myCurLocalIndex)->HasDetected();
1259 return !myLastPicked.IsNull();
1262 //=======================================================================
1263 //function : HasDetectedShape
1265 //=======================================================================
1267 Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
1269 if(HasOpenedContext())
1270 return myLocalContexts(myCurLocalIndex)->HasDetectedShape();
1271 return Standard_False;
1274 //=======================================================================
1275 //function : DetectedShape
1277 //=======================================================================
1280 AIS_InteractiveContext::DetectedShape() const
1282 return myLocalContexts(myCurLocalIndex)->DetectedShape();
1285 //=======================================================================
1286 //function : DetectedInteractive
1288 //=======================================================================
1290 Handle(AIS_InteractiveObject)
1291 AIS_InteractiveContext::DetectedInteractive() const
1293 if(HasOpenedContext())
1294 return myLocalContexts(myCurLocalIndex)->DetectedInteractive();
1295 return myLastPicked;
1299 Standard_Boolean AIS_InteractiveContext::HasNextDetected() const
1301 if(!HasOpenedContext())
1302 return Standard_False; // temporaire
1304 return myLocalContexts(myCurLocalIndex)->HasNextDetected();
1309 //=======================================================================
1310 //function : DetectedOwner
1312 //=======================================================================
1313 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedOwner() const
1315 if(HasOpenedContext())
1316 return myLocalContexts(myCurLocalIndex)->DetectedOwner();
1317 Handle(SelectMgr_EntityOwner) Ownr;
1322 //=======================================================================
1323 //function : HilightNextDetected
1325 //=======================================================================
1326 Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView,
1327 const Standard_Boolean theToRedrawImmediate)
1329 return HasOpenedContext()
1330 ? myLocalContexts (myCurLocalIndex)->HilightNextDetected (theView, theToRedrawImmediate)
1335 //=======================================================================
1336 //function : HilightNextDetected
1338 //=======================================================================
1339 Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1340 const Standard_Boolean theToRedrawImmediate)
1342 return HasOpenedContext()
1343 ? myLocalContexts (myCurLocalIndex)->HilightPreviousDetected (theView, theToRedrawImmediate)
1348 //=======================================================================
1349 //function : InitDetected
1351 //=======================================================================
1352 void AIS_InteractiveContext::InitDetected()
1354 if (HasOpenedContext())
1356 myLocalContexts(myCurLocalIndex)->InitDetected();
1360 if(myAISDetectedSeq.Length() != 0)
1362 myAISCurDetected = 1;
1366 //=======================================================================
1367 //function : MoreDetected
1369 //=======================================================================
1370 Standard_Boolean AIS_InteractiveContext::MoreDetected() const
1372 if (HasOpenedContext())
1374 return myLocalContexts(myCurLocalIndex)->MoreDetected();
1377 return (myAISCurDetected > 0 && myAISCurDetected <= myAISDetectedSeq.Length()) ?
1378 Standard_True : Standard_False;
1381 //=======================================================================
1382 //function : NextDetected
1384 //=======================================================================
1385 void AIS_InteractiveContext::NextDetected()
1387 if(HasOpenedContext())
1389 myLocalContexts(myCurLocalIndex)->NextDetected();
1396 //=======================================================================
1397 //function : DetectedCurrentShape
1399 //=======================================================================
1400 const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
1402 if (HasOpenedContext())
1404 return myLocalContexts(myCurLocalIndex)->DetectedCurrentShape();
1407 static TopoDS_Shape aDummyShape;
1409 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
1411 if (aCurrentShape.IsNull())
1416 return aCurrentShape->Shape();
1419 //=======================================================================
1420 //function : DetectedCurrentObject
1422 //=======================================================================
1423 Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const
1425 if (HasOpenedContext())
1427 return myLocalContexts(myCurLocalIndex)->DetectedCurrentObject();
1430 return MoreDetected() ? myAISDetectedSeq(myAISCurDetected) : NULL;