0027065: BRepOffsetAPI_MakePipe misses definition of virtual method Generated()
[occt.git] / src / BRepFill / BRepFill_Pipe.cxx
index 046279d..46bee4d 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-#include <BRepFill_Pipe.ixx>
 
-#include <Standard_ErrorHandler.hxx>
-
-#include <BRep_Tool.hxx>
+#include <Adaptor3d_CurveOnSurface.hxx>
 #include <BRep_Builder.hxx>
+#include <BRep_Tool.hxx>
+#include <BRepBuilderAPI_Copy.hxx>
+#include <BRepBuilderAPI_Transform.hxx>
 #include <BRepClass3d_SolidClassifier.hxx>
-#include <BRepLib_MakeVertex.hxx>
-#include <BRepTools_Substitution.hxx>
-
-#include <GeomFill_CorrectedFrenet.hxx>
-#include <GeomFill_Frenet.hxx>
-#include <GeomFill_DiscreteTrihedron.hxx>
-#include <GeomFill_CurveAndTrihedron.hxx>
-
+#include <BRepFill_Edge3DLaw.hxx>
+#include <BRepFill_LocationLaw.hxx>
+#include <BRepFill_Pipe.hxx>
 #include <BRepFill_SectionPlacement.hxx>
 #include <BRepFill_ShapeLaw.hxx>
-#include <BRepFill_Edge3DLaw.hxx>
 #include <BRepFill_Sweep.hxx>
-
+#include <BRepLib.hxx>
+#include <BRepLib_MakeVertex.hxx>
+#include <BRepTools_Substitution.hxx>
+#include <Geom2dAdaptor_HCurve.hxx>
+#include <Geom_BSplineCurve.hxx>
+#include <Geom_OffsetCurve.hxx>
+#include <Geom_TrimmedCurve.hxx>
 #include <GeomAbs_Shape.hxx>
-#include <TopExp.hxx>
+#include <GeomAdaptor_HSurface.hxx>
+#include <GeomFill_CorrectedFrenet.hxx>
+#include <GeomFill_CurveAndTrihedron.hxx>
+#include <GeomFill_DiscreteTrihedron.hxx>
+#include <GeomFill_Frenet.hxx>
+#include <gp_Pnt.hxx>
+#include <Precision.hxx>
+#include <ShapeUpgrade_RemoveLocations.hxx>
+#include <Standard_DomainError.hxx>
+#include <Standard_ErrorHandler.hxx>
+#include <Standard_NotImplemented.hxx>
+#include <StdFail_NotDone.hxx>
+#include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
+#include <TColStd_DataMapOfIntegerInteger.hxx>
 #include <TopAbs_ShapeEnum.hxx>
+#include <TopExp.hxx>
 #include <TopoDS.hxx>
-#include <TopoDS_Shell.hxx>
-#include <TopoDS_Solid.hxx>
 #include <TopoDS_Compound.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Face.hxx>
 #include <TopoDS_Iterator.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Shell.hxx>
+#include <TopoDS_Solid.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <TopoDS_Wire.hxx>
 #include <TopTools_DataMapOfShapeInteger.hxx>
-#include <TColStd_DataMapOfIntegerInteger.hxx>
-#include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
-
-#include <Precision.hxx>
-#include <Standard_NotImplemented.hxx>
-
-#include <Geom_TrimmedCurve.hxx>
-#include <Geom_OffsetCurve.hxx>
-#include <Geom_BSplineCurve.hxx>
-#include <BRepBuilderAPI_Transform.hxx>
-#include <BRepBuilderAPI_Copy.hxx>
-#include <TopTools_SequenceOfShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
-#include <BRepLib.hxx>
-
-#include <Geom2dAdaptor_HCurve.hxx>
-#include <GeomAdaptor_HSurface.hxx>
-#include <Adaptor3d_CurveOnSurface.hxx>
-
-#include <ShapeUpgrade_RemoveLocations.hxx>
+#include <TopTools_SequenceOfShape.hxx>
 
 #ifdef DRAW
 #include <DBRep.hxx>
 static Standard_Boolean Affich = 0;
 #endif
 
