From 7474cda8a5b26cc5b22935125f24cf462da22104 Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 10 Jun 2014 18:14:43 +0400 Subject: [PATCH] refs #80 - Sketch base GUI: create/draw point, circle and arc Edit feature: move call for all entities. There are bugs in moving. --- src/PartSet/PartSet_FeatureArcPrs.cpp | 74 ++++++++++++++++++++ src/PartSet/PartSet_FeatureArcPrs.h | 18 +++++ src/PartSet/PartSet_FeatureCirclePrs.cpp | 11 +++ src/PartSet/PartSet_FeatureCirclePrs.h | 11 ++- src/PartSet/PartSet_FeatureLinePrs.cpp | 21 ++++-- src/PartSet/PartSet_FeatureLinePrs.h | 10 ++- src/PartSet/PartSet_FeaturePointPrs.cpp | 11 +++ src/PartSet/PartSet_FeaturePointPrs.h | 9 ++- src/PartSet/PartSet_FeaturePrs.h | 18 +++++ src/PartSet/PartSet_OperationEditFeature.cpp | 22 +----- src/PartSet/PartSet_OperationEditFeature.h | 8 --- src/PartSet/PartSet_Tools.cpp | 43 ++++++------ src/PartSet/PartSet_Tools.h | 7 +- 13 files changed, 199 insertions(+), 64 deletions(-) diff --git a/src/PartSet/PartSet_FeatureArcPrs.cpp b/src/PartSet/PartSet_FeatureArcPrs.cpp index b742b64d7..dc9fd82e5 100644 --- a/src/PartSet/PartSet_FeatureArcPrs.cpp +++ b/src/PartSet/PartSet_FeatureArcPrs.cpp @@ -94,6 +94,80 @@ PartSet_SelectionMode PartSet_FeatureArcPrs::getNextMode(const std::string& theA return aMode; } +void PartSet_FeatureArcPrs::move(double theDeltaX, double theDeltaY) +{ + boost::shared_ptr aData = feature()->data(); + if (!aData->isValid()) + return; + + boost::shared_ptr aPoint1 = + boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_CENTER)); + aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY); + + boost::shared_ptr aPoint2 = + boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_START)); + aPoint2->setValue(aPoint2->x() + theDeltaX, aPoint2->y() + theDeltaY); + + boost::shared_ptr aPoint3 = + boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_END)); + aPoint1->setValue(aPoint3->x() + theDeltaX, aPoint3->y() + theDeltaY); +} + +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) +{ + 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(ARC_ATTR_CENTER)); + if (fabs(aPoint->x() - theX) < Precision::Confusion() && + fabs(aPoint->y() - theY) < Precision::Confusion()) { + aPoint2D = aPoint; + } + if (!aPoint2D) { + aPoint = boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_START)); + if (fabs(aPoint->x() - theX) < Precision::Confusion() && + fabs(aPoint->y() - theY) < Precision::Confusion()) + aPoint2D = aPoint; + } + if (!aPoint2D) { + aPoint = boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_END)); + if (fabs(aPoint->x() - theX) < Precision::Confusion() && + fabs(aPoint->y() - theY) < Precision::Confusion()) + aPoint2D = aPoint; + } + return aPoint2D; +} + void PartSet_FeatureArcPrs::projectPointOnArc(gp_Pnt& thePoint, Handle(V3d_View) theView, double& theX, double& theY) { diff --git a/src/PartSet/PartSet_FeatureArcPrs.h b/src/PartSet/PartSet_FeatureArcPrs.h index dc8a91bfa..80d07e014 100644 --- a/src/PartSet/PartSet_FeatureArcPrs.h +++ b/src/PartSet/PartSet_FeatureArcPrs.h @@ -54,6 +54,24 @@ public: void projectPointOnArc(gp_Pnt& thePoint, Handle_V3d_View theView, double& theX, double& theY); + /// \brief Move the full feature. + /// \param theDeltaX the delta for X coordinate is moved + /// \param theDeltaY the delta for Y coordinate is moved + virtual void move(double theDeltaX, double theDeltaY); + + /// 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 + /// \param theY the vertical point coordinate + virtual 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_FeatureCirclePrs.cpp b/src/PartSet/PartSet_FeatureCirclePrs.cpp index 976d96408..71bd9721c 100644 --- a/src/PartSet/PartSet_FeatureCirclePrs.cpp +++ b/src/PartSet/PartSet_FeatureCirclePrs.cpp @@ -87,6 +87,17 @@ PartSet_SelectionMode PartSet_FeatureCirclePrs::getNextMode(const std::string& t return aMode; } +void PartSet_FeatureCirclePrs::move(double theDeltaX, double theDeltaY) +{ + boost::shared_ptr aData = feature()->data(); + if (!aData->isValid()) + return; + + boost::shared_ptr aPoint1 = + boost::dynamic_pointer_cast(aData->attribute(CIRCLE_ATTR_CENTER)); + aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY); +} + double PartSet_FeatureCirclePrs::distanceToPoint(FeaturePtr theFeature, double theX, double theY) { diff --git a/src/PartSet/PartSet_FeatureCirclePrs.h b/src/PartSet/PartSet_FeatureCirclePrs.h index d75584d33..72a3d4855 100644 --- a/src/PartSet/PartSet_FeatureCirclePrs.h +++ b/src/PartSet/PartSet_FeatureCirclePrs.h @@ -48,18 +48,23 @@ public: /// \return next attribute selection mode virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const; + /// \brief Move the full feature. + /// \param theDeltaX the delta for X coordinate is moved + /// \param theDeltaY the delta for Y coordinate is moved + virtual void move(double theDeltaX, double theDeltaY); + /// 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); + 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 /// \param theY the vertical point coordinate - static boost::shared_ptr findPoint(FeaturePtr theFeature, double theX, - double theY); + virtual 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 53aa6befb..54af4c973 100644 --- a/src/PartSet/PartSet_FeatureLinePrs.cpp +++ b/src/PartSet/PartSet_FeatureLinePrs.cpp @@ -102,6 +102,21 @@ PartSet_SelectionMode PartSet_FeatureLinePrs::getNextMode(const std::string& the return aMode; } +void PartSet_FeatureLinePrs::move(double theDeltaX, double theDeltaY) +{ + boost::shared_ptr aData = feature()->data(); + if (!aData->isValid()) + return; + + boost::shared_ptr aPoint1 = + boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); + aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY); + + boost::shared_ptr aPoint2 = + boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); + aPoint2->setValue(aPoint2->x() + theDeltaX, aPoint2->y() + theDeltaY); +} + void PartSet_FeatureLinePrs::projectPointOnLine(FeaturePtr theFeature, const PartSet_SelectionMode& theMode, const gp_Pnt& thePoint, Handle(V3d_View) theView, @@ -133,7 +148,7 @@ double PartSet_FeatureLinePrs::distanceToPoint(FeaturePtr theFeature, double theX, double theY) { double aDelta = 0; - if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND) + if (!theFeature || theFeature->getKind() != getKind()) return aDelta; boost::shared_ptr aData = theFeature->data(); @@ -153,12 +168,10 @@ boost::shared_ptr PartSet_FeatureLinePrs::findPoint(Feature double theX, double theY) { boost::shared_ptr aPoint2D; - if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND) + if (!theFeature || theFeature->getKind() != getKind()) 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() && diff --git a/src/PartSet/PartSet_FeatureLinePrs.h b/src/PartSet/PartSet_FeatureLinePrs.h index b34e66c01..08ccc3837 100644 --- a/src/PartSet/PartSet_FeatureLinePrs.h +++ b/src/PartSet/PartSet_FeatureLinePrs.h @@ -51,6 +51,10 @@ public: /// \return next attribute selection mode virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const; + /// \brief Move the full feature. + /// \param theDeltaX the delta for X coordinate is moved + /// \param theDeltaY the delta for Y coordinate is moved + virtual void move(double theDeltaX, double theDeltaY); /// Project the point on a feature /// \param theFeature the feature to be projected on @@ -67,14 +71,14 @@ public: /// \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); + 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 /// \param theY the vertical point coordinate - static boost::shared_ptr findPoint(FeaturePtr theFeature, double theX, - double theY); + virtual boost::shared_ptr findPoint(FeaturePtr theFeature, double theX, + double theY); protected: /// Initializes current feature by the given diff --git a/src/PartSet/PartSet_FeaturePointPrs.cpp b/src/PartSet/PartSet_FeaturePointPrs.cpp index 569c771e0..df9c76bc9 100644 --- a/src/PartSet/PartSet_FeaturePointPrs.cpp +++ b/src/PartSet/PartSet_FeaturePointPrs.cpp @@ -71,6 +71,17 @@ PartSet_SelectionMode PartSet_FeaturePointPrs::getNextMode(const std::string& th return aMode; } +void PartSet_FeaturePointPrs::move(double theDeltaX, double theDeltaY) +{ + boost::shared_ptr aData = feature()->data(); + if (!aData->isValid()) + return; + + boost::shared_ptr aPoint1 = + boost::dynamic_pointer_cast(aData->attribute(POINT_ATTR_COORD)); + aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY); +} + double PartSet_FeaturePointPrs::distanceToPoint(FeaturePtr theFeature, double theX, double theY) { diff --git a/src/PartSet/PartSet_FeaturePointPrs.h b/src/PartSet/PartSet_FeaturePointPrs.h index b07bc1c38..f0962585e 100644 --- a/src/PartSet/PartSet_FeaturePointPrs.h +++ b/src/PartSet/PartSet_FeaturePointPrs.h @@ -48,17 +48,22 @@ public: /// \return next attribute selection mode virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const; + /// \brief Move the full feature. + /// \param theDeltaX the delta for X coordinate is moved + /// \param theDeltaY the delta for Y coordinate is moved + virtual void move(double theDeltaX, double theDeltaY); + /// 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); + 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 /// \param theY the vertical point coordinate - static boost::shared_ptr findPoint(FeaturePtr theFeature, double theX, + virtual boost::shared_ptr findPoint(FeaturePtr theFeature, double theX, double theY); protected: diff --git a/src/PartSet/PartSet_FeaturePrs.h b/src/PartSet/PartSet_FeaturePrs.h index bf965ed8d..6ba12c6d8 100644 --- a/src/PartSet/PartSet_FeaturePrs.h +++ b/src/PartSet/PartSet_FeaturePrs.h @@ -53,6 +53,24 @@ public: /// \return next attribute selection mode virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const = 0; + /// \brief Move the full feature. + /// \param theDeltaX the delta for X coordinate is moved + /// \param theDeltaY the delta for Y coordinate is moved + virtual void move(double theDeltaX, double theDeltaY) = 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 + /// \param theY the vertical point coordinate + virtual boost::shared_ptr findPoint(FeaturePtr theFeature, double theX, + double theY) = 0; + /// Creates constrains of the current /// \param theX the horizontal coordnate of the point /// \param theY the vertical coordnate of the point diff --git a/src/PartSet/PartSet_OperationEditFeature.cpp b/src/PartSet/PartSet_OperationEditFeature.cpp index 092df0604..fb8690720 100644 --- a/src/PartSet/PartSet_OperationEditFeature.cpp +++ b/src/PartSet/PartSet_OperationEditFeature.cpp @@ -132,16 +132,14 @@ void PartSet_OperationEditFeature::mouseMoved(QMouseEvent* theEvent, Handle(V3d_ double aDeltaX = aX - aCurX; double aDeltaY = anY - aCurY; - moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_START); - moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_END); + PartSet_Tools::moveFeature(feature(), aDeltaX, aDeltaY); std::list::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end(); for (; anIt != aLast; anIt++) { FeaturePtr aFeature = (*anIt).feature(); if (!aFeature || aFeature == feature()) continue; - moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_START); - moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_END); + PartSet_Tools::moveFeature(aFeature, aDeltaX, aDeltaY); } } sendFeatures(); @@ -211,22 +209,6 @@ FeaturePtr PartSet_OperationEditFeature::createFeature(const bool /*theFlushMess return FeaturePtr(); } -void PartSet_OperationEditFeature::moveLinePoint(FeaturePtr theFeature, - double theDeltaX, double theDeltaY, - const std::string& theAttribute) -{ - if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND) - return; - - boost::shared_ptr aData = theFeature->data(); - if (!aData->isValid()) - return; - boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(theAttribute)); - - aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY); -} - void PartSet_OperationEditFeature::sendFeatures() { static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_MOVED); diff --git a/src/PartSet/PartSet_OperationEditFeature.h b/src/PartSet/PartSet_OperationEditFeature.h index b3f5f8ee9..c817fc1ab 100644 --- a/src/PartSet/PartSet_OperationEditFeature.h +++ b/src/PartSet/PartSet_OperationEditFeature.h @@ -126,14 +126,6 @@ protected: /// \param isRestoreSelection the state whether the selected objects should be reselected void blockSelection(bool isBlocked, const bool isRestoreSelection = true); - /// \brief Save the point to the line. - /// \param theFeature the source feature - /// \param theDeltaX the delta for X coordinate is moved - /// \param theDeltaY the delta for Y coordinate is moved - /// \param theAttribute the start or end attribute of the line - void moveLinePoint(FeaturePtr theFeature, - double theDeltaX, double theDeltaY, - const std::string& theAttribute); /// Sends the features void sendFeatures(); diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index bc73da323..3cfa835db 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -229,21 +229,26 @@ FeaturePtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theVie double PartSet_Tools::distanceToPoint(FeaturePtr theFeature, double theX, double theY) { + boost::shared_ptr aFeaturePrs = PartSet_Tools::createFeaturePrs( + theFeature->getKind(), FeaturePtr(), theFeature); double aDelta = 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); - } + if (aFeaturePrs) + aDelta = aFeaturePrs->distanceToPoint(theFeature, theX, theY); return aDelta; } +void PartSet_Tools::moveFeature(FeaturePtr theFeature, double theDeltaX, double theDeltaY) +{ + if (!theFeature) + return; + + boost::shared_ptr aFeaturePrs = PartSet_Tools::createFeaturePrs( + theFeature->getKind(), FeaturePtr(), theFeature); + if (aFeaturePrs) + aFeaturePrs->move(theDeltaX, theDeltaY); +} + boost::shared_ptr PartSet_Tools::document() { return ModelAPI_PluginManager::get()->rootDocument(); @@ -303,20 +308,12 @@ void PartSet_Tools::createConstraint(FeaturePtr theSketch, boost::shared_ptr PartSet_Tools::findPoint(FeaturePtr theFeature, double theX, double theY) { - boost::shared_ptr aPoint2D; - if (!theFeature) - return aPoint2D; + boost::shared_ptr aFeaturePrs = PartSet_Tools::createFeaturePrs( + theFeature->getKind(), FeaturePtr(), theFeature); - std::string aKind = theFeature->getKind(); - if (aKind == PartSet_FeatureLinePrs::getKind()) { - aPoint2D = PartSet_FeatureLinePrs::findPoint(theFeature, theX, theY); - } - else if (aKind == PartSet_FeaturePointPrs::getKind()) { - aPoint2D = PartSet_FeaturePointPrs::findPoint(theFeature, theX, theY); - } - else if (aKind == PartSet_FeatureCirclePrs::getKind()) { - aPoint2D = PartSet_FeatureCirclePrs::findPoint(theFeature, theX, theY); - } + boost::shared_ptr aPoint2D; + if (aFeaturePrs) + aPoint2D = aFeaturePrs->findPoint(theFeature, theX, theY); return aPoint2D; } diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 4dd228226..fff206b6f 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -84,7 +84,6 @@ public: FeaturePtr theSketch, FeaturePtr theFeature = FeaturePtr()); - /// Returns a feature that is under the mouse point /// \param thePoint a screen point /// \param theView a 3D view @@ -93,6 +92,12 @@ public: static FeaturePtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch, const std::list& theFeatures); + /// \brief Move the feature. + /// \param theFeature the source feature + /// \param theDeltaX the delta for X coordinate is moved + /// \param theDeltaY the delta for Y coordinate is moved + static void moveFeature(FeaturePtr theFeature, double theDeltaX, double theDeltaY); + /// Returns pointer to the root document. static boost::shared_ptr document(); -- 2.39.2