]> SALOME platform Git repositories - modules/geom.git/blobdiff - src/GEOMImpl/GEOMImpl_ShapeDriver.cxx
Salome HOME
Merge branch 'master' of https://git.salome-platform.org/git/modules/geom
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ShapeDriver.cxx
index e1ef2802214944538c3c5d6409f788b89f764736..a54d8e0be71daf1b363fd42361f7434714b8e444 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 #include <GEOMImpl_ShapeDriver.hxx>
 
+#include <GEOMImpl_IIsoline.hxx>
 #include <GEOMImpl_IShapes.hxx>
 #include <GEOMImpl_IVector.hxx>
 #include <GEOMImpl_Types.hxx>
 #include <GEOMImpl_Block6Explorer.hxx>
 
 #include <GEOM_Function.hxx>
+#include <GEOMUtils_Hatcher.hxx>
 
 // OCCT Includes
 #include <ShapeFix_Wire.hxx>
@@ -42,6 +44,7 @@
 #include <BRepBuilderAPI_Sewing.hxx>
 #include <BRepBuilderAPI_MakeWire.hxx>
 #include <BRepBuilderAPI_MakeEdge.hxx>
+#include <BRepBuilderAPI_MakeSolid.hxx>
 #include <BRepCheck.hxx>
 #include <BRepCheck_Analyzer.hxx>
 #include <BRepCheck_Shell.hxx>
@@ -50,6 +53,7 @@
 #include <BRepLib_MakeEdge.hxx>
 #include <BRepTools_WireExplorer.hxx>
 
+#include <ShapeAnalysis.hxx>
 #include <ShapeAnalysis_FreeBounds.hxx>
 
 #include <TopAbs.hxx>
@@ -72,6 +76,7 @@
 #include <GCPnts_AbscissaPoint.hxx>
 
 #include <Geom_TrimmedCurve.hxx>
+#include <Geom_Surface.hxx>
 #include <GeomAbs_CurveType.hxx>
 #include <GeomConvert_CompCurveToBSplineCurve.hxx>
 #include <GeomConvert.hxx>
@@ -93,7 +98,7 @@
 //modified by NIZNHY-PKV Wed Dec 28 13:48:20 2011f
 //static
 //  void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
-//                   const Handle(TopTools_HSequenceOfShape)& aWires);
+//                    const Handle(TopTools_HSequenceOfShape)& aWires);
 //modified by NIZNHY-PKV Wed Dec 28 13:48:23 2011t
 
 //=======================================================================
@@ -129,73 +134,24 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
 
   TopoDS_Shape aShape;
   TCollection_AsciiString aWarning;
+  TopAbs_ShapeEnum anExpectedType = TopAbs_SHAPE;
 
   BRep_Builder B;
 
   if (aType == WIRE_EDGES) {
-    Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
-    TopoDS_Wire aWire;
-    B.MakeWire(aWire);
-
-    // add edges
-    for (unsigned int ind = 1; ind <= aShapes->Length(); ind++) {
-      Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
-      TopoDS_Shape aShape_i = aRefShape->GetValue();
-      if (aShape_i.IsNull()) {
-        Standard_NullObject::Raise("Shape for wire construction is null");
-      }
-      if (aShape_i.ShapeType() == TopAbs_EDGE || aShape_i.ShapeType() == TopAbs_WIRE) {
-        TopExp_Explorer exp (aShape_i, TopAbs_EDGE);
-        for (; exp.More(); exp.Next())
-          B.Add(aWire, TopoDS::Edge(exp.Current()));
-      } else {
-        Standard_TypeMismatch::Raise
-          ("Shape for wire construction is neither an edge nor a wire");
-      }
-    }
-
-    // fix edges order
-    Handle(ShapeFix_Wire) aFW = new ShapeFix_Wire;
-    aFW->Load(aWire);
-    aFW->FixReorder();
+    anExpectedType = TopAbs_WIRE;
 
-    if (aFW->StatusReorder(ShapeExtend_FAIL1)) {
-      Standard_ConstructionError::Raise("Wire construction failed: several loops detected");
-    } else if (aFW->StatusReorder(ShapeExtend_FAIL)) {
-      Standard_ConstructionError::Raise("Wire construction failed");
-    } else {
-    }
+    Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
 
-    // IMP 0019766: Building a Wire from unconnected edges by introducing a tolerance
     Standard_Real aTolerance = aCI.GetTolerance();
     if (aTolerance < Precision::Confusion())
       aTolerance = Precision::Confusion();
 
-    aFW->ClosedWireMode() = Standard_False;
-    aFW->FixConnected(aTolerance);
-    if (aFW->StatusConnected(ShapeExtend_FAIL)) {
-      Standard_ConstructionError::Raise("Wire construction failed: cannot build connected wire");
-    }
-    // IMP 0019766
-    if (aFW->StatusConnected(ShapeExtend_DONE3)) {
-      // Confused with <prec> but not Analyzer.Precision(), set the same
-      aFW->FixGapsByRangesMode() = Standard_True;
-      if (aFW->FixGaps3d()) {
-        Handle(ShapeExtend_WireData) sbwd = aFW->WireData();
-        Handle(ShapeFix_Edge) aFe = new ShapeFix_Edge;
-        for (Standard_Integer iedge = 1; iedge <= sbwd->NbEdges(); iedge++) {
-          TopoDS_Edge aEdge = TopoDS::Edge(sbwd->Edge(iedge));
-          aFe->FixVertexTolerance(aEdge);
-          aFe->FixSameParameter(aEdge);
-        }
-      }
-      else if (aFW->StatusGaps3d(ShapeExtend_FAIL)) {
-        Standard_ConstructionError::Raise("Wire construction failed: cannot fix 3d gaps");
-      }
-    }
-      aShape = aFW->WireAPIMake();
+    aShape = MakeWireFromEdges(aShapes, aTolerance);
   }
   else if (aType == FACE_WIRE) {
+    anExpectedType = TopAbs_FACE;
+
     Handle(GEOM_Function) aRefBase = aCI.GetBase();
     TopoDS_Shape aShapeBase = aRefBase->GetValue();
     if (aShapeBase.IsNull()) Standard_NullObject::Raise("Argument Shape is null");
@@ -229,6 +185,8 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
     }
   }
   else if (aType == FACE_WIRES) {
+    anExpectedType = TopAbs_FACE;
+
     // Try to build a face from a set of wires and edges
     int ind;
 
@@ -254,6 +212,10 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
       }
     }
 
