]> 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, 23 Jun 2014 14:46:48 +0000 (18:46 +0400)
committernds <natalia.donis@opencascade.com>
Mon, 23 Jun 2014 14:46:48 +0000 (18:46 +0400)
The PartSet presentation's functionality should be partially moved to SketchPlugin and a custom widget creation.
1. distanceToPoint method is moved to the sketch plugin feature.

28 files changed:
src/PartSet/PartSet_ConstraintDistancePrs.cpp
src/PartSet/PartSet_ConstraintDistancePrs.h
src/PartSet/PartSet_ConstraintLengthPrs.cpp
src/PartSet/PartSet_ConstraintLengthPrs.h
src/PartSet/PartSet_ConstraintRadiusPrs.cpp
src/PartSet/PartSet_ConstraintRadiusPrs.h
src/PartSet/PartSet_FeatureArcPrs.cpp
src/PartSet/PartSet_FeatureArcPrs.h
src/PartSet/PartSet_FeatureCirclePrs.cpp
src/PartSet/PartSet_FeatureCirclePrs.h
src/PartSet/PartSet_FeatureLinePrs.cpp
src/PartSet/PartSet_FeatureLinePrs.h
src/PartSet/PartSet_FeaturePointPrs.cpp
src/PartSet/PartSet_FeaturePointPrs.h
src/PartSet/PartSet_FeaturePrs.h
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/SketchPlugin/SketchPlugin_Arc.cpp
src/SketchPlugin/SketchPlugin_Arc.h
src/SketchPlugin/SketchPlugin_Circle.cpp
src/SketchPlugin/SketchPlugin_Circle.h
src/SketchPlugin/SketchPlugin_Constraint.h
src/SketchPlugin/SketchPlugin_Feature.h
src/SketchPlugin/SketchPlugin_Line.cpp
src/SketchPlugin/SketchPlugin_Line.h
src/SketchPlugin/SketchPlugin_Point.cpp
src/SketchPlugin/SketchPlugin_Point.h
src/SketchPlugin/SketchPlugin_Sketch.h

index 586a952465b52b1da93656eb4e1b57e99d1aee09..6bd7510c9b29c1d4841b0dc500a9ba7c1807d10d 100644 (file)
@@ -206,12 +206,6 @@ PartSet_SelectionMode PartSet_ConstraintDistancePrs::getNextMode(const std::stri
   return SM_FirstPoint;
 }
 
