0024023: Revamp the OCCT Handle -- downcast (automatic)
[occt.git] / src / AIS / AIS_InteractiveContext_1.cxx
index 0ba0744..4b7b25e 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-#define UKI60826       //GG_161199     Use the requested selection color instead of default
-
-#define        IMP280200       //GG Don't returns a NULL shape in SelectedShape()
-//                     method when the current selected is a shape !
-
-#define BUC60814       //GG_300101     Idem UKI60826
-
-#define OCC138          //VTN Avoding infinit loop in AddOrRemoveCurrentObject method.
-
-#define OCC9657
-
 #include <AIS_InteractiveContext.jxx>
 #include <SelectMgr_EntityOwner.hxx>
+#include <StdSelect_ViewerSelector3d.hxx>
 #include <AIS_Selection.hxx>
 #include <AIS_StatusOfDetection.hxx>
 #include <AIS_StatusOfPick.hxx>
@@ -43,6 +33,7 @@
 #include <V3d_SpotLight.hxx>
 #include <V3d_DirectionalLight.hxx>
 #include <V3d_AmbientLight.hxx>
+#include <Visual3d_View.hxx>
 
 #include <TColStd_ListIteratorOfListOfInteger.hxx>
 #include <SelectMgr_Selection.hxx>
 
 #include <Prs3d_Presentation.hxx>
 
-#ifdef OCC9657
 #include <AIS_MapOfInteractive.hxx>
 #include <AIS_MapIteratorOfMapOfInteractive.hxx>
-#endif
+#include <AIS_InteractiveObject.hxx>
 
 //=======================================================================
 //function : MoveTo
@@ -84,7 +74,7 @@ AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const Standard_Integer  th
   AIS_StatusOfDetection aStatus        = AIS_SOD_Nothing;
   Standard_Boolean      toUpdateViewer = Standard_False;
 
-  // allonzy
+  myFilters->SetDisabledObjects (theView->View()->HiddenObjects());
   myMainSel->Pick (theXPix, theYPix, theView);
 
   // filling of myAISDetectedSeq sequence storing information about detected AIS objects
