]> OCCT Git - occt-copy.git/commitdiff
0027151: Exception is raised during performing command "splitshape" in the Test Harness
authorgka <gka@opencascade.com>
Thu, 25 Feb 2016 13:32:00 +0000 (16:32 +0300)
committergka <gka@opencascade.com>
Thu, 25 Feb 2016 13:32:00 +0000 (16:32 +0300)
Modifications to avoid exception for case overlapped edges was made.
Returned values of the methods LocOpe_SplitShape:AddOpenWire() and LocOpe_SplitShape:AddClosedWire() were modified from void to boolean in order to avoid raising of the exceptions for cases when result wire can not be built.

src/LocOpe/LocOpe_SplitShape.cdl
src/LocOpe/LocOpe_SplitShape.cxx
src/LocOpe/LocOpe_Spliter.cxx
src/LocOpe/LocOpe_WiresOnShape.cxx

index 2313c9d5cb29535d095be0d1148ef88249b5fe6b..7628cf2f949bb040ce87af3ad29729493aac07f9 100644 (file)
@@ -76,6 +76,7 @@ is
 
     Add(me: in out; W: Wire from TopoDS;
                    F: Face from TopoDS)
+                  returns Boolean from Standard
        ---Purpose: Adds the wire <W> on the face <F>.
        raises NoSuchObject from Standard,
               -- if <F> does not belong to the original shape.
@@ -88,6 +89,7 @@ is
     
     Add(me: in out; Lwires: ListOfShape from TopTools;
                    F: Face from TopoDS)
+                  returns Boolean from Standard
        ---Purpose: Adds the list of wires <Lwires> on the face <F>.
        raises NoSuchObject from Standard,
               -- if <F> does not belong to the original shape.
@@ -131,11 +133,11 @@ is
 -- -- Private implementation methods
 
     AddOpenWire(me: in out; W: Wire from TopoDS; F: Face from TopoDS)
-    
+      returns Boolean from Standard
        is static private;
 
 
-    AddClosedWire(me: in out; W: Wire from TopoDS; F: Face from TopoDS)
+    AddClosedWire(me: in out; W: Wire from TopoDS; F: Face from TopoDS) returns Boolean from Standard
     
        is static private;
 
index 984def24b3254527674e21daaef8893871620cd1..98971c896a6bac89b4a28766e31e643109c8b24f 100644 (file)
@@ -62,11 +62,11 @@ static Standard_Boolean IsInside(const TopoDS_Face&,
 
 static void GetDirection(const TopoDS_Edge&,
                          const TopoDS_Face&,
-                         Standard_Real&,
                          gp_Pnt2d&,
-                         gp_Vec2d&);
+                         gp_Vec2d&, 
+                         Standard_Boolean isFirstEnd);
 
