From: nds Date: Tue, 10 Jun 2014 12:12:19 +0000 (+0400) Subject: refs #80 - Sketch base GUI: create/draw point, circle and arc X-Git-Tag: V_0.4.4~295 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a2757d51143b90fbdf87777722ecb8563b223412;p=modules%2Fshaper.git refs #80 - Sketch base GUI: create/draw point, circle and arc Edit feature: move specific feature functionality to the feature presentation. --- diff --git a/src/PartSet/PartSet_FeatureCirclePrs.cpp b/src/PartSet/PartSet_FeatureCirclePrs.cpp index d825fdd58..976d96408 100644 --- a/src/PartSet/PartSet_FeatureCirclePrs.cpp +++ b/src/PartSet/PartSet_FeatureCirclePrs.cpp @@ -26,6 +26,11 @@ PartSet_FeatureCirclePrs::PartSet_FeatureCirclePrs(FeaturePtr theSketch) { } +std::string PartSet_FeatureCirclePrs::getKind() +{ + return SKETCH_CIRCLE_KIND; +} + PartSet_SelectionMode PartSet_FeatureCirclePrs::setPoint(double theX, double theY, const PartSet_SelectionMode& theMode) { @@ -82,6 +87,37 @@ 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) +{ + boost::shared_ptr aPoint2D; + if (!theFeature || theFeature->getKind() != getKind()) + return aPoint2D; + + boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(CIRCLE_ATTR_CENTER)); + if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() ) + aPoint2D = aPoint; + + return aPoint2D; +} + boost::shared_ptr PartSet_FeatureCirclePrs::featurePoint (const PartSet_SelectionMode& theMode) { diff --git a/src/PartSet/PartSet_FeatureCirclePrs.h b/src/PartSet/PartSet_FeatureCirclePrs.h index 6a75b05b8..d75584d33 100644 --- a/src/PartSet/PartSet_FeatureCirclePrs.h +++ b/src/PartSet/PartSet_FeatureCirclePrs.h @@ -21,6 +21,10 @@ class GeomDataAPI_Point2D; class PARTSET_EXPORT PartSet_FeatureCirclePrs : public PartSet_FeaturePrs { public: + /// Returns the feature type processed by this presentation + /// \return the feature kind + static std::string getKind(); + /// Constructor /// \param theSketch the sketch feature PartSet_FeatureCirclePrs(FeaturePtr theSketch); @@ -44,6 +48,18 @@ 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 + static 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 + /// \param theY the vertical point coordinate + static boost::shared_ptr findPoint(FeaturePtr theFeature, 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 diff --git a/src/PartSet/PartSet_FeatureLinePrs.cpp b/src/PartSet/PartSet_FeatureLinePrs.cpp index d6200d576..53aa6befb 100644 --- a/src/PartSet/PartSet_FeatureLinePrs.cpp +++ b/src/PartSet/PartSet_FeatureLinePrs.cpp @@ -28,6 +28,11 @@ PartSet_FeatureLinePrs::PartSet_FeatureLinePrs(FeaturePtr theSketch) { } +std::string PartSet_FeatureLinePrs::getKind() +{ + return SKETCH_LINE_KIND; +} + void PartSet_FeatureLinePrs::initFeature(FeaturePtr theFeature) { if (feature() && theFeature) @@ -105,8 +110,8 @@ void PartSet_FeatureLinePrs::projectPointOnLine(FeaturePtr theFeature, if (theFeature) { double X0, X1, X2, X3; double Y0, Y1, Y2, Y3; - PartSet_Tools::getLinePoint(theFeature, LINE_ATTR_START, X2, Y2); - PartSet_Tools::getLinePoint(theFeature, LINE_ATTR_END, X3, Y3); + getLinePoint(theFeature, LINE_ATTR_START, X2, Y2); + getLinePoint(theFeature, LINE_ATTR_END, X3, Y3); PartSet_Tools::convertTo2D(thePoint, sketch(), theView, X1, Y1); switch (theMode) { @@ -114,7 +119,7 @@ void PartSet_FeatureLinePrs::projectPointOnLine(FeaturePtr theFeature, PartSet_Tools::projectPointOnLine(X2, Y2, X3, Y3, X1, Y1, theX, theY); break; case SM_SecondPoint: { - PartSet_Tools::getLinePoint(feature(), LINE_ATTR_START, X0, Y0); + getLinePoint(feature(), LINE_ATTR_START, X0, Y0); PartSet_Tools::intersectLines(X0, Y0, X1, Y1, X2, Y2, X3, Y3, theX, theY); } break; @@ -124,6 +129,50 @@ void PartSet_FeatureLinePrs::projectPointOnLine(FeaturePtr theFeature, } } +double PartSet_FeatureLinePrs::distanceToPoint(FeaturePtr theFeature, + double theX, double theY) +{ + double aDelta = 0; + if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND) + 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)); + + double aX, anY; + PartSet_Tools::projectPointOnLine(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y(), theX, theY, aX, anY); + aDelta = gp_Pnt(theX, theY, 0).Distance(gp_Pnt(aX, anY, 0)); + + return aDelta; +} + +boost::shared_ptr PartSet_FeatureLinePrs::findPoint(FeaturePtr theFeature, + double theX, double theY) +{ + boost::shared_ptr aPoint2D; + if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND) + return aPoint2D; + + boost::shared_ptr aData = theFeature->data(); + aPoint2D = PartSet_FeatureLinePrs::findPoint(theFeature, theX, theY); + + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); + if (fabs(aPoint->x() - theX) < Precision::Confusion() && + fabs(aPoint->y() - theY) < Precision::Confusion()) + aPoint2D = aPoint; + else { + aPoint = boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); + if (fabs(aPoint->x() - theX) < Precision::Confusion() && + fabs(aPoint->y() - theY) < Precision::Confusion()) + aPoint2D = aPoint; + } + return aPoint2D; +} + boost::shared_ptr PartSet_FeatureLinePrs::featurePoint (const PartSet_SelectionMode& theMode) { @@ -144,3 +193,15 @@ boost::shared_ptr PartSet_FeatureLinePrs::featurePoint (aData->attribute(aPointArg)); return aPoint; } + +void PartSet_FeatureLinePrs::getLinePoint(FeaturePtr theFeature, const std::string& theAttribute, + double& theX, double& theY) +{ + if (!theFeature || theFeature->getKind() != PartSet_FeatureLinePrs::getKind()) + return; + boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(theAttribute)); + theX = aPoint->x(); + theY = aPoint->y(); +} diff --git a/src/PartSet/PartSet_FeatureLinePrs.h b/src/PartSet/PartSet_FeatureLinePrs.h index eefced5e5..b34e66c01 100644 --- a/src/PartSet/PartSet_FeatureLinePrs.h +++ b/src/PartSet/PartSet_FeatureLinePrs.h @@ -24,6 +24,10 @@ class Handle_V3d_View; class PARTSET_EXPORT PartSet_FeatureLinePrs : public PartSet_FeaturePrs { public: + /// Returns the feature type processed by this presentation + /// \return the feature kind + static std::string getKind(); + /// Constructor /// \param theSketch the sketch feature PartSet_FeatureLinePrs(FeaturePtr theSketch); @@ -59,6 +63,19 @@ 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 + static 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 + /// \param theY the vertical point coordinate + static boost::shared_ptr findPoint(FeaturePtr theFeature, double theX, + double theY); + protected: /// Initializes current feature by the given /// \param theSourceFeature the feature, which attributes are used to initialize the current feature @@ -67,6 +84,14 @@ protected: /// Returns the feature point in the selection mode position. /// \param theMode the current operation selection mode. The feature attribute depends on the mode virtual boost::shared_ptr featurePoint(const PartSet_SelectionMode& theMode); + + /// \brief Get the line point 2d coordinates. + /// \param theFeature the line feature + /// \param theAttribute the start or end attribute of the line + /// \param theX the horizontal coordinate + /// \param theY the vertical coordinate + static void getLinePoint(FeaturePtr theFeature, const std::string& theAttribute, + double& theX, double& theY); }; #endif diff --git a/src/PartSet/PartSet_FeaturePointPrs.cpp b/src/PartSet/PartSet_FeaturePointPrs.cpp index ee6bc8140..569c771e0 100644 --- a/src/PartSet/PartSet_FeaturePointPrs.cpp +++ b/src/PartSet/PartSet_FeaturePointPrs.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -25,6 +26,11 @@ PartSet_FeaturePointPrs::PartSet_FeaturePointPrs(FeaturePtr theSketch) { } +std::string PartSet_FeaturePointPrs::getKind() +{ + return SKETCH_POINT_KIND; +} + PartSet_SelectionMode PartSet_FeaturePointPrs::setPoint(double theX, double theY, const PartSet_SelectionMode& theMode) { @@ -65,6 +71,37 @@ 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) +{ + boost::shared_ptr aPoint2D; + if (!theFeature || theFeature->getKind() != getKind()) + return aPoint2D; + + boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(POINT_ATTR_COORD)); + if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() ) + aPoint2D = aPoint; + + return aPoint2D; +} + boost::shared_ptr PartSet_FeaturePointPrs::featurePoint (const PartSet_SelectionMode& theMode) { diff --git a/src/PartSet/PartSet_FeaturePointPrs.h b/src/PartSet/PartSet_FeaturePointPrs.h index bd63137f2..b07bc1c38 100644 --- a/src/PartSet/PartSet_FeaturePointPrs.h +++ b/src/PartSet/PartSet_FeaturePointPrs.h @@ -21,6 +21,10 @@ class GeomDataAPI_Point2D; class PARTSET_EXPORT PartSet_FeaturePointPrs : public PartSet_FeaturePrs { public: + /// Returns the feature type processed by this presentation + /// \return the feature kind + static std::string getKind(); + /// Constructor /// \param theSketch the sketch feature PartSet_FeaturePointPrs(FeaturePtr theSketch); @@ -44,6 +48,19 @@ 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 + static 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 + /// \param theY the vertical point coordinate + static boost::shared_ptr findPoint(FeaturePtr theFeature, 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 diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 33a0a22bd..7966e9ed1 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -136,8 +136,8 @@ void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) return; if (myFeatures.size() != 1) { - FeaturePtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(), - theView, feature(), myFeatures); + FeaturePtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(), theView, feature(), + myFeatures); if (aFeature) restartOperation(PartSet_OperationEditFeature::Type(), aFeature); } diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 5563c9882..4a483de02 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -17,12 +17,13 @@ #include #include -#include -#include -#include #include #include +#include +#include +#include + #include #include @@ -173,10 +174,9 @@ void PartSet_Tools::projectPointOnLine(double theX1, double theY1, double theX2, } } -FeaturePtr PartSet_Tools::nearestFeature(QPoint thePoint, - Handle_V3d_View theView, - FeaturePtr theSketch, - const std::list& theFeatures) +FeaturePtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView, + FeaturePtr theSketch, + const std::list& theFeatures) { double aX, anY; gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(thePoint, theView); @@ -205,20 +205,16 @@ double PartSet_Tools::distanceToPoint(FeaturePtr theFeature, double theX, double theY) { double aDelta = 0; - if (theFeature->getKind() != SKETCH_LINE_KIND) - 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)); - - double aX, anY; - PartSet_Tools::projectPointOnLine(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y(), theX, theY, aX, anY); - - aDelta = gp_Pnt(theX, theY, 0).Distance(gp_Pnt(aX, anY, 0)); + std::string aKind = theFeature->getKind(); + if (aKind == PartSet_FeatureLinePrs::getKind()) { + aDelta = PartSet_FeatureLinePrs::distanceToPoint(theFeature, theX, theY); + } + else if (aKind == PartSet_FeaturePointPrs::getKind()) { + aDelta = PartSet_FeaturePointPrs::distanceToPoint(theFeature, theX, theY); + } + else if (aKind == PartSet_FeatureCirclePrs::getKind()) { + aDelta = PartSet_FeatureCirclePrs::distanceToPoint(theFeature, theX, theY); + } return aDelta; } @@ -279,18 +275,6 @@ void PartSet_Tools::createConstraint(FeaturePtr theSketch, aFeature->execute(); } -void PartSet_Tools::getLinePoint(FeaturePtr theFeature, const std::string& theAttribute, - double& theX, double& theY) -{ - if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND) - return; - boost::shared_ptr aData = theFeature->data(); - boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(theAttribute)); - theX = aPoint->x(); - theY = aPoint->y(); -} - boost::shared_ptr PartSet_Tools::findPoint(FeaturePtr theFeature, double theX, double theY) { @@ -298,32 +282,15 @@ boost::shared_ptr PartSet_Tools::findPoint(FeaturePtr theFe if (!theFeature) return aPoint2D; - boost::shared_ptr aData = theFeature->data(); - if (theFeature->getKind() == SKETCH_LINE_KIND) - { - boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); - if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() ) - aPoint2D = aPoint; - else { - aPoint = boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); - if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() ) - aPoint2D = aPoint; - } + std::string aKind = theFeature->getKind(); + if (aKind == PartSet_FeatureLinePrs::getKind()) { + aPoint2D = PartSet_FeatureLinePrs::findPoint(theFeature, theX, theY); } - else if (theFeature->getKind() == SKETCH_POINT_KIND) - { - boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(POINT_ATTR_COORD)); - if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() ) - aPoint2D = aPoint; + else if (aKind == PartSet_FeaturePointPrs::getKind()) { + aPoint2D = PartSet_FeaturePointPrs::findPoint(theFeature, theX, theY); } - else if (theFeature->getKind() == SKETCH_CIRCLE_KIND) - { - boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(CIRCLE_ATTR_CENTER)); - if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() ) - aPoint2D = aPoint; + else if (aKind == PartSet_FeatureCirclePrs::getKind()) { + aPoint2D = PartSet_FeatureCirclePrs::findPoint(theFeature, theX, theY); } return aPoint2D; diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 5cb8e9c7f..30c8fa401 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -107,13 +107,6 @@ public: boost::shared_ptr thePoint1, boost::shared_ptr thePoint2); - /// \brief Get the line point 2d coordinates. - /// \param theFeature the line feature - /// \param theAttribute the start or end attribute of the line - /// \param theX the horizontal coordinate - /// \param theY the vertical coordinate - static void getLinePoint(FeaturePtr theFeature, const std::string& theAttribute, - double& theX, double& theY); /// Find a point in the line with given coordinates /// \param theFeature the line feature /// \param theX the horizontal point coordinate