@@ -531,11 +521,7 @@ void AIS_InteractiveContext::SetCurrentObject(const Handle(AIS_InteractiveObject
     Standard_Boolean HasHiCol;
     if(IsHilighted(anIObj,HasHiCol,HiCol)){
       if(HasHiCol && HiCol!= mySelectionColor) {
-#ifdef UKI60826
        HilightWithColor(anIObj,mySelectionColor,updateviewer);
-#else
-       Hilight(anIObj,updateviewer);
-#endif
       }
     }
     return;
@@ -555,7 +541,7 @@ void AIS_InteractiveContext::SetCurrentObject(const Handle(AIS_InteractiveObject
     sel->Init();
     while (sel->More()) {
       TR = sel->Value();
-      IO = *((Handle(AIS_InteractiveObject)*)&TR);
+      IO = Handle(AIS_InteractiveObject)::DownCast (TR);
       Unhilight(IO,Standard_False);
       IO->State(0);
       sel->Next();
@@ -568,25 +554,17 @@ void AIS_InteractiveContext::SetCurrentObject(const Handle(AIS_InteractiveObject
     Standard_Boolean HasHiCol;
     if(IsHilighted(anIObj,HasHiCol,HiCol)){
       if(HasHiCol && HiCol!= mySelectionColor) {
-#ifdef UKI60826
          HilightWithColor(anIObj,mySelectionColor,Standard_False);
-#else
-         Hilight(anIObj,Standard_False);
-#endif
       }
     }
     else{
-#ifdef UKI60826
        HilightWithColor(anIObj,mySelectionColor,Standard_False);
-#else
-      Hilight(anIObj,Standard_False);
-#endif
     }
     if (updateviewer) 
       UpdateCurrentViewer();
   }
   else{
-#ifdef AIS_DEB
+#ifdef OCCT_DEBUG
     cout<<"Nothing Done : Opened Local Context"<<endl;
 #endif
   }
@@ -613,11 +591,7 @@ AddOrRemoveCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
     Standard_Integer mod = (SelStat==AIS_SS_Added) ? 1 : 0;
     anIObj->State(mod);
     if(mod==1)
-#ifdef BUC60814
       HilightWithColor(anIObj,mySelectionColor,Standard_False);
-#else
-      Hilight(anIObj,Standard_False);
-#endif
     else 
       Unhilight(anIObj,Standard_False);
     
@@ -626,7 +600,7 @@ AddOrRemoveCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
       UpdateCurrentViewer();
   }
   else{
-#ifdef AIS_DEB
+#ifdef OCCT_DEBUG
     cout<<"Nothing Done : Opened Local Context"<<endl;
 #endif
   }
@@ -701,7 +675,7 @@ void AIS_InteractiveContext::NextCurrent()
 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Current() const 
 {
   Handle(Standard_Transient) TR = AIS_Selection::Selection(myCurrentName.ToCString())->Value();
-  Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
+  Handle(AIS_InteractiveObject) IO = Handle(AIS_InteractiveObject)::DownCast (TR);
   return IO;
 }
 
@@ -744,12 +718,8 @@ void AIS_InteractiveContext::HilightCurrents(const Standard_Boolean updateviewer
   sel->Init();
   while (sel->More()) {
     TR = sel->Value();
-    IO = *((Handle(AIS_InteractiveObject)*)&TR);
-#ifdef BUC60814
+    IO = Handle(AIS_InteractiveObject)::DownCast (TR);
     HilightWithColor(IO,mySelectionColor,Standard_False);
-#else
-    Hilight(IO,Standard_False);
-#endif
     sel->Next();
   }
   if(updateviewer) 
@@ -770,7 +740,7 @@ void AIS_InteractiveContext::UnhilightCurrents(const Standard_Boolean updateview
   sel->Init();
   while (sel->More()) {
     TR = sel->Value();
-    IO = *((Handle(AIS_InteractiveObject)*)&TR);
+    IO = Handle(AIS_InteractiveObject)::DownCast (TR);
     Unhilight(IO,Standard_False);
     sel->Next();
   }
@@ -792,7 +762,7 @@ void AIS_InteractiveContext::ClearCurrents(const Standard_Boolean updateviewer)
   Handle(AIS_InteractiveObject) IO;
   for(S->Init();S->More();S->Next()){
     Tr = S->Value();
-    IO = (*((Handle(AIS_InteractiveObject)*)&Tr));
+    IO = Handle(AIS_InteractiveObject)::DownCast (Tr);
     IO->State(0);
     Unhilight(IO,Standard_False);
   }
@@ -817,12 +787,8 @@ void AIS_InteractiveContext::HilightSelected(const Standard_Boolean updateviewer
     sel->Init();
     while (sel->More()) {
       TR = sel->Value();
-      IO = *((Handle(AIS_InteractiveObject)*)&TR);
-#ifdef BUC60814
+      IO = Handle(AIS_InteractiveObject)::DownCast (TR);
       HilightWithColor(IO,mySelectionColor,Standard_False);
-#else
-      Hilight(IO,Standard_False);
-#endif
       sel->Next();
     }
   }
@@ -849,7 +815,7 @@ void AIS_InteractiveContext::UnhilightSelected(const Standard_Boolean updateview
     sel->Init();
     while (sel->More()) {
       TR = sel->Value();
-      IO = *((Handle(AIS_InteractiveObject)*)&TR);
+      IO = Handle(AIS_InteractiveObject)::DownCast (TR);
       Unhilight(IO,Standard_False);
       sel->Next();
     }
@@ -887,7 +853,7 @@ void AIS_InteractiveContext::SetSelectedCurrent()
 {
 
 
-#ifdef AIS_DEB
+#ifdef OCCT_DEBUG
   cout<<"Not Yet Implemented"<<endl;
 #endif
 }
@@ -944,7 +910,7 @@ void AIS_InteractiveContext::AddOrRemoveSelected(const TopoDS_Shape& aShap,
                                            const Standard_Boolean updateviewer)
 { 
   if(!HasOpenedContext()) {
-#ifdef AIS_DEB
+#ifdef OCCT_DEBUG
     cout<<" Attempt to remove a selected shape with no opened local context"<<endl;
 #endif
     return;
@@ -963,7 +929,7 @@ void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(SelectMgr_EntityOw
                                                 const Standard_Boolean updateviewer)
 { 
   if(!HasOpenedContext()) {
-#ifdef AIS_DEB
+#ifdef OCCT_DEBUG
     cout<<" Attempt to remove a selected ownr with no opened local context"<<endl;
 #endif
     return;
@@ -1039,16 +1005,12 @@ void AIS_InteractiveContext::NextSelected()
 Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const 
 {
   if(!HasOpenedContext()) {
-#ifdef IMP280200
     Handle(AIS_Shape) shape = 
        Handle(AIS_Shape)::DownCast(SelectedInteractive());
     if( !shape.IsNull() ) return Standard_True;
-#endif
     return Standard_False;
   }
-  return myLocalContexts(myCurLocalIndex)->HasShape();
-  
-  
+  return myLocalContexts(myCurLocalIndex)->HasSelectedShape();
 }
 
 //=======================================================================
@@ -1064,7 +1026,9 @@ TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
     Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (SelectedInteractive());
     if (!aShape.IsNull())
     {
-      aResShape = aShape->Shape().Located (TopLoc_Location (SelectedInteractive()->Transformation()) * aShape->Shape().Location());
+      TopLoc_Location aLocTrsf = SelectedInteractive()->Transformation().Form() == gp_Identity ?
+                                 TopLoc_Location() : TopLoc_Location (SelectedInteractive()->Transformation());
+      aResShape = aShape->Shape().Located (aLocTrsf * aShape->Shape().Location());
     }
 
     return aResShape;
@@ -1088,8 +1052,10 @@ Handle(AIS_InteractiveObject) AIS_InteractiveContext::Interactive() const
 Handle(AIS_InteractiveObject) AIS_InteractiveContext::SelectedInteractive() const 
 {
   if(!HasOpenedContext()){
+    if (AIS_Selection::Selection(myCurrentName.ToCString())->Extent() == 0)
+      return NULL;
     Handle(Standard_Transient) TR  =AIS_Selection::Selection(myCurrentName.ToCString())->Value();
-    Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
+    Handle(AIS_InteractiveObject) IO = Handle(AIS_InteractiveObject)::DownCast (TR);
     return IO;}
   
   return  myLocalContexts(myCurLocalIndex)->SelectedInteractive();
@@ -1114,7 +1080,7 @@ Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const
 //function : EntityOwners
 //purpose  : 
 //=======================================================================
-void AIS_InteractiveContext::EntityOwners(SelectMgr_IndexedMapOfOwner& theOwners,
+void AIS_InteractiveContext::EntityOwners(Handle(SelectMgr_IndexedMapOfOwner)& theOwners,
                                          const Handle(AIS_InteractiveObject)& theIObj,
                                          const Standard_Integer theMode) const 
 {
@@ -1127,6 +1093,9 @@ void AIS_InteractiveContext::EntityOwners(SelectMgr_IndexedMapOfOwner& theOwners
   else
     aModes.Append( theMode );
 
+  if (theOwners.IsNull())
+    theOwners = new SelectMgr_IndexedMapOfOwner();
+
   TColStd_ListIteratorOfListOfInteger anItr( aModes );
   for (; anItr.More(); anItr.Next() )
   {
@@ -1134,18 +1103,18 @@ void AIS_InteractiveContext::EntityOwners(SelectMgr_IndexedMapOfOwner& theOwners
     if ( !theIObj->HasSelection( aMode ) )
       continue;
 
-    Handle(SelectMgr_Selection) aSel = theIObj->Selection( aMode );
+    Handle(SelectMgr_Selection) aSel = theIObj->Selection(aMode);
 
     for ( aSel->Init(); aSel->More(); aSel->Next() )
     {
-      Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive();
+      Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive()->BaseSensitive();
       if ( aEntity.IsNull() )
        continue;
 
       Handle(SelectMgr_EntityOwner) aOwner =
        Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId());
       if ( !aOwner.IsNull() )
-       theOwners.Add( aOwner );
+       theOwners->Add( aOwner );
     }
   }
 }