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 IMP150501 //GG_150501 CADPAK_V2 Add Drag() method
26 #define IMP160701 //ZSV Add InitDetected(),MoreDetected(),NextDetected(),
27 // DetectedCurrentShape(),DetectedCurrentObject()
30 #define OCC138 //VTN Avoding infinit loop in AddOrRemoveCurrentObject method.
34 #include <AIS_InteractiveContext.jxx>
35 #include <SelectMgr_EntityOwner.hxx>
36 #include <AIS_Selection.hxx>
37 #include <AIS_StatusOfDetection.hxx>
38 #include <AIS_StatusOfPick.hxx>
40 #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
41 #include <AIS_LocalContext.hxx>
42 #include <AIS_GlobalStatus.hxx>
43 #include <AIS_Shape.hxx>
45 #include <V3d_Light.hxx>
46 #include <V3d_PositionalLight.hxx>
47 #include <V3d_SpotLight.hxx>
48 #include <V3d_DirectionalLight.hxx>
49 #include <V3d_AmbientLight.hxx>
51 #include <TColStd_ListIteratorOfListOfInteger.hxx>
52 #include <SelectMgr_Selection.hxx>
53 #include <SelectBasics_SensitiveEntity.hxx>
56 #include <Visual3d_TransientManager.hxx>
57 #include <Prs3d_Presentation.hxx>
61 #include <AIS_MapOfInteractive.hxx>
62 #include <AIS_MapIteratorOfMapOfInteractive.hxx>
67 static void InfoOnLight(const Handle(V3d_View) aView)
69 Standard_Real V1=0.,V2=0.,V3=0.;
70 Standard_Integer IndexOfLit(0);
72 static Standard_Boolean FirstTime (Standard_True);
75 FirstTime = Standard_False;
76 for (aView->InitActiveLights();aView->MoreActiveLights();aView->NextActiveLights()){
78 cout<<"lumiere no "<<IndexOfLit<<"\n************\n\t";
79 Handle(V3d_Light) Li = aView->ActiveLight();
80 Quantity_NameOfColor Col;
82 cout<<"Color :"<<Standard_Integer(Col)<<"\n\t"<<endl;
89 // Handle(V3d_AmbientLight)::DownCast(Li)->DisplayPosition(V1,V2,V3);
90 cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl;
95 cout<<" DIRECTIONAL\n\t";
96 Handle(V3d_DirectionalLight)::DownCast(Li)->DisplayPosition(V1,V2,V3);
97 cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl;
98 Handle(V3d_DirectionalLight)::DownCast(Li)->Direction(V1,V2,V3);
99 cout<<"Direction : V1 = "<<V1<<" V2 = "<<V2<<" V3 = "<<V3<<endl;
105 cout<<" POSITIONAL\n\t";
106 Handle(V3d_PositionalLight)::DownCast(Li)->Position(V1,V2,V3);
107 cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl;
108 Handle(V3d_PositionalLight)::DownCast(Li)->Target(V1,V2,V3);
109 cout<<"Target : x1 = "<<V1<<" x2 = "<<V2<<" x3 = "<<V3<<endl;
115 cout<<" DIRECTIONAL\n\t";
116 Handle(V3d_SpotLight)::DownCast(Li)->Position(V1,V2,V3);
117 cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl;
118 Handle(V3d_SpotLight)::DownCast(Li)->Direction(V1,V2,V3);
119 cout<<"Direction : V1 = "<<V1<<" V2 = "<<V2<<" V3 = "<<V3<<endl;
120 Handle(V3d_PositionalLight)::DownCast(Li)->Target(V1,V2,V3);
121 cout<<"Target : x1 = "<<V1<<" x2 = "<<V2<<" x3 = "<<V3<<endl;
122 cout<<"\tAngle :"<<Handle(V3d_SpotLight)::DownCast(Li)->Angle()<<endl;
131 //=======================================================================
134 //=======================================================================
136 AIS_StatusOfDetection AIS_InteractiveContext::MoveTo(const Standard_Integer XPix,
137 const Standard_Integer YPix,
138 const Handle(V3d_View)& aView)
140 if(HasOpenedContext()){
141 myWasLastMain = Standard_True;
142 return myLocalContexts(myCurLocalIndex)->MoveTo(XPix,YPix,aView);
146 //Nullify class members storing information about detected AIS objects.
147 myAISCurDetected = 0;
148 myAISDetectedSeq.Clear();
151 // OCC11904 - local variables made non-static - it looks and works better like this
152 Handle (PrsMgr_PresentationManager3d) pmgr ;
153 Handle (StdSelect_ViewerSelector3d) selector;
154 Standard_Boolean ismain = Standard_True,UpdVwr = Standard_False;
157 if(aView->Viewer()== myMainVwr) {
160 myLastPicked = myLastinMain;
161 myWasLastMain = Standard_True;
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() )
196 if ( !myFilters->IsOk( selector->OnePicked() ) )
197 return AIS_SOD_AllBad;
199 if ( !myLocalContexts( myCurLocalIndex )->Filter()->IsOk( selector->OnePicked() ) )
200 return AIS_SOD_AllBad;
203 // Does nothing if previously detected object is equal to the current one
204 if ( selector->OnePicked()->Selectable() == myLastPicked )
205 return AIS_SOD_OnlyOneDetected;
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 aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
215 if (myLastPicked->State() != 1)
217 pmgr->Unhighlight (myLastPicked, aHiMod);
218 UpdVwr = Standard_True;
220 else if (myToHilightSelected)
222 pmgr->Color (myLastPicked, mySelectionColor, aHiMod);
223 UpdVwr = Standard_True;
227 // Initialize myLastPicked field with currently detected object
228 myLastPicked = Handle(AIS_InteractiveObject)::DownCast (selector->OnePicked()->Selectable());
231 myLastinMain = myLastPicked;
233 // Highlight detected object if it is not selected or myToHilightSelected flag is true
234 if (!myLastPicked.IsNull()
235 && (myLastPicked->State()!= 1 || myToHilightSelected))
237 Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
238 pmgr->Color (myLastPicked, myHilightColor, aHiMod);
239 UpdVwr = Standard_True;
242 if (!myLastPicked.IsNull()
243 && myLastPicked->State() == 1)
245 TheStat = AIS_SOD_Selected;
250 // Previously detected object is unhilighted if it is not selected or hilighted
251 // with selection color if it is selected.
252 TheStat = AIS_SOD_Nothing;
253 if (!myLastPicked.IsNull())
255 Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
256 if (myLastPicked->State() != 1)
258 pmgr->Unhighlight (myLastPicked, aHiMod);
259 UpdVwr = Standard_True;
261 else if (myToHilightSelected)
263 pmgr->Color (myLastPicked, mySelectionColor, aHiMod);
264 UpdVwr = Standard_True;
269 myLastinMain.Nullify();
272 if(UpdVwr) aView->Viewer()->Update();
273 myLastPicked.Nullify();
275 mylastmoveview = aView;
279 //=======================================================================
282 //=======================================================================
284 AIS_StatusOfPick AIS_InteractiveContext::Select(const Standard_Integer XPMin,
285 const Standard_Integer YPMin,
286 const Standard_Integer XPMax,
287 const Standard_Integer YPMax,
288 const Handle(V3d_View)& aView,
289 const Standard_Boolean updateviewer)
291 // all objects detected by the selector are taken, previous current objects are emptied,
292 // new objects are put...
294 if(HasOpenedContext())
295 return myLocalContexts(myCurLocalIndex)->Select(XPMin,YPMin,XPMax,YPMax,aView,updateviewer);
297 ClearCurrents(Standard_False);
298 // OCC11904 - local variables made non-static - it looks and works better like this
299 Handle(StdSelect_ViewerSelector3d) selector;
301 if(aView->Viewer()== myMainVwr) {
303 myWasLastMain = Standard_True;}
305 selector->Pick(XPMin,YPMin,XPMax,YPMax,aView);
306 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
309 AIS_MapOfInteractive theSelectedObj;
310 for( selector->Init(); selector->More(); selector->Next() )
312 Handle( AIS_InteractiveObject ) anObj =
313 Handle( AIS_InteractiveObject )::DownCast( selector->Picked()->Selectable() );
314 if( !anObj.IsNull() )
315 theSelectedObj.Add( anObj );
317 AIS_MapIteratorOfMapOfInteractive anIt( theSelectedObj );
318 for( ; anIt.More(); anIt.Next() )
320 AIS_Selection::Select( anIt.Key() );
321 anIt.Key()->State(1);
324 for(selector->Init();selector->More();selector->Next()){
325 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
328 AIS_Selection::Select(SO);
329 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
331 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
332 AIS_Selection::Select(SO);
338 HilightCurrents(updateviewer);
340 Standard_Integer NS = NbCurrents();
341 if(NS==0) return AIS_SOP_NothingSelected;
342 if(NS==1) return AIS_SOP_OneSelected;
343 return AIS_SOP_SeveralSelected;
347 //=======================================================================
349 //purpose : Selection by polyline
350 //=======================================================================
352 AIS_StatusOfPick AIS_InteractiveContext::Select(const TColgp_Array1OfPnt2d& aPolyline,
353 const Handle(V3d_View)& aView,
354 const Standard_Boolean updateviewer)
356 // all objects detected by the selector are taken, previous current objects are emptied,
357 // new objects are put...
359 if(HasOpenedContext())
360 return myLocalContexts(myCurLocalIndex)->Select(aPolyline,aView,updateviewer);
362 ClearCurrents(Standard_False);
363 // OCC11904 - local variables made non-static - it looks and works better like this
364 Handle(StdSelect_ViewerSelector3d) selector;
366 if(aView->Viewer()== myMainVwr) {
368 myWasLastMain = Standard_True;}
370 selector->Pick(aPolyline,aView);
371 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
375 AIS_MapOfInteractive theSelectedObj;
376 for( selector->Init(); selector->More(); selector->Next() )
378 Handle( AIS_InteractiveObject ) anObj =
379 Handle( AIS_InteractiveObject )::DownCast( selector->Picked()->Selectable() );
380 if( !anObj.IsNull() )
381 theSelectedObj.Add( anObj );
383 AIS_MapIteratorOfMapOfInteractive anIt( theSelectedObj );
384 for( ; anIt.More(); anIt.Next() )
386 AIS_Selection::Select( anIt.Key() );
387 anIt.Key()->State(1);
390 for(selector->Init();selector->More();selector->Next()){
391 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
394 AIS_Selection::Select(SO);
395 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
397 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
398 AIS_Selection::Select(SO);
403 HilightCurrents(updateviewer);
405 Standard_Integer NS = NbCurrents();
406 if(NS==0) return AIS_SOP_NothingSelected;
407 if(NS==1) return AIS_SOP_OneSelected;
408 return AIS_SOP_SeveralSelected;
412 //=======================================================================
415 //=======================================================================
417 AIS_StatusOfPick AIS_InteractiveContext::Select(const Standard_Boolean updateviewer)
419 if(HasOpenedContext()){
421 return myLocalContexts(myCurLocalIndex)->Select(updateviewer);
424 myLocalContexts(myCurLocalIndex)->SetSelected(myLastPicked,updateviewer);
425 return AIS_SOP_OneSelected;
428 // AIS_StatusOfPick PS(AIS_SOP_NothingSelected);
429 if(myWasLastMain && !myLastinMain.IsNull()){
430 if(myLastinMain->State()!=1){
431 SetCurrentObject(myLastinMain,Standard_False);
433 UpdateCurrentViewer();}
436 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
437 Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
438 Handle(Standard_Transient) Tr;
439 Handle(AIS_InteractiveObject) IO;
441 for(S->Init();S->More();S->Next()){
443 IO = (*((Handle(AIS_InteractiveObject)*)&Tr));
445 Unhilight(IO,Standard_False);
446 if(myObjects.IsBound(IO)){ // anti-plantage-rob
447 if(myObjects(IO)->IsSubIntensityOn())
448 HilightWithColor(IO,mySubIntensity,Standard_False);
452 AIS_Selection::Select();
455 UpdateCurrentViewer();
458 Standard_Integer NS = NbCurrents();
459 if(NS==0) return AIS_SOP_NothingSelected;
460 if(NS==1) return AIS_SOP_OneSelected;
461 return AIS_SOP_SeveralSelected;
464 //=======================================================================
465 //function : ShiftSelect
467 //=======================================================================
469 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect(const Standard_Boolean updateviewer)
471 if(HasOpenedContext()){
473 return myLocalContexts(myCurLocalIndex)->ShiftSelect(updateviewer);
475 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(myLastPicked,updateviewer);
476 Standard_Integer NS =NbSelected();
477 if(NS==0) return AIS_SOP_NothingSelected;
478 if(NS==1) return AIS_SOP_OneSelected;
479 return AIS_SOP_SeveralSelected;
482 if(myWasLastMain && !myLastinMain.IsNull())
483 AddOrRemoveCurrentObject(myLastinMain,updateviewer);
485 Standard_Integer NS = NbCurrents();
486 if(NS==0) return AIS_SOP_NothingSelected;
487 if(NS==1) return AIS_SOP_OneSelected;
488 return AIS_SOP_SeveralSelected;
492 //=======================================================================
493 //function : ShiftSelect
495 //=======================================================================
497 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect(const Standard_Integer XPMin,
498 const Standard_Integer YPMin,
499 const Standard_Integer XPMax,
500 const Standard_Integer YPMax,
501 const Handle(V3d_View)& aView,
502 const Standard_Boolean updateviewer)
505 if(HasOpenedContext())
506 return myLocalContexts(myCurLocalIndex)->ShiftSelect(XPMin,YPMin,XPMax,YPMax,aView,updateviewer);
508 UnhilightCurrents(Standard_False);
509 // OCC11904 - local variables made non-static - it looks and works better like this
510 Handle(StdSelect_ViewerSelector3d) selector;
512 if(aView->Viewer()== myMainVwr) {
514 myWasLastMain = Standard_True;}
516 return AIS_SOP_NothingSelected;
518 selector->Pick(XPMin,YPMin,XPMax,YPMax,aView);
519 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
520 for(selector->Init();selector->More();selector->Next()){
521 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
523 AIS_SelectStatus SelStat = AIS_Selection::Select(SO);
524 Standard_Integer mod = (SelStat==AIS_SS_Added)?1:0;
525 (*((Handle(AIS_InteractiveObject)*)&SO))->State(mod);
529 HilightCurrents(updateviewer);
531 Standard_Integer NS =NbCurrents();
532 if(NS==0) return AIS_SOP_NothingSelected;
533 if(NS==1) return AIS_SOP_OneSelected;
534 return AIS_SOP_SeveralSelected;
538 //=======================================================================
539 //function : ShiftSelect
541 //=======================================================================
543 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect( const TColgp_Array1OfPnt2d& aPolyline,
544 const Handle(V3d_View)& aView,
545 const Standard_Boolean updateviewer )
547 if( HasOpenedContext() )
548 return myLocalContexts( myCurLocalIndex )->ShiftSelect( aPolyline, aView, updateviewer );
550 UnhilightCurrents( Standard_False );
551 // OCC11904 - local variables made non-static - it looks and works better like this
552 Handle(StdSelect_ViewerSelector3d) selector;
554 if( aView->Viewer() == myMainVwr ) {
556 myWasLastMain = Standard_True;
559 return AIS_SOP_NothingSelected;
561 selector->Pick( aPolyline, aView );
563 AIS_Selection::SetCurrentSelection( myCurrentName.ToCString() );
564 for( selector->Init(); selector->More(); selector->Next() ) {
565 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
567 AIS_SelectStatus SelStat = AIS_Selection::Select( SO );
568 Standard_Integer mod = ( SelStat == AIS_SS_Added ) ? 1 : 0;
569 (*((Handle(AIS_InteractiveObject)*)&SO))->State( mod );
573 HilightCurrents( updateviewer );
574 Standard_Integer NS = NbCurrents();
575 if( NS == 0 ) return AIS_SOP_NothingSelected;
576 if( NS == 1 ) return AIS_SOP_OneSelected;
577 return AIS_SOP_SeveralSelected;
580 //=======================================================================
581 //function : SetCurrentObject
583 //=======================================================================
585 void AIS_InteractiveContext::SetCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
586 const Standard_Boolean updateviewer)
588 // single case processing...
589 if(NbCurrents()==1 && anIObj->State()==1){
590 Quantity_NameOfColor HiCol;
591 Standard_Boolean HasHiCol;
592 if(IsHilighted(anIObj,HasHiCol,HiCol)){
593 if(HasHiCol && HiCol!= mySelectionColor) {
595 HilightWithColor(anIObj,mySelectionColor,updateviewer);
597 Hilight(anIObj,updateviewer);
606 if(!HasOpenedContext()) {
607 if(anIObj.IsNull()) return;
608 if(!myObjects.IsBound(anIObj))
609 Display(anIObj,Standard_False);
611 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
612 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
613 Handle(Standard_Transient) TR;
614 Handle(AIS_InteractiveObject) IO;
616 while (sel->More()) {
618 IO = *((Handle(AIS_InteractiveObject)*)&TR);
619 Unhilight(IO,Standard_False);
624 // added to avoid untimely viewer update...
625 AIS_Selection::ClearAndSelect(anIObj);
627 Quantity_NameOfColor HiCol;
628 Standard_Boolean HasHiCol;
629 if(IsHilighted(anIObj,HasHiCol,HiCol)){
630 if(HasHiCol && HiCol!= mySelectionColor) {
632 HilightWithColor(anIObj,mySelectionColor,Standard_False);
634 Hilight(anIObj,Standard_False);
640 HilightWithColor(anIObj,mySelectionColor,Standard_False);
642 Hilight(anIObj,Standard_False);
646 UpdateCurrentViewer();
650 cout<<"Nothing Done : Opened Local Context"<<endl;
655 //=======================================================================
656 //function : AddOrRemoveCurrentObject
658 //=======================================================================
660 void AIS_InteractiveContext::
661 AddOrRemoveCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
662 const Standard_Boolean updateviewer)
664 if(anIObj.IsNull()) return;
665 //OCC5682 to remove an object from neutral point even if Local Context is opened (Remove method)
666 if(!HasOpenedContext() /*OCC5682*/|| myObjects.IsBound(anIObj)) {
668 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
669 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
671 AIS_SelectStatus SelStat = AIS_Selection::Select(anIObj);
673 Standard_Integer mod = (SelStat==AIS_SS_Added) ? 1 : 0;
677 HilightWithColor(anIObj,mySelectionColor,Standard_False);
679 Hilight(anIObj,Standard_False);
682 Unhilight(anIObj,Standard_False);
686 UpdateCurrentViewer();
690 cout<<"Nothing Done : Opened Local Context"<<endl;
694 //=======================================================================
695 //function : UpdateCurrent
697 //=======================================================================
699 void AIS_InteractiveContext::UpdateCurrent()
704 //=======================================================================
705 //function : IsCurrent
707 //=======================================================================
709 Standard_Boolean AIS_InteractiveContext::IsCurrent(const Handle(AIS_InteractiveObject)& anIObj) const
712 if (anIObj.IsNull()) return Standard_False;
713 return (anIObj->State()==1);
715 // Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
717 // while (sel->More()) {
718 // if (anIObj == sel->Value()) return Standard_True;
721 // return Standard_False;
725 //=======================================================================
726 //function : InitCurrent
728 //=======================================================================
730 void AIS_InteractiveContext::InitCurrent()
732 AIS_Selection::Selection(myCurrentName.ToCString())->Init();
735 //=======================================================================
736 //function : MoreCurrent
738 //=======================================================================
740 Standard_Boolean AIS_InteractiveContext::MoreCurrent() const
742 return AIS_Selection::Selection(myCurrentName.ToCString())->More();
746 //=======================================================================
747 //function : NextCurrent
749 //=======================================================================
751 void AIS_InteractiveContext::NextCurrent()
753 AIS_Selection::Selection(myCurrentName.ToCString())->Next();
756 //=======================================================================
759 //=======================================================================
761 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Current() const
763 Handle(Standard_Transient) TR = AIS_Selection::Selection(myCurrentName.ToCString())->Value();
764 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
768 //=======================================================================
769 //function : FirstCurrentObject
771 //=======================================================================
772 Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstCurrentObject()
774 Handle(AIS_InteractiveObject) IO ;
782 //=======================================================================
783 //function : NbCurrents
785 //=======================================================================
786 Standard_Integer AIS_InteractiveContext::NbCurrents()
788 Standard_Integer i(0);
789 for(InitCurrent();MoreCurrent();NextCurrent())
794 //=======================================================================
795 //function : HilightCurrents
797 //=======================================================================
798 void AIS_InteractiveContext::HilightCurrents(const Standard_Boolean updateviewer)
800 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
801 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
802 Handle(Standard_Transient) TR;
803 Handle(AIS_InteractiveObject) IO;
805 while (sel->More()) {
807 IO = *((Handle(AIS_InteractiveObject)*)&TR);
809 HilightWithColor(IO,mySelectionColor,Standard_False);
811 Hilight(IO,Standard_False);
816 UpdateCurrentViewer();
819 //=======================================================================
820 //function : UnhilightCurrents
822 //=======================================================================
824 void AIS_InteractiveContext::UnhilightCurrents(const Standard_Boolean updateviewer)
826 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
827 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
828 Handle(Standard_Transient) TR;
829 Handle(AIS_InteractiveObject) IO;
831 while (sel->More()) {
833 IO = *((Handle(AIS_InteractiveObject)*)&TR);
834 Unhilight(IO,Standard_False);
838 UpdateCurrentViewer();
841 //=======================================================================
842 //function : ClearCurrents
844 //=======================================================================
846 void AIS_InteractiveContext::ClearCurrents(const Standard_Boolean updateviewer)
848 if(NbCurrents()==0) return;
849 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
850 Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
851 Handle(Standard_Transient) Tr;
852 Handle(AIS_InteractiveObject) IO;
853 for(S->Init();S->More();S->Next()){
855 IO = (*((Handle(AIS_InteractiveObject)*)&Tr));
857 Unhilight(IO,Standard_False);
859 AIS_Selection::Select();
861 UpdateCurrentViewer();
865 //=======================================================================
866 //function : HilightSelected
868 //=======================================================================
870 void AIS_InteractiveContext::HilightSelected(const Standard_Boolean updateviewer)
872 if(!HasOpenedContext()){
873 AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
874 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
875 Handle(Standard_Transient) TR;
876 Handle(AIS_InteractiveObject) IO;
878 while (sel->More()) {
880 IO = *((Handle(AIS_InteractiveObject)*)&TR);
882 HilightWithColor(IO,mySelectionColor,Standard_False);
884 Hilight(IO,Standard_False);
891 myLocalContexts(myCurLocalIndex)->HilightPicked(updateviewer);
894 UpdateCurrentViewer();
897 //=======================================================================
898 //function : UnhilightSelected
900 //=======================================================================
902 void AIS_InteractiveContext::UnhilightSelected(const Standard_Boolean updateviewer)
904 if(!HasOpenedContext()){
905 AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
906 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
907 Handle(Standard_Transient) TR;
908 Handle(AIS_InteractiveObject) IO;
910 while (sel->More()) {
912 IO = *((Handle(AIS_InteractiveObject)*)&TR);
913 Unhilight(IO,Standard_False);
917 UpdateCurrentViewer();
921 myLocalContexts(myCurLocalIndex)->UnhilightPicked(updateviewer);
926 //=======================================================================
927 //function : ClearSelected
929 //=======================================================================
931 void AIS_InteractiveContext::ClearSelected(const Standard_Boolean updateviewer)
933 if(!HasOpenedContext())
934 ClearCurrents(updateviewer);
936 myLocalContexts(myCurLocalIndex)->ClearSelected(updateviewer);
941 //=======================================================================
942 //function : SetSelectedCurrent
944 //=======================================================================
946 void AIS_InteractiveContext::SetSelectedCurrent()
951 cout<<"Not Yet Implemented"<<endl;
955 //=======================================================================
956 //function : UpdateSelection
958 //=======================================================================
960 void AIS_InteractiveContext::UpdateSelected(const Standard_Boolean updateviewer)
962 if(!HasOpenedContext()) {
968 myLocalContexts(myCurLocalIndex)->UpdateSelected(updateviewer);
971 //=======================================================================
972 //function : SetCurrentObject
974 //=======================================================================
975 void AIS_InteractiveContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,const Standard_Boolean updateviewer)
977 if(!HasOpenedContext())
978 SetCurrentObject(anIObj,updateviewer);
980 myLocalContexts(myCurLocalIndex)->SetSelected(anIObj,updateviewer);
983 //=======================================================================
984 //function : AddOrRemoveSelected
986 //=======================================================================
988 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj,
989 const Standard_Boolean updateviewer)
991 if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
992 if(!HasOpenedContext())
993 AddOrRemoveCurrentObject(anIObj,updateviewer);
995 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(anIObj,updateviewer);
998 //=======================================================================
999 //function : AddOrRemoveSelected
1001 //=======================================================================
1003 void AIS_InteractiveContext::AddOrRemoveSelected(const TopoDS_Shape& aShap,
1004 const Standard_Boolean updateviewer)
1006 if(!HasOpenedContext()) {
1008 cout<<" Attempt to remove a selected shape with no opened local context"<<endl;
1013 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(aShap,updateviewer);
1014 if(updateviewer) UpdateCurrentViewer();
1017 //=======================================================================
1018 //function : AddOrRemoveSelected
1020 //=======================================================================
1022 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(SelectMgr_EntityOwner)& Own,
1023 const Standard_Boolean updateviewer)
1025 if(!HasOpenedContext()) {
1027 cout<<" Attempt to remove a selected ownr with no opened local context"<<endl;
1032 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(Own,Standard_False);
1033 if(updateviewer) UpdateCurrentViewer();
1039 //=======================================================================
1040 //function : IsSelected
1042 //=======================================================================
1044 Standard_Boolean AIS_InteractiveContext::
1045 IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const
1047 if (anIObj.IsNull()) return Standard_False;
1049 if(!HasOpenedContext())
1050 return (anIObj->State()==1);
1052 return myLocalContexts(myCurLocalIndex)->IsSelected(anIObj);
1056 //=======================================================================
1057 //function : InitSelected
1059 //=======================================================================
1061 void AIS_InteractiveContext::InitSelected()
1063 if(!HasOpenedContext())
1064 AIS_Selection::Selection(myCurrentName.ToCString())->Init();
1066 myLocalContexts(myCurLocalIndex)->InitSelected();
1069 //=======================================================================
1070 //function : MoreSelected
1072 //=======================================================================
1074 Standard_Boolean AIS_InteractiveContext::MoreSelected() const
1076 if(!HasOpenedContext())
1077 return AIS_Selection::Selection(myCurrentName.ToCString())->More();
1078 return myLocalContexts(myCurLocalIndex)->MoreSelected();
1081 //=======================================================================
1082 //function : NextSelected
1084 //=======================================================================
1086 void AIS_InteractiveContext::NextSelected()
1088 if(!HasOpenedContext())
1089 AIS_Selection::Selection(myCurrentName.ToCString())->Next();
1091 myLocalContexts(myCurLocalIndex)->NextSelected();
1094 //=======================================================================
1095 //function : HasSelectedShape
1097 //=======================================================================
1099 Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
1101 if(!HasOpenedContext()) {
1103 Handle(AIS_Shape) shape =
1104 Handle(AIS_Shape)::DownCast(SelectedInteractive());
1105 if( !shape.IsNull() ) return Standard_True;
1107 return Standard_False;
1109 return myLocalContexts(myCurLocalIndex)->HasShape();
1114 //=======================================================================
1115 //function : SelectedShape
1117 //=======================================================================
1119 TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
1122 if(!HasOpenedContext()){
1125 Handle(AIS_Shape) shape =
1126 Handle(AIS_Shape)::DownCast(SelectedInteractive());
1127 if( !shape.IsNull() ) sh = shape->Shape();
1131 return myLocalContexts(myCurLocalIndex)->SelectedShape();
1134 //=======================================================================
1135 //function : Interactive
1137 //=======================================================================
1139 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Interactive() const
1141 return SelectedInteractive();
1144 Handle(AIS_InteractiveObject) AIS_InteractiveContext::SelectedInteractive() const
1146 if(!HasOpenedContext()){
1147 Handle(Standard_Transient) TR =AIS_Selection::Selection(myCurrentName.ToCString())->Value();
1148 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
1151 return myLocalContexts(myCurLocalIndex)->SelectedInteractive();
1154 //=======================================================================
1155 //function : Interactive
1157 //=======================================================================
1159 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const
1161 if(!HasOpenedContext()){
1162 Handle(SelectMgr_EntityOwner) Ownr;
1165 return myLocalContexts(myCurLocalIndex)->SelectedOwner();
1169 //=======================================================================
1170 //function : EntityOwners
1172 //=======================================================================
1173 void AIS_InteractiveContext::EntityOwners(SelectMgr_IndexedMapOfOwner& theOwners,
1174 const Handle(AIS_InteractiveObject)& theIObj,
1175 const Standard_Integer theMode) const
1177 if ( theIObj.IsNull() )
1180 TColStd_ListOfInteger aModes;
1181 if ( theMode == -1 )
1182 ActivatedModes( theIObj, aModes );
1184 aModes.Append( theMode );
1186 TColStd_ListIteratorOfListOfInteger anItr( aModes );
1187 for (; anItr.More(); anItr.Next() )
1189 int aMode = anItr.Value();
1190 if ( !theIObj->HasSelection( aMode ) )
1193 Handle(SelectMgr_Selection) aSel = theIObj->Selection( aMode );
1195 for ( aSel->Init(); aSel->More(); aSel->Next() )
1197 Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive();
1198 if ( aEntity.IsNull() )
1201 Handle(SelectMgr_EntityOwner) aOwner =
1202 Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId());
1203 if ( !aOwner.IsNull() )
1204 theOwners.Add( aOwner );
1209 Standard_Integer AIS_InteractiveContext::NbSelected()
1211 Standard_Integer i(0);
1212 for(InitSelected();MoreSelected();NextSelected())
1217 //=======================================================================
1218 //function : HasApplicative
1220 //=======================================================================
1222 Standard_Boolean AIS_InteractiveContext::HasApplicative() const
1224 return Interactive()->HasOwner();
1227 //=======================================================================
1228 //function : Applicative
1230 //=======================================================================
1232 Handle(Standard_Transient) AIS_InteractiveContext::Applicative() const
1234 return Interactive()->GetOwner();
1239 //==================================================
1242 //==================================================
1243 Standard_Boolean AIS_InteractiveContext::HasDetected() const
1245 if(HasOpenedContext())
1246 return myLocalContexts(myCurLocalIndex)->HasDetected();
1248 return !myLastPicked.IsNull();
1251 //=======================================================================
1252 //function : HasDetectedShape
1254 //=======================================================================
1256 Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
1258 if(HasOpenedContext())
1259 return myLocalContexts(myCurLocalIndex)->HasDetectedShape();
1260 return Standard_False;
1263 //=======================================================================
1264 //function : DetectedShape
1266 //=======================================================================
1269 AIS_InteractiveContext::DetectedShape() const
1271 return myLocalContexts(myCurLocalIndex)->DetectedShape();
1274 //=======================================================================
1275 //function : DetectedInteractive
1277 //=======================================================================
1279 Handle(AIS_InteractiveObject)
1280 AIS_InteractiveContext::DetectedInteractive() const
1282 if(HasOpenedContext())
1283 return myLocalContexts(myCurLocalIndex)->DetectedInteractive();
1284 return myLastPicked;
1288 Standard_Boolean AIS_InteractiveContext::HasNextDetected() const
1290 if(!HasOpenedContext())
1291 return Standard_False; // temporaire
1293 return myLocalContexts(myCurLocalIndex)->HasNextDetected();
1298 //=======================================================================
1299 //function : DetectedOwner
1301 //=======================================================================
1302 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedOwner() const
1304 if(HasOpenedContext())
1305 return myLocalContexts(myCurLocalIndex)->DetectedOwner();
1306 Handle(SelectMgr_EntityOwner) Ownr;
1311 //=======================================================================
1312 //function : HilightNextDetected
1314 //=======================================================================
1315 Standard_Integer AIS_InteractiveContext::HilightNextDetected(const Handle(V3d_View)& V)
1317 if(!HasOpenedContext())
1319 return myLocalContexts(myCurLocalIndex)->HilightNextDetected(V);
1323 //=======================================================================
1324 //function : HilightNextDetected
1326 //=======================================================================
1327 Standard_Integer AIS_InteractiveContext::HilightPreviousDetected(const Handle(V3d_View)& V)
1329 if(!HasOpenedContext())
1331 return myLocalContexts(myCurLocalIndex)->HilightPreviousDetected(V);
1336 void AIS_InteractiveContext::Drag(
1337 const Handle(V3d_View)& aView,
1338 const Handle(AIS_InteractiveObject)& anObject,
1339 const Handle(Geom_Transformation)& aTrsf,
1340 const Standard_Boolean postConcatenate,
1341 const Standard_Boolean update,
1342 const Standard_Boolean zBuffer) {
1344 if( anObject.IsNull() || aView.IsNull() ) return;
1347 anObject->SetTransformation(aTrsf,postConcatenate,Standard_True);
1349 } else if( Visual3d_TransientManager::BeginDraw(aView->View(),
1350 zBuffer,Standard_False) ) {
1351 Handle(Prs3d_Presentation) P = anObject->Presentation();
1353 if( postConcatenate ) P->Multiply(aTrsf);
1354 else P->Transform(aTrsf);
1355 Visual3d_TransientManager::DrawStructure(P);
1357 Visual3d_TransientManager::EndDraw(Standard_True);
1363 //=======================================================================
1364 //function : InitDetected
1366 //=======================================================================
1367 void AIS_InteractiveContext::InitDetected()
1369 if(HasOpenedContext())
1371 myLocalContexts(myCurLocalIndex)->InitDetected();
1375 if(myAISDetectedSeq.Length() != 0)
1376 myAISCurDetected = 1;
1380 //=======================================================================
1381 //function : MoreDetected
1383 //=======================================================================
1384 Standard_Boolean AIS_InteractiveContext::MoreDetected() const
1386 if(HasOpenedContext())
1387 return myLocalContexts(myCurLocalIndex)->MoreDetected();
1389 return (myAISCurDetected>0 &&myAISCurDetected <= myAISDetectedSeq.Length()) ?
1390 Standard_True : Standard_False;
1393 //=======================================================================
1394 //function : NextDetected
1396 //=======================================================================
1397 void AIS_InteractiveContext::NextDetected()
1399 if(HasOpenedContext())
1401 myLocalContexts(myCurLocalIndex)->NextDetected();
1408 //=======================================================================
1409 //function : DetectedCurrentShape
1411 //=======================================================================
1413 const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
1415 if(HasOpenedContext())
1416 return myLocalContexts(myCurLocalIndex)->DetectedCurrentShape();
1418 static TopoDS_Shape bidsh;
1419 if(myAISCurDetected > 0 &&
1420 myAISCurDetected <= myAISDetectedSeq.Length())
1421 return Handle(AIS_Shape)::DownCast(myAISDetectedSeq(myAISCurDetected))->Shape();
1425 //=======================================================================
1426 //function : DetectedCurrentObject
1428 //=======================================================================
1430 Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const {
1431 if(HasOpenedContext())
1432 return myLocalContexts(myCurLocalIndex)->DetectedCurrentObject();
1434 Handle(AIS_InteractiveObject) aBad;
1436 if(myAISCurDetected > 0 &&
1437 myAISCurDetected <= myAISDetectedSeq.Length())
1438 return myAISDetectedSeq(myAISCurDetected);