+// ---------------------------------------------------------------------------------
+// static function: UpdateMap
+// purpose:
+// ---------------------------------------------------------------------------------
+static Standard_Boolean UpdateMap(const TopoDS_Shape&                 theKey,
+                                  const TopoDS_Shape&                 theValue,
+                                  TopTools_DataMapOfShapeListOfShape& theMap)
+{
+  if(!theMap.IsBound(theKey))
+  {
+    TopTools_ListOfShape thelist;
+    theMap.Bind(theKey, thelist);
+  }
+  TopTools_ListOfShape& aList = theMap.ChangeFind(theKey);
+  TopTools_ListIteratorOfListOfShape anIt(aList);
+  Standard_Boolean found = Standard_False;
+
+  for(; anIt.More(); anIt.Next())
+  {
+    if(theValue.IsSame(anIt.Value()))
+    {
+      found = Standard_True;
+      break;
+    }
+  }
+
+  if(!found)
+    aList.Append(theValue);
+  
+  return !found;
+}
+
 static void ReverseModifiedEdges(TopoDS_Shape& aShape,
                                  TopTools_MapOfShape& Emap)
 {
@@ -263,8 +296,7 @@ void BRepFill_Pipe::Perform(const TopoDS_Wire&  Spine,
   myLoc->Law(1)->D0(first, M, V);
     fila.SetValues(M(1,1), M(1,2), M(1,3), V.X(),
                   M(2,1), M(2,2), M(2,3), V.Y(),
-                  M(3,1), M(3,2), M(3,3), V.Z(),
-                  1.e-12, 1.e-14);
+                  M(3,1), M(3,2), M(3,3), V.Z());
 
   fila.Multiply(myTrsf);
   TopLoc_Location LocFirst(fila);
@@ -275,26 +307,16 @@ void BRepFill_Pipe::Perform(const TopoDS_Wire&  Spine,
   }
 
   ShapeUpgrade_RemoveLocations RemLoc;
+  RemLoc.SetRemoveLevel(TopAbs_COMPOUND);
   RemLoc.Remove(myFirst);
   myFirst = RemLoc.GetResult();
-  TopLoc_Location theLoc = myFirst.Location();
-  if (!theLoc.IsIdentity())
-  {
-    TopoDS_Shape NewMyFirst = BRepBuilderAPI_Copy(myFirst);
-    RemLoc.Remove(NewMyFirst);
-    NewMyFirst = RemLoc.GetResult();
-    TopLoc_Location theIdentity;
-    NewMyFirst.Location(theIdentity);
-    myFirst = BRepBuilderAPI_Transform(NewMyFirst, theLoc.Transformation(), Standard_True);
-  }
   
   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
   fila.SetValues(M(1,1), M(1,2), M(1,3), V.X(),
                 M(2,1), M(2,2), M(2,3), V.Y(),
-                M(3,1), M(3,2), M(3,3), V.Z(),
-                1.e-12, 1.e-14);
+                M(3,1), M(3,2), M(3,3), V.Z());
   fila.Multiply(myTrsf);
   TopLoc_Location LocLast(fila);
   if (! myLoc->IsClosed() || LocFirst != LocLast) {
@@ -310,16 +332,6 @@ void BRepFill_Pipe::Perform(const TopoDS_Wire&  Spine,
 
   RemLoc.Remove(myLast);
   myLast = RemLoc.GetResult();
-  theLoc = myLast.Location();
-  if (!theLoc.IsIdentity())
-  {
-    TopoDS_Shape NewMyLast = BRepBuilderAPI_Copy(myLast);
-    RemLoc.Remove(NewMyLast);
-    NewMyLast = RemLoc.GetResult();
-    TopLoc_Location theIdentity;
-    NewMyLast.Location(theIdentity);
-    myLast = BRepBuilderAPI_Transform(NewMyLast, theLoc.Transformation(), Standard_True);
-  }
   
 #if DRAW
   if (Affich) {
@@ -363,6 +375,16 @@ const TopoDS_Shape& BRepFill_Pipe::Shape() const
   return myShape;
 }
 
+//=======================================================================
+//function : ErrorOnSurface
+//purpose  : 
+//=======================================================================
+
+Standard_Real BRepFill_Pipe::ErrorOnSurface() const 
+{
+  return myErrorOnSurf;
+}
+
 
 //=======================================================================
 //function : FirstShape
@@ -385,6 +407,47 @@ const TopoDS_Shape& BRepFill_Pipe::LastShape() const
   return myLast;
 }
 
+//=======================================================================
+//function : Generated
+//purpose  : 
+//=======================================================================
+void BRepFill_Pipe::Generated(const TopoDS_Shape&   theShape,
+                              TopTools_ListOfShape& theList) 
+{
+  theList.Clear();
+
+  if (theShape.IsSame(myProfile))
+    theList.Append(myShape);
+  else
+  {
+    if (theShape.ShapeType() == TopAbs_FACE ||
+        theShape.ShapeType() == TopAbs_WIRE)
+    {
+      if(myGenMap.IsBound(theShape))
+        theList = myGenMap.Find(theShape);
+    }
+    else if (theShape.ShapeType() == TopAbs_EDGE)
+    {
+      TopoDS_Iterator itw(mySpine);
+      for (; itw.More(); itw.Next())
+      {
+        const TopoDS_Edge& aSpineEdge = TopoDS::Edge(itw.Value());
+        const TopoDS_Shape& aFace = Face(aSpineEdge, TopoDS::Edge(theShape));
+        theList.Append(aFace);
+      }
+    }
+    else if (theShape.ShapeType() == TopAbs_VERTEX)
+    {
+      TopoDS_Iterator itw(mySpine);
+      for (; itw.More(); itw.Next())
+      {
+        const TopoDS_Edge& aSpineEdge = TopoDS::Edge(itw.Value());
+        const TopoDS_Shape& anEdge = Edge(aSpineEdge, TopoDS::Vertex(theShape));
+        theList.Append(anEdge);
+      }
+    }
+  }
+}
 
 //=======================================================================
 //function : Face
@@ -521,6 +584,7 @@ TopoDS_Wire BRepFill_Pipe::PipeLine(const gp_Pnt& Point)
  MkSw.Build( myReversedEdges, myTapes, myRails,
              BRepFill_Modified, myContinuity, GeomFill_Location, myDegmax, mySegmax );
  TopoDS_Shape aLocalShape = MkSw.Shape();
+ myErrorOnSurf = MkSw.ErrorOnSurface();
  return TopoDS::Wire(aLocalShape);
 // return TopoDS::Wire(MkSw.Shape());
 }
