0024667: BRepOffsetAPI_MakePipe::FirstShape() and LastShape() return shapes not from...
[occt.git] / src / BRepFill / BRepFill_Pipe.cxx
index 034fcf2..8620b0e 100644 (file)
@@ -5,8 +5,8 @@
 //
 // This file is part of Open CASCADE Technology software library.
 //
-// This library is free software; you can redistribute it and / or modify it
-// under the terms of the GNU Lesser General Public version 2.1 as published
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
 // by the Free Software Foundation, with special exception defined in the file
 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
 // distribution for complete text of the license and disclaimer of any warranty.
@@ -53,6 +53,7 @@
 #include <Geom_OffsetCurve.hxx>
 #include <Geom_BSplineCurve.hxx>
 #include <BRepBuilderAPI_Transform.hxx>
+#include <BRepBuilderAPI_Copy.hxx>
 #include <TopTools_SequenceOfShape.hxx>
 #include <BRepLib.hxx>
 
 #include <GeomAdaptor_HSurface.hxx>
 #include <Adaptor3d_CurveOnSurface.hxx>
 
+#include <ShapeUpgrade_RemoveLocations.hxx>
+
 #ifdef DRAW
 #include <DBRep.hxx>
 static Standard_Boolean Affich = 0;
 #endif
 
+static void ReverseModifiedEdges(TopoDS_Shape& aShape,
+                                 TopTools_MapOfShape& Emap)
+{
+  TopExp_Explorer Explo(aShape, TopAbs_FACE);
+  BRep_Builder BB;
+  for (; Explo.More(); Explo.Next())
+  {
+    TopoDS_Shape aFace = Explo.Current();
+    TopoDS_Iterator itf(aFace);
+    for (; itf.More(); itf.Next())
+    {
+      TopoDS_Shape aWire = itf.Value();
+      TopTools_SequenceOfShape ModEdges;
+      TopoDS_Iterator itw(aWire);
+      for (; itw.More(); itw.Next())
+      {
+        TopoDS_Shape anEdge = itw.Value();
+        if (Emap.Contains(anEdge))
+          ModEdges.Append(anEdge);
+      }
+      aWire.Free(Standard_True);
+      for (Standard_Integer ii = 1; ii <= ModEdges.Length(); ii++)
+      {
+        BB.Remove(aWire, ModEdges(ii));
+        BB.Add(aWire, ModEdges(ii).Reversed());
+      }
+    }
+  }
+}
 
 static void UpdateTolFromTopOrBottomPCurve(const TopoDS_Face& aFace,
                                            TopoDS_Edge& anEdge)
@@ -237,6 +269,18 @@ void BRepFill_Pipe::Perform(const TopoDS_Wire&  Spine,
     myFirst = BRepBuilderAPI_Transform(myProfile, fila, Standard_True); //copy
   }
 
+  ShapeUpgrade_RemoveLocations RemLoc;
+  RemLoc.Remove(myFirst);
+  myFirst = RemLoc.GetResult();
+  TopLoc_Location theLoc = myFirst.Location();
+  if (!theLoc.IsIdentity())
+  {
+    TopoDS_Shape NewMyFirst = BRepBuilderAPI_Copy(myFirst);
+    TopLoc_Location theIdentity;
+    NewMyFirst.Location(theIdentity);
+    myFirst = BRepBuilderAPI_Transform(NewMyFirst, theLoc.Transformation());
+  }
+  
   myLoc->Law(myLoc->NbLaw())->GetDomain(first, last);
   myLoc->Law(myLoc->NbLaw())->D0(last,M, V);
 //    try { // Not good, but there are no other means to test SetValues
@@ -256,6 +300,18 @@ void BRepFill_Pipe::Perform(const TopoDS_Wire&  Spine,
   else {
     myLast = myFirst;
   }
+
+  RemLoc.Remove(myLast);
+  myLast = RemLoc.GetResult();
+  theLoc = myLast.Location();
+  if (!theLoc.IsIdentity())
+  {
+    TopoDS_Shape NewMyLast = BRepBuilderAPI_Copy(myLast);
+    TopLoc_Location theIdentity;
+    NewMyLast.Location(theIdentity);
+    myLast = BRepBuilderAPI_Transform(NewMyLast, theLoc.Transformation());
+  }
+  
 #if DRAW
   if (Affich) {
     DBRep::Set("theprof",  TheProf);
@@ -583,6 +639,15 @@ TopoDS_Shape BRepFill_Pipe::MakeShape(const TopoDS_Shape& S,
       MkSw.Build( myReversedEdges, myTapes,
                   BRepFill_Modified, myContinuity, GeomFill_Location, myDegmax, mySegmax );
       result = MkSw.Shape();
+
+      Handle(TopTools_HArray2OfShape) aSections = MkSw.Sections();
+
+      if (aSections.IsNull() == Standard_False) {
+        const Standard_Integer aVLast = aSections->UpperCol();
+
+        myFirst = aSections->Value(1, 1);
+        myLast  = aSections->Value(1, aVLast);
+      }
     }
 
     if (TheS.ShapeType() == TopAbs_WIRE ) {
@@ -595,6 +660,9 @@ TopoDS_Shape BRepFill_Pipe::MakeShape(const TopoDS_Shape& S,
       MkSw.Build( myReversedEdges, myTapes,
                   BRepFill_Modified, myContinuity, GeomFill_Location, myDegmax, mySegmax );
       result = MkSw.Shape();
+      //Correct <myFirst> and <myLast>
+      ReverseModifiedEdges(myFirst, myReversedEdges);
+      ReverseModifiedEdges(myLast, myReversedEdges);
 
       // Labeling of elements
       if (mySections.IsNull()) {