Salome HOME
OCC functionality moving out from the widget
[modules/hydro.git] / src / HYDROCurveCreator / CurveCreator_Utils.cxx
index 1775167850ea90c1f35e20cca96947adf9fc4922..73b429b446db6a5a20047c7bf34a2f5c4d1163e4 100644 (file)
@@ -48,7 +48,7 @@
 #include <ElSLib.hxx>
 
 const double LOCAL_SELECTION_TOLERANCE = 0.0001;
-const int SCENE_PIXEL_TOLERANCE = 10;
+const int    SCENE_PIXEL_TOLERANCE = 10;
 
 //=======================================================================
 // function : ConvertClickToPoint()
@@ -69,28 +69,52 @@ void CurveCreator_Utils::ConvertPointToClick( const gp_Pnt& thePoint,
 gp_Pnt CurveCreator_Utils::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView )
 {
   return GEOMUtils::ConvertClickToPoint( x, y, aView );
-  /*
-  V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
-  aView->Eye( XEye, YEye, ZEye );
-
-  aView->At( XAt, YAt, ZAt );
-  gp_Pnt EyePoint( XEye, YEye, ZEye );
-  gp_Pnt AtPoint( XAt, YAt, ZAt );
-
-  gp_Vec EyeVector( EyePoint, AtPoint );
-  gp_Dir EyeDir( EyeVector );
+}
 
-  gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir );
-  Standard_Real X, Y, Z;
-  aView->Convert( x, y, X, Y, Z );
-  gp_Pnt ConvertedPoint( X, Y, Z );
+std::list<float> CurveCreator_Utils::getSelectedPoints( Handle(AIS_InteractiveContext) theContext )
+{
+  std::list<float> aSelectedPoints;
+
+  gp_Pnt aPnt;
+  for ( theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected() ) {
+    TopoDS_Vertex aVertex;
+    TopoDS_Shape aShape = theContext->SelectedShape();
+    if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
+      aVertex = TopoDS::Vertex( theContext->SelectedShape() );
+    else {
+      Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
+      if ( !anOwner.IsNull() ) {
+        Handle(AIS_InteractiveObject) anAIS = Handle(AIS_InteractiveObject)::DownCast( anOwner->Selectable() );
+        if ( !anAIS.IsNull() ) {
+          Handle(AIS_Point) aPoint = Handle(AIS_Point)::DownCast( anAIS);
+          if ( !aPoint.IsNull() )
+            aVertex = TopoDS::Vertex( aPoint->Vertex() );
+        }
+        if ( aVertex.IsNull() ) {
+          // the following happens if there are no points in the current curve, there is only a shape
+          /*Handle(StdSelect_BRepOwner) aBrepOwner = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
+          if ( aBrepOwner.IsNull() )
+            continue;
+          if ( aBrepOwner->HasShape() ) {
+            const TopoDS_Shape& aShape = aBrepOwner->Shape();
+            if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
+            {
+              aVertex = TopoDS::Vertex( aShape );
+            }
+          }*/
+        }
+      }
+    }
+    if ( aVertex.IsNull() )
+      continue;
+    aPnt = BRep_Tool::Pnt( aVertex );
+    aSelectedPoints.push_back( aPnt.X() );
+    aSelectedPoints.push_back( aPnt.Y() );
+    aSelectedPoints.push_back( aPnt.Z() );
+  }
 
-  gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint );
-  gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView );
-  return ResultPoint;
-  */
+  return aSelectedPoints;
 }
-
 //=======================================================================
 // function : setLocalPointContext
 // purpose  : Open/close the viewer local context