1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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 // File: BlockFix_PeriodicSurfaceModifier.cxx
24 // Created: 15.12.04 10:08:50
25 // Author: Sergey KUUL
27 #include <BlockFix_PeriodicSurfaceModifier.hxx>
29 #include <ShapeFix_Edge.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <TopoDS_Face.hxx>
35 #include <TopoDS_Vertex.hxx>
37 #include <TopLoc_Location.hxx>
39 #include <BRep_Builder.hxx>
40 #include <BRep_Tool.hxx>
42 #include <BRepTools.hxx>
44 #include <Geom_CylindricalSurface.hxx>
45 #include <Geom_SphericalSurface.hxx>
46 #include <Geom_Surface.hxx>
47 #include <Geom_Curve.hxx>
49 #include <Geom2d_Curve.hxx>
53 IMPLEMENT_STANDARD_HANDLE(BlockFix_PeriodicSurfaceModifier, BRepTools_Modification);
54 IMPLEMENT_STANDARD_RTTIEXT(BlockFix_PeriodicSurfaceModifier, BRepTools_Modification);
56 //=======================================================================
57 //function : BlockFix_PeriodicSurfaceModifier()
58 //purpose : Constructor
59 //=======================================================================
60 BlockFix_PeriodicSurfaceModifier::BlockFix_PeriodicSurfaceModifier()
63 myMapOfSurfaces.Clear();
66 //=======================================================================
67 //function : ~BlockFix_PeriodicSurfaceModifier()
68 //purpose : Destructor
69 //=======================================================================
70 BlockFix_PeriodicSurfaceModifier::~BlockFix_PeriodicSurfaceModifier()
74 //=======================================================================
75 //function : SetTolerance
77 //=======================================================================
78 void BlockFix_PeriodicSurfaceModifier::SetTolerance(const Standard_Real Tol)
83 //=======================================================================
84 //function : ModifySurface
86 //=======================================================================
87 static Standard_Boolean ModifySurface(const TopoDS_Face& aFace,
88 const Handle(Geom_Surface)& aSurface,
89 Handle(Geom_Surface)& aNewSurface)
91 Handle(Geom_Surface) S = aSurface;
93 if(S->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
94 Handle(Geom_CylindricalSurface) aCyl =
95 Handle(Geom_CylindricalSurface)::DownCast(S);
96 Standard_Real Umin, Umax, Vmin, Vmax;
97 BRepTools::UVBounds(aFace, Umin, Umax, Vmin, Vmax);
98 if (Umin < -Precision::PConfusion() || Umax > 2*M_PI + Precision::PConfusion()) {
99 gp_Ax3 ax3 = aCyl->Position();
100 gp_Ax1 NDir = ax3.Axis();
101 gp_Ax3 newax3 = ax3.Rotated(NDir,Umin-Precision::PConfusion());
102 Handle(Geom_CylindricalSurface) aNewCyl =
103 new Geom_CylindricalSurface(newax3,aCyl->Radius());
104 aNewSurface = aNewCyl;
105 return Standard_True;
109 if(S->IsKind(STANDARD_TYPE(Geom_SphericalSurface))) {
110 Handle(Geom_SphericalSurface) aSphere = Handle(Geom_SphericalSurface)::DownCast(S);
111 Standard_Real Umin, Umax, Vmin, Vmax;
112 BRepTools::UVBounds(aFace, Umin, Umax, Vmin, Vmax);
113 if (Umin < -Precision::PConfusion() || Umax > 2*M_PI + Precision::PConfusion()) {
114 gp_Ax3 ax3 = aSphere->Position();
115 gp_Ax1 NDir = ax3.Axis();
116 gp_Ax3 newax3 = ax3.Rotated(NDir,Umin-Precision::PConfusion());
117 Handle(Geom_SphericalSurface) aNewSphere = new Geom_SphericalSurface(newax3,aSphere->Radius());
118 aNewSurface = aNewSphere;
119 return Standard_True;
123 return Standard_False;
126 //=======================================================================
127 //function : NewSurface
129 //=======================================================================
130 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewSurface(const TopoDS_Face& F,
131 Handle(Geom_Surface)& S,
132 TopLoc_Location& L,Standard_Real& Tol,
133 Standard_Boolean& RevWires,
134 Standard_Boolean& RevFace)
137 Handle(Geom_Surface) SIni = BRep_Tool::Surface(F, LS);
139 if(ModifySurface(F, SIni, S)) {
141 RevWires = Standard_False;
142 RevFace = Standard_False;
145 Tol = BRep_Tool::Tolerance(F);
147 Standard_Integer anIndex = myMapOfSurfaces.Add(S);
148 myMapOfFaces.Bind(F,anIndex);
149 return Standard_True;
152 return Standard_False;
155 //=======================================================================
156 //function : NewCurve
158 //=======================================================================
159 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewCurve(const TopoDS_Edge& /*E*/,
160 Handle(Geom_Curve)& /*C*/,
161 TopLoc_Location& /*L*/,
162 Standard_Real& /*Tol*/)
164 return Standard_False;
167 //=======================================================================
168 //function : NewPoint
170 //=======================================================================
171 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewPoint(const TopoDS_Vertex& /*V*/,
173 Standard_Real& /*Tol*/)
175 return Standard_False;
178 //=======================================================================
179 //function : NewCurve2d
181 //=======================================================================
182 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewCurve2d(const TopoDS_Edge& E,
183 const TopoDS_Face& F,
184 const TopoDS_Edge& /*NewE*/,
185 const TopoDS_Face& /*NewF*/,
186 Handle(Geom2d_Curve)& C,
189 //check if undelying surface of the face was modified
190 if(myMapOfFaces.IsBound(F)) {
191 Standard_Integer anIndex = myMapOfFaces.Find(F);
193 Handle(Geom_Surface) aNewSurf = Handle(Geom_Surface)::DownCast(myMapOfSurfaces.FindKey(anIndex));
196 TopLoc_Location LC, LS;
197 Handle(Geom_Curve) C3d = BRep_Tool::Curve ( E, LC, f, l );
198 Handle(Geom_Surface) S = BRep_Tool::Surface(F, LS);
200 //taking into accound the orientation of the seam
201 C = BRep_Tool::CurveOnSurface(E,F,f,l);
202 Tol = BRep_Tool::Tolerance(E);
207 B.Add(TempE, TopExp::FirstVertex(E));
208 B.Add(TempE, TopExp::LastVertex(E));
211 B.UpdateEdge(TempE, Handle(Geom_Curve)::DownCast(C3d->Transformed(LC.Transformation())), Precision::Confusion());
212 B.Range(TempE, f, l);
214 Handle(ShapeFix_Edge) sfe = new ShapeFix_Edge;
215 Handle(Geom_Surface) STemp = Handle(Geom_Surface)::DownCast(aNewSurf->Transformed(LS.Transformation()));
216 TopLoc_Location LTemp;
219 Standard_Boolean isClosed = BRep_Tool::IsClosed (E, F);
220 Standard_Real aWorkTol = 2*myTolerance+Tol;
221 sfe->FixAddPCurve(TempE, STemp, LTemp, isClosed, Max(Precision::Confusion(), aWorkTol));
222 sfe->FixSameParameter(TempE);
224 //keep the orientation of original edge
225 TempE.Orientation(E.Orientation());
226 C = BRep_Tool::CurveOnSurface(TempE, STemp, LTemp, f, l);
228 //surface was modified
229 return Standard_True;
232 return Standard_False;
235 //=======================================================================
236 //function : NewParameter
238 //=======================================================================
239 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewParameter(const TopoDS_Vertex& /*V*/,
240 const TopoDS_Edge& /*E*/,
241 Standard_Real& /*P*/,
242 Standard_Real& /*Tol*/)
244 return Standard_False;
247 //=======================================================================
248 //function : Continuity
250 //=======================================================================
251 GeomAbs_Shape BlockFix_PeriodicSurfaceModifier::Continuity(const TopoDS_Edge& E,
252 const TopoDS_Face& F1,
253 const TopoDS_Face& F2,
254 const TopoDS_Edge& /*NewE*/,
255 const TopoDS_Face& /*NewF1*/,
256 const TopoDS_Face& /*NewF2*/)
258 return BRep_Tool::Continuity(E,F1,F2);