Salome HOME
Issue #2090: Line not selectable when creating an arc by its center
authordbv <dbv@opencascade.com>
Wed, 5 Apr 2017 08:21:40 +0000 (11:21 +0300)
committerdbv <dbv@opencascade.com>
Wed, 5 Apr 2017 08:21:40 +0000 (11:21 +0300)
Fixed validator.

src/GeomAPI/GeomAPI_Shape.cpp
src/GeomAPI/GeomAPI_Shape.h
src/SketchPlugin/SketchPlugin_Validators.cpp

index c811116dff5529eb7b96243b3eecbd07d05bdf2d..78179ec86047d1ea1e080a01d62c28b66307bf33 100644 (file)
@@ -10,6 +10,7 @@
 #include <BRepAlgoAPI_Section.hxx>
 #include <BRepBndLib.hxx>
 #include <BRepBuilderAPI_FindPlane.hxx>
+#include <BRepExtrema_DistShapeShape.hxx>
 #include <BRepTools.hxx>
 #include <Bnd_Box.hxx>
 #include <Geom_Circle.hxx>
@@ -31,6 +32,8 @@
 #include <sstream>
 #include <algorithm> // for std::transform
 
+#include <BRepTools.hxx>
+
 #define MY_SHAPE implPtr<TopoDS_Shape>()
 
 GeomAPI_Shape::GeomAPI_Shape()
@@ -455,3 +458,21 @@ GeomShapePtr GeomAPI_Shape::intersect(const GeomShapePtr theShape) const
   aResShape->setImpl(new TopoDS_Shape(aResult));
   return aResShape;
 }
+
+bool GeomAPI_Shape::isIntersect(const GeomShapePtr theShape) const
+{
+  if(!theShape.get()) {
+    return false;
+  }
+
+  const TopoDS_Shape& aShape1 = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
+  const TopoDS_Shape& aShape2 = theShape->impl<TopoDS_Shape>();
+
+  BRepExtrema_DistShapeShape aDist(aShape1, aShape2);
+  aDist.Perform();
+  if(aDist.IsDone() && aDist.Value() < Precision::Confusion()) {
+    return true;
+  }
+
+  return false;
+}
index 1c7f2c7f849e06a1ff6fa0640224799a82434ad7..fa1b7766b87ef4082e6da6d3e2619b042666c9d4 100644 (file)
@@ -124,6 +124,10 @@ public:
   /// Returns intersection of shapes
   GEOMAPI_EXPORT
   std::shared_ptr<GeomAPI_Shape> intersect(const std::shared_ptr<GeomAPI_Shape> theShape) const;
+
+  /// Returns true if min distance between shapes < tolerance.
+  GEOMAPI_EXPORT
+  bool isIntersect(const std::shared_ptr<GeomAPI_Shape> theShape) const;
 };
 
 //! Pointer on list of shapes
index 9190be38a30f8e15cb0e94d001712ddf102a3ca7..630ba0e8d1e72d411a4732e13b374b91f35f4d47 100755 (executable)
@@ -1384,8 +1384,7 @@ bool SketchPlugin_ArcEndPointIntersectionValidator::isValid(
   if(aResult.get()) {
     GeomShapePtr aShape = toInfiniteEdge(aResult->shape());
     if(aShape.get() && !aShape->isNull()) {
-      GeomShapePtr anIntersection = anArcShape->intersect(aShape);
-      if(anIntersection.get() && !anIntersection->isNull()) {
+      if(anArcShape->isIntersect(aShape)) {
         return true;
       }
     }
@@ -1400,8 +1399,7 @@ bool SketchPlugin_ArcEndPointIntersectionValidator::isValid(
     {
       GeomShapePtr aShape = toInfiniteEdge((*anIt)->shape());
       if(aShape.get() && !aShape->isNull()) {
-        GeomShapePtr anIntersection = anArcShape->intersect(aShape);
-        if(anIntersection.get() && !anIntersection->isNull()) {
+        if(anArcShape->isIntersect(aShape)) {
           return true;
         }
       }