1 // File: AIS_InteractiveContext_1.cxx
2 // Created: Wed Jan 29 10:29:35 1997
3 // Author: Robert COUBLANC
4 // <rob@robox.paris1.matra-dtv.fr>
6 #define UKI60826 //GG_161199 Use the requested selection color instead of default
8 #define IMP280200 //GG Don't returns a NULL shape in SelectedShape()
9 // method when the current selected is a shape !
11 #define BUC60814 //GG_300101 Idem UKI60826
13 #define IMP150501 //GG_150501 CADPAK_V2 Add Drag() method
15 #define IMP160701 //ZSV Add InitDetected(),MoreDetected(),NextDetected(),
16 // DetectedCurrentShape(),DetectedCurrentObject()
19 #define IMP191001 //GG Avoid to raise when switching with the
20 // SetAutomaticHilight() method.
21 // Thanks to IFO of SAMTECH company for this improvment.
23 #define OCC138 //VTN Avoding infinit loop in AddOrRemoveCurrentObject method.
27 #include <AIS_InteractiveContext.jxx>
28 #include <SelectMgr_EntityOwner.hxx>
29 #include <AIS_Selection.hxx>
30 #include <AIS_StatusOfDetection.hxx>
31 #include <AIS_StatusOfPick.hxx>
33 #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
34 #include <AIS_LocalContext.hxx>
35 #include <AIS_GlobalStatus.hxx>
36 #include <AIS_Shape.hxx>
38 #include <V3d_Light.hxx>
39 #include <V3d_PositionalLight.hxx>
40 #include <V3d_SpotLight.hxx>
41 #include <V3d_DirectionalLight.hxx>
42 #include <V3d_AmbientLight.hxx>
44 #include <TColStd_ListIteratorOfListOfInteger.hxx>
45 #include <SelectMgr_Selection.hxx>
46 #include <SelectBasics_SensitiveEntity.hxx>
49 #include <Visual3d_TransientManager.hxx>
50 #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;
124 //=======================================================================
127 //=======================================================================
129 AIS_StatusOfDetection AIS_InteractiveContext::MoveTo(const Standard_Integer XPix,
130 const Standard_Integer YPix,
131 const Handle(V3d_View)& aView)
133 if(HasOpenedContext()&& aView->Viewer()!=myCollectorVwr){
134 myWasLastMain = Standard_True;
135 return myLocalContexts(myCurLocalIndex)->MoveTo(XPix,YPix,aView);
139 //Nullify class members storing information about detected AIS objects.
140 myAISCurDetected = 0;
141 myAISDetectedSeq.Clear();
144 // OCC11904 - local variables made non-static - it looks and works better like this
145 Handle (PrsMgr_PresentationManager3d) pmgr ;
146 Handle (StdSelect_ViewerSelector3d) selector;
147 Standard_Boolean ismain = Standard_True,UpdVwr = Standard_False;
150 if(aView->Viewer()== myMainVwr) {
153 myLastPicked = myLastinMain;
154 myWasLastMain = Standard_True;
156 else if (aView->Viewer()== myCollectorVwr){
157 pmgr = myCollectorPM;
158 selector=myCollectorSel;
159 myLastPicked = myLastinColl;
160 ismain = Standard_False;
161 myWasLastMain = Standard_False;
164 return AIS_SOD_Error;
166 AIS_StatusOfDetection TheStat(AIS_SOD_Nothing);
170 selector->Pick(XPix, YPix, aView);
173 //filling of myAISDetectedSeq sequence storing information about detected AIS objects
174 // (the objects must be AIS_Shapes).
175 Handle(SelectMgr_EntityOwner) anEntityOwner;
176 const Standard_Integer NbDetected = selector->NbPicked();
177 for(Standard_Integer i_detect = 1;i_detect<=NbDetected;i_detect++)
179 anEntityOwner = selector->Picked(i_detect);
180 if(!anEntityOwner.IsNull())
181 if(myFilters->IsOk(anEntityOwner))
183 Handle(AIS_InteractiveObject) anObj =
184 Handle(AIS_InteractiveObject)::DownCast(anEntityOwner->Selectable());
185 if(!Handle(AIS_Shape)::DownCast(anObj).IsNull())
186 myAISDetectedSeq.Append(anObj);
192 if ( selector->More() )
194 if ( HasOpenedContext() )
195 if ( !myFilters->IsOk( selector->OnePicked() ) )
196 return AIS_SOD_AllBad;
198 if ( !myLocalContexts( myCurLocalIndex )->Filter()->IsOk( selector->OnePicked() ) )
199 return AIS_SOD_AllBad;
202 // Does nothing if previously detected object is equal to the current one
203 if ( selector->OnePicked()->Selectable() == myLastPicked )
204 return AIS_SOD_OnlyOneDetected;
206 // Previously detected object is unhilighted if it is not selected or hilighted
207 // with selection color if it is selected. Such highlighting with selection color
208 // is needed only if myToHilightSelected flag is true. In this case previously detected
209 // object has been already highlighted with myHilightColor during previous MoveTo()
210 // method call. As result it is necessary to rehighligt it with mySelectionColor.
211 if ( !myLastPicked.IsNull() )
213 Standard_Integer HiMod =
214 myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
215 if ( myLastPicked->State() != 1 )
217 pmgr->Unhighlight( myLastPicked, HiMod );
218 UpdVwr = Standard_True;
220 else if ( myToHilightSelected )
222 pmgr->Color( myLastPicked, mySelectionColor, HiMod );
223 UpdVwr = Standard_True;
227 // Initialize myLastPicked field with currently detected object
228 Handle(SelectMgr_SelectableObject) SO = selector->OnePicked()->Selectable();
229 myLastPicked = *((Handle(AIS_InteractiveObject)*)&SO);
232 myLastinMain = myLastPicked;
234 myLastinColl = myLastPicked;
236 // Highlight detected object if it is not selected or myToHilightSelected flag is true
237 if ( !myLastPicked.IsNull() &&
238 ( myLastPicked->State()!= 1 || myToHilightSelected ) )
240 if ( myLastPicked->State()!= 1 )
243 Standard_Integer HiMod =
244 myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
245 pmgr->Color( myLastPicked, myHilightColor, HiMod );
246 UpdVwr = Standard_True;
249 if ( myLastPicked->State()==1 )
250 TheStat = AIS_SOD_Selected;
254 // Previously detected object is unhilighted if it is not selected or hilighted
255 // with selection color if it is selected.
256 TheStat = AIS_SOD_Nothing;
257 if ( !myLastPicked.IsNull() )
259 Standard_Integer HiMod =
260 myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
261 if ( myLastPicked->State() != 1 )
263 pmgr->Unhighlight( myLastPicked, HiMod );
264 UpdVwr = Standard_True;
266 else if ( myToHilightSelected )
268 pmgr->Color( myLastPicked, mySelectionColor, HiMod );
269 UpdVwr = Standard_True;
274 myLastinMain.Nullify();
276 myLastinColl.Nullify();
279 if(UpdVwr) aView->Viewer()->Update();
280 myLastPicked.Nullify();
282 mylastmoveview = aView;
286 //=======================================================================
289 //=======================================================================
291 AIS_StatusOfPick AIS_InteractiveContext::Select(const Standard_Integer XPMin,
292 const Standard_Integer YPMin,
293 const Standard_Integer XPMax,
294 const Standard_Integer YPMax,
295 const Handle(V3d_View)& aView,
296 const Standard_Boolean updateviewer)
298 // all objects detected by the selector are taken, previous current objects are emptied,
299 // new objects are put...
301 if(HasOpenedContext())
302 return myLocalContexts(myCurLocalIndex)->Select(XPMin,YPMin,XPMax,YPMax,aView,updateviewer);
304 ClearCurrents(Standard_False);
305 // OCC11904 - local variables made non-static - it looks and works better like this
306 Handle(StdSelect_ViewerSelector3d) selector;
308 if(aView->Viewer()== myMainVwr) {
310 myWasLastMain = Standard_True;}
312 else if (aView->Viewer()==myCollectorVwr){
313 selector= myCollectorSel;
314 myWasLastMain = Standard_False;}
317 selector->Pick(XPMin,YPMin,XPMax,YPMax,aView);
318 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
321 AIS_MapOfInteractive theSelectedObj;
322 for( selector->Init(); selector->More(); selector->Next() )
324 Handle( AIS_InteractiveObject ) anObj =
325 Handle( AIS_InteractiveObject )::DownCast( selector->Picked()->Selectable() );
326 if( !anObj.IsNull() )
327 theSelectedObj.Add( anObj );
329 AIS_MapIteratorOfMapOfInteractive anIt( theSelectedObj );
330 for( ; anIt.More(); anIt.Next() )
332 AIS_Selection::Select( anIt.Key() );
333 anIt.Key()->State(1);
336 for(selector->Init();selector->More();selector->Next()){
337 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
340 AIS_Selection::Select(SO);
341 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
343 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
344 AIS_Selection::Select(SO);
350 HilightCurrents(updateviewer);
352 Standard_Integer NS = NbCurrents();
353 if(NS==0) return AIS_SOP_NothingSelected;
354 if(NS==1) return AIS_SOP_OneSelected;
355 return AIS_SOP_SeveralSelected;
359 //=======================================================================
361 //purpose : Selection by polyline
362 //=======================================================================
364 AIS_StatusOfPick AIS_InteractiveContext::Select(const TColgp_Array1OfPnt2d& aPolyline,
365 const Handle(V3d_View)& aView,
366 const Standard_Boolean updateviewer)
368 // all objects detected by the selector are taken, previous current objects are emptied,
369 // new objects are put...
371 if(HasOpenedContext())
372 return myLocalContexts(myCurLocalIndex)->Select(aPolyline,aView,updateviewer);
374 ClearCurrents(Standard_False);
375 // OCC11904 - local variables made non-static - it looks and works better like this
376 Handle(StdSelect_ViewerSelector3d) selector;
378 if(aView->Viewer()== myMainVwr) {
380 myWasLastMain = Standard_True;}
382 else if (aView->Viewer()==myCollectorVwr){
383 selector= myCollectorSel;
384 myWasLastMain = Standard_False;}
387 selector->Pick(aPolyline,aView);
388 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
392 AIS_MapOfInteractive theSelectedObj;
393 for( selector->Init(); selector->More(); selector->Next() )
395 Handle( AIS_InteractiveObject ) anObj =
396 Handle( AIS_InteractiveObject )::DownCast( selector->Picked()->Selectable() );
397 if( !anObj.IsNull() )
398 theSelectedObj.Add( anObj );
400 AIS_MapIteratorOfMapOfInteractive anIt( theSelectedObj );
401 for( ; anIt.More(); anIt.Next() )
403 AIS_Selection::Select( anIt.Key() );
404 anIt.Key()->State(1);
407 for(selector->Init();selector->More();selector->Next()){
408 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
411 AIS_Selection::Select(SO);
412 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
414 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
415 AIS_Selection::Select(SO);
420 HilightCurrents(updateviewer);
422 Standard_Integer NS = NbCurrents();
423 if(NS==0) return AIS_SOP_NothingSelected;
424 if(NS==1) return AIS_SOP_OneSelected;
425 return AIS_SOP_SeveralSelected;
429 //=======================================================================
432 //=======================================================================
434 AIS_StatusOfPick AIS_InteractiveContext::Select(const Standard_Boolean updateviewer)
436 if(HasOpenedContext()){
438 return myLocalContexts(myCurLocalIndex)->Select(updateviewer);
440 // picking was done in the collector, special processing is required...
442 myLocalContexts(myCurLocalIndex)->SetSelected(myLastPicked,updateviewer);
443 return AIS_SOP_OneSelected;
446 // AIS_StatusOfPick PS(AIS_SOP_NothingSelected);
447 if(myWasLastMain && !myLastinMain.IsNull()){
448 if(myLastinMain->State()!=1){
449 SetCurrentObject(myLastinMain,Standard_False);
451 UpdateCurrentViewer();}
453 else if (!myWasLastMain && !myLastinColl.IsNull()){
454 if(myLastinColl->State()!=1){
455 SetCurrentObject(myLastinColl,Standard_False);
460 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
461 Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
462 Handle(Standard_Transient) Tr;
463 Handle(AIS_InteractiveObject) IO;
465 for(S->Init();S->More();S->Next()){
467 IO = (*((Handle(AIS_InteractiveObject)*)&Tr));
469 Unhilight(IO,Standard_False);
470 if(myObjects.IsBound(IO)){ // anti-plantage-rob
471 if(myObjects(IO)->IsSubIntensityOn())
472 HilightWithColor(IO,mySubIntensity,Standard_False);
476 AIS_Selection::Select();
479 UpdateCurrentViewer();
484 Standard_Integer NS = NbCurrents();
485 if(NS==0) return AIS_SOP_NothingSelected;
486 if(NS==1) return AIS_SOP_OneSelected;
487 return AIS_SOP_SeveralSelected;
490 //=======================================================================
491 //function : ShiftSelect
493 //=======================================================================
495 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect(const Standard_Boolean updateviewer)
497 if(HasOpenedContext()){
499 return myLocalContexts(myCurLocalIndex)->ShiftSelect(updateviewer);
501 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(myLastPicked,updateviewer);
502 Standard_Integer NS =NbSelected();
503 if(NS==0) return AIS_SOP_NothingSelected;
504 if(NS==1) return AIS_SOP_OneSelected;
505 return AIS_SOP_SeveralSelected;
508 if(myWasLastMain && !myLastinMain.IsNull())
509 AddOrRemoveCurrentObject(myLastinMain,updateviewer);
510 else if (!myWasLastMain && !myLastinColl.IsNull())
511 AddOrRemoveCurrentObject(myLastinColl,updateviewer);
514 Standard_Integer NS = NbCurrents();
515 if(NS==0) return AIS_SOP_NothingSelected;
516 if(NS==1) return AIS_SOP_OneSelected;
517 return AIS_SOP_SeveralSelected;
521 //=======================================================================
522 //function : ShiftSelect
524 //=======================================================================
526 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect(const Standard_Integer XPMin,
527 const Standard_Integer YPMin,
528 const Standard_Integer XPMax,
529 const Standard_Integer YPMax,
530 const Handle(V3d_View)& aView,
531 const Standard_Boolean updateviewer)
534 if(HasOpenedContext())
535 return myLocalContexts(myCurLocalIndex)->ShiftSelect(XPMin,YPMin,XPMax,YPMax,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;}
545 else if (aView->Viewer()==myCollectorVwr){
546 selector= myCollectorSel;
547 myWasLastMain = Standard_False;}
549 return AIS_SOP_NothingSelected;
551 selector->Pick(XPMin,YPMin,XPMax,YPMax,aView);
552 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
553 for(selector->Init();selector->More();selector->Next()){
554 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
556 AIS_SelectStatus SelStat = AIS_Selection::Select(SO);
557 Standard_Integer mod = (SelStat==AIS_SS_Added)?1:0;
558 (*((Handle(AIS_InteractiveObject)*)&SO))->State(mod);
562 HilightCurrents(updateviewer);
564 Standard_Integer NS =NbCurrents();
565 if(NS==0) return AIS_SOP_NothingSelected;
566 if(NS==1) return AIS_SOP_OneSelected;
567 return AIS_SOP_SeveralSelected;
571 //=======================================================================
572 //function : ShiftSelect
574 //=======================================================================
576 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect( const TColgp_Array1OfPnt2d& aPolyline,
577 const Handle(V3d_View)& aView,
578 const Standard_Boolean updateviewer )
580 if( HasOpenedContext() )
581 return myLocalContexts( myCurLocalIndex )->ShiftSelect( aPolyline, aView, updateviewer );
583 UnhilightCurrents( Standard_False );
584 // OCC11904 - local variables made non-static - it looks and works better like this
585 Handle(StdSelect_ViewerSelector3d) selector;
587 if( aView->Viewer() == myMainVwr ) {
589 myWasLastMain = Standard_True;
591 else if ( aView->Viewer() == myCollectorVwr ) {
592 selector= myCollectorSel;
593 myWasLastMain = Standard_False;
596 return AIS_SOP_NothingSelected;
598 selector->Pick( aPolyline, aView );
600 AIS_Selection::SetCurrentSelection( myCurrentName.ToCString() );
601 for( selector->Init(); selector->More(); selector->Next() ) {
602 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
604 AIS_SelectStatus SelStat = AIS_Selection::Select( SO );
605 Standard_Integer mod = ( SelStat == AIS_SS_Added ) ? 1 : 0;
606 (*((Handle(AIS_InteractiveObject)*)&SO))->State( mod );
610 HilightCurrents( updateviewer );
611 Standard_Integer NS = NbCurrents();
612 if( NS == 0 ) return AIS_SOP_NothingSelected;
613 if( NS == 1 ) return AIS_SOP_OneSelected;
614 return AIS_SOP_SeveralSelected;
617 //=======================================================================
618 //function : SetCurrentObject
620 //=======================================================================
622 void AIS_InteractiveContext::SetCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
623 const Standard_Boolean updateviewer)
625 // single case processing...
626 if(NbCurrents()==1 && anIObj->State()==1){
627 Quantity_NameOfColor HiCol;
628 Standard_Boolean HasHiCol;
629 if(IsHilighted(anIObj,HasHiCol,HiCol)){
630 if(HasHiCol && HiCol!= mySelectionColor) {
632 HilightWithColor(anIObj,mySelectionColor,updateviewer);
634 Hilight(anIObj,updateviewer);
643 if(!HasOpenedContext()) {
644 if(anIObj.IsNull()) return;
645 if(!myObjects.IsBound(anIObj))
646 Display(anIObj,Standard_False);
648 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
649 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
650 Handle(Standard_Transient) TR;
651 Handle(AIS_InteractiveObject) IO;
653 while (sel->More()) {
655 IO = *((Handle(AIS_InteractiveObject)*)&TR);
656 Unhilight(IO,Standard_False);
661 // added to avoid untimely viewer update...
662 AIS_Selection::ClearAndSelect(anIObj);
664 Quantity_NameOfColor HiCol;
665 Standard_Boolean HasHiCol;
666 if(IsHilighted(anIObj,HasHiCol,HiCol)){
667 if(HasHiCol && HiCol!= mySelectionColor) {
669 HilightWithColor(anIObj,mySelectionColor,Standard_False);
671 Hilight(anIObj,Standard_False);
677 HilightWithColor(anIObj,mySelectionColor,Standard_False);
679 Hilight(anIObj,Standard_False);
683 UpdateCurrentViewer();
687 cout<<"Nothing Done : Opened Local Context"<<endl;
692 //=======================================================================
693 //function : AddOrRemoveCurrentObject
695 //=======================================================================
697 void AIS_InteractiveContext::
698 AddOrRemoveCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
699 const Standard_Boolean updateviewer)
701 if(anIObj.IsNull()) return;
702 //OCC5682 to remove an object from neutral point even if Local Context is opened (Remove method)
703 if(!HasOpenedContext() /*OCC5682*/|| myObjects.IsBound(anIObj)) {
705 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
706 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
708 AIS_SelectStatus SelStat = AIS_Selection::Select(anIObj);
710 Standard_Integer mod = (SelStat==AIS_SS_Added) ? 1 : 0;
714 HilightWithColor(anIObj,mySelectionColor,Standard_False);
716 Hilight(anIObj,Standard_False);
719 Unhilight(anIObj,Standard_False);
723 UpdateCurrentViewer();
727 cout<<"Nothing Done : Opened Local Context"<<endl;
731 //=======================================================================
732 //function : UpdateCurrent
734 //=======================================================================
736 void AIS_InteractiveContext::UpdateCurrent()
741 //=======================================================================
742 //function : IsCurrent
744 //=======================================================================
746 Standard_Boolean AIS_InteractiveContext::IsCurrent(const Handle(AIS_InteractiveObject)& anIObj) const
749 if (anIObj.IsNull()) return Standard_False;
750 return (anIObj->State()==1);
752 // Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
754 // while (sel->More()) {
755 // if (anIObj == sel->Value()) return Standard_True;
758 // return Standard_False;
762 //=======================================================================
763 //function : InitCurrent
765 //=======================================================================
767 void AIS_InteractiveContext::InitCurrent()
769 AIS_Selection::Selection(myCurrentName.ToCString())->Init();
772 //=======================================================================
773 //function : MoreCurrent
775 //=======================================================================
777 Standard_Boolean AIS_InteractiveContext::MoreCurrent() const
779 return AIS_Selection::Selection(myCurrentName.ToCString())->More();
783 //=======================================================================
784 //function : NextCurrent
786 //=======================================================================
788 void AIS_InteractiveContext::NextCurrent()
790 AIS_Selection::Selection(myCurrentName.ToCString())->Next();
793 //=======================================================================
796 //=======================================================================
798 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Current() const
800 Handle(Standard_Transient) TR = AIS_Selection::Selection(myCurrentName.ToCString())->Value();
801 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
805 //=======================================================================
806 //function : FirstCurrentObject
808 //=======================================================================
809 Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstCurrentObject()
811 Handle(AIS_InteractiveObject) IO ;
819 //=======================================================================
820 //function : NbCurrents
822 //=======================================================================
823 Standard_Integer AIS_InteractiveContext::NbCurrents()
825 Standard_Integer i(0);
826 for(InitCurrent();MoreCurrent();NextCurrent())
831 //=======================================================================
832 //function : HilightCurrents
834 //=======================================================================
835 void AIS_InteractiveContext::HilightCurrents(const Standard_Boolean updateviewer)
837 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
838 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
839 Handle(Standard_Transient) TR;
840 Handle(AIS_InteractiveObject) IO;
842 while (sel->More()) {
844 IO = *((Handle(AIS_InteractiveObject)*)&TR);
846 HilightWithColor(IO,mySelectionColor,Standard_False);
848 Hilight(IO,Standard_False);
853 UpdateCurrentViewer();
856 //=======================================================================
857 //function : UnhilightCurrents
859 //=======================================================================
861 void AIS_InteractiveContext::UnhilightCurrents(const Standard_Boolean updateviewer)
863 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
864 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
865 Handle(Standard_Transient) TR;
866 Handle(AIS_InteractiveObject) IO;
868 while (sel->More()) {
870 IO = *((Handle(AIS_InteractiveObject)*)&TR);
871 Unhilight(IO,Standard_False);
875 UpdateCurrentViewer();
878 //=======================================================================
879 //function : ClearCurrents
881 //=======================================================================
883 void AIS_InteractiveContext::ClearCurrents(const Standard_Boolean updateviewer)
885 if(NbCurrents()==0) return;
886 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
887 Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
888 Handle(Standard_Transient) Tr;
889 Handle(AIS_InteractiveObject) IO;
890 for(S->Init();S->More();S->Next()){
892 IO = (*((Handle(AIS_InteractiveObject)*)&Tr));
894 Unhilight(IO,Standard_False);
896 AIS_Selection::Select();
898 UpdateCurrentViewer();
902 //=======================================================================
903 //function : HilightSelected
905 //=======================================================================
907 void AIS_InteractiveContext::HilightSelected(const Standard_Boolean updateviewer)
909 if(!HasOpenedContext()){
910 AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
911 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
912 Handle(Standard_Transient) TR;
913 Handle(AIS_InteractiveObject) IO;
915 while (sel->More()) {
917 IO = *((Handle(AIS_InteractiveObject)*)&TR);
919 HilightWithColor(IO,mySelectionColor,Standard_False);
921 Hilight(IO,Standard_False);
928 myLocalContexts(myCurLocalIndex)->HilightPicked(updateviewer);
931 UpdateCurrentViewer();
934 //=======================================================================
935 //function : UnhilightSelected
937 //=======================================================================
939 void AIS_InteractiveContext::UnhilightSelected(const Standard_Boolean updateviewer)
941 if(!HasOpenedContext()){
942 AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
943 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
944 Handle(Standard_Transient) TR;
945 Handle(AIS_InteractiveObject) IO;
947 while (sel->More()) {
949 IO = *((Handle(AIS_InteractiveObject)*)&TR);
950 Unhilight(IO,Standard_False);
954 UpdateCurrentViewer();
958 myLocalContexts(myCurLocalIndex)->UnhilightPicked(updateviewer);
963 //=======================================================================
964 //function : ClearSelected
966 //=======================================================================
968 void AIS_InteractiveContext::ClearSelected(const Standard_Boolean updateviewer)
970 if(!HasOpenedContext())
971 ClearCurrents(updateviewer);
973 myLocalContexts(myCurLocalIndex)->ClearSelected(updateviewer);
978 //=======================================================================
979 //function : SetSelectedCurrent
981 //=======================================================================
983 void AIS_InteractiveContext::SetSelectedCurrent()
988 cout<<"Not Yet Implemented"<<endl;
992 //=======================================================================
993 //function : UpdateSelection
995 //=======================================================================
997 void AIS_InteractiveContext::UpdateSelected(const Standard_Boolean updateviewer)
999 if(!HasOpenedContext()) {
1005 myLocalContexts(myCurLocalIndex)->UpdateSelected(updateviewer);
1008 //=======================================================================
1009 //function : SetCurrentObject
1011 //=======================================================================
1012 void AIS_InteractiveContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,const Standard_Boolean updateviewer)
1014 if(!HasOpenedContext())
1015 SetCurrentObject(anIObj,updateviewer);
1017 myLocalContexts(myCurLocalIndex)->SetSelected(anIObj,updateviewer);
1020 //=======================================================================
1021 //function : AddOrRemoveSelected
1023 //=======================================================================
1025 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj,
1026 const Standard_Boolean updateviewer)
1028 if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
1029 if(!HasOpenedContext())
1030 AddOrRemoveCurrentObject(anIObj,updateviewer);
1032 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(anIObj,updateviewer);
1035 //=======================================================================
1036 //function : AddOrRemoveSelected
1038 //=======================================================================
1040 void AIS_InteractiveContext::AddOrRemoveSelected(const TopoDS_Shape& aShap,
1041 const Standard_Boolean updateviewer)
1043 if(!HasOpenedContext()) {
1045 cout<<" Attempt to remove a selected shape with no opened local context"<<endl;
1050 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(aShap,updateviewer);
1051 if(updateviewer) UpdateCurrentViewer();
1054 //=======================================================================
1055 //function : AddOrRemoveSelected
1057 //=======================================================================
1059 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(SelectMgr_EntityOwner)& Own,
1060 const Standard_Boolean updateviewer)
1062 if(!HasOpenedContext()) {
1064 cout<<" Attempt to remove a selected ownr with no opened local context"<<endl;
1069 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(Own,Standard_False);
1070 if(updateviewer) UpdateCurrentViewer();
1076 //=======================================================================
1077 //function : IsSelected
1079 //=======================================================================
1081 Standard_Boolean AIS_InteractiveContext::
1082 IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const
1084 if (anIObj.IsNull()) return Standard_False;
1086 if(!HasOpenedContext())
1087 return (anIObj->State()==1);
1089 return myLocalContexts(myCurLocalIndex)->IsSelected(anIObj);
1093 //=======================================================================
1094 //function : InitSelected
1096 //=======================================================================
1098 void AIS_InteractiveContext::InitSelected()
1100 if(!HasOpenedContext())
1101 AIS_Selection::Selection(myCurrentName.ToCString())->Init();
1103 myLocalContexts(myCurLocalIndex)->InitSelected();
1106 //=======================================================================
1107 //function : MoreSelected
1109 //=======================================================================
1111 Standard_Boolean AIS_InteractiveContext::MoreSelected() const
1113 if(!HasOpenedContext())
1114 return AIS_Selection::Selection(myCurrentName.ToCString())->More();
1115 return myLocalContexts(myCurLocalIndex)->MoreSelected();
1118 //=======================================================================
1119 //function : NextSelected
1121 //=======================================================================
1123 void AIS_InteractiveContext::NextSelected()
1125 if(!HasOpenedContext())
1126 AIS_Selection::Selection(myCurrentName.ToCString())->Next();
1128 myLocalContexts(myCurLocalIndex)->NextSelected();
1131 //=======================================================================
1132 //function : HasSelectedShape
1134 //=======================================================================
1136 Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
1138 if(!HasOpenedContext()) {
1140 Handle(AIS_Shape) shape =
1141 Handle(AIS_Shape)::DownCast(SelectedInteractive());
1142 if( !shape.IsNull() ) return Standard_True;
1144 return Standard_False;
1146 return myLocalContexts(myCurLocalIndex)->HasShape();
1151 //=======================================================================
1152 //function : SelectedShape
1154 //=======================================================================
1156 TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
1159 if(!HasOpenedContext()){
1162 Handle(AIS_Shape) shape =
1163 Handle(AIS_Shape)::DownCast(SelectedInteractive());
1164 if( !shape.IsNull() ) sh = shape->Shape();
1168 return myLocalContexts(myCurLocalIndex)->SelectedShape();
1171 //=======================================================================
1172 //function : Interactive
1174 //=======================================================================
1176 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Interactive() const
1178 return SelectedInteractive();
1181 Handle(AIS_InteractiveObject) AIS_InteractiveContext::SelectedInteractive() const
1183 if(!HasOpenedContext()){
1184 Handle(Standard_Transient) TR =AIS_Selection::Selection(myCurrentName.ToCString())->Value();
1185 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
1188 return myLocalContexts(myCurLocalIndex)->SelectedInteractive();
1191 //=======================================================================
1192 //function : Interactive
1194 //=======================================================================
1196 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const
1198 if(!HasOpenedContext()){
1199 Handle(SelectMgr_EntityOwner) Ownr;
1202 return myLocalContexts(myCurLocalIndex)->SelectedOwner();
1206 //=======================================================================
1207 //function : EntityOwners
1209 //=======================================================================
1210 void AIS_InteractiveContext::EntityOwners(SelectMgr_IndexedMapOfOwner& theOwners,
1211 const Handle(AIS_InteractiveObject)& theIObj,
1212 const Standard_Integer theMode) const
1214 if ( theIObj.IsNull() )
1217 TColStd_ListOfInteger aModes;
1218 if ( theMode == -1 )
1219 ActivatedModes( theIObj, aModes );
1221 aModes.Append( theMode );
1223 TColStd_ListIteratorOfListOfInteger anItr( aModes );
1224 for (; anItr.More(); anItr.Next() )
1226 int aMode = anItr.Value();
1227 if ( !theIObj->HasSelection( aMode ) )
1230 Handle(SelectMgr_Selection) aSel = theIObj->Selection( aMode );
1232 for ( aSel->Init(); aSel->More(); aSel->Next() )
1234 Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive();
1235 if ( aEntity.IsNull() )
1238 Handle(SelectMgr_EntityOwner) aOwner =
1239 Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId());
1240 if ( !aOwner.IsNull() )
1241 theOwners.Add( aOwner );
1246 Standard_Integer AIS_InteractiveContext::NbSelected()
1248 Standard_Integer i(0);
1249 for(InitSelected();MoreSelected();NextSelected())
1254 //=======================================================================
1255 //function : HasApplicative
1257 //=======================================================================
1259 Standard_Boolean AIS_InteractiveContext::HasApplicative() const
1261 return Interactive()->HasOwner();
1264 //=======================================================================
1265 //function : Applicative
1267 //=======================================================================
1269 Handle(Standard_Transient) AIS_InteractiveContext::Applicative() const
1271 return Interactive()->GetOwner();
1276 //==================================================
1279 //==================================================
1280 Standard_Boolean AIS_InteractiveContext::HasDetected() const
1282 if(HasOpenedContext())
1283 return myLocalContexts(myCurLocalIndex)->HasDetected();
1285 return !myLastPicked.IsNull();
1288 //=======================================================================
1289 //function : HasDetectedShape
1291 //=======================================================================
1293 Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
1295 if(HasOpenedContext())
1296 return myLocalContexts(myCurLocalIndex)->HasDetectedShape();
1297 return Standard_False;
1300 //=======================================================================
1301 //function : DetectedShape
1303 //=======================================================================
1306 AIS_InteractiveContext::DetectedShape() const
1308 return myLocalContexts(myCurLocalIndex)->DetectedShape();
1311 //=======================================================================
1312 //function : DetectedInteractive
1314 //=======================================================================
1316 Handle(AIS_InteractiveObject)
1317 AIS_InteractiveContext::DetectedInteractive() const
1319 if(HasOpenedContext())
1320 return myLocalContexts(myCurLocalIndex)->DetectedInteractive();
1321 return myLastPicked;
1325 Standard_Boolean AIS_InteractiveContext::HasNextDetected() const
1327 if(!HasOpenedContext())
1328 return Standard_False; // temporaire
1330 return myLocalContexts(myCurLocalIndex)->HasNextDetected();
1335 //=======================================================================
1336 //function : DetectedOwner
1338 //=======================================================================
1339 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedOwner() const
1341 if(HasOpenedContext())
1342 return myLocalContexts(myCurLocalIndex)->DetectedOwner();
1343 Handle(SelectMgr_EntityOwner) Ownr;
1348 //=======================================================================
1349 //function : HilightNextDetected
1351 //=======================================================================
1352 Standard_Integer AIS_InteractiveContext::HilightNextDetected(const Handle(V3d_View)& V)
1354 if(!HasOpenedContext())
1356 return myLocalContexts(myCurLocalIndex)->HilightNextDetected(V);
1360 //=======================================================================
1361 //function : HilightNextDetected
1363 //=======================================================================
1364 Standard_Integer AIS_InteractiveContext::HilightPreviousDetected(const Handle(V3d_View)& V)
1366 if(!HasOpenedContext())
1368 return myLocalContexts(myCurLocalIndex)->HilightPreviousDetected(V);
1373 void AIS_InteractiveContext::Drag(
1374 const Handle(V3d_View)& aView,
1375 const Handle(AIS_InteractiveObject)& anObject,
1376 const Handle(Geom_Transformation)& aTrsf,
1377 const Standard_Boolean postConcatenate,
1378 const Standard_Boolean update,
1379 const Standard_Boolean zBuffer) {
1381 if( anObject.IsNull() || aView.IsNull() ) return;
1384 anObject->SetTransformation(aTrsf,postConcatenate,Standard_True);
1386 } else if( Visual3d_TransientManager::BeginDraw(aView->View(),
1387 zBuffer,Standard_False) ) {
1388 Handle(Prs3d_Presentation) P = anObject->Presentation();
1390 if( postConcatenate ) P->Multiply(aTrsf);
1391 else P->Transform(aTrsf);
1392 Visual3d_TransientManager::DrawStructure(P);
1394 Visual3d_TransientManager::EndDraw(Standard_True);
1400 //=======================================================================
1401 //function : InitDetected
1403 //=======================================================================
1404 void AIS_InteractiveContext::InitDetected()
1406 if(HasOpenedContext())
1408 myLocalContexts(myCurLocalIndex)->InitDetected();
1412 if(myAISDetectedSeq.Length() != 0)
1413 myAISCurDetected = 1;
1417 //=======================================================================
1418 //function : MoreDetected
1420 //=======================================================================
1421 Standard_Boolean AIS_InteractiveContext::MoreDetected() const
1423 if(HasOpenedContext())
1424 return myLocalContexts(myCurLocalIndex)->MoreDetected();
1426 return (myAISCurDetected>0 &&myAISCurDetected <= myAISDetectedSeq.Length()) ?
1427 Standard_True : Standard_False;
1430 //=======================================================================
1431 //function : NextDetected
1433 //=======================================================================
1434 void AIS_InteractiveContext::NextDetected()
1436 if(HasOpenedContext())
1438 myLocalContexts(myCurLocalIndex)->NextDetected();
1445 //=======================================================================
1446 //function : DetectedCurrentShape
1448 //=======================================================================
1450 const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
1452 if(HasOpenedContext())
1453 return myLocalContexts(myCurLocalIndex)->DetectedCurrentShape();
1455 static TopoDS_Shape bidsh;
1456 if(myAISCurDetected > 0 &&
1457 myAISCurDetected <= myAISDetectedSeq.Length())
1458 return Handle(AIS_Shape)::DownCast(myAISDetectedSeq(myAISCurDetected))->Shape();
1462 //=======================================================================
1463 //function : DetectedCurrentObject
1465 //=======================================================================
1467 Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const {
1468 if(HasOpenedContext())
1469 return myLocalContexts(myCurLocalIndex)->DetectedCurrentObject();
1471 Handle(AIS_InteractiveObject) aBad;
1473 if(myAISCurDetected > 0 &&
1474 myAISCurDetected <= myAISDetectedSeq.Length())
1475 return myAISDetectedSeq(myAISCurDetected);