Salome HOME
22752: [EDF] Provide explicit feedback on what has been done by Shape Processing...
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ShapeDriver.cxx
index 037e6290005ccdc7adc7d9dd14689d903605c213..9e8f83b06d2d9e638d6fcd2640bb008847f24956 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <GEOMImpl_IIsoline.hxx>
 #include <GEOMImpl_IShapes.hxx>
+#include <GEOMImpl_IShapeExtend.hxx>
 #include <GEOMImpl_IVector.hxx>
 #include <GEOMImpl_Types.hxx>
 #include <GEOMImpl_Block6Explorer.hxx>
@@ -42,6 +43,7 @@
 #include <BRepAlgo_FaceRestrictor.hxx>
 #include <BRepBuilderAPI_Copy.hxx>
 #include <BRepBuilderAPI_Sewing.hxx>
+#include <BRepBuilderAPI_MakeFace.hxx>
 #include <BRepBuilderAPI_MakeWire.hxx>
 #include <BRepBuilderAPI_MakeEdge.hxx>
 #include <BRepBuilderAPI_MakeSolid.hxx>
@@ -76,6 +78,7 @@
 #include <GCPnts_AbscissaPoint.hxx>
 
 #include <Geom_TrimmedCurve.hxx>
+#include <Geom_RectangularTrimmedSurface.hxx>
 #include <Geom_Surface.hxx>
 #include <GeomAbs_CurveType.hxx>
 #include <GeomConvert_CompCurveToBSplineCurve.hxx>
 #include <Standard_TypeMismatch.hxx>
 #include <Standard_ConstructionError.hxx>
 
-// Uncomment this definition to check if type of created shape is the same
-// as expected. For further details please see the Mantis issue
-// http://salome.mantis.opencascade.com/view.php?id=22674 
-//#define RESULT_TYPE_CHECK
+#include <BOPAlgo_PaveFiller.hxx>
+#include <BOPAlgo_MakerVolume.hxx>
+
+#include <list>
 
 //modified by NIZNHY-PKV Wed Dec 28 13:48:20 2011f
 //static
@@ -139,16 +142,12 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
 
   TopoDS_Shape aShape;
   TCollection_AsciiString aWarning;
-#ifdef RESULT_TYPE_CHECK
-  TopAbs_ShapeEnum anExpectedType = TopAbs_SHAPE;
-#endif
+  std::list<TopAbs_ShapeEnum> anExpectedType;
 
   BRep_Builder B;
 
   if (aType == WIRE_EDGES) {
-#ifdef RESULT_TYPE_CHECK
-    anExpectedType = TopAbs_WIRE;
-#endif
+    anExpectedType.push_back(TopAbs_WIRE);
 
     Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
 
@@ -159,9 +158,7 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
     aShape = MakeWireFromEdges(aShapes, aTolerance);
   }
   else if (aType == FACE_WIRE) {
-#ifdef RESULT_TYPE_CHECK
-    anExpectedType = TopAbs_FACE;
-#endif
+    anExpectedType.push_back(TopAbs_FACE);
 
     Handle(GEOM_Function) aRefBase = aCI.GetBase();
     TopoDS_Shape aShapeBase = aRefBase->GetValue();
@@ -196,9 +193,7 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
     }
   }
   else if (aType == FACE_WIRES) {
-#ifdef RESULT_TYPE_CHECK
-    anExpectedType = TopAbs_FACE;
-#endif
+    anExpectedType.push_back(TopAbs_FACE);
 
     // Try to build a face from a set of wires and edges
     int ind;
@@ -225,6 +220,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(),
@@ -315,10 +314,44 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
       aShape = C;
     }
   }
