1 // Created on: 1997-01-29
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #define UKI60826 //GG_161199 Use the requested selection color instead of default
24 #define IMP280200 //GG Don't returns a NULL shape in SelectedShape()
25 // method when the current selected is a shape !
27 #define BUC60814 //GG_300101 Idem UKI60826
29 #define IMP150501 //GG_150501 CADPAK_V2 Add Drag() method
31 #define IMP160701 //ZSV Add InitDetected(),MoreDetected(),NextDetected(),
32 // DetectedCurrentShape(),DetectedCurrentObject()
35 #define IMP191001 //GG Avoid to raise when switching with the
36 // SetAutomaticHilight() method.
37 // Thanks to IFO of SAMTECH company for this improvment.
39 #define OCC138 //VTN Avoding infinit loop in AddOrRemoveCurrentObject method.
43 #include <AIS_InteractiveContext.jxx>
44 #include <SelectMgr_EntityOwner.hxx>
45 #include <AIS_Selection.hxx>
46 #include <AIS_StatusOfDetection.hxx>
47 #include <AIS_StatusOfPick.hxx>
49 #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
50 #include <AIS_LocalContext.hxx>
51 #include <AIS_GlobalStatus.hxx>
52 #include <AIS_Shape.hxx>
54 #include <V3d_Light.hxx>
55 #include <V3d_PositionalLight.hxx>
56 #include <V3d_SpotLight.hxx>
57 #include <V3d_DirectionalLight.hxx>
58 #include <V3d_AmbientLight.hxx>
60 #include <TColStd_ListIteratorOfListOfInteger.hxx>
61 #include <SelectMgr_Selection.hxx>
62 #include <SelectBasics_SensitiveEntity.hxx>
65 #include <Visual3d_TransientManager.hxx>
66 #include <Prs3d_Presentation.hxx>
70 #include <AIS_MapOfInteractive.hxx>
71 #include <AIS_MapIteratorOfMapOfInteractive.hxx>
76 static void InfoOnLight(const Handle(V3d_View) aView)
78 Standard_Real V1=0.,V2=0.,V3=0.;
79 Standard_Integer IndexOfLit(0);
81 static Standard_Boolean FirstTime (Standard_True);
84 FirstTime = Standard_False;
85 for (aView->InitActiveLights();aView->MoreActiveLights();aView->NextActiveLights()){
87 cout<<"lumiere no "<<IndexOfLit<<"\n************\n\t";
88 Handle(V3d_Light) Li = aView->ActiveLight();
89 Quantity_NameOfColor Col;
91 cout<<"Color :"<<Standard_Integer(Col)<<"\n\t"<<endl;
98 // Handle(V3d_AmbientLight)::DownCast(Li)->DisplayPosition(V1,V2,V3);
99 cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl;
102 case V3d_DIRECTIONAL:
104 cout<<" DIRECTIONAL\n\t";
105 Handle(V3d_DirectionalLight)::DownCast(Li)->DisplayPosition(V1,V2,V3);
106 cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl;
107 Handle(V3d_DirectionalLight)::DownCast(Li)->Direction(V1,V2,V3);
108 cout<<"Direction : V1 = "<<V1<<" V2 = "<<V2<<" V3 = "<<V3<<endl;
114 cout<<" POSITIONAL\n\t";
115 Handle(V3d_PositionalLight)::DownCast(Li)->Position(V1,V2,V3);
116 cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl;
117 Handle(V3d_PositionalLight)::DownCast(Li)->Target(V1,V2,V3);
118 cout<<"Target : x1 = "<<V1<<" x2 = "<<V2<<" x3 = "<<V3<<endl;
124 cout<<" DIRECTIONAL\n\t";
125 Handle(V3d_SpotLight)::DownCast(Li)->Position(V1,V2,V3);
126 cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl;
127 Handle(V3d_SpotLight)::DownCast(Li)->Direction(V1,V2,V3);
128 cout<<"Direction : V1 = "<<V1<<" V2 = "<<V2<<" V3 = "<<V3<<endl;
129 Handle(V3d_PositionalLight)::DownCast(Li)->Target(V1,V2,V3);
130 cout<<"Target : x1 = "<<V1<<" x2 = "<<V2<<" x3 = "<<V3<<endl;
131 cout<<"\tAngle :"<<Handle(V3d_SpotLight)::DownCast(Li)->Angle()<<endl;
140 //=======================================================================
143 //=======================================================================
145 AIS_StatusOfDetection AIS_InteractiveContext::MoveTo(const Standard_Integer XPix,
146 const Standard_Integer YPix,
147 const Handle(V3d_View)& aView)
149 if(HasOpenedContext()){
150 myWasLastMain = Standard_True;
151 return myLocalContexts(myCurLocalIndex)->MoveTo(XPix,YPix,aView);
155 //Nullify class members storing information about detected AIS objects.
156 myAISCurDetected = 0;
157 myAISDetectedSeq.Clear();
160 // OCC11904 - local variables made non-static - it looks and works better like this
161 Handle (PrsMgr_PresentationManager3d) pmgr ;
162 Handle (StdSelect_ViewerSelector3d) selector;
163 Standard_Boolean ismain = Standard_True,UpdVwr = Standard_False;
166 if(aView->Viewer()== myMainVwr) {
169 myLastPicked = myLastinMain;
170 myWasLastMain = Standard_True;
173 return AIS_SOD_Error;
175 AIS_StatusOfDetection TheStat(AIS_SOD_Nothing);
179 selector->Pick(XPix, YPix, aView);
182 //filling of myAISDetectedSeq sequence storing information about detected AIS objects
183 // (the objects must be AIS_Shapes).
184 Handle(SelectMgr_EntityOwner) anEntityOwner;
185 const Standard_Integer NbDetected = selector->NbPicked();
186 for(Standard_Integer i_detect = 1;i_detect<=NbDetected;i_detect++)
188 anEntityOwner = selector->Picked(i_detect);
189 if(!anEntityOwner.IsNull())
190 if(myFilters->IsOk(anEntityOwner))
192 Handle(AIS_InteractiveObject) anObj =
193 Handle(AIS_InteractiveObject)::DownCast(anEntityOwner->Selectable());
194 if(!Handle(AIS_Shape)::DownCast(anObj).IsNull())
195 myAISDetectedSeq.Append(anObj);
201 if ( selector->More() )
203 if ( HasOpenedContext() )
205 if ( !myFilters->IsOk( selector->OnePicked() ) )
206 return AIS_SOD_AllBad;
208 if ( !myLocalContexts( myCurLocalIndex )->Filter()->IsOk( selector->OnePicked() ) )
209 return AIS_SOD_AllBad;
212 // Does nothing if previously detected object is equal to the current one
213 if ( selector->OnePicked()->Selectable() == myLastPicked )
214 return AIS_SOD_OnlyOneDetected;
216 // Previously detected object is unhilighted if it is not selected or hilighted
217 // with selection color if it is selected. Such highlighting with selection color
218 // is needed only if myToHilightSelected flag is true. In this case previously detected
219 // object has been already highlighted with myHilightColor during previous MoveTo()
220 // method call. As result it is necessary to rehighligt it with mySelectionColor.
221 if ( !myLastPicked.IsNull() )
223 Standard_Integer HiMod =
224 myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
225 if ( myLastPicked->State() != 1 )
227 pmgr->Unhighlight( myLastPicked, HiMod );
228 UpdVwr = Standard_True;
230 else if ( myToHilightSelected )
232 pmgr->Color( myLastPicked, mySelectionColor, HiMod );
233 UpdVwr = Standard_True;
237 // Initialize myLastPicked field with currently detected object
238 Handle(SelectMgr_SelectableObject) SO = selector->OnePicked()->Selectable();
239 myLastPicked = *((Handle(AIS_InteractiveObject)*)&SO);
242 myLastinMain = myLastPicked;
244 // Highlight detected object if it is not selected or myToHilightSelected flag is true
245 if ( !myLastPicked.IsNull() &&
246 ( myLastPicked->State()!= 1 || myToHilightSelected ) )
248 if ( myLastPicked->State()!= 1 )
251 Standard_Integer HiMod =
252 myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
253 pmgr->Color( myLastPicked, myHilightColor, HiMod );
254 UpdVwr = Standard_True;
257 if ( myLastPicked->State()==1 )
258 TheStat = AIS_SOD_Selected;
262 // Previously detected object is unhilighted if it is not selected or hilighted
263 // with selection color if it is selected.
264 TheStat = AIS_SOD_Nothing;
265 if ( !myLastPicked.IsNull() )
267 Standard_Integer HiMod =
268 myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
269 if ( myLastPicked->State() != 1 )
271 pmgr->Unhighlight( myLastPicked, HiMod );
272 UpdVwr = Standard_True;
274 else if ( myToHilightSelected )
276 pmgr->Color( myLastPicked, mySelectionColor, HiMod );
277 UpdVwr = Standard_True;
282 myLastinMain.Nullify();
285 if(UpdVwr) aView->Viewer()->Update();
286 myLastPicked.Nullify();
288 mylastmoveview = aView;
292 //=======================================================================
295 //=======================================================================
297 AIS_StatusOfPick AIS_InteractiveContext::Select(const Standard_Integer XPMin,
298 const Standard_Integer YPMin,
299 const Standard_Integer XPMax,
300 const Standard_Integer YPMax,
301 const Handle(V3d_View)& aView,
302 const Standard_Boolean updateviewer)
304 // all objects detected by the selector are taken, previous current objects are emptied,
305 // new objects are put...
307 if(HasOpenedContext())
308 return myLocalContexts(myCurLocalIndex)->Select(XPMin,YPMin,XPMax,YPMax,aView,updateviewer);
310 ClearCurrents(Standard_False);
311 // OCC11904 - local variables made non-static - it looks and works better like this
312 Handle(StdSelect_ViewerSelector3d) selector;
314 if(aView->Viewer()== myMainVwr) {
316 myWasLastMain = Standard_True;}
318 selector->Pick(XPMin,YPMin,XPMax,YPMax,aView);
319 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
322 AIS_MapOfInteractive theSelectedObj;
323 for( selector->Init(); selector->More(); selector->Next() )
325 Handle( AIS_InteractiveObject ) anObj =
326 Handle( AIS_InteractiveObject )::DownCast( selector->Picked()->Selectable() );
327 if( !anObj.IsNull() )
328 theSelectedObj.Add( anObj );
330 AIS_MapIteratorOfMapOfInteractive anIt( theSelectedObj );
331 for( ; anIt.More(); anIt.Next() )
333 AIS_Selection::Select( anIt.Key() );
334 anIt.Key()->State(1);
337 for(selector->Init();selector->More();selector->Next()){
338 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
341 AIS_Selection::Select(SO);
342 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
344 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
345 AIS_Selection::Select(SO);
351 HilightCurrents(updateviewer);
353 Standard_Integer NS = NbCurrents();
354 if(NS==0) return AIS_SOP_NothingSelected;
355 if(NS==1) return AIS_SOP_OneSelected;
356 return AIS_SOP_SeveralSelected;
360 //=======================================================================
362 //purpose : Selection by polyline
363 //=======================================================================
365 AIS_StatusOfPick AIS_InteractiveContext::Select(const TColgp_Array1OfPnt2d& aPolyline,
366 const Handle(V3d_View)& aView,
367 const Standard_Boolean updateviewer)
369 // all objects detected by the selector are taken, previous current objects are emptied,
370 // new objects are put...
372 if(HasOpenedContext())
373 return myLocalContexts(myCurLocalIndex)->Select(aPolyline,aView,updateviewer);
375 ClearCurrents(Standard_False);
376 // OCC11904 - local variables made non-static - it looks and works better like this
377 Handle(StdSelect_ViewerSelector3d) selector;
379 if(aView->Viewer()== myMainVwr) {
381 myWasLastMain = Standard_True;}
383 selector->Pick(aPolyline,aView);
384 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
388 AIS_MapOfInteractive theSelectedObj;
389 for( selector->Init(); selector->More(); selector->Next() )
391 Handle( AIS_InteractiveObject ) anObj =
392 Handle( AIS_InteractiveObject )::DownCast( selector->Picked()->Selectable() );
393 if( !anObj.IsNull() )
394 theSelectedObj.Add( anObj );
396 AIS_MapIteratorOfMapOfInteractive anIt( theSelectedObj );
397 for( ; anIt.More(); anIt.Next() )
399 AIS_Selection::Select( anIt.Key() );
400 anIt.Key()->State(1);
403 for(selector->Init();selector->More();selector->Next()){
404 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
407 AIS_Selection::Select(SO);
408 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
410 (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
411 AIS_Selection::Select(SO);
416 HilightCurrents(updateviewer);
418 Standard_Integer NS = NbCurrents();
419 if(NS==0) return AIS_SOP_NothingSelected;
420 if(NS==1) return AIS_SOP_OneSelected;
421 return AIS_SOP_SeveralSelected;
425 //=======================================================================
428 //=======================================================================
430 AIS_StatusOfPick AIS_InteractiveContext::Select(const Standard_Boolean updateviewer)
432 if(HasOpenedContext()){
434 return myLocalContexts(myCurLocalIndex)->Select(updateviewer);
436 // picking was done in the collector, special processing is required...
438 myLocalContexts(myCurLocalIndex)->SetSelected(myLastPicked,updateviewer);
439 return AIS_SOP_OneSelected;
442 // AIS_StatusOfPick PS(AIS_SOP_NothingSelected);
443 if(myWasLastMain && !myLastinMain.IsNull()){
444 if(myLastinMain->State()!=1){
445 SetCurrentObject(myLastinMain,Standard_False);
447 UpdateCurrentViewer();}
450 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
451 Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
452 Handle(Standard_Transient) Tr;
453 Handle(AIS_InteractiveObject) IO;
455 for(S->Init();S->More();S->Next()){
457 IO = (*((Handle(AIS_InteractiveObject)*)&Tr));
459 Unhilight(IO,Standard_False);
460 if(myObjects.IsBound(IO)){ // anti-plantage-rob
461 if(myObjects(IO)->IsSubIntensityOn())
462 HilightWithColor(IO,mySubIntensity,Standard_False);
466 AIS_Selection::Select();
469 UpdateCurrentViewer();
472 Standard_Integer NS = NbCurrents();
473 if(NS==0) return AIS_SOP_NothingSelected;
474 if(NS==1) return AIS_SOP_OneSelected;
475 return AIS_SOP_SeveralSelected;
478 //=======================================================================
479 //function : ShiftSelect
481 //=======================================================================
483 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect(const Standard_Boolean updateviewer)
485 if(HasOpenedContext()){
487 return myLocalContexts(myCurLocalIndex)->ShiftSelect(updateviewer);
489 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(myLastPicked,updateviewer);
490 Standard_Integer NS =NbSelected();
491 if(NS==0) return AIS_SOP_NothingSelected;
492 if(NS==1) return AIS_SOP_OneSelected;
493 return AIS_SOP_SeveralSelected;
496 if(myWasLastMain && !myLastinMain.IsNull())
497 AddOrRemoveCurrentObject(myLastinMain,updateviewer);
499 Standard_Integer NS = NbCurrents();
500 if(NS==0) return AIS_SOP_NothingSelected;
501 if(NS==1) return AIS_SOP_OneSelected;
502 return AIS_SOP_SeveralSelected;
506 //=======================================================================
507 //function : ShiftSelect
509 //=======================================================================
511 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect(const Standard_Integer XPMin,
512 const Standard_Integer YPMin,
513 const Standard_Integer XPMax,
514 const Standard_Integer YPMax,
515 const Handle(V3d_View)& aView,
516 const Standard_Boolean updateviewer)
519 if(HasOpenedContext())
520 return myLocalContexts(myCurLocalIndex)->ShiftSelect(XPMin,YPMin,XPMax,YPMax,aView,updateviewer);
522 UnhilightCurrents(Standard_False);
523 // OCC11904 - local variables made non-static - it looks and works better like this
524 Handle(StdSelect_ViewerSelector3d) selector;
526 if(aView->Viewer()== myMainVwr) {
528 myWasLastMain = Standard_True;}
530 return AIS_SOP_NothingSelected;
532 selector->Pick(XPMin,YPMin,XPMax,YPMax,aView);
533 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
534 for(selector->Init();selector->More();selector->Next()){
535 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
537 AIS_SelectStatus SelStat = AIS_Selection::Select(SO);
538 Standard_Integer mod = (SelStat==AIS_SS_Added)?1:0;
539 (*((Handle(AIS_InteractiveObject)*)&SO))->State(mod);
543 HilightCurrents(updateviewer);
545 Standard_Integer NS =NbCurrents();
546 if(NS==0) return AIS_SOP_NothingSelected;
547 if(NS==1) return AIS_SOP_OneSelected;
548 return AIS_SOP_SeveralSelected;
552 //=======================================================================
553 //function : ShiftSelect
555 //=======================================================================
557 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect( const TColgp_Array1OfPnt2d& aPolyline,
558 const Handle(V3d_View)& aView,
559 const Standard_Boolean updateviewer )
561 if( HasOpenedContext() )
562 return myLocalContexts( myCurLocalIndex )->ShiftSelect( aPolyline, aView, updateviewer );
564 UnhilightCurrents( Standard_False );
565 // OCC11904 - local variables made non-static - it looks and works better like this
566 Handle(StdSelect_ViewerSelector3d) selector;
568 if( aView->Viewer() == myMainVwr ) {
570 myWasLastMain = Standard_True;
573 return AIS_SOP_NothingSelected;
575 selector->Pick( aPolyline, aView );
577 AIS_Selection::SetCurrentSelection( myCurrentName.ToCString() );
578 for( selector->Init(); selector->More(); selector->Next() ) {
579 const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
581 AIS_SelectStatus SelStat = AIS_Selection::Select( SO );
582 Standard_Integer mod = ( SelStat == AIS_SS_Added ) ? 1 : 0;
583 (*((Handle(AIS_InteractiveObject)*)&SO))->State( mod );
587 HilightCurrents( updateviewer );
588 Standard_Integer NS = NbCurrents();
589 if( NS == 0 ) return AIS_SOP_NothingSelected;
590 if( NS == 1 ) return AIS_SOP_OneSelected;
591 return AIS_SOP_SeveralSelected;
594 //=======================================================================
595 //function : SetCurrentObject
597 //=======================================================================
599 void AIS_InteractiveContext::SetCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
600 const Standard_Boolean updateviewer)
602 // single case processing...
603 if(NbCurrents()==1 && anIObj->State()==1){
604 Quantity_NameOfColor HiCol;
605 Standard_Boolean HasHiCol;
606 if(IsHilighted(anIObj,HasHiCol,HiCol)){
607 if(HasHiCol && HiCol!= mySelectionColor) {
609 HilightWithColor(anIObj,mySelectionColor,updateviewer);
611 Hilight(anIObj,updateviewer);
620 if(!HasOpenedContext()) {
621 if(anIObj.IsNull()) return;
622 if(!myObjects.IsBound(anIObj))
623 Display(anIObj,Standard_False);
625 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
626 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
627 Handle(Standard_Transient) TR;
628 Handle(AIS_InteractiveObject) IO;
630 while (sel->More()) {
632 IO = *((Handle(AIS_InteractiveObject)*)&TR);
633 Unhilight(IO,Standard_False);
638 // added to avoid untimely viewer update...
639 AIS_Selection::ClearAndSelect(anIObj);
641 Quantity_NameOfColor HiCol;
642 Standard_Boolean HasHiCol;
643 if(IsHilighted(anIObj,HasHiCol,HiCol)){
644 if(HasHiCol && HiCol!= mySelectionColor) {
646 HilightWithColor(anIObj,mySelectionColor,Standard_False);
648 Hilight(anIObj,Standard_False);
654 HilightWithColor(anIObj,mySelectionColor,Standard_False);
656 Hilight(anIObj,Standard_False);
660 UpdateCurrentViewer();
664 cout<<"Nothing Done : Opened Local Context"<<endl;
669 //=======================================================================
670 //function : AddOrRemoveCurrentObject
672 //=======================================================================
674 void AIS_InteractiveContext::
675 AddOrRemoveCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
676 const Standard_Boolean updateviewer)
678 if(anIObj.IsNull()) return;
679 //OCC5682 to remove an object from neutral point even if Local Context is opened (Remove method)
680 if(!HasOpenedContext() /*OCC5682*/|| myObjects.IsBound(anIObj)) {
682 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
683 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
685 AIS_SelectStatus SelStat = AIS_Selection::Select(anIObj);
687 Standard_Integer mod = (SelStat==AIS_SS_Added) ? 1 : 0;
691 HilightWithColor(anIObj,mySelectionColor,Standard_False);
693 Hilight(anIObj,Standard_False);
696 Unhilight(anIObj,Standard_False);
700 UpdateCurrentViewer();
704 cout<<"Nothing Done : Opened Local Context"<<endl;
708 //=======================================================================
709 //function : UpdateCurrent
711 //=======================================================================
713 void AIS_InteractiveContext::UpdateCurrent()
718 //=======================================================================
719 //function : IsCurrent
721 //=======================================================================
723 Standard_Boolean AIS_InteractiveContext::IsCurrent(const Handle(AIS_InteractiveObject)& anIObj) const
726 if (anIObj.IsNull()) return Standard_False;
727 return (anIObj->State()==1);
729 // Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
731 // while (sel->More()) {
732 // if (anIObj == sel->Value()) return Standard_True;
735 // return Standard_False;
739 //=======================================================================
740 //function : InitCurrent
742 //=======================================================================
744 void AIS_InteractiveContext::InitCurrent()
746 AIS_Selection::Selection(myCurrentName.ToCString())->Init();
749 //=======================================================================
750 //function : MoreCurrent
752 //=======================================================================
754 Standard_Boolean AIS_InteractiveContext::MoreCurrent() const
756 return AIS_Selection::Selection(myCurrentName.ToCString())->More();
760 //=======================================================================
761 //function : NextCurrent
763 //=======================================================================
765 void AIS_InteractiveContext::NextCurrent()
767 AIS_Selection::Selection(myCurrentName.ToCString())->Next();
770 //=======================================================================
773 //=======================================================================
775 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Current() const
777 Handle(Standard_Transient) TR = AIS_Selection::Selection(myCurrentName.ToCString())->Value();
778 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
782 //=======================================================================
783 //function : FirstCurrentObject
785 //=======================================================================
786 Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstCurrentObject()
788 Handle(AIS_InteractiveObject) IO ;
796 //=======================================================================
797 //function : NbCurrents
799 //=======================================================================
800 Standard_Integer AIS_InteractiveContext::NbCurrents()
802 Standard_Integer i(0);
803 for(InitCurrent();MoreCurrent();NextCurrent())
808 //=======================================================================
809 //function : HilightCurrents
811 //=======================================================================
812 void AIS_InteractiveContext::HilightCurrents(const Standard_Boolean updateviewer)
814 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
815 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
816 Handle(Standard_Transient) TR;
817 Handle(AIS_InteractiveObject) IO;
819 while (sel->More()) {
821 IO = *((Handle(AIS_InteractiveObject)*)&TR);
823 HilightWithColor(IO,mySelectionColor,Standard_False);
825 Hilight(IO,Standard_False);
830 UpdateCurrentViewer();
833 //=======================================================================
834 //function : UnhilightCurrents
836 //=======================================================================
838 void AIS_InteractiveContext::UnhilightCurrents(const Standard_Boolean updateviewer)
840 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
841 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
842 Handle(Standard_Transient) TR;
843 Handle(AIS_InteractiveObject) IO;
845 while (sel->More()) {
847 IO = *((Handle(AIS_InteractiveObject)*)&TR);
848 Unhilight(IO,Standard_False);
852 UpdateCurrentViewer();
855 //=======================================================================
856 //function : ClearCurrents
858 //=======================================================================
860 void AIS_InteractiveContext::ClearCurrents(const Standard_Boolean updateviewer)
862 if(NbCurrents()==0) return;
863 AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
864 Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
865 Handle(Standard_Transient) Tr;
866 Handle(AIS_InteractiveObject) IO;
867 for(S->Init();S->More();S->Next()){
869 IO = (*((Handle(AIS_InteractiveObject)*)&Tr));
871 Unhilight(IO,Standard_False);
873 AIS_Selection::Select();
875 UpdateCurrentViewer();
879 //=======================================================================
880 //function : HilightSelected
882 //=======================================================================
884 void AIS_InteractiveContext::HilightSelected(const Standard_Boolean updateviewer)
886 if(!HasOpenedContext()){
887 AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
888 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
889 Handle(Standard_Transient) TR;
890 Handle(AIS_InteractiveObject) IO;
892 while (sel->More()) {
894 IO = *((Handle(AIS_InteractiveObject)*)&TR);
896 HilightWithColor(IO,mySelectionColor,Standard_False);
898 Hilight(IO,Standard_False);
905 myLocalContexts(myCurLocalIndex)->HilightPicked(updateviewer);
908 UpdateCurrentViewer();
911 //=======================================================================
912 //function : UnhilightSelected
914 //=======================================================================
916 void AIS_InteractiveContext::UnhilightSelected(const Standard_Boolean updateviewer)
918 if(!HasOpenedContext()){
919 AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
920 Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
921 Handle(Standard_Transient) TR;
922 Handle(AIS_InteractiveObject) IO;
924 while (sel->More()) {
926 IO = *((Handle(AIS_InteractiveObject)*)&TR);
927 Unhilight(IO,Standard_False);
931 UpdateCurrentViewer();
935 myLocalContexts(myCurLocalIndex)->UnhilightPicked(updateviewer);
940 //=======================================================================
941 //function : ClearSelected
943 //=======================================================================
945 void AIS_InteractiveContext::ClearSelected(const Standard_Boolean updateviewer)
947 if(!HasOpenedContext())
948 ClearCurrents(updateviewer);
950 myLocalContexts(myCurLocalIndex)->ClearSelected(updateviewer);
955 //=======================================================================
956 //function : SetSelectedCurrent
958 //=======================================================================
960 void AIS_InteractiveContext::SetSelectedCurrent()
965 cout<<"Not Yet Implemented"<<endl;
969 //=======================================================================
970 //function : UpdateSelection
972 //=======================================================================
974 void AIS_InteractiveContext::UpdateSelected(const Standard_Boolean updateviewer)
976 if(!HasOpenedContext()) {
982 myLocalContexts(myCurLocalIndex)->UpdateSelected(updateviewer);
985 //=======================================================================
986 //function : SetCurrentObject
988 //=======================================================================
989 void AIS_InteractiveContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,const Standard_Boolean updateviewer)
991 if(!HasOpenedContext())
992 SetCurrentObject(anIObj,updateviewer);
994 myLocalContexts(myCurLocalIndex)->SetSelected(anIObj,updateviewer);
997 //=======================================================================
998 //function : AddOrRemoveSelected
1000 //=======================================================================
1002 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj,
1003 const Standard_Boolean updateviewer)
1005 if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
1006 if(!HasOpenedContext())
1007 AddOrRemoveCurrentObject(anIObj,updateviewer);
1009 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(anIObj,updateviewer);
1012 //=======================================================================
1013 //function : AddOrRemoveSelected
1015 //=======================================================================
1017 void AIS_InteractiveContext::AddOrRemoveSelected(const TopoDS_Shape& aShap,
1018 const Standard_Boolean updateviewer)
1020 if(!HasOpenedContext()) {
1022 cout<<" Attempt to remove a selected shape with no opened local context"<<endl;
1027 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(aShap,updateviewer);
1028 if(updateviewer) UpdateCurrentViewer();
1031 //=======================================================================
1032 //function : AddOrRemoveSelected
1034 //=======================================================================
1036 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(SelectMgr_EntityOwner)& Own,
1037 const Standard_Boolean updateviewer)
1039 if(!HasOpenedContext()) {
1041 cout<<" Attempt to remove a selected ownr with no opened local context"<<endl;
1046 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(Own,Standard_False);
1047 if(updateviewer) UpdateCurrentViewer();
1053 //=======================================================================
1054 //function : IsSelected
1056 //=======================================================================
1058 Standard_Boolean AIS_InteractiveContext::
1059 IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const
1061 if (anIObj.IsNull()) return Standard_False;
1063 if(!HasOpenedContext())
1064 return (anIObj->State()==1);
1066 return myLocalContexts(myCurLocalIndex)->IsSelected(anIObj);
1070 //=======================================================================
1071 //function : InitSelected
1073 //=======================================================================
1075 void AIS_InteractiveContext::InitSelected()
1077 if(!HasOpenedContext())
1078 AIS_Selection::Selection(myCurrentName.ToCString())->Init();
1080 myLocalContexts(myCurLocalIndex)->InitSelected();
1083 //=======================================================================
1084 //function : MoreSelected
1086 //=======================================================================
1088 Standard_Boolean AIS_InteractiveContext::MoreSelected() const
1090 if(!HasOpenedContext())
1091 return AIS_Selection::Selection(myCurrentName.ToCString())->More();
1092 return myLocalContexts(myCurLocalIndex)->MoreSelected();
1095 //=======================================================================
1096 //function : NextSelected
1098 //=======================================================================
1100 void AIS_InteractiveContext::NextSelected()
1102 if(!HasOpenedContext())
1103 AIS_Selection::Selection(myCurrentName.ToCString())->Next();
1105 myLocalContexts(myCurLocalIndex)->NextSelected();
1108 //=======================================================================
1109 //function : HasSelectedShape
1111 //=======================================================================
1113 Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
1115 if(!HasOpenedContext()) {
1117 Handle(AIS_Shape) shape =
1118 Handle(AIS_Shape)::DownCast(SelectedInteractive());
1119 if( !shape.IsNull() ) return Standard_True;
1121 return Standard_False;
1123 return myLocalContexts(myCurLocalIndex)->HasShape();
1128 //=======================================================================
1129 //function : SelectedShape
1131 //=======================================================================
1133 TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
1136 if(!HasOpenedContext()){
1139 Handle(AIS_Shape) shape =
1140 Handle(AIS_Shape)::DownCast(SelectedInteractive());
1141 if( !shape.IsNull() ) sh = shape->Shape();
1145 return myLocalContexts(myCurLocalIndex)->SelectedShape();
1148 //=======================================================================
1149 //function : Interactive
1151 //=======================================================================
1153 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Interactive() const
1155 return SelectedInteractive();
1158 Handle(AIS_InteractiveObject) AIS_InteractiveContext::SelectedInteractive() const
1160 if(!HasOpenedContext()){
1161 Handle(Standard_Transient) TR =AIS_Selection::Selection(myCurrentName.ToCString())->Value();
1162 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
1165 return myLocalContexts(myCurLocalIndex)->SelectedInteractive();
1168 //=======================================================================
1169 //function : Interactive
1171 //=======================================================================
1173 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const
1175 if(!HasOpenedContext()){
1176 Handle(SelectMgr_EntityOwner) Ownr;
1179 return myLocalContexts(myCurLocalIndex)->SelectedOwner();
1183 //=======================================================================
1184 //function : EntityOwners
1186 //=======================================================================
1187 void AIS_InteractiveContext::EntityOwners(SelectMgr_IndexedMapOfOwner& theOwners,
1188 const Handle(AIS_InteractiveObject)& theIObj,
1189 const Standard_Integer theMode) const
1191 if ( theIObj.IsNull() )
1194 TColStd_ListOfInteger aModes;
1195 if ( theMode == -1 )
1196 ActivatedModes( theIObj, aModes );
1198 aModes.Append( theMode );
1200 TColStd_ListIteratorOfListOfInteger anItr( aModes );
1201 for (; anItr.More(); anItr.Next() )
1203 int aMode = anItr.Value();
1204 if ( !theIObj->HasSelection( aMode ) )
1207 Handle(SelectMgr_Selection) aSel = theIObj->Selection( aMode );
1209 for ( aSel->Init(); aSel->More(); aSel->Next() )
1211 Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive();
1212 if ( aEntity.IsNull() )
1215 Handle(SelectMgr_EntityOwner) aOwner =
1216 Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId());
1217 if ( !aOwner.IsNull() )
1218 theOwners.Add( aOwner );
1223 Standard_Integer AIS_InteractiveContext::NbSelected()
1225 Standard_Integer i(0);
1226 for(InitSelected();MoreSelected();NextSelected())
1231 //=======================================================================
1232 //function : HasApplicative
1234 //=======================================================================
1236 Standard_Boolean AIS_InteractiveContext::HasApplicative() const
1238 return Interactive()->HasOwner();
1241 //=======================================================================
1242 //function : Applicative
1244 //=======================================================================
1246 Handle(Standard_Transient) AIS_InteractiveContext::Applicative() const
1248 return Interactive()->GetOwner();
1253 //==================================================
1256 //==================================================
1257 Standard_Boolean AIS_InteractiveContext::HasDetected() const
1259 if(HasOpenedContext())
1260 return myLocalContexts(myCurLocalIndex)->HasDetected();
1262 return !myLastPicked.IsNull();
1265 //=======================================================================
1266 //function : HasDetectedShape
1268 //=======================================================================
1270 Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
1272 if(HasOpenedContext())
1273 return myLocalContexts(myCurLocalIndex)->HasDetectedShape();
1274 return Standard_False;
1277 //=======================================================================
1278 //function : DetectedShape
1280 //=======================================================================
1283 AIS_InteractiveContext::DetectedShape() const
1285 return myLocalContexts(myCurLocalIndex)->DetectedShape();
1288 //=======================================================================
1289 //function : DetectedInteractive
1291 //=======================================================================
1293 Handle(AIS_InteractiveObject)
1294 AIS_InteractiveContext::DetectedInteractive() const
1296 if(HasOpenedContext())
1297 return myLocalContexts(myCurLocalIndex)->DetectedInteractive();
1298 return myLastPicked;
1302 Standard_Boolean AIS_InteractiveContext::HasNextDetected() const
1304 if(!HasOpenedContext())
1305 return Standard_False; // temporaire
1307 return myLocalContexts(myCurLocalIndex)->HasNextDetected();
1312 //=======================================================================
1313 //function : DetectedOwner
1315 //=======================================================================
1316 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedOwner() const
1318 if(HasOpenedContext())
1319 return myLocalContexts(myCurLocalIndex)->DetectedOwner();
1320 Handle(SelectMgr_EntityOwner) Ownr;
1325 //=======================================================================
1326 //function : HilightNextDetected
1328 //=======================================================================
1329 Standard_Integer AIS_InteractiveContext::HilightNextDetected(const Handle(V3d_View)& V)
1331 if(!HasOpenedContext())
1333 return myLocalContexts(myCurLocalIndex)->HilightNextDetected(V);
1337 //=======================================================================
1338 //function : HilightNextDetected
1340 //=======================================================================
1341 Standard_Integer AIS_InteractiveContext::HilightPreviousDetected(const Handle(V3d_View)& V)
1343 if(!HasOpenedContext())
1345 return myLocalContexts(myCurLocalIndex)->HilightPreviousDetected(V);
1350 void AIS_InteractiveContext::Drag(
1351 const Handle(V3d_View)& aView,
1352 const Handle(AIS_InteractiveObject)& anObject,
1353 const Handle(Geom_Transformation)& aTrsf,
1354 const Standard_Boolean postConcatenate,
1355 const Standard_Boolean update,
1356 const Standard_Boolean zBuffer) {
1358 if( anObject.IsNull() || aView.IsNull() ) return;
1361 anObject->SetTransformation(aTrsf,postConcatenate,Standard_True);
1363 } else if( Visual3d_TransientManager::BeginDraw(aView->View(),
1364 zBuffer,Standard_False) ) {
1365 Handle(Prs3d_Presentation) P = anObject->Presentation();
1367 if( postConcatenate ) P->Multiply(aTrsf);
1368 else P->Transform(aTrsf);
1369 Visual3d_TransientManager::DrawStructure(P);
1371 Visual3d_TransientManager::EndDraw(Standard_True);
1377 //=======================================================================
1378 //function : InitDetected
1380 //=======================================================================
1381 void AIS_InteractiveContext::InitDetected()
1383 if(HasOpenedContext())
1385 myLocalContexts(myCurLocalIndex)->InitDetected();
1389 if(myAISDetectedSeq.Length() != 0)
1390 myAISCurDetected = 1;
1394 //=======================================================================
1395 //function : MoreDetected
1397 //=======================================================================
1398 Standard_Boolean AIS_InteractiveContext::MoreDetected() const
1400 if(HasOpenedContext())
1401 return myLocalContexts(myCurLocalIndex)->MoreDetected();
1403 return (myAISCurDetected>0 &&myAISCurDetected <= myAISDetectedSeq.Length()) ?
1404 Standard_True : Standard_False;
1407 //=======================================================================
1408 //function : NextDetected
1410 //=======================================================================
1411 void AIS_InteractiveContext::NextDetected()
1413 if(HasOpenedContext())
1415 myLocalContexts(myCurLocalIndex)->NextDetected();
1422 //=======================================================================
1423 //function : DetectedCurrentShape
1425 //=======================================================================
1427 const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
1429 if(HasOpenedContext())
1430 return myLocalContexts(myCurLocalIndex)->DetectedCurrentShape();
1432 static TopoDS_Shape bidsh;
1433 if(myAISCurDetected > 0 &&
1434 myAISCurDetected <= myAISDetectedSeq.Length())
1435 return Handle(AIS_Shape)::DownCast(myAISDetectedSeq(myAISCurDetected))->Shape();
1439 //=======================================================================
1440 //function : DetectedCurrentObject
1442 //=======================================================================
1444 Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const {
1445 if(HasOpenedContext())
1446 return myLocalContexts(myCurLocalIndex)->DetectedCurrentObject();
1448 Handle(AIS_InteractiveObject) aBad;
1450 if(myAISCurDetected > 0 &&
1451 myAISCurDetected <= myAISDetectedSeq.Length())
1452 return myAISDetectedSeq(myAISCurDetected);