From 5ad83dd4300d19b33dbe06f414de71ec42243a7f Mon Sep 17 00:00:00 2001 From: dbv Date: Wed, 5 Apr 2017 11:21:40 +0300 Subject: [PATCH] Issue #2090: Line not selectable when creating an arc by its center Fixed validator. --- src/GeomAPI/GeomAPI_Shape.cpp | 21 ++++++++++++++++++++ src/GeomAPI/GeomAPI_Shape.h | 4 ++++ src/SketchPlugin/SketchPlugin_Validators.cpp | 6 ++---- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/GeomAPI/GeomAPI_Shape.cpp b/src/GeomAPI/GeomAPI_Shape.cpp index c811116df..78179ec86 100644 --- a/src/GeomAPI/GeomAPI_Shape.cpp +++ b/src/GeomAPI/GeomAPI_Shape.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -31,6 +32,8 @@ #include #include // for std::transform +#include + #define MY_SHAPE implPtr() 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(this)->impl(); + const TopoDS_Shape& aShape2 = theShape->impl(); + + BRepExtrema_DistShapeShape aDist(aShape1, aShape2); + aDist.Perform(); + if(aDist.IsDone() && aDist.Value() < Precision::Confusion()) { + return true; + } + + return false; +} diff --git a/src/GeomAPI/GeomAPI_Shape.h b/src/GeomAPI/GeomAPI_Shape.h index 1c7f2c7f8..fa1b7766b 100644 --- a/src/GeomAPI/GeomAPI_Shape.h +++ b/src/GeomAPI/GeomAPI_Shape.h @@ -124,6 +124,10 @@ public: /// Returns intersection of shapes GEOMAPI_EXPORT std::shared_ptr intersect(const std::shared_ptr theShape) const; + + /// Returns true if min distance between shapes < tolerance. + GEOMAPI_EXPORT + bool isIntersect(const std::shared_ptr theShape) const; }; //! Pointer on list of shapes diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index 9190be38a..630ba0e8d 100755 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -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; } } -- 2.39.2