1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
16 #include <BRepBuilderAPI_Sewing.hxx>
17 #include <BRepClass3d_SolidClassifier.hxx>
18 #include <ShapeAnalysis_ShapeTolerance.hxx>
19 #include <ShapeBuild_ReShape.hxx>
20 #include <ShapeUpgrade_ShellSewing.hxx>
21 #include <ShapeUpgrade_WireDivide.hxx>
22 #include <TopExp_Explorer.hxx>
24 #include <TopoDS_Shape.hxx>
25 #include <TopoDS_Shell.hxx>
26 #include <TopoDS_Solid.hxx>
28 //=======================================================================
29 //function : ShapeUpgrade_ShellSewing
31 //=======================================================================
32 ShapeUpgrade_ShellSewing::ShapeUpgrade_ShellSewing()
34 myReShape = new ShapeBuild_ReShape;
37 //=======================================================================
38 //function : ApplySewing
40 //=======================================================================
42 void ShapeUpgrade_ShellSewing::Init (const TopoDS_Shape& shape)
44 if (shape.IsNull()) return;
45 if (shape.ShapeType() == TopAbs_SHELL) myShells.Add (shape);
47 for (TopExp_Explorer exs (shape,TopAbs_SHELL); exs.More(); exs.Next()) {
48 myShells.Add (exs.Current());
53 //=======================================================================
56 //=======================================================================
58 Standard_Integer ShapeUpgrade_ShellSewing::Prepare (const Standard_Real tol)
60 Standard_Integer nb = myShells.Extent(), ns = 0;
61 for ( Standard_Integer i = 1; i <= nb; i ++) {
62 TopoDS_Shell sl = TopoDS::Shell ( myShells.FindKey (i) );
63 BRepBuilderAPI_Sewing ss ( tol );
64 TopExp_Explorer exp(sl,TopAbs_FACE);
65 for (; exp.More(); exp.Next()) ss.Add(exp.Current());
67 TopoDS_Shape newsh = ss.SewedShape();
68 if (!newsh.IsNull()) { myReShape->Replace (sl,newsh); ns ++; }
73 //=======================================================================
76 //=======================================================================
78 TopoDS_Shape ShapeUpgrade_ShellSewing::Apply (const TopoDS_Shape& shape,
79 const Standard_Real tol)
81 if ( shape.IsNull() || myShells.Extent() == 0 ) return shape;
83 TopoDS_Shape res = myReShape->Apply ( shape, TopAbs_FACE, 2 );
85 // A present orienter les solides correctement
87 Standard_Integer ns = 0;
88 for (TopExp_Explorer exd (shape,TopAbs_SOLID); exd.More(); exd.Next()) {
89 TopoDS_Solid sd = TopoDS::Solid ( exd.Current() );
90 BRepClass3d_SolidClassifier bsc3d (sd);
91 bsc3d.PerformInfinitePoint ( tol );
92 if (bsc3d.State() == TopAbs_IN) { myReShape->Replace (sd,sd.Reversed()); ns++; }
95 //szv#4:S4163:12Mar99 optimized
96 if (ns != 0) res = myReShape->Apply( res, TopAbs_SHELL, 2 );
101 //=======================================================================
102 //function : ApplySewing
104 //=======================================================================
106 TopoDS_Shape ShapeUpgrade_ShellSewing::ApplySewing (const TopoDS_Shape& shape,
107 const Standard_Real tol)
109 if (shape.IsNull()) return shape;
111 Standard_Real t = tol;
113 ShapeAnalysis_ShapeTolerance stu;
114 t = stu.Tolerance (shape,0); // tolerance moyenne
118 if ( Prepare ( t ) ) return Apply ( shape, t );
120 return TopoDS_Shape();