1 // Created on: 1998-06-16
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_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 : MakeChAsym
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 // <Dis> and Angle on <Pl1> .
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_MakeChAsym(TopOpeBRepDS_DataStructure& DStr,
55 const Handle(ChFiDS_SurfData)& Data,
58 const TopAbs_Orientation Or1,
59 const TopAbs_Orientation Or2,
60 const Standard_Real Dis,
61 const Standard_Real Angle,
63 const Standard_Real First,
64 const TopAbs_Orientation Of1,
65 const Standard_Boolean DisOnP1)
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(); }
75 gp_Ax3 Pos2 = Pl2.Position();
76 gp_Dir D2 = Pos2.XDirection().Crossed(Pos2.YDirection());
77 if (Or2 == TopAbs_REVERSED) { D2.Reverse(); }
79 // compute the intersection line of Pl1 and Pl2
80 IntAna_QuadQuadGeo LInt (Pl1, Pl2, Precision::Angular(),
81 Precision::Confusion());
86 Fint = ElCLib::Parameter(LInt.Line(1), ElCLib::Value(First, Spine));
87 P = ElCLib::Value(Fint, LInt.Line(1));
89 else { return Standard_False; }
91 gp_Dir LinAx1 = Spine.Direction();
92 gp_Dir VecTransl1 = LinAx1.Crossed(D1);
93 if ( VecTransl1.Dot(D2) < 0. )
96 gp_Dir VecTransl2 = LinAx1.Crossed(D2);
97 if ( VecTransl2.Dot(D1) < 0. )
100 Standard_Real cosP, sinP, dis1, dis2;
101 cosP = VecTransl1.Dot(VecTransl2);
102 sinP = sqrt(1. - cosP * cosP);
106 dis2 = Dis / (cosP + sinP / Tan(Angle));
109 dis1 = Dis / (cosP + sinP / Tan(Angle));
112 // Compute a point on the plane Pl1 and on the chamfer
113 gp_Pnt P1( P.X() + dis1 * VecTransl1.X(),
114 P.Y() + dis1 * VecTransl1.Y(),
115 P.Z() + dis1 * VecTransl1.Z());
117 // Point on the plane Pl2 and on the chamfer
118 gp_Pnt P2( P.X() + dis2 * VecTransl2.X(),
119 P.Y() + dis2 * VecTransl2.Y(),
120 P.Z() + dis2 * VecTransl2.Z());
122 //the middle point of P1 P2 is the origin of the chamfer
123 gp_Pnt Po ( (P1.X() + P2.X()) / 2., (P1.Y() + P2.Y()) / 2., (P1.Z() + P2.Z()) / 2.);
125 // compute a second point on the plane Pl2
126 gp_Pnt Pp = ElCLib::Value(Fint + 10., LInt.Line(1));
127 gp_Pnt P22(Pp.X() + dis2 * VecTransl2.X(),
128 Pp.Y() + dis2 * VecTransl2.Y(),
129 Pp.Z() + dis2 * VecTransl2.Z());
131 // Compute the normal vector <AxisPlan> to the chamfer's plane
132 gp_Dir V1 ( P2.X() - P1.X(), P2.Y() - P1.Y(), P2.Z() - P1.Z());
133 gp_Dir V2 ( P22.X() - P1.X(), P22.Y() - P1.Y(), P22.Z() - P1.Z());
134 gp_Dir AxisPlan = V1.Crossed(V2);
136 gp_Dir xdir = LinAx1; // u axis
137 gp_Ax3 PlanAx3 (Po, AxisPlan, xdir);
138 if (PlanAx3.YDirection().Dot(D2)>=0.) PlanAx3.YReverse();
140 Handle(Geom_Plane) gpl= new Geom_Plane(PlanAx3);
141 Data->ChangeSurf(ChFiKPart_IndexSurfaceInDS(gpl, DStr));
143 // About the orientation of the chamfer plane
144 // Compute the normal to the face 1
145 gp_Dir norpl = Pos1.XDirection().Crossed(Pos1.YDirection());
146 gp_Dir norface1 = norpl;
147 if (Of1 == TopAbs_REVERSED ) { norface1.Reverse(); }
149 // Compute the orientation of the chamfer plane
150 gp_Dir norplch = gpl->Pln().Position().XDirection().Crossed (
151 gpl->Pln().Position().YDirection());
153 gp_Dir DirCh12(gp_Vec(P1, P2));
154 Standard_Boolean toreverse = ( norplch.Dot(norface1) <= 0. );
155 if (VecTransl1.Dot(DirCh12) > 0) toreverse = !toreverse;
158 Data->ChangeOrientation() = TopAbs_REVERSED;
160 Data->ChangeOrientation() = TopAbs_FORWARD;
162 // Loading of the FaceInterferences with pcurves & 3d curves.
165 gp_Lin linPln(P1, xdir);
166 Handle(Geom_Line) GLinPln1 = new Geom_Line(linPln);
169 ElSLib::PlaneParameters(Pos1, P1, u, v);
170 gp_Pnt2d p2dPln(u, v);
171 gp_Dir2d dir2dPln( xdir.Dot(Pos1.XDirection()),
172 xdir.Dot(Pos1.YDirection()));
173 gp_Lin2d lin2dPln(p2dPln, dir2dPln);
174 Handle(Geom2d_Line) GLin2dPln1 = new Geom2d_Line(lin2dPln);
176 ElSLib::PlaneParameters(PlanAx3, P1, u, v);
177 p2dPln.SetCoord(u, v);
178 lin2dPln.SetLocation(p2dPln);
179 lin2dPln.SetDirection(gp::DX2d());
180 Handle(Geom2d_Line) GLin2dPlnCh1 = new Geom2d_Line(lin2dPln);
182 TopAbs_Orientation trans;
183 toreverse = ( norplch.Dot(norpl) <= 0. );
184 if (VecTransl1.Dot(DirCh12) > 0) toreverse = !toreverse;
186 trans = TopAbs_FORWARD;
188 trans = TopAbs_REVERSED;
190 Data->ChangeInterferenceOnS1().
191 SetInterference(ChFiKPart_IndexCurveInDS(GLinPln1, DStr),
192 trans, GLin2dPln1, GLin2dPlnCh1);
197 linPln.SetLocation(P2);
198 Handle(Geom_Line) GLinPln2 = new Geom_Line(linPln);
200 ElSLib::PlaneParameters(Pos2, P2, u, v);
201 p2dPln.SetCoord(u, v);
202 dir2dPln.SetCoord( xdir.Dot(Pos2.XDirection()),
203 xdir.Dot(Pos2.YDirection()));
204 lin2dPln.SetLocation(p2dPln);
205 lin2dPln.SetDirection(dir2dPln);
206 Handle(Geom2d_Line) GLin2dPln2 = new Geom2d_Line(lin2dPln);
208 ElSLib::PlaneParameters(PlanAx3, P2, u, v);
209 p2dPln.SetCoord(u, v);
210 lin2dPln.SetLocation(p2dPln);
211 lin2dPln.SetDirection(gp::DX2d());
212 Handle(Geom2d_Line) GLin2dPlnCh2 = new Geom2d_Line(lin2dPln);
214 norpl = Pos2.XDirection().Crossed(Pos2.YDirection());
215 toreverse = ( norplch.Dot(norpl) <= 0. );
216 if (VecTransl2.Dot(DirCh12) < 0) toreverse = !toreverse;
218 trans = TopAbs_REVERSED;
220 trans = TopAbs_FORWARD;
222 Data->ChangeInterferenceOnS2().
223 SetInterference(ChFiKPart_IndexCurveInDS(GLinPln2,DStr),
224 trans, GLin2dPln2, GLin2dPlnCh2);
226 return Standard_True;