]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2090: Line not selectable when creating an arc by its center
authordbv <dbv@opencascade.com>
Tue, 4 Apr 2017 14:11:04 +0000 (17:11 +0300)
committerdbv <dbv@opencascade.com>
Tue, 4 Apr 2017 14:11:18 +0000 (17:11 +0300)
Fixed arc validator.

src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp
src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h
src/SketchPlugin/SketchPlugin_Validators.cpp

index fed51bda42259a13c5fd7b044fec652012b84b46..8cb92153842d53e5ff13ab672b42532a041c5b4e 100644 (file)
@@ -54,6 +54,21 @@ std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::line(
   return aRes;
 }
 
+std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::line(
+    const std::shared_ptr<GeomAPI_Lin> theLin)
+{
+  if(!theLin.get()) {
+    return std::shared_ptr<GeomAPI_Edge>();
+  }
+
+  const gp_Lin& aLin = theLin->impl<gp_Lin>();
+  BRepBuilderAPI_MakeEdge anEdgeBuilder(aLin);
+  std::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge());
+  TopoDS_Edge anEdge = anEdgeBuilder.Edge();
+  aRes->setImpl(new TopoDS_Shape(anEdge));
+  return aRes;
+}
+
 std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::cylinderAxis(
     std::shared_ptr<GeomAPI_Shape> theCylindricalFace)
 {
@@ -143,6 +158,21 @@ std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::lineCircle(
   return aRes;
 }
 
+std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::lineCircle(
+    std::shared_ptr<GeomAPI_Circ> theCircle)
+{
+  if(!theCircle.get()) {
+    return std::shared_ptr<GeomAPI_Edge>();
+  }
+
+  const gp_Circ& aCirc = theCircle->impl<gp_Circ>();
+  BRepBuilderAPI_MakeEdge anEdgeBuilder(aCirc);
+  std::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge());
+  TopoDS_Edge anEdge = anEdgeBuilder.Edge();
+  aRes->setImpl(new TopoDS_Shape(anEdge));
+  return aRes;
+}
+
 std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::lineCircleArc(
     std::shared_ptr<GeomAPI_Pnt> theCenter, std::shared_ptr<GeomAPI_Pnt> theStartPoint,
     std::shared_ptr<GeomAPI_Pnt> theEndPoint, std::shared_ptr<GeomAPI_Dir> theNormal)
index b7b97aa7ee6818e881ed2106c38d0dd3e79adc09..a781ce219ac8ca76356f73c5ad29611fa0a4ad62 100644 (file)
@@ -11,6 +11,8 @@
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Pnt.h>
 #include <GeomAPI_Dir.h>
+#include <GeomAPI_Lin.h>
+#include <GeomAPI_Circ.h>
 #include <memory>
 
 /**\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<GeomAPI_Edge> line(const std::shared_ptr<GeomAPI_Lin> theLin);
+
   /// Creates edge - axis of the given cylindrical face. The result axis edge is infinite
   static std::shared_ptr<GeomAPI_Edge> cylinderAxis(
     std::shared_ptr<GeomAPI_Shape> theCylindricalFace);
@@ -44,6 +50,9 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_EdgeBuilder
                                                     std::shared_ptr<GeomAPI_Dir> theNormal,
                                                     double theRadius);
 
+  /// Creates linear edge in a form of a circle by GeomAPI_Circle
+  static std::shared_ptr<GeomAPI_Edge> lineCircle(std::shared_ptr<GeomAPI_Circ> theCircle);
+
   /// Creates linear edge in a form of a circle arc by a three points
   static std::shared_ptr<GeomAPI_Edge> lineCircleArc(std::shared_ptr<GeomAPI_Pnt> theCenter,
                                                        std::shared_ptr<GeomAPI_Pnt> theStartPoint,
index 236a104d1f5f94bf2aba41e777dddea9c5be425d..9190be38a30f8e15cb0e94d001712ddf102a3ca7 100755 (executable)
@@ -41,6 +41,7 @@
 #include <ModelGeomAlgo_Point2D.h>
 #include <ModelGeomAlgo_Shape.h>
 
+#include <GeomAlgoAPI_EdgeBuilder.h>
 #include <GeomAlgoAPI_ShapeTools.h>
 
 #include <GeomAPI_Circ.h>
@@ -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<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
+
+  if(!anEdge.get()) {
+    return theShape;
+  }
+
+  if(anEdge->isLine()) {
+    std::shared_ptr<GeomAPI_Lin> aLine = anEdge->line();
+    GeomShapePtr aShape = GeomAlgoAPI_EdgeBuilder::line(aLine);
+    return aShape;
+  }
+
+  if(anEdge->isCircle() || anEdge->isArc()) {
+    std::shared_ptr<GeomAPI_Circ> aCircle = anEdge->circle();
+    GeomShapePtr aShape = GeomAlgoAPI_EdgeBuilder::lineCircle(aCircle);
+    return aShape;
+  }
+}
+
 bool SketchPlugin_ArcEndPointIntersectionValidator::isValid(
     const AttributePtr& theAttribute,
     const std::list<std::string>& 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<ModelAPI_Result>(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()) {