1 // Created on: 1997-01-29
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #define UKI60826 //GG_161199 Use the requested selection color instead of default
19 #define IMP280200 //GG Don't returns a NULL shape in SelectedShape()
20 // method when the current selected is a shape !
22 #define BUC60814 //GG_300101 Idem UKI60826
24 #define OCC138 //VTN Avoding infinit loop in AddOrRemoveCurrentObject method.
28 #include <AIS_InteractiveContext.jxx>
29 #include <SelectMgr_EntityOwner.hxx>
30 #include <AIS_Selection.hxx>
31 #include <AIS_StatusOfDetection.hxx>
32 #include <AIS_StatusOfPick.hxx>
34 #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
35 #include <AIS_LocalContext.hxx>
36 #include <AIS_GlobalStatus.hxx>
37 #include <AIS_Shape.hxx>
39 #include <Aspect_Grid.hxx>
41 #include <V3d_Light.hxx>
42 #include <V3d_PositionalLight.hxx>
43 #include <V3d_SpotLight.hxx>
44 #include <V3d_DirectionalLight.hxx>
45 #include <V3d_AmbientLight.hxx>
47 #include <TColStd_ListIteratorOfListOfInteger.hxx>
48 #include <SelectMgr_Selection.hxx>
49 #include <SelectBasics_SensitiveEntity.hxx>
51 #include <Prs3d_Presentation.hxx>
54 #include <AIS_MapOfInteractive.hxx>
55 #include <AIS_MapIteratorOfMapOfInteractive.hxx>
60 static void InfoOnLight(const Handle(V3d_View) aView)
62 Standard_Real V1=0.,V2=0.,V3=0.;
63 Standard_Integer IndexOfLit(0);
65 static Standard_Boolean FirstTime (Standard_True);
68 FirstTime = Standard_False;
69 for (aView->InitActiveLights();aView->MoreActiveLights();aView->NextActiveLights()){
71 cout<<"lumiere no "<<IndexOfLit<<"\n************\n\t";
72 Handle(V3d_Light) Li = aView->ActiveLight();
73 Quantity_NameOfColor Col;
75 cout<<"Color :"<<Standard_Integer(Col)<<"\n\t"<<endl;
82 // Handle(V3d_AmbientLight)::DownCast(Li)->DisplayPosition(V1,V2,V3);
83 cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl;
88 cout<<" DIRECTIONAL\n\t";
89 Handle(V3d_DirectionalLight)::DownCast(Li)->DisplayPosition(V1,V2,V3);
90 cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl;
91 Handle(V3d_DirectionalLight)::DownCast(Li)->Direction(V1,V2,V3);
92 cout<<"Direction : V1 = "<<V1<<" V2 = "<<V2<<" V3 = "<<V3<<endl;
98 cout<<" POSITIONAL\n\t";
99 Handle(V3d_PositionalLight)::DownCast(Li)->Position(V1,V2,V3);
100 cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl;
101 Handle(V3d_PositionalLight)::DownCast(Li)->Target(V1,V2,V3);
102 cout<<"Target : x1 = "<<V1<<" x2 = "<<V2<<" x3 = "<<V3<<endl;
108 cout<<" DIRECTIONAL\n\t";
109 Handle(V3d_SpotLight)::DownCast(Li)->Position(V1,V2,V3);
110 cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl;
111 Handle(V3d_SpotLight)::DownCast(Li)->Direction(V1,V2,V3);
112 cout<<"Direction : V1 = "<<V1<<" V2 = "<<V2<<" V3 = "<<V3<<endl;
113 Handle(V3d_PositionalLight)::DownCast(Li)->Target(V1,V2,V3);
114 cout<<"Target : x1 = "<<V1<<" x2 = "<<V2<<" x3 = "<<V3<<endl;
115 cout<<"\tAngle :"<<Handle(V3d_SpotLight)::DownCast(Li)->Angle()<<endl;
125 //=======================================================================
128 //=======================================================================
129 AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const Standard_Integer theXPix,
130 const Standard_Integer theYPix,
131 const Handle(V3d_View)& theView,
132 const Standard_Boolean theToRedrawOnUpdate)
134 if (HasOpenedContext())
136 myWasLastMain = Standard_True;
137 return myLocalContexts (myCurLocalIndex)->MoveTo (theXPix, theYPix, theView, theToRedrawOnUpdate);
140 myAISCurDetected = 0;
141 myAISDetectedSeq.Clear();
143 if (theView->Viewer() != myMainVwr)
145 return AIS_SOD_Error;
149 myLastPicked = myLastinMain;
150 myWasLastMain = Standard_True;
151 AIS_StatusOfDetection aStatus = AIS_SOD_Nothing;
152 Standard_Boolean toUpdateViewer = Standard_False;
155 myMainSel->Pick (theXPix, theYPix, theView);
157 // filling of myAISDetectedSeq sequence storing information about detected AIS objects
158 // (the objects must be AIS_Shapes)
159 const Standard_Integer aDetectedNb = myMainSel->NbPicked();
160 for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
162 Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aDetIter);
164 || !myFilters->IsOk (anOwner))
169 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
170 if (!Handle(AIS_Shape)::DownCast (anObj).IsNull())
172 myAISDetectedSeq.Append (anObj);
177 if (myMainSel->More())
179 // does nothing if previously detected object is equal to the current one
180 if (myMainSel->OnePicked()->Selectable() == myLastPicked)
182 return AIS_SOD_OnlyOneDetected;
185 // Previously detected object is unhilighted if it is not selected or hilighted
186 // with selection color if it is selected. Such highlighting with selection color
187 // is needed only if myToHilightSelected flag is true. In this case previously detected
188 // object has been already highlighted with myHilightColor during previous MoveTo()
189 // method call. As result it is necessary to rehighligt it with mySelectionColor.
190 if (!myLastPicked.IsNull())
192 const Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
193 if (myLastPicked->State() != 1)
195 myMainPM->Unhighlight (myLastPicked, aHiMod);
196 toUpdateViewer = Standard_True;
198 else if (myToHilightSelected)
200 myMainPM->Color (myLastPicked, mySelectionColor, aHiMod);
201 toUpdateViewer = Standard_True;
205 // initialize myLastPicked field with currently detected object
206 myLastPicked = Handle(AIS_InteractiveObject)::DownCast (myMainSel->OnePicked()->Selectable());
207 myLastinMain = myLastPicked;
209 // highlight detected object if it is not selected or myToHilightSelected flag is true
210 if (!myLastPicked.IsNull())
212 if (myLastPicked->State() != 1 || myToHilightSelected)
214 const Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
215 myMainPM->Color (myLastPicked, myHilightColor, aHiMod);
216 toUpdateViewer = Standard_True;
219 if (myLastPicked->State() == 1)
221 aStatus = AIS_SOD_Selected;
227 // previously detected object is unhilighted if it is not selected or hilighted
228 // with selection color if it is selected
229 aStatus = AIS_SOD_Nothing;
230 if (!myLastPicked.IsNull())
232 Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
233 if (myLastPicked->State() != 1)
235 myMainPM->Unhighlight (myLastPicked, aHiMod);
236 toUpdateViewer = Standard_True;
238 else if (myToHilightSelected)
240 myMainPM->Color (myLastPicked, mySelectionColor, aHiMod);
241 toUpdateViewer = Standard_True;
245 myLastinMain.Nullify();
250 if (theToRedrawOnUpdate)
252 theView->Viewer()->Update();
256 theView->Viewer()->Invalidate();
260 myLastPicked.Nullify();
261 mylastmoveview = theView;
265 //=======================================================================
268 //=======================================================================
270 AIS_StatusOfPick AIS_InteractiveContext::Select(const Standard_Integer XPMin,
271 const Standard_Integer YPMin,
272 const Standard_Integer XPMax,
273 const Standard_Integer YPMax,
274 const Handle(V3d_View)& aView,
275 const Standard_Boolean updateviewer)
277 // all objects detected by the selector are taken, previous current objects are emptied,
278 // new objects are put...
280 if(HasOpenedContext())
281 return myLocalContexts(myCurLocalIndex)->Select(XPMin,YPMin,XPMax,YPMax,aView,updateviewer);
283 ClearCurrents(Standard_False);
284 // OCC11904 - local variables made non-static - it looks and works better like this
285 Handle(StdSelect_ViewerSelector3d) selector;
287 if(aView->Viewer()== myMainVwr) {
289 myWasLastMain = Standard_True;}
291 selector->Pick(XPMin,YPMin,XPMax,YPMax,aView);
292 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
295 AIS_MapOfInteractive theSelectedObj;
296 for( selector->Init(); selector->More(); selector->Next() )
298 Handle( AIS_InteractiveObject ) anObj =
299 Handle( AIS_InteractiveObject )::DownCast( selector->Picked()->Selectable() );
300 if( !anObj.IsNull() )
301 theSelectedObj.Add( anObj );
303 AIS_MapIteratorOfMapOfInteractive anIt( theSelectedObj );
304 for( ; anIt.More(); anIt.Next() )
306 AIS_Selection::Select( anIt.Key() );
307 anIt.Key()->State(1);
310 for(selector->Init();selector->More();selector->Next()){
311 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
314 AIS_Selection::Select(SO);
315 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
317 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
318 AIS_Selection::Select(SO);
324 HilightCurrents(updateviewer);
326 Standard_Integer NS = NbCurrents();
327 if(NS==0) return AIS_SOP_NothingSelected;
328 if(NS==1) return AIS_SOP_OneSelected;
329 return AIS_SOP_SeveralSelected;
333 //=======================================================================
335 //purpose : Selection by polyline
336 //=======================================================================
338 AIS_StatusOfPick AIS_InteractiveContext::Select(const TColgp_Array1OfPnt2d& aPolyline,
339 const Handle(V3d_View)& aView,
340 const Standard_Boolean updateviewer)
342 // all objects detected by the selector are taken, previous current objects are emptied,
343 // new objects are put...
345 if(HasOpenedContext())
346 return myLocalContexts(myCurLocalIndex)->Select(aPolyline,aView,updateviewer);
348 ClearCurrents(Standard_False);
349 // OCC11904 - local variables made non-static - it looks and works better like this
350 Handle(StdSelect_ViewerSelector3d) selector;
352 if(aView->Viewer()== myMainVwr) {
354 myWasLastMain = Standard_True;}
356 selector->Pick(aPolyline,aView);
357 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
361 AIS_MapOfInteractive theSelectedObj;
362 for( selector->Init(); selector->More(); selector->Next() )
364 Handle( AIS_InteractiveObject ) anObj =
365 Handle( AIS_InteractiveObject )::DownCast( selector->Picked()->Selectable() );
366 if( !anObj.IsNull() )
367 theSelectedObj.Add( anObj );
369 AIS_MapIteratorOfMapOfInteractive anIt( theSelectedObj );
370 for( ; anIt.More(); anIt.Next() )
372 AIS_Selection::Select( anIt.Key() );
373 anIt.Key()->State(1);
376 for(selector->Init();selector->More();selector->Next()){
377 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
380 AIS_Selection::Select(SO);
381 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
383 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
384 AIS_Selection::Select(SO);
389 HilightCurrents(updateviewer);
391 Standard_Integer NS = NbCurrents();
392 if(NS==0) return AIS_SOP_NothingSelected;
393 if(NS==1) return AIS_SOP_OneSelected;
394 return AIS_SOP_SeveralSelected;
398 //=======================================================================
401 //=======================================================================
403 AIS_StatusOfPick AIS_InteractiveContext::Select(const Standard_Boolean updateviewer)
405 if(HasOpenedContext()){
407 return myLocalContexts(myCurLocalIndex)->Select(updateviewer);
410 myLocalContexts(myCurLocalIndex)->SetSelected(myLastPicked,updateviewer);
411 return AIS_SOP_OneSelected;
414 // AIS_StatusOfPick PS(AIS_SOP_NothingSelected);
415 if(myWasLastMain && !myLastinMain.IsNull()){
416 if(myLastinMain->State()!=1){
417 SetCurrentObject(myLastinMain,Standard_False);
419 UpdateCurrentViewer();}
422 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
423 Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
424 Handle(Standard_Transient) Tr;
425 Handle(AIS_InteractiveObject) IO;
427 for(S->Init();S->More();S->Next()){
429 IO = (*((Handle(AIS_InteractiveObject)*)&Tr));
431 Unhilight(IO,Standard_False);
432 if(myObjects.IsBound(IO)){ // anti-plantage-rob
433 if(myObjects(IO)->IsSubIntensityOn())
434 HilightWithColor(IO,mySubIntensity,Standard_False);
438 AIS_Selection::Select();
441 UpdateCurrentViewer();
444 Standard_Integer NS = NbCurrents();
445 if(NS==0) return AIS_SOP_NothingSelected;
446 if(NS==1) return AIS_SOP_OneSelected;
447 return AIS_SOP_SeveralSelected;
450 //=======================================================================
451 //function : ShiftSelect
453 //=======================================================================
455 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect(const Standard_Boolean updateviewer)
457 if(HasOpenedContext()){
459 return myLocalContexts(myCurLocalIndex)->ShiftSelect(updateviewer);
461 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(myLastPicked,updateviewer);
462 Standard_Integer NS =NbSelected();
463 if(NS==0) return AIS_SOP_NothingSelected;
464 if(NS==1) return AIS_SOP_OneSelected;
465 return AIS_SOP_SeveralSelected;
468 if(myWasLastMain && !myLastinMain.IsNull())
469 AddOrRemoveCurrentObject(myLastinMain,updateviewer);
471 Standard_Integer NS = NbCurrents();
472 if(NS==0) return AIS_SOP_NothingSelected;
473 if(NS==1) return AIS_SOP_OneSelected;
474 return AIS_SOP_SeveralSelected;
478 //=======================================================================
479 //function : ShiftSelect
481 //=======================================================================
483 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect(const Standard_Integer XPMin,
484 const Standard_Integer YPMin,
485 const Standard_Integer XPMax,
486 const Standard_Integer YPMax,
487 const Handle(V3d_View)& aView,
488 const Standard_Boolean updateviewer)
491 if(HasOpenedContext())
492 return myLocalContexts(myCurLocalIndex)->ShiftSelect(XPMin,YPMin,XPMax,YPMax,aView,updateviewer);
494 UnhilightCurrents(Standard_False);
495 // OCC11904 - local variables made non-static - it looks and works better like this
496 Handle(StdSelect_ViewerSelector3d) selector;
498 if(aView->Viewer()== myMainVwr) {
500 myWasLastMain = Standard_True;}
502 return AIS_SOP_NothingSelected;
504 selector->Pick(XPMin,YPMin,XPMax,YPMax,aView);
505 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
506 for(selector->Init();selector->More();selector->Next()){
507 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
509 AIS_SelectStatus SelStat = AIS_Selection::Select(SO);
510 Standard_Integer mod = (SelStat==AIS_SS_Added)?1:0;
511 (*((Handle(AIS_InteractiveObject)*)&SO))->State(mod);
515 HilightCurrents(updateviewer);
517 Standard_Integer NS =NbCurrents();
518 if(NS==0) return AIS_SOP_NothingSelected;
519 if(NS==1) return AIS_SOP_OneSelected;
520 return AIS_SOP_SeveralSelected;
524 //=======================================================================
525 //function : ShiftSelect
527 //=======================================================================
529 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect( const TColgp_Array1OfPnt2d& aPolyline,
530 const Handle(V3d_View)& aView,
531 const Standard_Boolean updateviewer )
533 if( HasOpenedContext() )
534 return myLocalContexts( myCurLocalIndex )->ShiftSelect( aPolyline, aView, updateviewer );
536 UnhilightCurrents( Standard_False );
537 // OCC11904 - local variables made non-static - it looks and works better like this
538 Handle(StdSelect_ViewerSelector3d) selector;
540 if( aView->Viewer() == myMainVwr ) {
542 myWasLastMain = Standard_True;
545 return AIS_SOP_NothingSelected;
547 selector->Pick( aPolyline, aView );
549 AIS_Selection::SetCurrentSelection( myCurrentName.ToCString() );
550 for( selector->Init(); selector->More(); selector->Next() ) {
551 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
553 AIS_SelectStatus SelStat = AIS_Selection::Select( SO );
554 Standard_Integer mod = ( SelStat == AIS_SS_Added ) ? 1 : 0;
555 (*((Handle(AIS_InteractiveObject)*)&SO))->State( mod );
559 HilightCurrents( updateviewer );
560 Standard_Integer NS = NbCurrents();
561 if( NS == 0 ) return AIS_SOP_NothingSelected;
562 if( NS == 1 ) return AIS_SOP_OneSelected;
563 return AIS_SOP_SeveralSelected;
566 //=======================================================================
567 //function : SetCurrentObject
569 //=======================================================================
571 void AIS_InteractiveContext::SetCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
572 const Standard_Boolean updateviewer)
574 // single case processing...
575 if(NbCurrents()==1 && anIObj->State()==1){
576 Quantity_NameOfColor HiCol;
577 Standard_Boolean HasHiCol;
578 if(IsHilighted(anIObj,HasHiCol,HiCol)){
579 if(HasHiCol && HiCol!= mySelectionColor) {
581 HilightWithColor(anIObj,mySelectionColor,updateviewer);
583 Hilight(anIObj,updateviewer);
592 if(!HasOpenedContext()) {
593 if(anIObj.IsNull()) return;
594 if(!myObjects.IsBound(anIObj))
595 Display(anIObj,Standard_False);
597 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
598 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
599 Handle(Standard_Transient) TR;
600 Handle(AIS_InteractiveObject) IO;
602 while (sel->More()) {
604 IO = *((Handle(AIS_InteractiveObject)*)&TR);
605 Unhilight(IO,Standard_False);
610 // added to avoid untimely viewer update...
611 AIS_Selection::ClearAndSelect(anIObj);
613 Quantity_NameOfColor HiCol;
614 Standard_Boolean HasHiCol;
615 if(IsHilighted(anIObj,HasHiCol,HiCol)){
616 if(HasHiCol && HiCol!= mySelectionColor) {
618 HilightWithColor(anIObj,mySelectionColor,Standard_False);
620 Hilight(anIObj,Standard_False);
626 HilightWithColor(anIObj,mySelectionColor,Standard_False);
628 Hilight(anIObj,Standard_False);
632 UpdateCurrentViewer();
636 cout<<"Nothing Done : Opened Local Context"<<endl;
641 //=======================================================================
642 //function : AddOrRemoveCurrentObject
644 //=======================================================================
646 void AIS_InteractiveContext::
647 AddOrRemoveCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
648 const Standard_Boolean updateviewer)
650 if(anIObj.IsNull()) return;
651 //OCC5682 to remove an object from neutral point even if Local Context is opened (Remove method)
652 if(!HasOpenedContext() /*OCC5682*/|| myObjects.IsBound(anIObj)) {
654 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
655 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
657 AIS_SelectStatus SelStat = AIS_Selection::Select(anIObj);
659 Standard_Integer mod = (SelStat==AIS_SS_Added) ? 1 : 0;
663 HilightWithColor(anIObj,mySelectionColor,Standard_False);
665 Hilight(anIObj,Standard_False);
668 Unhilight(anIObj,Standard_False);
672 UpdateCurrentViewer();
676 cout<<"Nothing Done : Opened Local Context"<<endl;
680 //=======================================================================
681 //function : UpdateCurrent
683 //=======================================================================
685 void AIS_InteractiveContext::UpdateCurrent()
690 //=======================================================================
691 //function : IsCurrent
693 //=======================================================================
695 Standard_Boolean AIS_InteractiveContext::IsCurrent(const Handle(AIS_InteractiveObject)& anIObj) const
698 if (anIObj.IsNull()) return Standard_False;
699 return (anIObj->State()==1);
701 // Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
703 // while (sel->More()) {
704 // if (anIObj == sel->Value()) return Standard_True;
707 // return Standard_False;
711 //=======================================================================
712 //function : InitCurrent
714 //=======================================================================
716 void AIS_InteractiveContext::InitCurrent()
718 AIS_Selection::Selection(myCurrentName.ToCString())->Init();
721 //=======================================================================
722 //function : MoreCurrent
724 //=======================================================================
726 Standard_Boolean AIS_InteractiveContext::MoreCurrent() const
728 return AIS_Selection::Selection(myCurrentName.ToCString())->More();
732 //=======================================================================
733 //function : NextCurrent
735 //=======================================================================
737 void AIS_InteractiveContext::NextCurrent()
739 AIS_Selection::Selection(myCurrentName.ToCString())->Next();
742 //=======================================================================
745 //=======================================================================
747 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Current() const
749 Handle(Standard_Transient) TR = AIS_Selection::Selection(myCurrentName.ToCString())->Value();
750 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
754 //=======================================================================
755 //function : FirstCurrentObject
757 //=======================================================================
758 Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstCurrentObject()
760 Handle(AIS_InteractiveObject) IO ;
768 //=======================================================================
769 //function : NbCurrents
771 //=======================================================================
772 Standard_Integer AIS_InteractiveContext::NbCurrents()
774 Standard_Integer i(0);
775 for(InitCurrent();MoreCurrent();NextCurrent())
780 //=======================================================================
781 //function : HilightCurrents
783 //=======================================================================
784 void AIS_InteractiveContext::HilightCurrents(const Standard_Boolean updateviewer)
786 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
787 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
788 Handle(Standard_Transient) TR;
789 Handle(AIS_InteractiveObject) IO;
791 while (sel->More()) {
793 IO = *((Handle(AIS_InteractiveObject)*)&TR);
795 HilightWithColor(IO,mySelectionColor,Standard_False);
797 Hilight(IO,Standard_False);
802 UpdateCurrentViewer();
805 //=======================================================================
806 //function : UnhilightCurrents
808 //=======================================================================
810 void AIS_InteractiveContext::UnhilightCurrents(const Standard_Boolean updateviewer)
812 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
813 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
814 Handle(Standard_Transient) TR;
815 Handle(AIS_InteractiveObject) IO;
817 while (sel->More()) {
819 IO = *((Handle(AIS_InteractiveObject)*)&TR);
820 Unhilight(IO,Standard_False);
824 UpdateCurrentViewer();
827 //=======================================================================
828 //function : ClearCurrents
830 //=======================================================================
832 void AIS_InteractiveContext::ClearCurrents(const Standard_Boolean updateviewer)
834 if(NbCurrents()==0) return;
835 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
836 Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
837 Handle(Standard_Transient) Tr;
838 Handle(AIS_InteractiveObject) IO;
839 for(S->Init();S->More();S->Next()){
841 IO = (*((Handle(AIS_InteractiveObject)*)&Tr));
843 Unhilight(IO,Standard_False);
845 AIS_Selection::Select();
847 UpdateCurrentViewer();
851 //=======================================================================
852 //function : HilightSelected
854 //=======================================================================
856 void AIS_InteractiveContext::HilightSelected(const Standard_Boolean updateviewer)
858 if(!HasOpenedContext()){
859 AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
860 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
861 Handle(Standard_Transient) TR;
862 Handle(AIS_InteractiveObject) IO;
864 while (sel->More()) {
866 IO = *((Handle(AIS_InteractiveObject)*)&TR);
868 HilightWithColor(IO,mySelectionColor,Standard_False);
870 Hilight(IO,Standard_False);
877 myLocalContexts(myCurLocalIndex)->HilightPicked(updateviewer);
880 UpdateCurrentViewer();
883 //=======================================================================
884 //function : UnhilightSelected
886 //=======================================================================
888 void AIS_InteractiveContext::UnhilightSelected(const Standard_Boolean updateviewer)
890 if(!HasOpenedContext()){
891 AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
892 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
893 Handle(Standard_Transient) TR;
894 Handle(AIS_InteractiveObject) IO;
896 while (sel->More()) {
898 IO = *((Handle(AIS_InteractiveObject)*)&TR);
899 Unhilight(IO,Standard_False);
903 UpdateCurrentViewer();
907 myLocalContexts(myCurLocalIndex)->UnhilightPicked(updateviewer);
912 //=======================================================================
913 //function : ClearSelected
915 //=======================================================================
917 void AIS_InteractiveContext::ClearSelected(const Standard_Boolean updateviewer)
919 if(!HasOpenedContext())
920 ClearCurrents(updateviewer);
922 myLocalContexts(myCurLocalIndex)->ClearSelected(updateviewer);
927 //=======================================================================
928 //function : SetSelectedCurrent
930 //=======================================================================
932 void AIS_InteractiveContext::SetSelectedCurrent()
937 cout<<"Not Yet Implemented"<<endl;
941 //=======================================================================
942 //function : UpdateSelection
944 //=======================================================================
946 void AIS_InteractiveContext::UpdateSelected(const Standard_Boolean updateviewer)
948 if(!HasOpenedContext()) {
954 myLocalContexts(myCurLocalIndex)->UpdateSelected(updateviewer);
957 //=======================================================================
958 //function : SetCurrentObject
960 //=======================================================================
961 void AIS_InteractiveContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,const Standard_Boolean updateviewer)
963 if(!HasOpenedContext())
964 SetCurrentObject(anIObj,updateviewer);
966 myLocalContexts(myCurLocalIndex)->SetSelected(anIObj,updateviewer);
969 //=======================================================================
970 //function : AddOrRemoveSelected
972 //=======================================================================
974 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj,
975 const Standard_Boolean updateviewer)
977 if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
978 if(!HasOpenedContext())
979 AddOrRemoveCurrentObject(anIObj,updateviewer);
981 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(anIObj,updateviewer);
984 //=======================================================================
985 //function : AddOrRemoveSelected
987 //=======================================================================
989 void AIS_InteractiveContext::AddOrRemoveSelected(const TopoDS_Shape& aShap,
990 const Standard_Boolean updateviewer)
992 if(!HasOpenedContext()) {
994 cout<<" Attempt to remove a selected shape with no opened local context"<<endl;
999 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(aShap,updateviewer);
1000 if(updateviewer) UpdateCurrentViewer();
1003 //=======================================================================
1004 //function : AddOrRemoveSelected
1006 //=======================================================================
1008 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(SelectMgr_EntityOwner)& Own,
1009 const Standard_Boolean updateviewer)
1011 if(!HasOpenedContext()) {
1013 cout<<" Attempt to remove a selected ownr with no opened local context"<<endl;
1018 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(Own,Standard_False);
1019 if(updateviewer) UpdateCurrentViewer();
1025 //=======================================================================
1026 //function : IsSelected
1028 //=======================================================================
1030 Standard_Boolean AIS_InteractiveContext::
1031 IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const
1033 if (anIObj.IsNull()) return Standard_False;
1035 if(!HasOpenedContext())
1036 return (anIObj->State()==1);
1038 return myLocalContexts(myCurLocalIndex)->IsSelected(anIObj);
1042 //=======================================================================
1043 //function : InitSelected
1045 //=======================================================================
1047 void AIS_InteractiveContext::InitSelected()
1049 if(!HasOpenedContext())
1050 AIS_Selection::Selection(myCurrentName.ToCString())->Init();
1052 myLocalContexts(myCurLocalIndex)->InitSelected();
1055 //=======================================================================
1056 //function : MoreSelected
1058 //=======================================================================
1060 Standard_Boolean AIS_InteractiveContext::MoreSelected() const
1062 if(!HasOpenedContext())
1063 return AIS_Selection::Selection(myCurrentName.ToCString())->More();
1064 return myLocalContexts(myCurLocalIndex)->MoreSelected();
1067 //=======================================================================
1068 //function : NextSelected
1070 //=======================================================================
1072 void AIS_InteractiveContext::NextSelected()
1074 if(!HasOpenedContext())
1075 AIS_Selection::Selection(myCurrentName.ToCString())->Next();
1077 myLocalContexts(myCurLocalIndex)->NextSelected();
1080 //=======================================================================
1081 //function : HasSelectedShape
1083 //=======================================================================
1085 Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
1087 if(!HasOpenedContext()) {
1089 Handle(AIS_Shape) shape =
1090 Handle(AIS_Shape)::DownCast(SelectedInteractive());
1091 if( !shape.IsNull() ) return Standard_True;
1093 return Standard_False;
1095 return myLocalContexts(myCurLocalIndex)->HasShape();
1100 //=======================================================================
1101 //function : SelectedShape
1103 //=======================================================================
1105 TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
1108 if(!HasOpenedContext()){
1111 Handle(AIS_Shape) shape =
1112 Handle(AIS_Shape)::DownCast(SelectedInteractive());
1113 if( !shape.IsNull() ) sh = shape->Shape();
1117 return myLocalContexts(myCurLocalIndex)->SelectedShape();
1120 //=======================================================================
1121 //function : Interactive
1123 //=======================================================================
1125 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Interactive() const
1127 return SelectedInteractive();
1130 Handle(AIS_InteractiveObject) AIS_InteractiveContext::SelectedInteractive() const
1132 if(!HasOpenedContext()){
1133 Handle(Standard_Transient) TR =AIS_Selection::Selection(myCurrentName.ToCString())->Value();
1134 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
1137 return myLocalContexts(myCurLocalIndex)->SelectedInteractive();
1140 //=======================================================================
1141 //function : Interactive
1143 //=======================================================================
1145 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const
1147 if(!HasOpenedContext()){
1148 Handle(SelectMgr_EntityOwner) Ownr;
1151 return myLocalContexts(myCurLocalIndex)->SelectedOwner();
1155 //=======================================================================
1156 //function : EntityOwners
1158 //=======================================================================
1159 void AIS_InteractiveContext::EntityOwners(SelectMgr_IndexedMapOfOwner& theOwners,
1160 const Handle(AIS_InteractiveObject)& theIObj,
1161 const Standard_Integer theMode) const
1163 if ( theIObj.IsNull() )
1166 TColStd_ListOfInteger aModes;
1167 if ( theMode == -1 )
1168 ActivatedModes( theIObj, aModes );
1170 aModes.Append( theMode );
1172 TColStd_ListIteratorOfListOfInteger anItr( aModes );
1173 for (; anItr.More(); anItr.Next() )
1175 int aMode = anItr.Value();
1176 if ( !theIObj->HasSelection( aMode ) )
1179 Handle(SelectMgr_Selection) aSel = theIObj->Selection( aMode );
1181 for ( aSel->Init(); aSel->More(); aSel->Next() )
1183 Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive();
1184 if ( aEntity.IsNull() )
1187 Handle(SelectMgr_EntityOwner) aOwner =
1188 Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId());
1189 if ( !aOwner.IsNull() )
1190 theOwners.Add( aOwner );
1195 Standard_Integer AIS_InteractiveContext::NbSelected()
1197 Standard_Integer i(0);
1198 for(InitSelected();MoreSelected();NextSelected())
1203 //=======================================================================
1204 //function : HasApplicative
1206 //=======================================================================
1208 Standard_Boolean AIS_InteractiveContext::HasApplicative() const
1210 return Interactive()->HasOwner();
1213 //=======================================================================
1214 //function : Applicative
1216 //=======================================================================
1218 Handle(Standard_Transient) AIS_InteractiveContext::Applicative() const
1220 return Interactive()->GetOwner();
1225 //==================================================
1228 //==================================================
1229 Standard_Boolean AIS_InteractiveContext::HasDetected() const
1231 if(HasOpenedContext())
1232 return myLocalContexts(myCurLocalIndex)->HasDetected();
1234 return !myLastPicked.IsNull();
1237 //=======================================================================
1238 //function : HasDetectedShape
1240 //=======================================================================
1242 Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
1244 if(HasOpenedContext())
1245 return myLocalContexts(myCurLocalIndex)->HasDetectedShape();
1246 return Standard_False;
1249 //=======================================================================
1250 //function : DetectedShape
1252 //=======================================================================
1255 AIS_InteractiveContext::DetectedShape() const
1257 return myLocalContexts(myCurLocalIndex)->DetectedShape();
1260 //=======================================================================
1261 //function : DetectedInteractive
1263 //=======================================================================
1265 Handle(AIS_InteractiveObject)
1266 AIS_InteractiveContext::DetectedInteractive() const
1268 if(HasOpenedContext())
1269 return myLocalContexts(myCurLocalIndex)->DetectedInteractive();
1270 return myLastPicked;
1274 Standard_Boolean AIS_InteractiveContext::HasNextDetected() const
1276 if(!HasOpenedContext())
1277 return Standard_False; // temporaire
1279 return myLocalContexts(myCurLocalIndex)->HasNextDetected();
1284 //=======================================================================
1285 //function : DetectedOwner
1287 //=======================================================================
1288 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedOwner() const
1290 if(HasOpenedContext())
1291 return myLocalContexts(myCurLocalIndex)->DetectedOwner();
1292 Handle(SelectMgr_EntityOwner) Ownr;
1297 //=======================================================================
1298 //function : HilightNextDetected
1300 //=======================================================================
1301 Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView,
1302 const Standard_Boolean theToRedrawImmediate)
1304 return HasOpenedContext()
1305 ? myLocalContexts (myCurLocalIndex)->HilightNextDetected (theView, theToRedrawImmediate)
1310 //=======================================================================
1311 //function : HilightNextDetected
1313 //=======================================================================
1314 Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1315 const Standard_Boolean theToRedrawImmediate)
1317 return HasOpenedContext()
1318 ? myLocalContexts (myCurLocalIndex)->HilightPreviousDetected (theView, theToRedrawImmediate)
1323 //=======================================================================
1324 //function : InitDetected
1326 //=======================================================================
1327 void AIS_InteractiveContext::InitDetected()
1329 if(HasOpenedContext())
1331 myLocalContexts(myCurLocalIndex)->InitDetected();
1335 if(myAISDetectedSeq.Length() != 0)
1336 myAISCurDetected = 1;
1340 //=======================================================================
1341 //function : MoreDetected
1343 //=======================================================================
1344 Standard_Boolean AIS_InteractiveContext::MoreDetected() const
1346 if(HasOpenedContext())
1347 return myLocalContexts(myCurLocalIndex)->MoreDetected();
1349 return (myAISCurDetected>0 &&myAISCurDetected <= myAISDetectedSeq.Length()) ?
1350 Standard_True : Standard_False;
1353 //=======================================================================
1354 //function : NextDetected
1356 //=======================================================================
1357 void AIS_InteractiveContext::NextDetected()
1359 if(HasOpenedContext())
1361 myLocalContexts(myCurLocalIndex)->NextDetected();
1368 //=======================================================================
1369 //function : DetectedCurrentShape
1371 //=======================================================================
1373 const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
1375 if(HasOpenedContext())
1376 return myLocalContexts(myCurLocalIndex)->DetectedCurrentShape();
1378 static TopoDS_Shape bidsh;
1379 if(myAISCurDetected > 0 &&
1380 myAISCurDetected <= myAISDetectedSeq.Length())
1381 return Handle(AIS_Shape)::DownCast(myAISDetectedSeq(myAISCurDetected))->Shape();
1385 //=======================================================================
1386 //function : DetectedCurrentObject
1388 //=======================================================================
1390 Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const {
1391 if(HasOpenedContext())
1392 return myLocalContexts(myCurLocalIndex)->DetectedCurrentObject();
1394 Handle(AIS_InteractiveObject) aBad;
1396 if(myAISCurDetected > 0 &&
1397 myAISCurDetected <= myAISDetectedSeq.Length())
1398 return myAISDetectedSeq(myAISCurDetected);