From: dbv Date: Tue, 4 Apr 2017 14:11:04 +0000 (+0300) Subject: Issue #2090: Line not selectable when creating an arc by its center X-Git-Tag: V_2.7.0~78 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9b9b902d9e7e1d5f5d6ad1678d083cb731b1fc35;p=modules%2Fshaper.git Issue #2090: Line not selectable when creating an arc by its center Fixed arc validator. --- diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp index fed51bda4..8cb921538 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp @@ -54,6 +54,21 @@ std::shared_ptr GeomAlgoAPI_EdgeBuilder::line( return aRes; } +std::shared_ptr GeomAlgoAPI_EdgeBuilder::line( + const std::shared_ptr theLin) +{ + if(!theLin.get()) { + return std::shared_ptr(); + } + + const gp_Lin& aLin = theLin->impl(); + BRepBuilderAPI_MakeEdge anEdgeBuilder(aLin); + std::shared_ptr aRes(new GeomAPI_Edge()); + TopoDS_Edge anEdge = anEdgeBuilder.Edge(); + aRes->setImpl(new TopoDS_Shape(anEdge)); + return aRes; +} + std::shared_ptr GeomAlgoAPI_EdgeBuilder::cylinderAxis( std::shared_ptr theCylindricalFace) { @@ -143,6 +158,21 @@ std::shared_ptr GeomAlgoAPI_EdgeBuilder::lineCircle( return aRes; } +std::shared_ptr GeomAlgoAPI_EdgeBuilder::lineCircle( + std::shared_ptr theCircle) +{ + if(!theCircle.get()) { + return std::shared_ptr(); + } + + const gp_Circ& aCirc = theCircle->impl(); + BRepBuilderAPI_MakeEdge anEdgeBuilder(aCirc); + std::shared_ptr aRes(new GeomAPI_Edge()); + TopoDS_Edge anEdge = anEdgeBuilder.Edge(); + aRes->setImpl(new TopoDS_Shape(anEdge)); + return aRes; +} + std::shared_ptr GeomAlgoAPI_EdgeBuilder::lineCircleArc( std::shared_ptr theCenter, std::shared_ptr theStartPoint, std::shared_ptr theEndPoint, std::shared_ptr theNormal) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h index b7b97aa7e..a781ce219 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include /**\class GeomAlgoAPI_EdgeBuilder @@ -35,6 +37,10 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_EdgeBuilder double theDY, double theDZ); + /// Creates linear edge by GeomAPI_Lin. + /// \param theLin line. + static std::shared_ptr line(const std::shared_ptr theLin); + /// Creates edge - axis of the given cylindrical face. The result axis edge is infinite static std::shared_ptr cylinderAxis( std::shared_ptr theCylindricalFace); @@ -44,6 +50,9 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_EdgeBuilder std::shared_ptr theNormal, double theRadius); + /// Creates linear edge in a form of a circle by GeomAPI_Circle + static std::shared_ptr lineCircle(std::shared_ptr theCircle); + /// Creates linear edge in a form of a circle arc by a three points static std::shared_ptr lineCircleArc(std::shared_ptr theCenter, std::shared_ptr theStartPoint, diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index 236a104d1..9190be38a 100755 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -1325,6 +1326,35 @@ bool SketchPlugin_ArcEndPointValidator::isValid( return true; } +static GeomShapePtr toInfiniteEdge(const GeomShapePtr theShape) +{ + if(!theShape.get()) { + return theShape; + } + + if(!theShape->isEdge()) { + return theShape; + } + + std::shared_ptr anEdge(new GeomAPI_Edge(theShape)); + + if(!anEdge.get()) { + return theShape; + } + + if(anEdge->isLine()) { + std::shared_ptr aLine = anEdge->line(); + GeomShapePtr aShape = GeomAlgoAPI_EdgeBuilder::line(aLine); + return aShape; + } + + if(anEdge->isCircle() || anEdge->isArc()) { + std::shared_ptr aCircle = anEdge->circle(); + GeomShapePtr aShape = GeomAlgoAPI_EdgeBuilder::lineCircle(aCircle); + return aShape; + } +} + bool SketchPlugin_ArcEndPointIntersectionValidator::isValid( const AttributePtr& theAttribute, const std::list& theArguments, @@ -1338,7 +1368,7 @@ bool SketchPlugin_ArcEndPointIntersectionValidator::isValid( return true; } - GeomShapePtr anArcShape = anArcFeature->getArcShape(false); + GeomShapePtr anArcShape = toInfiniteEdge(anArcFeature->getArcShape(false)); if(!anArcShape.get() || anArcShape->isNull()) { return true; @@ -1352,7 +1382,7 @@ bool SketchPlugin_ArcEndPointIntersectionValidator::isValid( ResultPtr aResult = std::dynamic_pointer_cast(anObject); if(aResult.get()) { - GeomShapePtr aShape = aResult->shape(); + GeomShapePtr aShape = toInfiniteEdge(aResult->shape()); if(aShape.get() && !aShape->isNull()) { GeomShapePtr anIntersection = anArcShape->intersect(aShape); if(anIntersection.get() && !anIntersection->isNull()) { @@ -1368,7 +1398,7 @@ bool SketchPlugin_ArcEndPointIntersectionValidator::isValid( anIt != aResults.cend(); ++anIt) { - GeomShapePtr aShape = (*anIt)->shape(); + GeomShapePtr aShape = toInfiniteEdge((*anIt)->shape()); if(aShape.get() && !aShape->isNull()) { GeomShapePtr anIntersection = anArcShape->intersect(aShape); if(anIntersection.get() && !anIntersection->isNull()) {