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.
18 #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
19 #include <AIS_GlobalStatus.hxx>
20 #include <AIS_InteractiveContext.hxx>
21 #include <AIS_InteractiveObject.hxx>
22 #include <AIS_LocalContext.hxx>
23 #include <AIS_MapIteratorOfMapOfInteractive.hxx>
24 #include <AIS_MapOfInteractive.hxx>
25 #include <AIS_Selection.hxx>
26 #include <AIS_Shape.hxx>
27 #include <AIS_StatusOfDetection.hxx>
28 #include <AIS_StatusOfPick.hxx>
29 #include <Aspect_Grid.hxx>
30 #include <Prs3d_BasicAspect.hxx>
31 #include <Prs3d_LineAspect.hxx>
32 #include <Prs3d_Presentation.hxx>
33 #include <Quantity_Color.hxx>
34 #include <SelectBasics_SensitiveEntity.hxx>
35 #include <SelectMgr_EntityOwner.hxx>
36 #include <SelectMgr_Filter.hxx>
37 #include <SelectMgr_OrFilter.hxx>
38 #include <SelectMgr_Selection.hxx>
39 #include <SelectMgr_SelectionManager.hxx>
40 #include <Standard_Transient.hxx>
41 #include <StdSelect_ViewerSelector3d.hxx>
42 #include <TCollection_AsciiString.hxx>
43 #include <TCollection_ExtendedString.hxx>
44 #include <TColStd_ListIteratorOfListOfInteger.hxx>
45 #include <TopLoc_Location.hxx>
46 #include <TopoDS_Shape.hxx>
47 #include <V3d_AmbientLight.hxx>
48 #include <V3d_DirectionalLight.hxx>
49 #include <V3d_Light.hxx>
50 #include <V3d_PositionalLight.hxx>
51 #include <V3d_SpotLight.hxx>
52 #include <V3d_View.hxx>
53 #include <V3d_Viewer.hxx>
54 #include <Visual3d_View.hxx>
56 //=======================================================================
59 //=======================================================================
60 AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const Standard_Integer theXPix,
61 const Standard_Integer theYPix,
62 const Handle(V3d_View)& theView,
63 const Standard_Boolean theToRedrawOnUpdate)
65 if (HasOpenedContext())
67 myWasLastMain = Standard_True;
68 return myLocalContexts (myCurLocalIndex)->MoveTo (theXPix, theYPix, theView, theToRedrawOnUpdate);
72 myAISDetectedSeq.Clear();
74 if (theView->Viewer() != myMainVwr)
80 myLastPicked = myLastinMain;
81 myWasLastMain = Standard_True;
82 AIS_StatusOfDetection aStatus = AIS_SOD_Nothing;
83 Standard_Boolean toUpdateViewer = Standard_False;
85 myFilters->SetDisabledObjects (theView->View()->HiddenObjects());
86 myMainSel->Pick (theXPix, theYPix, theView);
88 // filling of myAISDetectedSeq sequence storing information about detected AIS objects
89 // (the objects must be AIS_Shapes)
90 const Standard_Integer aDetectedNb = myMainSel->NbPicked();
91 Standard_Integer aNewDetected = 0;
92 for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
94 Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aDetIter);
96 || !myFilters->IsOk (anOwner))
101 if (aNewDetected < 1)
103 aNewDetected = aDetIter;
105 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
108 myAISDetectedSeq.Append (anObj);
112 if (aNewDetected >= 1)
114 // does nothing if previously detected object is equal to the current one
115 Handle(SelectMgr_EntityOwner) aNewPickedOwner = myMainSel->Picked (aNewDetected);
116 if (aNewPickedOwner->Selectable() == myLastPicked)
118 return myLastPicked->State() == 1
120 : AIS_SOD_OnlyOneDetected;
123 // Previously detected object is unhilighted if it is not selected or hilighted
124 // with selection color if it is selected. Such highlighting with selection color
125 // is needed only if myToHilightSelected flag is true. In this case previously detected
126 // object has been already highlighted with myHilightColor during previous MoveTo()
127 // method call. As result it is necessary to rehighligt it with mySelectionColor.
128 if (!myLastPicked.IsNull())
130 const Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
131 if (myLastPicked->State() != 1)
133 myMainPM->Unhighlight (myLastPicked, aHiMod);
134 toUpdateViewer = Standard_True;
136 else if (myToHilightSelected)
138 myMainPM->Color (myLastPicked, mySelectionColor, aHiMod);
139 toUpdateViewer = Standard_True;
143 // initialize myLastPicked field with currently detected object
144 myLastPicked = Handle(AIS_InteractiveObject)::DownCast (aNewPickedOwner->Selectable());
145 myLastinMain = myLastPicked;
147 // highlight detected object if it is not selected or myToHilightSelected flag is true
148 if (!myLastPicked.IsNull())
150 if (myLastPicked->State() != 1 || myToHilightSelected)
152 const Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
153 myMainPM->Color (myLastPicked, myHilightColor, aHiMod);
154 toUpdateViewer = Standard_True;
157 aStatus = myLastPicked->State() == 1
159 : AIS_SOD_OnlyOneDetected;
164 // previously detected object is unhilighted if it is not selected or hilighted
165 // with selection color if it is selected
166 aStatus = AIS_SOD_Nothing;
167 if (!myLastPicked.IsNull())
169 Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
170 if (myLastPicked->State() != 1)
172 myMainPM->Unhighlight (myLastPicked, aHiMod);
173 toUpdateViewer = Standard_True;
175 else if (myToHilightSelected)
177 myMainPM->Color (myLastPicked, mySelectionColor, aHiMod);
178 toUpdateViewer = Standard_True;
182 myLastinMain.Nullify();
183 myLastPicked.Nullify();
188 if (theToRedrawOnUpdate)
190 theView->Viewer()->Update();
194 theView->Viewer()->Invalidate();
198 mylastmoveview = theView;
202 //=======================================================================
205 //=======================================================================
206 AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Integer theXPMin,
207 const Standard_Integer theYPMin,
208 const Standard_Integer theXPMax,
209 const Standard_Integer theYPMax,
210 const Handle(V3d_View)& theView,
211 const Standard_Boolean toUpdateViewer)
213 // all objects detected by the selector are taken, previous current objects are emptied,
214 // new objects are put...
216 if (HasOpenedContext())
218 return myLocalContexts(myCurLocalIndex)->Select (theXPMin, theYPMin,
220 theView, toUpdateViewer);
223 ClearCurrents (Standard_False);
225 Handle(StdSelect_ViewerSelector3d) aSelector;
227 if (theView->Viewer() == myMainVwr)
229 aSelector = myMainSel;
230 myWasLastMain = Standard_True;
233 aSelector->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
234 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
236 AIS_MapOfInteractive anObjectsToSelect;
237 for (aSelector->Init(); aSelector->More(); aSelector->Next())
239 Handle(AIS_InteractiveObject) anObj =
240 Handle(AIS_InteractiveObject)::DownCast (aSelector->Picked()->Selectable());
243 anObjectsToSelect.Add (anObj);
247 AIS_MapIteratorOfMapOfInteractive anIt (anObjectsToSelect);
248 for ( ; anIt.More(); anIt.Next())
250 AIS_Selection::Select (anIt.Key());
251 anIt.Key()->State (1);
254 HilightCurrents (toUpdateViewer);
256 Standard_Integer aSelNum = NbCurrents();
258 return (aSelNum == 0) ? AIS_SOP_NothingSelected
259 : (aSelNum == 1) ? AIS_SOP_OneSelected
260 : AIS_SOP_SeveralSelected;
264 //=======================================================================
266 //purpose : Selection by polyline
267 //=======================================================================
268 AIS_StatusOfPick AIS_InteractiveContext::Select (const TColgp_Array1OfPnt2d& thePolyline,
269 const Handle(V3d_View)& theView,
270 const Standard_Boolean toUpdateViewer)
272 // all objects detected by the selector are taken, previous current objects are emptied,
273 // new objects are put...
275 if (HasOpenedContext())
277 return myLocalContexts(myCurLocalIndex)->Select (thePolyline, theView, toUpdateViewer);
280 ClearCurrents (Standard_False);
282 Handle(StdSelect_ViewerSelector3d) aSelector;
284 if (theView->Viewer() == myMainVwr)
286 aSelector = myMainSel;
287 myWasLastMain = Standard_True;
290 aSelector->Pick (thePolyline, theView);
291 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
293 AIS_MapOfInteractive anObjectsToSelect;
294 for (aSelector->Init(); aSelector->More(); aSelector->Next())
296 Handle(AIS_InteractiveObject) anObj =
297 Handle( AIS_InteractiveObject )::DownCast (aSelector->Picked()->Selectable());
300 anObjectsToSelect.Add (anObj);
304 AIS_MapIteratorOfMapOfInteractive anIt (anObjectsToSelect);
305 for ( ; anIt.More(); anIt.Next())
307 AIS_Selection::Select (anIt.Key());
308 anIt.Key()->State (1);
311 HilightCurrents (toUpdateViewer);
313 Standard_Integer aSelNum = NbCurrents();
315 return (aSelNum == 0) ? AIS_SOP_NothingSelected
316 : (aSelNum == 1) ? AIS_SOP_OneSelected
317 : AIS_SOP_SeveralSelected;
321 //=======================================================================
324 //=======================================================================
325 AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean toUpdateViewer)
327 if (HasOpenedContext())
331 return myLocalContexts(myCurLocalIndex)->Select (toUpdateViewer);
335 myLocalContexts(myCurLocalIndex)->SetSelected (myLastPicked, toUpdateViewer);
336 return AIS_SOP_OneSelected;
340 if (myWasLastMain && !myLastinMain.IsNull())
342 if(myLastinMain->State() != 1)
344 SetCurrentObject (myLastinMain,Standard_False);
347 UpdateCurrentViewer();
353 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
354 Handle(AIS_Selection) aSelection = AIS_Selection::CurrentSelection();
355 Handle(AIS_InteractiveObject) anObj;
356 for (aSelection->Init(); aSelection->More(); aSelection->Next())
358 anObj = Handle(AIS_InteractiveObject)::DownCast (aSelection->Value());
360 Unhilight (anObj,Standard_False);
361 if (myObjects.IsBound (anObj) && myObjects(anObj)->IsSubIntensityOn())
363 HilightWithColor (anObj, mySubIntensity, Standard_False);
367 AIS_Selection::Select();
368 if (toUpdateViewer && myWasLastMain)
370 UpdateCurrentViewer();
374 Standard_Integer aSelNum = NbCurrents();
376 return (aSelNum == 0) ? AIS_SOP_NothingSelected
377 : (aSelNum == 1) ? AIS_SOP_OneSelected
378 : AIS_SOP_SeveralSelected;
381 //=======================================================================
382 //function : ShiftSelect
384 //=======================================================================
385 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Boolean toUpdateViewer)
387 if (HasOpenedContext())
391 return myLocalContexts (myCurLocalIndex)->ShiftSelect (toUpdateViewer);
395 myLocalContexts (myCurLocalIndex)->AddOrRemoveSelected (myLastPicked, toUpdateViewer);
397 Standard_Integer aSelNum = NbSelected();
398 return (aSelNum == 0) ? AIS_SOP_NothingSelected
399 : (aSelNum == 1) ? AIS_SOP_OneSelected
400 : AIS_SOP_SeveralSelected;
404 if (myWasLastMain && !myLastinMain.IsNull())
406 AddOrRemoveCurrentObject (myLastinMain, toUpdateViewer);
409 Standard_Integer aCurrentSelNum = NbCurrents();
411 return (aCurrentSelNum == 0) ? AIS_SOP_NothingSelected
412 : (aCurrentSelNum == 1) ? AIS_SOP_OneSelected
413 : AIS_SOP_SeveralSelected;
416 //=======================================================================
417 //function : ShiftSelect
419 //=======================================================================
420 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Integer theXPMin,
421 const Standard_Integer theYPMin,
422 const Standard_Integer theXPMax,
423 const Standard_Integer theYPMax,
424 const Handle(V3d_View)& theView,
425 const Standard_Boolean toUpdateViewer)
427 if (HasOpenedContext())
429 return myLocalContexts(myCurLocalIndex)->ShiftSelect (theXPMin, theYPMin, theXPMax, theYPMax,
430 theView, toUpdateViewer);
433 UnhilightCurrents (Standard_False);
435 Handle(StdSelect_ViewerSelector3d) aSelector;
436 if (theView->Viewer() == myMainVwr)
438 aSelector = myMainSel;
439 myWasLastMain = Standard_True;
443 return AIS_SOP_NothingSelected;
446 aSelector->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
447 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
448 for (aSelector->Init(); aSelector->More(); aSelector->Next())
450 Handle(AIS_InteractiveObject) anObjToSelect = Handle(AIS_InteractiveObject)::DownCast (aSelector->Picked()->Selectable());
451 if (!anObjToSelect.IsNull())
453 AIS_SelectStatus aSelStatus = AIS_Selection::Select (anObjToSelect);
454 Standard_Integer aState = (aSelStatus == AIS_SS_Added) ? 1 : 0;
455 anObjToSelect->State (aState);
459 HilightCurrents (toUpdateViewer);
461 Standard_Integer aSelNum = NbCurrents();
463 return (aSelNum == 0) ? AIS_SOP_NothingSelected
464 : (aSelNum == 1) ? AIS_SOP_OneSelected
465 : AIS_SOP_SeveralSelected;
469 //=======================================================================
470 //function : ShiftSelect
472 //=======================================================================
473 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline,
474 const Handle(V3d_View)& theView,
475 const Standard_Boolean toUpdateViewer)
477 if (HasOpenedContext())
479 return myLocalContexts(myCurLocalIndex)->ShiftSelect (thePolyline, theView, toUpdateViewer);
482 UnhilightCurrents (Standard_False);
484 Handle(StdSelect_ViewerSelector3d) aSelector;
486 if (theView->Viewer() == myMainVwr)
488 aSelector= myMainSel;
489 myWasLastMain = Standard_True;
493 return AIS_SOP_NothingSelected;
496 aSelector->Pick (thePolyline, theView);
498 AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
499 for (aSelector->Init(); aSelector->More(); aSelector->Next())
501 Handle(AIS_InteractiveObject) anObjToSelect = Handle(AIS_InteractiveObject)::DownCast (aSelector->Picked()->Selectable());
502 if (!anObjToSelect.IsNull())
504 AIS_SelectStatus aSelStatus = AIS_Selection::Select (anObjToSelect);
505 Standard_Integer aState = (aSelStatus == AIS_SS_Added ) ? 1 : 0;
506 anObjToSelect->State (aState);
510 HilightCurrents (toUpdateViewer);
512 Standard_Integer aSelNum = NbCurrents();
514 return (aSelNum == 0) ? AIS_SOP_NothingSelected
515 : (aSelNum == 1) ? AIS_SOP_OneSelected
516 : AIS_SOP_SeveralSelected;
519 //=======================================================================
520 //function : SetCurrentObject
522 //=======================================================================
523 void AIS_InteractiveContext::SetCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
524 const Standard_Boolean updateviewer)
526 // single case processing...
527 if(NbCurrents()==1 && anIObj->State()==1){
528 Quantity_NameOfColor HiCol;
529 Standard_Boolean HasHiCol;
530 if(IsHilighted(anIObj,HasHiCol,HiCol)){
531 if(HasHiCol && HiCol!= mySelectionColor) {
532 HilightWithColor(anIObj,mySelectionColor,updateviewer);
540 if(!HasOpenedContext()) {
541 if(anIObj.IsNull()) return;
542 if(!myObjects.IsBound(anIObj))
543 Display(anIObj,Standard_False);
545 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
546 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
547 Handle(Standard_Transient) TR;
548 Handle(AIS_InteractiveObject) IO;
550 while (sel->More()) {
552 IO = Handle(AIS_InteractiveObject)::DownCast (TR);
553 Unhilight(IO,Standard_False);
558 // added to avoid untimely viewer update...
559 AIS_Selection::ClearAndSelect(anIObj);
561 Quantity_NameOfColor HiCol;
562 Standard_Boolean HasHiCol;
563 if(IsHilighted(anIObj,HasHiCol,HiCol)){
564 if(HasHiCol && HiCol!= mySelectionColor) {
565 HilightWithColor(anIObj,mySelectionColor,Standard_False);
569 HilightWithColor(anIObj,mySelectionColor,Standard_False);
572 UpdateCurrentViewer();
576 cout<<"Nothing Done : Opened Local Context"<<endl;
581 //=======================================================================
582 //function : AddOrRemoveCurrentObject
584 //=======================================================================
586 void AIS_InteractiveContext::
587 AddOrRemoveCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
588 const Standard_Boolean updateviewer)
590 if(anIObj.IsNull()) return;
591 //OCC5682 to remove an object from neutral point even if Local Context is opened (Remove method)
592 if(!HasOpenedContext() /*OCC5682*/|| myObjects.IsBound(anIObj)) {
594 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
595 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
597 AIS_SelectStatus SelStat = AIS_Selection::Select(anIObj);
599 Standard_Integer mod = (SelStat==AIS_SS_Added) ? 1 : 0;
602 HilightWithColor(anIObj,mySelectionColor,Standard_False);
604 Unhilight(anIObj,Standard_False);
608 UpdateCurrentViewer();
612 cout<<"Nothing Done : Opened Local Context"<<endl;
616 //=======================================================================
617 //function : UpdateCurrent
619 //=======================================================================
621 void AIS_InteractiveContext::UpdateCurrent()
626 //=======================================================================
627 //function : IsCurrent
629 //=======================================================================
631 Standard_Boolean AIS_InteractiveContext::IsCurrent(const Handle(AIS_InteractiveObject)& anIObj) const
634 if (anIObj.IsNull()) return Standard_False;
635 return (anIObj->State()==1);
637 // Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
639 // while (sel->More()) {
640 // if (anIObj == sel->Value()) return Standard_True;
643 // return Standard_False;
647 //=======================================================================
648 //function : InitCurrent
650 //=======================================================================
652 void AIS_InteractiveContext::InitCurrent()
654 AIS_Selection::Selection(myCurrentName.ToCString())->Init();
657 //=======================================================================
658 //function : MoreCurrent
660 //=======================================================================
662 Standard_Boolean AIS_InteractiveContext::MoreCurrent() const
664 return AIS_Selection::Selection(myCurrentName.ToCString())->More();
668 //=======================================================================
669 //function : NextCurrent
671 //=======================================================================
673 void AIS_InteractiveContext::NextCurrent()
675 AIS_Selection::Selection(myCurrentName.ToCString())->Next();
678 //=======================================================================
681 //=======================================================================
683 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Current() const
685 Handle(Standard_Transient) TR = AIS_Selection::Selection(myCurrentName.ToCString())->Value();
686 Handle(AIS_InteractiveObject) IO = Handle(AIS_InteractiveObject)::DownCast (TR);
690 //=======================================================================
691 //function : FirstCurrentObject
693 //=======================================================================
694 Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstCurrentObject()
696 Handle(AIS_InteractiveObject) IO ;
704 //=======================================================================
705 //function : NbCurrents
707 //=======================================================================
708 Standard_Integer AIS_InteractiveContext::NbCurrents()
710 Standard_Integer i(0);
711 for(InitCurrent();MoreCurrent();NextCurrent())
716 //=======================================================================
717 //function : HilightCurrents
719 //=======================================================================
720 void AIS_InteractiveContext::HilightCurrents(const Standard_Boolean updateviewer)
722 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
723 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
724 Handle(Standard_Transient) TR;
725 Handle(AIS_InteractiveObject) IO;
727 while (sel->More()) {
729 IO = Handle(AIS_InteractiveObject)::DownCast (TR);
730 HilightWithColor(IO,mySelectionColor,Standard_False);
734 UpdateCurrentViewer();
737 //=======================================================================
738 //function : UnhilightCurrents
740 //=======================================================================
742 void AIS_InteractiveContext::UnhilightCurrents(const Standard_Boolean updateviewer)
744 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
745 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
746 Handle(Standard_Transient) TR;
747 Handle(AIS_InteractiveObject) IO;
749 while (sel->More()) {
751 IO = Handle(AIS_InteractiveObject)::DownCast (TR);
752 Unhilight(IO,Standard_False);
756 UpdateCurrentViewer();
759 //=======================================================================
760 //function : ClearCurrents
762 //=======================================================================
764 void AIS_InteractiveContext::ClearCurrents(const Standard_Boolean updateviewer)
766 if(NbCurrents()==0) return;
767 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
768 Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
769 Handle(Standard_Transient) Tr;
770 Handle(AIS_InteractiveObject) IO;
771 for(S->Init();S->More();S->Next()){
773 IO = Handle(AIS_InteractiveObject)::DownCast (Tr);
775 Unhilight(IO,Standard_False);
777 AIS_Selection::Select();
779 UpdateCurrentViewer();
783 //=======================================================================
784 //function : HilightSelected
786 //=======================================================================
788 void AIS_InteractiveContext::HilightSelected(const Standard_Boolean updateviewer)
790 if(!HasOpenedContext()){
791 AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
792 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
793 Handle(Standard_Transient) TR;
794 Handle(AIS_InteractiveObject) IO;
796 while (sel->More()) {
798 IO = Handle(AIS_InteractiveObject)::DownCast (TR);
799 HilightWithColor(IO,mySelectionColor,Standard_False);
805 myLocalContexts(myCurLocalIndex)->HilightPicked(updateviewer);
808 UpdateCurrentViewer();
811 //=======================================================================
812 //function : UnhilightSelected
814 //=======================================================================
816 void AIS_InteractiveContext::UnhilightSelected(const Standard_Boolean updateviewer)
818 if(!HasOpenedContext()){
819 AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
820 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
821 Handle(Standard_Transient) TR;
822 Handle(AIS_InteractiveObject) IO;
824 while (sel->More()) {
826 IO = Handle(AIS_InteractiveObject)::DownCast (TR);
827 Unhilight(IO,Standard_False);
831 UpdateCurrentViewer();
835 myLocalContexts(myCurLocalIndex)->UnhilightPicked(updateviewer);
840 //=======================================================================
841 //function : ClearSelected
843 //=======================================================================
845 void AIS_InteractiveContext::ClearSelected(const Standard_Boolean updateviewer)
847 if(!HasOpenedContext())
848 ClearCurrents(updateviewer);
850 myLocalContexts(myCurLocalIndex)->ClearSelected(updateviewer);
855 //=======================================================================
856 //function : SetSelectedCurrent
858 //=======================================================================
860 void AIS_InteractiveContext::SetSelectedCurrent()
865 cout<<"Not Yet Implemented"<<endl;
869 //=======================================================================
870 //function : UpdateSelection
872 //=======================================================================
874 void AIS_InteractiveContext::UpdateSelected(const Standard_Boolean updateviewer)
876 if(!HasOpenedContext()) {
882 myLocalContexts(myCurLocalIndex)->UpdateSelected(updateviewer);
885 //=======================================================================
886 //function : SetCurrentObject
888 //=======================================================================
889 void AIS_InteractiveContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,const Standard_Boolean updateviewer)
891 if(!HasOpenedContext())
892 SetCurrentObject(anIObj,updateviewer);
894 myLocalContexts(myCurLocalIndex)->SetSelected(anIObj,updateviewer);
897 //=======================================================================
898 //function : AddOrRemoveSelected
900 //=======================================================================
902 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj,
903 const Standard_Boolean updateviewer)
905 if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
906 if(!HasOpenedContext())
907 AddOrRemoveCurrentObject(anIObj,updateviewer);
909 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(anIObj,updateviewer);
912 //=======================================================================
913 //function : AddOrRemoveSelected
915 //=======================================================================
917 void AIS_InteractiveContext::AddOrRemoveSelected(const TopoDS_Shape& aShap,
918 const Standard_Boolean updateviewer)
920 if(!HasOpenedContext()) {
922 cout<<" Attempt to remove a selected shape with no opened local context"<<endl;
927 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(aShap,updateviewer);
928 if(updateviewer) UpdateCurrentViewer();
931 //=======================================================================
932 //function : AddOrRemoveSelected
934 //=======================================================================
936 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(SelectMgr_EntityOwner)& Own,
937 const Standard_Boolean updateviewer)
939 if(!HasOpenedContext()) {
941 cout<<" Attempt to remove a selected ownr with no opened local context"<<endl;
946 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(Own,Standard_False);
947 if(updateviewer) UpdateCurrentViewer();
953 //=======================================================================
954 //function : IsSelected
956 //=======================================================================
958 Standard_Boolean AIS_InteractiveContext::
959 IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const
961 if (anIObj.IsNull()) return Standard_False;
963 if(!HasOpenedContext())
964 return (anIObj->State()==1);
966 return myLocalContexts(myCurLocalIndex)->IsSelected(anIObj);
970 //=======================================================================
971 //function : InitSelected
973 //=======================================================================
975 void AIS_InteractiveContext::InitSelected()
977 if(!HasOpenedContext())
978 AIS_Selection::Selection(myCurrentName.ToCString())->Init();
980 myLocalContexts(myCurLocalIndex)->InitSelected();
983 //=======================================================================
984 //function : MoreSelected
986 //=======================================================================
988 Standard_Boolean AIS_InteractiveContext::MoreSelected() const
990 if(!HasOpenedContext())
991 return AIS_Selection::Selection(myCurrentName.ToCString())->More();
992 return myLocalContexts(myCurLocalIndex)->MoreSelected();
995 //=======================================================================
996 //function : NextSelected
998 //=======================================================================
1000 void AIS_InteractiveContext::NextSelected()
1002 if(!HasOpenedContext())
1003 AIS_Selection::Selection(myCurrentName.ToCString())->Next();
1005 myLocalContexts(myCurLocalIndex)->NextSelected();
1008 //=======================================================================
1009 //function : HasSelectedShape
1011 //=======================================================================
1013 Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
1015 if(!HasOpenedContext()) {
1016 Handle(AIS_Shape) shape =
1017 Handle(AIS_Shape)::DownCast(SelectedInteractive());
1018 if( !shape.IsNull() ) return Standard_True;
1019 return Standard_False;
1021 return myLocalContexts(myCurLocalIndex)->HasSelectedShape();
1024 //=======================================================================
1025 //function : SelectedShape
1027 //=======================================================================
1029 TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
1031 if (!HasOpenedContext())
1033 TopoDS_Shape aResShape;
1034 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (SelectedInteractive());
1035 if (!aShape.IsNull())
1037 TopLoc_Location aLocTrsf = SelectedInteractive()->Transformation().Form() == gp_Identity ?
1038 TopLoc_Location() : TopLoc_Location (SelectedInteractive()->Transformation());
1039 aResShape = aShape->Shape().Located (aLocTrsf * aShape->Shape().Location());
1046 return myLocalContexts (myCurLocalIndex)->SelectedShape();
1050 //=======================================================================
1051 //function : Interactive
1053 //=======================================================================
1055 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Interactive() const
1057 return SelectedInteractive();
1060 Handle(AIS_InteractiveObject) AIS_InteractiveContext::SelectedInteractive() const
1062 if(!HasOpenedContext()){
1063 if (AIS_Selection::Selection(myCurrentName.ToCString())->Extent() == 0)
1065 Handle(Standard_Transient) TR =AIS_Selection::Selection(myCurrentName.ToCString())->Value();
1066 Handle(AIS_InteractiveObject) IO = Handle(AIS_InteractiveObject)::DownCast (TR);
1069 return myLocalContexts(myCurLocalIndex)->SelectedInteractive();
1072 //=======================================================================
1073 //function : Interactive
1075 //=======================================================================
1077 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const
1079 if(!HasOpenedContext()){
1080 Handle(SelectMgr_EntityOwner) Ownr;
1083 return myLocalContexts(myCurLocalIndex)->SelectedOwner();
1087 //=======================================================================
1088 //function : EntityOwners
1090 //=======================================================================
1091 void AIS_InteractiveContext::EntityOwners(Handle(SelectMgr_IndexedMapOfOwner)& theOwners,
1092 const Handle(AIS_InteractiveObject)& theIObj,
1093 const Standard_Integer theMode) const
1095 if ( theIObj.IsNull() )
1098 TColStd_ListOfInteger aModes;
1099 if ( theMode == -1 )
1100 ActivatedModes( theIObj, aModes );
1102 aModes.Append( theMode );
1104 if (theOwners.IsNull())
1105 theOwners = new SelectMgr_IndexedMapOfOwner();
1107 TColStd_ListIteratorOfListOfInteger anItr( aModes );
1108 for (; anItr.More(); anItr.Next() )
1110 int aMode = anItr.Value();
1111 if ( !theIObj->HasSelection( aMode ) )
1114 Handle(SelectMgr_Selection) aSel = theIObj->Selection(aMode);
1116 for ( aSel->Init(); aSel->More(); aSel->Next() )
1118 Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive()->BaseSensitive();
1119 if ( aEntity.IsNull() )
1122 Handle(SelectMgr_EntityOwner) aOwner =
1123 Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId());
1124 if ( !aOwner.IsNull() )
1125 theOwners->Add( aOwner );
1130 Standard_Integer AIS_InteractiveContext::NbSelected()
1132 Standard_Integer i(0);
1133 for(InitSelected();MoreSelected();NextSelected())
1138 //=======================================================================
1139 //function : HasApplicative
1141 //=======================================================================
1143 Standard_Boolean AIS_InteractiveContext::HasApplicative() const
1145 return Interactive()->HasOwner();
1148 //=======================================================================
1149 //function : Applicative
1151 //=======================================================================
1153 Handle(Standard_Transient) AIS_InteractiveContext::Applicative() const
1155 return Interactive()->GetOwner();
1160 //==================================================
1163 //==================================================
1164 Standard_Boolean AIS_InteractiveContext::HasDetected() const
1166 if(HasOpenedContext())
1167 return myLocalContexts(myCurLocalIndex)->HasDetected();
1169 return !myLastPicked.IsNull();
1172 //=======================================================================
1173 //function : HasDetectedShape
1175 //=======================================================================
1177 Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
1179 if(HasOpenedContext())
1180 return myLocalContexts(myCurLocalIndex)->HasDetectedShape();
1181 return Standard_False;
1184 //=======================================================================
1185 //function : DetectedShape
1187 //=======================================================================
1190 AIS_InteractiveContext::DetectedShape() const
1192 return myLocalContexts(myCurLocalIndex)->DetectedShape();
1195 //=======================================================================
1196 //function : DetectedInteractive
1198 //=======================================================================
1200 Handle(AIS_InteractiveObject)
1201 AIS_InteractiveContext::DetectedInteractive() const
1203 if(HasOpenedContext())
1204 return myLocalContexts(myCurLocalIndex)->DetectedInteractive();
1205 return myLastPicked;
1209 Standard_Boolean AIS_InteractiveContext::HasNextDetected() const
1211 if(!HasOpenedContext())
1212 return Standard_False; // temporaire
1214 return myLocalContexts(myCurLocalIndex)->HasNextDetected();
1219 //=======================================================================
1220 //function : DetectedOwner
1222 //=======================================================================
1223 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedOwner() const
1225 if(HasOpenedContext())
1226 return myLocalContexts(myCurLocalIndex)->DetectedOwner();
1227 Handle(SelectMgr_EntityOwner) Ownr;
1232 //=======================================================================
1233 //function : HilightNextDetected
1235 //=======================================================================
1236 Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView,
1237 const Standard_Boolean theToRedrawImmediate)
1239 return HasOpenedContext()
1240 ? myLocalContexts (myCurLocalIndex)->HilightNextDetected (theView, theToRedrawImmediate)
1245 //=======================================================================
1246 //function : HilightNextDetected
1248 //=======================================================================
1249 Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1250 const Standard_Boolean theToRedrawImmediate)
1252 return HasOpenedContext()
1253 ? myLocalContexts (myCurLocalIndex)->HilightPreviousDetected (theView, theToRedrawImmediate)
1258 //=======================================================================
1259 //function : InitDetected
1261 //=======================================================================
1262 void AIS_InteractiveContext::InitDetected()
1264 if (HasOpenedContext())
1266 myLocalContexts(myCurLocalIndex)->InitDetected();
1270 if(myAISDetectedSeq.Length() != 0)
1272 myAISCurDetected = 1;
1276 //=======================================================================
1277 //function : MoreDetected
1279 //=======================================================================
1280 Standard_Boolean AIS_InteractiveContext::MoreDetected() const
1282 if (HasOpenedContext())
1284 return myLocalContexts(myCurLocalIndex)->MoreDetected();
1287 return (myAISCurDetected > 0 && myAISCurDetected <= myAISDetectedSeq.Length()) ?
1288 Standard_True : Standard_False;
1291 //=======================================================================
1292 //function : NextDetected
1294 //=======================================================================
1295 void AIS_InteractiveContext::NextDetected()
1297 if(HasOpenedContext())
1299 myLocalContexts(myCurLocalIndex)->NextDetected();
1306 //=======================================================================
1307 //function : DetectedCurrentShape
1309 //=======================================================================
1310 const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
1312 if (HasOpenedContext())
1314 return myLocalContexts(myCurLocalIndex)->DetectedCurrentShape();
1317 static TopoDS_Shape aDummyShape;
1319 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
1321 if (aCurrentShape.IsNull())
1326 return aCurrentShape->Shape();
1329 //=======================================================================
1330 //function : DetectedCurrentObject
1332 //=======================================================================
1333 Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const
1335 if (HasOpenedContext())
1337 return myLocalContexts(myCurLocalIndex)->DetectedCurrentObject();
1340 return MoreDetected() ? myAISDetectedSeq(myAISCurDetected) : NULL;