0030480: Visualization - Clear of Select3D_SensitiveGroup does not update internal...
[occt.git] / src / BlendFunc / BlendFunc_Chamfer.cxx
1 // Created on: 1996-06-05
2 // Created by: Stagiaire Xuan Trang PHAMPHU
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 // Modified : 20/08/96 PMN Ajout des methodes (Nb)Intervals et IsRationnal
18 // Modified : 30/12/96 PMN Ajout GetMinimalWeight, GetSectionSize;
19
20 #include <Adaptor3d_HCurve.hxx>
21 #include <Adaptor3d_HSurface.hxx>
22 #include <Blend_Point.hxx>
23 #include <BlendFunc.hxx>
24 #include <BlendFunc_Chamfer.hxx>
25 #include <ElCLib.hxx>
26 #include <gp_Lin.hxx>
27 #include <gp_Pnt.hxx>
28 #include <gp_Vec.hxx>
29 #include <gp_Vec2d.hxx>
30 #include <math_Matrix.hxx>
31 #include <Precision.hxx>
32 #include <Standard_NotImplemented.hxx>
33
34 //=======================================================================
35 //function : BlendFunc_Chamfer
36 //purpose  : 
37 //=======================================================================
38
39 BlendFunc_Chamfer::BlendFunc_Chamfer(const Handle(Adaptor3d_HSurface)& S1,
40                                      const Handle(Adaptor3d_HSurface)& S2,
41                                      const Handle(Adaptor3d_HCurve)&   CG)
42   : BlendFunc_GenChamfer(S1,S2,CG),
43     corde1(S1,CG),corde2(S2,CG)
44 {
45 }
46
47 //=======================================================================
48 //function : Set
49 //purpose  : 
50 //=======================================================================
51
52 void BlendFunc_Chamfer::Set(const Standard_Real Dist1, const Standard_Real Dist2,
53                             const Standard_Integer Choix)
54 {
55   corde1.SetDist(Dist1);
56   corde2.SetDist(Dist2);
57   choix = Choix;
58 }
59
60 //=======================================================================
61 //function : Set
62 //purpose  : 
63 //=======================================================================
64
65 void BlendFunc_Chamfer::Set(const Standard_Real Param)
66 {
67   corde1.SetParam(Param);
68   corde2.SetParam(Param);
69 }
70
71 //=======================================================================
72 //function : IsSolution
73 //purpose  : 
74 //=======================================================================
75
76 Standard_Boolean BlendFunc_Chamfer::IsSolution(const math_Vector& Sol, const Standard_Real Tol)
77 {
78   math_Vector Sol1(1,2), Sol2(1,2);
79
80   Sol1(1) = Sol(1);
81   Sol1(2) = Sol(2);
82   Sol2(1) = Sol(3); 
83   Sol2(2) = Sol(4); 
84   
85   Standard_Boolean issol = corde1.IsSolution(Sol1,Tol);
86   issol = issol && corde2.IsSolution(Sol2,Tol);
87   tol = Tol;
88   if (issol) 
89     distmin = Min (distmin, corde1.PointOnS().Distance(corde2.PointOnS()));
90
91   return issol;
92 }
93
94 //=======================================================================
95 //function : Value
96 //purpose  : 
97 //=======================================================================
98
99 Standard_Boolean BlendFunc_Chamfer::Value(const math_Vector& X, math_Vector& F)
100 {
101   math_Vector x(1,2), f(1,2);
102
103   x(1) = X(1); x(2) = X(2);
104   corde1.Value(x,f);
105   F(1) = f(1); F(2) = f(2);
106
107   x(1) = X(3); x(2) = X(4);
108   corde2.Value(x,f);
109   F(3) = f(1); F(4) = f(2);
110
111   return Standard_True;
112 }
113
114
115 //=======================================================================
116 //function : Derivatives
117 //purpose  : 
118 //=======================================================================
119
120 Standard_Boolean BlendFunc_Chamfer::Derivatives(const math_Vector& X, math_Matrix& D)
121 {
122   Standard_Integer i,j;
123   math_Vector x(1,2);
124   math_Matrix d(1,2,1,2);
125
126   x(1) = X(1); x(2) = X(2);
127   corde1.Derivatives(x,d);
128   for( i=1; i<3; i++ ){
129     for( j=1; j<3; j++ ){
130       D(i,j) = d(i,j);
131       D(i,j+2) = 0.;
132     }
133   }   
134
135   x(1) = X(3); x(2) = X(4);
136   corde2.Derivatives(x,d);
137   for( i=1; i<3; i++ ){
138     for( j=1; j<3; j++ ){
139       D(i+2,j+2) = d(i,j);
140       D(i+2,j) = 0.;
141     }
142   }   
143
144   return Standard_True;
145 }
146
147 //=======================================================================
148 //function : PointOnS1
149 //purpose  : 
150 //=======================================================================
151
152 const gp_Pnt& BlendFunc_Chamfer::PointOnS1 () const
153 {
154   return corde1.PointOnS();
155 }
156   
157 //=======================================================================
158 //function : PointOnS2
159 //purpose  : 
160 //=======================================================================
161
162 const gp_Pnt& BlendFunc_Chamfer::PointOnS2 () const
163 {
164   return corde2.PointOnS();
165 }
166
167
168 //=======================================================================
169 //function : IsTangencyPoint
170 //purpose  : 
171 //=======================================================================
172
173 Standard_Boolean BlendFunc_Chamfer::IsTangencyPoint () const
174 {
175   return corde1.IsTangencyPoint() && corde2.IsTangencyPoint();
176 }
177
178 //=======================================================================
179 //function : TangentOnS1
180 //purpose  : 
181 //=======================================================================
182
183 const gp_Vec& BlendFunc_Chamfer::TangentOnS1 () const
184 {
185   return corde1.TangentOnS();
186 }
187
188 //=======================================================================
189 //function : TangentOnS2
190 //purpose  : 
191 //=======================================================================
192
193 const gp_Vec& BlendFunc_Chamfer::TangentOnS2 () const
194 {
195   return corde2.TangentOnS();
196 }
197
198 //=======================================================================
199 //function : Tangent2dOnS1
200 //purpose  : 
201 //=======================================================================
202
203 const gp_Vec2d& BlendFunc_Chamfer::Tangent2dOnS1 () const
204 {
205   return corde1.Tangent2dOnS();
206 }
207
208 //=======================================================================
209 //function : Tangent2dOnS2
210 //purpose  : 
211 //=======================================================================
212
213 const gp_Vec2d& BlendFunc_Chamfer::Tangent2dOnS2 () const
214 {
215   return corde2.Tangent2dOnS();
216 }
217
218 //=======================================================================
219 //function : Tangent
220 //purpose  : TgF,NmF et TgL,NmL les tangentes et normales respectives
221 //           aux surfaces S1 et S2 
222 //=======================================================================
223
224 void BlendFunc_Chamfer::Tangent(const Standard_Real U1,
225                                 const Standard_Real V1,
226                                 const Standard_Real U2,
227                                 const Standard_Real V2,
228                                 gp_Vec& TgF,
229                                 gp_Vec& TgL,
230                                 gp_Vec& NmF,
231                                 gp_Vec& NmL) const
232 {
233   gp_Pnt pt1,pt2,ptgui;
234   gp_Vec d1u1,d1v1,d1u2,d1v2;
235   gp_Vec nplan;
236   Standard_Boolean revF = Standard_False;
237   Standard_Boolean revL = Standard_False;
238
239   ptgui = corde1.PointOnGuide();
240   nplan = corde1.NPlan();
241   surf1->D1(U1,V1,pt1,d1u1,d1v1);
242   NmF = d1u1.Crossed(d1v1);
243
244   surf2->D1(U2,V2,pt2,d1u2,d1v2);
245   NmL = d1u2.Crossed(d1v2);
246
247   TgF = (nplan.Crossed(NmF)).Normalized();
248   TgL = (nplan.Crossed(NmL)).Normalized();
249
250   if( (choix == 2)||(choix == 5) ){
251     revF = Standard_True;
252     revL = Standard_True;
253   }
254   if( (choix == 4)||(choix == 7) )
255     revL = Standard_True;
256   if( (choix == 3)||(choix == 8) )
257     revF = Standard_True;
258
259   if( revF )
260     TgF.Reverse();
261   if( revL )
262     TgL.Reverse();
263 }
264
265 //=======================================================================
266 //function : GetSectionSize
267 //purpose  : Non implementee (non necessaire car non rationel)
268 //=======================================================================
269 Standard_Real BlendFunc_Chamfer::GetSectionSize() const 
270 {
271   throw Standard_NotImplemented("BlendFunc_Chamfer::GetSectionSize()");
272 }