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>
58 //=======================================================================
61 //=======================================================================
62 AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const Standard_Integer theXPix,
63 const Standard_Integer theYPix,
64 const Handle(V3d_View)& theView,
65 const Standard_Boolean theToRedrawOnUpdate)
67 if (HasOpenedContext())
69 myWasLastMain = Standard_True;
70 return myLocalContexts (myCurLocalIndex)->MoveTo (theXPix, theYPix, theView, theToRedrawOnUpdate);
74 myAISDetectedSeq.Clear();
76 if (theView->Viewer() != myMainVwr)
82 myLastPicked = myLastinMain;
83 myWasLastMain = Standard_True;
84 AIS_StatusOfDetection aStatus = AIS_SOD_Nothing;
85 Standard_Boolean toUpdateViewer = Standard_False;
88 myMainSel->Pick (theXPix, theYPix, theView);
90 // filling of myAISDetectedSeq sequence storing information about detected AIS objects
91 // (the objects must be AIS_Shapes)
92 const Standard_Integer aDetectedNb = myMainSel->NbPicked();
93 Standard_Integer aNewDetected = 0;
94 for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
96 Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aDetIter);
98 || !myFilters->IsOk (anOwner))
103 if (aNewDetected < 1)
105 aNewDetected = aDetIter;
107 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
110 myAISDetectedSeq.Append (anObj);
114 if (aNewDetected >= 1)
116 // does nothing if previously detected object is equal to the current one
117 Handle(SelectMgr_EntityOwner) aNewPickedOwner = myMainSel->Picked (aNewDetected);
118 if (aNewPickedOwner->Selectable() == myLastPicked)
120 return myLastPicked->State() == 1
122 : AIS_SOD_OnlyOneDetected;
125 // Previously detected object is unhilighted if it is not selected or hilighted
126 // with selection color if it is selected. Such highlighting with selection color
127 // is needed only if myToHilightSelected flag is true. In this case previously detected
128 // object has been already highlighted with myHilightColor during previous MoveTo()
129 // method call. As result it is necessary to rehighligt it with mySelectionColor.
130 if (!myLastPicked.IsNull())
132 const Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
133 if (myLastPicked->State() != 1)
135 myMainPM->Unhighlight (myLastPicked, aHiMod);
136 toUpdateViewer = Standard_True;
138 else if (myToHilightSelected)
140 myMainPM->Color (myLastPicked, mySelectionColor, aHiMod);
141 toUpdateViewer = Standard_True;
145 // initialize myLastPicked field with currently detected object
146 myLastPicked = Handle(AIS_InteractiveObject)::DownCast (aNewPickedOwner->Selectable());
147 myLastinMain = myLastPicked;
149 // highlight detected object if it is not selected or myToHilightSelected flag is true
150 if (!myLastPicked.IsNull())
152 if (myLastPicked->State() != 1 || myToHilightSelected)
154 const Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
155 myMainPM->Color (myLastPicked, myHilightColor, aHiMod);
156 toUpdateViewer = Standard_True;
159 aStatus = myLastPicked->State() == 1
161 : AIS_SOD_OnlyOneDetected;
166 // previously detected object is unhilighted if it is not selected or hilighted
167 // with selection color if it is selected
168 aStatus = AIS_SOD_Nothing;
169 if (!myLastPicked.IsNull())
171 Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
172 if (myLastPicked->State() != 1)
174 myMainPM->Unhighlight (myLastPicked, aHiMod);
175 toUpdateViewer = Standard_True;
177 else if (myToHilightSelected)
179 myMainPM->Color (myLastPicked, mySelectionColor, aHiMod);
180 toUpdateViewer = Standard_True;
184 myLastinMain.Nullify();
185 myLastPicked.Nullify();
190 if (theToRedrawOnUpdate)
192 theView->Viewer()->Update();
196 theView->Viewer()->Invalidate();
200 mylastmoveview = theView;
204 //=======================================================================
207 //=======================================================================
208 AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Integer theXPMin,
209 const Standard_Integer theYPMin,
210 const Standard_Integer theXPMax,
211 const Standard_Integer theYPMax,
212 const Handle(V3d_View)& theView,
213 const Standard_Boolean toUpdateViewer)
215 // all objects detected by the selector are taken, previous current objects are emptied,
216 // new objects are put...
218 if (HasOpenedContext())
220 return myLocalContexts(myCurLocalIndex)->Select (theXPMin, theYPMin,
222 theView, toUpdateViewer);
225 ClearCurrents (Standard_False);
227 Handle(StdSelect_ViewerSelector3d) aSelector;
229 if (theView->Viewer() == myMainVwr)
231 aSelector = myMainSel;
232 myWasLastMain = Standard_True;
235 aSelector->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
236 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
238 AIS_MapOfInteractive anObjectsToSelect;
239 for (aSelector->Init(); aSelector->More(); aSelector->Next())
241 Handle(AIS_InteractiveObject) anObj =
242 Handle(AIS_InteractiveObject)::DownCast (aSelector->Picked()->Selectable());
245 anObjectsToSelect.Add (anObj);
249 AIS_MapIteratorOfMapOfInteractive anIt (anObjectsToSelect);
250 for ( ; anIt.More(); anIt.Next())
252 AIS_Selection::Select (anIt.Key());
253 anIt.Key()->State (1);
256 HilightCurrents (toUpdateViewer);
258 Standard_Integer aSelNum = NbCurrents();
260 return (aSelNum == 0) ? AIS_SOP_NothingSelected
261 : (aSelNum == 1) ? AIS_SOP_OneSelected
262 : AIS_SOP_SeveralSelected;
266 //=======================================================================
268 //purpose : Selection by polyline
269 //=======================================================================
270 AIS_StatusOfPick AIS_InteractiveContext::Select (const TColgp_Array1OfPnt2d& thePolyline,
271 const Handle(V3d_View)& theView,
272 const Standard_Boolean toUpdateViewer)
274 // all objects detected by the selector are taken, previous current objects are emptied,
275 // new objects are put...
277 if (HasOpenedContext())
279 return myLocalContexts(myCurLocalIndex)->Select (thePolyline, theView, toUpdateViewer);
282 ClearCurrents (Standard_False);
284 Handle(StdSelect_ViewerSelector3d) aSelector;
286 if (theView->Viewer() == myMainVwr)
288 aSelector = myMainSel;
289 myWasLastMain = Standard_True;
292 aSelector->Pick (thePolyline, theView);
293 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
295 AIS_MapOfInteractive anObjectsToSelect;
296 for (aSelector->Init(); aSelector->More(); aSelector->Next())
298 Handle(AIS_InteractiveObject) anObj =
299 Handle( AIS_InteractiveObject )::DownCast (aSelector->Picked()->Selectable());
302 anObjectsToSelect.Add (anObj);
306 AIS_MapIteratorOfMapOfInteractive anIt (anObjectsToSelect);
307 for ( ; anIt.More(); anIt.Next())
309 AIS_Selection::Select (anIt.Key());
310 anIt.Key()->State (1);
313 HilightCurrents (toUpdateViewer);
315 Standard_Integer aSelNum = NbCurrents();
317 return (aSelNum == 0) ? AIS_SOP_NothingSelected
318 : (aSelNum == 1) ? AIS_SOP_OneSelected
319 : AIS_SOP_SeveralSelected;
323 //=======================================================================
326 //=======================================================================
327 AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean toUpdateViewer)
329 if (HasOpenedContext())
333 return myLocalContexts(myCurLocalIndex)->Select (toUpdateViewer);
337 myLocalContexts(myCurLocalIndex)->SetSelected (myLastPicked, toUpdateViewer);
338 return AIS_SOP_OneSelected;
342 if (myWasLastMain && !myLastinMain.IsNull())
344 if(myLastinMain->State() != 1)
346 SetCurrentObject (myLastinMain,Standard_False);
349 UpdateCurrentViewer();
355 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
356 Handle(AIS_Selection) aSelection = AIS_Selection::CurrentSelection();
357 Handle(AIS_InteractiveObject) anObj;
358 for (aSelection->Init(); aSelection->More(); aSelection->Next())
360 anObj = Handle(AIS_InteractiveObject)::DownCast (aSelection->Value());
362 Unhilight (anObj,Standard_False);
363 if (myObjects.IsBound (anObj) && myObjects(anObj)->IsSubIntensityOn())
365 HilightWithColor (anObj, mySubIntensity, Standard_False);
369 AIS_Selection::Select();
370 if (toUpdateViewer && myWasLastMain)
372 UpdateCurrentViewer();
376 Standard_Integer aSelNum = NbCurrents();
378 return (aSelNum == 0) ? AIS_SOP_NothingSelected
379 : (aSelNum == 1) ? AIS_SOP_OneSelected
380 : AIS_SOP_SeveralSelected;
383 //=======================================================================
384 //function : ShiftSelect
386 //=======================================================================
387 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Boolean toUpdateViewer)
389 if (HasOpenedContext())
393 return myLocalContexts (myCurLocalIndex)->ShiftSelect (toUpdateViewer);
397 myLocalContexts (myCurLocalIndex)->AddOrRemoveSelected (myLastPicked, toUpdateViewer);
399 Standard_Integer aSelNum = NbSelected();
400 return (aSelNum == 0) ? AIS_SOP_NothingSelected
401 : (aSelNum == 1) ? AIS_SOP_OneSelected
402 : AIS_SOP_SeveralSelected;
406 if (myWasLastMain && !myLastinMain.IsNull())
408 AddOrRemoveCurrentObject (myLastinMain, toUpdateViewer);
411 Standard_Integer aCurrentSelNum = NbCurrents();
413 return (aCurrentSelNum == 0) ? AIS_SOP_NothingSelected
414 : (aCurrentSelNum == 1) ? AIS_SOP_OneSelected
415 : AIS_SOP_SeveralSelected;
418 //=======================================================================
419 //function : ShiftSelect
421 //=======================================================================
422 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Integer theXPMin,
423 const Standard_Integer theYPMin,
424 const Standard_Integer theXPMax,
425 const Standard_Integer theYPMax,
426 const Handle(V3d_View)& theView,
427 const Standard_Boolean toUpdateViewer)
429 if (HasOpenedContext())
431 return myLocalContexts(myCurLocalIndex)->ShiftSelect (theXPMin, theYPMin, theXPMax, theYPMax,
432 theView, toUpdateViewer);
435 UnhilightCurrents (Standard_False);
437 Handle(StdSelect_ViewerSelector3d) aSelector;
438 if (theView->Viewer() == myMainVwr)
440 aSelector = myMainSel;
441 myWasLastMain = Standard_True;
445 return AIS_SOP_NothingSelected;
448 aSelector->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
449 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
450 for (aSelector->Init(); aSelector->More(); aSelector->Next())
452 Handle(AIS_InteractiveObject) anObjToSelect = Handle(AIS_InteractiveObject)::DownCast (aSelector->Picked()->Selectable());
453 if (!anObjToSelect.IsNull())
455 AIS_SelectStatus aSelStatus = AIS_Selection::Select (anObjToSelect);
456 Standard_Integer aState = (aSelStatus == AIS_SS_Added) ? 1 : 0;
457 anObjToSelect->State (aState);
461 HilightCurrents (toUpdateViewer);
463 Standard_Integer aSelNum = NbCurrents();
465 return (aSelNum == 0) ? AIS_SOP_NothingSelected
466 : (aSelNum == 1) ? AIS_SOP_OneSelected
467 : AIS_SOP_SeveralSelected;
471 //=======================================================================
472 //function : ShiftSelect
474 //=======================================================================
475 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline,
476 const Handle(V3d_View)& theView,
477 const Standard_Boolean toUpdateViewer)
479 if (HasOpenedContext())
481 return myLocalContexts(myCurLocalIndex)->ShiftSelect (thePolyline, theView, toUpdateViewer);
484 UnhilightCurrents (Standard_False);
486 Handle(StdSelect_ViewerSelector3d) aSelector;
488 if (theView->Viewer() == myMainVwr)
490 aSelector= myMainSel;
491 myWasLastMain = Standard_True;
495 return AIS_SOP_NothingSelected;
498 aSelector->Pick (thePolyline, theView);
500 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
501 for (aSelector->Init(); aSelector->More(); aSelector->Next())
503 Handle(AIS_InteractiveObject) anObjToSelect = Handle(AIS_InteractiveObject)::DownCast (aSelector->Picked()->Selectable());
504 if (!anObjToSelect.IsNull())
506 AIS_SelectStatus aSelStatus = AIS_Selection::Select (anObjToSelect);
507 Standard_Integer aState = (aSelStatus == AIS_SS_Added ) ? 1 : 0;
508 anObjToSelect->State (aState);
512 HilightCurrents (toUpdateViewer);
514 Standard_Integer aSelNum = NbCurrents();
516 return (aSelNum == 0) ? AIS_SOP_NothingSelected
517 : (aSelNum == 1) ? AIS_SOP_OneSelected
518 : AIS_SOP_SeveralSelected;
521 //=======================================================================
522 //function : SetCurrentObject
524 //=======================================================================
525 void AIS_InteractiveContext::SetCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
526 const Standard_Boolean updateviewer)
528 // single case processing...
529 if(NbCurrents()==1 && anIObj->State()==1){
530 Quantity_NameOfColor HiCol;
531 Standard_Boolean HasHiCol;
532 if(IsHilighted(anIObj,HasHiCol,HiCol)){
533 if(HasHiCol && HiCol!= mySelectionColor) {
535 HilightWithColor(anIObj,mySelectionColor,updateviewer);
537 Hilight(anIObj,updateviewer);
546 if(!HasOpenedContext()) {
547 if(anIObj.IsNull()) return;
548 if(!myObjects.IsBound(anIObj))
549 Display(anIObj,Standard_False);
551 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
552 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
553 Handle(Standard_Transient) TR;
554 Handle(AIS_InteractiveObject) IO;
556 while (sel->More()) {
558 IO = *((Handle(AIS_InteractiveObject)*)&TR);
559 Unhilight(IO,Standard_False);
564 // added to avoid untimely viewer update...
565 AIS_Selection::ClearAndSelect(anIObj);
567 Quantity_NameOfColor HiCol;
568 Standard_Boolean HasHiCol;
569 if(IsHilighted(anIObj,HasHiCol,HiCol)){
570 if(HasHiCol && HiCol!= mySelectionColor) {
572 HilightWithColor(anIObj,mySelectionColor,Standard_False);
574 Hilight(anIObj,Standard_False);
580 HilightWithColor(anIObj,mySelectionColor,Standard_False);
582 Hilight(anIObj,Standard_False);
586 UpdateCurrentViewer();
590 cout<<"Nothing Done : Opened Local Context"<<endl;
595 //=======================================================================
596 //function : AddOrRemoveCurrentObject
598 //=======================================================================
600 void AIS_InteractiveContext::
601 AddOrRemoveCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
602 const Standard_Boolean updateviewer)
604 if(anIObj.IsNull()) return;
605 //OCC5682 to remove an object from neutral point even if Local Context is opened (Remove method)
606 if(!HasOpenedContext() /*OCC5682*/|| myObjects.IsBound(anIObj)) {
608 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
609 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
611 AIS_SelectStatus SelStat = AIS_Selection::Select(anIObj);
613 Standard_Integer mod = (SelStat==AIS_SS_Added) ? 1 : 0;
617 HilightWithColor(anIObj,mySelectionColor,Standard_False);
619 Hilight(anIObj,Standard_False);
622 Unhilight(anIObj,Standard_False);
626 UpdateCurrentViewer();
630 cout<<"Nothing Done : Opened Local Context"<<endl;
634 //=======================================================================
635 //function : UpdateCurrent
637 //=======================================================================
639 void AIS_InteractiveContext::UpdateCurrent()
644 //=======================================================================
645 //function : IsCurrent
647 //=======================================================================
649 Standard_Boolean AIS_InteractiveContext::IsCurrent(const Handle(AIS_InteractiveObject)& anIObj) const
652 if (anIObj.IsNull()) return Standard_False;
653 return (anIObj->State()==1);
655 // Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
657 // while (sel->More()) {
658 // if (anIObj == sel->Value()) return Standard_True;
661 // return Standard_False;
665 //=======================================================================
666 //function : InitCurrent
668 //=======================================================================
670 void AIS_InteractiveContext::InitCurrent()
672 AIS_Selection::Selection(myCurrentName.ToCString())->Init();
675 //=======================================================================
676 //function : MoreCurrent
678 //=======================================================================
680 Standard_Boolean AIS_InteractiveContext::MoreCurrent() const
682 return AIS_Selection::Selection(myCurrentName.ToCString())->More();
686 //=======================================================================
687 //function : NextCurrent
689 //=======================================================================
691 void AIS_InteractiveContext::NextCurrent()
693 AIS_Selection::Selection(myCurrentName.ToCString())->Next();
696 //=======================================================================
699 //=======================================================================
701 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Current() const
703 Handle(Standard_Transient) TR = AIS_Selection::Selection(myCurrentName.ToCString())->Value();
704 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
708 //=======================================================================
709 //function : FirstCurrentObject
711 //=======================================================================
712 Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstCurrentObject()
714 Handle(AIS_InteractiveObject) IO ;
722 //=======================================================================
723 //function : NbCurrents
725 //=======================================================================
726 Standard_Integer AIS_InteractiveContext::NbCurrents()
728 Standard_Integer i(0);
729 for(InitCurrent();MoreCurrent();NextCurrent())
734 //=======================================================================
735 //function : HilightCurrents
737 //=======================================================================
738 void AIS_InteractiveContext::HilightCurrents(const Standard_Boolean updateviewer)
740 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
741 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
742 Handle(Standard_Transient) TR;
743 Handle(AIS_InteractiveObject) IO;
745 while (sel->More()) {
747 IO = *((Handle(AIS_InteractiveObject)*)&TR);
749 HilightWithColor(IO,mySelectionColor,Standard_False);
751 Hilight(IO,Standard_False);
756 UpdateCurrentViewer();
759 //=======================================================================
760 //function : UnhilightCurrents
762 //=======================================================================
764 void AIS_InteractiveContext::UnhilightCurrents(const Standard_Boolean updateviewer)
766 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
767 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
768 Handle(Standard_Transient) TR;
769 Handle(AIS_InteractiveObject) IO;
771 while (sel->More()) {
773 IO = *((Handle(AIS_InteractiveObject)*)&TR);
774 Unhilight(IO,Standard_False);
778 UpdateCurrentViewer();
781 //=======================================================================
782 //function : ClearCurrents
784 //=======================================================================
786 void AIS_InteractiveContext::ClearCurrents(const Standard_Boolean updateviewer)
788 if(NbCurrents()==0) return;
789 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
790 Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
791 Handle(Standard_Transient) Tr;
792 Handle(AIS_InteractiveObject) IO;
793 for(S->Init();S->More();S->Next()){
795 IO = (*((Handle(AIS_InteractiveObject)*)&Tr));
797 Unhilight(IO,Standard_False);
799 AIS_Selection::Select();
801 UpdateCurrentViewer();
805 //=======================================================================
806 //function : HilightSelected
808 //=======================================================================
810 void AIS_InteractiveContext::HilightSelected(const Standard_Boolean updateviewer)
812 if(!HasOpenedContext()){
813 AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
814 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
815 Handle(Standard_Transient) TR;
816 Handle(AIS_InteractiveObject) IO;
818 while (sel->More()) {
820 IO = *((Handle(AIS_InteractiveObject)*)&TR);
822 HilightWithColor(IO,mySelectionColor,Standard_False);
824 Hilight(IO,Standard_False);
831 myLocalContexts(myCurLocalIndex)->HilightPicked(updateviewer);
834 UpdateCurrentViewer();
837 //=======================================================================
838 //function : UnhilightSelected
840 //=======================================================================
842 void AIS_InteractiveContext::UnhilightSelected(const Standard_Boolean updateviewer)
844 if(!HasOpenedContext()){
845 AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
846 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
847 Handle(Standard_Transient) TR;
848 Handle(AIS_InteractiveObject) IO;
850 while (sel->More()) {
852 IO = *((Handle(AIS_InteractiveObject)*)&TR);
853 Unhilight(IO,Standard_False);
857 UpdateCurrentViewer();
861 myLocalContexts(myCurLocalIndex)->UnhilightPicked(updateviewer);
866 //=======================================================================
867 //function : ClearSelected
869 //=======================================================================
871 void AIS_InteractiveContext::ClearSelected(const Standard_Boolean updateviewer)
873 if(!HasOpenedContext())
874 ClearCurrents(updateviewer);
876 myLocalContexts(myCurLocalIndex)->ClearSelected(updateviewer);
881 //=======================================================================
882 //function : SetSelectedCurrent
884 //=======================================================================
886 void AIS_InteractiveContext::SetSelectedCurrent()
891 cout<<"Not Yet Implemented"<<endl;
895 //=======================================================================
896 //function : UpdateSelection
898 //=======================================================================
900 void AIS_InteractiveContext::UpdateSelected(const Standard_Boolean updateviewer)
902 if(!HasOpenedContext()) {
908 myLocalContexts(myCurLocalIndex)->UpdateSelected(updateviewer);
911 //=======================================================================
912 //function : SetCurrentObject
914 //=======================================================================
915 void AIS_InteractiveContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,const Standard_Boolean updateviewer)
917 if(!HasOpenedContext())
918 SetCurrentObject(anIObj,updateviewer);
920 myLocalContexts(myCurLocalIndex)->SetSelected(anIObj,updateviewer);
923 //=======================================================================
924 //function : AddOrRemoveSelected
926 //=======================================================================
928 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj,
929 const Standard_Boolean updateviewer)
931 if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
932 if(!HasOpenedContext())
933 AddOrRemoveCurrentObject(anIObj,updateviewer);
935 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(anIObj,updateviewer);
938 //=======================================================================
939 //function : AddOrRemoveSelected
941 //=======================================================================
943 void AIS_InteractiveContext::AddOrRemoveSelected(const TopoDS_Shape& aShap,
944 const Standard_Boolean updateviewer)
946 if(!HasOpenedContext()) {
948 cout<<" Attempt to remove a selected shape with no opened local context"<<endl;
953 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(aShap,updateviewer);
954 if(updateviewer) UpdateCurrentViewer();
957 //=======================================================================
958 //function : AddOrRemoveSelected
960 //=======================================================================
962 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(SelectMgr_EntityOwner)& Own,
963 const Standard_Boolean updateviewer)
965 if(!HasOpenedContext()) {
967 cout<<" Attempt to remove a selected ownr with no opened local context"<<endl;
972 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(Own,Standard_False);
973 if(updateviewer) UpdateCurrentViewer();
979 //=======================================================================
980 //function : IsSelected
982 //=======================================================================
984 Standard_Boolean AIS_InteractiveContext::
985 IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const
987 if (anIObj.IsNull()) return Standard_False;
989 if(!HasOpenedContext())
990 return (anIObj->State()==1);
992 return myLocalContexts(myCurLocalIndex)->IsSelected(anIObj);
996 //=======================================================================
997 //function : InitSelected
999 //=======================================================================
1001 void AIS_InteractiveContext::InitSelected()
1003 if(!HasOpenedContext())
1004 AIS_Selection::Selection(myCurrentName.ToCString())->Init();
1006 myLocalContexts(myCurLocalIndex)->InitSelected();
1009 //=======================================================================
1010 //function : MoreSelected
1012 //=======================================================================
1014 Standard_Boolean AIS_InteractiveContext::MoreSelected() const
1016 if(!HasOpenedContext())
1017 return AIS_Selection::Selection(myCurrentName.ToCString())->More();
1018 return myLocalContexts(myCurLocalIndex)->MoreSelected();
1021 //=======================================================================
1022 //function : NextSelected
1024 //=======================================================================
1026 void AIS_InteractiveContext::NextSelected()
1028 if(!HasOpenedContext())
1029 AIS_Selection::Selection(myCurrentName.ToCString())->Next();
1031 myLocalContexts(myCurLocalIndex)->NextSelected();
1034 //=======================================================================
1035 //function : HasSelectedShape
1037 //=======================================================================
1039 Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
1041 if(!HasOpenedContext()) {
1043 Handle(AIS_Shape) shape =
1044 Handle(AIS_Shape)::DownCast(SelectedInteractive());
1045 if( !shape.IsNull() ) return Standard_True;
1047 return Standard_False;
1049 return myLocalContexts(myCurLocalIndex)->HasShape();
1054 //=======================================================================
1055 //function : SelectedShape
1057 //=======================================================================
1059 TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
1061 if (!HasOpenedContext())
1063 TopoDS_Shape aResShape;
1064 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (SelectedInteractive());
1065 if (!aShape.IsNull())
1067 aResShape = aShape->Shape().Located (TopLoc_Location (SelectedInteractive()->Transformation()) * aShape->Shape().Location());
1074 return myLocalContexts (myCurLocalIndex)->SelectedShape();
1078 //=======================================================================
1079 //function : Interactive
1081 //=======================================================================
1083 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Interactive() const
1085 return SelectedInteractive();
1088 Handle(AIS_InteractiveObject) AIS_InteractiveContext::SelectedInteractive() const
1090 if(!HasOpenedContext()){
1091 Handle(Standard_Transient) TR =AIS_Selection::Selection(myCurrentName.ToCString())->Value();
1092 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
1095 return myLocalContexts(myCurLocalIndex)->SelectedInteractive();
1098 //=======================================================================
1099 //function : Interactive
1101 //=======================================================================
1103 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const
1105 if(!HasOpenedContext()){
1106 Handle(SelectMgr_EntityOwner) Ownr;
1109 return myLocalContexts(myCurLocalIndex)->SelectedOwner();
1113 //=======================================================================
1114 //function : EntityOwners
1116 //=======================================================================
1117 void AIS_InteractiveContext::EntityOwners(SelectMgr_IndexedMapOfOwner& theOwners,
1118 const Handle(AIS_InteractiveObject)& theIObj,
1119 const Standard_Integer theMode) const
1121 if ( theIObj.IsNull() )
1124 TColStd_ListOfInteger aModes;
1125 if ( theMode == -1 )
1126 ActivatedModes( theIObj, aModes );
1128 aModes.Append( theMode );
1130 TColStd_ListIteratorOfListOfInteger anItr( aModes );
1131 for (; anItr.More(); anItr.Next() )
1133 int aMode = anItr.Value();
1134 if ( !theIObj->HasSelection( aMode ) )
1137 Handle(SelectMgr_Selection) aSel = theIObj->Selection( aMode );
1139 for ( aSel->Init(); aSel->More(); aSel->Next() )
1141 Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive();
1142 if ( aEntity.IsNull() )
1145 Handle(SelectMgr_EntityOwner) aOwner =
1146 Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId());
1147 if ( !aOwner.IsNull() )
1148 theOwners.Add( aOwner );
1153 Standard_Integer AIS_InteractiveContext::NbSelected()
1155 Standard_Integer i(0);
1156 for(InitSelected();MoreSelected();NextSelected())
1161 //=======================================================================
1162 //function : HasApplicative
1164 //=======================================================================
1166 Standard_Boolean AIS_InteractiveContext::HasApplicative() const
1168 return Interactive()->HasOwner();
1171 //=======================================================================
1172 //function : Applicative
1174 //=======================================================================
1176 Handle(Standard_Transient) AIS_InteractiveContext::Applicative() const
1178 return Interactive()->GetOwner();
1183 //==================================================
1186 //==================================================
1187 Standard_Boolean AIS_InteractiveContext::HasDetected() const
1189 if(HasOpenedContext())
1190 return myLocalContexts(myCurLocalIndex)->HasDetected();
1192 return !myLastPicked.IsNull();
1195 //=======================================================================
1196 //function : HasDetectedShape
1198 //=======================================================================
1200 Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
1202 if(HasOpenedContext())
1203 return myLocalContexts(myCurLocalIndex)->HasDetectedShape();
1204 return Standard_False;
1207 //=======================================================================
1208 //function : DetectedShape
1210 //=======================================================================
1213 AIS_InteractiveContext::DetectedShape() const
1215 return myLocalContexts(myCurLocalIndex)->DetectedShape();
1218 //=======================================================================
1219 //function : DetectedInteractive
1221 //=======================================================================
1223 Handle(AIS_InteractiveObject)
1224 AIS_InteractiveContext::DetectedInteractive() const
1226 if(HasOpenedContext())
1227 return myLocalContexts(myCurLocalIndex)->DetectedInteractive();
1228 return myLastPicked;
1232 Standard_Boolean AIS_InteractiveContext::HasNextDetected() const
1234 if(!HasOpenedContext())
1235 return Standard_False; // temporaire
1237 return myLocalContexts(myCurLocalIndex)->HasNextDetected();
1242 //=======================================================================
1243 //function : DetectedOwner
1245 //=======================================================================
1246 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedOwner() const
1248 if(HasOpenedContext())
1249 return myLocalContexts(myCurLocalIndex)->DetectedOwner();
1250 Handle(SelectMgr_EntityOwner) Ownr;
1255 //=======================================================================
1256 //function : HilightNextDetected
1258 //=======================================================================
1259 Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView,
1260 const Standard_Boolean theToRedrawImmediate)
1262 return HasOpenedContext()
1263 ? myLocalContexts (myCurLocalIndex)->HilightNextDetected (theView, theToRedrawImmediate)
1268 //=======================================================================
1269 //function : HilightNextDetected
1271 //=======================================================================
1272 Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1273 const Standard_Boolean theToRedrawImmediate)
1275 return HasOpenedContext()
1276 ? myLocalContexts (myCurLocalIndex)->HilightPreviousDetected (theView, theToRedrawImmediate)
1281 //=======================================================================
1282 //function : InitDetected
1284 //=======================================================================
1285 void AIS_InteractiveContext::InitDetected()
1287 if (HasOpenedContext())
1289 myLocalContexts(myCurLocalIndex)->InitDetected();
1293 if(myAISDetectedSeq.Length() != 0)
1295 myAISCurDetected = 1;
1299 //=======================================================================
1300 //function : MoreDetected
1302 //=======================================================================
1303 Standard_Boolean AIS_InteractiveContext::MoreDetected() const
1305 if (HasOpenedContext())
1307 return myLocalContexts(myCurLocalIndex)->MoreDetected();
1310 return (myAISCurDetected > 0 && myAISCurDetected <= myAISDetectedSeq.Length()) ?
1311 Standard_True : Standard_False;
1314 //=======================================================================
1315 //function : NextDetected
1317 //=======================================================================
1318 void AIS_InteractiveContext::NextDetected()
1320 if(HasOpenedContext())
1322 myLocalContexts(myCurLocalIndex)->NextDetected();
1329 //=======================================================================
1330 //function : DetectedCurrentShape
1332 //=======================================================================
1333 const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
1335 if (HasOpenedContext())
1337 return myLocalContexts(myCurLocalIndex)->DetectedCurrentShape();
1340 static TopoDS_Shape aDummyShape;
1342 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
1344 if (aCurrentShape.IsNull())
1349 return aCurrentShape->Shape();
1352 //=======================================================================
1353 //function : DetectedCurrentObject
1355 //=======================================================================
1356 Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const
1358 if (HasOpenedContext())
1360 return myLocalContexts(myCurLocalIndex)->DetectedCurrentObject();
1363 return MoreDetected() ? myAISDetectedSeq(myAISCurDetected) : NULL;