-static void ChoixUV(const TopoDS_Edge&,
+static Standard_Boolean ChoixUV(const TopoDS_Edge&,
                     const TopoDS_Face&,
                     const TopTools_IndexedMapOfShape&,
                     TopoDS_Edge&,
@@ -82,9 +82,6 @@ static TopoDS_Shape ChooseDirection(const TopoDS_Shape&,
 inline Standard_Boolean SameUV(const gp_Pnt2d& P1, const gp_Pnt2d& P2, 
                                const BRepAdaptor_Surface& theBAS)//const Standard_Real tol)
 {
-  //  Standard_Real tol = Precision::Confusion();
-  //  return P1.SquareDistance(P2) < 10*tol;
-  //gka
   Standard_Boolean isSame = Standard_True;
   if(theBAS.IsUPeriodic())
     isSame = (fabs(P1.X() - P2.X()) < theBAS.UPeriod() *0.5);
@@ -155,7 +152,7 @@ void LocOpe_SplitShape::Add(const TopoDS_Vertex& V,
                             const TopoDS_Edge& E)
 {
   if (!CanSplit(E)) {
-    Standard_ConstructionError::Raise();
+    return;
   }
 
   BRep_Builder B;
@@ -165,22 +162,32 @@ void LocOpe_SplitShape::Add(const TopoDS_Vertex& V,
   }
   TopTools_ListIteratorOfListOfShape itl(le);
   Standard_Real f,l;
-
+  TopTools_ListOfShape aNewList;
   for (; itl.More(); itl.Next()) {
     const TopoDS_Edge& edg = TopoDS::Edge(itl.Value());
     BRep_Tool::Range(edg,f,l);
-    if (P>f && P <l) {
+    if (P > f + Precision::PConfusion() && P < l - Precision::PConfusion()) {
       break;
+     
     }
+    aNewList.Append(edg);
   }
   if (!itl.More()) {
-    Standard_ConstructionError::Raise();
+    return;
   }
   TopoDS_Edge edg = TopoDS::Edge(itl.Value());
   le.Remove(itl);
   if (V.Orientation() == TopAbs_FORWARD ||
     V.Orientation() == TopAbs_REVERSED) {
-
+      //TopAbs_Orientation anOriEdge= edg.Orientation();
+      //////
+      edg.Orientation(TopAbs_FORWARD);
+      TopoDS_Vertex aCurV1, aCurV2;
+      TopExp::Vertices(edg, aCurV1, aCurV2);
+      Standard_Real aPar1 = BRep_Tool::Parameter(aCurV1,edg);
+      
+      Standard_Real aPar2 = BRep_Tool::Parameter(aCurV2,edg);
+      //////////
       TopoDS_Shape aLocalShape = edg.EmptyCopied();
       TopoDS_Edge E1 = TopoDS::Edge(aLocalShape);
       aLocalShape = edg.EmptyCopied();
@@ -190,37 +197,42 @@ void LocOpe_SplitShape::Add(const TopoDS_Vertex& V,
       E1.Orientation(TopAbs_FORWARD);
       E2.Orientation(TopAbs_FORWARD);
       TopoDS_Vertex newVtx = V;
+      
+      
+      aCurV1.Orientation(TopAbs_FORWARD);
+     
+      B.Add(E1,aCurV1);
+      B.UpdateVertex(aCurV1,aPar1,E1,BRep_Tool::Tolerance(aCurV1));
       newVtx.Orientation(TopAbs_REVERSED);
       B.Add(E1,newVtx);
       B.UpdateVertex(newVtx,P,E1,BRep_Tool::Tolerance(V));
+    
       newVtx.Orientation(TopAbs_FORWARD);
       B.Add(E2,newVtx);
       B.UpdateVertex(newVtx,P,E2,BRep_Tool::Tolerance(V));
-      edg.Orientation(TopAbs_FORWARD);
-      TopExp_Explorer exp;
-      for (exp.Init(edg,TopAbs_VERTEX); exp.More(); exp.Next()) {
-        //    for (TopExp_Explorer exp(edg,TopAbs_VERTEX); exp.More(); exp.Next()) {
-        const TopoDS_Vertex& vtx = TopoDS::Vertex(exp.Current());
-        f = BRep_Tool::Parameter(vtx,edg);
-        if (f < P) {
-          B.Add(E1,vtx);
-          B.UpdateVertex(vtx,f,E1,BRep_Tool::Tolerance(vtx));
-        }
-        else {
-          B.Add(E2,vtx);
-          B.UpdateVertex(vtx,f,E2,BRep_Tool::Tolerance(vtx));
-        }
+      
+      aCurV2.Orientation(TopAbs_REVERSED);
+      B.Add(E2,aCurV2);
+      B.UpdateVertex(aCurV2,aPar2,E2,BRep_Tool::Tolerance(aCurV2));
+      
+      aNewList.Append(E1);
+      aNewList.Append(E2);
+      for (; itl.More(); itl.Next()) 
+      {
+        const TopoDS_Edge& edg = TopoDS::Edge(itl.Value());
+        aNewList.Append(edg);
       }
-      le.Append(E1);
-      le.Append(E2);
+      myMap.UnBind(E);
+      myMap.Bind(E, aNewList);
+
   }
   else {
     TopoDS_Shape aLocalShape = edg.EmptyCopied();
     TopoDS_Edge E1 = TopoDS::Edge(aLocalShape);
-    //    TopoDS_Edge E1 = TopoDS::Edge(edg.EmptyCopied());
+   
     TopExp_Explorer exp;
     for (exp.Init(edg,TopAbs_VERTEX); exp.More(); exp.Next()) {
-      //    for (TopExp_Explorer exp(edg,TopAbs_VERTEX); exp.More(); exp.Next()) {
+     
       const TopoDS_Vertex& vtx = TopoDS::Vertex(exp.Current());
       f = BRep_Tool::Parameter(vtx,edg);
       B.Add(E1,vtx);
@@ -237,12 +249,12 @@ void LocOpe_SplitShape::Add(const TopoDS_Vertex& V,
 //purpose  : adds the list of wires on the face <F>
 //=======================================================================
 
-void LocOpe_SplitShape::Add(const TopTools_ListOfShape& Lwires,
+Standard_Boolean LocOpe_SplitShape::Add(const TopTools_ListOfShape& Lwires,
                             const TopoDS_Face& F)
 {
 
   if (myDone) {
-    Standard_ConstructionError::Raise();
+    return Standard_False;
   }
 
   TopTools_ListOfShape& lf = myMap(F);
@@ -257,25 +269,25 @@ void LocOpe_SplitShape::Add(const TopTools_ListOfShape& Lwires,
 
   BRepTools::Update(F);
 
+  TopTools_ListOfShape aLInside;
   for (; itl.More(); itl.Next())
   {
     const TopoDS_Face& fac = TopoDS::Face(itl.Value());
-    Standard_Boolean AllWiresInside = Standard_True;
     TopTools_ListIteratorOfListOfShape itwires(Lwires);
     for (; itwires.More(); itwires.Next())
     {
       const TopoDS_Wire& aWire = TopoDS::Wire(itwires.Value());
-      if (!IsInside(fac, aWire))
+      if (IsInside(fac, aWire))
       {
-        AllWiresInside = Standard_False;
-        break;
+        aLInside.Append(aWire);
+        
       }
     }
-    if (AllWiresInside)
+    if(aLInside.Extent())
       break;
   }
-  if (!itl.More()) {
-    Standard_ConstructionError::Raise();
+  if (!aLInside.Extent() || !itl.More()) {
+    return Standard_False;
   }
 
   TopoDS_Face FaceRef = TopoDS::Face(itl.Value());
@@ -285,7 +297,7 @@ void LocOpe_SplitShape::Add(const TopTools_ListOfShape& Lwires,
   TopTools_ListOfShape NewWires;
 
   TopTools_DataMapOfShapeInteger SectionsTimes;
-  for (itl.Initialize(Lwires); itl.More(); itl.Next())
+  for (itl.Initialize(aLInside); itl.More(); itl.Next())
     SectionsTimes.Bind(itl.Value(), 2);
   
   TopTools_ListOfShape BreakVertices;
@@ -294,7 +306,7 @@ void LocOpe_SplitShape::Add(const TopTools_ListOfShape& Lwires,
   TopTools_DataMapOfShapeShape VerWireMap;
   Standard_Integer i;
   TopExp_Explorer ExploF, ExploW;
-  for (itl.Initialize(Lwires); itl.More(); itl.Next())
+  for (itl.Initialize(aLInside); itl.More(); itl.Next())
   {
     const TopoDS_Wire& aSection = TopoDS::Wire(itl.Value());
     TopoDS_Vertex Ver [2];
@@ -323,7 +335,7 @@ void LocOpe_SplitShape::Add(const TopTools_ListOfShape& Lwires,
   }  
   
   TopTools_DataMapOfShapeListOfShape VerSecMap;
-  for (itl.Initialize(Lwires); itl.More(); itl.Next())
+  for (itl.Initialize(aLInside); itl.More(); itl.Next())
   {
     const TopoDS_Wire& aWire = TopoDS::Wire(itl.Value());
     TopoDS_Vertex V1, V2;
@@ -520,7 +532,7 @@ void LocOpe_SplitShape::Add(const TopTools_ListOfShape& Lwires,
   ///////////////////
   
   // JAG 10.11.95 Codage des regularites
-  for (itl.Initialize(Lwires); itl.More(); itl.Next())
+  for (itl.Initialize(aLInside); itl.More(); itl.Next())
     for (ExploW.Init(itl.Value(), TopAbs_EDGE); ExploW.More(); ExploW.Next())
     {
       const TopoDS_Edge& edg = TopoDS::Edge(ExploW.Current());
@@ -528,6 +540,7 @@ void LocOpe_SplitShape::Add(const TopTools_ListOfShape& Lwires,
         BB.Continuity(edg,F,F,GeomAbs_CN);
       }
     }
+  return Standard_True;
 }
 
 
@@ -536,12 +549,12 @@ void LocOpe_SplitShape::Add(const TopTools_ListOfShape& Lwires,
 //purpose  : 
 //=======================================================================
 
-void LocOpe_SplitShape::Add(const TopoDS_Wire& W,
+Standard_Boolean LocOpe_SplitShape::Add(const TopoDS_Wire& W,
                             const TopoDS_Face& F)
 {
 
   if (myDone) {
-    Standard_ConstructionError::Raise();
+    return Standard_False;
   }
 
 
@@ -553,16 +566,18 @@ void LocOpe_SplitShape::Add(const TopoDS_Wire& W,
   try {
     OCC_CATCH_SIGNALS
     if (!LocOpe::Closed(W,F)) {
-      AddOpenWire(W,F);
+      if(!AddOpenWire(W,F))
+        return Standard_False;
     }
     else {
-      AddClosedWire(W,F);
+      if(!AddClosedWire(W,F))
+        return Standard_False;
     }
   } catch (Standard_Failure ) {
 #ifdef OCCT_DEBUG
     cout << "Warning: SpliShape internal problem detected, some faces may be lost. Check input edges/wires" <<endl;
 #endif
-    return;
+    return Standard_False;
   }
   // JAG 10.11.95 Codage des regularites
   BRep_Builder B;
@@ -572,16 +587,16 @@ void LocOpe_SplitShape::Add(const TopoDS_Wire& W,
       B.Continuity(edg,F,F,GeomAbs_CN);
     }
   }
+  return Standard_True;
 }
 
 
-
 //=======================================================================
 //function : AddClosedWire
 //purpose  : 
 //=======================================================================
 
-void LocOpe_SplitShape::AddClosedWire(const TopoDS_Wire& W,
+Standard_Boolean LocOpe_SplitShape::AddClosedWire(const TopoDS_Wire& W,
                                       const TopoDS_Face& F)
 {
   TopExp_Explorer exp;
@@ -592,23 +607,18 @@ void LocOpe_SplitShape::AddClosedWire(const TopoDS_Wire& W,
   TopoDS_Wire outerW;
   for (; itl.More(); itl.Next()) {
     const TopoDS_Face& fac = TopoDS::Face(itl.Value());
-    /*
-    outerW = BRepTools::OuterWire(fac);
-    if (IsInside(F,W,outerW)) {
-    break;
-    }
-    */
+
     if (IsInside(fac,W)) {
       break;
     }
 
   }
   if (!itl.More()) {
-    Standard_ConstructionError::Raise();
+    return Standard_False;
   }
 
   BRep_Builder B;
-
   TopAbs_Orientation orWire = W.Orientation();
   TopoDS_Shape aLocalFace = F.EmptyCopied();
   TopoDS_Face newFace = TopoDS::Face(aLocalFace);
@@ -654,7 +664,7 @@ void LocOpe_SplitShape::AddClosedWire(const TopoDS_Wire& W,
   B.Add(newRef,W.Oriented(TopAbs::Reverse(orWire)));
   lf.Append(newRef);
   lf.Append(newFace);
-
+  return Standard_True;
 }
 
 
@@ -663,7 +673,7 @@ void LocOpe_SplitShape::AddClosedWire(const TopoDS_Wire& W,
 //purpose  : 
 //=======================================================================
 
-void LocOpe_SplitShape::AddOpenWire(const TopoDS_Wire& W,
+Standard_Boolean LocOpe_SplitShape::AddOpenWire(const TopoDS_Wire& W,
                                     const TopoDS_Face& F)
 {
   // On cherche la face descendante de F qui continent le wire
@@ -682,16 +692,16 @@ void LocOpe_SplitShape::AddOpenWire(const TopoDS_Wire& W,
   toll = BRep_Tool::Tolerance(Vlast);
   tol1 = Max(tolf, toll);
 
-
   TopExp_Explorer exp,exp2;  
-
+  
   TopoDS_Wire wfirst,wlast;
   for (; itl.More(); itl.Next()) {
     TopoDS_Face fac = TopoDS::Face(itl.Value());
     if (!IsInside(fac,W)) {
       continue;
     }
-    
+   
     fac.Orientation(TopAbs_FORWARD);
     Standard_Boolean ffound = Standard_False;
     Standard_Boolean lfound = Standard_False;
@@ -719,7 +729,7 @@ void LocOpe_SplitShape::AddOpenWire(const TopoDS_Wire& W,
     }
   }
   if (!itl.More()) {
-    Standard_ConstructionError::Raise();
+    return Standard_False;
   }
 
   TopoDS_Face FaceRef = TopoDS::Face(itl.Value());
@@ -766,7 +776,6 @@ void LocOpe_SplitShape::AddOpenWire(const TopoDS_Wire& W,
     TopTools_MapOfOrientedShape MapE;
     TopoDS_Vertex vdeb,vfin;
     Standard_Integer nbPoss;
-
     // On recherche l`edge contenant Vlast
     TopoDS_Edge LastEdge;
     gp_Pnt2d pfirst,plast;
@@ -785,6 +794,7 @@ void LocOpe_SplitShape::AddOpenWire(const TopoDS_Wire& W,
       if (exp2.More()) {
         LastEdge = edg;
         LastEdge.Orientation(edg.Orientation());
+        
         break;
       }
     }
@@ -816,27 +826,10 @@ void LocOpe_SplitShape::AddOpenWire(const TopoDS_Wire& W,
       }
     }
     aLocalFace  = FaceRef.Oriented(wfirst.Orientation());
-    C2d = BRep_Tool::CurveOnSurface(LastEdge, TopoDS::Face(aLocalFace), f, l);
-    Standard_Real dpar = (l - f)*0.01;
-    if (LastEdge.Orientation() == TopAbs_FORWARD) {
-      C2d->D1(l,plast,dlast);
-      if (dlast.Magnitude() < gp::Resolution())
-      {
-        gp_Pnt2d PrevPnt = C2d->Value(l - dpar);
-        dlast.SetXY(plast.XY() - PrevPnt.XY());
-      }
-    }
-    else {
-      C2d->D1(f,plast,dlast);
-      if (dlast.Magnitude() < gp::Resolution())
-      {
-        gp_Pnt2d NextPnt = C2d->Value(f + dpar);
-        dlast.SetXY(NextPnt.XY() - plast.XY());
-      }
-      dlast.Reverse();
-    }
-
+   
+    //TopoDS_Edge aStartEdge = LastEdge;
+    GetDirection(LastEdge, TopoDS::Face(aLocalFace),plast , dlast, Standard_False);
+   
     Standard_Boolean cond;
 
     if(IsPeriodic) {
@@ -846,7 +839,7 @@ void LocOpe_SplitShape::AddOpenWire(const TopoDS_Wire& W,
     else {
       cond = !(Vfirst.IsSame(Vlast));
     }
-        
+    
     while (cond) {      
       PossE.Clear();
       
@@ -857,11 +850,17 @@ void LocOpe_SplitShape::AddOpenWire(const TopoDS_Wire& W,
 
         orient = edg.Orientation();
         TopExp::Vertices(edg,vdeb,vfin);
-        if (orient == TopAbs_FORWARD && Vlast.IsSame(vdeb)) {
-          PossE.Add(edg.Oriented(orient));
-        }
-        else if (orient == TopAbs_REVERSED && Vlast.IsSame(vfin)) {
-          PossE.Add(edg.Oriented(orient));
+        
+        if ((orient == TopAbs_FORWARD && Vlast.IsSame(vdeb)) || 
+          (orient == TopAbs_REVERSED && Vlast.IsSame(vfin))) {
+         /*   if(edg == aStartEdge)
+            {
+              PossE.Clear();
+              PossE.Add(edg);
+              break;
+            }*/
+            PossE.Add(edg);
+       
         }
       }
       nbPoss = PossE.Extent();
@@ -873,46 +872,30 @@ void LocOpe_SplitShape::AddOpenWire(const TopoDS_Wire& W,
       TopoDS_Edge aNextEdge;
       if (nbPoss == 1) {
         aNextEdge = TopoDS::Edge (PossE.FindKey (1));
-        TopoDS_Shape aLocalFace  = FaceRef.Oriented(wfirst.Orientation());
-        C2d = BRep_Tool::CurveOnSurface(aNextEdge,
-                                        TopoDS::Face(aLocalFace), f, l);
-        Standard_Real dpar = (l - f)*0.01;
-
-        if (aNextEdge.Orientation() == TopAbs_FORWARD) {
-          C2d->D1(l,plast,dlast);
-          if (dlast.Magnitude() < gp::Resolution())
-          {
-            gp_Pnt2d PrevPnt = C2d->Value(l - dpar);
-            dlast.SetXY(plast.XY() - PrevPnt.XY());
-          }
-        }
-        else {
-          C2d->D1(f,plast,dlast);
-          if (dlast.Magnitude() < gp::Resolution())
-          {
-            gp_Pnt2d NextPnt = C2d->Value(f + dpar);
-            dlast.SetXY(NextPnt.XY() - plast.XY());
-          }
-          dlast.Reverse();
-        }
+        TopoDS_Shape aLocalFaceTemp  = FaceRef.Oriented(wfirst.Orientation());
+        GetDirection(aNextEdge, TopoDS::Face(aLocalFaceTemp),plast , dlast, Standard_False);
+       
       }
       else if (nbPoss > 1) {
         // Faire choix en U,V...
-        TopoDS_Shape aLocalFace  = FaceRef.Oriented(wfirst.Orientation());
+        TopoDS_Shape aLocalFaceTemp  = FaceRef.Oriented(wfirst.Orientation());
         
-        ChoixUV(LastEdge, TopoDS::Face(aLocalFace), PossE,
-                aNextEdge, plast, dlast, toll);
+        if(!ChoixUV(LastEdge, TopoDS::Face(aLocalFaceTemp), PossE,
+                aNextEdge, plast, dlast, toll))
+                return Standard_False;
+
       }
 
       if (nbPoss >= 1) {
         if (aNextEdge.IsNull())
         {
           // loop is not closed. Split is not possible
-          Standard_ConstructionError::Raise("Split is not possible: split loop is not closed"); 
+          return Standard_False;
         }
 
-        if (MapE.Contains(aNextEdge)) 
+        if (MapE.Contains(aNextEdge))
           break;
+        
         B.Add(newW1, aNextEdge);
         MapE.Add(aNextEdge);        
         LastEdge = aNextEdge;
@@ -931,7 +914,7 @@ void LocOpe_SplitShape::AddOpenWire(const TopoDS_Wire& W,
       //MODIFICATION PIERRE SMEYERS : si pas de possibilite, on sort avec erreur
       else{
         cout<<"erreur Spliter : pas de chainage du wire"<<endl;
-        Standard_ConstructionError::Raise();        
+        return Standard_False;
       }
       //fin MODIF.
       
@@ -959,10 +942,7 @@ void LocOpe_SplitShape::AddOpenWire(const TopoDS_Wire& W,
     // modifs JAG 97.05.28
 
     B.Add(newF1,newW1);
-    //BRepTools::Write(newF1, "k:/queries/WrongBOP/NewF1.brep");
     B.Add(newF2,newW2);
-    //BRepTools::Write(newF2, "k:/queries/WrongBOP/NewF2.brep");
-    
     for (exp.Init(FaceRef.Oriented(TopAbs_FORWARD),TopAbs_WIRE); exp.More(); exp.Next()) {
       const TopoDS_Wire& wir = TopoDS::Wire(exp.Current());
       if (!wir.IsSame(wfirst)) {
@@ -1082,6 +1062,7 @@ void LocOpe_SplitShape::AddOpenWire(const TopoDS_Wire& W,
       
     }
   }
+  return Standard_True;
 }
 
 
@@ -1364,44 +1345,35 @@ static Standard_Boolean IsInside(const TopoDS_Face& F,
 //=======================================================================
 static void GetDirection(const TopoDS_Edge& theEdge,
                          const TopoDS_Face& theFace,
-                         Standard_Real& theTol,
                          gp_Pnt2d& thePnt,
-                         gp_Vec2d& theDir)
+                         gp_Vec2d& theDir,
+                         Standard_Boolean isFirstEnd)
 {
   Standard_Real aFirst, aLast;
   Handle(Geom2d_Curve) aC2d = BRep_Tool::CurveOnSurface (theEdge, theFace, aFirst, aLast);
 
   TopAbs_Orientation anOr = theEdge.Orientation();
   TopoDS_Vertex aVtx;
-  if (anOr == TopAbs_FORWARD)
+  Standard_Boolean takeFirst = ((anOr == TopAbs_FORWARD && isFirstEnd) ||
+    (anOr == TopAbs_REVERSED && !isFirstEnd));
+  Standard_Real dpar = (aLast - aFirst)*0.01;
+  gp_Pnt2d aP2d;
+  if (takeFirst)
   {
-    aVtx = TopExp::FirstVertex (theEdge);
     aC2d->D0 (aFirst, thePnt);
+    gp_Pnt2d aNextPnt = aC2d->Value(aFirst + dpar);
+    theDir = gp_Vec2d(thePnt, aNextPnt);
   }
-  else
-  {
-    aVtx = TopExp::LastVertex (theEdge);
-    aC2d->D0 (aLast, thePnt);
-  }
-
-  BRepAdaptor_Surface aSurf (theFace, Standard_False);
-  theTol = BRep_Tool::Tolerance (aVtx);
-  Standard_Real aTol = Max (aSurf.UResolution (theTol), aSurf.VResolution (theTol));
-  aTol = Min (aTol, (aLast - aFirst)*0.1);
-
-  gp_Pnt2d aP2d;
 
-  if (anOr == TopAbs_FORWARD)
-  {
-      aFirst += aTol;
-      aC2d->D0 (aFirst, aP2d);
-  }
   else
   {
-      aLast -= aTol;
-      aC2d->D0 (aLast, aP2d);
+    aC2d->D0 (aLast, thePnt);
+    gp_Pnt2d aPrevPnt = aC2d->Value(aLast - dpar);
+    theDir = gp_Vec2d( aPrevPnt, thePnt );
   }
-  theDir = gp_Vec2d (thePnt, aP2d);
+  if(anOr == TopAbs_REVERSED)
+    theDir.Reverse();
 }
 
 //=======================================================================
@@ -1409,7 +1381,7 @@ static void GetDirection(const TopoDS_Edge& theEdge,
 //purpose  : 
 //=======================================================================
 
-static void ChoixUV(const TopoDS_Edge& Last,
+Standard_Boolean ChoixUV(const TopoDS_Edge& Last,
                     const TopoDS_Face& F,
                     const TopTools_IndexedMapOfShape& Poss,
                     TopoDS_Edge& theResEdge,
@@ -1417,8 +1389,6 @@ static void ChoixUV(const TopoDS_Edge& Last,
                     gp_Vec2d& dlst,
                     const Standard_Real toll)
 {
-
-  Standard_Real f,l;
   gp_Pnt2d p2d;
   gp_Vec2d v2d;
   gp_Pnt aPCur, aPlst;
@@ -1431,15 +1401,19 @@ static void ChoixUV(const TopoDS_Edge& Last,
   gp_Dir2d ref2d(dlst);
 
   Handle(Geom2d_Curve) C2d;
-  Standard_Real dpar;
+  
 
   Standard_Integer index = 0, imin=0;
   Standard_Real  angmax = -M_PI, dist, ang;
-
-
+  
   for (index = 1; index <= Poss.Extent(); index++) {
     TopoDS_Edge anEdge = TopoDS::Edge (Poss.FindKey (index));
-    GetDirection (anEdge, F, tol, p2d, v2d);
+    
+    TopoDS_Vertex aVF = TopExp::FirstVertex(anEdge, Standard_True);
+               if( aVF.IsNull())
+      return 0;
+    tol = BRep_Tool::Tolerance(aVF);
+    GetDirection (anEdge, F, p2d, v2d, Standard_True);
 
     surf.D0 (p2d.X(), p2d.Y(), aPCur);
 
@@ -1463,29 +1437,10 @@ static void ChoixUV(const TopoDS_Edge& Last,
   if (imin)
   {
     theResEdge = TopoDS::Edge (Poss.FindKey (imin));
-    C2d = BRep_Tool::CurveOnSurface (theResEdge, F, f, l);
-    dpar = (l - f)*0.01;
-    if (theResEdge.Orientation() == TopAbs_FORWARD)
-    {
-      C2d->D1 (l, plst, dlst);
-      if (dlst.Magnitude() < gp::Resolution())
-      {
-        gp_Pnt2d PrevPnt = C2d->Value(l - dpar);
-        dlst.SetXY(plst.XY() - PrevPnt.XY());
-      }
-    }
-    else
-    {
-      C2d->D1 (f, plst, dlst);
-      if (dlst.Magnitude() < gp::Resolution())
-      {
-        gp_Pnt2d NextPnt = C2d->Value(f + dpar);
-        dlst.SetXY(NextPnt.XY() - plst.XY());
-      }
-      dlst.Reverse();
-    }
+    GetDirection (theResEdge, F, plst, dlst, Standard_False);
   }
 
+  return (imin);
 }
 
 //=======================================================================
index 5a4b757dd5386e40c3fa87f600f580269f0111c8..9d744f1819ce713bb3cc97d1a32f2e52ca0c5365 100644 (file)
@@ -147,7 +147,7 @@ void LocOpe_Spliter::Perform(const Handle(LocOpe_WiresOnShape)& PW)
 
   TopTools_MapOfShape theFacesWithSection;
   for (PW->InitEdgeIterator(); PW->MoreEdge(); PW->NextEdge()) {
-    const TopoDS_Edge& edg = PW->Edge();
+    TopoDS_Edge edg = PW->Edge();
     for (exp.Init(edg,TopAbs_VERTEX); exp.More(); exp.Next()) {
       const TopoDS_Vertex& vtx = TopoDS::Vertex(exp.Current());
       if (!mapV.Contains(vtx)) {
@@ -290,7 +290,7 @@ void LocOpe_Spliter::Perform(const Handle(LocOpe_WiresOnShape)& PW)
       TopoDS_Shape ebase = lsubs.First();
       lsubs.Clear();
       lsubs.Append(e1.Oriented(ebase.Orientation()));
-      theSubs.Substitute(ebase.Oriented(TopAbs_FORWARD),lsubs);
+      theSubs.Substitute(ebase,lsubs);
     }
     else {
 #ifdef OCCT_DEBUG
@@ -602,7 +602,7 @@ static void Select(const TopoDS_Edge& Ebase,
 
   if (!Loc.IsIdentity()) {
     Handle(Geom_Geometry) GG = C->Transformed(Loc.Transformation());
-    C = *((Handle(Geom_Curve)*)&GG);
+    C = Handle(Geom_Curve)::DownCast (GG);
   }
   gp_Pnt Pt(C->Value((f+l)/2.));
 
@@ -615,7 +615,7 @@ static void Select(const TopoDS_Edge& Ebase,
     C = BRep_Tool::Curve(edg,Loc,f,l);
     if (!Loc.IsIdentity()) {
       Handle(Geom_Geometry) GG = C->Transformed(Loc.Transformation());
-      C = *((Handle(Geom_Curve)*)&GG);
+      C = Handle(Geom_Curve)::DownCast (GG);
     }
     proj.Init(Pt,C,f,l);
     if (proj.NbPoints() > 0) {
index 91c40ece2bc3f146c9d44fa0feaf4d50e2ab4a58..106a2acb0044d82ed2771a435677c4edf041bffc 100644 (file)
@@ -17,6 +17,7 @@
 #include <LocOpe_WiresOnShape.ixx>
 
 #include <TopExp_Explorer.hxx>
+
 #include <BRep_Builder.hxx>
 #include <BRep_Tool.hxx>
 #include <TopTools_MapOfShape.hxx>
@@ -81,9 +82,7 @@ static void PutPCurves(const TopoDS_Edge&,
 
 static void FindInternalIntersections(const TopoDS_Edge&,
                                       const TopoDS_Face&,
-                                      TopTools_IndexedDataMapOfShapeListOfShape&,
-                                      TopTools_DataMapOfShapeShape&,
-                                      TopTools_MapOfShape&);
+                                      TopTools_IndexedDataMapOfShapeListOfShape&);
 
 //=======================================================================
 //function : LocOpe_WiresOnShape
@@ -240,7 +239,7 @@ void LocOpe_WiresOnShape::BindAll()
       continue;
 
     if (myCheckInterior)
-      FindInternalIntersections(edg, fac, Splits, myMap, theMap);
+      FindInternalIntersections(edg, fac, Splits);//, myMap, theMap);
   }
 
   for (Ind = 1; Ind <= Splits.Extent(); Ind++)
@@ -259,13 +258,7 @@ void LocOpe_WiresOnShape::BindAll()
       myMapEF.Add(itl.Value(), aFace);
   }
   
-  // Il faut s`occuper maintenant des vertex "de changement de face", 
-  // et des vertex "libres"
-//  TopTools_DataMapIteratorOfDataMapOfShapeShape ite2;
-
-//  for (ite.Initialize(myMapEF); ite.More(); ite.Next()) {
-//    const TopoDS_Edge& edg = TopoDS::Edge(ite.Key());
-//    const TopoDS_Face& fac = TopoDS::Face(ite.Value());
   for (Ind = 1; Ind <= myMapEF.Extent(); Ind++) {
     const TopoDS_Edge& edg = TopoDS::Edge(myMapEF.FindKey(Ind));
     const TopoDS_Face& fac = TopoDS::Face(myMapEF(Ind));
@@ -278,11 +271,11 @@ void LocOpe_WiresOnShape::BindAll()
       if (theMap.Contains(vtx)) {
        continue;
       }
-      ////
+      
       Standard_Real vtx_param = BRep_Tool::Parameter(vtx, edg);
       BRepAdaptor_Curve2d BAcurve2d(edg, fac);
       gp_Pnt2d p2d = BAcurve2d.Value(vtx_param);
-      ////
+
       TopoDS_Edge Epro;
       Standard_Real prm = 0.;
       Standard_Boolean ok = Project(vtx, p2d, fac, Epro, prm);
@@ -457,13 +450,24 @@ Standard_Boolean LocOpe_WiresOnShape::OnEdge(const TopoDS_Vertex& V,
   }
   
   Ed = TopoDS::Edge(myMap(V));
-  TopoDS_Face theFace = TopoDS::Face(myMapEF.FindFromKey(EdgeFrom));
+  if(!myMapEF.Contains(EdgeFrom))
+    return Standard_False;
+
+  TopoDS_Shape aShape = myMapEF.FindFromKey(EdgeFrom);
+  if(  aShape.ShapeType() == TopAbs_FACE)
+  {
   ////
-  Standard_Real vtx_param = BRep_Tool::Parameter(V, EdgeFrom);
-  BRepAdaptor_Curve2d BAcurve2d(EdgeFrom, theFace);
-  gp_Pnt2d p2d = BAcurve2d.Value(vtx_param);
+    TopoDS_Face aFace = TopoDS::Face(aShape);
+    Standard_Real vtx_param = BRep_Tool::Parameter(V, EdgeFrom);
+    BRepAdaptor_Curve2d BAcurve2d(EdgeFrom, aFace);
+    gp_Pnt2d p2d = BAcurve2d.Value(vtx_param);
+
   ////
-  prm = Project(V, p2d, Ed, theFace);
+    prm = Project(V, p2d, Ed, aFace);
+  }
+  else
+    prm = Project( V, TopoDS::Edge(Ed));
+       
   return Standard_True;
 }
 
@@ -506,12 +510,24 @@ Standard_Boolean Project(const TopoDS_Vertex& V,
 
   if(theEdge.IsNull())
     return Standard_False;
+  //compute distance in 3D space
+
+  Handle(Geom2d_Curve) aCrvBound = BRep_Tool::CurveOnSurface(theEdge, F, f, l);
+  gp_Pnt2d aPBound2d;
+  aCrvBound->D0(param,aPBound2d);
+  gp_Pnt aPBound;
+  Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
+  aSurf->D0(aPBound2d.X(), aPBound2d.Y(), aPBound);
+  
+  gp_Pnt aPV;
+  aSurf->D0(p2d.X(), p2d.Y(), aPV);
+  Standard_Real aDist3d = aPV.Distance(aPBound);
 
   Standard_Real ttol = BRep_Tool::Tolerance(V) + BRep_Tool::Tolerance(theEdge);
-  if (dmin <= ttol) {
+  if (aDist3d <= ttol) {
     valret = Standard_True;
     BRep_Builder B;
-    B.UpdateVertex(V, Max(dmin, BRep_Tool::Tolerance(V)));
+    B.UpdateVertex(V, Max(aDist3d, BRep_Tool::Tolerance(V)));
   }
 #ifdef OCCT_DEBUG_MESH
   else {
@@ -540,7 +556,7 @@ Standard_Real Project(const TopoDS_Vertex& V,
   C = BRep_Tool::Curve(theEdge,Loc,f,l);
   if (!Loc.IsIdentity()) {
     Handle(Geom_Geometry) GG = C->Transformed(Loc.Transformation());
-    C = *((Handle(Geom_Curve)*)&GG);
+    C = Handle(Geom_Curve)::DownCast (GG);
   }
   proj.Init(toproj,C,f,l);
   
@@ -569,7 +585,7 @@ Standard_Real Project(const TopoDS_Vertex&,
   /*
   if (!Loc.IsIdentity()) {
     Handle(Geom_Geometry) GG = C->Transformed(Loc.Transformation());
-    C = *((Handle(Geom_Curve)*)&GG);
+    C = Handle(Geom_Curve)::DownCast (GG);
   }
   */
   proj.Init(p2d, PC, f, l);
@@ -593,7 +609,7 @@ void PutPCurve(const TopoDS_Edge& Edg,
   Handle(Standard_Type) styp = S->DynamicType();
 
   if (styp == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
-    S = (*((Handle(Geom_RectangularTrimmedSurface)*)&(S)))->BasisSurface();
+    S = Handle(Geom_RectangularTrimmedSurface)::DownCast (S)->BasisSurface();
     styp = S->DynamicType();
   }
 
@@ -606,9 +622,6 @@ void PutPCurve(const TopoDS_Edge& Edg,
 
   Standard_Real f,l;
 
-  //if (!BRep_Tool::CurveOnSurface(Edg,Fac,f,l).IsNull()) {
-  //  return;
-  //}
   Handle(Geom2d_Curve) aC2d = BRep_Tool::CurveOnSurface(Edg,Fac,f,l);
   if ( !aC2d.IsNull() ) {
     gp_Pnt2d p2d;
@@ -635,7 +648,7 @@ void PutPCurve(const TopoDS_Edge& Edg,
   Handle(Geom_Curve) C = BRep_Tool::Curve(Edg,Loc,f,l);
   if (!Loc.IsIdentity()) {
     Handle(Geom_Geometry) GG = C->Transformed(Loc.Transformation());
-    C = *((Handle(Geom_Curve)*)&GG);
+    C = Handle(Geom_Curve)::DownCast (GG);
   }
 
   if (C->DynamicType() != STANDARD_TYPE(Geom_TrimmedCurve)) {
@@ -709,20 +722,6 @@ void PutPCurve(const TopoDS_Edge& Edg,
       }
     }
 
-/*
-    if (theUmin > Umax-tolu) {
-      while (theUmin > Umax-tolu) {
-       theUmin -= up;
-       nbtra--;
-      }
-    }
-    else if (theUmax < Umin+tolu) {
-      while (theUmax < Umin+tolu) {
-       theUmax += up;
-       nbtra++;
-      }
-    }
-*/
     if (nbtra !=0) {
       C2d->Translate(gp_Vec2d(nbtra*up,0.));
     }
@@ -822,7 +821,7 @@ void PutPCurves(const TopoDS_Edge& Efrom,
       S = BRep_Tool::Surface(Fac, LocFac);
       styp = S->DynamicType();
       if (styp == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
-       S = (*((Handle(Geom_RectangularTrimmedSurface)*)&(S)))->BasisSurface();
+       S = Handle(Geom_RectangularTrimmedSurface)::DownCast (S)->BasisSurface();
        styp = S->DynamicType();
       }
       if (styp == STANDARD_TYPE(Geom_Plane)) {
@@ -834,7 +833,7 @@ void PutPCurves(const TopoDS_Edge& Efrom,
       C = BRep_Tool::Curve(Efrom,Loc,f,l);
       if (!Loc.IsIdentity()) {
        Handle(Geom_Geometry) GG = C->Transformed(Loc.Transformation());
-       C = *((Handle(Geom_Curve)*)&GG);
+       C = Handle(Geom_Curve)::DownCast (GG);
       }
       
       if (C->DynamicType() != STANDARD_TYPE(Geom_TrimmedCurve)) {
@@ -999,7 +998,7 @@ void PutPCurves(const TopoDS_Edge& Efrom,
     C = BRep_Tool::Curve(Efrom,Loc,f,l);
     if (!Loc.IsIdentity()) {
       Handle(Geom_Geometry) GG = C->Transformed(Loc.Transformation());
-      C = *((Handle(Geom_Curve)*)&GG);
+      C = Handle(Geom_Curve)::DownCast (GG);
     }
 
     gp_Pnt pt;
@@ -1007,18 +1006,18 @@ void PutPCurves(const TopoDS_Edge& Efrom,
 
     C->D1(f,pt,d1f);
 
-    ////
+
     TopoDS_Vertex FirstVertex = TopExp::FirstVertex(Efrom);
     Standard_Real vtx_param = BRep_Tool::Parameter(FirstVertex, Efrom);
     BRepAdaptor_Curve2d BAcurve2d(Efrom, Fac);
     gp_Pnt2d p2d = BAcurve2d.Value(vtx_param);
-    ////
+
     Standard_Real prmproj = Project(TopExp::FirstVertex(Efrom),p2d,Eto,Fac);
     
     C = BRep_Tool::Curve(Eto,Loc,f,l);
     if (!Loc.IsIdentity()) {
       Handle(Geom_Geometry) GG = C->Transformed(Loc.Transformation());
-      C = *((Handle(Geom_Curve)*)&GG);
+      C = Handle(Geom_Curve)::DownCast (GG);
     }
     
     C->D1(prmproj,pt,d1t);
@@ -1030,14 +1029,14 @@ void PutPCurves(const TopoDS_Edge& Efrom,
       S = BRep_Tool::Surface(Fac);
       styp = S->DynamicType();
       if (styp == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
-       S = (*((Handle(Geom_RectangularTrimmedSurface)*)&(S)))->BasisSurface();
+       S = Handle(Geom_RectangularTrimmedSurface)::DownCast (S)->BasisSurface();
        styp = S->DynamicType();
       }
       
       C = BRep_Tool::Curve(Efrom,Loc,f,l);
       if (!Loc.IsIdentity()) {
        Handle(Geom_Geometry) GG = C->Transformed(Loc.Transformation());
-       C = *((Handle(Geom_Curve)*)&GG);
+       C = Handle(Geom_Curve)::DownCast (GG);
       }
       
       if (C->DynamicType() != STANDARD_TYPE(Geom_TrimmedCurve)) {
@@ -1136,9 +1135,7 @@ void PutPCurves(const TopoDS_Edge& Efrom,
 
 void FindInternalIntersections(const TopoDS_Edge& theEdge,
                                const TopoDS_Face& theFace,
-                               TopTools_IndexedDataMapOfShapeListOfShape& Splits,
-                               TopTools_DataMapOfShapeShape& GlobalMap,
-                               TopTools_MapOfShape& theMap)
+                               TopTools_IndexedDataMapOfShapeListOfShape& Splits)
 {
   Standard_Real TolExt = Precision::PConfusion();
   Standard_Integer i, j, aNbExt;
@@ -1159,7 +1156,7 @@ void FindInternalIntersections(const TopoDS_Edge& theEdge,
   Standard_Real /*theFpar, theLpar,*/ aFpar, aLpar;
   const Handle(Geom_Curve)& theCurve = BRep_Tool::Curve(theEdge, thePar[0], thePar[1]);
   GeomAdaptor_Curve theGAcurve(theCurve, thePar[0], thePar[1]);
-  
+  Standard_Real aDistMax = Precision::Confusion();
   TopExp_Explorer Explo(theFace, TopAbs_EDGE);
   for (; Explo.More(); Explo.Next())
   {
@@ -1191,43 +1188,24 @@ void FindInternalIntersections(const TopoDS_Edge& theEdge,
       anExtrema.Points(i, aPOnC1, aPOnC2);
       Standard_Real theIntPar = aPOnC1.Parameter();
       Standard_Real anIntPar = aPOnC2.Parameter();
-      Standard_Boolean IntersFound = Standard_False;
+      //Standard_Boolean IntersFound = Standard_False;
       for (j = 0; j < 2; j++) //try to find intersection on an extremity of "theEdge"
       {
-        if (Abs(theIntPar - thePar[j]) <= Precision::PConfusion() &&
-            aDist <= Precision::Confusion())
-        {
-          theMap.Add(theVertices[j]);
-          TopExp_Explorer exp2(anEdge, TopAbs_VERTEX);
-          for (; exp2.More(); exp2.Next())
-          {
-            const TopoDS_Vertex& aVertex = TopoDS::Vertex(exp2.Current());
-            if (aVertex.IsSame(theVertices[j]))
-            {
-              IntersFound = Standard_True;
-              break;
-            }
-            if (BRepTools::Compare(theVertices[j], aVertex))
-            {
-              GlobalMap.Bind(theVertices[j], aVertex);
-              IntersFound = Standard_True;
-              break;
-            }
-          }
-          if (!IntersFound)
-          {
-            GlobalMap.Bind(theVertices[j], anEdge);
-            IntersFound = Standard_True;
-            break;
-          }
-        }
+        if (Abs(theIntPar - thePar[j]) <= Precision::PConfusion())
+          break;
+                
       }
-      if (!IntersFound && aDist <= Precision::Confusion()) //intersection is inside "theEdge" => split
+      //intersection found in the middle of the edge
+      if (j >= 2)//!IntersFound) //intersection is inside "theEdge" => split
       {
         gp_Pnt aPoint = aCurve->Value(anIntPar);
         if (aPoint.Distance(thePnt[0]) > BRep_Tool::Tolerance(theVertices[0]) &&
             aPoint.Distance(thePnt[1]) > BRep_Tool::Tolerance(theVertices[1]))
+        {
           SplitPars.Append(theIntPar);
+          if( aDist > aDistMax)
+            aDistMax = aDist;
+        }
       }
     }
   }
@@ -1244,7 +1222,6 @@ void FindInternalIntersections(const TopoDS_Edge& theEdge,
         SplitPars(i) = SplitPars(j);
         SplitPars(j) = Tmp;
       }
-
   //Remove repeating points
   i = 1;
   while (i < SplitPars.Length())
@@ -1272,6 +1249,8 @@ void FindInternalIntersections(const TopoDS_Edge& theEdge,
       LastPar = SplitPars(i);
       gp_Pnt LastPoint = theCurve->Value(LastPar);
       LastVertex = BRepLib_MakeVertex(LastPoint);
+      BRep_Builder aB;
+      aB.UpdateVertex(LastVertex, aDistMax);
     }
     else
     {