0022822: Skipping of the first and the last edges of a wire for opened wires
authorVRO <>
Fri, 10 Feb 2012 09:57:58 +0000 (09:57 +0000)
committerbugmaster <bugmaster@opencascade.com>
Mon, 5 Mar 2012 15:32:26 +0000 (19:32 +0400)
src/SWDRAW/SWDRAW_ShapeAnalysis.cxx
src/ShapeAnalysis/ShapeAnalysis_Wire.cxx

index f22a1d5..8cc35de 100755 (executable)
@@ -42,6 +42,7 @@
 #include <BRepGProp.hxx>
 #include <BRepTopAdaptor_FClass2d.hxx>
 #include <ShapeAnalysis_ShapeContents.hxx>
+#include <BRepBuilderAPI_MakeFace.hxx>
 
 #include <TopoDS_Compound.hxx>
 #include <BRep_Builder.hxx>
@@ -54,6 +55,7 @@
 #include <ShapeFix_FreeBounds.hxx>
 
 #include <ShapeExtend_WireData.hxx>
+#include <ShapeAnalysis_Wire.hxx>
 
 static Standard_Integer tolerance
   (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
@@ -830,6 +832,61 @@ static Standard_Integer getareacontour (Draw_Interpretor& di,
   return 0;
 }
 
+
+static Standard_Integer checkselfintersection
+  (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+{
+  if (argc < 2) 
+  { 
+      di<<"Call please \"checkselfintersection wire [face]\""<<"\n";  
+      return 1; 
+  }
+
+  // Get wire.
+  const char* arg1 = argv[1];
+  TopoDS_Shape wire = DBRep::Get(arg1);
+  if (wire.IsNull() || wire.ShapeType() != TopAbs_WIRE)
+  { 
+      di<<"A null shape or not a wire is used."<<"\n";  
+      return 2; 
+  }
+
+  // Get face if the user provided us with a face.
+  TopoDS_Shape face;
+  if (argc > 2)
+  {
+      const char* arg2 = argv[2];
+      face = DBRep::Get(arg2);
+      if (face.IsNull() || face.ShapeType() != TopAbs_FACE)
+      { 
+          di<<"A null shape or not a face is used."<<"\n";  
+          return 3; 
+      }
+  }
+
+  // If the face is null, make a plane inside the wire.
+  if (face.IsNull())
+  {
+      BRepBuilderAPI_MakeFace mkFace(TopoDS::Wire(wire), true);
+      if (mkFace.IsDone())
+          face = mkFace.Face();
+      else
+      { 
+          di<<"Can't make a face for the wire. Provide please a face for analysis."<<"\n";  
+          return 4; 
+      }
+  }
+
+  ShapeAnalysis_Wire analyser(TopoDS::Wire(wire), TopoDS::Face(face), Precision::Confusion());
+  Standard_Boolean result = analyser.CheckSelfIntersection();
+
+  if (result == Standard_True)
+      di<<"A self-intersecting wire."<<"\n";
+  else
+      di<<"Not self-intersecting wire."<<"\n";
+  return 0;
+}
+
 //=======================================================================
 //function : InitCommands
 //purpose  : 
@@ -866,4 +923,5 @@ static Standard_Integer getareacontour (Draw_Interpretor& di,
                   __FILE__, MyVISEDG, groupold);
     
   theCommands.Add("getareacontour","wire ",__FILE__, getareacontour, groupold);
+  theCommands.Add ("checkselfintersection","wire [face]", __FILE__,checkselfintersection,g);
 }
index c62b08d..13a471a 100755 (executable)
@@ -395,7 +395,9 @@ void ShapeAnalysis_Wire::SetSurface (const Handle(Geom_Surface)& surface,
   
   Standard_Boolean isFail = Standard_False, isDone = Standard_False;
   for(Standard_Integer num1 = 1; num1 < nb-1; num1++) {
-    Standard_Integer fin = (num1 == 1 ? nb-1 : nb);
+    Standard_Integer fin = nb;
+    if (CheckClosed(Precision::Confusion()) && 1 == num1)
+      fin = nb-1;
     for(Standard_Integer num2 = num1+2; num2 <= fin; num2++) 
       if(!boxes(num1).IsOut(boxes(num2))){
        CheckIntersectingEdges(num1, num2);