+    if (aSeqEdgesIn->IsEmpty()) {
+      Standard_ConstructionError::Raise("No edges given");
+    }
+
     // 2. Connect edges to wires of maximum length
     Handle(TopTools_HSequenceOfShape) aSeqWiresOut;
     ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdgesIn, Precision::Confusion(),
@@ -345,11 +307,13 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
     }
   }
   else if (aType == SHELL_FACES) {
+    anExpectedType = TopAbs_SHELL;
+
     Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
     unsigned int ind, nbshapes = aShapes->Length();
 
     // add faces
-    BRepBuilderAPI_Sewing aSewing(Precision::Confusion()*10.0);
+    BRepBuilderAPI_Sewing aSewing (Precision::Confusion()*10.0);
     for (ind = 1; ind <= nbshapes; ind++) {
       Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
       TopoDS_Shape aShape_i = aRefShape->GetValue();
@@ -362,7 +326,8 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
     aSewing.Perform();
 
     TopoDS_Shape sh = aSewing.SewedShape();
-    if( sh.ShapeType()==TopAbs_FACE && nbshapes==1 ) {
+
+    if (sh.ShapeType()==TopAbs_FACE && nbshapes==1) {
       // case for creation of shell from one face - PAL12722 (skl 26.06.2006)
       TopoDS_Shell ss;
       B.MakeShell(ss);
@@ -378,44 +343,35 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
         ish++;
       }
 
-      if (ish != 1)
-        aShape = aSewing.SewedShape();
-    }
-
-  }
-  else if (aType == SOLID_SHELL) {
-    Handle(GEOM_Function) aRefShell = aCI.GetBase();
-    TopoDS_Shape aShapeShell = aRefShell->GetValue();
-    if (!aShapeShell.IsNull() && aShapeShell.ShapeType() == TopAbs_COMPOUND) {
-      TopoDS_Iterator It (aShapeShell, Standard_True, Standard_True);
-      if (It.More()) aShapeShell = It.Value();
-    }
-    if (aShapeShell.IsNull() || aShapeShell.ShapeType() != TopAbs_SHELL) {
-      Standard_NullObject::Raise("Shape for solid construction is null or not a shell");
-    }
-
-    BRepCheck_Shell chkShell(TopoDS::Shell(aShapeShell));
-    if (chkShell.Closed() == BRepCheck_NotClosed) return 0;
+      if (ish != 1) {
+        // try the case of one face (Mantis issue 0021809)
+        TopExp_Explorer expF (sh, TopAbs_FACE);
+        Standard_Integer ifa = 0;
+        for (; expF.More(); expF.Next()) {
+          aShape = expF.Current();
+          ifa++;
+        }
 
-    TopoDS_Solid Sol;
-    B.MakeSolid(Sol);
-    B.Add(Sol, aShapeShell);
-    BRepClass3d_SolidClassifier SC (Sol);
-    SC.PerformInfinitePoint(Precision::Confusion());
-    if (SC.State() == TopAbs_IN) {
-      B.MakeSolid(Sol);
-      B.Add(Sol, aShapeShell.Reversed());
+        if (ifa == 1) {
+          TopoDS_Shell ss;
+          B.MakeShell(ss);
+          B.Add(ss,aShape);
+          aShape = ss;
+        }
+        else {
+          aShape = aSewing.SewedShape();
+        }
+      }
     }
 
-    aShape = Sol;
-
   }
   else if (aType == SOLID_SHELLS) {
+    anExpectedType = TopAbs_SOLID;
+
     Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
     unsigned int ind, nbshapes = aShapes->Length();
     Standard_Integer ish = 0;
-    TopoDS_Solid Sol;
-    B.MakeSolid(Sol);
+    BRepBuilderAPI_MakeSolid aMkSolid;
 
     // add shapes
     for (ind = 1; ind <= nbshapes; ind++) {
@@ -429,11 +385,13 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
         if (It.More()) aShapeShell = It.Value();
       }
       if (aShapeShell.ShapeType() == TopAbs_SHELL) {
-        B.Add(Sol, aShapeShell);
+        aMkSolid.Add(TopoDS::Shell(aShapeShell));
         ish++;
       }
     }
-    if (ish == 0) return 0;
+    if (ish == 0 || !aMkSolid.IsDone()) return 0;
+
+    TopoDS_Solid Sol = aMkSolid.Solid();
     BRepClass3d_SolidClassifier SC (Sol);
     SC.PerformInfinitePoint(Precision::Confusion());
     if (SC.State() == TopAbs_IN)
@@ -442,6 +400,8 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
       aShape = Sol;
   }
   else if (aType == COMPOUND_SHAPES) {
+    anExpectedType = TopAbs_COMPOUND;
+
     Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
     unsigned int ind, nbshapes = aShapes->Length();
 
@@ -460,31 +420,9 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
     aShape = C;
 
   }
