1 // File: BlockFix_PeriodicSurfaceModifier.cxx
2 // Created: 15.12.04 10:08:50
4 // Copyright: Open CASCADE SA 2004
6 #include <BlockFix_PeriodicSurfaceModifier.ixx>
8 #include <BRep_Builder.hxx>
9 #include <BRep_Tool.hxx>
10 #include <BRepTools.hxx>
11 #include <Geom_CylindricalSurface.hxx>
12 #include <Geom_SphericalSurface.hxx>
13 #include <ShapeFix_Edge.hxx>
17 //=======================================================================
18 //function : BlockFix_PeriodicSurfaceModifier()
19 //purpose : Constructor
20 //=======================================================================
22 BlockFix_PeriodicSurfaceModifier::BlockFix_PeriodicSurfaceModifier ( )
25 myMapOfSurfaces.Clear();
29 //=======================================================================
30 //function : SetTolerance
32 //=======================================================================
34 void BlockFix_PeriodicSurfaceModifier::SetTolerance(const Standard_Real Tol)
40 //=======================================================================
41 //function : ModifySurface
43 //=======================================================================
45 static Standard_Boolean ModifySurface(const TopoDS_Face& aFace,
46 const Handle(Geom_Surface)& aSurface,
47 Handle(Geom_Surface)& aNewSurface)
49 Handle(Geom_Surface) S = aSurface;
51 if(S->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
52 Handle(Geom_CylindricalSurface) aCyl =
53 Handle(Geom_CylindricalSurface)::DownCast(S);
54 Standard_Real Umin, Umax, Vmin, Vmax;
55 BRepTools::UVBounds(aFace, Umin, Umax, Vmin, Vmax);
56 if( Umin<-Precision::PConfusion() || Umax>2*PI+Precision::PConfusion() ) {
57 gp_Ax3 ax3 = aCyl->Position();
58 gp_Ax1 NDir = ax3.Axis();
59 gp_Ax3 newax3 = ax3.Rotated(NDir,Umin-Precision::PConfusion());
60 Handle(Geom_CylindricalSurface) aNewCyl =
61 new Geom_CylindricalSurface(newax3,aCyl->Radius());
62 aNewSurface = aNewCyl;
67 if(S->IsKind(STANDARD_TYPE(Geom_SphericalSurface))) {
68 Handle(Geom_SphericalSurface) aSphere = Handle(Geom_SphericalSurface)::DownCast(S);
69 Standard_Real Umin, Umax, Vmin, Vmax;
70 BRepTools::UVBounds(aFace, Umin, Umax, Vmin, Vmax);
71 if( Umin<-Precision::PConfusion() || Umax>2*PI+Precision::PConfusion() ) {
72 gp_Ax3 ax3 = aSphere->Position();
73 gp_Ax1 NDir = ax3.Axis();
74 gp_Ax3 newax3 = ax3.Rotated(NDir,Umin-Precision::PConfusion());
75 Handle(Geom_SphericalSurface) aNewSphere = new Geom_SphericalSurface(newax3,aSphere->Radius());
76 aNewSurface = aNewSphere;
81 return Standard_False;
85 //=======================================================================
86 //function : NewSurface
88 //=======================================================================
90 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewSurface(const TopoDS_Face& F,
91 Handle(Geom_Surface)& S,
92 TopLoc_Location& L,Standard_Real& Tol,
93 Standard_Boolean& RevWires,
94 Standard_Boolean& RevFace)
97 Handle(Geom_Surface) SIni = BRep_Tool::Surface(F, LS);
99 if(ModifySurface(F, SIni, S)) {
101 RevWires = Standard_False;
102 RevFace = Standard_False;
105 Tol = BRep_Tool::Tolerance(F);
107 Standard_Integer anIndex = myMapOfSurfaces.Add(S);
108 myMapOfFaces.Bind(F,anIndex);
109 return Standard_True;
112 return Standard_False;
116 //=======================================================================
117 //function : NewCurve
119 //=======================================================================
121 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewCurve(const TopoDS_Edge& /*E*/,
122 Handle(Geom_Curve)& /*C*/,
123 TopLoc_Location& /*L*/,
124 Standard_Real& /*Tol*/)
126 return Standard_False;
130 //=======================================================================
131 //function : NewPoint
133 //=======================================================================
135 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewPoint(const TopoDS_Vertex& /*V*/,
137 Standard_Real& /*Tol*/)
139 return Standard_False;
143 //=======================================================================
144 //function : NewCurve2d
146 //=======================================================================
148 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewCurve2d(const TopoDS_Edge& E,
149 const TopoDS_Face& F,
150 const TopoDS_Edge& /*NewE*/,
151 const TopoDS_Face& /*NewF*/,
152 Handle(Geom2d_Curve)& C,
155 //check if undelying surface of the face was modified
156 if(myMapOfFaces.IsBound(F)) {
157 Standard_Integer anIndex = myMapOfFaces.Find(F);
159 Handle(Geom_Surface) aNewSurf = Handle(Geom_Surface)::DownCast(myMapOfSurfaces.FindKey(anIndex));
162 TopLoc_Location LC, LS;
163 Handle(Geom_Curve) C3d = BRep_Tool::Curve ( E, LC, f, l );
164 Handle(Geom_Surface) S = BRep_Tool::Surface(F, LS);
166 //taking into accound the orientation of the seam
167 C = BRep_Tool::CurveOnSurface(E,F,f,l);
168 Tol = BRep_Tool::Tolerance(E);
173 B.Add(TempE, TopExp::FirstVertex(E));
174 B.Add(TempE, TopExp::LastVertex(E));
177 B.UpdateEdge(TempE, Handle(Geom_Curve)::DownCast(C3d->Transformed(LC.Transformation())), Precision::Confusion());
178 B.Range(TempE, f, l);
180 Handle(ShapeFix_Edge) sfe = new ShapeFix_Edge;
181 Handle(Geom_Surface) STemp = Handle(Geom_Surface)::DownCast(aNewSurf->Transformed(LS.Transformation()));
182 TopLoc_Location LTemp;
185 Standard_Boolean isClosed = BRep_Tool::IsClosed (E, F);
186 Standard_Real aWorkTol = 2*myTolerance+Tol;
187 sfe->FixAddPCurve(TempE, STemp, LTemp, isClosed, Max(Precision::Confusion(), aWorkTol));
188 sfe->FixSameParameter(TempE);
190 //keep the orientation of original edge
191 TempE.Orientation(E.Orientation());
192 C = BRep_Tool::CurveOnSurface(TempE, STemp, LTemp, f, l);
194 //surface was modified
195 return Standard_True;
198 return Standard_False;
202 //=======================================================================
203 //function : NewParameter
205 //=======================================================================
207 Standard_Boolean BlockFix_PeriodicSurfaceModifier::NewParameter(const TopoDS_Vertex& /*V*/,
208 const TopoDS_Edge& /*E*/,
209 Standard_Real& /*P*/,
210 Standard_Real& /*Tol*/)
212 return Standard_False;
216 //=======================================================================
217 //function : Continuity
219 //=======================================================================
221 GeomAbs_Shape BlockFix_PeriodicSurfaceModifier::Continuity(const TopoDS_Edge& E,
222 const TopoDS_Face& F1,
223 const TopoDS_Face& F2,
224 const TopoDS_Edge& /*NewE*/,
225 const TopoDS_Face& /*NewF1*/,
226 const TopoDS_Face& /*NewF2*/)
228 return BRep_Tool::Continuity(E,F1,F2);