@@ -566,20 +630,21 @@ TopoDS_Shape BRepFill_Pipe::MakeShape(const TopoDS_Shape& S,
       B.MakeShell(TopoDS::Shell(result));
       B.MakeWire(W);
       B.Add(W, S);
-      W.Closed(S.Closed());
+      W.Closed(BRep_Tool::IsClosed(S));
       TheS = W;
       if (!FirstShape.IsNull()) {
        B.MakeWire(W);
        B.Add(W, FirstShape);
-       W.Closed(FirstShape.Closed());
+       W.Closed(BRep_Tool::IsClosed(FirstShape));
        TheFirst = W;
       }
       if (!LastShape.IsNull()) {
        B.MakeWire(W);
        B.Add(W, LastShape);
-       W.Closed(LastShape.Closed());
+       W.Closed(BRep_Tool::IsClosed(LastShape));
        TheLast = W;
       }
+      result.Closed (BRep_Tool::IsClosed (result));
       break;
     }
          
@@ -594,6 +659,7 @@ TopoDS_Shape BRepFill_Pipe::MakeShape(const TopoDS_Shape& S,
       if ( !mySpine.Closed() && !TheFirst.IsNull()) {
         B.Add(result, TheFirst.Reversed());
       }
+      result.Closed (BRep_Tool::IsClosed (result));
       break;
     }
 