-  /*
-  else if (aType == REVERSE_ORIENTATION) {
-    Handle(GEOM_Function) aRefShape = aCI.GetBase();
-    TopoDS_Shape aShape_i = aRefShape->GetValue();
-    if (aShape_i.IsNull()) {
-       Standard_NullObject::Raise("Shape for reverse is null");
-    }
-
-    BRepBuilderAPI_Copy Copy(aShape_i);
-    if( Copy.IsDone() ) {
-      TopoDS_Shape tds = Copy.Shape();
-      if( tds.IsNull() ) {
-        Standard_ConstructionError::Raise("Orientation aborted : Can not reverse the shape");
-      }
-
-      if( tds.Orientation() == TopAbs_FORWARD)
-        tds.Orientation(TopAbs_REVERSED);
-      else
-        tds.Orientation(TopAbs_FORWARD);
-
-      aShape = tds;
-    }
-  }
-  */
   else if (aType == EDGE_WIRE) {
+    anExpectedType = TopAbs_EDGE;
+
     Handle(GEOM_Function) aRefBase = aCI.GetBase();
     TopoDS_Shape aWire = aRefBase->GetValue();
     Standard_Real LinTol = aCI.GetTolerance();
@@ -494,6 +432,8 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
     aShape = MakeEdgeFromWire(aWire, LinTol, AngTol);
   }
   else if (aType == EDGE_CURVE_LENGTH) {
+    anExpectedType = TopAbs_EDGE;
+
     GEOMImpl_IVector aVI (aFunction);
 
     // RefCurve
@@ -567,6 +507,32 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
     BRepBuilderAPI_MakeEdge aME (ReOrientedCurve, UFirst, aParam);
     if (aME.IsDone())
       aShape = aME.Shape();
+  } else if (aType == SHAPE_ISOLINE) {
+    GEOMImpl_IIsoline     aII (aFunction);
+    Handle(GEOM_Function) aRefFace = aII.GetFace();
+    TopoDS_Shape          aShapeFace = aRefFace->GetValue();
+
+    if (aShapeFace.ShapeType() == TopAbs_FACE) {
+      TopoDS_Face   aFace  = TopoDS::Face(aShapeFace);
+      bool          isUIso = aII.GetIsUIso();
+      Standard_Real aParam = aII.GetParameter();
+      Standard_Real U1,U2,V1,V2;
+
+      // Construct a real geometric parameter.
+      aFace.Orientation(TopAbs_FORWARD);
+      ShapeAnalysis::GetFaceUVBounds(aFace,U1,U2,V1,V2);
+
+      if (isUIso) {
+        aParam = U1 + (U2 - U1)*aParam;
+      } else {
+        aParam = V1 + (V2 - V1)*aParam;
+      }
+
+      aShape = MakeIsoline(aFace, isUIso, aParam);
+    } else {
+      Standard_NullObject::Raise
+        ("Shape for isoline construction is not a face");
+    }
   }
   else {
   }
@@ -577,6 +543,17 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
   BRepCheck_Analyzer ana (aShape, false);
   if (!ana.IsValid()) {
     //Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
+    // For Mantis issue 0021772: EDF 2336 GEOM: Non valid face created from two circles
+    Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape (aShape);
+    aSfs->Perform();
+    aShape = aSfs->Shape();
+  }
+
+  // Check if the result shape type is compatible with the expected.
+  const TopAbs_ShapeEnum aShType = aShape.ShapeType();
+
+  if (anExpectedType != TopAbs_SHAPE && anExpectedType != aShType) {
+    Standard_ConstructionError::Raise("Result type check failed");
   }
 
   aFunction->SetValue(aShape);
