]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
authornds <natalia.donis@opencascade.com>
Mon, 9 Jun 2014 13:20:27 +0000 (17:20 +0400)
committernds <natalia.donis@opencascade.com>
Mon, 9 Jun 2014 13:20:27 +0000 (17:20 +0400)
Feature Arc creation. Project third point on the arc circle

src/GeomAPI/CMakeLists.txt
src/GeomAPI/GeomAPI_Circ2d.cpp [new file with mode: 0644]
src/GeomAPI/GeomAPI_Circ2d.h [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp
src/PartSet/PartSet_FeatureArcPrs.cpp
src/PartSet/PartSet_FeatureArcPrs.h
src/PartSet/PartSet_OperationCreateFeature.cpp

index 2a2f3ed40e5ffe4ac1b7ef99880054a9a1a4e1a2..e14d63fe3d7559daea10803987490dd6194efb7e 100644 (file)
@@ -5,6 +5,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
 
 SET(PROJECT_HEADERS
     GeomAPI.h
+    GeomAPI_Circ2d.h
     GeomAPI_Interface.h
     GeomAPI_XY.h
     GeomAPI_XYZ.h
@@ -18,6 +19,7 @@ SET(PROJECT_HEADERS
 )
 
 SET(PROJECT_SOURCES
+    GeomAPI_Circ2d.cpp
     GeomAPI_Interface.cpp
     GeomAPI_XY.cpp
     GeomAPI_XYZ.cpp
diff --git a/src/GeomAPI/GeomAPI_Circ2d.cpp b/src/GeomAPI/GeomAPI_Circ2d.cpp
new file mode 100644 (file)
index 0000000..4985ae3
--- /dev/null
@@ -0,0 +1,70 @@
+// File:        GeomAPI_Circ2d.cpp
+// Created:     29 May 2014
+// Author:      Artem ZHIDKOV
+
+#include <GeomAPI_Circ2d.h>
+#include <GeomAPI_Pnt2d.h>
+
+#include <gp_Dir2d.hxx>
+#include <gp_Circ2d.hxx>
+#include <gp_Pnt2d.hxx>
+#include <gp_Ax2d.hxx>
+#include <Geom2d_Circle.hxx>
+#include <Geom2dAPI_ProjectPointOnCurve.hxx>
+#include <Precision.hxx>
+
+#include <IntAna2d_AnaIntersection.hxx>
+
+#define MY_CIRC2D static_cast<gp_Circ2d*>(myImpl)
+
+static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY,
+                            const double thePointX,   const double thePointY)
+{
+  gp_Pnt2d aCenter(theCenterX, theCenterY);
+  gp_Pnt2d aPoint(thePointX, thePointY);
+
+  double aRadius = aCenter.Distance(aPoint);
+
+  if (aCenter.IsEqual(aPoint, Precision::Confusion()))
+      return NULL;
+
+  gp_Dir2d aDir(theCenterX - thePointX, theCenterY - thePointY);
+  return new gp_Circ2d(gp_Ax2d(aCenter, aDir), aRadius);
+}
+
+
+GeomAPI_Circ2d::GeomAPI_Circ2d(const boost::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+                               const boost::shared_ptr<GeomAPI_Pnt2d>& theCirclePoint)
+  : GeomAPI_Interface(newCirc2d(theCenter->x(), theCenter->y(),
+                                theCirclePoint->x(),   theCirclePoint->y()))
+{}
+
+const boost::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Circ2d::project(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const
+{
+  boost::shared_ptr<GeomAPI_Pnt2d> aResult;
+  if (!MY_CIRC2D)
+    return aResult;
+
+  Handle(Geom2d_Circle) aCircle = new Geom2d_Circle(MY_CIRC2D->Axis(), MY_CIRC2D->Radius());//(aCirc);
+
+  const gp_Pnt2d& aPoint = thePoint->impl<gp_Pnt2d>();
+
+  Geom2dAPI_ProjectPointOnCurve aProj(aPoint, aCircle);
+  Standard_Integer aNbPoint = aProj.NbPoints();
+  double aX, anY;
+  if (aNbPoint > 0) {
+    double aMinDistance = 0, aDistance;
+    for (Standard_Integer j = 1; j <= aNbPoint; j++) {
+      gp_Pnt2d aNewPoint = aProj.Point(j);
+      aDistance = aNewPoint.Distance(aPoint);
+      if (!aMinDistance || aDistance < aMinDistance) {
+        aX = aNewPoint.X();
+        anY = aNewPoint.Y();
+        aMinDistance = aDistance;
+        aResult = boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, anY));
+      }
+    }
+  }
+  return aResult;
+}
+
diff --git a/src/GeomAPI/GeomAPI_Circ2d.h b/src/GeomAPI/GeomAPI_Circ2d.h
new file mode 100644 (file)
index 0000000..8b91d83
--- /dev/null
@@ -0,0 +1,30 @@
+// File:        GeomAPI_Circ2d.h
+// Created:     29 May 2014
+// Author:      Artem ZHIDKOV
+
+#ifndef GeomAPI_Circ2d_HeaderFile
+#define GeomAPI_Circ2d_HeaderFile
+
+#include <GeomAPI_Interface.h>
+#include <boost/shared_ptr.hpp>
+
+class GeomAPI_Pnt2d;
+
+/**\class GeomAPI_Circ2d
+ * \ingroup DataModel
+ * \brief Line in 2D
+ */
+
+class GEOMAPI_EXPORT GeomAPI_Circ2d: public GeomAPI_Interface
+{
+public:
+  /// Creation of circle defined by center point and circle radius
+  GeomAPI_Circ2d(const boost::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+                 const boost::shared_ptr<GeomAPI_Pnt2d>& theCirclePoint);
+
+  /// Project point on line
+  const boost::shared_ptr<GeomAPI_Pnt2d> project(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const;
+};
+
+#endif
+
index 51437474968900e6d73b8c1a04aec5dc1ec61472..d12cbdd73816d48fadbfd83cd4e41fa339a73805 100644 (file)
@@ -58,7 +58,16 @@ boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_EdgeBuilder::lineCircleArc(
   double aRadius = theCenter->distance(theStartPoint);
   gp_Circ aCircle(gp_Ax2(aCenter, aDir), aRadius);
 
-  BRepBuilderAPI_MakeEdge anEdgeBuilder(aCircle);
+  const gp_Pnt& aStart = theStartPoint->impl<gp_Pnt>();
+  const gp_Pnt& anEnd = theEndPoint->impl<gp_Pnt>();
+
+  BRepBuilderAPI_MakeEdge anEdgeBuilder;
+  if (aStart.IsEqual(anEnd, Precision::Confusion()) ||
+      gp_Pnt(0, 0, 0).IsEqual(anEnd, Precision::Confusion()))
+    anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle);
+  else
+    anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle, aStart, anEnd);
+
   boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
   TopoDS_Edge anEdge = anEdgeBuilder.Edge();
   aRes->setImpl(new TopoDS_Shape(anEdge));
index 4cc26f008ce7b6ac61c14d80dfb1f093be634827..97af28864808bec64eb31ed4f435a80f36634151 100644 (file)
 #include <SketchPlugin_Arc.h>
 
 #include <GeomDataAPI_Point2D.h>
+#include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Circ2d.h>
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeRefList.h>
 
+#include <V3d_View.hxx>
+
 #include <Precision.hxx>
 
 using namespace std;
@@ -42,8 +46,8 @@ PartSet_SelectionMode PartSet_FeatureArcPrs::setPoint(double theX, double theY,
    }
    break;
    case SM_ThirdPoint: {
-      PartSet_Tools::setFeaturePoint(feature(), theX, theY, ARC_ATTR_END);
-      aMode = SM_DonePoint;
+     PartSet_Tools::setFeaturePoint(feature(), theX, theY, ARC_ATTR_END);
+     aMode = SM_DonePoint;
    }
     break;
     default:
@@ -85,6 +89,31 @@ PartSet_SelectionMode PartSet_FeatureArcPrs::getNextMode(const std::string& theA
   return aMode;
 }
 
+void PartSet_FeatureArcPrs::projectPointOnArc(gp_Pnt& thePoint, Handle(V3d_View) theView,
+                                              double& theX, double& theY)
+{
+  FeaturePtr aSketch = sketch();
+  if (aSketch) {
+    double aX, anY;
+    PartSet_Tools::convertTo2D(thePoint, aSketch, theView, aX, anY);
+
+    // circle origin point and radius
+    boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+    boost::shared_ptr<GeomDataAPI_Point2D> aCenter = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+                                                              (aData->attribute(ARC_ATTR_CENTER));
+    boost::shared_ptr<GeomDataAPI_Point2D> aStart = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+                                                              (aData->attribute(ARC_ATTR_START));
+
+    boost::shared_ptr<GeomAPI_Circ2d> aCirc(new GeomAPI_Circ2d(aCenter->pnt(), aStart->pnt()));
+    boost::shared_ptr<GeomAPI_Pnt2d> aGeomPoint2d(new GeomAPI_Pnt2d(aX, anY));
+    boost::shared_ptr<GeomAPI_Pnt2d> aPnt2d = aCirc->project(aGeomPoint2d);
+    if (aPnt2d) {
+      theX = aPnt2d->x();
+      theY = aPnt2d->y();
+    }
+  }
+}
+
 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureArcPrs::featurePoint
                                                      (const PartSet_SelectionMode& theMode)
 {
index ea25b971f2332b69aee18d245edb6a233f92806d..a02029e7fec24b79fe726c3c34b97394dadc4026 100644 (file)
 #include "PartSet_FeaturePrs.h"
 #include "PartSet_Constants.h"
 
+#include <gp_Pnt.hxx>
+
 class GeomDataAPI_Point2D;
+class Handle_V3d_View;
 
 /*!
  \class PartSet_FeatureArcPrs
@@ -44,6 +47,9 @@ public:
   /// \return next attribute selection mode
   virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
 
+  void projectPointOnArc(gp_Pnt& thePoint, Handle_V3d_View theView,
+                         double& theX, double& theY);
+
 protected:
   /// Returns the feature point in the selection mode position.
   /// \param theMode the current operation selection mode. The feature attribute depends on the mode
index 4c117b3ebec475bb07e1572ac692f6a582a0fd17..e9257138215714e2f3b863c02793d588916155f2 100644 (file)
@@ -153,6 +153,12 @@ void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle
     case SM_FirstPoint:
     case SM_SecondPoint:
     case SM_ThirdPoint: {
+      if (feature()->getKind() == SKETCH_ARC_KIND) {
+        PartSet_FeatureArcPrs* anArcPrs = dynamic_cast<PartSet_FeatureArcPrs*>(myFeaturePrs);
+        if (anArcPrs) {
+          anArcPrs->projectPointOnArc(aPoint, theView, aX, anY);
+        }
+      }
       PartSet_SelectionMode aMode = myFeaturePrs->setPoint(aX, anY, myPointSelectionMode);
       flushUpdated();
       setPointSelectionMode(aMode);
@@ -174,6 +180,14 @@ void PartSet_OperationCreateFeature::mouseMoved(QMouseEvent* theEvent, Handle(V3
       double aX, anY;
       gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
       PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+      if (myPointSelectionMode == SM_ThirdPoint) {
+        if (feature()->getKind() == SKETCH_ARC_KIND) {
+          PartSet_FeatureArcPrs* anArcPrs = dynamic_cast<PartSet_FeatureArcPrs*>(myFeaturePrs);
+          if (anArcPrs) {
+            anArcPrs->projectPointOnArc(aPoint, theView, aX, anY);
+          }
+        }
+      }
       myFeaturePrs->setPoint(aX, anY, myPointSelectionMode);
 
       flushUpdated();