Salome HOME
Issue #19019: python dump not loadable occ/19019
authorArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Fri, 29 May 2020 11:24:17 +0000 (14:24 +0300)
committerArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Fri, 29 May 2020 11:24:17 +0000 (14:24 +0300)
Geometrical selection: search a face, using projection of a point to it. It was done, because for some reasons, parametric boundaries of a face may float from time to time.

src/GeomAPI/GeomAPI_Vertex.cpp
src/GeomAPI/GeomAPI_Vertex.h
src/ModelGeomAlgo/ModelGeomAlgo_Shape.cpp

index 042b9d5c320297662fa9524d361af47b965642f7..43a43e7eb772a0cf4fef4fb13aa1a8cb9477cc98 100644 (file)
 #include <gp_Pnt.hxx>
 #include <Precision.hxx>
 
+static TopoDS_Shape* buildVertex(const gp_Pnt& thePoint)
+{
+  TopoDS_Vertex aVertex;
+  BRep_Builder aBuilder;
+  aBuilder.MakeVertex(aVertex, thePoint, Precision::Confusion());
+  return new TopoDS_Shape(aVertex);
+}
+
 GeomAPI_Vertex::GeomAPI_Vertex()
   : GeomAPI_Shape()
 {
@@ -41,12 +49,14 @@ GeomAPI_Vertex::GeomAPI_Vertex(const std::shared_ptr<GeomAPI_Shape>& theShape)
   }
 }
 
+GeomAPI_Vertex::GeomAPI_Vertex(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
+{
+  setImpl(buildVertex(thePoint->impl<gp_Pnt>()));
+}
+
 GeomAPI_Vertex::GeomAPI_Vertex(double theX, double theY, double theZ)
 {
-  TopoDS_Vertex aVertex;
-  BRep_Builder aBuilder;
-  aBuilder.MakeVertex(aVertex, gp_Pnt(theX, theY, theZ), Precision::Confusion());
-  setImpl(new TopoDS_Shape(aVertex));
+  setImpl(buildVertex(gp_Pnt(theX, theY, theZ)));
 }
 
 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Vertex::point()
index cded80618ff744e9a6b0aebf3b97e70f2dfdba2b..53aed1f9135ce6af2680fbc4c661662619f838ed 100644 (file)
@@ -38,6 +38,10 @@ public:
   GEOMAPI_EXPORT
   GeomAPI_Vertex(const std::shared_ptr<GeomAPI_Shape>& theShape);
 
+  /// Creation of vertex by the given point.
+  GEOMAPI_EXPORT
+  GeomAPI_Vertex(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
+
    /// Creation of vertex by 3d coordinates.
   GEOMAPI_EXPORT
   GeomAPI_Vertex(double theX, double theY, double theZ);
index 5de56ada29a79404a712b5617dc513664c684b73..b92bf677bd3b6a590c1ae8564098be036e91186c 100644 (file)
@@ -33,6 +33,8 @@
 #include <GeomAPI_PlanarEdges.h>
 #include <GeomAPI_Pnt.h>
 
+#include <GeomAlgoAPI_ShapeTools.h>
+
 
 #ifdef WIN32
 #pragma warning(disable : 4996) // for sprintf
@@ -78,7 +80,25 @@ namespace ModelGeomAlgo_Shape
     for (std::list<GeomShapePtr>::const_iterator aSubIt = aSubs.begin();
          aSubIt != aSubs.end(); ++aSubIt) {
       GeomPointPtr aMiddlePoint = (*aSubIt)->middlePoint();
-      if (aMiddlePoint && aMiddlePoint->distance(thePoint) < theTolerance)
+      if (!aMiddlePoint)
+        continue;
+
+      double aDistance = aMiddlePoint->distance(thePoint);
+      bool isFound = aDistance < theTolerance;
+      // issue #19019: special workaround for faces, because if the face contains B-spline contour,
+      // the middle point is calculated with respect to its poles, but not a curve itself.
+      // Thus is some operations (like BOP) the curve may have different number of poles
+      // from time to time, as a result, the face parametric boundaries are floating
+      // as well as the middle point.
+      // The workaround is to find a distance from the picking point to the face, if the distance
+      // between the picking point and the middle point on the face is small to some extend.
+      static const double THE_THRESHOLD = 100.;
+      if (!isFound && aDistance < THE_THRESHOLD * theTolerance && (*aSubIt)->isFace()) {
+        GeomVertexPtr aVertex(new GeomAPI_Vertex(thePoint));
+        aDistance = GeomAlgoAPI_ShapeTools::minimalDistance(aVertex, *aSubIt);
+        isFound = aDistance < theTolerance;
+      }
+      if (isFound)
         aFoundSubs.push_back(*aSubIt);
     }
     return aFoundSubs;