@@ -589,6 +566,73 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
   return 1;
 }
 
+TopoDS_Wire GEOMImpl_ShapeDriver::MakeWireFromEdges(const Handle(TColStd_HSequenceOfTransient)& theEdgesFuncs,
+                                                    const Standard_Real theTolerance)
+{
+  BRep_Builder B;
+
+  TopoDS_Wire aWire;
+  B.MakeWire(aWire);
+
+  // add edges
+  for (unsigned int ind = 1; ind <= theEdgesFuncs->Length(); ind++) {
+    Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(theEdgesFuncs->Value(ind));
+    TopoDS_Shape aShape_i = aRefShape->GetValue();
+    if (aShape_i.IsNull()) {
+      Standard_NullObject::Raise("Shape for wire construction is null");
+    }
+    if (aShape_i.ShapeType() == TopAbs_EDGE || aShape_i.ShapeType() == TopAbs_WIRE) {
+      TopExp_Explorer exp (aShape_i, TopAbs_EDGE);
+      for (; exp.More(); exp.Next())
+        B.Add(aWire, TopoDS::Edge(exp.Current()));
+    } else {
+      Standard_TypeMismatch::Raise
+        ("Shape for wire construction is neither an edge nor a wire");
+    }
+  }
+
+  // fix edges order
+  Handle(ShapeFix_Wire) aFW = new ShapeFix_Wire;
+  aFW->Load(aWire);
+  aFW->FixReorder();
+
+  if (aFW->StatusReorder(ShapeExtend_FAIL1)) {
+    Standard_ConstructionError::Raise("Wire construction failed: several loops detected");
+  }
+  else if (aFW->StatusReorder(ShapeExtend_FAIL)) {
+    Standard_ConstructionError::Raise("Wire construction failed");
+  }
+  else {
+  }
+
+  // IMP 0019766: Building a Wire from unconnected edges by introducing a tolerance
+  aFW->ClosedWireMode() = Standard_False;
+  aFW->FixConnected(theTolerance);
+  if (aFW->StatusConnected(ShapeExtend_FAIL)) {
+    Standard_ConstructionError::Raise("Wire construction failed: cannot build connected wire");
+  }
+  // IMP 0019766
+  if (aFW->StatusConnected(ShapeExtend_DONE3)) {
+    // Confused with <prec> but not Analyzer.Precision(), set the same
+    aFW->FixGapsByRangesMode() = Standard_True;
+    if (aFW->FixGaps3d()) {
+      Handle(ShapeExtend_WireData) sbwd = aFW->WireData();
+      Handle(ShapeFix_Edge) aFe = new ShapeFix_Edge;
+      for (Standard_Integer iedge = 1; iedge <= sbwd->NbEdges(); iedge++) {
+        TopoDS_Edge aEdge = TopoDS::Edge(sbwd->Edge(iedge));
+        aFe->FixVertexTolerance(aEdge);
+        aFe->FixSameParameter(aEdge);
+      }
+    }
+    else if (aFW->StatusGaps3d(ShapeExtend_FAIL)) {
+      Standard_ConstructionError::Raise("Wire construction failed: cannot fix 3d gaps");
+    }
+  }
+  aWire = aFW->WireAPIMake();
+
+  return aWire;
+}
+
 TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
                                                    const Standard_Real LinTol,
                                                    const Standard_Real AngTol)
@@ -609,7 +653,7 @@ TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
     TColStd_SequenceOfReal TolSeq;
     GeomAbs_CurveType CurType;
     TopoDS_Vertex FirstVertex, LastVertex;
-    Standard_Boolean FinalReverse = Standard_False;
+    Standard_Real aPntShiftDist = 0.;
 
     BRepTools_WireExplorer wexp(theWire) ;
     for (; wexp.More(); wexp.Next())
@@ -641,8 +685,6 @@ TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
         LparSeq.Append(lpar);
         CurType = aType;
         FirstVertex = wexp.CurrentVertex();
