1 // Created on: 1994-02-03
2 // Created by: Isabelle GRIGNON
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Adaptor3d_HSurface.hxx>
19 #include <ChFiDS_Spine.hxx>
20 #include <ChFiDS_SurfData.hxx>
21 #include <ChFiKPart_ComputeData.hxx>
22 #include <ChFiKPart_ComputeData_Fcts.hxx>
25 #include <Geom2d_Circle.hxx>
26 #include <Geom2d_Line.hxx>
27 #include <Geom_Circle.hxx>
28 #include <Geom_Line.hxx>
29 #include <Geom_SphericalSurface.hxx>
30 #include <Geom_ToroidalSurface.hxx>
34 #include <gp_Circ.hxx>
35 #include <gp_Cone.hxx>
37 #include <gp_Dir2d.hxx>
39 #include <gp_Lin2d.hxx>
42 #include <gp_Pnt2d.hxx>
44 #include <IntAna_QuadQuadGeo.hxx>
45 #include <Precision.hxx>
46 #include <TopOpeBRepDS_DataStructure.hxx>
48 //=======================================================================
49 //function : MakeFillet
50 //purpose : case cone/plane or plane/cone.
51 //=======================================================================
52 Standard_Boolean ChFiKPart_MakeFillet(TopOpeBRepDS_DataStructure& DStr,
53 const Handle(ChFiDS_SurfData)& Data,
56 const Standard_Real fu,
57 const Standard_Real lu,
58 const TopAbs_Orientation Or1,
59 const TopAbs_Orientation Or2,
60 const Standard_Real Radius,
62 const Standard_Real First,
63 const TopAbs_Orientation Ofpl,
64 const Standard_Boolean plandab)
66 //calculate the fillet (torus or sphere).
67 Standard_Boolean c1sphere = Standard_False;
68 gp_Ax3 PosPl = Pln.Position();
69 gp_Dir Dpnat = PosPl.XDirection().Crossed(PosPl.YDirection());
72 if (Or1 == TopAbs_REVERSED) { Dp.Reverse(); }
73 if (Ofpl == TopAbs_REVERSED) { Df.Reverse(); }
75 gp_Pnt Or = Con.Location();
77 ElSLib::PlaneParameters(PosPl,Or,u,v);
79 ElSLib::PlaneD0(u,v,PosPl,Or);
81 Or.SetCoord(Or.X()+Radius*Dp.X(),
83 Or.Z()+Radius*Dp.Z());
87 ElCLib::D1(First,Spine,PtSp,DSp);
88 IntAna_QuadQuadGeo CInt (Pln,Con,Precision::Angular(),
89 Precision::Confusion());
92 //The origin of the fillet is set at the start point on the
94 Pv = ElCLib::Value(ElCLib::Parameter(CInt.Circle(1),PtSp),
97 else { return Standard_False; }
98 gp_Dir Dx(gp_Vec(cPln,Pv));
100 ElSLib::Parameters(Con,Pv,u,v);
103 ElSLib::D1(u,v,Con,PtCon,Vu,Vv);
104 gp_Dir Dc(Vu.Crossed(Vv));
105 if (Or2 == TopAbs_REVERSED) { Dc.Reverse(); }
108 gp_Pnt pp(Pv.X()+Dc.X(),Pv.Y()+Dc.Y(),Pv.Z()+Dc.Z());
109 ElSLib::PlaneParameters(PosPl,pp,u,v);
110 ElSLib::PlaneD0(u,v,PosPl,pp);
111 gp_Dir ddp(gp_Vec(Pv,pp));
112 ElSLib::Parameters(Con,Pv,u,v);
114 ElSLib::D1(u,v,Con,pp,dcu,dcv);
116 if(ddc.Dot(Dp) < 0.) ddc.Reverse();
117 Standard_Real Ang = ddp.Angle(ddc);
118 Standard_Real Rabio = Radius/Tan(Ang/2);
119 Standard_Real Maxrad = cPln.Distance(Pv);
121 Standard_Boolean dedans = Dx.Dot(Dc) <= 0. ;
123 if (!plandab){ Dz.Reverse(); }
124 Rad = Maxrad - Rabio;
125 if(Abs(Rad) <= Precision::Confusion()){ c1sphere = Standard_True; }
128 std::cout<<"the fillet does not pass"<<std::endl;
130 return Standard_False;
134 if (plandab){ Dz.Reverse(); }
135 Rad = Maxrad + Rabio;
137 gp_Ax3 FilAx3(Or,Dz,Dx);
138 if (FilAx3.YDirection().Dot(Dy) <= 0.){ FilAx3.YReverse(); }
141 Handle(Geom_SphericalSurface)
142 gsph = new Geom_SphericalSurface(FilAx3,Radius);
143 Data->ChangeSurf(ChFiKPart_IndexSurfaceInDS(gsph,DStr));
146 Handle(Geom_ToroidalSurface)
147 gtor = new Geom_ToroidalSurface(FilAx3,Rad,Radius);
148 Data->ChangeSurf(ChFiKPart_IndexSurfaceInDS(gtor,DStr));
151 // It is checked if the orientation of the fillet is the same
155 P.SetCoord(cPln.X()+Rad*Dx.X(),
157 cPln.Z()+Rad*Dx.Z());
159 ElSLib::SphereParameters(FilAx3,Rad,P,u,v);
160 ElSLib::SphereD1(u,v,FilAx3,Rad,PP,deru,derv);
163 ElSLib::TorusParameters(FilAx3,Rad,Radius,P,u,v);
164 ElSLib::TorusD1(u,v,FilAx3,Rad,Radius,PP,deru,derv);
165 if(!plandab && Ang < M_PI/2 && dedans) v = v + 2*M_PI;
167 gp_Pnt2d p2dFil(0.,v);
168 gp_Dir norFil(deru.Crossed(derv));
169 Standard_Boolean toreverse = ( norFil.Dot(Df) <= 0. );
170 if (toreverse) { Data->ChangeOrientation() = TopAbs_REVERSED; }
171 else { Data->ChangeOrientation() = TopAbs_FORWARD; }
173 // FaceInterferences are loaded with pcurves and curves 3d.
174 // ---------------------------------------------------------------
179 Handle(Geom2d_Circle) GCirc2dPln;
180 Handle(Geom_Circle) GCircPln;
181 gp_Ax2 circAx2 = FilAx3.Ax2();
183 ElSLib::PlaneParameters(PosPl,P,u,v);
184 gp_Pnt2d p2dPln(u,v);
185 gp_Dir2d d2d(DSp.Dot(PosPl.XDirection()),DSp.Dot(PosPl.YDirection()));
186 gp_Ax22d ax2dPln(c2dPln,gp_Dir2d(gp_Vec2d(c2dPln,p2dPln)),d2d);
187 gp_Circ2d circ2dPln(ax2dPln,Rad);
188 GCirc2dPln = new Geom2d_Circle(circ2dPln);
189 circAx2.SetLocation(cPln);
190 gp_Circ circPln(circAx2,Rad);
191 GCircPln = new Geom_Circle(circPln);
193 gp_Lin2d lin2dFil(p2dFil,gp::DX2d());
194 Handle(Geom2d_Line) GLin2dFil1 = new Geom2d_Line(lin2dFil);
195 toreverse = ( norFil.Dot(Dpnat) <= 0. );
196 TopAbs_Orientation trans;
197 if ((toreverse && plandab) || (!toreverse && !plandab) ){
198 trans = TopAbs_FORWARD;
201 trans = TopAbs_REVERSED;
204 Data->ChangeInterferenceOnS1().
205 SetInterference(ChFiKPart_IndexCurveInDS(GCircPln,DStr),
206 trans,GCirc2dPln,GLin2dFil1);
209 Data->ChangeInterferenceOnS2().
210 SetInterference(ChFiKPart_IndexCurveInDS(GCircPln,DStr),
211 trans,GCirc2dPln,GLin2dFil1);
217 P.SetCoord(Pv.X()+Rabio*ddc.X(),
218 Pv.Y()+Rabio*ddc.Y(),
219 Pv.Z()+Rabio*ddc.Z());
221 ElSLib::SphereParameters(FilAx3,Radius,P,u,v);
222 ElSLib::SphereD1(u,v,FilAx3,Radius,PP,deru,derv);
225 ElSLib::TorusParameters(FilAx3,Rad,Radius,P,u,v);
226 ElSLib::TorusD1(u,v,FilAx3,Rad,Radius,PP,deru,derv);
227 if(plandab && Ang < M_PI/2 && dedans) v = v + 2*M_PI;
229 norFil = deru.Crossed(derv);
230 p2dFil.SetCoord(0.,v);
231 lin2dFil.SetLocation(p2dFil);
232 Handle(Geom2d_Line) GLin2dFil2 = new Geom2d_Line(lin2dFil);
233 ElSLib::Parameters(Con,P,u,v);
234 Standard_Real tol = Precision::PConfusion();
235 Standard_Boolean careaboutsens = 0;
236 if(Abs(lu - fu - 2*M_PI) < tol) careaboutsens = 1;
237 if(u >= fu - tol && u < fu) u = fu;
238 if(u <= lu + tol && u > lu) u = lu;
239 if(u < fu || u > lu) u = ElCLib::InPeriod(u,fu,fu + 2*M_PI);
240 ElSLib::D1(u,v,Con,PP,deru,derv);
241 gp_Dir norCon = deru.Crossed(derv);
242 gp_Dir2d d2dCon = gp::DX2d();
243 if( deru.Dot(Dy) < 0. ){
245 if(careaboutsens && Abs(fu-u)<tol) u = lu;
247 else if(careaboutsens && Abs(lu-u)<tol) u = fu;
248 gp_Pnt2d p2dCon(u,v);
249 gp_Lin2d lin2dCon(p2dCon,d2dCon);
250 Handle(Geom2d_Line) GLin2dCon = new Geom2d_Line(lin2dCon);
251 Standard_Real scal = gp_Vec(Dp).Dot(gp_Vec(Pv,P));
252 PP.SetCoord(cPln.X()+scal*Dp.X(),
253 cPln.Y()+scal*Dp.Y(),
254 cPln.Z()+scal*Dp.Z());
255 circAx2.SetLocation(PP);
256 gp_Circ circCon(circAx2,P.Distance(PP));
257 Handle(Geom_Circle) GCircCon = new Geom_Circle(circCon);
258 toreverse = ( norFil.Dot(norCon) <= 0. );
259 if ((toreverse && plandab) || (!toreverse && !plandab) ){
260 trans = TopAbs_REVERSED;
263 trans = TopAbs_FORWARD;
266 Data->ChangeInterferenceOnS2().
267 SetInterference(ChFiKPart_IndexCurveInDS(GCircCon,DStr),
268 trans,GLin2dCon,GLin2dFil2);
271 Data->ChangeInterferenceOnS1().
272 SetInterference(ChFiKPart_IndexCurveInDS(GCircCon,DStr),
273 trans,GLin2dCon,GLin2dFil2);
275 return Standard_True;