1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // Created: Tue Dec 7 11:59:05 2004
22 // Author: Pavel DURANDIN
25 #include <BlockFix.hxx>
26 #include <TopoDS_Shape.hxx>
27 #include <TopTools_DataMapOfShapeShape.hxx>
28 #include <ShapeCustom.hxx>
29 #include <BRepTools.hxx>
30 #include <ShapeBuild_ReShape.hxx>
31 #include <TopoDS_Face.hxx>
32 #include <TopExp_Explorer.hxx>
34 #include <TopLoc_Location.hxx>
35 #include <Geom_Surface.hxx>
36 #include <Geom_CylindricalSurface.hxx>
37 #include <Geom_ConicalSurface.hxx>
38 #include <ShapeFix_Wire.hxx>
39 #include <TopoDS_Wire.hxx>
40 #include <BRepTools_Modifier.hxx>
41 #include <Geom_SphericalSurface.hxx>
42 #include <Geom_ToroidalSurface.hxx>
43 #include <BRep_Tool.hxx>
44 #include <TopoDS_Edge.hxx>
45 #include <Geom2d_Curve.hxx>
46 #include <BRep_Builder.hxx>
47 #include <ShapeAnalysis_Edge.hxx>
48 #include <ShapeFix_Edge.hxx>
49 #include <ShapeFix.hxx>
50 #include <ShapeFix_Face.hxx>
51 #include <ShapeAnalysis.hxx>
53 #include <TColgp_SequenceOfPnt2d.hxx>
54 #include <ShapeAnalysis_Curve.hxx>
55 #include <TopoDS_Vertex.hxx>
56 #include <ShapeBuild_Edge.hxx>
58 #include <BlockFix_SphereSpaceModifier.hxx>
59 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
60 #include <TopTools_MapOfShape.hxx>
61 #include <BlockFix_PeriodicSurfaceModifier.hxx>
63 #include <TopoDS_Solid.hxx>
66 //=======================================================================
67 //function : FixResult
69 //=======================================================================
70 static void FixResult(const TopoDS_Shape& result,
71 Handle(ShapeBuild_ReShape)& Context,
72 const Standard_Real Tol)
74 for (TopExp_Explorer ex_f(result,TopAbs_FACE); ex_f.More(); ex_f.Next()) {
75 TopoDS_Shape aShape = Context->Apply(ex_f.Current().Oriented(TopAbs_FORWARD));
76 // face coud not be dropped or splitted on this step
77 TopoDS_Face aFace = TopoDS::Face(aShape);
79 Handle(Geom_Surface) Surf = BRep_Tool::Surface(aFace,L);
81 if( Surf->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
82 Surf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) ) {
84 Standard_Integer nbWires = 0;
85 for (TopExp_Explorer ex_w(aFace,TopAbs_WIRE); ex_w.More(); ex_w.Next()) {
87 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire(TopoDS::Wire(ex_w.Current()),
89 Precision::Confusion());
91 if(sfw->StatusReorder ( ShapeExtend_FAIL ))
94 sfw->SetPrecision(2.*Tol);
97 Standard_Boolean isDone = sfw->LastFixStatus ( ShapeExtend_DONE );
98 isDone |= sfw->FixDegenerated();
100 // remove degenerated edges from not degenerated points
101 ShapeAnalysis_Edge sae;
102 Handle(ShapeExtend_WireData) sewd = sfw->WireData();
104 for( i = 1; i<=sewd->NbEdges();i++) {
105 TopoDS_Edge E = sewd->Edge(i);
106 if(BRep_Tool::Degenerated(E)&&!sae.HasPCurve(E,aFace)) {
108 isDone = Standard_True;
113 //isDone |= sfw->FixLacking(); // commented by skl 22.03.2005 (PAL8395)
115 // remove neighbour seam edges
117 for( i = 1; i<sewd->NbEdges();i++) {
118 if(sewd->IsSeam(i) && sewd->IsSeam(i+1)) {
119 isDone = Standard_True;
125 if(sewd->IsSeam(1) && sewd->IsSeam(sewd->NbEdges())) {
127 sewd->Remove(sewd->NbEdges());
133 TopoDS_Wire ResWire = sfw->Wire();
134 Context->Replace(ex_w.Current(), ResWire);
137 // Implement fix orientation in case of several wires
139 TopoDS_Face aFixedFace = TopoDS::Face(Context->Apply(aFace));
140 Handle(ShapeFix_Face) sff = new ShapeFix_Face(aFixedFace);
141 if(sff->FixOrientation())
142 Context->Replace(aFixedFace,sff->Face());
153 //=======================================================================
154 //function : ConvertToAnalytical
156 //=======================================================================
158 TopoDS_Shape BlockFix::RotateSphereSpace (const TopoDS_Shape& S,
159 const Standard_Real Tol)
162 // Create a modification description
163 Handle(BlockFix_SphereSpaceModifier) SR = new BlockFix_SphereSpaceModifier;
164 SR->SetTolerance(Tol);
166 TopTools_DataMapOfShapeShape context;
167 BRepTools_Modifier MD;
168 TopoDS_Shape result = ShapeCustom::ApplyModifier ( S, SR, context,MD );
170 Handle(ShapeBuild_ReShape) RS = new ShapeBuild_ReShape;
171 FixResult(result,RS,Tol);
172 result = RS->Apply(result);
175 for(TopExp_Explorer exp(result,TopAbs_EDGE); exp.More(); exp.Next()) {
176 TopoDS_Edge E = TopoDS::Edge(exp.Current());
177 sfe.FixVertexTolerance (E);
180 ShapeFix::SameParameter(result,Standard_False);
185 //=======================================================================
186 //function : FixRanges
188 //=======================================================================
190 TopoDS_Shape BlockFix::FixRanges (const TopoDS_Shape& S,
191 const Standard_Real Tol)
193 // Create a modification description
194 Handle(BlockFix_PeriodicSurfaceModifier) SR = new BlockFix_PeriodicSurfaceModifier;
195 SR->SetTolerance(Tol);
197 TopTools_DataMapOfShapeShape context;
198 BRepTools_Modifier MD;
199 TopoDS_Shape result = ShapeCustom::ApplyModifier ( S, SR, context,MD );
201 Handle(ShapeBuild_ReShape) RS = new ShapeBuild_ReShape;
202 FixResult(result,RS,Tol);
203 result = RS->Apply(result);
206 for(TopExp_Explorer exp(result,TopAbs_EDGE); exp.More(); exp.Next()) {
207 TopoDS_Edge E = TopoDS::Edge(exp.Current());
208 sfe.FixVertexTolerance (E);
211 ShapeFix::SameParameter(result,Standard_False);