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;
201 // si c'est le meme qu'au coup precedent -> fin
202 // Does nothing if previously detected object is equal to the current one
203 if ( selector->OnePicked()->Selectable() == myLastPicked )
204 return AIS_SOD_OnlyOneDetected;
205 //si le precedent est un objet courant, on ne le desilighte pas, sinon si
207 // Previously detected object is unhilighted if it is not selected or hilighted
208 // with selection color if it is selected. Such highlighting with selection color
209 // is needed only if myToHilightSelected flag is true. In this case previously detected
210 // object has been already highlighted with myHilightColor during previous MoveTo()
211 // method call. As result it is necessary to rehighligt it with mySelectionColor.
212 if ( !myLastPicked.IsNull() )
214 Standard_Integer HiMod =
215 myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
216 if ( myLastPicked->State() != 1 )
218 pmgr->Unhighlight( myLastPicked, HiMod );
219 UpdVwr = Standard_True;
221 else if ( myToHilightSelected )
223 pmgr->Color( myLastPicked, mySelectionColor, HiMod );
224 UpdVwr = Standard_True;
228 // Initialize myLastPicked field with currently detected object
229 Handle(SelectMgr_SelectableObject) SO = selector->OnePicked()->Selectable();
230 myLastPicked = *((Handle(AIS_InteractiveObject)*)&SO);
233 myLastinMain = myLastPicked;
235 myLastinColl = myLastPicked;
236 // si l'objet detecte n'est pas courant, on le hilighte...
238 // Highlight detected object if it is not selected or myToHilightSelected flag is true
239 if ( !myLastPicked.IsNull() &&
240 ( myLastPicked->State()!= 1 || myToHilightSelected ) )
242 if ( myLastPicked->State()!= 1 )
245 Standard_Integer HiMod =
246 myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
247 pmgr->Color( myLastPicked, myHilightColor, HiMod );
248 UpdVwr = Standard_True;
251 if ( myLastPicked->State()==1 )
252 TheStat = AIS_SOD_Selected;
256 // Previously detected object is unhilighted if it is not selected or hilighted
257 // with selection color if it is selected.
258 TheStat = AIS_SOD_Nothing;
259 if ( !myLastPicked.IsNull() )
261 Standard_Integer HiMod =
262 myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
263 if ( myLastPicked->State() != 1 )
265 pmgr->Unhighlight( myLastPicked, HiMod );
266 UpdVwr = Standard_True;
268 else if ( myToHilightSelected )
270 pmgr->Color( myLastPicked, mySelectionColor, HiMod );
271 UpdVwr = Standard_True;
276 myLastinMain.Nullify();
278 myLastinColl.Nullify();
281 if(UpdVwr) aView->Viewer()->Update();
282 myLastPicked.Nullify();
284 mylastmoveview = aView;
288 //=======================================================================
291 //=======================================================================
293 AIS_StatusOfPick AIS_InteractiveContext::Select(const Standard_Integer XPMin,
294 const Standard_Integer YPMin,
295 const Standard_Integer XPMax,
296 const Standard_Integer YPMax,
297 const Handle(V3d_View)& aView,
298 const Standard_Boolean updateviewer)
300 // on prend tous les objets detectes par le selecteur, on vide les precedents objets courants,
301 // on met les nouveaux...
303 if(HasOpenedContext())
304 return myLocalContexts(myCurLocalIndex)->Select(XPMin,YPMin,XPMax,YPMax,aView,updateviewer);
306 ClearCurrents(Standard_False);
307 // OCC11904 - local variables made non-static - it looks and works better like this
308 Handle(StdSelect_ViewerSelector3d) selector;
310 if(aView->Viewer()== myMainVwr) {
312 myWasLastMain = Standard_True;}
314 else if (aView->Viewer()==myCollectorVwr){
315 selector= myCollectorSel;
316 myWasLastMain = Standard_False;}
319 selector->Pick(XPMin,YPMin,XPMax,YPMax,aView);
320 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
323 AIS_MapOfInteractive theSelectedObj;
324 for( selector->Init(); selector->More(); selector->Next() )
326 Handle( AIS_InteractiveObject ) anObj =
327 Handle( AIS_InteractiveObject )::DownCast( selector->Picked()->Selectable() );
328 if( !anObj.IsNull() )
329 theSelectedObj.Add( anObj );
331 AIS_MapIteratorOfMapOfInteractive anIt( theSelectedObj );
332 for( ; anIt.More(); anIt.Next() )
334 AIS_Selection::Select( anIt.Key() );
335 anIt.Key()->State(1);
338 for(selector->Init();selector->More();selector->Next()){
339 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
342 AIS_Selection::Select(SO);
343 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
345 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
346 AIS_Selection::Select(SO);
352 HilightCurrents(updateviewer);
354 Standard_Integer NS = NbCurrents();
355 if(NS==0) return AIS_SOP_NothingSelected;
356 if(NS==1) return AIS_SOP_OneSelected;
357 return AIS_SOP_SeveralSelected;
361 //=======================================================================
363 //purpose : Selection by polyline
364 //=======================================================================
366 AIS_StatusOfPick AIS_InteractiveContext::Select(const TColgp_Array1OfPnt2d& aPolyline,
367 const Handle(V3d_View)& aView,
368 const Standard_Boolean updateviewer)
370 // on prend tous les objets detectes par le selecteur, on vide les precedents objets courants,
371 // on met les nouveaux...
373 if(HasOpenedContext())
374 return myLocalContexts(myCurLocalIndex)->Select(aPolyline,aView,updateviewer);
376 ClearCurrents(Standard_False);
377 // OCC11904 - local variables made non-static - it looks and works better like this
378 Handle(StdSelect_ViewerSelector3d) selector;
380 if(aView->Viewer()== myMainVwr) {
382 myWasLastMain = Standard_True;}
384 else if (aView->Viewer()==myCollectorVwr){
385 selector= myCollectorSel;
386 myWasLastMain = Standard_False;}
389 selector->Pick(aPolyline,aView);
390 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
394 AIS_MapOfInteractive theSelectedObj;
395 for( selector->Init(); selector->More(); selector->Next() )
397 Handle( AIS_InteractiveObject ) anObj =
398 Handle( AIS_InteractiveObject )::DownCast( selector->Picked()->Selectable() );
399 if( !anObj.IsNull() )
400 theSelectedObj.Add( anObj );
402 AIS_MapIteratorOfMapOfInteractive anIt( theSelectedObj );
403 for( ; anIt.More(); anIt.Next() )
405 AIS_Selection::Select( anIt.Key() );
406 anIt.Key()->State(1);
409 for(selector->Init();selector->More();selector->Next()){
410 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
413 AIS_Selection::Select(SO);
414 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
416 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
417 AIS_Selection::Select(SO);
422 HilightCurrents(updateviewer);
424 Standard_Integer NS = NbCurrents();
425 if(NS==0) return AIS_SOP_NothingSelected;
426 if(NS==1) return AIS_SOP_OneSelected;
427 return AIS_SOP_SeveralSelected;
431 //=======================================================================
434 //=======================================================================
436 AIS_StatusOfPick AIS_InteractiveContext::Select(const Standard_Boolean updateviewer)
438 if(HasOpenedContext()){
440 return myLocalContexts(myCurLocalIndex)->Select(updateviewer);
442 // on a picke dans le collecteur, il faut faire un traitement special...
444 myLocalContexts(myCurLocalIndex)->SetSelected(myLastPicked,updateviewer);
445 return AIS_SOP_OneSelected;
448 // AIS_StatusOfPick PS(AIS_SOP_NothingSelected);
449 if(myWasLastMain && !myLastinMain.IsNull()){
450 if(myLastinMain->State()!=1){
451 SetCurrentObject(myLastinMain,Standard_False);
453 UpdateCurrentViewer();}
455 else if (!myWasLastMain && !myLastinColl.IsNull()){
456 if(myLastinColl->State()!=1){
457 SetCurrentObject(myLastinColl,Standard_False);
462 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
463 Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
464 Handle(Standard_Transient) Tr;
465 Handle(AIS_InteractiveObject) IO;
467 for(S->Init();S->More();S->Next()){
469 IO = (*((Handle(AIS_InteractiveObject)*)&Tr));
471 Unhilight(IO,Standard_False);
472 if(myObjects.IsBound(IO)){ // anti-plantage-rob
473 if(myObjects(IO)->IsSubIntensityOn())
474 HilightWithColor(IO,mySubIntensity,Standard_False);
478 AIS_Selection::Select();
481 UpdateCurrentViewer();
486 Standard_Integer NS = NbCurrents();
487 if(NS==0) return AIS_SOP_NothingSelected;
488 if(NS==1) return AIS_SOP_OneSelected;
489 return AIS_SOP_SeveralSelected;
492 //=======================================================================
493 //function : ShiftSelect
495 //=======================================================================
497 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect(const Standard_Boolean updateviewer)
499 if(HasOpenedContext()){
501 return myLocalContexts(myCurLocalIndex)->ShiftSelect(updateviewer);
503 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(myLastPicked,updateviewer);
504 Standard_Integer NS =NbSelected();
505 if(NS==0) return AIS_SOP_NothingSelected;
506 if(NS==1) return AIS_SOP_OneSelected;
507 return AIS_SOP_SeveralSelected;
510 if(myWasLastMain && !myLastinMain.IsNull())
511 AddOrRemoveCurrentObject(myLastinMain,updateviewer);
512 else if (!myWasLastMain && !myLastinColl.IsNull())
513 AddOrRemoveCurrentObject(myLastinColl,updateviewer);
516 Standard_Integer NS = NbCurrents();
517 if(NS==0) return AIS_SOP_NothingSelected;
518 if(NS==1) return AIS_SOP_OneSelected;
519 return AIS_SOP_SeveralSelected;
523 //=======================================================================
524 //function : ShiftSelect
526 //=======================================================================
528 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect(const Standard_Integer XPMin,
529 const Standard_Integer YPMin,
530 const Standard_Integer XPMax,
531 const Standard_Integer YPMax,
532 const Handle(V3d_View)& aView,
533 const Standard_Boolean updateviewer)
536 if(HasOpenedContext())
537 return myLocalContexts(myCurLocalIndex)->ShiftSelect(XPMin,YPMin,XPMax,YPMax,aView,updateviewer);
539 UnhilightCurrents(Standard_False);
540 // OCC11904 - local variables made non-static - it looks and works better like this
541 Handle(StdSelect_ViewerSelector3d) selector;
543 if(aView->Viewer()== myMainVwr) {
545 myWasLastMain = Standard_True;}
547 else if (aView->Viewer()==myCollectorVwr){
548 selector= myCollectorSel;
549 myWasLastMain = Standard_False;}
551 return AIS_SOP_NothingSelected;
553 selector->Pick(XPMin,YPMin,XPMax,YPMax,aView);
554 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
555 for(selector->Init();selector->More();selector->Next()){
556 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
558 AIS_SelectStatus SelStat = AIS_Selection::Select(SO);
559 Standard_Integer mod = (SelStat==AIS_SS_Added)?1:0;
560 (*((Handle(AIS_InteractiveObject)*)&SO))->State(mod);
564 HilightCurrents(updateviewer);
566 Standard_Integer NS =NbCurrents();
567 if(NS==0) return AIS_SOP_NothingSelected;
568 if(NS==1) return AIS_SOP_OneSelected;
569 return AIS_SOP_SeveralSelected;
573 //=======================================================================
574 //function : ShiftSelect
576 //=======================================================================
578 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect( const TColgp_Array1OfPnt2d& aPolyline,
579 const Handle(V3d_View)& aView,
580 const Standard_Boolean updateviewer )
582 if( HasOpenedContext() )
583 return myLocalContexts( myCurLocalIndex )->ShiftSelect( aPolyline, aView, updateviewer );
585 UnhilightCurrents( Standard_False );
586 // OCC11904 - local variables made non-static - it looks and works better like this
587 Handle(StdSelect_ViewerSelector3d) selector;
589 if( aView->Viewer() == myMainVwr ) {
591 myWasLastMain = Standard_True;
593 else if ( aView->Viewer() == myCollectorVwr ) {
594 selector= myCollectorSel;
595 myWasLastMain = Standard_False;
598 return AIS_SOP_NothingSelected;
600 selector->Pick( aPolyline, aView );
602 AIS_Selection::SetCurrentSelection( myCurrentName.ToCString() );
603 for( selector->Init(); selector->More(); selector->Next() ) {
604 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
606 AIS_SelectStatus SelStat = AIS_Selection::Select( SO );
607 Standard_Integer mod = ( SelStat == AIS_SS_Added ) ? 1 : 0;
608 (*((Handle(AIS_InteractiveObject)*)&SO))->State( mod );
612 HilightCurrents( updateviewer );
613 Standard_Integer NS = NbCurrents();
614 if( NS == 0 ) return AIS_SOP_NothingSelected;
615 if( NS == 1 ) return AIS_SOP_OneSelected;
616 return AIS_SOP_SeveralSelected;
619 //=======================================================================
620 //function : SetCurrentObject
622 //=======================================================================
624 void AIS_InteractiveContext::SetCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
625 const Standard_Boolean updateviewer)
627 // traitement d'un cas singulier...
628 if(NbCurrents()==1 && anIObj->State()==1){
629 Quantity_NameOfColor HiCol;
630 Standard_Boolean HasHiCol;
631 if(IsHilighted(anIObj,HasHiCol,HiCol)){
632 if(HasHiCol && HiCol!= mySelectionColor) {
634 HilightWithColor(anIObj,mySelectionColor,updateviewer);
636 Hilight(anIObj,updateviewer);
645 if(!HasOpenedContext()) {
646 if(anIObj.IsNull()) return;
647 if(!myObjects.IsBound(anIObj))
648 Display(anIObj,Standard_False);
650 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
651 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
652 Handle(Standard_Transient) TR;
653 Handle(AIS_InteractiveObject) IO;
655 while (sel->More()) {
657 IO = *((Handle(AIS_InteractiveObject)*)&TR);
658 Unhilight(IO,Standard_False);
663 // ajout pour ne pas faire d'updateviewer intempestif...
664 AIS_Selection::ClearAndSelect(anIObj);
666 Quantity_NameOfColor HiCol;
667 Standard_Boolean HasHiCol;
668 if(IsHilighted(anIObj,HasHiCol,HiCol)){
669 if(HasHiCol && HiCol!= mySelectionColor) {
671 HilightWithColor(anIObj,mySelectionColor,Standard_False);
673 Hilight(anIObj,Standard_False);
679 HilightWithColor(anIObj,mySelectionColor,Standard_False);
681 Hilight(anIObj,Standard_False);
685 UpdateCurrentViewer();
689 cout<<"Nothing Done : Opened Local Context"<<endl;
694 //=======================================================================
695 //function : AddOrRemoveCurrentObject
697 //=======================================================================
699 void AIS_InteractiveContext::
700 AddOrRemoveCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
701 const Standard_Boolean updateviewer)
703 if(anIObj.IsNull()) return;
704 //OCC5682 to remove an object from neutral point even if Local Context is opened (Remove method)
705 if(!HasOpenedContext() /*OCC5682*/|| myObjects.IsBound(anIObj)) {
707 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
708 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
710 AIS_SelectStatus SelStat = AIS_Selection::Select(anIObj);
712 Standard_Integer mod = (SelStat==AIS_SS_Added) ? 1 : 0;
716 HilightWithColor(anIObj,mySelectionColor,Standard_False);
718 Hilight(anIObj,Standard_False);
721 Unhilight(anIObj,Standard_False);
725 UpdateCurrentViewer();
729 cout<<"Nothing Done : Opened Local Context"<<endl;
733 //=======================================================================
734 //function : UpdateCurrent
736 //=======================================================================
738 void AIS_InteractiveContext::UpdateCurrent()
743 //=======================================================================
744 //function : IsCurrent
746 //=======================================================================
748 Standard_Boolean AIS_InteractiveContext::IsCurrent(const Handle(AIS_InteractiveObject)& anIObj) const
751 if (anIObj.IsNull()) return Standard_False;
752 return (anIObj->State()==1);
754 // Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
756 // while (sel->More()) {
757 // if (anIObj == sel->Value()) return Standard_True;
760 // return Standard_False;
764 //=======================================================================
765 //function : InitCurrent
767 //=======================================================================
769 void AIS_InteractiveContext::InitCurrent()
771 AIS_Selection::Selection(myCurrentName.ToCString())->Init();
774 //=======================================================================
775 //function : MoreCurrent
777 //=======================================================================
779 Standard_Boolean AIS_InteractiveContext::MoreCurrent() const
781 return AIS_Selection::Selection(myCurrentName.ToCString())->More();
785 //=======================================================================
786 //function : NextCurrent
788 //=======================================================================
790 void AIS_InteractiveContext::NextCurrent()
792 AIS_Selection::Selection(myCurrentName.ToCString())->Next();
795 //=======================================================================
798 //=======================================================================
800 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Current() const
802 Handle(Standard_Transient) TR = AIS_Selection::Selection(myCurrentName.ToCString())->Value();
803 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
807 //=======================================================================
808 //function : FirstCurrentObject
810 //=======================================================================
811 Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstCurrentObject()
813 Handle(AIS_InteractiveObject) IO ;
821 //=======================================================================
822 //function : NbCurrents
824 //=======================================================================
825 Standard_Integer AIS_InteractiveContext::NbCurrents()
827 Standard_Integer i(0);
828 for(InitCurrent();MoreCurrent();NextCurrent())
833 //=======================================================================
834 //function : HilightCurrents
836 //=======================================================================
837 void AIS_InteractiveContext::HilightCurrents(const Standard_Boolean updateviewer)
839 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
840 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
841 Handle(Standard_Transient) TR;
842 Handle(AIS_InteractiveObject) IO;
844 while (sel->More()) {
846 IO = *((Handle(AIS_InteractiveObject)*)&TR);
848 HilightWithColor(IO,mySelectionColor,Standard_False);
850 Hilight(IO,Standard_False);
855 UpdateCurrentViewer();
858 //=======================================================================
859 //function : UnhilightCurrents
861 //=======================================================================
863 void AIS_InteractiveContext::UnhilightCurrents(const Standard_Boolean updateviewer)
865 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
866 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
867 Handle(Standard_Transient) TR;
868 Handle(AIS_InteractiveObject) IO;
870 while (sel->More()) {
872 IO = *((Handle(AIS_InteractiveObject)*)&TR);
873 Unhilight(IO,Standard_False);
877 UpdateCurrentViewer();
880 //=======================================================================
881 //function : ClearCurrents
883 //=======================================================================
885 void AIS_InteractiveContext::ClearCurrents(const Standard_Boolean updateviewer)
887 if(NbCurrents()==0) return;
888 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
889 Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
890 Handle(Standard_Transient) Tr;
891 Handle(AIS_InteractiveObject) IO;
892 for(S->Init();S->More();S->Next()){
894 IO = (*((Handle(AIS_InteractiveObject)*)&Tr));
896 Unhilight(IO,Standard_False);
898 AIS_Selection::Select();
900 UpdateCurrentViewer();
904 //=======================================================================
905 //function : HilightSelected
907 //=======================================================================
909 void AIS_InteractiveContext::HilightSelected(const Standard_Boolean updateviewer)
911 if(!HasOpenedContext()){
912 AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
913 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
914 Handle(Standard_Transient) TR;
915 Handle(AIS_InteractiveObject) IO;
917 while (sel->More()) {
919 IO = *((Handle(AIS_InteractiveObject)*)&TR);
921 HilightWithColor(IO,mySelectionColor,Standard_False);
923 Hilight(IO,Standard_False);
930 myLocalContexts(myCurLocalIndex)->HilightPicked(updateviewer);
933 UpdateCurrentViewer();
936 //=======================================================================
937 //function : UnhilightSelected
939 //=======================================================================
941 void AIS_InteractiveContext::UnhilightSelected(const Standard_Boolean updateviewer)
943 if(!HasOpenedContext()){
944 AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
945 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
946 Handle(Standard_Transient) TR;
947 Handle(AIS_InteractiveObject) IO;
949 while (sel->More()) {
951 IO = *((Handle(AIS_InteractiveObject)*)&TR);
952 Unhilight(IO,Standard_False);
956 UpdateCurrentViewer();
960 myLocalContexts(myCurLocalIndex)->UnhilightPicked(updateviewer);
965 //=======================================================================
966 //function : ClearSelected
968 //=======================================================================
970 void AIS_InteractiveContext::ClearSelected(const Standard_Boolean updateviewer)
972 if(!HasOpenedContext())
973 ClearCurrents(updateviewer);
975 myLocalContexts(myCurLocalIndex)->ClearSelected(updateviewer);
980 //=======================================================================
981 //function : SetSelectedCurrent
983 //=======================================================================
985 void AIS_InteractiveContext::SetSelectedCurrent()
990 cout<<"Not Yet Implemented"<<endl;
994 //=======================================================================
995 //function : UpdateSelection
997 //=======================================================================
999 void AIS_InteractiveContext::UpdateSelected(const Standard_Boolean updateviewer)
1001 if(!HasOpenedContext()) {
1007 myLocalContexts(myCurLocalIndex)->UpdateSelected(updateviewer);
1010 //=======================================================================
1011 //function : SetCurrentObject
1013 //=======================================================================
1014 void AIS_InteractiveContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,const Standard_Boolean updateviewer)
1016 if(!HasOpenedContext())
1017 SetCurrentObject(anIObj,updateviewer);
1019 myLocalContexts(myCurLocalIndex)->SetSelected(anIObj,updateviewer);
1022 //=======================================================================
1023 //function : AddOrRemoveSelected
1025 //=======================================================================
1027 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj,
1028 const Standard_Boolean updateviewer)
1030 if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
1031 if(!HasOpenedContext())
1032 AddOrRemoveCurrentObject(anIObj,updateviewer);
1034 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(anIObj,updateviewer);
1037 //=======================================================================
1038 //function : AddOrRemoveSelected
1040 //=======================================================================
1042 void AIS_InteractiveContext::AddOrRemoveSelected(const TopoDS_Shape& aShap,
1043 const Standard_Boolean updateviewer)
1045 if(!HasOpenedContext()) {
1047 cout<<" Attempt to remove a selected shape with no opened local context"<<endl;
1052 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(aShap,updateviewer);
1053 if(updateviewer) UpdateCurrentViewer();
1056 //=======================================================================
1057 //function : AddOrRemoveSelected
1059 //=======================================================================
1061 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(SelectMgr_EntityOwner)& Own,
1062 const Standard_Boolean updateviewer)
1064 if(!HasOpenedContext()) {
1066 cout<<" Attempt to remove a selected ownr with no opened local context"<<endl;
1071 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(Own,Standard_False);
1072 if(updateviewer) UpdateCurrentViewer();
1078 //=======================================================================
1079 //function : IsSelected
1081 //=======================================================================
1083 Standard_Boolean AIS_InteractiveContext::
1084 IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const
1086 if (anIObj.IsNull()) return Standard_False;
1088 if(!HasOpenedContext())
1089 return (anIObj->State()==1);
1091 return myLocalContexts(myCurLocalIndex)->IsSelected(anIObj);
1095 //=======================================================================
1096 //function : InitSelected
1098 //=======================================================================
1100 void AIS_InteractiveContext::InitSelected()
1102 if(!HasOpenedContext())
1103 AIS_Selection::Selection(myCurrentName.ToCString())->Init();
1105 myLocalContexts(myCurLocalIndex)->InitSelected();
1108 //=======================================================================
1109 //function : MoreSelected
1111 //=======================================================================
1113 Standard_Boolean AIS_InteractiveContext::MoreSelected() const
1115 if(!HasOpenedContext())
1116 return AIS_Selection::Selection(myCurrentName.ToCString())->More();
1117 return myLocalContexts(myCurLocalIndex)->MoreSelected();
1120 //=======================================================================
1121 //function : NextSelected
1123 //=======================================================================
1125 void AIS_InteractiveContext::NextSelected()
1127 if(!HasOpenedContext())
1128 AIS_Selection::Selection(myCurrentName.ToCString())->Next();
1130 myLocalContexts(myCurLocalIndex)->NextSelected();
1133 //=======================================================================
1134 //function : HasSelectedShape
1136 //=======================================================================
1138 Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
1140 if(!HasOpenedContext()) {
1142 Handle(AIS_Shape) shape =
1143 Handle(AIS_Shape)::DownCast(SelectedInteractive());
1144 if( !shape.IsNull() ) return Standard_True;
1146 return Standard_False;
1148 return myLocalContexts(myCurLocalIndex)->HasShape();
1153 //=======================================================================
1154 //function : SelectedShape
1156 //=======================================================================
1158 TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
1161 if(!HasOpenedContext()){
1164 Handle(AIS_Shape) shape =
1165 Handle(AIS_Shape)::DownCast(SelectedInteractive());
1166 if( !shape.IsNull() ) sh = shape->Shape();
1170 return myLocalContexts(myCurLocalIndex)->SelectedShape();
1173 //=======================================================================
1174 //function : Interactive
1176 //=======================================================================
1178 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Interactive() const
1180 return SelectedInteractive();
1183 Handle(AIS_InteractiveObject) AIS_InteractiveContext::SelectedInteractive() const
1185 if(!HasOpenedContext()){
1186 Handle(Standard_Transient) TR =AIS_Selection::Selection(myCurrentName.ToCString())->Value();
1187 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
1190 return myLocalContexts(myCurLocalIndex)->SelectedInteractive();
1193 //=======================================================================
1194 //function : Interactive
1196 //=======================================================================
1198 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const
1200 if(!HasOpenedContext()){
1201 Handle(SelectMgr_EntityOwner) Ownr;
1204 return myLocalContexts(myCurLocalIndex)->SelectedOwner();
1208 //=======================================================================
1209 //function : EntityOwners
1211 //=======================================================================
1212 void AIS_InteractiveContext::EntityOwners(SelectMgr_IndexedMapOfOwner& theOwners,
1213 const Handle(AIS_InteractiveObject)& theIObj,
1214 const Standard_Integer theMode) const
1216 if ( theIObj.IsNull() )
1219 TColStd_ListOfInteger aModes;
1220 if ( theMode == -1 )
1221 ActivatedModes( theIObj, aModes );
1223 aModes.Append( theMode );
1225 TColStd_ListIteratorOfListOfInteger anItr( aModes );
1226 for (; anItr.More(); anItr.Next() )
1228 int aMode = anItr.Value();
1229 if ( !theIObj->HasSelection( aMode ) )
1232 Handle(SelectMgr_Selection) aSel = theIObj->Selection( aMode );
1234 for ( aSel->Init(); aSel->More(); aSel->Next() )
1236 Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive();
1237 if ( aEntity.IsNull() )
1240 Handle(SelectMgr_EntityOwner) aOwner =
1241 Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId());
1242 if ( !aOwner.IsNull() )
1243 theOwners.Add( aOwner );
1248 Standard_Integer AIS_InteractiveContext::NbSelected()
1250 Standard_Integer i(0);
1251 for(InitSelected();MoreSelected();NextSelected())
1256 //=======================================================================
1257 //function : HasApplicative
1259 //=======================================================================
1261 Standard_Boolean AIS_InteractiveContext::HasApplicative() const
1263 return Interactive()->HasOwner();
1266 //=======================================================================
1267 //function : Applicative
1269 //=======================================================================
1271 Handle(Standard_Transient) AIS_InteractiveContext::Applicative() const
1273 return Interactive()->GetOwner();
1278 //==================================================
1281 //==================================================
1282 Standard_Boolean AIS_InteractiveContext::HasDetected() const
1284 if(HasOpenedContext())
1285 return myLocalContexts(myCurLocalIndex)->HasDetected();
1287 return !myLastPicked.IsNull();
1290 //=======================================================================
1291 //function : HasDetectedShape
1293 //=======================================================================
1295 Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
1297 if(HasOpenedContext())
1298 return myLocalContexts(myCurLocalIndex)->HasDetectedShape();
1299 return Standard_False;
1302 //=======================================================================
1303 //function : DetectedShape
1305 //=======================================================================
1308 AIS_InteractiveContext::DetectedShape() const
1310 return myLocalContexts(myCurLocalIndex)->DetectedShape();
1313 //=======================================================================
1314 //function : DetectedInteractive
1316 //=======================================================================
1318 Handle(AIS_InteractiveObject)
1319 AIS_InteractiveContext::DetectedInteractive() const
1321 if(HasOpenedContext())
1322 return myLocalContexts(myCurLocalIndex)->DetectedInteractive();
1323 return myLastPicked;
1327 Standard_Boolean AIS_InteractiveContext::HasNextDetected() const
1329 if(!HasOpenedContext())
1330 return Standard_False; // temporaire
1332 return myLocalContexts(myCurLocalIndex)->HasNextDetected();
1337 //=======================================================================
1338 //function : DetectedOwner
1340 //=======================================================================
1341 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedOwner() const
1343 if(HasOpenedContext())
1344 return myLocalContexts(myCurLocalIndex)->DetectedOwner();
1345 Handle(SelectMgr_EntityOwner) Ownr;
1350 //=======================================================================
1351 //function : HilightNextDetected
1353 //=======================================================================
1354 Standard_Integer AIS_InteractiveContext::HilightNextDetected(const Handle(V3d_View)& V)
1356 if(!HasOpenedContext())
1358 return myLocalContexts(myCurLocalIndex)->HilightNextDetected(V);
1362 //=======================================================================
1363 //function : HilightNextDetected
1365 //=======================================================================
1366 Standard_Integer AIS_InteractiveContext::HilightPreviousDetected(const Handle(V3d_View)& V)
1368 if(!HasOpenedContext())
1370 return myLocalContexts(myCurLocalIndex)->HilightPreviousDetected(V);
1375 void AIS_InteractiveContext::Drag(
1376 const Handle(V3d_View)& aView,
1377 const Handle(AIS_InteractiveObject)& anObject,
1378 const Handle(Geom_Transformation)& aTrsf,
1379 const Standard_Boolean postConcatenate,
1380 const Standard_Boolean update,
1381 const Standard_Boolean zBuffer) {
1383 if( anObject.IsNull() || aView.IsNull() ) return;
1386 anObject->SetTransformation(aTrsf,postConcatenate,Standard_True);
1388 } else if( Visual3d_TransientManager::BeginDraw(aView->View(),
1389 zBuffer,Standard_False) ) {
1390 Handle(Prs3d_Presentation) P = anObject->Presentation();
1392 if( postConcatenate ) P->Multiply(aTrsf);
1393 else P->Transform(aTrsf);
1394 Visual3d_TransientManager::DrawStructure(P);
1396 Visual3d_TransientManager::EndDraw(Standard_True);
1402 //=======================================================================
1403 //function : InitDetected
1405 //=======================================================================
1406 void AIS_InteractiveContext::InitDetected()
1408 if(HasOpenedContext())
1410 myLocalContexts(myCurLocalIndex)->InitDetected();
1414 if(myAISDetectedSeq.Length() != 0)
1415 myAISCurDetected = 1;
1419 //=======================================================================
1420 //function : MoreDetected
1422 //=======================================================================
1423 Standard_Boolean AIS_InteractiveContext::MoreDetected() const
1425 if(HasOpenedContext())
1426 return myLocalContexts(myCurLocalIndex)->MoreDetected();
1428 return (myAISCurDetected>0 &&myAISCurDetected <= myAISDetectedSeq.Length()) ?
1429 Standard_True : Standard_False;
1432 //=======================================================================
1433 //function : NextDetected
1435 //=======================================================================
1436 void AIS_InteractiveContext::NextDetected()
1438 if(HasOpenedContext())
1440 myLocalContexts(myCurLocalIndex)->NextDetected();
1447 //=======================================================================
1448 //function : DetectedCurrentShape
1450 //=======================================================================
1452 const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
1454 if(HasOpenedContext())
1455 return myLocalContexts(myCurLocalIndex)->DetectedCurrentShape();
1457 static TopoDS_Shape bidsh;
1458 if(myAISCurDetected > 0 &&
1459 myAISCurDetected <= myAISDetectedSeq.Length())
1460 return Handle(AIS_Shape)::DownCast(myAISDetectedSeq(myAISCurDetected))->Shape();
1464 //=======================================================================
1465 //function : DetectedCurrentObject
1467 //=======================================================================
1469 Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const {
1470 if(HasOpenedContext())
1471 return myLocalContexts(myCurLocalIndex)->DetectedCurrentObject();
1473 Handle(AIS_InteractiveObject) aBad;
1475 if(myAISCurDetected > 0 &&
1476 myAISCurDetected <= myAISDetectedSeq.Length())
1477 return myAISDetectedSeq(myAISCurDetected);