-        if (anEdge.Orientation() == TopAbs_REVERSED)
-          FinalReverse = Standard_True;
       }
       else
       {
@@ -689,6 +731,18 @@ TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
                 gp_Pnt P2 = ElCLib::Value(lpar, aLine);
                 NewFpar = ElCLib::Parameter(PrevLine, P1);
                 NewLpar = ElCLib::Parameter(PrevLine, P2);
+
+                // Compute shift
+                if (ConnectByOrigin == TopAbs_FORWARD) {
+                  gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevLine);
+
+                  aPntShiftDist += P2.Distance(aNewP2);
+                } else {
+                  gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevLine);
+
+                  aPntShiftDist += P1.Distance(aNewP1);
+                }
+
                 if (NewLpar < NewFpar)
                 {
                   Standard_Real MemNewFpar = NewFpar;
@@ -708,6 +762,8 @@ TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
                   Abs(aCircle.Radius() - PrevCircle.Radius()) <= LinTol &&
                   aCircle.Axis().IsParallel(PrevCircle.Axis(), AngTol))
               {
+                const Standard_Boolean isFwd = ConnectByOrigin == TopAbs_FORWARD;
+
                 if (aCircle.Axis().Direction() * PrevCircle.Axis().Direction() < 0.)
                 {
                   Standard_Real memfpar = fpar;
@@ -719,6 +775,18 @@ TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
                 gp_Pnt P2 = ElCLib::Value(lpar, aCircle);
                 NewFpar = ElCLib::Parameter(PrevCircle, P1);
                 NewLpar = ElCLib::Parameter(PrevCircle, P2);
+
+                // Compute shift
+                if (isFwd) {
+                  gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevCircle);
+
+                  aPntShiftDist += P2.Distance(aNewP2);
+                } else {
+                  gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevCircle);
+
+                  aPntShiftDist += P1.Distance(aNewP1);
+                }
+
                 if (NewLpar < NewFpar)
                   NewLpar += 2.*M_PI;
                 //Standard_Real MemNewFpar = NewFpar, MemNewLpar =  NewLpar;
@@ -744,6 +812,8 @@ TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
                   Abs(anEllipse.MinorRadius() - PrevEllipse.MinorRadius()) <= LinTol &&
                   anEllipse.Axis().IsParallel(PrevEllipse.Axis(), AngTol))
               {
+                const Standard_Boolean isFwd = ConnectByOrigin == TopAbs_FORWARD;
+
                 if (anEllipse.Axis().Direction() * PrevEllipse.Axis().Direction() < 0.)
                 {
                   Standard_Real memfpar = fpar;
@@ -755,6 +825,18 @@ TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
                 gp_Pnt P2 = ElCLib::Value(lpar, anEllipse);
                 NewFpar = ElCLib::Parameter(PrevEllipse, P1);
                 NewLpar = ElCLib::Parameter(PrevEllipse, P2);
+
+                // Compute shift
+                if (isFwd) {
+                  gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevEllipse);
+
+                  aPntShiftDist += P2.Distance(aNewP2);
+                } else {
+                  gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevEllipse);
+
+                  aPntShiftDist += P1.Distance(aNewP1);
+                }
+
                 if (NewLpar < NewFpar)
                   NewLpar += 2.*M_PI;
                 if (ConnectByOrigin == TopAbs_FORWARD)
@@ -783,6 +865,18 @@ TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
                 gp_Pnt P2 = ElCLib::Value(lpar, aHypr);
                 NewFpar = ElCLib::Parameter(PrevHypr, P1);
                 NewLpar = ElCLib::Parameter(PrevHypr, P2);
+
+                // Compute shift
+                if (ConnectByOrigin == TopAbs_FORWARD) {
+                  gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevHypr);
+
+                  aPntShiftDist += P2.Distance(aNewP2);
+                } else {
+                  gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevHypr);
+
+                  aPntShiftDist += P1.Distance(aNewP1);
+                }
+
                 if (NewLpar < NewFpar)
                 {
                   Standard_Real MemNewFpar = NewFpar;
@@ -807,6 +901,18 @@ TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
                 gp_Pnt P2 = ElCLib::Value(lpar, aParab);
                 NewFpar = ElCLib::Parameter(PrevParab, P1);
                 NewLpar = ElCLib::Parameter(PrevParab, P2);
+
+                // Compute shift
+                if (ConnectByOrigin == TopAbs_FORWARD) {
+                  gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevParab);
+
+                  aPntShiftDist += P2.Distance(aNewP2);
+                } else {
+                  gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevParab);
+
+                  aPntShiftDist += P1.Distance(aNewP1);
+                }
+
                 if (NewLpar < NewFpar)
                 {
                   Standard_Real MemNewFpar = NewFpar;
@@ -836,19 +942,18 @@ TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
           LocSeq.Append(aLocShape);
           FparSeq.Append(fpar);
           LparSeq.Append(lpar);
-          TolSeq.Append(BRep_Tool::Tolerance(CurVertex));
+          TolSeq.Append(aPntShiftDist + BRep_Tool::Tolerance(CurVertex));
+          aPntShiftDist = 0.;
           CurType = aType;
         }
       } // end of else (CurveSeq.IsEmpty()) -> not first time
     } // end for (; wexp.More(); wexp.Next())
 
     LastVertex = wexp.CurrentVertex();
-    TolSeq.Append(BRep_Tool::Tolerance(LastVertex));
+    TolSeq.Append(aPntShiftDist + BRep_Tool::Tolerance(LastVertex));
 
