]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Calculate Flyout point for distance and length
authorvsv <vitaly.smetannikov@opencascade.com>
Thu, 25 Sep 2014 08:13:30 +0000 (12:13 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Thu, 25 Sep 2014 08:13:30 +0000 (12:13 +0400)
src/GeomAPI/GeomAPI_Lin2d.cpp
src/GeomAPI/GeomAPI_Lin2d.h
src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp
src/SketchPlugin/SketchPlugin_ConstraintLength.cpp

index 1e902f4b5fd07e31304dda01b852b1028eba7852..929cff9f84d29ad8a48a9c0c70b22c3ec18e4c25 100644 (file)
@@ -69,3 +69,15 @@ bool GeomAPI_Lin2d::isRight(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) co
 
   return aDir.Crossed(aPnt - aLoc) > 0;
 }
+
+
+boost::shared_ptr<GeomAPI_Pnt2d> 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<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aLin.Location().X(), aLin.Location().Y()));
+}
index 82afee29a65d5be5a13f8a49538e03b32f001f2b..10089d67a73b72890aece0daa93081b0f8f103d5 100644 (file)
@@ -35,6 +35,9 @@ class GEOMAPI_EXPORT GeomAPI_Lin2d : public GeomAPI_Interface
       const boost::shared_ptr<GeomAPI_Pnt2d>& 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<GeomAPI_Pnt2d>& thePoint) const;
+
+  /// Returns a location point shifted on theShift in perpendicular direction
+  boost::shared_ptr<GeomAPI_Pnt2d> shiftedLocation(double theShift) const;
 };
 
 #endif
index b11bff25686049830fe7a127efa9361092e0ea38..65c6cf9cee8a0fdb5e2b5f7d5bbb245bc45a6933 100644 (file)
@@ -112,6 +112,12 @@ AISObjectPtr SketchPlugin_ConstraintDistance::getAISObject(AISObjectPtr thePrevi
   boost::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = boost::shared_ptr<GeomAPI_Pnt>();
   if(aFlyOutAttr->isInitialized()) {
     aFlyoutPnt = sketch()->to3D(aFlyOutAttr->x(), aFlyOutAttr->y());
+  } else {
+    boost::shared_ptr<GeomAPI_Lin2d> aLine = boost::shared_ptr<GeomAPI_Lin2d>(new GeomAPI_Lin2d(aPnt_A, aPnt_B));
+    double aDist = aPoint1->distance(aPoint2)/5.;
+    boost::shared_ptr<GeomAPI_Pnt2d> aFPnt = aLine->shiftedLocation(aDist);
+    aFlyOutAttr->setValue(aFPnt);
+    aFlyoutPnt = sketch()->to3D(aFPnt->x(), aFPnt->y());
   }
   // value calculation
   boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = boost::dynamic_pointer_cast<
index a1dce4b0c5a0c77122b8118272534d612fced9f4..00061c7390de1321b522f79522dd83e368e71d06 100644 (file)
@@ -80,6 +80,13 @@ AISObjectPtr SketchPlugin_ConstraintLength::getAISObject(AISObjectPtr thePreviou
   boost::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = boost::shared_ptr<GeomAPI_Pnt>();
   if (aFlyOutAttr->isInitialized()) {
     aFlyoutPnt = sketch()->to3D(aFlyOutAttr->x(), aFlyOutAttr->y());
+  } else {
+    boost::shared_ptr<GeomAPI_Lin2d> aLine = 
+      boost::shared_ptr<GeomAPI_Lin2d>(new GeomAPI_Lin2d(aStartPoint->pnt(), anEndPoint->pnt()));
+    double aDist = aPoint1->distance(aPoint2)/5.;
+    boost::shared_ptr<GeomAPI_Pnt2d> aFPnt = aLine->shiftedLocation(aDist);
+    aFlyOutAttr->setValue(aFPnt);
+    aFlyoutPnt = sketch()->to3D(aFPnt->x(), aFPnt->y());
   }
   // value calculation
   boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = boost::dynamic_pointer_cast<