From 22cf9cf652173aeb898f242632048ce85b081297 Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 25 Sep 2014 12:13:30 +0400 Subject: [PATCH] Calculate Flyout point for distance and length --- src/GeomAPI/GeomAPI_Lin2d.cpp | 12 ++++++++++++ src/GeomAPI/GeomAPI_Lin2d.h | 3 +++ src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp | 6 ++++++ src/SketchPlugin/SketchPlugin_ConstraintLength.cpp | 7 +++++++ 4 files changed, 28 insertions(+) diff --git a/src/GeomAPI/GeomAPI_Lin2d.cpp b/src/GeomAPI/GeomAPI_Lin2d.cpp index 1e902f4b5..929cff9f8 100644 --- a/src/GeomAPI/GeomAPI_Lin2d.cpp +++ b/src/GeomAPI/GeomAPI_Lin2d.cpp @@ -69,3 +69,15 @@ bool GeomAPI_Lin2d::isRight(const boost::shared_ptr& thePoint) co return aDir.Crossed(aPnt - aLoc) > 0; } + + +boost::shared_ptr GeomAPI_Lin2d::shiftedLocation(double theShift) const +{ + gp_Vec2d aVec = MY_LIN2D->Direction(); + aVec = aVec.GetNormal(); + aVec.Normalize(); + aVec.Reverse(); + aVec.Scale(theShift); + gp_Lin2d aLin = MY_LIN2D->Translated(aVec); + return boost::shared_ptr(new GeomAPI_Pnt2d(aLin.Location().X(), aLin.Location().Y())); +} diff --git a/src/GeomAPI/GeomAPI_Lin2d.h b/src/GeomAPI/GeomAPI_Lin2d.h index 82afee29a..10089d67a 100644 --- a/src/GeomAPI/GeomAPI_Lin2d.h +++ b/src/GeomAPI/GeomAPI_Lin2d.h @@ -35,6 +35,9 @@ class GEOMAPI_EXPORT GeomAPI_Lin2d : public GeomAPI_Interface const boost::shared_ptr& thePoint) const; /// Computes the cross product of the line direction and a vector from the line start point to the point bool isRight(const boost::shared_ptr& thePoint) const; + + /// Returns a location point shifted on theShift in perpendicular direction + boost::shared_ptr shiftedLocation(double theShift) const; }; #endif diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index b11bff256..65c6cf9ce 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -112,6 +112,12 @@ AISObjectPtr SketchPlugin_ConstraintDistance::getAISObject(AISObjectPtr thePrevi boost::shared_ptr aFlyoutPnt = boost::shared_ptr(); if(aFlyOutAttr->isInitialized()) { aFlyoutPnt = sketch()->to3D(aFlyOutAttr->x(), aFlyOutAttr->y()); + } else { + boost::shared_ptr aLine = boost::shared_ptr(new GeomAPI_Lin2d(aPnt_A, aPnt_B)); + double aDist = aPoint1->distance(aPoint2)/5.; + boost::shared_ptr aFPnt = aLine->shiftedLocation(aDist); + aFlyOutAttr->setValue(aFPnt); + aFlyoutPnt = sketch()->to3D(aFPnt->x(), aFPnt->y()); } // value calculation boost::shared_ptr aValueAttr = boost::dynamic_pointer_cast< diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp index a1dce4b0c..00061c739 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp @@ -80,6 +80,13 @@ AISObjectPtr SketchPlugin_ConstraintLength::getAISObject(AISObjectPtr thePreviou boost::shared_ptr aFlyoutPnt = boost::shared_ptr(); if (aFlyOutAttr->isInitialized()) { aFlyoutPnt = sketch()->to3D(aFlyOutAttr->x(), aFlyOutAttr->y()); + } else { + boost::shared_ptr aLine = + boost::shared_ptr(new GeomAPI_Lin2d(aStartPoint->pnt(), anEndPoint->pnt())); + double aDist = aPoint1->distance(aPoint2)/5.; + boost::shared_ptr aFPnt = aLine->shiftedLocation(aDist); + aFlyOutAttr->setValue(aFPnt); + aFlyoutPnt = sketch()->to3D(aFPnt->x(), aFPnt->y()); } // value calculation boost::shared_ptr aValueAttr = boost::dynamic_pointer_cast< -- 2.39.2