0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / IVtkOCC / IVtkOCC_ShapePickerAlgo.cxx
index 24255ce..fac7391 100644 (file)
 #include <Message_Messenger.hxx>
 #include <StdSelect_BRepOwner.hxx>
 
+IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_ShapePickerAlgo,IVtk_IShapePickerAlgo)
+
 // Handle implementation
-IMPLEMENT_STANDARD_HANDLE(IVtkOCC_ShapePickerAlgo, IVtk_IShapePickerAlgo)
-IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_ShapePickerAlgo, IVtk_IShapePickerAlgo)
+
 
 //================================================================
 // Function : Constructor
@@ -58,7 +59,7 @@ IVtk_SelectionModeList IVtkOCC_ShapePickerAlgo::GetSelectionModes (
 {
   IVtk_SelectionModeList aRes;
 
-  if (theShape)
+  if (! theShape.IsNull())
   {
     // Get shape implementation from shape interface.
     Handle(IVtkOCC_Shape) aShapeImpl = Handle(IVtkOCC_Shape)::DownCast(theShape);
@@ -91,7 +92,7 @@ void IVtkOCC_ShapePickerAlgo::SetSelectionMode (const IVtk_IShape::Handle& theSh
                                                 const IVtk_SelectionMode theMode,
                                                 const bool theIsTurnOn)
 {
-  if (!theShape)
+  if (theShape.IsNull())
   {
     return;
   }
@@ -258,9 +259,7 @@ void IVtkOCC_ShapePickerAlgo::SubShapesPicked (const IVtk_IdType theId, IVtk_Sha
 {
   if (mySubShapesPicked.IsBound (theId))
   {
-    // Need non-const this to call the map's operator[]
-    IVtkOCC_ShapePickerAlgo* that = const_cast< IVtkOCC_ShapePickerAlgo* >(this);
-    theShapeList = that->mySubShapesPicked (theId);
+    theShapeList = mySubShapesPicked (theId);
   }
 }
 
@@ -270,6 +269,7 @@ void IVtkOCC_ShapePickerAlgo::SubShapesPicked (const IVtk_IdType theId, IVtk_Sha
 //================================================================
 void IVtkOCC_ShapePickerAlgo::clearPicked()
 {
+  myTopPickedPoint.SetCoord (RealLast(), RealLast(), RealLast());
   myShapesPicked.Clear();
   mySubShapesPicked.Clear();
 }
@@ -290,9 +290,11 @@ int IVtkOCC_ShapePickerAlgo::NbPicked()
 bool IVtkOCC_ShapePickerAlgo::processPicked()
 {
   Standard_Integer aNbPicked =  myViewerSelector->NbPicked();
+
   Handle(StdSelect_BRepOwner) anEntityOwner;
   Handle(Message_Messenger) anOutput = Message::DefaultMessenger();
 
+  bool isTop = true;
   for (Standard_Integer aDetectIt = 1; aDetectIt <= aNbPicked; aDetectIt++)
   {
     // ViewerSelector detects sensitive entities under the mouse
@@ -306,33 +308,38 @@ bool IVtkOCC_ShapePickerAlgo::processPicked()
       Handle(IVtkOCC_SelectableObject) aSelectable =
         Handle(IVtkOCC_SelectableObject)::DownCast (anEntityOwner->Selectable());
 
-      if (!aSelectable)
+      if (aSelectable.IsNull())
       {
-        anOutput << "Error: EntityOwner having null SelectableObject picked!";
+        anOutput->SendAlarm() << "Error: EntityOwner having null SelectableObject picked!";
         continue;
       }
 
       Handle(IVtkOCC_Shape) aSelShape = aSelectable->GetShape();
-      if (!aSelShape)
+      if (aSelShape.IsNull())
       {
-        anOutput << "Error: SelectableObject with null OccShape pointer picked!";
+        anOutput->SendAlarm() << "Error: SelectableObject with null OccShape pointer picked!";
         continue;
       }
 
       IVtk_IdType aTopLevelId = aSelShape->GetId();
       myShapesPicked.Append (aTopLevelId);
+      if (isTop)
+      {
+        isTop = false;
+        myTopPickedPoint = myViewerSelector->PickedPoint (aDetectIt);
+      }
 
       // Now try to guess if it's the top-level shape itself or just a sub-shape picked
       TopoDS_Shape aTopLevelShape = aSelShape->GetShape();
       TopoDS_Shape aSubShape      = anEntityOwner->Shape();
       if (aTopLevelShape.IsNull())
       {
-        anOutput << "Error: OccShape with null top-level TopoDS_Shape picked!";
+        anOutput->SendAlarm() << "Error: OccShape with null top-level TopoDS_Shape picked!";
         continue;
       }
       if (aSubShape.IsNull())
       {
-        anOutput << "Error: EntityOwner with null TopoDS_Shape picked!";
+        anOutput->SendAlarm() << "Error: EntityOwner with null TopoDS_Shape picked!";
         continue;
       }
 
@@ -353,3 +360,23 @@ bool IVtkOCC_ShapePickerAlgo::processPicked()
 
   return !myShapesPicked.IsEmpty();
 }
+
+//============================================================================
+//  Method: RemoveSelectableActor
+// Purpose: Remove selectable object from the picker (from internal maps).
+//============================================================================
+void IVtkOCC_ShapePickerAlgo::RemoveSelectableObject(const IVtk_IShape::Handle& theShape)
+{
+  clearPicked();
+  // Get shape implementation from shape interface.
+  Handle(IVtkOCC_Shape) aShapeImpl =
+    Handle(IVtkOCC_Shape)::DownCast(theShape);
+
+  // Get selectable object from the shape implementation.
+  Handle(IVtkOCC_SelectableObject) aSelObj =
+    Handle(IVtkOCC_SelectableObject)::DownCast(aShapeImpl->GetSelectableObject());
+
+  myViewerSelector->RemoveSelectableObject(aSelObj);
+  myViewerSelector->Clear();
+  aShapeImpl->SetSelectableObject(NULL);
+}
\ No newline at end of file