From f7e8fe1d882bba26b1b022db9b9eb900495b29ad Mon Sep 17 00:00:00 2001
From: abk <abk@opencascade.com>
Date: Thu, 28 Feb 2013 12:04:18 +0400
Subject: [PATCH] Tolerance post Build (Perform) fix was changed for: -
 BRepBuilderAPI_Sewing, - BRepFeat_MakePrism, - BRepFilletAPI_MakeChamfer, -
 BRepFilletAPI_MakeFillet, - BRepOffsetAPI_MakePipe, -
 BRepOffsetAPI_MakePipeShell so that input shapes remain unchanged by the fix.

Tolerance post Build (Perform) fix was slightly changed for:
- BRepOffsetAPI_NormalProjection,
- ShapeFix_Shape,
- ShapeUpgrade_ShapeDivide.

Correction of tolerances in input shapes was made for tests:
- blend buildevol F9,
-       complex B6,
-               B8,
-               D5,
-               E2,
-               E4,
-               E6,
-               E9,
- sewing tol_0_01 G3,
-                 G4.
---
 src/BRepBuilderAPI/BRepBuilderAPI_Sewing.cdl  |  5 +++
 src/BRepBuilderAPI/BRepBuilderAPI_Sewing.cxx  | 24 ++++++++++++--
 src/BRepFeat/BRepFeat_MakePrism.cdl           |  5 +++
 src/BRepFeat/BRepFeat_MakePrism.cxx           | 33 +++++++++++++++----
 .../BRepFilletAPI_MakeChamfer.cdl             |  5 +++
 .../BRepFilletAPI_MakeChamfer.cxx             | 16 +++++++--
 .../BRepFilletAPI_MakeFillet.cdl              |  5 +++
 .../BRepFilletAPI_MakeFillet.cxx              | 16 +++++++--
 src/BRepOffsetAPI/BRepOffsetAPI_MakePipe.cdl  |  6 ++++
 src/BRepOffsetAPI/BRepOffsetAPI_MakePipe.cxx  | 16 +++++++--
 .../BRepOffsetAPI_MakePipeShell.cdl           |  6 ++++
 .../BRepOffsetAPI_MakePipeShell.cxx           | 18 ++++++++--
 .../BRepOffsetAPI_NormalProjection.cxx        |  4 +--
 src/ShapeFix/ShapeFix_Shape.cxx               |  4 +--
 src/ShapeUpgrade/ShapeUpgrade_ShapeDivide.cxx |  6 ++--
 tests/blend/buildevol/F9                      |  1 +
 tests/blend/complex/B6                        |  1 +
 tests/blend/complex/B8                        |  1 +
 tests/blend/complex/D5                        |  1 +
 tests/blend/complex/E2                        |  1 +
 tests/blend/complex/E4                        |  1 +
 tests/blend/complex/E6                        |  1 +
 tests/blend/complex/E9                        |  1 +
 tests/sewing/tol_0_01/G3                      |  1 +
 tests/sewing/tol_0_01/G4                      |  1 +
 25 files changed, 155 insertions(+), 24 deletions(-)

diff --git a/src/BRepBuilderAPI/BRepBuilderAPI_Sewing.cdl b/src/BRepBuilderAPI/BRepBuilderAPI_Sewing.cdl
index b04686613e..51ee751c51 100755
--- a/src/BRepBuilderAPI/BRepBuilderAPI_Sewing.cdl
+++ b/src/BRepBuilderAPI/BRepBuilderAPI_Sewing.cdl
@@ -212,6 +212,9 @@ is
     raises NoSuchObject from Standard; -- raised if shape has not been modified
     	---Purpose: Gives a modifieded subshape
 	
+    IsProtectedFromModification(me; theS : Shape from TopoDS) returns Boolean;
+      ---Purpose: Indicates if theS is protected from modification.
+
     Dump(me);
     	---Purpose: print the informations
 
@@ -554,4 +557,6 @@ fields
 
     myReShape        : ReShape from BRepTools is protected;
     myMergedEdges    : MapOfShape from TopTools;
+
+    myProtectedFromModificationShapes : IndexedMapOfShape from TopTools;
 end Sewing;