-double PartSet_ConstraintDistancePrs::distanceToPoint(FeaturePtr theFeature,
-                                                 double theX, double theY)
-{
-  return 0;
-}
-
 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_ConstraintDistancePrs::findPoint(FeaturePtr theFeature,
                                                                            double theX, double theY)
 {
index 717d704a866b1bbced893fee21406a5143c207cd..4b957e007139ed631575e7d6dd5de84e91e0915e 100644 (file)
@@ -64,12 +64,6 @@ public:
   /// \return next attribute selection mode
   virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
 
-  /// Return the distance between the feature and the point
-  /// \param theFeature feature object
-  /// \param theX the horizontal coordinate of the point
-  /// \param theX the vertical coordinate of the point
-  virtual double distanceToPoint(FeaturePtr theFeature, double theX, double theY);
-
   /// Find a point in the line with given coordinates
   /// \param theFeature the line feature
   /// \param theX the horizontal point coordinate
index 16aecb5f853130a971476395ee9fc9f981cf1a81..b866ff2e8c4ac76a35c81a14335d9123f3045e11 100644 (file)
@@ -204,12 +204,6 @@ PartSet_SelectionMode PartSet_ConstraintLengthPrs::getNextMode(const std::string
   return SM_FirstPoint;
 }
 
-double PartSet_ConstraintLengthPrs::distanceToPoint(FeaturePtr theFeature,
-                                                 double theX, double theY)
-{
-  return 0;
-}
-
 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_ConstraintLengthPrs::findPoint(FeaturePtr theFeature,
                                                                            double theX, double theY)
 {
index a29465de3ce98744421906f7afd2f6b9f2c7182e..a8d5a03cff29d10335af169e7d17ebcd8a7c1d85 100644 (file)
@@ -64,12 +64,6 @@ public:
   /// \return next attribute selection mode
   virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
 
-  /// Return the distance between the feature and the point
-  /// \param theFeature feature object
-  /// \param theX the horizontal coordinate of the point
-  /// \param theX the vertical coordinate of the point
-  virtual double distanceToPoint(FeaturePtr theFeature, double theX, double theY);
-
   /// Find a point in the line with given coordinates
   /// \param theFeature the line feature
   /// \param theX the horizontal point coordinate
index 305351ef22a393631debdab5a22d9c62fbe1c8e0..a5430b8da2136805caa900e6e698e178915fada0 100644 (file)
@@ -243,12 +243,6 @@ PartSet_SelectionMode PartSet_ConstraintRadiusPrs::getNextMode(const std::string
   return SM_FirstPoint;
 }
 
-double PartSet_ConstraintRadiusPrs::distanceToPoint(FeaturePtr theFeature,
-                                                 double theX, double theY)
-{
-  return 0;
-}
-
 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_ConstraintRadiusPrs::findPoint(FeaturePtr theFeature,
                                                                            double theX, double theY)
 {
index 7f618795434417f99c8713158f46c0bd28d523e7..5e87a5fee3a3b4bf71113d69c2503614d8ba78b9 100644 (file)
@@ -67,12 +67,6 @@ public:
   /// \return next attribute selection mode
   virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
 
-  /// Return the distance between the feature and the point
-  /// \param theFeature feature object
-  /// \param theX the horizontal coordinate of the point
-  /// \param theX the vertical coordinate of the point
-  virtual double distanceToPoint(FeaturePtr theFeature, double theX, double theY);
-
   /// Find a point in the line with given coordinates
   /// \param theFeature the line feature
   /// \param theX the horizontal point coordinate
index 56b671fe4632f8786831c0ef5a662128633a0183..ac90bf55794776ee062132124fe6f9c94338b487 100644 (file)
@@ -94,32 +94,6 @@ PartSet_SelectionMode PartSet_FeatureArcPrs::getNextMode(const std::string& theA
   return aMode;
 }
 
-double PartSet_FeatureArcPrs::distanceToPoint(FeaturePtr theFeature,
-                                               double theX, double theY)
-{
-  double aDelta = 0;
-  if (!theFeature || theFeature->getKind() != getKind())
-    return aDelta;
-  boost::shared_ptr<GeomAPI_Pnt2d> aPoint2d(new GeomAPI_Pnt2d(theX, theY));
-
-
-  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_CENTER));
-  aDelta = aPoint1->pnt()->distance(aPoint2d);
-
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_START));
-  aDelta = qMin(aDelta, aPoint2->pnt()->distance(aPoint2d));
-
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint3 =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_END));
-  aDelta = qMin(aDelta, aPoint3->pnt()->distance(aPoint2d));
-
-  return aDelta;
-}
-
 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureArcPrs::findPoint(FeaturePtr theFeature,
                                                                         double theX, double theY)
 {
index 2ebc17e7bf62836cfdca9bae9cd8af47b750132a..a34a08d6f4747010229d8ded7c63baca17f23ba5 100644 (file)
@@ -61,12 +61,6 @@ public:
   static void projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch, gp_Pnt& thePoint,
                                     Handle_V3d_View theView, double& theX, double& theY);
 
-  /// Return the distance between the feature and the point
-  /// \param theFeature feature object
-  /// \param theX the horizontal coordinate of the point
-  /// \param theX the vertical coordinate of the point
-  virtual double distanceToPoint(FeaturePtr theFeature, double theX, double theY);
-
   /// Find a point in the line with given coordinates
   /// \param theFeature the line feature
   /// \param theX the horizontal point coordinate
index 1de3bb5e3e0f412953dca45a2272f47348c923ce..56e4f93b605b512ce3fa18de999cf42947f574ad 100644 (file)
@@ -92,21 +92,6 @@ PartSet_SelectionMode PartSet_FeatureCirclePrs::getNextMode(const std::string& t
   return aMode;
 }
 