-    TopoDS_Vertex FirstVtx_final = (FinalReverse)? LastVertex : FirstVertex;
-    FirstVtx_final.Orientation(TopAbs_FORWARD);
-    TopoDS_Vertex LastVtx_final = (FinalReverse)? FirstVertex : LastVertex;
-    LastVtx_final.Orientation(TopAbs_REVERSED);
+    FirstVertex.Orientation(TopAbs_FORWARD);
+    LastVertex.Orientation(TopAbs_REVERSED);
 
     if (!CurveSeq.IsEmpty())
     {
@@ -916,71 +1021,278 @@ TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
         if (concatcurve->Value(concatcurve->Lower())->Continuity()==GeomAbs_C0){
           Standard_ConstructionError::Raise("Construction aborted : The given Wire has sharp bends between some Edges, no valid Edge can be built");
         }
-        ResEdge = BRepLib_MakeEdge(concatcurve->Value(concatcurve->Lower()),
-                                   FirstVtx_final, LastVtx_final,
-                                   concatcurve->Value(concatcurve->Lower())->FirstParameter(),
-                                   concatcurve->Value(concatcurve->Lower())->LastParameter());
+
+        Standard_Boolean isValidEndVtx = Standard_True;
+
+        if (closed_flag) {
+          // Check if closed curve is reordered.
+          Handle(Geom_Curve) aCurve  = concatcurve->Value(concatcurve->Lower());
+          Standard_Real      aFPar   = aCurve->FirstParameter();
+          gp_Pnt             aPFirst;
+          gp_Pnt             aPntVtx = BRep_Tool::Pnt(FirstVertex);
+          Standard_Real      aTolVtx = BRep_Tool::Tolerance(FirstVertex);
+
+          aCurve->D0(aFPar, aPFirst);
+
+          if (!aPFirst.IsEqual(aPntVtx, aTolVtx)) {
+            // The curve is reordered. Find the new first and last vertices.
+            TopTools_IndexedMapOfShape aMapVtx;
+            TopExp::MapShapes(theWire, TopAbs_VERTEX, aMapVtx);
+
+            const Standard_Integer aNbVtx = aMapVtx.Extent();
+            Standard_Integer       iVtx;
+
+            for (iVtx = 1; iVtx <= aNbVtx; iVtx++) {
+              const TopoDS_Vertex aVtx = TopoDS::Vertex(aMapVtx.FindKey(iVtx));
+              const gp_Pnt        aPnt = BRep_Tool::Pnt(aVtx);
+              const Standard_Real aTol = BRep_Tool::Tolerance(aVtx);
+
+              if (aPFirst.IsEqual(aPnt, aTol)) {
+                // The coinsident vertex is found.
+                FirstVertex = aVtx;
+                LastVertex  = aVtx;
+                FirstVertex.Orientation(TopAbs_FORWARD);
+                LastVertex.Orientation(TopAbs_REVERSED);
+                break;
+              }
+            }
+
+            if (iVtx > aNbVtx) {
+              // It is necessary to create new vertices.
+              isValidEndVtx = Standard_False;
+            }
+          }
+        }
+
+        if (isValidEndVtx) {
+          ResEdge = BRepLib_MakeEdge(concatcurve->Value(concatcurve->Lower()),
+                                     FirstVertex, LastVertex,
+                                     concatcurve->Value(concatcurve->Lower())->FirstParameter(),
+                                     concatcurve->Value(concatcurve->Lower())->LastParameter());
+        } else {
+          ResEdge = BRepLib_MakeEdge(concatcurve->Value(concatcurve->Lower()),
+                                     concatcurve->Value(concatcurve->Lower())->FirstParameter(),
+                                     concatcurve->Value(concatcurve->Lower())->LastParameter());
+        }
       }
       else
       {
         if (CurveSeq(1)->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
           CurveSeq(1) = (*((Handle(Geom_TrimmedCurve)*)&(CurveSeq(1))))->BasisCurve();
 
-        CurveSeq(1)->Transform(LocSeq(1).Location().Transformation());
-        ResEdge = BRepLib_MakeEdge(CurveSeq(1),
-                                   FirstVtx_final, LastVtx_final,
+        Handle(Geom_Curve) aNewCurve =
+          Handle(Geom_Curve)::DownCast(CurveSeq(1)->Copy());
+
+        aNewCurve->Transform(LocSeq(1).Location().Transformation());
+
+        if (LocSeq(1).Orientation() == TopAbs_REVERSED) {
+          const TopoDS_Vertex aVtxTmp = FirstVertex;
+
+          FirstVertex = LastVertex;
+          LastVertex  = aVtxTmp;
+          FirstVertex.Orientation(TopAbs_FORWARD);
+          LastVertex.Orientation(TopAbs_REVERSED);
+        }
+
+        ResEdge = BRepLib_MakeEdge(aNewCurve,
+                                   FirstVertex, LastVertex,
                                    FparSeq(1), LparSeq(1));
+
+        if (LocSeq(1).Orientation() == TopAbs_REVERSED) {
+          ResEdge.Reverse();
+        }
       }
     }
 
-    if (FinalReverse)
-      ResEdge.Reverse();
-
     return ResEdge;
 }
 
