1 // Created on: 1995-04-28
2 // Created by: Flore Lantheaume
3 // Copyright (c) 1995-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_Line.hxx>
26 #include <Geom_Line.hxx>
27 #include <Geom_Plane.hxx>
31 #include <gp_Dir2d.hxx>
33 #include <gp_Lin2d.hxx>
36 #include <gp_Pnt2d.hxx>
37 #include <IntAna_QuadQuadGeo.hxx>
38 #include <Precision.hxx>
39 #include <TopOpeBRepDS_DataStructure.hxx>
41 //=======================================================================
42 //function : MakeChamfer
43 //Purpose : Compute the chamfer in the particular case plane/plane.
44 // Compute the SurfData <Data> of the chamfer on the <Spine>
45 // between the plane <Pl1> and the plane <Pl2>, with distances
46 // <Dis1> on <Pl1> and <Dis2> on <Pl2>.
47 // <First> is the parameter of the start point on the <Spine>
48 // <Or1> and <Or2> are the orientations of the plane <Pl1> and
49 // <Pl2>, and <Of1> the orientation of the face build on the
51 //Out : True if the chamfer has been computed
53 //=======================================================================
54 Standard_Boolean ChFiKPart_MakeChamfer(TopOpeBRepDS_DataStructure& DStr,
55 const Handle(ChFiDS_SurfData)& Data,
56 const ChFiDS_ChamfMode theMode,
59 const TopAbs_Orientation Or1,
60 const TopAbs_Orientation Or2,
61 const Standard_Real theDis1,
62 const Standard_Real theDis2,
64 const Standard_Real First,
65 const TopAbs_Orientation Of1)
68 // Creation of the plane which carry the chamfer
70 // compute the normals to the planes Pl1 and Pl2
71 gp_Ax3 Pos1 = Pl1.Position();
72 gp_Dir D1 = Pos1.XDirection().Crossed(Pos1.YDirection());
73 if (Or1 == TopAbs_REVERSED) { D1.Reverse(); }
74 gp_Ax3 Pos2 = Pl2.Position();
75 gp_Dir D2 = Pos2.XDirection().Crossed(Pos2.YDirection());
76 if (Or2 == TopAbs_REVERSED) { D2.Reverse(); }
78 // compute the intersection line of Pl1 and Pl2
79 IntAna_QuadQuadGeo LInt (Pl1,Pl2,Precision::Angular(),
80 Precision::Confusion());
85 Fint = ElCLib::Parameter(LInt.Line(1),ElCLib::Value(First,Spine));
86 P = ElCLib::Value(Fint,LInt.Line(1));
88 else { return Standard_False; }
90 gp_Dir LinAx1 = Spine.Direction();
91 gp_Dir VecTransl1 = LinAx1.Crossed(D1);
92 if ( VecTransl1.Dot(D2) <=0. )
95 gp_Dir VecTransl2 = LinAx1.Crossed(D2);
96 if ( VecTransl2.Dot(D1) <=0. )
99 Standard_Real Dis1 = theDis1, Dis2 = theDis2;
100 Standard_Real Alpha = VecTransl1.Angle(VecTransl2);
101 Standard_Real CosHalfAlpha = Cos(Alpha/2);
102 if (theMode == ChFiDS_ConstThroatChamfer)
103 Dis1 = Dis2 = theDis1 / CosHalfAlpha;
104 else if (theMode == ChFiDS_ConstThroatWithPenetrationChamfer)
106 Standard_Real aDis1 = Min(theDis1, theDis2);
107 Standard_Real aDis2 = Max(theDis1, theDis2);
108 Standard_Real dis1dis1 = aDis1*aDis1, dis2dis2 = aDis2*aDis2;
109 Standard_Real SinAlpha = Sin(Alpha);
110 Standard_Real CosAlpha = Cos(Alpha);
111 Standard_Real CotanAlpha = CosAlpha/SinAlpha;
112 Dis1 = sqrt(dis2dis2 - dis1dis1) - aDis1*CotanAlpha;
113 Standard_Real CosBeta = sqrt(1-dis1dis1/dis2dis2)*CosAlpha + aDis1/aDis2*SinAlpha;
114 Standard_Real FullDist1 = aDis2/CosBeta;
115 Dis2 = FullDist1 - aDis1/SinAlpha;
118 // Compute a point on the plane Pl1 and on the chamfer
119 gp_Pnt P1( P.X()+Dis1*VecTransl1.X(),
120 P.Y()+Dis1*VecTransl1.Y(),
121 P.Z()+Dis1*VecTransl1.Z());
123 // Point on the plane Pl2 and on the chamfer
124 gp_Pnt P2( P.X()+Dis2*VecTransl2.X(),
125 P.Y()+Dis2*VecTransl2.Y(),
126 P.Z()+Dis2*VecTransl2.Z());
128 //the middle point of P1 P2 is the origin of the chamfer
129 gp_Pnt Po ( (P1.X()+P2.X())/2. ,(P1.Y()+P2.Y())/2. , (P1.Z()+P2.Z())/2. );
131 // compute a second point on the plane Pl2
132 gp_Pnt Pp = ElCLib::Value(Fint+10.,LInt.Line(1));
133 gp_Pnt P22(Pp.X()+Dis2*VecTransl2.X(),
134 Pp.Y()+Dis2*VecTransl2.Y(),
135 Pp.Z()+Dis2*VecTransl2.Z());
137 // Compute the normal vector <AxisPlan> to the chamfer's plane
138 gp_Dir V1 ( P2.X()-P1.X(), P2.Y()-P1.Y(), P2.Z()-P1.Z());
139 gp_Dir V2 ( P22.X()-P1.X(), P22.Y()-P1.Y(), P22.Z()-P1.Z());
140 gp_Dir AxisPlan = V1.Crossed(V2);
142 gp_Dir xdir = LinAx1; // u axis
143 gp_Ax3 PlanAx3 ( Po, AxisPlan, xdir);
144 if (PlanAx3.YDirection().Dot(D2)>=0.) PlanAx3.YReverse();
146 Handle(Geom_Plane) gpl= new Geom_Plane(PlanAx3);
147 Data->ChangeSurf(ChFiKPart_IndexSurfaceInDS(gpl,DStr));
150 // About the orientation of the chamfer plane
151 // Compute the normal to the face 1
152 gp_Dir norpl = Pos1.XDirection().Crossed(Pos1.YDirection());
153 gp_Dir norface1 = norpl;
154 if (Of1 == TopAbs_REVERSED ) { norface1.Reverse(); }
156 // Compute the orientation of the chamfer plane
157 gp_Dir norplch = gpl->Pln().Position().XDirection().Crossed (
158 gpl->Pln().Position().YDirection());
160 gp_Dir DirCh12(gp_Vec(P1, P2));
161 Standard_Boolean toreverse = ( norplch.Dot(norface1) <= 0. );
162 if (VecTransl1.Dot(DirCh12) > 0) toreverse = !toreverse;
165 Data->ChangeOrientation() = TopAbs_REVERSED;
167 Data->ChangeOrientation() = TopAbs_FORWARD;
171 // Loading of the FaceInterferences with pcurves & 3d curves.
174 gp_Lin linPln(P1, xdir);
175 Handle(Geom_Line) GLinPln1 = new Geom_Line(linPln);
178 ElSLib::PlaneParameters(Pos1,P1,u,v);
179 gp_Pnt2d p2dPln(u,v);
180 gp_Dir2d dir2dPln( xdir.Dot(Pos1.XDirection()),
181 xdir.Dot(Pos1.YDirection()));
182 gp_Lin2d lin2dPln(p2dPln,dir2dPln);
183 Handle(Geom2d_Line) GLin2dPln1 = new Geom2d_Line(lin2dPln);
185 ElSLib::PlaneParameters(PlanAx3,P1,u,v);
186 p2dPln.SetCoord(u,v);
187 lin2dPln.SetLocation(p2dPln);
188 lin2dPln.SetDirection(gp::DX2d());
189 Handle(Geom2d_Line) GLin2dPlnCh1 = new Geom2d_Line(lin2dPln);
191 TopAbs_Orientation trans;
192 toreverse = ( norplch.Dot(norpl) <= 0. );
193 if (VecTransl1.Dot(DirCh12) > 0) toreverse = !toreverse;
195 trans = TopAbs_FORWARD;
197 trans = TopAbs_REVERSED;
199 Data->ChangeInterferenceOnS1().
200 SetInterference(ChFiKPart_IndexCurveInDS(GLinPln1,DStr),
201 trans,GLin2dPln1,GLin2dPlnCh1);
206 linPln.SetLocation(P2);
207 Handle(Geom_Line) GLinPln2 = new Geom_Line(linPln);
209 ElSLib::PlaneParameters(Pos2,P2,u,v);
210 p2dPln.SetCoord(u,v);
211 dir2dPln.SetCoord( xdir.Dot(Pos2.XDirection()),
212 xdir.Dot(Pos2.YDirection()));
213 lin2dPln.SetLocation(p2dPln);
214 lin2dPln.SetDirection(dir2dPln);
215 Handle(Geom2d_Line) GLin2dPln2 = new Geom2d_Line(lin2dPln);
217 ElSLib::PlaneParameters(PlanAx3,P2,u,v);
218 p2dPln.SetCoord(u,v);
219 lin2dPln.SetLocation(p2dPln);
220 lin2dPln.SetDirection(gp::DX2d());
221 Handle(Geom2d_Line) GLin2dPlnCh2 = new Geom2d_Line(lin2dPln);
224 norpl = Pos2.XDirection().Crossed(Pos2.YDirection());
225 toreverse = ( norplch.Dot(norpl) <= 0. );
226 if (VecTransl2.Dot(DirCh12) < 0) toreverse = !toreverse;
228 trans = TopAbs_REVERSED;
230 trans = TopAbs_FORWARD;
232 Data->ChangeInterferenceOnS2().
233 SetInterference(ChFiKPart_IndexCurveInDS(GLinPln2,DStr),
234 trans,GLin2dPln2,GLin2dPlnCh2);
236 return Standard_True;