-double PartSet_FeatureCirclePrs::distanceToPoint(FeaturePtr theFeature,
-                                                 double theX, double theY)
-{
-  double aDelta = 0;
-  if (!theFeature || theFeature->getKind() != getKind())
-    return aDelta;
-
-  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
-
-  boost::shared_ptr<GeomAPI_Pnt2d> aPoint2d(new GeomAPI_Pnt2d(theX, theY));
-  return aPoint->pnt()->distance(aPoint2d);
-}
-
 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureCirclePrs::findPoint(FeaturePtr theFeature,
                                                                            double theX, double theY)
 {
index dccead22532697f786225ad2ae165a08963f7a23..546fb5eb029ed8a5d15194bc44dbede9ae81e621 100644 (file)
@@ -51,12 +51,6 @@ public:
   /// \return next attribute selection mode
   virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
 
-  /// Return the distance between the feature and the point
-  /// \param theFeature feature object
-  /// \param theX the horizontal coordinate of the point
-  /// \param theX the vertical coordinate of the point
-  virtual double distanceToPoint(FeaturePtr theFeature, double theX, double theY);
-
   /// Find a point in the line with given coordinates
   /// \param theFeature the line feature
   /// \param theX the horizontal point coordinate
index ac173167f1e4c0e50df38abc4cd98b5010ad31f7..4aa747a997ce4208246531c72af5c9cd6f21c996 100644 (file)
@@ -148,33 +148,6 @@ void PartSet_FeatureLinePrs::projectPointOnLine(FeaturePtr theFeature,
   }
 }
 
-double PartSet_FeatureLinePrs::distanceToPoint(FeaturePtr theFeature,
-                                      double theX, double theY)
-{
-  double aDelta = 0;
-  if (!theFeature || theFeature->getKind() != getKind())
-    return aDelta;
-
-  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
-
-  GeomAPI_Lin2d aLin2d(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y());
-  boost::shared_ptr<GeomAPI_Pnt2d> aPoint = boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY));
-
-  if (false/*projection*/) { // TODO: if it has not been necessary, remove this block
-    boost::shared_ptr<GeomAPI_Pnt2d> aResult = aLin2d.project(aPoint);
-    aDelta = aResult->distance(aPoint);
-  }
-  else { // distance
-    aDelta = aLin2d.distance(aPoint);
-  }
-
-  return aDelta;
-}
-
 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureLinePrs::findPoint(FeaturePtr theFeature,
                                                                          double theX, double theY)
 {
index 13d973ec66fe1e68093aee50b1fbc2f1223b7a43..b4a16dc5c36176e784085da6f760be52111640c1 100644 (file)
@@ -69,12 +69,6 @@ public:
                           const gp_Pnt& thePoint, Handle_V3d_View theView,
                           double& theX, double& theY);
 
-  /// Return the distance between the feature and the point
-  /// \param theFeature feature object
-  /// \param theX the horizontal coordinate of the point
-  /// \param theX the vertical coordinate of the point
-  virtual double distanceToPoint(FeaturePtr theFeature, double theX, double theY);
-
   /// Find a point in the line with given coordinates
   /// \param theFeature the line feature
   /// \param theX the horizontal point coordinate
index 569c771e03475e638cbd9fa5f2aead9ae5022da7..fa33cd40ae3e5d84e0325232e87be91f885e04d6 100644 (file)
@@ -71,21 +71,6 @@ PartSet_SelectionMode PartSet_FeaturePointPrs::getNextMode(const std::string& th
   return aMode;
 }
 