-//=======================================================================
-//function :  GEOMImpl_ShapeDriver_Type_
-//purpose  :
-//=======================================================================
-Standard_EXPORT Handle_Standard_Type& GEOMImpl_ShapeDriver_Type_()
+//=============================================================================
+/*!
+ * \brief Returns an isoline for a face.
+ */
+//=============================================================================
+
+TopoDS_Shape GEOMImpl_ShapeDriver::MakeIsoline
+                            (const TopoDS_Face &theFace,
+                             const bool         IsUIso,
+                             const double       theParameter) const
 {
+  TopoDS_Shape          aResult;
+  GEOMUtils::Hatcher    aHatcher(theFace);
+  const GeomAbs_IsoType aType = (IsUIso ? GeomAbs_IsoU : GeomAbs_IsoV);
 
-  static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
-  if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
-  static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
-  if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
-  static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
-  if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
+  aHatcher.Init(aType, theParameter);
+  aHatcher.Perform();
 
+  if (!aHatcher.IsDone()) {
+    Standard_ConstructionError::Raise("MakeIsoline : Hatcher failure");
+  }
+
+  const Handle(TColStd_HArray1OfInteger) &anIndices =
+    (IsUIso ? aHatcher.GetUIndices() : aHatcher.GetVIndices());
+
+  if (anIndices.IsNull()) {
+    Standard_ConstructionError::Raise("MakeIsoline : Null hatching indices");
+  }
+
+  const Standard_Integer anIsoInd = anIndices->Lower();
+  const Standard_Integer aHatchingIndex = anIndices->Value(anIsoInd);
 
-  static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
-  static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ShapeDriver",
-                                                         sizeof(GEOMImpl_ShapeDriver),
-                                                         1,
-                                                         (Standard_Address)_Ancestors,
-                                                         (Standard_Address)NULL);
+  if (aHatchingIndex == 0) {
+    Standard_ConstructionError::Raise("MakeIsoline : Invalid hatching index");
+  }
+
+  const Standard_Integer aNbDomains =
+    aHatcher.GetNbDomains(aHatchingIndex);
 
-  return _aType;
+  if (aNbDomains < 0) {
+    Standard_ConstructionError::Raise("MakeIsoline : Invalid number of domains");
+  }
+
+  // The hatching is performed successfully. Create the 3d Curve.
+  Handle(Geom_Surface) aSurface   = BRep_Tool::Surface(theFace);
+  Handle(Geom_Curve)   anIsoCurve = (IsUIso ?
+    aSurface->UIso(theParameter) : aSurface->VIso(theParameter));
+  Handle(Geom2d_Curve) aPIsoCurve =
+    aHatcher.GetHatching(aHatchingIndex);
+  const Standard_Real  aTol = Precision::Confusion();
+  Standard_Integer     anIDom = 1;
+  Standard_Real        aV1;
+  Standard_Real        aV2;
+  BRep_Builder         aBuilder;
+  Standard_Integer     aNbEdges = 0;
+
+  for (; anIDom <= aNbDomains; anIDom++) {
+    if (aHatcher.GetDomain(aHatchingIndex, anIDom, aV1, aV2)) {
+      // Check first and last parameters.
+      if (!aHatcher.IsDomainInfinite(aHatchingIndex, anIDom)) {
+        // Create an edge.
+        TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(anIsoCurve, aV1, aV2);
+
+        // Update it with a parametric curve on face.
+        aBuilder.UpdateEdge(anEdge, aPIsoCurve, theFace, aTol);
+        aNbEdges++;
+
+        if (aNbEdges > 1) {
+          // Result is a compond.
+          if (aNbEdges == 2) {
+            // Create a new compound.
+            TopoDS_Compound aCompound;
+
+            aBuilder.MakeCompound(aCompound);
+            aBuilder.Add(aCompound, aResult);
+            aResult = aCompound;
+          }
+
+          // Add an edge to the compound.
+          aBuilder.Add(aResult, anEdge);
+        } else {
+          // Result is the edge.
+          aResult = anEdge;
+        }
+      }
+    }
+  }
+
+  if (aNbEdges == 0) {
+    Standard_ConstructionError::Raise("MakeIsoline : Empty result");
+  }
+
+  return aResult;
 }
 
