X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FPartSet%2FPartSet_FeatureArcPrs.cpp;h=dc9fd82e514ac8430a2f67875a41d564a7020cf6;hb=f8d51abf2ab6024a974d42c139f7650ccf0ef774;hp=4cc26f008ce7b6ac61c14d80dfb1f093be634827;hpb=575552af0d56b268d9cdd1ddd423365f99b95d77;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_FeatureArcPrs.cpp b/src/PartSet/PartSet_FeatureArcPrs.cpp index 4cc26f008..dc9fd82e5 100644 --- a/src/PartSet/PartSet_FeatureArcPrs.cpp +++ b/src/PartSet/PartSet_FeatureArcPrs.cpp @@ -10,12 +10,16 @@ #include #include +#include +#include #include #include #include #include +#include + #include using namespace std; @@ -25,6 +29,11 @@ PartSet_FeatureArcPrs::PartSet_FeatureArcPrs(FeaturePtr theSketch) { } +std::string PartSet_FeatureArcPrs::getKind() +{ + return SKETCH_ARC_KIND; +} + PartSet_SelectionMode PartSet_FeatureArcPrs::setPoint(double theX, double theY, const PartSet_SelectionMode& theMode) { @@ -42,8 +51,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 +94,105 @@ 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) +{ + FeaturePtr aSketch = sketch(); + if (aSketch) { + double aX, anY; + PartSet_Tools::convertTo2D(thePoint, aSketch, theView, aX, anY); + + // circle origin point and radius + boost::shared_ptr aData = feature()->data(); + boost::shared_ptr aCenter = boost::dynamic_pointer_cast + (aData->attribute(ARC_ATTR_CENTER)); + boost::shared_ptr aStart = boost::dynamic_pointer_cast + (aData->attribute(ARC_ATTR_START)); + + boost::shared_ptr aCirc(new GeomAPI_Circ2d(aCenter->pnt(), aStart->pnt())); + boost::shared_ptr aGeomPoint2d(new GeomAPI_Pnt2d(aX, anY)); + boost::shared_ptr aPnt2d = aCirc->project(aGeomPoint2d); + if (aPnt2d) { + theX = aPnt2d->x(); + theY = aPnt2d->y(); + } + } +} + boost::shared_ptr PartSet_FeatureArcPrs::featurePoint (const PartSet_SelectionMode& theMode) {