-double PartSet_FeaturePointPrs::distanceToPoint(FeaturePtr theFeature,
-                                                double theX, double theY)
-{
-  double aDelta = 0;
-  if (!theFeature || theFeature->getKind() != getKind())
-    return aDelta;
-
-  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(POINT_ATTR_COORD));
-
-  boost::shared_ptr<GeomAPI_Pnt2d> aPoint2d(new GeomAPI_Pnt2d(theX, theY));
-  return aPoint->pnt()->distance(aPoint2d);
-}
-
 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeaturePointPrs::findPoint(FeaturePtr theFeature,
                                                                           double theX, double theY)
 {
index cc344dc2522aa1b1376c4e2192309d0c72cccb6f..d43a8227221e3785ef449584ef9ae095aca00d2b 100644 (file)
@@ -48,12 +48,6 @@ public:
   /// \return next attribute selection mode
   virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
 
-  /// Return the distance between the feature and the point
-  /// \param theFeature feature object
-  /// \param theX the horizontal coordinate of the point
-  /// \param theX the vertical coordinate of the point
-  virtual double distanceToPoint(FeaturePtr theFeature, double theX, double theY);
-
   /// Find a point in the line with given coordinates
   /// \param theFeature the line feature
   /// \param theX the horizontal point coordinate
index 75aca1bb9f43162bdc82eb83555be35dd7aa476f..eeaa0b85187d82622f0c8a9eb42ebaac2728a3c4 100644 (file)
@@ -59,12 +59,6 @@ public:
   /// \return next attribute selection mode
   virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const = 0;
 
-  /// Return the distance between the feature and the point
-  /// \param theFeature feature object
-  /// \param theX the horizontal coordinate of the point
-  /// \param theX the vertical coordinate of the point
-  virtual double distanceToPoint(FeaturePtr theFeature, double theX, double theY) = 0;
-
   /// Find a point in the line with given coordinates
   /// \param theFeature the line feature
   /// \param theX the horizontal point coordinate
index 8f3090ec5501db13516676b05c9255c1c8843e16..8d1329046f89eca5481f2a05b29576a091d15350 100644 (file)
@@ -194,7 +194,12 @@ FeaturePtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theVie
     aPrs = *anIt;
     if (!aPrs.feature())
       continue;
-    double aDelta = distanceToPoint(aPrs.feature(), aX, anY);
+    boost::shared_ptr<SketchPlugin_Feature> aSketchFeature = 
+                           boost::dynamic_pointer_cast<SketchPlugin_Feature>(aPrs.feature());
+    if (!aSketchFeature)
+      continue;
+    double aDelta = aSketchFeature->distanceToPoint(
+                               boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, anY)));
     if (aMinDelta < 0 || aMinDelta > aDelta) {
       aMinDelta = aDelta;
       aDeltaFeature = aPrs.feature();
@@ -203,18 +208,6 @@ FeaturePtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theVie
   return aDeltaFeature;
 }
 
-double PartSet_Tools::distanceToPoint(FeaturePtr theFeature,
-                                      double theX, double theY)
-{
-  boost::shared_ptr<PartSet_FeaturePrs> aFeaturePrs = PartSet_Tools::createFeaturePrs(
-                                           theFeature->getKind(), FeaturePtr(), theFeature);
-  double aDelta = 0;
-  if (aFeaturePrs)
-    aDelta = aFeaturePrs->distanceToPoint(theFeature, theX, theY);
-
-  return aDelta;
-}
-
 boost::shared_ptr<ModelAPI_Document> PartSet_Tools::document()
 {
   return ModelAPI_PluginManager::get()->rootDocument();
index cf841a81b8d8d22b746e8a3d4e00f11e8b9eb077..f4e4ae62b565619c2204687648ff2d4da5318420 100644 (file)
@@ -132,13 +132,6 @@ public:
   /// \param theKind a feature kind
   /// \return the boolean value
   static bool isConstraintFeature(const std::string& theKind);
-
-private:
-  /// Return the distance between the feature and the point
-  /// \param theFeature feature object
-  /// \param theX the horizontal coordinate of the point
-  /// \param theX the vertical coordinate of the point
-  static double distanceToPoint(FeaturePtr theFeature, double theX, double theY);
 };
 
 #endif
index 566ef84d441e71da6758954c5c4fb6c2187b5335..5bb8fa0d242862e16f24e07455d1647a0deae0c2 100644 (file)
@@ -6,6 +6,8 @@
 #include "SketchPlugin_Sketch.h"
 #include <ModelAPI_Data.h>
 
