1 // Copyright (C) 2007-2010 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 // File: BlockFix_PeriodicSurfaceModifier.cxx
24 // Created: 15.12.04 10:08:50
25 // Author: Sergey KUUL
27 #include <BlockFix_PeriodicSurfaceModifier.ixx>
29 #include <BRep_Builder.hxx>
30 #include <BRep_Tool.hxx>
31 #include <BRepTools.hxx>
32 #include <Geom_CylindricalSurface.hxx>
33 #include <Geom_SphericalSurface.hxx>
34 #include <ShapeFix_Edge.hxx>
38 //=======================================================================
39 //function : BlockFix_PeriodicSurfaceModifier()
40 //purpose : Constructor
41 //=======================================================================
43 BlockFix_PeriodicSurfaceModifier::BlockFix_PeriodicSurfaceModifier ( )
46 myMapOfSurfaces.Clear();
50 //=======================================================================
51 //function : SetTolerance
53 //=======================================================================
55 void BlockFix_PeriodicSurfaceModifier::SetTolerance(const Standard_Real Tol)
61 //=======================================================================
62 //function : ModifySurface
64 //=======================================================================
66 static Standard_Boolean ModifySurface(const TopoDS_Face& aFace,
67 const Handle(Geom_Surface)& aSurface,
68 Handle(Geom_Surface)& aNewSurface)
70 Handle(Geom_Surface) S = aSurface;
72 if(S->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
73 Handle(Geom_CylindricalSurface) aCyl =
74 Handle(Geom_CylindricalSurface)::DownCast(S);
75 Standard_Real Umin, Umax, Vmin, Vmax;
76 BRepTools::UVBounds(aFace, Umin, Umax, Vmin, Vmax);
77 if( Umin<-Precision::PConfusion() || Umax>2*PI+Precision::PConfusion() ) {
78 gp_Ax3 ax3 = aCyl->Position();
79 gp_Ax1 NDir = ax3.Axis();
80 gp_Ax3 newax3 = ax3.Rotated(NDir,Umin-Precision::PConfusion());
81 Handle(Geom_CylindricalSurface) aNewCyl =
82 new Geom_CylindricalSurface(newax3,aCyl->Radius());
83 aNewSurface = aNewCyl;
88 if(S->IsKind(STANDARD_TYPE(Geom_SphericalSurface))) {
89 Handle(Geom_SphericalSurface) aSphere = Handle(Geom_SphericalSurface)::DownCast(S);
90 Standard_Real Umin, Umax, Vmin, Vmax;
91 BRepTools::UVBounds(aFace, Umin, Umax, Vmin, Vmax);
92 if( Umin<-Precision::PConfusion() || Umax>2*PI+Precision::PConfusion() ) {
93 gp_Ax3 ax3 = aSphere->Position();
94 gp_Ax1 NDir = ax3.Axis();
95 gp_Ax3 newax3 = ax3.Rotated(NDir,Umin-Precision::PConfusion());
96 Handle(Geom_SphericalSurface) aNewSphere = new Geom_SphericalSurface(newax3,aSphere->Radius());
97 aNewSurface = aNewSphere;
102 return Standard_False;
106 //=======================================================================
107 //function : NewSurface
109 //=======================================================================
111 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewSurface(const TopoDS_Face& F,
112 Handle(Geom_Surface)& S,
113 TopLoc_Location& L,Standard_Real& Tol,
114 Standard_Boolean& RevWires,
115 Standard_Boolean& RevFace)
118 Handle(Geom_Surface) SIni = BRep_Tool::Surface(F, LS);
120 if(ModifySurface(F, SIni, S)) {
122 RevWires = Standard_False;
123 RevFace = Standard_False;
126 Tol = BRep_Tool::Tolerance(F);
128 Standard_Integer anIndex = myMapOfSurfaces.Add(S);
129 myMapOfFaces.Bind(F,anIndex);
130 return Standard_True;
133 return Standard_False;
137 //=======================================================================
138 //function : NewCurve
140 //=======================================================================
142 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewCurve(const TopoDS_Edge& /*E*/,
143 Handle(Geom_Curve)& /*C*/,
144 TopLoc_Location& /*L*/,
145 Standard_Real& /*Tol*/)
147 return Standard_False;
151 //=======================================================================
152 //function : NewPoint
154 //=======================================================================
156 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewPoint(const TopoDS_Vertex& /*V*/,
158 Standard_Real& /*Tol*/)
160 return Standard_False;
164 //=======================================================================
165 //function : NewCurve2d
167 //=======================================================================
169 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewCurve2d(const TopoDS_Edge& E,
170 const TopoDS_Face& F,
171 const TopoDS_Edge& /*NewE*/,
172 const TopoDS_Face& /*NewF*/,
173 Handle(Geom2d_Curve)& C,
176 //check if undelying surface of the face was modified
177 if(myMapOfFaces.IsBound(F)) {
178 Standard_Integer anIndex = myMapOfFaces.Find(F);
180 Handle(Geom_Surface) aNewSurf = Handle(Geom_Surface)::DownCast(myMapOfSurfaces.FindKey(anIndex));
183 TopLoc_Location LC, LS;
184 Handle(Geom_Curve) C3d = BRep_Tool::Curve ( E, LC, f, l );
185 Handle(Geom_Surface) S = BRep_Tool::Surface(F, LS);
187 //taking into accound the orientation of the seam
188 C = BRep_Tool::CurveOnSurface(E,F,f,l);
189 Tol = BRep_Tool::Tolerance(E);
194 B.Add(TempE, TopExp::FirstVertex(E));
195 B.Add(TempE, TopExp::LastVertex(E));
198 B.UpdateEdge(TempE, Handle(Geom_Curve)::DownCast(C3d->Transformed(LC.Transformation())), Precision::Confusion());
199 B.Range(TempE, f, l);
201 Handle(ShapeFix_Edge) sfe = new ShapeFix_Edge;
202 Handle(Geom_Surface) STemp = Handle(Geom_Surface)::DownCast(aNewSurf->Transformed(LS.Transformation()));
203 TopLoc_Location LTemp;
206 Standard_Boolean isClosed = BRep_Tool::IsClosed (E, F);
207 Standard_Real aWorkTol = 2*myTolerance+Tol;
208 sfe->FixAddPCurve(TempE, STemp, LTemp, isClosed, Max(Precision::Confusion(), aWorkTol));
209 sfe->FixSameParameter(TempE);
211 //keep the orientation of original edge
212 TempE.Orientation(E.Orientation());
213 C = BRep_Tool::CurveOnSurface(TempE, STemp, LTemp, f, l);
215 //surface was modified
216 return Standard_True;
219 return Standard_False;
223 //=======================================================================
224 //function : NewParameter
226 //=======================================================================
228 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewParameter(const TopoDS_Vertex& /*V*/,
229 const TopoDS_Edge& /*E*/,
230 Standard_Real& /*P*/,
231 Standard_Real& /*Tol*/)
233 return Standard_False;
237 //=======================================================================
238 //function : Continuity
240 //=======================================================================
242 GeomAbs_Shape BlockFix_PeriodicSurfaceModifier::Continuity(const TopoDS_Edge& E,
243 const TopoDS_Face& F1,
244 const TopoDS_Face& F2,
245 const TopoDS_Edge& /*NewE*/,
246 const TopoDS_Face& /*NewF1*/,
247 const TopoDS_Face& /*NewF2*/)
249 return BRep_Tool::Continuity(E,F1,F2);