1 // Copyright (C) 2007-2021 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_RTTIEXT(BlockFix_PeriodicSurfaceModifier, BRepTools_Modification)
55 //=======================================================================
56 //function : BlockFix_PeriodicSurfaceModifier()
57 //purpose : Constructor
58 //=======================================================================
59 BlockFix_PeriodicSurfaceModifier::BlockFix_PeriodicSurfaceModifier()
62 myMapOfSurfaces.Clear();
65 //=======================================================================
66 //function : ~BlockFix_PeriodicSurfaceModifier()
67 //purpose : Destructor
68 //=======================================================================
69 BlockFix_PeriodicSurfaceModifier::~BlockFix_PeriodicSurfaceModifier()
73 //=======================================================================
74 //function : SetTolerance
76 //=======================================================================
77 void BlockFix_PeriodicSurfaceModifier::SetTolerance(const Standard_Real Tol)
82 //=======================================================================
83 //function : ModifySurface
85 //=======================================================================
86 static Standard_Boolean ModifySurface(const TopoDS_Face& aFace,
87 const Handle(Geom_Surface)& aSurface,
88 Handle(Geom_Surface)& aNewSurface)
90 Handle(Geom_Surface) S = aSurface;
92 if(S->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
93 Handle(Geom_CylindricalSurface) aCyl =
94 Handle(Geom_CylindricalSurface)::DownCast(S);
95 Standard_Real Umin, Umax, Vmin, Vmax;
96 BRepTools::UVBounds(aFace, Umin, Umax, Vmin, Vmax);
97 if (Umin < -Precision::PConfusion() || Umax > 2*M_PI + Precision::PConfusion()) {
98 gp_Ax3 ax3 = aCyl->Position();
99 gp_Ax1 NDir = ax3.Axis();
100 gp_Ax3 newax3 = ax3.Rotated(NDir,Umin-Precision::PConfusion());
101 Handle(Geom_CylindricalSurface) aNewCyl =
102 new Geom_CylindricalSurface(newax3,aCyl->Radius());
103 aNewSurface = aNewCyl;
104 return Standard_True;
108 if(S->IsKind(STANDARD_TYPE(Geom_SphericalSurface))) {
109 Handle(Geom_SphericalSurface) aSphere = Handle(Geom_SphericalSurface)::DownCast(S);
110 Standard_Real Umin, Umax, Vmin, Vmax;
111 BRepTools::UVBounds(aFace, Umin, Umax, Vmin, Vmax);
112 if (Umin < -Precision::PConfusion() || Umax > 2*M_PI + Precision::PConfusion()) {
113 gp_Ax3 ax3 = aSphere->Position();
114 gp_Ax1 NDir = ax3.Axis();
115 gp_Ax3 newax3 = ax3.Rotated(NDir,Umin-Precision::PConfusion());
116 Handle(Geom_SphericalSurface) aNewSphere = new Geom_SphericalSurface(newax3,aSphere->Radius());
117 aNewSurface = aNewSphere;
118 return Standard_True;
122 return Standard_False;
125 //=======================================================================
126 //function : NewSurface
128 //=======================================================================
129 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewSurface(const TopoDS_Face& F,
130 Handle(Geom_Surface)& S,
131 TopLoc_Location& L,Standard_Real& Tol,
132 Standard_Boolean& RevWires,
133 Standard_Boolean& RevFace)
136 Handle(Geom_Surface) SIni = BRep_Tool::Surface(F, LS);
138 if(ModifySurface(F, SIni, S)) {
140 RevWires = Standard_False;
141 RevFace = Standard_False;
144 Tol = BRep_Tool::Tolerance(F);
146 Standard_Integer anIndex = myMapOfSurfaces.Add(S);
147 myMapOfFaces.Bind(F,anIndex);
148 return Standard_True;
151 return Standard_False;
154 //=======================================================================
155 //function : NewCurve
157 //=======================================================================
158 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewCurve(const TopoDS_Edge& /*E*/,
159 Handle(Geom_Curve)& /*C*/,
160 TopLoc_Location& /*L*/,
161 Standard_Real& /*Tol*/)
163 return Standard_False;
166 //=======================================================================
167 //function : NewPoint
169 //=======================================================================
170 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewPoint(const TopoDS_Vertex& /*V*/,
172 Standard_Real& /*Tol*/)
174 return Standard_False;
177 //=======================================================================
178 //function : NewCurve2d
180 //=======================================================================
181 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewCurve2d(const TopoDS_Edge& E,
182 const TopoDS_Face& F,
183 const TopoDS_Edge& /*NewE*/,
184 const TopoDS_Face& /*NewF*/,
185 Handle(Geom2d_Curve)& C,
188 //check if undelying surface of the face was modified
189 if(myMapOfFaces.IsBound(F)) {
190 Standard_Integer anIndex = myMapOfFaces.Find(F);
192 Handle(Geom_Surface) aNewSurf = Handle(Geom_Surface)::DownCast(myMapOfSurfaces.FindKey(anIndex));
195 TopLoc_Location LC, LS;
196 Handle(Geom_Curve) C3d = BRep_Tool::Curve ( E, LC, f, l );
197 Handle(Geom_Surface) S = BRep_Tool::Surface(F, LS);
199 //taking into account the orientation of the seam
200 C = BRep_Tool::CurveOnSurface(E,F,f,l);
201 Tol = BRep_Tool::Tolerance(E);
206 B.Add(TempE, TopExp::FirstVertex(E));
207 B.Add(TempE, TopExp::LastVertex(E));
210 B.UpdateEdge(TempE, Handle(Geom_Curve)::DownCast(C3d->Transformed(LC.Transformation())), Precision::Confusion());
211 B.Range(TempE, f, l);
213 Handle(ShapeFix_Edge) sfe = new ShapeFix_Edge;
214 Handle(Geom_Surface) STemp = Handle(Geom_Surface)::DownCast(aNewSurf->Transformed(LS.Transformation()));
215 TopLoc_Location LTemp;
218 Standard_Boolean isClosed = BRep_Tool::IsClosed (E, F);
219 Standard_Real aWorkTol = 2*myTolerance+Tol;
220 sfe->FixAddPCurve(TempE, STemp, LTemp, isClosed, Max(Precision::Confusion(), aWorkTol));
221 sfe->FixSameParameter(TempE);
223 //keep the orientation of original edge
224 TempE.Orientation(E.Orientation());
225 C = BRep_Tool::CurveOnSurface(TempE, STemp, LTemp, f, l);
227 //surface was modified
228 return Standard_True;
231 return Standard_False;
234 //=======================================================================
235 //function : NewParameter
237 //=======================================================================
238 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewParameter(const TopoDS_Vertex& /*V*/,
239 const TopoDS_Edge& /*E*/,
240 Standard_Real& /*P*/,
241 Standard_Real& /*Tol*/)
243 return Standard_False;
246 //=======================================================================
247 //function : Continuity
249 //=======================================================================
250 GeomAbs_Shape BlockFix_PeriodicSurfaceModifier::Continuity(const TopoDS_Edge& E,
251 const TopoDS_Face& F1,
252 const TopoDS_Face& F2,
253 const TopoDS_Edge& /*NewE*/,
254 const TopoDS_Face& /*NewF1*/,
255 const TopoDS_Face& /*NewF2*/)
257 return BRep_Tool::Continuity(E,F1,F2);