]> OCCT Git - occt-copy.git/commitdiff
Static public method EnsureToleranceRule(const TopoDS_Shape & theS) was
authorabk <abk@opencascade.com>
Tue, 25 Dec 2012 09:15:00 +0000 (13:15 +0400)
committerabk <abk@opencascade.com>
Wed, 13 Feb 2013 13:25:20 +0000 (17:25 +0400)
created in class BRepBuilderAPI_MakeShape to fix all tolerances of the
shape and it's subshapes by the tolerance rule:
vertex tolerance >= edge tolerance >= face tolerance.
Edge or vertex tolerance which does not satisfy the tolerance rule will be
increased.
Draw command EnsureTolRule was created to test new functional.
Tolerance post Build (Perform) fix was made for:
- BRepBuilderAPI_Sewing,
- BRepFilletAPI_MakeChamfer,
- BRepFilletAPI_MakeFillet,
- BRepOffsetAPI_MakePipe,
- BRepOffsetAPI_NormalProjection,
- ShapeFix_Shape,
- ShapeUpgrade_ShapeDivide.

src/BRepBuilderAPI/BRepBuilderAPI_MakeShape.cdl
src/BRepBuilderAPI/BRepBuilderAPI_MakeShape.cxx
src/BRepBuilderAPI/BRepBuilderAPI_Sewing.cxx
src/BRepFilletAPI/BRepFilletAPI_MakeChamfer.cxx
src/BRepFilletAPI/BRepFilletAPI_MakeFillet.cxx
src/BRepOffsetAPI/BRepOffsetAPI_MakePipe.cxx
src/BRepOffsetAPI/BRepOffsetAPI_NormalProjection.cxx
src/BRepTest/BRepTest_BasicCommands.cxx
src/ShapeFix/ShapeFix_Shape.cdl
src/ShapeFix/ShapeFix_Shape.cxx
src/ShapeUpgrade/ShapeUpgrade_ShapeDivide.cxx

index f68da8030449d266505912791faed45e28440061..9a31f831d09f76023a05ee11a74c31e2d0cdfd50 100755 (executable)
@@ -92,6 +92,11 @@ is
     is virtual;
        ---Purpose: Returns true if the shape S has been deleted.
 
+    EnsureToleranceRule (myclass; theS : Shape from TopoDS);
+    ---Purpose: Fixes all tolerances of shape theS and it's subshapes by the tolerance
+    -- rule: vertex tolerance >= edge tolerance >= face tolerance.
+    -- Edge or vertex tolerance which does not satisfy the tolerance rule will
+    -- be increased.
     
 fields
  
index 8821a6aed14def8a649e1d9e31c7e4edcedd74e1..8c8cfe85c8222d81c4c1ab240c7dc671458600e6 100755 (executable)
 
 
 #include <BRepBuilderAPI_MakeShape.ixx>
+#include <BRep_TEdge.hxx>
+#include <BRep_TFace.hxx>
+#include <BRep_TVertex.hxx>
+#include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Face.hxx>
@@ -116,4 +120,63 @@ Standard_Boolean BRepBuilderAPI_MakeShape::IsDeleted (const TopoDS_Shape& S)
 
 
 
