]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Correct filtering of the edges placed on the sketch plane (issue #1377)
authorazv <azv@opencascade.com>
Thu, 24 Mar 2016 07:20:13 +0000 (10:20 +0300)
committerazv <azv@opencascade.com>
Thu, 24 Mar 2016 07:20:13 +0000 (10:20 +0300)
src/GeomAPI/GeomAPI_Edge.cpp
src/GeomAPI/GeomAPI_Edge.h
src/ModuleBase/ModuleBase_ViewerFilters.cpp

index 2edd787d94d9333de94d9ede8eaa99081c756b36..eed61730738abc4c2614a5c9b0c0f9603fdbd688 100644 (file)
@@ -5,6 +5,7 @@
 // Author:      Artem ZHIDKOV
 
 #include<GeomAPI_Edge.h>
+#include<GeomAPI_Pln.h>
 #include<GeomAPI_Pnt.h>
 #include<GeomAPI_Circ.h>
 #include<GeomAPI_Dir.h>
@@ -19,6 +20,7 @@
 #include <Geom_Circle.hxx>
 #include <GeomAdaptor_Curve.hxx>
 #include <gp_Ax1.hxx>
+#include <gp_Pln.hxx>
 
 GeomAPI_Edge::GeomAPI_Edge()
   : GeomAPI_Shape()
@@ -172,3 +174,39 @@ void GeomAPI_Edge::getRange(double& theFirst, double& theLast) const
   const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
   Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, theFirst, theLast);
 }
+
+bool GeomAPI_Edge::isInPlane(std::shared_ptr<GeomAPI_Pln> thePlane) const
+{
+  double aFirst, aLast;
+  const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
+  Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
+
+  double A, B, C, D;
+  thePlane->coefficients(A, B, C, D);
+  gp_Pln aPlane(A, B, C, D);
+
+  bool inPlane = false;
+  if (aCurve->IsKind(STANDARD_TYPE(Geom_Line))) {
+    // check start and end points on the plane
+    gp_Pnt aFirstPnt = aCurve->Value(aFirst);
+    gp_Pnt aLastPnt = aCurve->Value(aLast);
+    inPlane = aPlane.SquareDistance(aFirstPnt) < Precision::SquareConfusion() &&
+              aPlane.SquareDistance(aLastPnt) < Precision::SquareConfusion();
+  } else if (aCurve->IsKind(STANDARD_TYPE(Geom_Circle))) {
+    // check the center on the plane and normals are collinear
+    Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast(aCurve);
+    gp_Pnt aCenter = aCirc->Location();
+    Standard_Real aDot = aPlane.Axis().Direction().Dot(aCirc->Axis().Direction());
+    inPlane = aPlane.SquareDistance(aCenter) < Precision::SquareConfusion() &&
+              Abs(Abs(aDot) - 1.0) < Precision::Confusion();
+  } else {
+    // three points checking
+    gp_Pnt aFirstPnt = aCurve->Value(aFirst);
+    gp_Pnt aMidPnt = aCurve->Value((aFirst + aLast) / 2.);
+    gp_Pnt aLastPnt = aCurve->Value(aLast);
+    inPlane = aPlane.SquareDistance(aFirstPnt) < Precision::SquareConfusion() &&
+              aPlane.SquareDistance(aMidPnt) < Precision::SquareConfusion() &&
+              aPlane.SquareDistance(aLastPnt) < Precision::SquareConfusion();
+  }
+  return inPlane;
+}
index 4c929aa2a86379615e2523e983dc0f0801707ec5..d0d5ca2e81c4b9ba70cbbe8e7877c2add5c5fd4c 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <GeomAPI_Shape.h>
 
+class GeomAPI_Pln;
 class GeomAPI_Pnt;
 class GeomAPI_Circ;
 class GeomAPI_Lin;
@@ -64,6 +65,10 @@ public:
   /// Returns range of parameter on the curve
   GEOMAPI_EXPORT 
   void getRange(double& theFirst, double& theLast) const;
+
+  /// Returns true, if the edge is fully placed in the specified plane
+  GEOMAPI_EXPORT
+  bool isInPlane(const std::shared_ptr<GeomAPI_Pln> thePlane) const;
 };
 
 #endif
index 8ee95af0c03c8527e8b0081bc25bb9111ec29659..f92e3895e9ab363cdb63cb29d0a6b0b6f0f13fb9 100644 (file)
@@ -13,6 +13,8 @@
 #include <ModelAPI_Document.h>
 #include <ModelAPI_ResultConstruction.h>
 
+#include <GeomAPI_Edge.h>
+
 #include <AIS_InteractiveObject.hxx>
 #include <AIS_Shape.hxx>
 #include <AIS_Axis.hxx>
@@ -89,20 +91,13 @@ Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(const Handle(SelectMgr_Enti
         case TopAbs_VERTEX:
           {
             gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
-            return aPlane.Distance(aPnt) < Precision::Confusion();
+            return aPlane.SquareDistance(aPnt) < Precision::SquareConfusion();
           }
         case TopAbs_EDGE:
           {
-            TopoDS_Edge aEdge = TopoDS::Edge(aShape);
-            Standard_Real aFirst, aLast;
-            Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aFirst, aLast);
-            gp_Pnt aFirstPnt = aCurve->Value(aFirst);
-            gp_Pnt aMidPnt = aCurve->Value((aFirst + aLast) / 2.);
-            gp_Pnt aLastPnt = aCurve->Value(aLast);
-            bool aD1 = aPlane.Distance(aFirstPnt) < Precision::Confusion();
-            bool aD2 = aPlane.Distance(aMidPnt) < Precision::Confusion();
-            bool aD3 = aPlane.Distance(aLastPnt) < Precision::Confusion();
-            return aD1 && aD2 && aD3;
+            std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge);
+            anEdge->setImpl<TopoDS_Shape>(new TopoDS_Shape(aShape));
+            return anEdge->isInPlane(myPlane);
           }
         default:
           // The object can be selected in Object browser and contain, for example, compound.