+#include <GeomAPI_Pnt2d.h>
+
 #include <GeomDataAPI_Point2D.h>
 #include <GeomDataAPI_Dir.h>
 
@@ -88,3 +90,27 @@ void SketchPlugin_Arc::move(double theDeltaX, double theDeltaY)
         boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_END));
   aPoint3->setValue(aPoint3->x() + theDeltaX, aPoint3->y() + theDeltaY);
 }
+
+double SketchPlugin_Arc::distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+  double aDelta = 0;
+  boost::shared_ptr<ModelAPI_Data> aData = data();
+
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_CENTER));
+  aDelta = aPoint1->pnt()->distance(thePoint);
+
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_START));
+  double aDistance = aPoint2->pnt()->distance(thePoint);
+  if (aDelta < aDistance)
+    aDelta = aDistance;
+
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint3 =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_END));
+  aDistance = aPoint3->pnt()->distance(thePoint);
+  if (aDelta < aDistance)
+    aDelta = aDistance;
+
+  return aDelta;
+}
index 4d6e6778562f6aba5d88840a50ed8ed8de9c8a73..b40024b8bad181b235bb3e15a30c9c38b7c6903d 100644 (file)
@@ -53,6 +53,10 @@ public:
   /// \param theDeltaY the delta for Y coordinate is moved
   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
 
+  /// Return the distance between the feature and the point
+  /// \param thePoint the point
+  virtual double distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+
   /// Use plugin manager for features creation
   SketchPlugin_Arc();
 };
index ab842378a2bc944be0dd0711710060a3cb3f9b73..ef6ecf13fd738360e8ab86d806a8f5dd027d4bad 100644 (file)
@@ -6,6 +6,8 @@
 #include "SketchPlugin_Sketch.h"
 #include <ModelAPI_Data.h>
 
+#include <GeomAPI_Pnt2d.h>
+
 #include <GeomDataAPI_Point2D.h>
 #include <GeomDataAPI_Dir.h>
 
@@ -75,3 +77,12 @@ void SketchPlugin_Circle::move(double theDeltaX, double theDeltaY)
         boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
   aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
 }
+
+double SketchPlugin_Circle::distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+  boost::shared_ptr<ModelAPI_Data> aData = data();
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
+
+  return aPoint->pnt()->distance(thePoint);
+}
index e74332eff97f322b84a457dd28f2ddfdd175ad1e..e81107b30cb1982cb7d0d489b579256fd3850ef2 100644 (file)
@@ -51,6 +51,10 @@ public:
   /// \param theDeltaY the delta for Y coordinate is moved
   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
 
+  /// Return the distance between the feature and the point
+  /// \param thePoint the point
+  virtual double distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+
   /// Use plugin manager for features creation
   SketchPlugin_Circle();
 };
index 2cc8bad32c98156eb01b0e8e8acb5d3478f46886..fbc182c64445752fb27cb0c985e2a5973ba47119 100644 (file)
@@ -66,6 +66,10 @@ public:
   /// \param theDeltaY the delta for Y coordinate is moved
   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) {};
 
+  /// Return the distance between the feature and the point
+  /// \param thePoint the point
+  virtual double distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) { return 0; };
+
 protected:
   /// \brief Use plugin manager for features creation
   SketchPlugin_Constraint() {}
index 4bf9ae7cb6ccbc452623a1c5befc591d53145703..5563c90135b31b815bb9398b0e2d185a78470395 100644 (file)
@@ -10,6 +10,7 @@
 #include <GeomAPI_Shape.h>
 
 class SketchPlugin_Sketch;