+//=======================================================================
+//function : EnsureToleranceRule
+//purpose  : 
+//=======================================================================
+
+void BRepBuilderAPI_MakeShape::EnsureToleranceRule(const TopoDS_Shape & theS)
+{
+  if (theS.IsNull())
+  {
+    return;
+  }
+  //
+  for (TopExp_Explorer aFE(theS, TopAbs_FACE); aFE.More(); aFE.Next())
+  {
+    TopoDS_Face aF = TopoDS::Face(aFE.Current());
+    Standard_Real aFT = (*((Handle_BRep_TFace *)&aF.TShape()))->Tolerance();
+    //
+    for (TopExp_Explorer anEE(aF, TopAbs_EDGE); anEE.More(); anEE.Next())
+    {
+      TopoDS_Edge anES = TopoDS::Edge(anEE.Current());
+      Handle_BRep_TEdge & anEG = *(Handle_BRep_TEdge *)&anES.TShape();
+      Standard_Real anET = anEG->Tolerance();
+      if (anET < aFT)
+      {
+        anET = aFT;
+        anEG->Tolerance(anET);
+      }
+      for (TopExp_Explorer aVE(anES, TopAbs_VERTEX); aVE.More(); aVE.Next())
+      {
+        TopoDS_Vertex aVS = TopoDS::Vertex(aVE.Current());
+        Handle_BRep_TVertex & aVG = *(Handle_BRep_TVertex *)&aVS.TShape();
+        aVG->UpdateTolerance(anET);
+      }
+    }
+    //
+    for (TopExp_Explorer aVE(aF, TopAbs_VERTEX, TopAbs_EDGE);
+      aVE.More(); aVE.Next())
+    {
+      TopoDS_Vertex aVS = TopoDS::Vertex(aVE.Current());
+      Handle_BRep_TVertex & aVG = *(Handle_BRep_TVertex *)&aVS.TShape();
+      aVG->UpdateTolerance(aFT);
+    }
+  }
+  //
+  for (TopExp_Explorer anEE(theS, TopAbs_EDGE, TopAbs_FACE);
+    anEE.More(); anEE.Next())
+  {
+    TopoDS_Edge anES = TopoDS::Edge(anEE.Current());
+    Handle_BRep_TEdge & anEG = *(Handle_BRep_TEdge *)&anES.TShape();
+    Standard_Real anET = anEG->Tolerance();
+    for (TopExp_Explorer aVE(anES, TopAbs_VERTEX); aVE.More(); aVE.Next())
+    {
+      TopoDS_Vertex aVS = TopoDS::Vertex(aVE.Current());
+      Handle_BRep_TVertex & aVG = *(Handle_BRep_TVertex *)&aVS.TShape();
+      aVG->UpdateTolerance(anET);
+    }
+  }
+}
+
 
index 2834271f7d688ca7660dbfacb8b755137e344be5..2e6b2de6322d8cb211cb2d8a1b4d3c489f1934e8 100755 (executable)
 #include <BRepBuilderAPI_VertexInspector.hxx>
 #include <BRepBuilderAPI_CellFilter.hxx>
 #include <BRepBuilderAPI_BndBoxTreeSelector.hxx>
+#include <BRepBuilderAPI_MakeShape.hxx>
 #include <NCollection_UBTreeFiller.hxx>
 
 static void SortBox (const Handle(Bnd_HArray1OfBox) hSetBoxes,
@@ -1909,6 +1910,7 @@ void BRepBuilderAPI_Sewing::Perform(const Handle(Message_ProgressIndicator)& the
       mySewedShape.Nullify();
       return;
     }
+    BRepBuilderAPI_MakeShape::EnsureToleranceRule(mySewedShape);
   }
 #if DEB
   chr_total.Stop();