diff --git a/src/BRepBuilderAPI/BRepBuilderAPI_Sewing.cxx b/src/BRepBuilderAPI/BRepBuilderAPI_Sewing.cxx
index b2b0212017..0cf12318ff 100755
--- a/src/BRepBuilderAPI/BRepBuilderAPI_Sewing.cxx
+++ b/src/BRepBuilderAPI/BRepBuilderAPI_Sewing.cxx
@@ -55,6 +55,7 @@
 #include <BRep_Builder.hxx>
 #include <BRep_Tool.hxx>
 #include <BRepLib.hxx>
+#include <BRepLib_ToleranceRule.hxx>
 #include <BRepTools_Quilt.hxx>
 #include <BSplCLib.hxx>
 #include <Extrema_ExtPC.hxx>
@@ -1736,7 +1737,12 @@ void BRepBuilderAPI_Sewing::Load(const TopoDS_Shape& theShape)
 {
   myReShape->Clear();
   if (theShape.IsNull()) myShape.Nullify();
-  else myShape = myReShape->Apply(theShape);
+  else
+  {
+    TopExp::MapShapes(theShape, myProtectedFromModificationShapes);
+    //
+    myShape = myReShape->Apply(theShape);
+  }
   mySewedShape.Nullify();
   // Nullify flags and counters
   myNbShapes = myNbEdges = myNbVertices = 0;
@@ -1766,6 +1772,9 @@ void BRepBuilderAPI_Sewing::Load(const TopoDS_Shape& theShape)
 void BRepBuilderAPI_Sewing::Add(const TopoDS_Shape& aShape)
 {
   if (aShape.IsNull()) return;
+  //
+  TopExp::MapShapes(aShape, myProtectedFromModificationShapes);
+  //
   TopoDS_Shape oShape = myReShape->Apply(aShape);
   myOldShapes.Add(aShape,oShape);
   myNbShapes = myOldShapes.Extent();
@@ -1909,7 +1918,8 @@ void BRepBuilderAPI_Sewing::Perform(const Handle(Message_ProgressIndicator)& the
       mySewedShape.Nullify();
       return;
     }
-    BRepLib::UpdateTolerances(mySewedShape);
+    BRepLib_ToleranceRule::SetProperTolerances(
+      mySewedShape, *this);
   }
 #if DEB
   chr_total.Stop();
@@ -2148,6 +2158,16 @@ TopoDS_Shape BRepBuilderAPI_Sewing::ModifiedSubShape(const TopoDS_Shape& aShape)
   return myReShape->Apply(aShape);
 }
 
+//=======================================================================
+//function : IsProtectedFromModification
+//purpose  :
+//=======================================================================
+Standard_Boolean BRepBuilderAPI_Sewing::IsProtectedFromModification(
+  const TopoDS_Shape & theS) const
+{
+  return myProtectedFromModificationShapes.Contains(theS);
+}
+
 //=======================================================================
 //function : Dump
 //purpose  : 
diff --git a/src/BRepFeat/BRepFeat_MakePrism.cdl b/src/BRepFeat/BRepFeat_MakePrism.cdl
index d3d3df3d06..88a341db21 100755
--- a/src/BRepFeat/BRepFeat_MakePrism.cdl
+++ b/src/BRepFeat/BRepFeat_MakePrism.cdl
@@ -168,6 +168,10 @@ is
     BarycCurve(me: in out)    
     	returns Curve from Geom;
     	---Purpose: Generates a curve along the center of mass of the primitive.
+
+    IsProtectedFromModification(me; theS : Shape from TopoDS)
+    returns Boolean from Standard;
+      ---Purpose: Indicates if theS is protected from modification.
 fields
 
     myPbase  : Shape                     from TopoDS;
@@ -176,5 +180,6 @@ fields
     myCurves : SequenceOfCurve           from TColGeom;
     myBCurve : Curve                     from Geom;
     myStatusError : StatusError          from BRepFeat;
+    myProtectedFromModificationShapes : IndexedMapOfShape from TopTools;
 
 end MakePrism;
diff --git a/src/BRepFeat/BRepFeat_MakePrism.cxx b/src/BRepFeat/BRepFeat_MakePrism.cxx
index a457764675..772f369ceb 100755
--- a/src/BRepFeat/BRepFeat_MakePrism.cxx
+++ b/src/BRepFeat/BRepFeat_MakePrism.cxx
@@ -45,7 +45,7 @@
 
 #include <BRep_Tool.hxx>
 
-#include <BRepLib.hxx>
+#include <BRepLib_ToleranceRule.hxx>
 
 #include <BRepTools.hxx>
 
