From: nds Date: Mon, 23 Jun 2014 14:46:48 +0000 (+0400) Subject: refs #80 - Sketch base GUI: create/draw point, circle and arc X-Git-Tag: V_0.4.4~263^2~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=59b3db4a19c10138bf23f01f0c5ca7a28a3b8949;p=modules%2Fshaper.git refs #80 - Sketch base GUI: create/draw point, circle and arc 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. --- diff --git a/src/PartSet/PartSet_ConstraintDistancePrs.cpp b/src/PartSet/PartSet_ConstraintDistancePrs.cpp index 586a95246..6bd7510c9 100644 --- a/src/PartSet/PartSet_ConstraintDistancePrs.cpp +++ b/src/PartSet/PartSet_ConstraintDistancePrs.cpp @@ -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 PartSet_ConstraintDistancePrs::findPoint(FeaturePtr theFeature, double theX, double theY) { diff --git a/src/PartSet/PartSet_ConstraintDistancePrs.h b/src/PartSet/PartSet_ConstraintDistancePrs.h index 717d704a8..4b957e007 100644 --- a/src/PartSet/PartSet_ConstraintDistancePrs.h +++ b/src/PartSet/PartSet_ConstraintDistancePrs.h @@ -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 diff --git a/src/PartSet/PartSet_ConstraintLengthPrs.cpp b/src/PartSet/PartSet_ConstraintLengthPrs.cpp index 16aecb5f8..b866ff2e8 100644 --- a/src/PartSet/PartSet_ConstraintLengthPrs.cpp +++ b/src/PartSet/PartSet_ConstraintLengthPrs.cpp @@ -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 PartSet_ConstraintLengthPrs::findPoint(FeaturePtr theFeature, double theX, double theY) { diff --git a/src/PartSet/PartSet_ConstraintLengthPrs.h b/src/PartSet/PartSet_ConstraintLengthPrs.h index a29465de3..a8d5a03cf 100644 --- a/src/PartSet/PartSet_ConstraintLengthPrs.h +++ b/src/PartSet/PartSet_ConstraintLengthPrs.h @@ -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 diff --git a/src/PartSet/PartSet_ConstraintRadiusPrs.cpp b/src/PartSet/PartSet_ConstraintRadiusPrs.cpp index 305351ef2..a5430b8da 100644 --- a/src/PartSet/PartSet_ConstraintRadiusPrs.cpp +++ b/src/PartSet/PartSet_ConstraintRadiusPrs.cpp @@ -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 PartSet_ConstraintRadiusPrs::findPoint(FeaturePtr theFeature, double theX, double theY) { diff --git a/src/PartSet/PartSet_ConstraintRadiusPrs.h b/src/PartSet/PartSet_ConstraintRadiusPrs.h index 7f6187954..5e87a5fee 100644 --- a/src/PartSet/PartSet_ConstraintRadiusPrs.h +++ b/src/PartSet/PartSet_ConstraintRadiusPrs.h @@ -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 diff --git a/src/PartSet/PartSet_FeatureArcPrs.cpp b/src/PartSet/PartSet_FeatureArcPrs.cpp index 56b671fe4..ac90bf557 100644 --- a/src/PartSet/PartSet_FeatureArcPrs.cpp +++ b/src/PartSet/PartSet_FeatureArcPrs.cpp @@ -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 aPoint2d(new GeomAPI_Pnt2d(theX, theY)); - - - boost::shared_ptr aData = theFeature->data(); - - boost::shared_ptr aPoint1 = - boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_CENTER)); - aDelta = aPoint1->pnt()->distance(aPoint2d); - - boost::shared_ptr aPoint2 = - boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_START)); - aDelta = qMin(aDelta, aPoint2->pnt()->distance(aPoint2d)); - - boost::shared_ptr aPoint3 = - boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_END)); - aDelta = qMin(aDelta, aPoint3->pnt()->distance(aPoint2d)); - - return aDelta; -} - boost::shared_ptr PartSet_FeatureArcPrs::findPoint(FeaturePtr theFeature, double theX, double theY) { diff --git a/src/PartSet/PartSet_FeatureArcPrs.h b/src/PartSet/PartSet_FeatureArcPrs.h index 2ebc17e7b..a34a08d6f 100644 --- a/src/PartSet/PartSet_FeatureArcPrs.h +++ b/src/PartSet/PartSet_FeatureArcPrs.h @@ -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 diff --git a/src/PartSet/PartSet_FeatureCirclePrs.cpp b/src/PartSet/PartSet_FeatureCirclePrs.cpp index 1de3bb5e3..56e4f93b6 100644 --- a/src/PartSet/PartSet_FeatureCirclePrs.cpp +++ b/src/PartSet/PartSet_FeatureCirclePrs.cpp @@ -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 aData = theFeature->data(); - boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(CIRCLE_ATTR_CENTER)); - - boost::shared_ptr aPoint2d(new GeomAPI_Pnt2d(theX, theY)); - return aPoint->pnt()->distance(aPoint2d); -} - boost::shared_ptr PartSet_FeatureCirclePrs::findPoint(FeaturePtr theFeature, double theX, double theY) { diff --git a/src/PartSet/PartSet_FeatureCirclePrs.h b/src/PartSet/PartSet_FeatureCirclePrs.h index dccead225..546fb5eb0 100644 --- a/src/PartSet/PartSet_FeatureCirclePrs.h +++ b/src/PartSet/PartSet_FeatureCirclePrs.h @@ -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 diff --git a/src/PartSet/PartSet_FeatureLinePrs.cpp b/src/PartSet/PartSet_FeatureLinePrs.cpp index ac173167f..4aa747a99 100644 --- a/src/PartSet/PartSet_FeatureLinePrs.cpp +++ b/src/PartSet/PartSet_FeatureLinePrs.cpp @@ -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 aData = theFeature->data(); - boost::shared_ptr aPoint1 = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); - boost::shared_ptr aPoint2 = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); - - GeomAPI_Lin2d aLin2d(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y()); - boost::shared_ptr aPoint = boost::shared_ptr(new GeomAPI_Pnt2d(theX, theY)); - - if (false/*projection*/) { // TODO: if it has not been necessary, remove this block - boost::shared_ptr aResult = aLin2d.project(aPoint); - aDelta = aResult->distance(aPoint); - } - else { // distance - aDelta = aLin2d.distance(aPoint); - } - - return aDelta; -} - boost::shared_ptr PartSet_FeatureLinePrs::findPoint(FeaturePtr theFeature, double theX, double theY) { diff --git a/src/PartSet/PartSet_FeatureLinePrs.h b/src/PartSet/PartSet_FeatureLinePrs.h index 13d973ec6..b4a16dc5c 100644 --- a/src/PartSet/PartSet_FeatureLinePrs.h +++ b/src/PartSet/PartSet_FeatureLinePrs.h @@ -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 diff --git a/src/PartSet/PartSet_FeaturePointPrs.cpp b/src/PartSet/PartSet_FeaturePointPrs.cpp index 569c771e0..fa33cd40a 100644 --- a/src/PartSet/PartSet_FeaturePointPrs.cpp +++ b/src/PartSet/PartSet_FeaturePointPrs.cpp @@ -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 aData = theFeature->data(); - boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(POINT_ATTR_COORD)); - - boost::shared_ptr aPoint2d(new GeomAPI_Pnt2d(theX, theY)); - return aPoint->pnt()->distance(aPoint2d); -} - boost::shared_ptr PartSet_FeaturePointPrs::findPoint(FeaturePtr theFeature, double theX, double theY) { diff --git a/src/PartSet/PartSet_FeaturePointPrs.h b/src/PartSet/PartSet_FeaturePointPrs.h index cc344dc25..d43a82272 100644 --- a/src/PartSet/PartSet_FeaturePointPrs.h +++ b/src/PartSet/PartSet_FeaturePointPrs.h @@ -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 diff --git a/src/PartSet/PartSet_FeaturePrs.h b/src/PartSet/PartSet_FeaturePrs.h index 75aca1bb9..eeaa0b851 100644 --- a/src/PartSet/PartSet_FeaturePrs.h +++ b/src/PartSet/PartSet_FeaturePrs.h @@ -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 diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 8f3090ec5..8d1329046 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -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 aSketchFeature = + boost::dynamic_pointer_cast(aPrs.feature()); + if (!aSketchFeature) + continue; + double aDelta = aSketchFeature->distanceToPoint( + boost::shared_ptr(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 aFeaturePrs = PartSet_Tools::createFeaturePrs( - theFeature->getKind(), FeaturePtr(), theFeature); - double aDelta = 0; - if (aFeaturePrs) - aDelta = aFeaturePrs->distanceToPoint(theFeature, theX, theY); - - return aDelta; -} - boost::shared_ptr PartSet_Tools::document() { return ModelAPI_PluginManager::get()->rootDocument(); diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index cf841a81b..f4e4ae62b 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -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 diff --git a/src/SketchPlugin/SketchPlugin_Arc.cpp b/src/SketchPlugin/SketchPlugin_Arc.cpp index 566ef84d4..5bb8fa0d2 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.cpp +++ b/src/SketchPlugin/SketchPlugin_Arc.cpp @@ -6,6 +6,8 @@ #include "SketchPlugin_Sketch.h" #include +#include + #include #include @@ -88,3 +90,27 @@ void SketchPlugin_Arc::move(double theDeltaX, double theDeltaY) boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_END)); aPoint3->setValue(aPoint3->x() + theDeltaX, aPoint3->y() + theDeltaY); } + +double SketchPlugin_Arc::distanceToPoint(const boost::shared_ptr& thePoint) +{ + double aDelta = 0; + boost::shared_ptr aData = data(); + + boost::shared_ptr aPoint1 = + boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_CENTER)); + aDelta = aPoint1->pnt()->distance(thePoint); + + boost::shared_ptr aPoint2 = + boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_START)); + double aDistance = aPoint2->pnt()->distance(thePoint); + if (aDelta < aDistance) + aDelta = aDistance; + + boost::shared_ptr aPoint3 = + boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_END)); + aDistance = aPoint3->pnt()->distance(thePoint); + if (aDelta < aDistance) + aDelta = aDistance; + + return aDelta; +} diff --git a/src/SketchPlugin/SketchPlugin_Arc.h b/src/SketchPlugin/SketchPlugin_Arc.h index 4d6e67785..b40024b8b 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.h +++ b/src/SketchPlugin/SketchPlugin_Arc.h @@ -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& thePoint); + /// Use plugin manager for features creation SketchPlugin_Arc(); }; diff --git a/src/SketchPlugin/SketchPlugin_Circle.cpp b/src/SketchPlugin/SketchPlugin_Circle.cpp index ab842378a..ef6ecf13f 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.cpp +++ b/src/SketchPlugin/SketchPlugin_Circle.cpp @@ -6,6 +6,8 @@ #include "SketchPlugin_Sketch.h" #include +#include + #include #include @@ -75,3 +77,12 @@ void SketchPlugin_Circle::move(double theDeltaX, double theDeltaY) boost::dynamic_pointer_cast(aData->attribute(CIRCLE_ATTR_CENTER)); aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY); } + +double SketchPlugin_Circle::distanceToPoint(const boost::shared_ptr& thePoint) +{ + boost::shared_ptr aData = data(); + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(CIRCLE_ATTR_CENTER)); + + return aPoint->pnt()->distance(thePoint); +} diff --git a/src/SketchPlugin/SketchPlugin_Circle.h b/src/SketchPlugin/SketchPlugin_Circle.h index e74332eff..e81107b30 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.h +++ b/src/SketchPlugin/SketchPlugin_Circle.h @@ -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& thePoint); + /// Use plugin manager for features creation SketchPlugin_Circle(); }; diff --git a/src/SketchPlugin/SketchPlugin_Constraint.h b/src/SketchPlugin/SketchPlugin_Constraint.h index 2cc8bad32..fbc182c64 100644 --- a/src/SketchPlugin/SketchPlugin_Constraint.h +++ b/src/SketchPlugin/SketchPlugin_Constraint.h @@ -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& thePoint) { return 0; }; + protected: /// \brief Use plugin manager for features creation SketchPlugin_Constraint() {} diff --git a/src/SketchPlugin/SketchPlugin_Feature.h b/src/SketchPlugin/SketchPlugin_Feature.h index 4bf9ae7cb..5563c9013 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.h +++ b/src/SketchPlugin/SketchPlugin_Feature.h @@ -10,6 +10,7 @@ #include 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& thePoint) = 0; + protected: /// Set the shape to the internal preview field /// \param theShape a preview shape diff --git a/src/SketchPlugin/SketchPlugin_Line.cpp b/src/SketchPlugin/SketchPlugin_Line.cpp index 25751f06b..245440e22 100644 --- a/src/SketchPlugin/SketchPlugin_Line.cpp +++ b/src/SketchPlugin/SketchPlugin_Line.cpp @@ -5,7 +5,11 @@ #include "SketchPlugin_Line.h" #include "SketchPlugin_Sketch.h" #include + #include +#include +#include + #include #include @@ -62,3 +66,26 @@ void SketchPlugin_Line::move(double theDeltaX, double theDeltaY) boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); aPoint2->setValue(aPoint2->x() + theDeltaX, aPoint2->y() + theDeltaY); } + +double SketchPlugin_Line::distanceToPoint(const boost::shared_ptr& thePoint) +{ + double aDelta = 0; + + boost::shared_ptr aData = data(); + boost::shared_ptr aPoint1 = + boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); + boost::shared_ptr aPoint2 = + boost::dynamic_pointer_cast(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 aResult = aLin2d.project(thePoint); + aDelta = aResult->distance(thePoint); + } + else { // distance + aDelta = aLin2d.distance(thePoint); + } + + return aDelta; +} diff --git a/src/SketchPlugin/SketchPlugin_Line.h b/src/SketchPlugin/SketchPlugin_Line.h index 554fd5e53..c6d23b2ef 100644 --- a/src/SketchPlugin/SketchPlugin_Line.h +++ b/src/SketchPlugin/SketchPlugin_Line.h @@ -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& thePoint); + /// Use plugin manager for features creation SketchPlugin_Line(); }; diff --git a/src/SketchPlugin/SketchPlugin_Point.cpp b/src/SketchPlugin/SketchPlugin_Point.cpp index 208063d35..74860bb62 100644 --- a/src/SketchPlugin/SketchPlugin_Point.cpp +++ b/src/SketchPlugin/SketchPlugin_Point.cpp @@ -4,7 +4,11 @@ #include "SketchPlugin_Point.h" #include "SketchPlugin_Sketch.h" + #include + +#include + #include #include @@ -48,3 +52,12 @@ void SketchPlugin_Point::move(double theDeltaX, double theDeltaY) boost::dynamic_pointer_cast(aData->attribute(POINT_ATTR_COORD)); aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY); } + +double SketchPlugin_Point::distanceToPoint(const boost::shared_ptr& thePoint) +{ + boost::shared_ptr aData = data(); + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(POINT_ATTR_COORD)); + + return aPoint->pnt()->distance(thePoint); +} diff --git a/src/SketchPlugin/SketchPlugin_Point.h b/src/SketchPlugin/SketchPlugin_Point.h index 9faf8c911..be36d016f 100644 --- a/src/SketchPlugin/SketchPlugin_Point.h +++ b/src/SketchPlugin/SketchPlugin_Point.h @@ -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& thePoint); + /// Use plugin manager for features creation SketchPlugin_Point(); }; diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index 3172d2f24..7470d7161 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -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& thePoint) { return 0; }; + /// Converts a 2D sketch space point into point in 3D space SKETCHPLUGIN_EXPORT boost::shared_ptr to3D( const double theX, const double theY);