1 // Created on: 1998-06-18
2 // Created by: Philippe NOUAILLE
3 // Copyright (c) 1998-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_ConicalSurface.hxx>
29 #include <Geom_CylindricalSurface.hxx>
33 #include <gp_Circ.hxx>
35 #include <gp_Dir2d.hxx>
36 #include <gp_Lin2d.hxx>
38 #include <gp_Pnt2d.hxx>
40 #include <Precision.hxx>
41 #include <TopOpeBRepDS_DataStructure.hxx>
43 //=======================================================================
44 //function : MakeChAsym
45 //purpose : Compute the chamfer in the particular case Plane/Cone or
47 // Compute the SurfData <Data> of the chamfer build on the <Spine>
48 // between the plane <Pln> and the cone <Con>, with the
49 // distances <Dis1> on <Pln> and <Dis2> on <Con>.
50 // <Or1> and <Or2> are the orientations of <Pln> and <Con>
51 // and <Ofpl> this of the face carried by <Pln>.
52 // <First> is the start point on the <Spine>
53 // <Plandab> is equal to True if the plane is the surface S1
54 // <fu> and <lu> are the first and last u parameters of the
56 //out : True if the chanfer has been computed
58 //=======================================================================
59 Standard_Boolean ChFiKPart_MakeChAsym(TopOpeBRepDS_DataStructure& DStr,
60 const Handle(ChFiDS_SurfData)& Data,
63 const Standard_Real fu,
64 const Standard_Real lu,
65 const TopAbs_Orientation Or1,
66 const TopAbs_Orientation Or2,
67 const Standard_Real Dis,
68 const Standard_Real Angle,
70 const Standard_Real First,
71 const TopAbs_Orientation Ofpl,
72 const Standard_Boolean plandab,
73 const Standard_Boolean DisOnP)
75 // Compute the chamfer surface(cone)
76 gp_Ax3 PosPl = Pln.Position();
77 gp_Dir Dpl = PosPl.XDirection().Crossed(PosPl.YDirection());
79 if (Ofpl == TopAbs_REVERSED ) norf.Reverse();
80 if ( Or1 == TopAbs_REVERSED ) Dpl.Reverse();
82 // compute the origin of the conical chamfer PtPl
83 gp_Pnt Or = Con.Location();
85 ElSLib::PlaneParameters(PosPl,Or,u,v);
86 gp_Pnt2d pt2dPln(u,v);
87 ElSLib::PlaneD0(u,v,PosPl,Or);
92 ElCLib::D1(First,Spine,PtSp,DSp);
93 gp_Dir Dx(gp_Vec(PtPl,PtSp));
95 //compute the normal to the cone in PtSp
98 ElSLib::Parameters(Con,PtSp,u,v);
99 ElSLib::D1(u,v,Con,PtCon ,deru,derv);
100 gp_Dir Dcon( deru.Crossed(derv) );
101 if ( Or2 == TopAbs_REVERSED ) Dcon.Reverse();
103 Standard_Boolean dedans = ( Dx.Dot(Dcon) <= 0.);
104 Standard_Boolean ouvert = ( Dpl.Dot(Dcon) >= 0.);
106 // variables used to compute the semiangle of the chamfer
107 Standard_Real angCon = Con.SemiAngle();
109 Standard_Real ChamfRad,SemiAngl;
110 Standard_Boolean pointu = Standard_False;
112 Standard_Boolean iscylinder = Standard_False;
113 Standard_Boolean isConPar = Standard_False;
115 if ( (plandab && DisOnP) || (!plandab && !DisOnP) ) {
116 Standard_Real tgang = Tan(Angle), Dis11;
117 Standard_Real tgCon = Abs(Tan(angCon));
119 move = Dis * tgang / (1. - tgCon * tgang);
120 Dis11 = move * tgCon;
124 move = Dis * tgang / (1. + tgCon * tgang);
125 Dis11 = move * tgCon;
129 // compute the parameters of the conical chamfer
131 ChamfRad = Spine.Radius() - Dis;
132 if ( Abs(ChamfRad) < Precision::Confusion() ) pointu = Standard_True;
135 cout<<"the chamfer can't pass"<<endl;
137 return Standard_False;
139 SemiAngl = M_PI / 2. - Angle;
142 ChamfRad = Spine.Radius() + Dis;
143 SemiAngl = Angle - M_PI / 2.;
147 if (Abs(angCon) - Abs(SemiAngl) > -Precision::Confusion() ) {
149 cout<<"wrong choice of angle for the chamfer"<<endl;
151 return Standard_False;
157 move = Dis * Cos(angCon);
159 SemiAngl = Abs(angCon) + Angle;
161 if ( (M_PI / 2. - SemiAngl) < Precision::Confusion() ) {
163 cout <<"wrong choice of angle for the chamfer"<<endl;
165 return Standard_False;
167 Dis1 = move * Tan(SemiAngl) - Dis * Abs(Sin(angCon));
169 if (!dedans) SemiAngl = -SemiAngl;
173 SemiAngl = Abs(angCon) - Angle;
175 if ( Abs(SemiAngl) < Precision::Confusion() ) {
176 iscylinder = Standard_True;
177 Dis1 = Dis * Abs(Sin(angCon));
180 Dis1 = Dis * Abs(Sin(angCon)) - move * Tan(SemiAngl);
183 if (SemiAngl > Precision::Confusion())
184 isConPar = Standard_True;
186 if (dedans) SemiAngl = -SemiAngl;
190 // compute the parameters of the conical chamfer
192 ChamfRad = Spine.Radius() - Dis1;
194 if ( Abs(ChamfRad) < Precision::Confusion() ) pointu = Standard_True;
197 cout<<"the chamfer can't pass"<<endl;
199 return Standard_False;
203 ChamfRad = Spine.Radius() + Dis1;
208 dis = Dis1 + Dis * Abs(Sin(angCon));
210 dis = Dis1 - Dis * Abs(Sin(angCon));
213 Or.SetCoord( Or.X()+ move*Dpl.X(),
214 Or.Y()+ move*Dpl.Y(),
215 Or.Z()+ move*Dpl.Z());
216 gp_Pnt Pt(Or.X()+dis*PosPl.XDirection().X(),
217 Or.Y()+dis*PosPl.XDirection().Y(),
218 Or.Z()+dis*PosPl.XDirection().Z());
220 gp_Ax3 ChamfAx3(PtPl,Dpl,Dx);
224 Handle (Geom_CylindricalSurface)
225 gcyl = new Geom_CylindricalSurface( ChamfAx3, ChamfRad );
227 // changes due to the fact the parameters of the chamfer must go increasing
228 // from surface S1 to surface S2
230 gcyl->VReverse();// be carefull : the SemiAngle was changed
231 ChamfAx3 = gcyl->Position();
234 // changes due to the fact we have reversed the V direction of
236 if (ChamfAx3.YDirection().Dot(DSp) <= 0.) {
238 gcyl->SetPosition(ChamfAx3);
241 Data->ChangeSurf(ChFiKPart_IndexSurfaceInDS(gcyl,DStr));
243 Standard_Boolean torevcha = !ChamfAx3.Direct();
244 gp_Dir cylaxe = (ChamfAx3.Axis()).Direction();
245 torevcha = ( (torevcha && !plandab) || (!torevcha && plandab));
247 if (torevcha) cylaxe.Reverse();
248 Standard_Boolean toreverse = (norf.Dot(cylaxe) < 0.);
250 if ((toreverse && dedans) || (!toreverse && !dedans))
251 Data->ChangeOrientation() = TopAbs_REVERSED;
253 Data->ChangeOrientation() = TopAbs_FORWARD;
255 //we load the faceInterference with the pcurves and
258 // Case of the plane face
259 // NB: in the case 'pointu', no pcurve on the plane surface
260 // and no intersection plane-chamfer are needed
262 // intersection plane-chamfer
263 Handle(Geom_Circle) GCirPln;
264 Handle(Geom2d_Circle) GCir2dPln;
265 gp_Ax2 CirAx2 = ChamfAx3.Ax2();
266 CirAx2.SetLocation(PtPl);
268 Pt.SetCoord(PtPl.X()+ChamfRad*Dx.X(),
269 PtPl.Y()+ChamfRad*Dx.Y(),
270 PtPl.Z()+ChamfRad*Dx.Z());
271 gp_Circ CirPln(CirAx2,ChamfRad);
272 GCirPln = new Geom_Circle(CirPln);
274 //pcurve on the plane
275 ElSLib::PlaneParameters(PosPl,Pt ,u,v);
276 gp_Pnt2d p2dPln(u,v);
277 gp_Dir2d d2d(DSp.Dot(PosPl.XDirection()),DSp.Dot(PosPl.YDirection()));
278 gp_Ax22d ax2dPln(pt2dPln, gp_Dir2d(gp_Vec2d(pt2dPln,p2dPln)),d2d);
279 gp_Circ2d cir2dPln(ax2dPln,ChamfRad);
280 GCir2dPln = new Geom2d_Circle(cir2dPln);
284 p2dch.SetCoord(0.,0.);
285 // ElSLib::CylinderD1(0.,0.,ChamfAx3,ChamfRad,Pt,deru,derv);
286 gp_Lin2d lin2dch(p2dch,gp::DX2d());
287 Handle(Geom2d_Line) GLin2dCh1 = new Geom2d_Line(lin2dch);
290 TopAbs_Orientation trans;
291 gp_Dir norpl = PosPl.XDirection().Crossed(PosPl.YDirection());
292 toreverse = (norpl.Dot(cylaxe) < 0.);
294 toreverse = (toreverse && plandab) || (!toreverse && !plandab);
296 if ((toreverse && dedans) || (!toreverse && !dedans)) {
297 trans = TopAbs_FORWARD;
300 trans = TopAbs_REVERSED;
304 Data->ChangeInterferenceOnS1().
305 SetInterference(ChFiKPart_IndexCurveInDS(GCirPln,DStr),
306 trans,GCir2dPln,GLin2dCh1);
309 Data->ChangeInterferenceOnS2().
310 SetInterference(ChFiKPart_IndexCurveInDS(GCirPln,DStr),
311 trans,GCir2dPln,GLin2dCh1);
314 // Case of the conical face
316 //intersection cone-chamfer
319 Rad = ChamfRad + dis;
321 Rad = ChamfRad - dis;
323 CirAx2.SetLocation(Or);
324 gp_Circ CirCon(CirAx2, Rad);
325 Handle(Geom_Circle) GCirCon = new Geom_Circle(CirCon);
329 v = sqrt(dis*dis + move*move);
331 v = - sqrt(dis*dis + move*move);
332 p2dch.SetCoord(0.,v);
333 ElSLib::CylinderD1(0.,v,ChamfAx3,ChamfRad,Pt,deru,derv);
334 lin2dch.SetLocation(p2dch);
335 Handle(Geom2d_Line) GLin2dCh2 = new Geom2d_Line(lin2dch);
338 Pt.SetCoord(Or.X()+Rad*Dx.X(),
341 ElSLib::Parameters(Con,Pt ,u,v);
342 Standard_Real tol = Precision::PConfusion();
343 if(u >= 2*M_PI - tol && u <= 2*M_PI) u = 0.;
344 if(u >= fu - tol && u < fu) u = fu;
345 if(u <= lu + tol && u > lu) u = lu;
346 if(u < fu || u > lu) u = ElCLib::InPeriod(u,fu,fu + 2*M_PI);
347 ElSLib::D1(u,v,Con,Pt,deru,derv);
348 gp_Pnt2d p2dCon(u,v);
350 if ( deru.Dot(DSp)<=0. )
351 d2dCon = - gp::DX2d();
354 gp_Lin2d lin2dCon(p2dCon,d2dCon);
355 Handle(Geom2d_Line) GLin2dCon = new Geom2d_Line(lin2dCon);
358 gp_Dir norcon = deru.Crossed(derv);
360 gp_Dir DirCon = (Con.Axis()).Direction();
361 if (angCon > Precision::Confusion()) DirCon.Reverse();
362 Standard_Boolean torevcon = ( norcon.Dot(DirCon) < 0. );
364 if ((torevcon && dedans) || (!torevcon && !dedans) ) {
365 trans = TopAbs_REVERSED;
368 trans = TopAbs_FORWARD;
372 Data->ChangeInterferenceOnS2().
373 SetInterference(ChFiKPart_IndexCurveInDS(GCirCon,DStr),
374 trans,GLin2dCon,GLin2dCh2);
377 Data->ChangeInterferenceOnS1().
378 SetInterference(ChFiKPart_IndexCurveInDS(GCirCon,DStr),
379 trans,GLin2dCon,GLin2dCh2);
383 Handle (Geom_ConicalSurface)
384 gcon = new Geom_ConicalSurface( ChamfAx3, SemiAngl, ChamfRad );
386 // changes due to the fact the parameters of the chamfer must go increasing
387 // from surface S1 to surface S2
389 gcon->VReverse();// be carefull : the SemiAngle was changed
390 ChamfAx3 = gcon->Position();
391 SemiAngl = gcon->SemiAngle();
394 // changes due to the fact we have reversed the V direction of
396 if (ChamfAx3.YDirection().Dot(DSp) <= 0.) {
398 gcon->SetPosition(ChamfAx3);
401 Data->ChangeSurf(ChFiKPart_IndexSurfaceInDS(gcon,DStr));
403 //compute the chamfer's orientation according to the orientation
406 //search the normal to the conical chamfer
410 v = sqrt(dis*dis + move*move);
412 v = - sqrt(dis*dis + move*move);
414 ElSLib::ConeD1(u,v,ChamfAx3,ChamfRad,SemiAngl,P,deru,derv);
415 gp_Dir norchamf(deru.Crossed(derv));
417 Standard_Boolean toreverse = (norf.Dot(norchamf) < 0.);
419 if (isConPar) toreverse = !toreverse;
422 Data->ChangeOrientation() = TopAbs_REVERSED;
424 Data->ChangeOrientation() = TopAbs_FORWARD;
426 //we load the faceInterference with the pcurves and
429 // Case of the plane face
430 // NB: in the case 'pointu', no pcurve on the plane surface
431 // and no intersection plane-chamfer are needed
433 // intersection plane-chamfer
434 Handle(Geom_Circle) GCirPln;
435 Handle(Geom2d_Circle) GCir2dPln;
436 gp_Ax2 CirAx2 = ChamfAx3.Ax2();
437 CirAx2.SetLocation(PtPl);
440 Pt.SetCoord(PtPl.X()+ChamfRad*Dx.X(),
441 PtPl.Y()+ChamfRad*Dx.Y(),
442 PtPl.Z()+ChamfRad*Dx.Z());
443 gp_Circ CirPln(CirAx2,ChamfRad);
444 GCirPln = new Geom_Circle(CirPln);
446 //pcurve on the plane
447 ElSLib::PlaneParameters(PosPl,Pt ,u,v);
448 gp_Pnt2d p2dPln(u,v);
449 gp_Dir2d d2d(DSp.Dot(PosPl.XDirection()),DSp.Dot(PosPl.YDirection()));
450 gp_Ax22d ax2dPln(pt2dPln, gp_Dir2d(gp_Vec2d(pt2dPln,p2dPln)),d2d);
451 gp_Circ2d cir2dPln(ax2dPln,ChamfRad);
452 GCir2dPln = new Geom2d_Circle(cir2dPln);
457 p2dch.SetCoord(0.,0.);
458 ElSLib::ConeD1(0.,0.,ChamfAx3,ChamfRad,SemiAngl,Pt,deru,derv);
459 gp_Lin2d lin2dch(p2dch,gp::DX2d());
460 Handle(Geom2d_Line) GLin2dCh1 = new Geom2d_Line(lin2dch);
463 TopAbs_Orientation trans;
464 gp_Dir norpl = PosPl.XDirection().Crossed(PosPl.YDirection());
466 norchamf.SetXYZ (deru.Crossed(derv).XYZ());
467 toreverse = ( norchamf.Dot(norpl) <= 0. );
469 if (isConPar) toreverse = !toreverse;
471 if ((toreverse && plandab) || (!toreverse && !plandab)){
472 trans = TopAbs_FORWARD;
475 trans = TopAbs_REVERSED;
479 Data->ChangeInterferenceOnS1().
480 SetInterference(ChFiKPart_IndexCurveInDS(GCirPln,DStr),
481 trans,GCir2dPln,GLin2dCh1);
484 Data->ChangeInterferenceOnS2().
485 SetInterference(ChFiKPart_IndexCurveInDS(GCirPln,DStr),
486 trans,GCir2dPln,GLin2dCh1);
489 // Case of the conical face
491 //intersection cone-chamfer
494 Rad = ChamfRad + dis;
496 Rad = ChamfRad - dis;
498 CirAx2.SetLocation(Or);
499 gp_Circ CirCon(CirAx2, Rad);
500 Handle(Geom_Circle) GCirCon = new Geom_Circle(CirCon);
504 v = sqrt(dis*dis + move*move);
506 v = - sqrt(dis*dis + move*move);
507 p2dch.SetCoord(0.,v);
508 ElSLib::ConeD1(0.,v,ChamfAx3,ChamfRad,SemiAngl,Pt,deru,derv);
509 lin2dch.SetLocation(p2dch);
510 Handle(Geom2d_Line) GLin2dCh2 = new Geom2d_Line(lin2dch);
513 norchamf.SetXYZ (deru.Crossed(derv).XYZ());
515 Pt.SetCoord(Or.X()+Rad*Dx.X(),
518 ElSLib::Parameters(Con,Pt ,u,v);
519 Standard_Real tol = Precision::PConfusion();
520 if (u >= 2*M_PI - tol && u <= 2*M_PI) u = 0.;
521 if (u >= fu - tol && u < fu) u = fu;
522 if (u <= lu + tol && u > lu) u = lu;
523 if (u < fu || u > lu) u = ElCLib::InPeriod(u,fu,fu + 2*M_PI);
524 ElSLib::D1(u,v,Con,Pt,deru,derv);
525 gp_Pnt2d p2dCon(u,v);
527 if ( deru.Dot(DSp)<=0. )
528 d2dCon = - gp::DX2d();
531 gp_Lin2d lin2dCon(p2dCon,d2dCon);
532 Handle(Geom2d_Line) GLin2dCon = new Geom2d_Line(lin2dCon);
535 gp_Dir norcon = deru.Crossed(derv);
537 gp_Dir DirCon = (Con.Axis()).Direction();
538 gp_Dir DirChamf = (gcon->Axis()).Direction();
539 if (angCon > Precision::Confusion()) DirCon.Reverse();
540 if (SemiAngl > Precision::Confusion()) DirChamf.Reverse();
542 Standard_Boolean torevcon = ( norcon.Dot(DirCon) > 0. );
543 Standard_Boolean torevcha = ( norchamf.Dot(DirChamf) > 0. );
545 toreverse = ( (torevcon && !torevcha) || (!torevcon && torevcha) );
547 if ((toreverse && plandab) || (!toreverse && !plandab) ) {
548 trans = TopAbs_REVERSED;
551 trans = TopAbs_FORWARD;
555 Data->ChangeInterferenceOnS2().
556 SetInterference(ChFiKPart_IndexCurveInDS(GCirCon,DStr),
557 trans,GLin2dCon,GLin2dCh2);
560 Data->ChangeInterferenceOnS1().
561 SetInterference(ChFiKPart_IndexCurveInDS(GCirCon,DStr),
562 trans,GLin2dCon,GLin2dCh2);
566 return Standard_True;