1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // Created: Tue Dec 7 11:59:05 2004
24 // Author: Pavel DURANDIN
26 #include <BlockFix.hxx>
27 #include <TopoDS_Shape.hxx>
28 #include <TopTools_DataMapOfShapeShape.hxx>
29 #include <ShapeCustom.hxx>
30 #include <BRepTools.hxx>
31 #include <ShapeBuild_ReShape.hxx>
32 #include <TopoDS_Face.hxx>
33 #include <TopExp_Explorer.hxx>
35 #include <TopLoc_Location.hxx>
36 #include <Geom_Surface.hxx>
37 #include <Geom_CylindricalSurface.hxx>
38 #include <Geom_ConicalSurface.hxx>
39 #include <ShapeFix_Wire.hxx>
40 #include <TopoDS_Wire.hxx>
41 #include <BRepTools_Modifier.hxx>
42 #include <Geom_SphericalSurface.hxx>
43 #include <Geom_ToroidalSurface.hxx>
44 #include <BRep_Tool.hxx>
45 #include <TopoDS_Edge.hxx>
46 #include <Geom2d_Curve.hxx>
47 #include <BRep_Builder.hxx>
48 #include <ShapeAnalysis_Edge.hxx>
49 #include <ShapeFix_Edge.hxx>
50 #include <ShapeFix.hxx>
51 #include <ShapeFix_Face.hxx>
52 #include <ShapeAnalysis.hxx>
54 #include <TColgp_SequenceOfPnt2d.hxx>
55 #include <ShapeAnalysis_Curve.hxx>
56 #include <TopoDS_Vertex.hxx>
57 #include <ShapeBuild_Edge.hxx>
59 #include <BlockFix_SphereSpaceModifier.hxx>
60 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
61 #include <TopTools_MapOfShape.hxx>
62 #include <BlockFix_PeriodicSurfaceModifier.hxx>
64 #include <TopoDS_Solid.hxx>
67 //=======================================================================
68 //function : FixResult
70 //=======================================================================
71 static void FixResult(const TopoDS_Shape& result,
72 Handle(ShapeBuild_ReShape)& Context,
73 const Standard_Real Tol)
75 for (TopExp_Explorer ex_f(result,TopAbs_FACE); ex_f.More(); ex_f.Next()) {
76 TopoDS_Shape aShape = Context->Apply(ex_f.Current().Oriented(TopAbs_FORWARD));
77 // face coud not be dropped or splitted on this step
78 TopoDS_Face aFace = TopoDS::Face(aShape);
80 Handle(Geom_Surface) Surf = BRep_Tool::Surface(aFace,L);
82 if( Surf->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
83 Surf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) ) {
85 Standard_Integer nbWires = 0;
86 for (TopExp_Explorer ex_w(aFace,TopAbs_WIRE); ex_w.More(); ex_w.Next()) {
88 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire(TopoDS::Wire(ex_w.Current()),
90 Precision::Confusion());
92 if(sfw->StatusReorder ( ShapeExtend_FAIL ))
95 sfw->SetPrecision(2.*Tol);
98 Standard_Boolean isDone = sfw->LastFixStatus ( ShapeExtend_DONE );
99 isDone |= sfw->FixDegenerated();
101 // remove degenerated edges from not degenerated points
102 ShapeAnalysis_Edge sae;
103 Handle(ShapeExtend_WireData) sewd = sfw->WireData();
105 for( i = 1; i<=sewd->NbEdges();i++) {
106 TopoDS_Edge E = sewd->Edge(i);
107 if(BRep_Tool::Degenerated(E)&&!sae.HasPCurve(E,aFace)) {
109 isDone = Standard_True;
114 //isDone |= sfw->FixLacking(); // commented by skl 22.03.2005 (PAL8395)
116 // remove neighbour seam edges
118 for( i = 1; i<sewd->NbEdges();i++) {
119 if(sewd->IsSeam(i) && sewd->IsSeam(i+1)) {
120 isDone = Standard_True;
126 if(sewd->IsSeam(1) && sewd->IsSeam(sewd->NbEdges())) {
128 sewd->Remove(sewd->NbEdges());
134 TopoDS_Wire ResWire = sfw->Wire();
135 Context->Replace(ex_w.Current(), ResWire);
138 // Implement fix orientation in case of several wires
140 TopoDS_Face aFixedFace = TopoDS::Face(Context->Apply(aFace));
141 Handle(ShapeFix_Face) sff = new ShapeFix_Face(aFixedFace);
142 if(sff->FixOrientation())
143 Context->Replace(aFixedFace,sff->Face());
154 //=======================================================================
155 //function : ConvertToAnalytical
157 //=======================================================================
159 TopoDS_Shape BlockFix::RotateSphereSpace (const TopoDS_Shape& S,
160 const Standard_Real Tol)
163 // Create a modification description
164 Handle(BlockFix_SphereSpaceModifier) SR = new BlockFix_SphereSpaceModifier;
165 SR->SetTolerance(Tol);
167 TopTools_DataMapOfShapeShape context;
168 BRepTools_Modifier MD;
169 TopoDS_Shape result = ShapeCustom::ApplyModifier ( S, SR, context,MD );
171 Handle(ShapeBuild_ReShape) RS = new ShapeBuild_ReShape;
172 FixResult(result,RS,Tol);
173 result = RS->Apply(result);
176 for(TopExp_Explorer exp(result,TopAbs_EDGE); exp.More(); exp.Next()) {
177 TopoDS_Edge E = TopoDS::Edge(exp.Current());
178 sfe.FixVertexTolerance (E);
181 ShapeFix::SameParameter(result,Standard_False);
186 //=======================================================================
187 //function : FixRanges
189 //=======================================================================
191 TopoDS_Shape BlockFix::FixRanges (const TopoDS_Shape& S,
192 const Standard_Real Tol)
194 // Create a modification description
195 Handle(BlockFix_PeriodicSurfaceModifier) SR = new BlockFix_PeriodicSurfaceModifier;
196 SR->SetTolerance(Tol);
198 TopTools_DataMapOfShapeShape context;
199 BRepTools_Modifier MD;
200 TopoDS_Shape result = ShapeCustom::ApplyModifier ( S, SR, context,MD );
202 Handle(ShapeBuild_ReShape) RS = new ShapeBuild_ReShape;
203 FixResult(result,RS,Tol);
204 result = RS->Apply(result);
207 for(TopExp_Explorer exp(result,TopAbs_EDGE); exp.More(); exp.Next()) {
208 TopoDS_Edge E = TopoDS::Edge(exp.Current());
209 sfe.FixVertexTolerance (E);
212 ShapeFix::SameParameter(result,Standard_False);