+class GeomAPI_Pnt2d;
 
 /**\class SketchPlugin_Feature
  * \ingroup DataModel
@@ -37,6 +38,10 @@ public:
   /// \param theDeltaY the delta for Y coordinate is moved
   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) = 0;
 
+  /// Return the distance between the feature and the point
+  /// \param thePoint the point
+  virtual double distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) = 0;
+
 protected:
   /// Set the shape to the internal preview field
   /// \param theShape a preview shape
index 25751f06bd285d712faccad4ae9ad449a5ba6549..245440e22cebc7f290428e9d6b538f610577b006 100644 (file)
@@ -5,7 +5,11 @@
 #include "SketchPlugin_Line.h"
 #include "SketchPlugin_Sketch.h"
 #include <ModelAPI_Data.h>
+
 #include <GeomAPI_Pnt.h>
+#include <GeomAPI_Lin2d.h>
+#include <GeomAPI_Pnt2d.h>
+
 #include <GeomAlgoAPI_EdgeBuilder.h>
 #include <GeomDataAPI_Point2D.h>
 
@@ -62,3 +66,26 @@ void SketchPlugin_Line::move(double theDeltaX, double theDeltaY)
         boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
   aPoint2->setValue(aPoint2->x() + theDeltaX, aPoint2->y() + theDeltaY);
 }
+
+double SketchPlugin_Line::distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+  double aDelta = 0;
+
+  boost::shared_ptr<ModelAPI_Data> aData = data();
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
+
+  GeomAPI_Lin2d aLin2d(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y());
+
+  if (false/*projection*/) { // TODO: if it has not been necessary, remove this block
+    boost::shared_ptr<GeomAPI_Pnt2d> aResult = aLin2d.project(thePoint);
+    aDelta = aResult->distance(thePoint);
+  }
+  else { // distance
+    aDelta = aLin2d.distance(thePoint);
+  }
+
+  return aDelta;
+}
index 554fd5e5300313f214c03ca73bf99cb9f13b8ce0..c6d23b2efd5cede1f15bbec2aa5bda2c7263796d 100644 (file)
@@ -52,6 +52,10 @@ public:
   /// \param theDeltaY the delta for Y coordinate is moved
   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
 
+  /// Return the distance between the feature and the point
+  /// \param thePoint the point
+  virtual double distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+
   /// Use plugin manager for features creation
   SketchPlugin_Line();
 };
index 208063d3595505f1b412889ddc1fbeedff8fd6c0..74860bb6290c7e4384ac8bc546b1bd9fa53b18ce 100644 (file)
@@ -4,7 +4,11 @@
 
 #include "SketchPlugin_Point.h"
 #include "SketchPlugin_Sketch.h"
+
 #include <ModelAPI_Data.h>
+
+#include <GeomAPI_Pnt2d.h>
+
 #include <GeomDataAPI_Point2D.h>
 #include <GeomAlgoAPI_PointBuilder.h>
 
@@ -48,3 +52,12 @@ void SketchPlugin_Point::move(double theDeltaX, double theDeltaY)
         boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(POINT_ATTR_COORD));
   aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
 }
+
+double SketchPlugin_Point::distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+  boost::shared_ptr<ModelAPI_Data> aData = data();
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(POINT_ATTR_COORD));
+
+  return aPoint->pnt()->distance(thePoint);
+}
index 9faf8c9110f35d7d3cb1c337583baff79605ace1..be36d016fb9f8ea6ad53eb3a6de5bc88c4b3fcfa 100644 (file)
@@ -50,6 +50,10 @@ public:
   /// \param theDeltaY the delta for Y coordinate is moved
   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
 
+  /// Return the distance between the feature and the point
+  /// \param thePoint the point
+  virtual double distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+
   /// Use plugin manager for features creation
   SketchPlugin_Point();
 };
index 3172d2f24280461a30ebcd0be10178a5b1f464d0..7470d716129c75343ab23cbf47c7311335e9c28a 100644 (file)
@@ -58,6 +58,10 @@ public:
   /// \param theDeltaY the delta for Y coordinate is moved
   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) {};
 
+  /// Return the distance between the feature and the point
+  /// \param thePoint the point
+  virtual double distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) { return 0; };
+
   /// Converts a 2D sketch space point into point in 3D space
   SKETCHPLUGIN_EXPORT boost::shared_ptr<GeomAPI_Pnt> to3D(
     const double theX, const double theY);