+  else if (aType == FACE_FROM_SURFACE) {
+    anExpectedType.push_back(TopAbs_FACE);
+
+    Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
+
+    if (aShapes.IsNull() == Standard_False) {
+      Standard_Integer aNbShapes = aShapes->Length();
+
+      if (aNbShapes == 2) {
+        Handle(GEOM_Function) aRefFace =
+          Handle(GEOM_Function)::DownCast(aShapes->Value(1));
+        Handle(GEOM_Function) aRefWire =
+          Handle(GEOM_Function)::DownCast(aShapes->Value(2));
+
+        if (aRefFace.IsNull() == Standard_False &&
+            aRefWire.IsNull() == Standard_False) {
+          TopoDS_Shape aShFace = aRefFace->GetValue();
+          TopoDS_Shape aShWire = aRefWire->GetValue();
+
+          if (aShFace.IsNull()    == Standard_False &&
+              aShFace.ShapeType() == TopAbs_FACE    &&
+              aShWire.IsNull()    == Standard_False &&
+              aShWire.ShapeType() == TopAbs_WIRE) {
+            TopoDS_Face             aFace = TopoDS::Face(aShFace);
+            TopoDS_Wire             aWire = TopoDS::Wire(aShWire);
+            Handle(Geom_Surface)    aSurf = BRep_Tool::Surface(aFace);
+            BRepBuilderAPI_MakeFace aMkFace(aSurf, aWire);
+
+            if (aMkFace.IsDone()) {
+              aShape = aMkFace.Shape();
+            }
+          }
+        }
+      }
+    }
+  }
   else if (aType == SHELL_FACES) {
-#ifdef RESULT_TYPE_CHECK
-    anExpectedType = TopAbs_SHELL;
-#endif
+    anExpectedType.push_back(TopAbs_SHELL);
 
     Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
     unsigned int ind, nbshapes = aShapes->Length();
@@ -375,42 +408,9 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
       }
     }
 
-  }
-  else if (aType == SOLID_SHELL) {
-#ifdef RESULT_TYPE_CHECK
-    anExpectedType = TopAbs_SOLID;
-#endif
-
-    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;
-
-    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());
-    }
-
-    aShape = Sol;
-
   }
   else if (aType == SOLID_SHELLS) {
-#ifdef RESULT_TYPE_CHECK
-    anExpectedType = TopAbs_SOLID;
-#endif
+    anExpectedType.push_back(TopAbs_SOLID);
 
     Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
     unsigned int ind, nbshapes = aShapes->Length();
@@ -444,9 +444,7 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
       aShape = Sol;
   }
   else if (aType == COMPOUND_SHAPES) {
-#ifdef RESULT_TYPE_CHECK
-    anExpectedType = TopAbs_COMPOUND;
-#endif
+    anExpectedType.push_back(TopAbs_COMPOUND);
 
     Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
     unsigned int ind, nbshapes = aShapes->Length();
@@ -466,34 +464,8 @@ 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) {
-#ifdef RESULT_TYPE_CHECK
-    anExpectedType = TopAbs_EDGE;
-#endif
+    anExpectedType.push_back(TopAbs_EDGE);
 
     Handle(GEOM_Function) aRefBase = aCI.GetBase();
     TopoDS_Shape aWire = aRefBase->GetValue();
@@ -503,10 +475,35 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
 
     aShape = MakeEdgeFromWire(aWire, LinTol, AngTol);
   }
+  else if (aType == SOLID_FACES) {
+    anExpectedType.push_back(TopAbs_SOLID);
+    anExpectedType.push_back(TopAbs_COMPOUND);
+    anExpectedType.push_back(TopAbs_COMPSOLID);
+    
+    Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
+    unsigned int ind, nbshapes = aShapes->Length();
+    
+    // add faces
+    BOPCol_ListOfShape aLS;
+    for (ind = 1; ind <= nbshapes; 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 solid construction is null");
+      }
+      aLS.Append(aShape_i);
+    }
+
+    BOPAlgo_MakerVolume aMV;
+    aMV.SetArguments(aLS);
+    aMV.SetIntersect(aCI.GetIsIntersect());
+    aMV.Perform();
+    if (aMV.ErrorStatus()) return 0;
+
+    aShape = aMV.Shape();
+  }
   else if (aType == EDGE_CURVE_LENGTH) {
-#ifdef RESULT_TYPE_CHECK
-    anExpectedType = TopAbs_EDGE;
-#endif
+    anExpectedType.push_back(TopAbs_EDGE);
 
     GEOMImpl_IVector aVI (aFunction);
 
@@ -582,10 +579,6 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
     if (aME.IsDone())
       aShape = aME.Shape();
   } else if (aType == SHAPE_ISOLINE) {
-#ifdef RESULT_TYPE_CHECK
-    anExpectedType = TopAbs_EDGE;
-#endif
-
     GEOMImpl_IIsoline     aII (aFunction);
     Handle(GEOM_Function) aRefFace = aII.GetFace();
     TopoDS_Shape          aShapeFace = aRefFace->GetValue();
@@ -611,6 +604,70 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
       Standard_NullObject::Raise
         ("Shape for isoline construction is not a face");
     }
