1 // Copyright (C) 2007-2011 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
22 // File: BlockFix_PeriodicSurfaceModifier.cxx
23 // Created: 15.12.04 10:08:50
24 // Author: Sergey KUUL
26 #include <BlockFix_PeriodicSurfaceModifier.ixx>
28 #include <BRep_Builder.hxx>
29 #include <BRep_Tool.hxx>
30 #include <BRepTools.hxx>
31 #include <Geom_CylindricalSurface.hxx>
32 #include <Geom_SphericalSurface.hxx>
33 #include <ShapeFix_Edge.hxx>
37 //=======================================================================
38 //function : BlockFix_PeriodicSurfaceModifier()
39 //purpose : Constructor
40 //=======================================================================
42 BlockFix_PeriodicSurfaceModifier::BlockFix_PeriodicSurfaceModifier ( )
45 myMapOfSurfaces.Clear();
49 //=======================================================================
50 //function : SetTolerance
52 //=======================================================================
54 void BlockFix_PeriodicSurfaceModifier::SetTolerance(const Standard_Real Tol)
60 //=======================================================================
61 //function : ModifySurface
63 //=======================================================================
65 static Standard_Boolean ModifySurface(const TopoDS_Face& aFace,
66 const Handle(Geom_Surface)& aSurface,
67 Handle(Geom_Surface)& aNewSurface)
69 Handle(Geom_Surface) S = aSurface;
71 if(S->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
72 Handle(Geom_CylindricalSurface) aCyl =
73 Handle(Geom_CylindricalSurface)::DownCast(S);
74 Standard_Real Umin, Umax, Vmin, Vmax;
75 BRepTools::UVBounds(aFace, Umin, Umax, Vmin, Vmax);
76 if (Umin < -Precision::PConfusion() || Umax > 2*M_PI + Precision::PConfusion()) {
77 gp_Ax3 ax3 = aCyl->Position();
78 gp_Ax1 NDir = ax3.Axis();
79 gp_Ax3 newax3 = ax3.Rotated(NDir,Umin-Precision::PConfusion());
80 Handle(Geom_CylindricalSurface) aNewCyl =
81 new Geom_CylindricalSurface(newax3,aCyl->Radius());
82 aNewSurface = aNewCyl;
87 if(S->IsKind(STANDARD_TYPE(Geom_SphericalSurface))) {
88 Handle(Geom_SphericalSurface) aSphere = Handle(Geom_SphericalSurface)::DownCast(S);
89 Standard_Real Umin, Umax, Vmin, Vmax;
90 BRepTools::UVBounds(aFace, Umin, Umax, Vmin, Vmax);
91 if (Umin < -Precision::PConfusion() || Umax > 2*M_PI + Precision::PConfusion()) {
92 gp_Ax3 ax3 = aSphere->Position();
93 gp_Ax1 NDir = ax3.Axis();
94 gp_Ax3 newax3 = ax3.Rotated(NDir,Umin-Precision::PConfusion());
95 Handle(Geom_SphericalSurface) aNewSphere = new Geom_SphericalSurface(newax3,aSphere->Radius());
96 aNewSurface = aNewSphere;
101 return Standard_False;
105 //=======================================================================
106 //function : NewSurface
108 //=======================================================================
110 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewSurface(const TopoDS_Face& F,
111 Handle(Geom_Surface)& S,
112 TopLoc_Location& L,Standard_Real& Tol,
113 Standard_Boolean& RevWires,
114 Standard_Boolean& RevFace)
117 Handle(Geom_Surface) SIni = BRep_Tool::Surface(F, LS);
119 if(ModifySurface(F, SIni, S)) {
121 RevWires = Standard_False;
122 RevFace = Standard_False;
125 Tol = BRep_Tool::Tolerance(F);
127 Standard_Integer anIndex = myMapOfSurfaces.Add(S);
128 myMapOfFaces.Bind(F,anIndex);
129 return Standard_True;
132 return Standard_False;
136 //=======================================================================
137 //function : NewCurve
139 //=======================================================================
141 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewCurve(const TopoDS_Edge& /*E*/,
142 Handle(Geom_Curve)& /*C*/,
143 TopLoc_Location& /*L*/,
144 Standard_Real& /*Tol*/)
146 return Standard_False;
150 //=======================================================================
151 //function : NewPoint
153 //=======================================================================
155 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewPoint(const TopoDS_Vertex& /*V*/,
157 Standard_Real& /*Tol*/)
159 return Standard_False;
163 //=======================================================================
164 //function : NewCurve2d
166 //=======================================================================
168 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewCurve2d(const TopoDS_Edge& E,
169 const TopoDS_Face& F,
170 const TopoDS_Edge& /*NewE*/,
171 const TopoDS_Face& /*NewF*/,
172 Handle(Geom2d_Curve)& C,
175 //check if undelying surface of the face was modified
176 if(myMapOfFaces.IsBound(F)) {
177 Standard_Integer anIndex = myMapOfFaces.Find(F);
179 Handle(Geom_Surface) aNewSurf = Handle(Geom_Surface)::DownCast(myMapOfSurfaces.FindKey(anIndex));
182 TopLoc_Location LC, LS;
183 Handle(Geom_Curve) C3d = BRep_Tool::Curve ( E, LC, f, l );
184 Handle(Geom_Surface) S = BRep_Tool::Surface(F, LS);
186 //taking into accound the orientation of the seam
187 C = BRep_Tool::CurveOnSurface(E,F,f,l);
188 Tol = BRep_Tool::Tolerance(E);
193 B.Add(TempE, TopExp::FirstVertex(E));
194 B.Add(TempE, TopExp::LastVertex(E));
197 B.UpdateEdge(TempE, Handle(Geom_Curve)::DownCast(C3d->Transformed(LC.Transformation())), Precision::Confusion());
198 B.Range(TempE, f, l);
200 Handle(ShapeFix_Edge) sfe = new ShapeFix_Edge;
201 Handle(Geom_Surface) STemp = Handle(Geom_Surface)::DownCast(aNewSurf->Transformed(LS.Transformation()));
202 TopLoc_Location LTemp;
205 Standard_Boolean isClosed = BRep_Tool::IsClosed (E, F);
206 Standard_Real aWorkTol = 2*myTolerance+Tol;
207 sfe->FixAddPCurve(TempE, STemp, LTemp, isClosed, Max(Precision::Confusion(), aWorkTol));
208 sfe->FixSameParameter(TempE);
210 //keep the orientation of original edge
211 TempE.Orientation(E.Orientation());
212 C = BRep_Tool::CurveOnSurface(TempE, STemp, LTemp, f, l);
214 //surface was modified
215 return Standard_True;
218 return Standard_False;
222 //=======================================================================
223 //function : NewParameter
225 //=======================================================================
227 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewParameter(const TopoDS_Vertex& /*V*/,
228 const TopoDS_Edge& /*E*/,
229 Standard_Real& /*P*/,
230 Standard_Real& /*Tol*/)
232 return Standard_False;
236 //=======================================================================
237 //function : Continuity
239 //=======================================================================
241 GeomAbs_Shape BlockFix_PeriodicSurfaceModifier::Continuity(const TopoDS_Edge& E,
242 const TopoDS_Face& F1,
243 const TopoDS_Face& F2,
244 const TopoDS_Edge& /*NewE*/,
245 const TopoDS_Face& /*NewF1*/,
246 const TopoDS_Face& /*NewF2*/)
248 return BRep_Tool::Continuity(E,F1,F2);