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
20 // File: BlockFix_PeriodicSurfaceModifier.cxx
21 // Created: 15.12.04 10:08:50
22 // Author: Sergey KUUL
23 // Copyright: Open CASCADE SA 2004
25 #include <BlockFix_PeriodicSurfaceModifier.ixx>
27 #include <BRep_Builder.hxx>
28 #include <BRep_Tool.hxx>
29 #include <BRepTools.hxx>
30 #include <Geom_CylindricalSurface.hxx>
31 #include <Geom_SphericalSurface.hxx>
32 #include <ShapeFix_Edge.hxx>
36 //=======================================================================
37 //function : BlockFix_PeriodicSurfaceModifier()
38 //purpose : Constructor
39 //=======================================================================
41 BlockFix_PeriodicSurfaceModifier::BlockFix_PeriodicSurfaceModifier ( )
44 myMapOfSurfaces.Clear();
48 //=======================================================================
49 //function : SetTolerance
51 //=======================================================================
53 void BlockFix_PeriodicSurfaceModifier::SetTolerance(const Standard_Real Tol)
59 //=======================================================================
60 //function : ModifySurface
62 //=======================================================================
64 static Standard_Boolean ModifySurface(const TopoDS_Face& aFace,
65 const Handle(Geom_Surface)& aSurface,
66 Handle(Geom_Surface)& aNewSurface)
68 Handle(Geom_Surface) S = aSurface;
70 if(S->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
71 Handle(Geom_CylindricalSurface) aCyl =
72 Handle(Geom_CylindricalSurface)::DownCast(S);
73 Standard_Real Umin, Umax, Vmin, Vmax;
74 BRepTools::UVBounds(aFace, Umin, Umax, Vmin, Vmax);
75 if( Umin<-Precision::PConfusion() || Umax>2*PI+Precision::PConfusion() ) {
76 gp_Ax3 ax3 = aCyl->Position();
77 gp_Ax1 NDir = ax3.Axis();
78 gp_Ax3 newax3 = ax3.Rotated(NDir,Umin-Precision::PConfusion());
79 Handle(Geom_CylindricalSurface) aNewCyl =
80 new Geom_CylindricalSurface(newax3,aCyl->Radius());
81 aNewSurface = aNewCyl;
86 if(S->IsKind(STANDARD_TYPE(Geom_SphericalSurface))) {
87 Handle(Geom_SphericalSurface) aSphere = Handle(Geom_SphericalSurface)::DownCast(S);
88 Standard_Real Umin, Umax, Vmin, Vmax;
89 BRepTools::UVBounds(aFace, Umin, Umax, Vmin, Vmax);
90 if( Umin<-Precision::PConfusion() || Umax>2*PI+Precision::PConfusion() ) {
91 gp_Ax3 ax3 = aSphere->Position();
92 gp_Ax1 NDir = ax3.Axis();
93 gp_Ax3 newax3 = ax3.Rotated(NDir,Umin-Precision::PConfusion());
94 Handle(Geom_SphericalSurface) aNewSphere = new Geom_SphericalSurface(newax3,aSphere->Radius());
95 aNewSurface = aNewSphere;
100 return Standard_False;
104 //=======================================================================
105 //function : NewSurface
107 //=======================================================================
109 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewSurface(const TopoDS_Face& F,
110 Handle(Geom_Surface)& S,
111 TopLoc_Location& L,Standard_Real& Tol,
112 Standard_Boolean& RevWires,
113 Standard_Boolean& RevFace)
116 Handle(Geom_Surface) SIni = BRep_Tool::Surface(F, LS);
118 if(ModifySurface(F, SIni, S)) {
120 RevWires = Standard_False;
121 RevFace = Standard_False;
124 Tol = BRep_Tool::Tolerance(F);
126 Standard_Integer anIndex = myMapOfSurfaces.Add(S);
127 myMapOfFaces.Bind(F,anIndex);
128 return Standard_True;
131 return Standard_False;
135 //=======================================================================
136 //function : NewCurve
138 //=======================================================================
140 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewCurve(const TopoDS_Edge& /*E*/,
141 Handle(Geom_Curve)& /*C*/,
142 TopLoc_Location& /*L*/,
143 Standard_Real& /*Tol*/)
145 return Standard_False;
149 //=======================================================================
150 //function : NewPoint
152 //=======================================================================
154 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewPoint(const TopoDS_Vertex& /*V*/,
156 Standard_Real& /*Tol*/)
158 return Standard_False;
162 //=======================================================================
163 //function : NewCurve2d
165 //=======================================================================
167 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewCurve2d(const TopoDS_Edge& E,
168 const TopoDS_Face& F,
169 const TopoDS_Edge& /*NewE*/,
170 const TopoDS_Face& /*NewF*/,
171 Handle(Geom2d_Curve)& C,
174 //check if undelying surface of the face was modified
175 if(myMapOfFaces.IsBound(F)) {
176 Standard_Integer anIndex = myMapOfFaces.Find(F);
178 Handle(Geom_Surface) aNewSurf = Handle(Geom_Surface)::DownCast(myMapOfSurfaces.FindKey(anIndex));
181 TopLoc_Location LC, LS;
182 Handle(Geom_Curve) C3d = BRep_Tool::Curve ( E, LC, f, l );
183 Handle(Geom_Surface) S = BRep_Tool::Surface(F, LS);
185 //taking into accound the orientation of the seam
186 C = BRep_Tool::CurveOnSurface(E,F,f,l);
187 Tol = BRep_Tool::Tolerance(E);
192 B.Add(TempE, TopExp::FirstVertex(E));
193 B.Add(TempE, TopExp::LastVertex(E));
196 B.UpdateEdge(TempE, Handle(Geom_Curve)::DownCast(C3d->Transformed(LC.Transformation())), Precision::Confusion());
197 B.Range(TempE, f, l);
199 Handle(ShapeFix_Edge) sfe = new ShapeFix_Edge;
200 Handle(Geom_Surface) STemp = Handle(Geom_Surface)::DownCast(aNewSurf->Transformed(LS.Transformation()));
201 TopLoc_Location LTemp;
204 Standard_Boolean isClosed = BRep_Tool::IsClosed (E, F);
205 Standard_Real aWorkTol = 2*myTolerance+Tol;
206 sfe->FixAddPCurve(TempE, STemp, LTemp, isClosed, Max(Precision::Confusion(), aWorkTol));
207 sfe->FixSameParameter(TempE);
209 //keep the orientation of original edge
210 TempE.Orientation(E.Orientation());
211 C = BRep_Tool::CurveOnSurface(TempE, STemp, LTemp, f, l);
213 //surface was modified
214 return Standard_True;
217 return Standard_False;
221 //=======================================================================
222 //function : NewParameter
224 //=======================================================================
226 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewParameter(const TopoDS_Vertex& /*V*/,
227 const TopoDS_Edge& /*E*/,
228 Standard_Real& /*P*/,
229 Standard_Real& /*Tol*/)
231 return Standard_False;
235 //=======================================================================
236 //function : Continuity
238 //=======================================================================
240 GeomAbs_Shape BlockFix_PeriodicSurfaceModifier::Continuity(const TopoDS_Edge& E,
241 const TopoDS_Face& F1,
242 const TopoDS_Face& F2,
243 const TopoDS_Edge& /*NewE*/,
244 const TopoDS_Face& /*NewF1*/,
245 const TopoDS_Face& /*NewF2*/)
247 return BRep_Tool::Continuity(E,F1,F2);