index 5b016e697475776f5c368663d833e139a264b434..3ec82c9a1b134faae58f4a959f9233e15dd9f671 100755 (executable)
@@ -391,6 +391,7 @@ void BRepFilletAPI_MakeChamfer::Build()
   if (myBuilder.IsDone()){
     Done();
     myShape = myBuilder.Shape();
+    EnsureToleranceRule(myShape);
       
       //creation of the Map.
     TopExp_Explorer ex;
index 29f0b00b28aa753c71e1213318826ac1f76114eb..5c7c465e189a9a35a3cf9ac80ea72ff9f902ab4a 100755 (executable)
@@ -532,6 +532,7 @@ void BRepFilletAPI_MakeFillet::Build()
   if(myBuilder.IsDone()) {
     Done();
     myShape = myBuilder.Shape();
+    EnsureToleranceRule(myShape);
 
     // creation of the Map.
     TopExp_Explorer ex;
index f98ffe37fbdba693fe0d1e9dbe22706daaf4564c..9c1f484cbb2d5c909b7fd682c16b3aa175630b0b 100755 (executable)
@@ -59,6 +59,7 @@ const BRepFill_Pipe& BRepOffsetAPI_MakePipe::Pipe() const
 void BRepOffsetAPI_MakePipe::Build() 
 {
   myShape = myPipe.Shape();
+  BRepBuilderAPI_MakeShape::EnsureToleranceRule(myShape);
   Done();
 }
 
index 203f29b82fe064a166f86594d6e59330c2fce240..80771ecc064fd30b609db9672dc295c8b3b84ab9 100755 (executable)
@@ -64,6 +64,7 @@ BRepOffsetAPI_NormalProjection::BRepOffsetAPI_NormalProjection()
 {
   myNormalProjector.Build();
   myShape = myNormalProjector.Projection();
+  BRepBuilderAPI_MakeShape::EnsureToleranceRule(myShape);
   Done();
 }
 
index b1472a4d7a06fbbc0ee13d7101c9ff6251b23088..109eb1eb9e6b65870da0b8a738bed7254f931ab6 100755 (executable)
@@ -800,6 +800,27 @@ static Standard_Integer scalexyz(Draw_Interpretor& di, Standard_Integer n, const
   return 0;  
 }
 
+static Standard_Integer EnsureTolRule(
+  Draw_Interpretor & theDI, Standard_Integer theC, const char ** theAs)
+{
+  if (theC != 3)
+  {
+    return 1;
+  }
+  //
+  TopoDS_Shape aS = DBRep::Get(theAs[2]);
+  if (aS.IsNull())
+  {
+    return 1;
+  }
+  //
+  TopoDS_Shape aRes = BRepBuilderAPI_Copy(aS);
+  BRepBuilderAPI_MakeShape::EnsureToleranceRule(aRes);
+  //
+  DBRep::Set(theAs[1], aRes);
+  return 0;
+}
+
 void  BRepTest::BasicCommands(Draw_Interpretor& theCommands)
 {
   static Standard_Boolean done = Standard_False;
@@ -931,4 +952,6 @@ void  BRepTest::BasicCommands(Draw_Interpretor& theCommands)
                   "scalexyz res shape factor_x factor_y factor_z",
                  __FILE__,
                  scalexyz, g);
+
+  theCommands.Add("EnsureTolRule", "res shape", __FILE__, EnsureTolRule, g);
 }
index b3a9c5def90e91a8553af641d45c326dfbd9946a..9db1790d3b45ed1a2d6eb10a383ef2a57e25862c 100755 (executable)
@@ -49,10 +49,14 @@ is
     Init (me: mutable; shape: Shape from TopoDS);
        ---Purpose: Initislises by shape.
 
-    Perform (me          : mutable;
+    Perform  (me          : mutable;
              theProgress : ProgressIndicator from Message = 0) returns Boolean;
        ---Purpose: Iterates on sub- shape and performs fixes
 
+    PerformR (me          : mutable;
+             theProgress : ProgressIndicator from Message    ) returns Boolean is private;
+       ---Purpose: Internal method. Called by Perform.
+
     SameParameter (me          : mutable; 
                    shape       : Shape from TopoDS; 
                    enforce     : Boolean;
index 9c3584632c272cab7d8d6c2fe8f3f9f161b6c6aa..71e40f9fdb279a96b8452331352f5076e49bc136 100755 (executable)
@@ -33,6 +33,7 @@
 #include <TopAbs_ShapeEnum.hxx>
 #include <BRepTools.hxx>
 #include <BRep_Builder.hxx>
+#include <BRepBuilderAPI_MakeShape.hxx>
 
 #include <ShapeFix.hxx>
 #include <ShapeBuild_ReShape.hxx>
@@ -99,7 +100,22 @@ void ShapeFix_Shape::Init(const TopoDS_Shape& shape)
 //purpose  : 
 //=======================================================================
 
-Standard_Boolean ShapeFix_Shape::Perform(const Handle(Message_ProgressIndicator)& theProgress) 
+Standard_Boolean ShapeFix_Shape::Perform(const Handle(Message_ProgressIndicator)& theProgress)
+{
+  Standard_Boolean aR = PerformR(theProgress);
+  if (aR)
+  {
+    BRepBuilderAPI_MakeShape::EnsureToleranceRule(myResult);
+  }
+  return aR;
+}
+
+//=======================================================================
+//function : PerformR
+//purpose  : 
+//=======================================================================
+
+Standard_Boolean ShapeFix_Shape::PerformR(const Handle(Message_ProgressIndicator)& theProgress)
 {
   Standard_Integer savFixSmallAreaWireMode = 0;
 
index df80a5fb9d1c23de8612194b2b6ca35b566a799c..fafad096331a55900fb2ab86e8d07fa4f3c305bb 100755 (executable)
@@ -37,6 +37,7 @@
 #include <ShapeUpgrade_WireDivide.hxx>
 #include <Standard_ErrorHandler.hxx>
 #include <Standard_Failure.hxx>
+#include <BRepBuilderAPI_MakeShape.hxx>
 
 //=======================================================================
 //function : ShapeUpgrade_ShapeDivide
@@ -174,6 +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 );
+      BRepBuilderAPI_MakeShape::EnsureToleranceRule(myResult);
       return Standard_True;
     }
     myResult = myShape;
@@ -282,6 +284,7 @@ Standard_Boolean ShapeUpgrade_ShapeDivide::Perform(const Standard_Boolean newCon
     }
   }
   myResult = myContext->Apply ( myShape, TopAbs_SHAPE );
+  BRepBuilderAPI_MakeShape::EnsureToleranceRule(myResult);
   return ! myResult.IsSame ( myShape );
 }