0023301: Comparing variable to itself in ShapeUpgrade_WireDivide.cxx
[occt.git] / src / ShapeUpgrade / ShapeUpgrade_ShellSewing.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18//szv#4 S4163
19#include <ShapeUpgrade_ShellSewing.ixx>
20
21#include <TopoDS.hxx>
22#include <TopoDS_Shell.hxx>
23#include <TopoDS_Solid.hxx>
24#include <TopExp_Explorer.hxx>
25
26#include <BRepBuilderAPI_Sewing.hxx>
27#include <BRepClass3d_SolidClassifier.hxx>
28
29#include <ShapeAnalysis_ShapeTolerance.hxx>
30
31//=======================================================================
32//function : ShapeUpgrade_ShellSewing
33//purpose :
34//=======================================================================
35
36ShapeUpgrade_ShellSewing::ShapeUpgrade_ShellSewing()
37{
38 myReShape = new ShapeBuild_ReShape;
39}
40
41//=======================================================================
42//function : ApplySewing
43//purpose :
44//=======================================================================
45
46void ShapeUpgrade_ShellSewing::Init (const TopoDS_Shape& shape)
47{
48 if (shape.IsNull()) return;
49 if (shape.ShapeType() == TopAbs_SHELL) myShells.Add (shape);
50 else {
51 for (TopExp_Explorer exs (shape,TopAbs_SHELL); exs.More(); exs.Next()) {
52 myShells.Add (exs.Current());
53 }
54 }
55}
56
57//=======================================================================
58//function : Prepare
59//purpose :
60//=======================================================================
61
62Standard_Integer ShapeUpgrade_ShellSewing::Prepare (const Standard_Real tol)
63{
64 Standard_Integer nb = myShells.Extent(), ns = 0;
65 for ( Standard_Integer i = 1; i <= nb; i ++) {
66 TopoDS_Shell sl = TopoDS::Shell ( myShells.FindKey (i) );
67 BRepBuilderAPI_Sewing ss ( tol );
68 TopExp_Explorer exp(sl,TopAbs_FACE);
69 for (; exp.More(); exp.Next()) ss.Add(exp.Current());
70 ss.Perform();
71 TopoDS_Shape newsh = ss.SewedShape();
72 if (!newsh.IsNull()) { myReShape->Replace (sl,newsh); ns ++; }
73 }
74 return ns;
75}
76
77//=======================================================================
78//function : Apply
79//purpose :
80//=======================================================================
81
82TopoDS_Shape ShapeUpgrade_ShellSewing::Apply (const TopoDS_Shape& shape,
83 const Standard_Real tol)
84{
85 if ( shape.IsNull() || myShells.Extent() == 0 ) return shape;
86
87 TopoDS_Shape res = myReShape->Apply ( shape, TopAbs_FACE, 2 );
88
89 // A present orienter les solides correctement
90 myReShape->Clear();
91 Standard_Integer ns = 0;
92 for (TopExp_Explorer exd (shape,TopAbs_SOLID); exd.More(); exd.Next()) {
93 TopoDS_Solid sd = TopoDS::Solid ( exd.Current() );
94 BRepClass3d_SolidClassifier bsc3d (sd);
95 bsc3d.PerformInfinitePoint ( tol );
96 if (bsc3d.State() == TopAbs_IN) { myReShape->Replace (sd,sd.Reversed()); ns++; }
97 }
98
99 //szv#4:S4163:12Mar99 optimized
100 if (ns != 0) res = myReShape->Apply( res, TopAbs_SHELL, 2 );
101
102 return res;
103}
104
105//=======================================================================
106//function : ApplySewing
107//purpose :
108//=======================================================================
109
110TopoDS_Shape ShapeUpgrade_ShellSewing::ApplySewing (const TopoDS_Shape& shape,
111 const Standard_Real tol)
112{
113 if (shape.IsNull()) return shape;
114
115 Standard_Real t = tol;
116 if (t <= 0.) {
117 ShapeAnalysis_ShapeTolerance stu;
118 t = stu.Tolerance (shape,0); // tolerance moyenne
119 }
120
121 Init ( shape );
122 if ( Prepare ( t ) ) return Apply ( shape, t );
123
124 return TopoDS_Shape();
125}