973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
7fd59977 |
14 | //szv#4 S4163 |
7fd59977 |
15 | |
16 | #include <BRepBuilderAPI_Sewing.hxx> |
17 | #include <BRepClass3d_SolidClassifier.hxx> |
7fd59977 |
18 | #include <ShapeAnalysis_ShapeTolerance.hxx> |
42cf5bc1 |
19 | #include <ShapeBuild_ReShape.hxx> |
20 | #include <ShapeUpgrade_ShellSewing.hxx> |
c04c30b3 |
21 | #include <ShapeUpgrade_WireDivide.hxx> |
42cf5bc1 |
22 | #include <TopExp_Explorer.hxx> |
23 | #include <TopoDS.hxx> |
24 | #include <TopoDS_Shape.hxx> |
25 | #include <TopoDS_Shell.hxx> |
26 | #include <TopoDS_Solid.hxx> |
7fd59977 |
27 | |
28 | //======================================================================= |
29 | //function : ShapeUpgrade_ShellSewing |
30 | //purpose : |
31 | //======================================================================= |
7fd59977 |
32 | ShapeUpgrade_ShellSewing::ShapeUpgrade_ShellSewing() |
33 | { |
34 | myReShape = new ShapeBuild_ReShape; |
35 | } |
36 | |
37 | //======================================================================= |
38 | //function : ApplySewing |
39 | //purpose : |
40 | //======================================================================= |
41 | |
42 | void ShapeUpgrade_ShellSewing::Init (const TopoDS_Shape& shape) |
43 | { |
44 | if (shape.IsNull()) return; |
45 | if (shape.ShapeType() == TopAbs_SHELL) myShells.Add (shape); |
46 | else { |
47 | for (TopExp_Explorer exs (shape,TopAbs_SHELL); exs.More(); exs.Next()) { |
48 | myShells.Add (exs.Current()); |
49 | } |
50 | } |
51 | } |
52 | |
53 | //======================================================================= |
54 | //function : Prepare |
55 | //purpose : |
56 | //======================================================================= |
57 | |
58 | Standard_Integer ShapeUpgrade_ShellSewing::Prepare (const Standard_Real tol) |
59 | { |
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()); |
66 | ss.Perform(); |
67 | TopoDS_Shape newsh = ss.SewedShape(); |
68 | if (!newsh.IsNull()) { myReShape->Replace (sl,newsh); ns ++; } |
69 | } |
70 | return ns; |
71 | } |
72 | |
73 | //======================================================================= |
74 | //function : Apply |
75 | //purpose : |
76 | //======================================================================= |
77 | |
78 | TopoDS_Shape ShapeUpgrade_ShellSewing::Apply (const TopoDS_Shape& shape, |
79 | const Standard_Real tol) |
80 | { |
81 | if ( shape.IsNull() || myShells.Extent() == 0 ) return shape; |
82 | |
83 | TopoDS_Shape res = myReShape->Apply ( shape, TopAbs_FACE, 2 ); |
84 | |
85 | // A present orienter les solides correctement |
86 | myReShape->Clear(); |
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++; } |
93 | } |
94 | |
95 | //szv#4:S4163:12Mar99 optimized |
96 | if (ns != 0) res = myReShape->Apply( res, TopAbs_SHELL, 2 ); |
97 | |
98 | return res; |
99 | } |
100 | |
101 | //======================================================================= |
102 | //function : ApplySewing |
103 | //purpose : |
104 | //======================================================================= |
105 | |
106 | TopoDS_Shape ShapeUpgrade_ShellSewing::ApplySewing (const TopoDS_Shape& shape, |
107 | const Standard_Real tol) |
108 | { |
109 | if (shape.IsNull()) return shape; |
110 | |
111 | Standard_Real t = tol; |
112 | if (t <= 0.) { |
113 | ShapeAnalysis_ShapeTolerance stu; |
114 | t = stu.Tolerance (shape,0); // tolerance moyenne |
115 | } |
116 | |
117 | Init ( shape ); |
118 | if ( Prepare ( t ) ) return Apply ( shape, t ); |
119 | |
120 | return TopoDS_Shape(); |
121 | } |