1 // Created on: 1997-01-29
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #define UKI60826 //GG_161199 Use the requested selection color instead of default
19 #define IMP280200 //GG Don't returns a NULL shape in SelectedShape()
20 // method when the current selected is a shape !
22 #define BUC60814 //GG_300101 Idem UKI60826
24 #define OCC138 //VTN Avoding infinit loop in AddOrRemoveCurrentObject method.
28 #include <AIS_InteractiveContext.jxx>
29 #include <SelectMgr_EntityOwner.hxx>
30 #include <AIS_Selection.hxx>
31 #include <AIS_StatusOfDetection.hxx>
32 #include <AIS_StatusOfPick.hxx>
34 #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
35 #include <AIS_LocalContext.hxx>
36 #include <AIS_GlobalStatus.hxx>
37 #include <AIS_Shape.hxx>
39 #include <Aspect_Grid.hxx>
41 #include <V3d_Light.hxx>
42 #include <V3d_PositionalLight.hxx>
43 #include <V3d_SpotLight.hxx>
44 #include <V3d_DirectionalLight.hxx>
45 #include <V3d_AmbientLight.hxx>
47 #include <TColStd_ListIteratorOfListOfInteger.hxx>
48 #include <SelectMgr_Selection.hxx>
49 #include <SelectBasics_SensitiveEntity.hxx>
51 #include <Prs3d_Presentation.hxx>
54 #include <AIS_MapOfInteractive.hxx>
55 #include <AIS_MapIteratorOfMapOfInteractive.hxx>
60 static void InfoOnLight(const Handle(V3d_View) aView)
62 Standard_Real V1=0.,V2=0.,V3=0.;
63 Standard_Integer IndexOfLit(0);
65 static Standard_Boolean FirstTime (Standard_True);
68 FirstTime = Standard_False;
69 for (aView->InitActiveLights();aView->MoreActiveLights();aView->NextActiveLights()){
71 cout<<"lumiere no "<<IndexOfLit<<"\n************\n\t";
72 Handle(V3d_Light) Li = aView->ActiveLight();
73 Quantity_NameOfColor Col;
75 cout<<"Color :"<<Standard_Integer(Col)<<"\n\t"<<endl;
82 // Handle(V3d_AmbientLight)::DownCast(Li)->DisplayPosition(V1,V2,V3);
83 cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl;
88 cout<<" DIRECTIONAL\n\t";
89 Handle(V3d_DirectionalLight)::DownCast(Li)->DisplayPosition(V1,V2,V3);
90 cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl;
91 Handle(V3d_DirectionalLight)::DownCast(Li)->Direction(V1,V2,V3);
92 cout<<"Direction : V1 = "<<V1<<" V2 = "<<V2<<" V3 = "<<V3<<endl;
98 cout<<" POSITIONAL\n\t";
99 Handle(V3d_PositionalLight)::DownCast(Li)->Position(V1,V2,V3);
100 cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl;
101 Handle(V3d_PositionalLight)::DownCast(Li)->Target(V1,V2,V3);
102 cout<<"Target : x1 = "<<V1<<" x2 = "<<V2<<" x3 = "<<V3<<endl;
108 cout<<" DIRECTIONAL\n\t";
109 Handle(V3d_SpotLight)::DownCast(Li)->Position(V1,V2,V3);
110 cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl;
111 Handle(V3d_SpotLight)::DownCast(Li)->Direction(V1,V2,V3);
112 cout<<"Direction : V1 = "<<V1<<" V2 = "<<V2<<" V3 = "<<V3<<endl;
113 Handle(V3d_PositionalLight)::DownCast(Li)->Target(V1,V2,V3);
114 cout<<"Target : x1 = "<<V1<<" x2 = "<<V2<<" x3 = "<<V3<<endl;
115 cout<<"\tAngle :"<<Handle(V3d_SpotLight)::DownCast(Li)->Angle()<<endl;
125 //=======================================================================
128 //=======================================================================
129 AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const Standard_Integer theXPix,
130 const Standard_Integer theYPix,
131 const Handle(V3d_View)& theView,
132 const Standard_Boolean theToRedrawOnUpdate)
134 if (HasOpenedContext())
136 myWasLastMain = Standard_True;
137 return myLocalContexts (myCurLocalIndex)->MoveTo (theXPix, theYPix, theView, theToRedrawOnUpdate);
140 myAISCurDetected = 0;
141 myAISDetectedSeq.Clear();
143 if (theView->Viewer() != myMainVwr)
145 return AIS_SOD_Error;
149 myLastPicked = myLastinMain;
150 myWasLastMain = Standard_True;
151 AIS_StatusOfDetection aStatus = AIS_SOD_Nothing;
152 Standard_Boolean toUpdateViewer = Standard_False;
155 myMainSel->Pick (theXPix, theYPix, theView);
157 // filling of myAISDetectedSeq sequence storing information about detected AIS objects
158 // (the objects must be AIS_Shapes)
159 const Standard_Integer aDetectedNb = myMainSel->NbPicked();
160 for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
162 Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aDetIter);
164 || !myFilters->IsOk (anOwner))
169 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
172 myAISDetectedSeq.Append (anObj);
177 if (myMainSel->More())
179 // does nothing if previously detected object is equal to the current one
180 if (myMainSel->OnePicked()->Selectable() == myLastPicked)
182 return myLastPicked->State() == 1
184 : AIS_SOD_OnlyOneDetected;
187 // Previously detected object is unhilighted if it is not selected or hilighted
188 // with selection color if it is selected. Such highlighting with selection color
189 // is needed only if myToHilightSelected flag is true. In this case previously detected
190 // object has been already highlighted with myHilightColor during previous MoveTo()
191 // method call. As result it is necessary to rehighligt it with mySelectionColor.
192 if (!myLastPicked.IsNull())
194 const Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
195 if (myLastPicked->State() != 1)
197 myMainPM->Unhighlight (myLastPicked, aHiMod);
198 toUpdateViewer = Standard_True;
200 else if (myToHilightSelected)
202 myMainPM->Color (myLastPicked, mySelectionColor, aHiMod);
203 toUpdateViewer = Standard_True;
207 // initialize myLastPicked field with currently detected object
208 myLastPicked = Handle(AIS_InteractiveObject)::DownCast (myMainSel->OnePicked()->Selectable());
209 myLastinMain = myLastPicked;
211 // highlight detected object if it is not selected or myToHilightSelected flag is true
212 if (!myLastPicked.IsNull())
214 if (myLastPicked->State() != 1 || myToHilightSelected)
216 const Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
217 myMainPM->Color (myLastPicked, myHilightColor, aHiMod);
218 toUpdateViewer = Standard_True;
221 aStatus = myLastPicked->State() == 1
223 : AIS_SOD_OnlyOneDetected;
228 // previously detected object is unhilighted if it is not selected or hilighted
229 // with selection color if it is selected
230 aStatus = AIS_SOD_Nothing;
231 if (!myLastPicked.IsNull())
233 Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
234 if (myLastPicked->State() != 1)
236 myMainPM->Unhighlight (myLastPicked, aHiMod);
237 toUpdateViewer = Standard_True;
239 else if (myToHilightSelected)
241 myMainPM->Color (myLastPicked, mySelectionColor, aHiMod);
242 toUpdateViewer = Standard_True;
246 myLastinMain.Nullify();
247 myLastPicked.Nullify();
252 if (theToRedrawOnUpdate)
254 theView->Viewer()->Update();
258 theView->Viewer()->Invalidate();
262 mylastmoveview = theView;
266 //=======================================================================
269 //=======================================================================
271 AIS_StatusOfPick AIS_InteractiveContext::Select(const Standard_Integer XPMin,
272 const Standard_Integer YPMin,
273 const Standard_Integer XPMax,
274 const Standard_Integer YPMax,
275 const Handle(V3d_View)& aView,
276 const Standard_Boolean updateviewer)
278 // all objects detected by the selector are taken, previous current objects are emptied,
279 // new objects are put...
281 if(HasOpenedContext())
282 return myLocalContexts(myCurLocalIndex)->Select(XPMin,YPMin,XPMax,YPMax,aView,updateviewer);
284 ClearCurrents(Standard_False);
285 // OCC11904 - local variables made non-static - it looks and works better like this
286 Handle(StdSelect_ViewerSelector3d) selector;
288 if(aView->Viewer()== myMainVwr) {
290 myWasLastMain = Standard_True;}
292 selector->Pick(XPMin,YPMin,XPMax,YPMax,aView);
293 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
296 AIS_MapOfInteractive theSelectedObj;
297 for( selector->Init(); selector->More(); selector->Next() )
299 Handle( AIS_InteractiveObject ) anObj =
300 Handle( AIS_InteractiveObject )::DownCast( selector->Picked()->Selectable() );
301 if( !anObj.IsNull() )
302 theSelectedObj.Add( anObj );
304 AIS_MapIteratorOfMapOfInteractive anIt( theSelectedObj );
305 for( ; anIt.More(); anIt.Next() )
307 AIS_Selection::Select( anIt.Key() );
308 anIt.Key()->State(1);
311 for(selector->Init();selector->More();selector->Next()){
312 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
315 AIS_Selection::Select(SO);
316 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
318 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
319 AIS_Selection::Select(SO);
325 HilightCurrents(updateviewer);
327 Standard_Integer NS = NbCurrents();
328 if(NS==0) return AIS_SOP_NothingSelected;
329 if(NS==1) return AIS_SOP_OneSelected;
330 return AIS_SOP_SeveralSelected;
334 //=======================================================================
336 //purpose : Selection by polyline
337 //=======================================================================
339 AIS_StatusOfPick AIS_InteractiveContext::Select(const TColgp_Array1OfPnt2d& aPolyline,
340 const Handle(V3d_View)& aView,
341 const Standard_Boolean updateviewer)
343 // all objects detected by the selector are taken, previous current objects are emptied,
344 // new objects are put...
346 if(HasOpenedContext())
347 return myLocalContexts(myCurLocalIndex)->Select(aPolyline,aView,updateviewer);
349 ClearCurrents(Standard_False);
350 // OCC11904 - local variables made non-static - it looks and works better like this
351 Handle(StdSelect_ViewerSelector3d) selector;
353 if(aView->Viewer()== myMainVwr) {
355 myWasLastMain = Standard_True;}
357 selector->Pick(aPolyline,aView);
358 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
362 AIS_MapOfInteractive theSelectedObj;
363 for( selector->Init(); selector->More(); selector->Next() )
365 Handle( AIS_InteractiveObject ) anObj =
366 Handle( AIS_InteractiveObject )::DownCast( selector->Picked()->Selectable() );
367 if( !anObj.IsNull() )
368 theSelectedObj.Add( anObj );
370 AIS_MapIteratorOfMapOfInteractive anIt( theSelectedObj );
371 for( ; anIt.More(); anIt.Next() )
373 AIS_Selection::Select( anIt.Key() );
374 anIt.Key()->State(1);
377 for(selector->Init();selector->More();selector->Next()){
378 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
381 AIS_Selection::Select(SO);
382 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
384 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
385 AIS_Selection::Select(SO);
390 HilightCurrents(updateviewer);
392 Standard_Integer NS = NbCurrents();
393 if(NS==0) return AIS_SOP_NothingSelected;
394 if(NS==1) return AIS_SOP_OneSelected;
395 return AIS_SOP_SeveralSelected;
399 //=======================================================================
402 //=======================================================================
404 AIS_StatusOfPick AIS_InteractiveContext::Select(const Standard_Boolean updateviewer)
406 if(HasOpenedContext()){
408 return myLocalContexts(myCurLocalIndex)->Select(updateviewer);
411 myLocalContexts(myCurLocalIndex)->SetSelected(myLastPicked,updateviewer);
412 return AIS_SOP_OneSelected;
415 // AIS_StatusOfPick PS(AIS_SOP_NothingSelected);
416 if(myWasLastMain && !myLastinMain.IsNull()){
417 if(myLastinMain->State()!=1){
418 SetCurrentObject(myLastinMain,Standard_False);
420 UpdateCurrentViewer();}
423 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
424 Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
425 Handle(Standard_Transient) Tr;
426 Handle(AIS_InteractiveObject) IO;
428 for(S->Init();S->More();S->Next()){
430 IO = (*((Handle(AIS_InteractiveObject)*)&Tr));
432 Unhilight(IO,Standard_False);
433 if(myObjects.IsBound(IO)){ // anti-plantage-rob
434 if(myObjects(IO)->IsSubIntensityOn())
435 HilightWithColor(IO,mySubIntensity,Standard_False);
439 AIS_Selection::Select();
442 UpdateCurrentViewer();
445 Standard_Integer NS = NbCurrents();
446 if(NS==0) return AIS_SOP_NothingSelected;
447 if(NS==1) return AIS_SOP_OneSelected;
448 return AIS_SOP_SeveralSelected;
451 //=======================================================================
452 //function : ShiftSelect
454 //=======================================================================
456 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect(const Standard_Boolean updateviewer)
458 if(HasOpenedContext()){
460 return myLocalContexts(myCurLocalIndex)->ShiftSelect(updateviewer);
462 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(myLastPicked,updateviewer);
463 Standard_Integer NS =NbSelected();
464 if(NS==0) return AIS_SOP_NothingSelected;
465 if(NS==1) return AIS_SOP_OneSelected;
466 return AIS_SOP_SeveralSelected;
469 if(myWasLastMain && !myLastinMain.IsNull())
470 AddOrRemoveCurrentObject(myLastinMain,updateviewer);
472 Standard_Integer NS = NbCurrents();
473 if(NS==0) return AIS_SOP_NothingSelected;
474 if(NS==1) return AIS_SOP_OneSelected;
475 return AIS_SOP_SeveralSelected;
479 //=======================================================================
480 //function : ShiftSelect
482 //=======================================================================
484 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect(const Standard_Integer XPMin,
485 const Standard_Integer YPMin,
486 const Standard_Integer XPMax,
487 const Standard_Integer YPMax,
488 const Handle(V3d_View)& aView,
489 const Standard_Boolean updateviewer)
492 if(HasOpenedContext())
493 return myLocalContexts(myCurLocalIndex)->ShiftSelect(XPMin,YPMin,XPMax,YPMax,aView,updateviewer);
495 UnhilightCurrents(Standard_False);
496 // OCC11904 - local variables made non-static - it looks and works better like this
497 Handle(StdSelect_ViewerSelector3d) selector;
499 if(aView->Viewer()== myMainVwr) {
501 myWasLastMain = Standard_True;}
503 return AIS_SOP_NothingSelected;
505 selector->Pick(XPMin,YPMin,XPMax,YPMax,aView);
506 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
507 for(selector->Init();selector->More();selector->Next()){
508 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
510 AIS_SelectStatus SelStat = AIS_Selection::Select(SO);
511 Standard_Integer mod = (SelStat==AIS_SS_Added)?1:0;
512 (*((Handle(AIS_InteractiveObject)*)&SO))->State(mod);
516 HilightCurrents(updateviewer);
518 Standard_Integer NS =NbCurrents();
519 if(NS==0) return AIS_SOP_NothingSelected;
520 if(NS==1) return AIS_SOP_OneSelected;
521 return AIS_SOP_SeveralSelected;
525 //=======================================================================
526 //function : ShiftSelect
528 //=======================================================================
530 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect( const TColgp_Array1OfPnt2d& aPolyline,
531 const Handle(V3d_View)& aView,
532 const Standard_Boolean updateviewer )
534 if( HasOpenedContext() )
535 return myLocalContexts( myCurLocalIndex )->ShiftSelect( aPolyline, aView, updateviewer );
537 UnhilightCurrents( Standard_False );
538 // OCC11904 - local variables made non-static - it looks and works better like this
539 Handle(StdSelect_ViewerSelector3d) selector;
541 if( aView->Viewer() == myMainVwr ) {
543 myWasLastMain = Standard_True;
546 return AIS_SOP_NothingSelected;
548 selector->Pick( aPolyline, aView );
550 AIS_Selection::SetCurrentSelection( myCurrentName.ToCString() );
551 for( selector->Init(); selector->More(); selector->Next() ) {
552 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
554 AIS_SelectStatus SelStat = AIS_Selection::Select( SO );
555 Standard_Integer mod = ( SelStat == AIS_SS_Added ) ? 1 : 0;
556 (*((Handle(AIS_InteractiveObject)*)&SO))->State( mod );
560 HilightCurrents( updateviewer );
561 Standard_Integer NS = NbCurrents();
562 if( NS == 0 ) return AIS_SOP_NothingSelected;
563 if( NS == 1 ) return AIS_SOP_OneSelected;
564 return AIS_SOP_SeveralSelected;
567 //=======================================================================
568 //function : SetCurrentObject
570 //=======================================================================
572 void AIS_InteractiveContext::SetCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
573 const Standard_Boolean updateviewer)
575 // single case processing...
576 if(NbCurrents()==1 && anIObj->State()==1){
577 Quantity_NameOfColor HiCol;
578 Standard_Boolean HasHiCol;
579 if(IsHilighted(anIObj,HasHiCol,HiCol)){
580 if(HasHiCol && HiCol!= mySelectionColor) {
582 HilightWithColor(anIObj,mySelectionColor,updateviewer);
584 Hilight(anIObj,updateviewer);
593 if(!HasOpenedContext()) {
594 if(anIObj.IsNull()) return;
595 if(!myObjects.IsBound(anIObj))
596 Display(anIObj,Standard_False);
598 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
599 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
600 Handle(Standard_Transient) TR;
601 Handle(AIS_InteractiveObject) IO;
603 while (sel->More()) {
605 IO = *((Handle(AIS_InteractiveObject)*)&TR);
606 Unhilight(IO,Standard_False);
611 // added to avoid untimely viewer update...
612 AIS_Selection::ClearAndSelect(anIObj);
614 Quantity_NameOfColor HiCol;
615 Standard_Boolean HasHiCol;
616 if(IsHilighted(anIObj,HasHiCol,HiCol)){
617 if(HasHiCol && HiCol!= mySelectionColor) {
619 HilightWithColor(anIObj,mySelectionColor,Standard_False);
621 Hilight(anIObj,Standard_False);
627 HilightWithColor(anIObj,mySelectionColor,Standard_False);
629 Hilight(anIObj,Standard_False);
633 UpdateCurrentViewer();
637 cout<<"Nothing Done : Opened Local Context"<<endl;
642 //=======================================================================
643 //function : AddOrRemoveCurrentObject
645 //=======================================================================
647 void AIS_InteractiveContext::
648 AddOrRemoveCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
649 const Standard_Boolean updateviewer)
651 if(anIObj.IsNull()) return;
652 //OCC5682 to remove an object from neutral point even if Local Context is opened (Remove method)
653 if(!HasOpenedContext() /*OCC5682*/|| myObjects.IsBound(anIObj)) {
655 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
656 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
658 AIS_SelectStatus SelStat = AIS_Selection::Select(anIObj);
660 Standard_Integer mod = (SelStat==AIS_SS_Added) ? 1 : 0;
664 HilightWithColor(anIObj,mySelectionColor,Standard_False);
666 Hilight(anIObj,Standard_False);
669 Unhilight(anIObj,Standard_False);
673 UpdateCurrentViewer();
677 cout<<"Nothing Done : Opened Local Context"<<endl;
681 //=======================================================================
682 //function : UpdateCurrent
684 //=======================================================================
686 void AIS_InteractiveContext::UpdateCurrent()
691 //=======================================================================
692 //function : IsCurrent
694 //=======================================================================
696 Standard_Boolean AIS_InteractiveContext::IsCurrent(const Handle(AIS_InteractiveObject)& anIObj) const
699 if (anIObj.IsNull()) return Standard_False;
700 return (anIObj->State()==1);
702 // Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
704 // while (sel->More()) {
705 // if (anIObj == sel->Value()) return Standard_True;
708 // return Standard_False;
712 //=======================================================================
713 //function : InitCurrent
715 //=======================================================================
717 void AIS_InteractiveContext::InitCurrent()
719 AIS_Selection::Selection(myCurrentName.ToCString())->Init();
722 //=======================================================================
723 //function : MoreCurrent
725 //=======================================================================
727 Standard_Boolean AIS_InteractiveContext::MoreCurrent() const
729 return AIS_Selection::Selection(myCurrentName.ToCString())->More();
733 //=======================================================================
734 //function : NextCurrent
736 //=======================================================================
738 void AIS_InteractiveContext::NextCurrent()
740 AIS_Selection::Selection(myCurrentName.ToCString())->Next();
743 //=======================================================================
746 //=======================================================================
748 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Current() const
750 Handle(Standard_Transient) TR = AIS_Selection::Selection(myCurrentName.ToCString())->Value();
751 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
755 //=======================================================================
756 //function : FirstCurrentObject
758 //=======================================================================
759 Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstCurrentObject()
761 Handle(AIS_InteractiveObject) IO ;
769 //=======================================================================
770 //function : NbCurrents
772 //=======================================================================
773 Standard_Integer AIS_InteractiveContext::NbCurrents()
775 Standard_Integer i(0);
776 for(InitCurrent();MoreCurrent();NextCurrent())
781 //=======================================================================
782 //function : HilightCurrents
784 //=======================================================================
785 void AIS_InteractiveContext::HilightCurrents(const Standard_Boolean updateviewer)
787 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
788 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
789 Handle(Standard_Transient) TR;
790 Handle(AIS_InteractiveObject) IO;
792 while (sel->More()) {
794 IO = *((Handle(AIS_InteractiveObject)*)&TR);
796 HilightWithColor(IO,mySelectionColor,Standard_False);
798 Hilight(IO,Standard_False);
803 UpdateCurrentViewer();
806 //=======================================================================
807 //function : UnhilightCurrents
809 //=======================================================================
811 void AIS_InteractiveContext::UnhilightCurrents(const Standard_Boolean updateviewer)
813 AIS_Selection::SetCurrentSelection(myCurrentName.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);
821 Unhilight(IO,Standard_False);
825 UpdateCurrentViewer();
828 //=======================================================================
829 //function : ClearCurrents
831 //=======================================================================
833 void AIS_InteractiveContext::ClearCurrents(const Standard_Boolean updateviewer)
835 if(NbCurrents()==0) return;
836 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
837 Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
838 Handle(Standard_Transient) Tr;
839 Handle(AIS_InteractiveObject) IO;
840 for(S->Init();S->More();S->Next()){
842 IO = (*((Handle(AIS_InteractiveObject)*)&Tr));
844 Unhilight(IO,Standard_False);
846 AIS_Selection::Select();
848 UpdateCurrentViewer();
852 //=======================================================================
853 //function : HilightSelected
855 //=======================================================================
857 void AIS_InteractiveContext::HilightSelected(const Standard_Boolean updateviewer)
859 if(!HasOpenedContext()){
860 AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
861 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
862 Handle(Standard_Transient) TR;
863 Handle(AIS_InteractiveObject) IO;
865 while (sel->More()) {
867 IO = *((Handle(AIS_InteractiveObject)*)&TR);
869 HilightWithColor(IO,mySelectionColor,Standard_False);
871 Hilight(IO,Standard_False);
878 myLocalContexts(myCurLocalIndex)->HilightPicked(updateviewer);
881 UpdateCurrentViewer();
884 //=======================================================================
885 //function : UnhilightSelected
887 //=======================================================================
889 void AIS_InteractiveContext::UnhilightSelected(const Standard_Boolean updateviewer)
891 if(!HasOpenedContext()){
892 AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
893 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
894 Handle(Standard_Transient) TR;
895 Handle(AIS_InteractiveObject) IO;
897 while (sel->More()) {
899 IO = *((Handle(AIS_InteractiveObject)*)&TR);
900 Unhilight(IO,Standard_False);
904 UpdateCurrentViewer();
908 myLocalContexts(myCurLocalIndex)->UnhilightPicked(updateviewer);
913 //=======================================================================
914 //function : ClearSelected
916 //=======================================================================
918 void AIS_InteractiveContext::ClearSelected(const Standard_Boolean updateviewer)
920 if(!HasOpenedContext())
921 ClearCurrents(updateviewer);
923 myLocalContexts(myCurLocalIndex)->ClearSelected(updateviewer);
928 //=======================================================================
929 //function : SetSelectedCurrent
931 //=======================================================================
933 void AIS_InteractiveContext::SetSelectedCurrent()
938 cout<<"Not Yet Implemented"<<endl;
942 //=======================================================================
943 //function : UpdateSelection
945 //=======================================================================
947 void AIS_InteractiveContext::UpdateSelected(const Standard_Boolean updateviewer)
949 if(!HasOpenedContext()) {
955 myLocalContexts(myCurLocalIndex)->UpdateSelected(updateviewer);
958 //=======================================================================
959 //function : SetCurrentObject
961 //=======================================================================
962 void AIS_InteractiveContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,const Standard_Boolean updateviewer)
964 if(!HasOpenedContext())
965 SetCurrentObject(anIObj,updateviewer);
967 myLocalContexts(myCurLocalIndex)->SetSelected(anIObj,updateviewer);
970 //=======================================================================
971 //function : AddOrRemoveSelected
973 //=======================================================================
975 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj,
976 const Standard_Boolean updateviewer)
978 if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
979 if(!HasOpenedContext())
980 AddOrRemoveCurrentObject(anIObj,updateviewer);
982 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(anIObj,updateviewer);
985 //=======================================================================
986 //function : AddOrRemoveSelected
988 //=======================================================================
990 void AIS_InteractiveContext::AddOrRemoveSelected(const TopoDS_Shape& aShap,
991 const Standard_Boolean updateviewer)
993 if(!HasOpenedContext()) {
995 cout<<" Attempt to remove a selected shape with no opened local context"<<endl;
1000 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(aShap,updateviewer);
1001 if(updateviewer) UpdateCurrentViewer();
1004 //=======================================================================
1005 //function : AddOrRemoveSelected
1007 //=======================================================================
1009 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(SelectMgr_EntityOwner)& Own,
1010 const Standard_Boolean updateviewer)
1012 if(!HasOpenedContext()) {
1014 cout<<" Attempt to remove a selected ownr with no opened local context"<<endl;
1019 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(Own,Standard_False);
1020 if(updateviewer) UpdateCurrentViewer();
1026 //=======================================================================
1027 //function : IsSelected
1029 //=======================================================================
1031 Standard_Boolean AIS_InteractiveContext::
1032 IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const
1034 if (anIObj.IsNull()) return Standard_False;
1036 if(!HasOpenedContext())
1037 return (anIObj->State()==1);
1039 return myLocalContexts(myCurLocalIndex)->IsSelected(anIObj);
1043 //=======================================================================
1044 //function : InitSelected
1046 //=======================================================================
1048 void AIS_InteractiveContext::InitSelected()
1050 if(!HasOpenedContext())
1051 AIS_Selection::Selection(myCurrentName.ToCString())->Init();
1053 myLocalContexts(myCurLocalIndex)->InitSelected();
1056 //=======================================================================
1057 //function : MoreSelected
1059 //=======================================================================
1061 Standard_Boolean AIS_InteractiveContext::MoreSelected() const
1063 if(!HasOpenedContext())
1064 return AIS_Selection::Selection(myCurrentName.ToCString())->More();
1065 return myLocalContexts(myCurLocalIndex)->MoreSelected();
1068 //=======================================================================
1069 //function : NextSelected
1071 //=======================================================================
1073 void AIS_InteractiveContext::NextSelected()
1075 if(!HasOpenedContext())
1076 AIS_Selection::Selection(myCurrentName.ToCString())->Next();
1078 myLocalContexts(myCurLocalIndex)->NextSelected();
1081 //=======================================================================
1082 //function : HasSelectedShape
1084 //=======================================================================
1086 Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
1088 if(!HasOpenedContext()) {
1090 Handle(AIS_Shape) shape =
1091 Handle(AIS_Shape)::DownCast(SelectedInteractive());
1092 if( !shape.IsNull() ) return Standard_True;
1094 return Standard_False;
1096 return myLocalContexts(myCurLocalIndex)->HasShape();
1101 //=======================================================================
1102 //function : SelectedShape
1104 //=======================================================================
1106 TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
1109 if(!HasOpenedContext()){
1112 Handle(AIS_Shape) shape =
1113 Handle(AIS_Shape)::DownCast(SelectedInteractive());
1114 if( !shape.IsNull() ) sh = shape->Shape();
1118 return myLocalContexts(myCurLocalIndex)->SelectedShape();
1121 //=======================================================================
1122 //function : Interactive
1124 //=======================================================================
1126 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Interactive() const
1128 return SelectedInteractive();
1131 Handle(AIS_InteractiveObject) AIS_InteractiveContext::SelectedInteractive() const
1133 if(!HasOpenedContext()){
1134 Handle(Standard_Transient) TR =AIS_Selection::Selection(myCurrentName.ToCString())->Value();
1135 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
1138 return myLocalContexts(myCurLocalIndex)->SelectedInteractive();
1141 //=======================================================================
1142 //function : Interactive
1144 //=======================================================================
1146 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const
1148 if(!HasOpenedContext()){
1149 Handle(SelectMgr_EntityOwner) Ownr;
1152 return myLocalContexts(myCurLocalIndex)->SelectedOwner();
1156 //=======================================================================
1157 //function : EntityOwners
1159 //=======================================================================
1160 void AIS_InteractiveContext::EntityOwners(SelectMgr_IndexedMapOfOwner& theOwners,
1161 const Handle(AIS_InteractiveObject)& theIObj,
1162 const Standard_Integer theMode) const
1164 if ( theIObj.IsNull() )
1167 TColStd_ListOfInteger aModes;
1168 if ( theMode == -1 )
1169 ActivatedModes( theIObj, aModes );
1171 aModes.Append( theMode );
1173 TColStd_ListIteratorOfListOfInteger anItr( aModes );
1174 for (; anItr.More(); anItr.Next() )
1176 int aMode = anItr.Value();
1177 if ( !theIObj->HasSelection( aMode ) )
1180 Handle(SelectMgr_Selection) aSel = theIObj->Selection( aMode );
1182 for ( aSel->Init(); aSel->More(); aSel->Next() )
1184 Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive();
1185 if ( aEntity.IsNull() )
1188 Handle(SelectMgr_EntityOwner) aOwner =
1189 Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId());
1190 if ( !aOwner.IsNull() )
1191 theOwners.Add( aOwner );
1196 Standard_Integer AIS_InteractiveContext::NbSelected()
1198 Standard_Integer i(0);
1199 for(InitSelected();MoreSelected();NextSelected())
1204 //=======================================================================
1205 //function : HasApplicative
1207 //=======================================================================
1209 Standard_Boolean AIS_InteractiveContext::HasApplicative() const
1211 return Interactive()->HasOwner();
1214 //=======================================================================
1215 //function : Applicative
1217 //=======================================================================
1219 Handle(Standard_Transient) AIS_InteractiveContext::Applicative() const
1221 return Interactive()->GetOwner();
1226 //==================================================
1229 //==================================================
1230 Standard_Boolean AIS_InteractiveContext::HasDetected() const
1232 if(HasOpenedContext())
1233 return myLocalContexts(myCurLocalIndex)->HasDetected();
1235 return !myLastPicked.IsNull();
1238 //=======================================================================
1239 //function : HasDetectedShape
1241 //=======================================================================
1243 Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
1245 if(HasOpenedContext())
1246 return myLocalContexts(myCurLocalIndex)->HasDetectedShape();
1247 return Standard_False;
1250 //=======================================================================
1251 //function : DetectedShape
1253 //=======================================================================
1256 AIS_InteractiveContext::DetectedShape() const
1258 return myLocalContexts(myCurLocalIndex)->DetectedShape();
1261 //=======================================================================
1262 //function : DetectedInteractive
1264 //=======================================================================
1266 Handle(AIS_InteractiveObject)
1267 AIS_InteractiveContext::DetectedInteractive() const
1269 if(HasOpenedContext())
1270 return myLocalContexts(myCurLocalIndex)->DetectedInteractive();
1271 return myLastPicked;
1275 Standard_Boolean AIS_InteractiveContext::HasNextDetected() const
1277 if(!HasOpenedContext())
1278 return Standard_False; // temporaire
1280 return myLocalContexts(myCurLocalIndex)->HasNextDetected();
1285 //=======================================================================
1286 //function : DetectedOwner
1288 //=======================================================================
1289 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedOwner() const
1291 if(HasOpenedContext())
1292 return myLocalContexts(myCurLocalIndex)->DetectedOwner();
1293 Handle(SelectMgr_EntityOwner) Ownr;
1298 //=======================================================================
1299 //function : HilightNextDetected
1301 //=======================================================================
1302 Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView,
1303 const Standard_Boolean theToRedrawImmediate)
1305 return HasOpenedContext()
1306 ? myLocalContexts (myCurLocalIndex)->HilightNextDetected (theView, theToRedrawImmediate)
1311 //=======================================================================
1312 //function : HilightNextDetected
1314 //=======================================================================
1315 Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1316 const Standard_Boolean theToRedrawImmediate)
1318 return HasOpenedContext()
1319 ? myLocalContexts (myCurLocalIndex)->HilightPreviousDetected (theView, theToRedrawImmediate)
1324 //=======================================================================
1325 //function : InitDetected
1327 //=======================================================================
1328 void AIS_InteractiveContext::InitDetected()
1330 if (HasOpenedContext())
1332 myLocalContexts(myCurLocalIndex)->InitDetected();
1336 if(myAISDetectedSeq.Length() != 0)
1338 myAISCurDetected = 1;
1342 //=======================================================================
1343 //function : MoreDetected
1345 //=======================================================================
1346 Standard_Boolean AIS_InteractiveContext::MoreDetected() const
1348 if (HasOpenedContext())
1350 return myLocalContexts(myCurLocalIndex)->MoreDetected();
1353 return (myAISCurDetected > 0 && myAISCurDetected <= myAISDetectedSeq.Length()) ?
1354 Standard_True : Standard_False;
1357 //=======================================================================
1358 //function : NextDetected
1360 //=======================================================================
1361 void AIS_InteractiveContext::NextDetected()
1363 if(HasOpenedContext())
1365 myLocalContexts(myCurLocalIndex)->NextDetected();
1372 //=======================================================================
1373 //function : DetectedCurrentShape
1375 //=======================================================================
1376 const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
1378 if (HasOpenedContext())
1380 return myLocalContexts(myCurLocalIndex)->DetectedCurrentShape();
1383 static TopoDS_Shape aDummyShape;
1385 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
1387 if (aCurrentShape.IsNull())
1392 return aCurrentShape->Shape();
1395 //=======================================================================
1396 //function : DetectedCurrentObject
1398 //=======================================================================
1399 Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const
1401 if (HasOpenedContext())
1403 return myLocalContexts(myCurLocalIndex)->DetectedCurrentObject();
1406 return MoreDetected() ? myAISDetectedSeq(myAISCurDetected) : NULL;