+  } else if (aType == EDGE_UV) {
+    anExpectedType.push_back(TopAbs_EDGE);
+    GEOMImpl_IShapeExtend aSE (aFunction);
+    Handle(GEOM_Function) aRefEdge   = aSE.GetShape();
+    TopoDS_Shape          aShapeEdge = aRefEdge->GetValue();
+
+    if (aShapeEdge.ShapeType() == TopAbs_EDGE) {
+      TopoDS_Edge anEdge = TopoDS::Edge(aShapeEdge);
+
+      aShape = ExtendEdge(anEdge, aSE.GetUMin(), aSE.GetUMax());
+    }
+  } else if (aType == FACE_UV) {
+    anExpectedType.push_back(TopAbs_FACE);
+
+    GEOMImpl_IShapeExtend aSE (aFunction);
+    Handle(GEOM_Function) aRefFace   = aSE.GetShape();
+    TopoDS_Shape          aShapeFace = aRefFace->GetValue();
+
+    if (aShapeFace.ShapeType() == TopAbs_FACE) {
+      TopoDS_Face aFace = TopoDS::Face(aShapeFace);
+
+      aFace.Orientation(TopAbs_FORWARD);
+      aShape = ExtendFace(aFace, aSE.GetUMin(), aSE.GetUMax(),
+                          aSE.GetVMin(), aSE.GetVMax()); 
+    }
+  } else if (aType == SURFACE_FROM_FACE) {
+    anExpectedType.push_back(TopAbs_FACE);
+
+    GEOMImpl_IShapeExtend aSE (aFunction);
+    Handle(GEOM_Function) aRefFace   = aSE.GetShape();
+    TopoDS_Shape          aShapeFace = aRefFace->GetValue();
+
+    if (aShapeFace.ShapeType() == TopAbs_FACE) {
+      TopoDS_Face          aFace    = TopoDS::Face(aShapeFace);
+      Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace);
+
+      if (aSurface.IsNull() == Standard_False) {
+        Handle(Standard_Type) aType = aSurface->DynamicType();
+        Standard_Real         aU1;
+        Standard_Real         aU2;
+        Standard_Real         aV1;
+        Standard_Real         aV2;
+
+         // Get U, V bounds of the face.
+        aFace.Orientation(TopAbs_FORWARD);
+        ShapeAnalysis::GetFaceUVBounds(aFace, aU1, aU2, aV1, aV2);
+
+        // Get the surface of original type
+        while (aType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
+          Handle(Geom_RectangularTrimmedSurface) aTrSurface =
+            Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
+
+          aSurface = aTrSurface->BasisSurface();
+          aType    = aSurface->DynamicType();
+        }
+
+        const Standard_Real     aTol = BRep_Tool::Tolerance(aFace);
+        BRepBuilderAPI_MakeFace aMF(aSurface, aU1, aU2, aV1, aV2, aTol);
+
+        if (aMF.IsDone()) {
+          aShape = aMF.Shape();
+        }
+      }
+    }
   }
   else {
   }
@@ -627,34 +684,17 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
     aShape = aSfs->Shape();
   }
 
-#ifdef RESULT_TYPE_CHECK
   // Check if the result shape type is compatible with the expected.
   const TopAbs_ShapeEnum aShType = aShape.ShapeType();
 
-  if (anExpectedType != TopAbs_SHAPE && anExpectedType != aShType) {
-    if (aShType == TopAbs_COMPOUND) {
-      // The result is compound. Check its sub-shapes.
-      TopoDS_Iterator anIter(aShape);
-
-      if (!anIter.More()) {
-        // The result is an empty compound.
-        Standard_ConstructionError::Raise("Result type check failed");
-      }
-
-      for (; anIter.More(); anIter.Next()) {
-        const TopAbs_ShapeEnum aSubType = anIter.Value().ShapeType();
-
-        if (anExpectedType != aSubType) {
-          // There is an incompatible type.
-          Standard_ConstructionError::Raise("Result type check failed");
-        }
-      }
-    } else {
-      // There is an incompatible type.
+  if (!anExpectedType.empty()) {
+    bool ok = false;
+    std::list<TopAbs_ShapeEnum>::const_iterator it;
+    for (it = anExpectedType.begin(); it != anExpectedType.end() && !ok; ++it)
+      ok = (*it == TopAbs_SHAPE || *it == aShType);
+    if (!ok)
       Standard_ConstructionError::Raise("Result type check failed");
-    }
   }
-#endif
 
   aFunction->SetValue(aShape);
 
@@ -753,6 +793,7 @@ TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
     TColStd_SequenceOfReal TolSeq;
     GeomAbs_CurveType CurType;
     TopoDS_Vertex FirstVertex, LastVertex;
+    Standard_Real aPntShiftDist = 0.;
 
     BRepTools_WireExplorer wexp(theWire) ;
     for (; wexp.More(); wexp.Next())
@@ -830,6 +871,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;
@@ -849,6 +902,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;
@@ -860,6 +915,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;
@@ -885,6 +952,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;
@@ -896,6 +965,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)
@@ -924,6 +1005,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;
@@ -948,6 +1041,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;
@@ -977,14 +1082,15 @@ 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));
 
     FirstVertex.Orientation(TopAbs_FORWARD);
     LastVertex.Orientation(TopAbs_REVERSED);
