0027960: Configuration - fix compilation of OSD_Directory with MinGW-w64
[occt.git] / src / ChFiKPart / ChFiKPart_ComputeData_ChPlnPln.cxx
CommitLineData
b311480e 1// Created on: 1995-04-28
2// Created by: Flore Lantheaume
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17
42cf5bc1 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>
7fd59977 23#include <ElCLib.hxx>
24#include <ElSLib.hxx>
7fd59977 25#include <Geom2d_Line.hxx>
26#include <Geom_Line.hxx>
7fd59977 27#include <Geom_Plane.hxx>
42cf5bc1 28#include <gp.hxx>
29#include <gp_Ax3.hxx>
30#include <gp_Dir.hxx>
31#include <gp_Dir2d.hxx>
32#include <gp_Lin.hxx>
33#include <gp_Lin2d.hxx>
34#include <gp_Pln.hxx>
35#include <gp_Pnt.hxx>
36#include <gp_Pnt2d.hxx>
7fd59977 37#include <IntAna_QuadQuadGeo.hxx>
42cf5bc1 38#include <Precision.hxx>
39#include <TopOpeBRepDS_DataStructure.hxx>
7fd59977 40
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
50// plane <Pl1>.
51//Out : True if the chamfer has been computed
52// False else
53//=======================================================================
7fd59977 54Standard_Boolean ChFiKPart_MakeChamfer(TopOpeBRepDS_DataStructure& DStr,
55 const Handle(ChFiDS_SurfData)& Data,
56 const gp_Pln& Pl1,
57 const gp_Pln& Pl2,
58 const TopAbs_Orientation Or1,
59 const TopAbs_Orientation Or2,
60 const Standard_Real Dis1,
61 const Standard_Real Dis2,
62 const gp_Lin& Spine,
63 const Standard_Real First,
64 const TopAbs_Orientation Of1)
65{
66
67 // Creation of the plane which carry the chamfer
68
69 // compute the normals to the planes Pl1 and Pl2
70 gp_Ax3 Pos1 = Pl1.Position();
71 gp_Dir D1 = Pos1.XDirection().Crossed(Pos1.YDirection());
72 if (Or1 == TopAbs_REVERSED) { D1.Reverse(); }
73 gp_Ax3 Pos2 = Pl2.Position();
74 gp_Dir D2 = Pos2.XDirection().Crossed(Pos2.YDirection());
75 if (Or2 == TopAbs_REVERSED) { D2.Reverse(); }
76
77 // compute the intersection line of Pl1 and Pl2
78 IntAna_QuadQuadGeo LInt (Pl1,Pl2,Precision::Angular(),
79 Precision::Confusion());
80
81 gp_Pnt P;
82 Standard_Real Fint;
83 if (LInt.IsDone()) {
84 Fint = ElCLib::Parameter(LInt.Line(1),ElCLib::Value(First,Spine));
85 P = ElCLib::Value(Fint,LInt.Line(1));
86 }
87 else { return Standard_False; }
88
89 gp_Dir LinAx1 = Spine.Direction();
90 gp_Dir VecTransl1 = LinAx1.Crossed(D1);
91 if ( VecTransl1.Dot(D2) <=0. )
92 VecTransl1.Reverse();
93
94 gp_Dir VecTransl2 = LinAx1.Crossed(D2);
95 if ( VecTransl2.Dot(D1) <=0. )
96 VecTransl2.Reverse();
97
98
99 // Compute a point on the plane Pl1 and on the chamfer
100 gp_Pnt P1( P.X()+Dis1*VecTransl1.X(),
101 P.Y()+Dis1*VecTransl1.Y(),
102 P.Z()+Dis1*VecTransl1.Z());
103
104 // Point on the plane Pl2 and on the chamfer
105 gp_Pnt P2( P.X()+Dis2*VecTransl2.X(),
106 P.Y()+Dis2*VecTransl2.Y(),
107 P.Z()+Dis2*VecTransl2.Z());
108
109 //the middle point of P1 P2 is the origin of the chamfer
110 gp_Pnt Po ( (P1.X()+P2.X())/2. ,(P1.Y()+P2.Y())/2. , (P1.Z()+P2.Z())/2. );
111
112 // compute a second point on the plane Pl2
113 gp_Pnt Pp = ElCLib::Value(Fint+10.,LInt.Line(1));
114 gp_Pnt P22(Pp.X()+Dis2*VecTransl2.X(),
115 Pp.Y()+Dis2*VecTransl2.Y(),
116 Pp.Z()+Dis2*VecTransl2.Z());
117
118 // Compute the normal vector <AxisPlan> to the chamfer's plane
119 gp_Dir V1 ( P2.X()-P1.X(), P2.Y()-P1.Y(), P2.Z()-P1.Z());
120 gp_Dir V2 ( P22.X()-P1.X(), P22.Y()-P1.Y(), P22.Z()-P1.Z());
121 gp_Dir AxisPlan = V1.Crossed(V2);
122
123 gp_Dir xdir = LinAx1; // u axis
124 gp_Ax3 PlanAx3 ( Po, AxisPlan, xdir);
125 if (PlanAx3.YDirection().Dot(D2)>=0.) PlanAx3.YReverse();
126
127 Handle(Geom_Plane) gpl= new Geom_Plane(PlanAx3);
128 Data->ChangeSurf(ChFiKPart_IndexSurfaceInDS(gpl,DStr));
129
130
131 // About the orientation of the chamfer plane
132 // Compute the normal to the face 1
133 gp_Dir norpl = Pos1.XDirection().Crossed(Pos1.YDirection());
134 gp_Dir norface1 = norpl;
135 if (Of1 == TopAbs_REVERSED ) { norface1.Reverse(); }
136
137 // Compute the orientation of the chamfer plane
138 gp_Dir norplch = gpl->Pln().Position().XDirection().Crossed (
139 gpl->Pln().Position().YDirection());
140
141 gp_Dir DirCh12(gp_Vec(P1, P2));
142 Standard_Boolean toreverse = ( norplch.Dot(norface1) <= 0. );
143 if (VecTransl1.Dot(DirCh12) > 0) toreverse = !toreverse;
144
145 if (toreverse)
146 Data->ChangeOrientation() = TopAbs_REVERSED;
147 else
148 Data->ChangeOrientation() = TopAbs_FORWARD;
149
150
151
152 // Loading of the FaceInterferences with pcurves & 3d curves.
153
154 // case face 1
155 gp_Lin linPln(P1, xdir);
156 Handle(Geom_Line) GLinPln1 = new Geom_Line(linPln);
157
158 Standard_Real u,v;
159 ElSLib::PlaneParameters(Pos1,P1,u,v);
160 gp_Pnt2d p2dPln(u,v);
161 gp_Dir2d dir2dPln( xdir.Dot(Pos1.XDirection()),
162 xdir.Dot(Pos1.YDirection()));
163 gp_Lin2d lin2dPln(p2dPln,dir2dPln);
164 Handle(Geom2d_Line) GLin2dPln1 = new Geom2d_Line(lin2dPln);
165
166 ElSLib::PlaneParameters(PlanAx3,P1,u,v);
167 p2dPln.SetCoord(u,v);
168 lin2dPln.SetLocation(p2dPln);
169 lin2dPln.SetDirection(gp::DX2d());
170 Handle(Geom2d_Line) GLin2dPlnCh1 = new Geom2d_Line(lin2dPln);
171
172 TopAbs_Orientation trans;
173 toreverse = ( norplch.Dot(norpl) <= 0. );
174 if (VecTransl1.Dot(DirCh12) > 0) toreverse = !toreverse;
175 if (toreverse)
176 trans = TopAbs_FORWARD;
177 else
178 trans = TopAbs_REVERSED;
179
180 Data->ChangeInterferenceOnS1().
181 SetInterference(ChFiKPart_IndexCurveInDS(GLinPln1,DStr),
182 trans,GLin2dPln1,GLin2dPlnCh1);
183
184
185 // case face 2
186
187 linPln.SetLocation(P2);
188 Handle(Geom_Line) GLinPln2 = new Geom_Line(linPln);
189
190 ElSLib::PlaneParameters(Pos2,P2,u,v);
191 p2dPln.SetCoord(u,v);
192 dir2dPln.SetCoord( xdir.Dot(Pos2.XDirection()),
193 xdir.Dot(Pos2.YDirection()));
194 lin2dPln.SetLocation(p2dPln);
195 lin2dPln.SetDirection(dir2dPln);
196 Handle(Geom2d_Line) GLin2dPln2 = new Geom2d_Line(lin2dPln);
197
198 ElSLib::PlaneParameters(PlanAx3,P2,u,v);
199 p2dPln.SetCoord(u,v);
200 lin2dPln.SetLocation(p2dPln);
201 lin2dPln.SetDirection(gp::DX2d());
202 Handle(Geom2d_Line) GLin2dPlnCh2 = new Geom2d_Line(lin2dPln);
203
204
205 norpl = Pos2.XDirection().Crossed(Pos2.YDirection());
206 toreverse = ( norplch.Dot(norpl) <= 0. );
207 if (VecTransl2.Dot(DirCh12) < 0) toreverse = !toreverse;
208 if (toreverse)
209 trans = TopAbs_REVERSED;
210 else
211 trans = TopAbs_FORWARD;
212
213 Data->ChangeInterferenceOnS2().
214 SetInterference(ChFiKPart_IndexCurveInDS(GLinPln2,DStr),
215 trans,GLin2dPln2,GLin2dPlnCh2);
216
217 return Standard_True;
218
219 }
220
221
222
223
224
225