-//=======================================================================
-//function : DownCast
-//purpose  :
-//=======================================================================
-const Handle(GEOMImpl_ShapeDriver) Handle(GEOMImpl_ShapeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
-{
-  Handle(GEOMImpl_ShapeDriver) _anOtherObject;
+//================================================================================
+/*!
+ * \brief Returns a name of creation operation and names and values of creation parameters
+ */
+//================================================================================
 
-  if (!AnObject.IsNull()) {
-     if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ShapeDriver))) {
-       _anOtherObject = Handle(GEOMImpl_ShapeDriver)((Handle(GEOMImpl_ShapeDriver)&)AnObject);
-     }
+bool GEOMImpl_ShapeDriver::
+GetCreationInformation(std::string&             theOperationName,
+                       std::vector<GEOM_Param>& theParams)
+{
+  if (Label().IsNull()) return 0;
+  Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
+
+  GEOMImpl_IShapes aCI( function );
+  Standard_Integer aType = function->GetType();
+
+  switch ( aType ) {
+  case WIRE_EDGES:
+    theOperationName = "WIRE";
+    AddParam( theParams, "Wires/edges", aCI.GetShapes() );
+    AddParam( theParams, "Tolerance", aCI.GetTolerance() );
+    break;
+  case FACE_WIRE:
+    theOperationName = "FACE";
+    AddParam( theParams, "Wire/edge", aCI.GetBase() );
+    AddParam( theParams, "Is planar wanted", aCI.GetIsPlanar() );
+    break;
+  case FACE_WIRES:
+    theOperationName = "FACE";
+    AddParam( theParams, "Wires/edges", aCI.GetShapes() );
+    AddParam( theParams, "Is planar wanted", aCI.GetIsPlanar() );
+    break;
+  case SHELL_FACES:
+    theOperationName = "SHELL";
+    AddParam( theParams, "Objects", aCI.GetShapes() );
+    break;
+  case SOLID_SHELLS:
+    theOperationName = "SOLID";
+    AddParam( theParams, "Objects", aCI.GetShapes() );
+    break;
+  case COMPOUND_SHAPES:
+    theOperationName = "COMPOUND";
+    AddParam( theParams, "Objects", aCI.GetShapes() );
+    break;
+  case EDGE_WIRE:
+    theOperationName = "EDGE";
+    AddParam( theParams, "Wire", aCI.GetBase() );
+    AddParam( theParams, "Linear Tolerance", aCI.GetTolerance() );
+    AddParam( theParams, "Angular Tolerance", aCI.GetAngularTolerance() );
+    break;
+  case EDGE_CURVE_LENGTH:
+    theOperationName = "EDGE";
+    {
+      GEOMImpl_IVector aCI( function );
+      AddParam( theParams, "Edge", aCI.GetPoint1() );
+      AddParam( theParams, "Start point", aCI.GetPoint2() );
+      AddParam( theParams, "Length", aCI.GetParameter() );
+    }
+    break;
+  case SHAPES_ON_SHAPE:
+  {
+    theOperationName = "GetShapesOnShapeAsCompound";
+    Handle(TColStd_HSequenceOfTransient) shapes = aCI.GetShapes();
+    if ( !shapes.IsNull() && shapes->Length() > 0 )
+      AddParam( theParams, "Check shape", shapes->Value(1) );
+    if ( !shapes.IsNull() && shapes->Length() > 1 )
+      AddParam( theParams, "Shape", shapes->Value(2) );
+    AddParam( theParams, "Shape type", TopAbs_ShapeEnum( aCI.GetSubShapeType() ));
+    AddParam( theParams, "State", TopAbs_State((int) aCI.GetTolerance() ));
+    break;
+  }
+  case SHAPE_ISOLINE:
+  {
+    GEOMImpl_IIsoline aII (function);
+
+    theOperationName = "ISOLINE";
+    AddParam(theParams, "Face", aII.GetFace());
+    AddParam(theParams, "Isoline type", (aII.GetIsUIso() ? "U" : "V"));
+    AddParam(theParams, "Parameter", aII.GetParameter());
+    break;
+  }
+  default:
+    return false;
   }
 
-  return _anOtherObject;
+  return true;
 }
 
+IMPLEMENT_STANDARD_HANDLE (GEOMImpl_ShapeDriver,GEOM_BaseDriver);
+IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_ShapeDriver,GEOM_BaseDriver);
+
 //modified by NIZNHY-PKV Wed Dec 28 13:48:31 2011f
 #include <TopoDS_Iterator.hxx>
 #include <TopTools_HSequenceOfShape.hxx>
@@ -996,7 +1308,7 @@ const Handle(GEOMImpl_ShapeDriver) Handle(GEOMImpl_ShapeDriver)::DownCast(const
 //=======================================================================
 /*
 void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
-                   const Handle(TopTools_HSequenceOfShape)& aWires)
+                    const Handle(TopTools_HSequenceOfShape)& aWires)
 {
   Standard_Integer aNbWires, aNbEdges;
   // 
@@ -1035,7 +1347,7 @@ void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
     for (j=1; j<=aNbEdges; ++j) {
       const TopoDS_Shape& aE=aEdges->Value(j);
       if (aMEx.Contains(aE)) {
-       aBB.Add(aWy, aE);
+        aBB.Add(aWy, aE);
       }
     }
     //