@@ -1236,6 +1342,150 @@ TopoDS_Shape GEOMImpl_ShapeDriver::MakeIsoline
   return aResult;
 }
 
+//=============================================================================
+/*!
+ * \brief Returns an extended edge.
+ */
+//=============================================================================
+
+TopoDS_Shape GEOMImpl_ShapeDriver::ExtendEdge
+                         (const TopoDS_Edge   &theEdge,
+                          const Standard_Real  theMin,
+                          const Standard_Real  theMax) const
+{
+  TopoDS_Shape        aResult;
+  Standard_Real       aF;
+  Standard_Real       aL;
+  Handle(Geom_Curve)  aCurve   = BRep_Tool::Curve(theEdge, aF, aL);
+  const Standard_Real aTol     = BRep_Tool::Tolerance(theEdge);
+  Standard_Real       aRange2d = aL - aF;
+
+  if (aCurve.IsNull() == Standard_False && aRange2d > aTol) {
+    Standard_Real aMin = aF + aRange2d*theMin;
+    Standard_Real aMax = aF + aRange2d*theMax;
+
+    Handle(Standard_Type) aType = aCurve->DynamicType();
+
+    // Get the curve of original type
+    while (aType == STANDARD_TYPE(Geom_TrimmedCurve)) {
+      Handle(Geom_TrimmedCurve) aTrCurve =
+        Handle(Geom_TrimmedCurve)::DownCast(aCurve);
+
+      aCurve = aTrCurve->BasisCurve();
+      aType  = aCurve->DynamicType();
+    }
+
+    if (aCurve->IsPeriodic()) {
+      // The curve is periodic. Check if a new range is less then a period.
+      if (aMax - aMin > aCurve->Period()) {
+        aMax = aMin + aCurve->Period();
+      }
+    } else {
+      // The curve is not periodic. Check if aMin and aMax within bounds.
+      aMin = Max(aMin, aCurve->FirstParameter());
+      aMax = Min(aMax, aCurve->LastParameter());
+    }
+
+    if (aMax - aMin > aTol) {
+      // Create a new edge.
+      BRepBuilderAPI_MakeEdge aME (aCurve, aMin, aMax);
+
+      if (aME.IsDone()) {
+        aResult = aME.Shape();
+      }
+    }
+  }
+
+  return aResult;
+}
+
+//=============================================================================
+/*!
+ * \brief Returns an extended face.
+ */
+//=============================================================================
+
+TopoDS_Shape GEOMImpl_ShapeDriver::ExtendFace
+                         (const TopoDS_Face   &theFace,
+                          const Standard_Real  theUMin,
+                          const Standard_Real  theUMax,
+                          const Standard_Real  theVMin,
+                          const Standard_Real  theVMax) const
+{
+  TopoDS_Shape         aResult;
+  Handle(Geom_Surface) aSurface = BRep_Tool::Surface(theFace);
+  const Standard_Real  aTol     = BRep_Tool::Tolerance(theFace);
+  Standard_Real        aU1;
+  Standard_Real        aU2;
+  Standard_Real        aV1;
+  Standard_Real        aV2;
+
+  // Get U, V bounds of the face.
+  ShapeAnalysis::GetFaceUVBounds(theFace, aU1, aU2, aV1, aV2);
+
+  const Standard_Real aURange = aU2 - aU1;
+  const Standard_Real aVRange = aV2 - aV1;
+
+  if (aSurface.IsNull() == Standard_False &&
+      aURange > aTol && aURange > aTol) {
+    Handle(Standard_Type) aType = aSurface->DynamicType();
+
+    // Get the surface of original type
+    while (aType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
+      Handle(Geom_RectangularTrimmedSurface) aTrSurface =
+        Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
+
+      aSurface = aTrSurface->BasisSurface();
+      aType    = aSurface->DynamicType();
+    }
+
+    Standard_Real aUMin = aU1 + aURange*theUMin;
+    Standard_Real aUMax = aU1 + aURange*theUMax;
+    Standard_Real aVMin = aV1 + aVRange*theVMin;
+    Standard_Real aVMax = aV1 + aVRange*theVMax;
+
+    aSurface->Bounds(aU1, aU2, aV1, aV2);
+
+    if (aSurface->IsUPeriodic()) {
+      // The surface is U-periodic. Check if a new U range is less
+      // then a period.
+      if (aUMax - aUMin > aSurface->UPeriod()) {
+        aUMax = aUMin + aSurface->UPeriod();
+      }
+    } else {
+      // The surface is not V-periodic. Check if aUMin and aUMax
+      // within bounds.
+      aUMin = Max(aUMin, aU1);
+      aUMax = Min(aUMax, aU2);
+    }
+
+    if (aSurface->IsVPeriodic()) {
+      // The surface is V-periodic. Check if a new V range is less
+      // then a period.
+      if (aVMax - aVMin > aSurface->VPeriod()) {
+        aVMax = aVMin + aSurface->VPeriod();
+      }
+    } else {
+      // The surface is not V-periodic. Check if aVMin and aVMax
+      // within bounds.
+      aVMin = Max(aVMin, aV1);
+      aVMax = Min(aVMax, aV2);
+    }
+
+    if (aUMax - aUMin > aTol && aVMax - aVMin > aTol) {
+      // Create a new edge.
+      BRepBuilderAPI_MakeFace aMF
+        (aSurface, aUMin, aUMax, aVMin, aVMax, aTol);
+    
+      if (aMF.IsDone()) {
+        aResult = aMF.Shape();
+      }
+    }
+  }
+
+  return aResult;
+}
+
 //================================================================================
 /*!
  * \brief Returns a name of creation operation and names and values of creation parameters
@@ -1268,15 +1518,38 @@ GetCreationInformation(std::string&             theOperationName,
     AddParam( theParams, "Wires/edges", aCI.GetShapes() );
     AddParam( theParams, "Is planar wanted", aCI.GetIsPlanar() );
     break;
+  case FACE_FROM_SURFACE:
+  {
+    theOperationName = "FACE";
+
+    Handle(TColStd_HSequenceOfTransient) shapes = aCI.GetShapes();
+
+    if (shapes.IsNull() == Standard_False) {
+      Standard_Integer aNbShapes = shapes->Length();
+
+      if (aNbShapes > 0) {
+        AddParam(theParams, "Face", shapes->Value(1));
+
+        if (aNbShapes > 1) {
+          AddParam(theParams, "Wire", shapes->Value(2));
+        }
+      }
+    }
+    break;
+  }
   case SHELL_FACES:
     theOperationName = "SHELL";
     AddParam( theParams, "Objects", aCI.GetShapes() );
     break;
-  case SOLID_SHELL:
   case SOLID_SHELLS:
     theOperationName = "SOLID";
     AddParam( theParams, "Objects", aCI.GetShapes() );
     break;
+  case SOLID_FACES:
+    theOperationName = "SOLID_FROM_FACES";
+    AddParam( theParams, "Objects", aCI.GetShapes() );
+    AddParam( theParams, "Is intersect", aCI.GetIsIntersect() );
+    break;
   case COMPOUND_SHAPES:
     theOperationName = "COMPOUND";
     AddParam( theParams, "Objects", aCI.GetShapes() );
@@ -1318,6 +1591,36 @@ GetCreationInformation(std::string&             theOperationName,
     AddParam(theParams, "Parameter", aII.GetParameter());
     break;
   }
+  case EDGE_UV:
+  {
+    GEOMImpl_IShapeExtend aSE (function);
+
+    theOperationName = "EDGE_EXTEND";
+    AddParam(theParams, "Edge", aSE.GetShape());
+    AddParam(theParams, "Min", aSE.GetUMin());
+    AddParam(theParams, "Max", aSE.GetUMax());
+    break;
+  }
+  case FACE_UV:
+  {
+    GEOMImpl_IShapeExtend aSE (function);
+
+    theOperationName = "FACE_EXTEND";
+    AddParam(theParams, "Face", aSE.GetShape());
+    AddParam(theParams, "UMin", aSE.GetUMin());
+    AddParam(theParams, "UMax", aSE.GetUMax());
+    AddParam(theParams, "VMin", aSE.GetVMin());
+    AddParam(theParams, "VMax", aSE.GetVMax());
+    break;
+  }
+  case SURFACE_FROM_FACE:
+  {
+    GEOMImpl_IShapeExtend aSE (function);
+
+    theOperationName = "SURFACE_FROM_FACE";
+    AddParam(theParams, "Face", aSE.GetShape());
+    break;
+  }
   default:
     return false;
   }