Salome HOME
OCC functionality moving out from the widget
[modules/hydro.git] / src / HYDROCurveCreator / CurveCreator_Utils.cxx
index 1fa61b3378265aaa96134014f620f2de147b8980..12d7ee7d84cf92d6a17a80aef4630e1eaf760122 100644 (file)
@@ -71,14 +71,62 @@ gp_Pnt CurveCreator_Utils::ConvertClickToPoint( int x, int y, Handle(V3d_View) a
   return GEOMUtils::ConvertClickToPoint( x, y, aView );
 }
 
+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() );
+  }
+
+  return aSelectedPoints;
+}
 //=======================================================================
 // function : setLocalPointContext
 // purpose  : Open/close the viewer local context
 //=======================================================================
+//#define USE_COMPOUND
 void CurveCreator_Utils::setLocalPointContext(
                                               Handle(AIS_InteractiveContext) theContext,
                                               const bool theOpen )
 {
+#ifdef USE_COMPOUND
+  return;
+#endif
   if ( !theContext )
     return;
 
@@ -102,8 +150,8 @@ void CurveCreator_Utils::setLocalPointContext(
         if ( anAIS->IsKind( STANDARD_TYPE( AIS_Shape ) ) )
         {
           theContext->Load( anAIS, -1/*selection mode*/, true/*allow decomposition*/ );
-          theContext->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)TopAbs_WIRE ) );
-          //theContext->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)TopAbs_VERTEX ) );
+          //theContext->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)TopAbs_WIRE ) );
+          theContext->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)TopAbs_VERTEX ) );
         }
         else if ( anAIS->DynamicType() != STANDARD_TYPE(AIS_Trihedron) )
         {