@@ -141,6 +141,10 @@ void BRepFeat_MakePrism::Init(const TopoDS_Shape& Sbase,
   Standard_Boolean trc = BRepFeat_GettraceFEAT();
   if (trc) cout << "BRepFeat_MakePrism::Init" << endl;
 #endif
+  TopExp::MapShapes(Sbase,  myProtectedFromModificationShapes);
+  TopExp::MapShapes(Pbase,  myProtectedFromModificationShapes);
+  TopExp::MapShapes(Skface, myProtectedFromModificationShapes);
+  //
   mySkface = Skface;
   SketchFaceValid();
   mySbase  = Sbase;
@@ -206,6 +210,8 @@ void BRepFeat_MakePrism::Add(const TopoDS_Edge& E,
   Standard_Boolean trc = BRepFeat_GettraceFEAT();
   if (trc) cout << "BRepFeat_MakePrism::Add(Edge,face)" << endl;
 #endif
+  TopExp::MapShapes(E, myProtectedFromModificationShapes);
+  //
   TopExp_Explorer exp;
   for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
     if (exp.Current().IsSame(F)) {
@@ -366,6 +372,8 @@ void BRepFeat_MakePrism::Perform(const TopoDS_Shape& Until)
   Standard_Boolean trc = BRepFeat_GettraceFEAT();
   if (trc) cout << "BRepFeat_MakePrism::Perform(Until)" << endl;
 #endif
+  TopExp::MapShapes(Until, myProtectedFromModificationShapes);
+  //
   if (Until.IsNull()) {
     Standard_ConstructionError::Raise();
   }
@@ -465,7 +473,7 @@ void BRepFeat_MakePrism::Perform(const TopoDS_Shape& Until)
       }
     }         
   }
