Salome HOME
Issue #2208: Fix for perpendicular constraint
authorvsv <vsv@opencascade.com>
Wed, 20 Sep 2017 08:41:59 +0000 (11:41 +0300)
committervsv <vsv@opencascade.com>
Wed, 20 Sep 2017 08:41:59 +0000 (11:41 +0300)
src/GeomAPI/GeomAPI_Lin.cpp
src/GeomAPI/GeomAPI_Lin.h
src/SketcherPrs/SketcherPrs_Perpendicular.cpp
src/SketcherPrs/SketcherPrs_PositionMgr.cpp

index 5d31b18df67c33084c6726d907becdf8b253a288..d3f44a404aedef61c6d26e1c8625bf2a247f79d6 100644 (file)
@@ -107,14 +107,21 @@ const std::shared_ptr<GeomAPI_Pnt> GeomAPI_Lin::intersect(
   new GeomAPI_Pnt(aResult.X(), aResult.Y(), aResult.Z()));
 }
 
-const std::shared_ptr<GeomAPI_Pnt> GeomAPI_Lin::project(
-    const std::shared_ptr<GeomAPI_Pnt>& thePoint) const
+double GeomAPI_Lin::projParam(
+      const std::shared_ptr<GeomAPI_Pnt>& thePoint) const
 {
   const gp_XYZ& aDir = MY_LIN->Direction().XYZ();
   const gp_XYZ& aLoc = MY_LIN->Location().XYZ();
   const gp_XYZ& aPnt = thePoint->impl<gp_Pnt>().XYZ();
-  double aParam = aDir.Dot(aPnt - aLoc);
+  return aDir.Dot(aPnt - aLoc);
+}
 
+const std::shared_ptr<GeomAPI_Pnt> GeomAPI_Lin::project(
+    const std::shared_ptr<GeomAPI_Pnt>& thePoint) const
+{
+  const gp_XYZ& aDir = MY_LIN->Direction().XYZ();
+  const gp_XYZ& aLoc = MY_LIN->Location().XYZ();
+  double aParam = projParam(thePoint);
   gp_XYZ aResult = aLoc + aDir * aParam;
   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aResult.X(), aResult.Y(), aResult.Z()));
 }
index e8c91e2e4d17495481cf7226066ba496a026030f..71048019cdd90890436c36c5cebbd10aa6b47027 100644 (file)
@@ -68,6 +68,10 @@ class GeomAPI_Lin : public GeomAPI_Interface
   const std::shared_ptr<GeomAPI_Pnt> project(
       const std::shared_ptr<GeomAPI_Pnt>& thePoint) const;
 
+  /// Returns parameter of the point projection
+  GEOMAPI_EXPORT
+  double projParam(const std::shared_ptr<GeomAPI_Pnt>& thePoint) const;
+
   /// \return true if this line contains thePoint, that is,
   /// if the distance between thePoint and this line
   ///         is less than or equal to theLinearTolerance.
index 16b5531009417c484c53acbc634e8aa005d68e2c..14cef6b266af7a1c93305663db2914bd06e8da1d 100644 (file)
@@ -78,14 +78,28 @@ bool SketcherPrs_Perpendicular::updateIfReadyToDisplay(double theStep, bool with
   std::shared_ptr<GeomAPI_Lin> aLin2 = aEdge2->line();
 
   std::shared_ptr<GeomAPI_Pnt> aPnt = aLin1->intersect(aLin2);
+  double aParam1 = aLin1->projParam(aPnt);
+  double aParam2 = aLin2->projParam(aPnt);
+
+  GeomAPI_Curve aCurve1(aShp1);
+  GeomAPI_Curve aCurve2(aShp2);
+  bool isInside1 = ((aParam1 - aCurve1.startParam()) >= -Precision::Confusion()) &&
+    ((aCurve1.endParam() - aParam1) >= Precision::Confusion());
+  bool isInside2 = ((aParam2 - aCurve2.startParam()) >= -Precision::Confusion()) &&
+    ((aCurve2.endParam() - aParam2) >= Precision::Confusion());
+
+  if (!(isInside1 && isInside2))
+    aPnt = std::shared_ptr<GeomAPI_Pnt>();
 
   // Compute position of symbols
   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
   gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep, aPnt);
-  //gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep);
-  myPntArray = new Graphic3d_ArrayOfPoints(1, withColor);
+  myPntArray = new Graphic3d_ArrayOfPoints(aPnt.get()? 1 : 2, withColor);
   myPntArray->AddVertex(aP1);
-  //myPntArray->AddVertex(aP2);
+  if (!aPnt.get()) {
+    gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep);
+    myPntArray->AddVertex(aP2);
+  }
   return true;
 }
 
index 65b1d045166f3044044e2917d7f1119f52af0e71..43e84107fde9cd07338579f458badcc1f07d1a81 100644 (file)
@@ -27,6 +27,7 @@
 #include <GeomAPI_Dir.h>
 #include <GeomAPI_Ax3.h>
 #include <GeomAPI_Circ.h>
+#include <GeomAPI_Lin2d.h>
 
 #include <GeomDataAPI_Point2D.h>
 
@@ -324,9 +325,16 @@ std::list<ObjectPtr> getCurves(const GeomPointPtr& thePnt, const SketcherPrs_Sym
       GeomPnt2dPtr aPnt2 = aSPnt2->pnt();
 
       if (aPnt1->isEqual(aPnt2d) || aPnt2->isEqual(aPnt2d)) {
+        // a point corresponds to one of the line end
         GeomShapePtr aShp = SketcherPrs_Tools::getShape(aFeature->firstResult());
         GeomCurvePtr aCurv = std::shared_ptr<GeomAPI_Curve>(new GeomAPI_Curve(aShp));
         aList.push_back(aFeature->firstResult());
+      } else {
+        // Check that a point belongs to the curve
+        GeomAPI_Lin2d aLin2d(aPnt1, aPnt2);
+        double aDist = aLin2d.distance(aPnt2d);
+        if (aDist <= Precision::Confusion())
+          aList.push_back(aFeature->firstResult());
       }
     } else if ((aFeature->getKind() == SketchPlugin_Circle::ID()) ||
               (aFeature->getKind() == SketchPlugin_Arc::ID())) {