@@ -648,6 +714,8 @@ TopoDS_Shape BRepFill_Pipe::MakeShape(const TopoDS_Shape& S,
       MkSw.Build( myReversedEdges, myTapes, myRails,
                   BRepFill_Modified, myContinuity, GeomFill_Location, myDegmax, mySegmax );
       result = MkSw.Shape();
+      UpdateMap(TheS.Located(myProfile.Location()), result, myGenMap);
+      myErrorOnSurf = MkSw.ErrorOnSurface();
 
       Handle(TopTools_HArray2OfShape) aSections = MkSw.Sections();
 
@@ -669,6 +737,8 @@ TopoDS_Shape BRepFill_Pipe::MakeShape(const TopoDS_Shape& S,
       MkSw.Build( myReversedEdges, myTapes, myRails,
                   BRepFill_Modified, myContinuity, GeomFill_Location, myDegmax, mySegmax );
       result = MkSw.Shape();
+      UpdateMap(TheS.Located(myProfile.Location()), result, myGenMap);
+      myErrorOnSurf = MkSw.ErrorOnSurface();
       //Correct <myFirst> and <myLast>
       ReverseModifiedEdges(myFirst, myReversedEdges);
       ReverseModifiedEdges(myLast, myReversedEdges);
@@ -775,6 +845,7 @@ TopoDS_Shape BRepFill_Pipe::MakeShape(const TopoDS_Shape& S,
       BS.Add(solid,TopoDS::Shell(aLocalShape));
 //      BS.Add(solid,TopoDS::Shell(result.Reversed()));
     }
+    UpdateMap(TheS.Located(myProfile.Location()), solid, myGenMap);
     return solid;
   }
   else {
@@ -804,14 +875,14 @@ Standard_Integer BRepFill_Pipe::FindEdge(const TopoDS_Shape& S,
          
   case TopAbs_WIRE :
     {
-      Standard_Integer ii = InitialLength+1;
       Handle(BRepFill_ShapeLaw) Section = 
-       new (BRepFill_ShapeLaw) (TopoDS::Wire(S), Standard_False);
-      InitialLength += Section->NbLaw();
-     
-      for (; (ii<=InitialLength) && (!result); ii++) {
-       if (E.IsSame(Section->Edge(ii)) ) result = ii;
+        new (BRepFill_ShapeLaw) (TopoDS::Wire(S), Standard_False);
+      Standard_Integer NbLaw = Section->NbLaw();
+
+      for (Standard_Integer ii = 1; (ii<=NbLaw) && (!result); ii++) {
+        if (E.IsSame(Section->Edge(ii)) ) result = InitialLength + ii;
       }
+      InitialLength += NbLaw;
       break;
     }
 
@@ -923,13 +994,13 @@ void BRepFill_Pipe::DefineRealSegmax()
             C->DynamicType() == STANDARD_TYPE(Geom_OffsetCurve))
        {
          if (C->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve))
-           C = (*((Handle(Geom_TrimmedCurve)*)&C))->BasisCurve();
+           C = Handle(Geom_TrimmedCurve)::DownCast (C)->BasisCurve();
          if (C->DynamicType() == STANDARD_TYPE(Geom_OffsetCurve))
-           C = (*((Handle(Geom_OffsetCurve)*)&C))->BasisCurve();
+           C = Handle(Geom_OffsetCurve)::DownCast (C)->BasisCurve();
        }
       if (C->DynamicType() == STANDARD_TYPE(Geom_BSplineCurve))
        {
-         const Handle(Geom_BSplineCurve)& BC = *((Handle(Geom_BSplineCurve)*)&C);
+         Handle(Geom_BSplineCurve) BC (Handle(Geom_BSplineCurve)::DownCast (C));
          Standard_Integer NbKnots = BC->NbKnots();
          Standard_Integer RealNbKnots = NbKnots;
          if (first > BC->FirstParameter())