-  BRepLib::UpdateTolerances(myShape);
+  BRepLib_ToleranceRule::SetProperTolerances(myShape, *this);
 /*   // loop of control of descendance
 
   TopExp_Explorer expr(mySbase, TopAbs_FACE);
@@ -517,6 +525,9 @@ void BRepFeat_MakePrism::Perform(const TopoDS_Shape& From,
   Standard_Boolean trc = BRepFeat_GettraceFEAT();
   if (trc) cout << "BRepFeat_MakePrism::Perform(From,Until)" << endl;
 #endif
+  TopExp::MapShapes(From,  myProtectedFromModificationShapes);
+  TopExp::MapShapes(Until, myProtectedFromModificationShapes);
+  //
   if (From.IsNull() || Until.IsNull()) {
     Standard_ConstructionError::Raise();
   }
@@ -788,6 +799,8 @@ void BRepFeat_MakePrism::PerformFromEnd(const TopoDS_Shape& Until)
   Standard_Boolean trc = BRepFeat_GettraceFEAT();
   if (trc) cout << "BRepFeat_MakePrism::PerformFromEnd(From,Until)" << endl;
 #endif
+  TopExp::MapShapes(Until, myProtectedFromModificationShapes);
+  //
   if (Until.IsNull()) {
     Standard_ConstructionError::Raise();
   }
@@ -991,6 +1004,8 @@ void BRepFeat_MakePrism::PerformUntilHeight(const TopoDS_Shape& Until,
   Standard_Boolean trc = BRepFeat_GettraceFEAT();
   if (trc) cout << "BRepFeat_MakePrism::PerformUntilHeight(Until,Length)" << endl;
 #endif
+  TopExp::MapShapes(Until, myProtectedFromModificationShapes);
+  //
   if (Until.IsNull()) {
     Perform(Length);
   }
@@ -1435,8 +1450,12 @@ Standard_Boolean ToFuse(const TopoDS_Face& F1,
   return ValRet;
 }
 
-
-
-
-
-
+//=======================================================================
+//function : IsProtectedFromModification
+//purpose  :
+//=======================================================================
+Standard_Boolean BRepFeat_MakePrism::IsProtectedFromModification(
+  const TopoDS_Shape & theS) const
+{
+  return myProtectedFromModificationShapes.Contains(theS);
+}
diff --git a/src/BRepFilletAPI/BRepFilletAPI_MakeChamfer.cdl b/src/BRepFilletAPI/BRepFilletAPI_MakeChamfer.cdl
index 5d6dfb19ca..2c7b2dd312 100755
--- a/src/BRepFilletAPI/BRepFilletAPI_MakeChamfer.cdl
+++ b/src/BRepFilletAPI/BRepFilletAPI_MakeChamfer.cdl
@@ -379,6 +379,10 @@ is
     returns Boolean
     is redefined virtual;
 
+    IsProtectedFromModification(me; theS : Shape from TopoDS)
+    returns Boolean from Standard;
+      ---Purpose: Indicates if theS is protected from modification.
+
     -------------------------------
     ---Methods for quick simulation
     -------------------------------
@@ -396,6 +400,7 @@ fields
 
     myBuilder : ChBuilder  from ChFi3d;
     myMap     : MapOfShape from TopTools;
+    myProtectedFromModificationShapes : IndexedMapOfShape from TopTools;
     
 end MakeChamfer;
 
diff --git a/src/BRepFilletAPI/BRepFilletAPI_MakeChamfer.cxx b/src/BRepFilletAPI/BRepFilletAPI_MakeChamfer.cxx
index a6da6c6463..538f3f999c 100755
--- a/src/BRepFilletAPI/BRepFilletAPI_MakeChamfer.cxx
+++ b/src/BRepFilletAPI/BRepFilletAPI_MakeChamfer.cxx
@@ -25,7 +25,8 @@
 #include <TopTools_ListIteratorOfListOfShape.hxx>
 #include <ChFiDS_Spine.hxx>
 #include <TopExp_Explorer.hxx>
-#include <BRepLib.hxx>
+#include <BRepLib_ToleranceRule.hxx>
+#include <TopExp.hxx>
 
 
 
@@ -35,6 +36,7 @@
 //=======================================================================
 BRepFilletAPI_MakeChamfer::BRepFilletAPI_MakeChamfer(const TopoDS_Shape &S):myBuilder(S)
 {
+  TopExp::MapShapes(S, myProtectedFromModificationShapes);
 }
 
 
@@ -392,7 +394,7 @@ void BRepFilletAPI_MakeChamfer::Build()
   if (myBuilder.IsDone()){
     Done();
     myShape = myBuilder.Shape();
-    BRepLib::UpdateTolerances(myShape);
+    BRepLib_ToleranceRule::SetProperTolerances(myShape, *this);
       
       //creation of the Map.
     TopExp_Explorer ex;
@@ -472,6 +474,16 @@ Standard_Boolean BRepFilletAPI_MakeChamfer::IsDeleted(const TopoDS_Shape& F)
   return Standard_True;    
 }
 
+//=======================================================================
+//function : IsProtectedFromModification
+//purpose  :
+//=======================================================================
+Standard_Boolean BRepFilletAPI_MakeChamfer::IsProtectedFromModification(
+  const TopoDS_Shape & theS) const
+{
+  return myProtectedFromModificationShapes.Contains(theS);
+}
+
 //=======================================================================
 //function : Simulate
 //purpose  : 
diff --git a/src/BRepFilletAPI/BRepFilletAPI_MakeFillet.cdl b/src/BRepFilletAPI/BRepFilletAPI_MakeFillet.cdl
index 07a6e88296..45b7494ad3 100755
--- a/src/BRepFilletAPI/BRepFilletAPI_MakeFillet.cdl
+++ b/src/BRepFilletAPI/BRepFilletAPI_MakeFillet.cdl
@@ -450,6 +450,10 @@ is
     returns Boolean
     is redefined virtual;
 
+    IsProtectedFromModification(me; theS : Shape from TopoDS)
+    returns Boolean from Standard;
+      ---Purpose: Indicates if theS is protected from modification.
+
     -------------------------------------------
     -- Methods usefull for BRepCtx utilities --
     -------------------------------------------
@@ -538,5 +542,6 @@ fields
 
     myBuilder : FilBuilder from ChFi3d;
     myMap     : MapOfShape from TopTools;
+    myProtectedFromModificationShapes : IndexedMapOfShape from TopTools;
 
 end MakeFillet;
diff --git a/src/BRepFilletAPI/BRepFilletAPI_MakeFillet.cxx b/src/BRepFilletAPI/BRepFilletAPI_MakeFillet.cxx
index b8ccc2f031..fa35932330 100755
--- a/src/BRepFilletAPI/BRepFilletAPI_MakeFillet.cxx
+++ b/src/BRepFilletAPI/BRepFilletAPI_MakeFillet.cxx
@@ -30,7 +30,8 @@
 #include <Law_Linear.hxx>
 #include <Law_S.hxx>
 #include <Law_Interpol.hxx>
-#include <BRepLib.hxx>
+#include <BRepLib_ToleranceRule.hxx>
+#include <TopExp.hxx>
 
 //=======================================================================
 //function : BRepFilletAPI_MakeFillet
@@ -41,6 +42,7 @@ BRepFilletAPI_MakeFillet::BRepFilletAPI_MakeFillet(const TopoDS_Shape& S,
 				       const ChFi3d_FilletShape FShape):
    myBuilder(S,FShape)
 {
+  TopExp::MapShapes(S, myProtectedFromModificationShapes);
 }
 
 //=======================================================================
@@ -533,7 +535,7 @@ void BRepFilletAPI_MakeFillet::Build()
   if(myBuilder.IsDone()) {
     Done();
     myShape = myBuilder.Shape();
-    BRepLib::UpdateTolerances(myShape);
+    BRepLib_ToleranceRule::SetProperTolerances(myShape, *this);
 
     // creation of the Map.
     TopExp_Explorer ex;
@@ -667,6 +669,16 @@ Standard_Boolean BRepFilletAPI_MakeFillet::IsDeleted(const TopoDS_Shape& F)
   return Standard_True;    
 }
 
+//=======================================================================
+//function : IsProtectedFromModification
+//purpose  :
+//=======================================================================
+Standard_Boolean BRepFilletAPI_MakeFillet::IsProtectedFromModification(
+  const TopoDS_Shape & theS) const
+{
+  return myProtectedFromModificationShapes.Contains(theS);
+}
+
 //=======================================================================
 //function : NbFaultyContours
 //purpose  : 
diff --git a/src/BRepOffsetAPI/BRepOffsetAPI_MakePipe.cdl b/src/BRepOffsetAPI/BRepOffsetAPI_MakePipe.cdl
index 1d1b6032cd..ce7f11cb93 100755
--- a/src/BRepOffsetAPI/BRepOffsetAPI_MakePipe.cdl
+++ b/src/BRepOffsetAPI/BRepOffsetAPI_MakePipe.cdl
@@ -86,8 +86,14 @@ is
     returns Shape from TopoDS;
 
 
+    IsProtectedFromModification(me; theS : Shape from TopoDS)
+      ---Purpose: Indicates if theS is protected from modification.
+    returns Boolean from Standard;
+
 fields
 
     myPipe : Pipe from BRepFill;
 
+    myProtectedFromModificationShapes : IndexedMapOfShape from TopTools;
+
 end MakePipe; 
diff --git a/src/BRepOffsetAPI/BRepOffsetAPI_MakePipe.cxx b/src/BRepOffsetAPI/BRepOffsetAPI_MakePipe.cxx
index 8b06baa3d7..d6ce5a7f59 100755
--- a/src/BRepOffsetAPI/BRepOffsetAPI_MakePipe.cxx
+++ b/src/BRepOffsetAPI/BRepOffsetAPI_MakePipe.cxx
@@ -21,13 +21,14 @@
 
 #include <BRepOffsetAPI_MakePipe.ixx>
 
-#include <BRepLib.hxx>
+#include <BRepLib_ToleranceRule.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS_Face.hxx>
 #include <TopoDS_Edge.hxx>
 #include <TopoDS_Vertex.hxx>
 #include <TopoDS.hxx>
 #include <TopAbs_ShapeEnum.hxx>
+#include <TopExp.hxx>
 
 //=======================================================================
 //function : BRepOffsetAPI_MakePipe
@@ -38,6 +39,8 @@ BRepOffsetAPI_MakePipe::BRepOffsetAPI_MakePipe(const TopoDS_Wire&  Spine ,
 				   const TopoDS_Shape& Profile)
      : myPipe(Spine, Profile)
 {
+  TopExp::MapShapes(Profile, myProtectedFromModificationShapes);
+  //
   Build();
 }
 
@@ -60,7 +63,7 @@ const BRepFill_Pipe& BRepOffsetAPI_MakePipe::Pipe() const
 void BRepOffsetAPI_MakePipe::Build() 
 {
   myShape = myPipe.Shape();
-  BRepLib::UpdateTolerances(myShape);
+  BRepLib_ToleranceRule::SetProperTolerances(myShape, *this);
   Done();
 }
 
@@ -107,3 +110,12 @@ TopoDS_Shape BRepOffsetAPI_MakePipe::Generated (const TopoDS_Shape& SSpine,
   return bid;
 }
 
+//=======================================================================
+//function : IsProtectedFromModification
+//purpose  :
+//=======================================================================
+Standard_Boolean BRepOffsetAPI_MakePipe::IsProtectedFromModification(
+  const TopoDS_Shape & theS) const
+{
+  return myProtectedFromModificationShapes.Contains(theS);
+}
diff --git a/src/BRepOffsetAPI/BRepOffsetAPI_MakePipeShell.cdl b/src/BRepOffsetAPI/BRepOffsetAPI_MakePipeShell.cdl
index 1141a12fac..682e5e108f 100755
--- a/src/BRepOffsetAPI/BRepOffsetAPI_MakePipeShell.cdl
+++ b/src/BRepOffsetAPI/BRepOffsetAPI_MakePipeShell.cdl
@@ -320,9 +320,15 @@ is
     returns ListOfShape from TopTools
     is redefined; 
      
+    IsProtectedFromModification(me; theS : Shape)
+      ---Purpose: Indicates if theS is protected from modification.
+    returns Boolean;
+
 fields 
   myPipe  :  PipeShell  from  BRepFill;
 
+  myProtectedFromModificationShapes : IndexedMapOfShape from TopTools;
+
 end MakePipeShell;
 
 
diff --git a/src/BRepOffsetAPI/BRepOffsetAPI_MakePipeShell.cxx b/src/BRepOffsetAPI/BRepOffsetAPI_MakePipeShell.cxx
index de3fb85005..b0ece92965 100755
--- a/src/BRepOffsetAPI/BRepOffsetAPI_MakePipeShell.cxx
+++ b/src/BRepOffsetAPI/BRepOffsetAPI_MakePipeShell.cxx
@@ -22,10 +22,11 @@
 
 #include <BRepOffsetAPI_MakePipeShell.ixx>
 
-#include <BRepLib.hxx>
+#include <BRepLib_ToleranceRule.hxx>
 #include <GeomFill_PipeError.hxx>
 #include <Standard_NotImplemented.hxx>
 #include <StdFail_NotDone.hxx>
+#include <TopExp.hxx>
 
 //=======================================================================
 //function :
@@ -96,6 +97,7 @@ BRepOffsetAPI_MakePipeShell::BRepOffsetAPI_MakePipeShell(const TopoDS_Wire& Spin
 				       const Standard_Boolean WithContact,
 				       const Standard_Boolean WithCorrection) 
 {
+  TopExp::MapShapes(Profile, myProtectedFromModificationShapes);
   myPipe->Add(Profile, WithContact, WithCorrection);
 }
 
@@ -108,6 +110,7 @@ BRepOffsetAPI_MakePipeShell::BRepOffsetAPI_MakePipeShell(const TopoDS_Wire& Spin
 				       const Standard_Boolean WithContact,
 				       const Standard_Boolean WithCorrection) 
 {
+  TopExp::MapShapes(Profile, myProtectedFromModificationShapes);
   myPipe->Add(Profile, Location, WithContact, WithCorrection);
 }
 
@@ -120,6 +123,7 @@ BRepOffsetAPI_MakePipeShell::BRepOffsetAPI_MakePipeShell(const TopoDS_Wire& Spin
 					  const Standard_Boolean WithContact,
 					  const Standard_Boolean WithCorrection) 
 {
+  TopExp::MapShapes(Profile, myProtectedFromModificationShapes);
   myPipe->SetLaw(Profile, L, WithContact, WithCorrection);
 }
 
@@ -133,6 +137,7 @@ BRepOffsetAPI_MakePipeShell::BRepOffsetAPI_MakePipeShell(const TopoDS_Wire& Spin
 					  const Standard_Boolean WithContact,
 					  const Standard_Boolean WithCorrection) 
 {
+  TopExp::MapShapes(Profile, myProtectedFromModificationShapes);
   myPipe->SetLaw(Profile, L, Location, WithContact, WithCorrection);
 }
 
@@ -226,7 +231,7 @@ void BRepOffsetAPI_MakePipeShell::Delete( const TopoDS_Shape& Profile)
   Ok = myPipe->Build();
   if (Ok) {
     myShape = myPipe->Shape();
-    BRepLib::UpdateTolerances(myShape);
+    BRepLib_ToleranceRule::SetProperTolerances(myShape, *this);
     Done();
   }
   else NotDone(); 
@@ -274,3 +279,12 @@ BRepOffsetAPI_MakePipeShell::Generated(const TopoDS_Shape& S)
   return myGenerated;
 }
 
+//=======================================================================
+//function : IsProtectedFromModification
+//purpose  :
+//=======================================================================
+Standard_Boolean BRepOffsetAPI_MakePipeShell::IsProtectedFromModification(
+  const TopoDS_Shape & theS) const
+{
+  return myProtectedFromModificationShapes.Contains(theS);
+}
diff --git a/src/BRepOffsetAPI/BRepOffsetAPI_NormalProjection.cxx b/src/BRepOffsetAPI/BRepOffsetAPI_NormalProjection.cxx
index e8e9749b93..f2aacb4548 100755
--- a/src/BRepOffsetAPI/BRepOffsetAPI_NormalProjection.cxx
+++ b/src/BRepOffsetAPI/BRepOffsetAPI_NormalProjection.cxx
@@ -20,7 +20,7 @@
 
 
 #include <BRepOffsetAPI_NormalProjection.ixx>
-#include <BRepLib.hxx>
+#include <BRepLib_ToleranceRule.hxx>
 
 BRepOffsetAPI_NormalProjection::BRepOffsetAPI_NormalProjection()
 {
@@ -65,7 +65,7 @@ BRepOffsetAPI_NormalProjection::BRepOffsetAPI_NormalProjection()
 {
   myNormalProjector.Build();
   myShape = myNormalProjector.Projection();
-  BRepLib::UpdateTolerances(myShape);
+  BRepLib_ToleranceRule::SetProperTolerances(myShape);
   Done();
 }
 
diff --git a/src/ShapeFix/ShapeFix_Shape.cxx b/src/ShapeFix/ShapeFix_Shape.cxx
index fbe2d5ec01..66fbfa55ee 100755
--- a/src/ShapeFix/ShapeFix_Shape.cxx
+++ b/src/ShapeFix/ShapeFix_Shape.cxx
@@ -33,7 +33,7 @@
 #include <TopAbs_ShapeEnum.hxx>
 #include <BRepTools.hxx>
 #include <BRep_Builder.hxx>
-#include <BRepLib.hxx>
+#include <BRepLib_ToleranceRule.hxx>
 
 #include <ShapeFix.hxx>
 #include <ShapeBuild_ReShape.hxx>
@@ -103,7 +103,7 @@ void ShapeFix_Shape::Init(const TopoDS_Shape& shape)
 Standard_Boolean ShapeFix_Shape::Perform(const Handle(Message_ProgressIndicator)& theProgress)
 {
   Standard_Boolean aR = PerformR(theProgress);
-  BRepLib::UpdateTolerances(myResult);
+  BRepLib_ToleranceRule::SetProperTolerances(myResult);
   return aR;
 }
 
diff --git a/src/ShapeUpgrade/ShapeUpgrade_ShapeDivide.cxx b/src/ShapeUpgrade/ShapeUpgrade_ShapeDivide.cxx
index 254e0c3572..8962386d27 100755
--- a/src/ShapeUpgrade/ShapeUpgrade_ShapeDivide.cxx
+++ b/src/ShapeUpgrade/ShapeUpgrade_ShapeDivide.cxx
@@ -37,7 +37,7 @@
 #include <ShapeUpgrade_WireDivide.hxx>
 #include <Standard_ErrorHandler.hxx>
 #include <Standard_Failure.hxx>
-#include <BRepLib.hxx>
+#include <BRepLib_ToleranceRule.hxx>
 
 //=======================================================================
 //function : ShapeUpgrade_ShapeDivide
@@ -175,7 +175,7 @@ Standard_Boolean ShapeUpgrade_ShapeDivide::Perform(const Standard_Boolean newCon
     if ( Status ( ShapeExtend_DONE ) ) {
       myResult = myContext->Apply ( C, TopAbs_SHAPE );
       myContext->Replace ( myShape, myResult );
-      BRepLib::UpdateTolerances(myResult);
+      BRepLib_ToleranceRule::SetProperTolerances(myResult);
       return Standard_True;
     }
     myResult = myShape;
@@ -284,7 +284,7 @@ Standard_Boolean ShapeUpgrade_ShapeDivide::Perform(const Standard_Boolean newCon
     }
   }
   myResult = myContext->Apply ( myShape, TopAbs_SHAPE );
-  BRepLib::UpdateTolerances(myResult);
+  BRepLib_ToleranceRule::SetProperTolerances(myResult);
   return ! myResult.IsSame ( myShape );
 }
 
diff --git a/tests/blend/buildevol/F9 b/tests/blend/buildevol/F9
index cd89940ac6..a1aff6f872 100644
--- a/tests/blend/buildevol/F9
+++ b/tests/blend/buildevol/F9
@@ -1,4 +1,5 @@
 restore [locate_data_file CFI_2_o12ffq.rle] s
+updatetolerance s
 explode s e
 
 mkevol result s
diff --git a/tests/blend/complex/B6 b/tests/blend/complex/B6
index 75136c155f..48f529f4b6 100644
--- a/tests/blend/complex/B6
+++ b/tests/blend/complex/B6
@@ -5,6 +5,7 @@
 ## ====================================
 
 restore [locate_data_file CTO900_pro12880c.rle] a
+updatetolerance a
 explode a e
 blend result a 5 a_89
 
diff --git a/tests/blend/complex/B8 b/tests/blend/complex/B8
index e48cc1a8ee..9a21178747 100644
--- a/tests/blend/complex/B8
+++ b/tests/blend/complex/B8
@@ -5,6 +5,7 @@
 ## ====================================
 
 restore [locate_data_file CFI_pro12894.rle] a
+updatetolerance a
 explode a e
 blend result a 5 a_89
 
diff --git a/tests/blend/complex/D5 b/tests/blend/complex/D5
index f841944e12..f900b75fff 100644
--- a/tests/blend/complex/D5
+++ b/tests/blend/complex/D5
@@ -5,6 +5,7 @@
 ## ====================================
 
 restore [locate_data_file CFI_ger60206.rle] a
+updatetolerance a
 explode a e
 mkevol result a
 updatevol a_21 0 0.5 1 1
diff --git a/tests/blend/complex/E2 b/tests/blend/complex/E2
index ed3742eb35..38cf1dec7d 100644
--- a/tests/blend/complex/E2
+++ b/tests/blend/complex/E2
@@ -5,6 +5,7 @@
 ## ====================================
 
 restore [locate_data_file CFI_pro8792.rle] a
+updatetolerance a
 explode a e
 mkevol result a
 updatevol a_20 0 15 0.5 20 1 5
diff --git a/tests/blend/complex/E4 b/tests/blend/complex/E4
index 099e2e281a..0ef6d74dfb 100644
--- a/tests/blend/complex/E4
+++ b/tests/blend/complex/E4
@@ -5,6 +5,7 @@
 ## ====================================
 
 restore [locate_data_file CFI_pro10631.rle] a
+updatetolerance a
 explode a e
 blend result a 5 a_45
 
diff --git a/tests/blend/complex/E6 b/tests/blend/complex/E6
index 15f8fc27c4..b25c4f1f62 100644
--- a/tests/blend/complex/E6
+++ b/tests/blend/complex/E6
@@ -5,6 +5,7 @@
 ## ====================================
 
 restore [locate_data_file CFI_pro10522.rle] a
+updatetolerance a
 explode a e
 blend result a 2 a_82
 
diff --git a/tests/blend/complex/E9 b/tests/blend/complex/E9
index 019310ec01..d9f1be77cd 100644
--- a/tests/blend/complex/E9
+++ b/tests/blend/complex/E9
@@ -5,6 +5,7 @@
 ## ====================================
 
 restore [locate_data_file CFI_pro10117.rle] a
+updatetolerance a
 explode a e
 blend result a 2 a_128 1 a_10
 
diff --git a/tests/sewing/tol_0_01/G3 b/tests/sewing/tol_0_01/G3
index 61e280f899..e0abbaee84 100644
--- a/tests/sewing/tol_0_01/G3
+++ b/tests/sewing/tol_0_01/G3
@@ -1 +1,2 @@
 restore [locate_data_file CCH_propag.rle] a
+updatetolerance a
diff --git a/tests/sewing/tol_0_01/G4 b/tests/sewing/tol_0_01/G4
index 22a7f0a317..6aebc42c3f 100644
--- a/tests/sewing/tol_0_01/G4
+++ b/tests/sewing/tol_0_01/G4
@@ -1 +1,2 @@
 restore [locate_data_file CCH_r2.rle] a
+updatetolerance a