0024778: Convertation of the generic classes to the non-generic. Part 9
[occt.git] / src / Geom2dGcc / Geom2dGcc_Circ2d2TanOn.cxx
1 // Created on: 1992-10-21
2 // Created by: Remi GILET
3 // Copyright (c) 1992-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 #include <Geom2dGcc_Circ2d2TanOn.ixx>
18 #include <Geom2dAdaptor_Curve.hxx>
19 #include <GccAna_Circ2d2TanOn.hxx>
20 #include <Geom2dGcc_Circ2d2TanOnGeo.hxx>
21 #include <Geom2dGcc_Circ2d2TanOnIter.hxx>
22 #include <Geom2dGcc_QCurve.hxx>
23 #include <GccEnt_BadQualifier.hxx>
24 #include <Geom2d_Circle.hxx>
25 #include <Geom2d_Line.hxx>
26 #include <GccEnt_QualifiedCirc.hxx>
27 #include <GccEnt_QualifiedLin.hxx>
28 #include <StdFail_NotDone.hxx>
29
30 Geom2dGcc_Circ2d2TanOn::
31    Geom2dGcc_Circ2d2TanOn (const Geom2dGcc_QualifiedCurve&    Qualified1 , 
32                            const Geom2dGcc_QualifiedCurve&    Qualified2 , 
33                            const Geom2dAdaptor_Curve&         OnCurve    ,
34                            const Standard_Real                Tolerance  ,
35                            const Standard_Real                Param1     ,
36                            const Standard_Real                Param2     ,
37                            const Standard_Real                ParamOn    ):
38   cirsol(1,8)   ,
39   qualifier1(1,8),
40   qualifier2(1,8),
41   TheSame1(1,8) ,
42   TheSame2(1,8) ,
43   pnttg1sol(1,8),
44   pnttg2sol(1,8),
45   pntcen(1,8)   ,
46   par1sol(1,8)  ,
47   par2sol(1,8)  ,
48   pararg1(1,8)  ,
49   pararg2(1,8)  ,
50   parcen3(1,8)  
51 {
52   Geom2dAdaptor_Curve C1 = Qualified1.Qualified();
53   Geom2dAdaptor_Curve C2 = Qualified2.Qualified();
54   GeomAbs_CurveType Type1 = C1.GetType();
55   GeomAbs_CurveType Type2 = C2.GetType();
56   GeomAbs_CurveType Type3 = OnCurve.GetType();
57   Handle(Geom2d_Curve) CC1 = C1.Curve();
58   Handle(Geom2d_Curve) CC2 = C2.Curve();
59   Handle(Geom2d_Curve) Con = OnCurve.Curve();
60
61 //=============================================================================
62 //                            Appel a GccAna.                                 +
63 //=============================================================================
64
65   Invert = Standard_False;
66   NbrSol = 0;
67   if ((Type1 == GeomAbs_Line || Type1 == GeomAbs_Circle) &&
68       (Type2 == GeomAbs_Line || Type2 == GeomAbs_Circle)) {
69     if (Type3 == GeomAbs_Line || Type3 == GeomAbs_Circle) {
70       if (Type1 == GeomAbs_Circle) {
71         Handle(Geom2d_Circle) CCC1 = Handle(Geom2d_Circle)::DownCast(CC1);
72         gp_Circ2d c1(CCC1->Circ2d());
73         GccEnt_QualifiedCirc Qc1 = 
74           GccEnt_QualifiedCirc(c1,Qualified1.Qualifier());
75         if (Type2 == GeomAbs_Circle) {
76           Handle(Geom2d_Circle) CCC2 = Handle(Geom2d_Circle)::DownCast(CC2);
77           gp_Circ2d c2(CCC2->Circ2d());
78           if (Type3 == GeomAbs_Circle) {
79             Handle(Geom2d_Circle) CCon = Handle(Geom2d_Circle)::DownCast(Con);
80             GccAna_Circ2d2TanOn CircAna(Qc1,
81                                GccEnt_QualifiedCirc(c2,Qualified2.Qualifier()),
82                                         CCon->Circ2d(),Tolerance);
83             WellDone = CircAna.IsDone();
84             NbrSol = CircAna.NbSolutions();
85             for(Standard_Integer i=1; i<=NbrSol; i++) {
86               CircAna.WhichQualifier(i,qualifier1(i),qualifier2(i));
87             }
88             Results(CircAna);
89           }
90           else {
91             Handle(Geom2d_Line) LLon = Handle(Geom2d_Line)::DownCast(Con);
92             GccAna_Circ2d2TanOn CircAna(Qc1,
93                                GccEnt_QualifiedCirc(c2,Qualified2.Qualifier()),
94                                         LLon->Lin2d(),Tolerance);
95             WellDone = CircAna.IsDone();
96             NbrSol = CircAna.NbSolutions();
97             for(Standard_Integer i=1; i<=NbrSol; i++) {
98               CircAna.WhichQualifier(i,qualifier1(i),qualifier2(i));
99             }
100             Results(CircAna);
101           }
102         }
103         else {
104           Handle(Geom2d_Line) LL2 = Handle(Geom2d_Line)::DownCast(CC2);
105           gp_Lin2d l2(LL2->Lin2d());
106           if (Type3 == GeomAbs_Circle) {
107             Handle(Geom2d_Circle) CCon = Handle(Geom2d_Circle)::DownCast(Con);
108             GccAna_Circ2d2TanOn CircAna(Qc1,
109                                GccEnt_QualifiedLin(l2,Qualified2.Qualifier()),
110                                         CCon->Circ2d(),Tolerance);
111             WellDone = CircAna.IsDone();
112             NbrSol = CircAna.NbSolutions();
113             for(Standard_Integer i=1; i<=NbrSol; i++) {
114               CircAna.WhichQualifier(i,qualifier1(i),qualifier2(i));
115             }
116             Results(CircAna);
117           }
118           else {
119             Handle(Geom2d_Line) LLon = Handle(Geom2d_Line)::DownCast(Con);
120             GccAna_Circ2d2TanOn CircAna(Qc1,
121                                GccEnt_QualifiedLin(l2,Qualified2.Qualifier()),
122                                         LLon->Lin2d(),Tolerance);
123             WellDone = CircAna.IsDone();
124             NbrSol = CircAna.NbSolutions();
125             for(Standard_Integer i=1; i<=NbrSol; i++) {
126               CircAna.WhichQualifier(i,qualifier1(i),qualifier2(i));
127             }
128             Results(CircAna);
129           }
130         }
131       }
132       else {
133         Handle(Geom2d_Line) LL1 = Handle(Geom2d_Line)::DownCast(CC1);
134         gp_Lin2d l1(LL1->Lin2d());
135         GccEnt_QualifiedLin Ql1 = 
136           GccEnt_QualifiedLin(l1,Qualified1.Qualifier());
137         if (Type2 == GeomAbs_Circle) {
138           Handle(Geom2d_Circle) CCC2 = Handle(Geom2d_Circle)::DownCast(CC2);
139           gp_Circ2d c2(CCC2->Circ2d());
140           if (Type3 == GeomAbs_Circle) {
141             Handle(Geom2d_Circle) CCon = Handle(Geom2d_Circle)::DownCast(Con);
142             GccAna_Circ2d2TanOn CircAna(GccEnt_QualifiedCirc(c2,
143                                                        Qualified2.Qualifier()),
144                                         Ql1,CCon->Circ2d(),Tolerance);
145             WellDone = CircAna.IsDone();
146             NbrSol = CircAna.NbSolutions();
147             for(Standard_Integer i=1; i<=NbrSol; i++) {
148               CircAna.WhichQualifier(i,qualifier1(i),qualifier2(i));
149             }
150             Results(CircAna);
151             Invert = Standard_True;
152           }
153           else {
154             Handle(Geom2d_Line) LLon = Handle(Geom2d_Line)::DownCast(Con);
155             GccAna_Circ2d2TanOn CircAna(GccEnt_QualifiedCirc(c2,
156                                                        Qualified2.Qualifier()),
157                                         Ql1,LLon->Lin2d(),Tolerance);
158             WellDone = CircAna.IsDone();
159             NbrSol = CircAna.NbSolutions();
160             for(Standard_Integer i=1; i<=NbrSol; i++) {
161               CircAna.WhichQualifier(i,qualifier1(i),qualifier2(i));
162             }
163             Results(CircAna);
164             Invert = Standard_True;
165           }
166         }
167         else {
168           Handle(Geom2d_Line) LL2 = Handle(Geom2d_Line)::DownCast(CC2);
169           gp_Lin2d l2(LL2->Lin2d());
170           if (Type3 == GeomAbs_Circle) {
171             Handle(Geom2d_Circle) CCon = Handle(Geom2d_Circle)::DownCast(Con);
172             GccAna_Circ2d2TanOn CircAna(Ql1,
173                                GccEnt_QualifiedLin(l2,Qualified2.Qualifier()),
174                                         CCon->Circ2d(),Tolerance);
175             WellDone = CircAna.IsDone();
176             NbrSol = CircAna.NbSolutions();
177             for(Standard_Integer i=1; i<=NbrSol; i++) {
178               CircAna.WhichQualifier(i,qualifier1(i),qualifier2(i));
179             }
180             Results(CircAna);
181           }
182           else {
183             Handle(Geom2d_Line) LLon = Handle(Geom2d_Line)::DownCast(Con);
184             GccAna_Circ2d2TanOn CircAna(Ql1,
185                                GccEnt_QualifiedLin(l2,Qualified2.Qualifier()),
186                                         LLon->Lin2d(),Tolerance);
187             WellDone = CircAna.IsDone();
188             NbrSol = CircAna.NbSolutions();
189             for(Standard_Integer i=1; i<=NbrSol; i++) {
190               CircAna.WhichQualifier(i,qualifier1(i),qualifier2(i));
191             }
192             Results(CircAna);
193           }
194         }
195       }
196     }
197
198 //=============================================================================
199 //                            Appel a GccGeo.                                 +
200 //=============================================================================
201
202     else {
203       if (Type1 == GeomAbs_Circle) {
204         Handle(Geom2d_Circle) CCC1 = Handle(Geom2d_Circle)::DownCast(CC1);
205         gp_Circ2d c1(CCC1->Circ2d());
206         GccEnt_QualifiedCirc Qc1 =
207           GccEnt_QualifiedCirc(c1,Qualified1.Qualifier());
208         if (Type2 == GeomAbs_Circle) {
209           Handle(Geom2d_Circle) CCC2 = Handle(Geom2d_Circle)::DownCast(CC2);
210           gp_Circ2d c2(CCC2->Circ2d());
211           GccEnt_QualifiedCirc Qc2 =
212             GccEnt_QualifiedCirc(c2,Qualified2.Qualifier());
213           Geom2dGcc_Circ2d2TanOnGeo CircGeo(Qc1,Qc2,OnCurve,Tolerance);
214           WellDone = CircGeo.IsDone();
215           NbrSol = CircGeo.NbSolutions();
216           for(Standard_Integer i=1; i<=NbrSol; i++) {
217             CircGeo.WhichQualifier(i,qualifier1(i),qualifier2(i));
218           }
219           Results(CircGeo);
220         }
221         else {
222           Handle(Geom2d_Line) LL2 = Handle(Geom2d_Line)::DownCast(CC2);
223           gp_Lin2d l2(LL2->Lin2d());
224           GccEnt_QualifiedLin Ql2 =
225             GccEnt_QualifiedLin(l2,Qualified2.Qualifier());
226           Geom2dGcc_Circ2d2TanOnGeo CircGeo(Qc1,Ql2,OnCurve,Tolerance);
227           WellDone = CircGeo.IsDone();
228           NbrSol = CircGeo.NbSolutions();
229           for(Standard_Integer i=1; i<=NbrSol; i++) {
230             CircGeo.WhichQualifier(i,qualifier1(i),qualifier2(i));
231           }
232           Results(CircGeo);
233         }
234       }
235       else {
236         Handle(Geom2d_Line) LL1 = Handle(Geom2d_Line)::DownCast(CC1);
237         gp_Lin2d l1(LL1->Lin2d());
238         GccEnt_QualifiedLin Ql1 =
239           GccEnt_QualifiedLin(l1,Qualified1.Qualifier());
240         if (Type2 == GeomAbs_Circle) {
241           Handle(Geom2d_Circle) CCC2 = Handle(Geom2d_Circle)::DownCast(CC2);
242           gp_Circ2d c2(CCC2->Circ2d());
243           GccEnt_QualifiedCirc Qc2 =
244             GccEnt_QualifiedCirc(c2,Qualified2.Qualifier());
245           Geom2dGcc_Circ2d2TanOnGeo CircGeo(Qc2,Ql1,OnCurve,Tolerance);
246           WellDone = CircGeo.IsDone();
247           NbrSol = CircGeo.NbSolutions();
248           for(Standard_Integer i=1; i<=NbrSol; i++) {
249             CircGeo.WhichQualifier(i,qualifier1(i),qualifier2(i));
250           }
251           Results(CircGeo);
252           Invert = Standard_True;
253         }
254         else {
255           Handle(Geom2d_Line) LL2 = Handle(Geom2d_Line)::DownCast(CC2);
256           gp_Lin2d l2(LL2->Lin2d());
257           GccEnt_QualifiedLin Ql2 =
258             GccEnt_QualifiedLin(l2,Qualified2.Qualifier());
259           Geom2dGcc_Circ2d2TanOnGeo CircGeo(Ql1,Ql2,OnCurve,Tolerance);
260           WellDone = CircGeo.IsDone();
261           NbrSol = CircGeo.NbSolutions();
262           for(Standard_Integer i=1; i<=NbrSol; i++) {
263             CircGeo.WhichQualifier(i,qualifier1(i),qualifier2(i));
264           }
265           Results(CircGeo);
266         }
267       }
268     }
269   }
270   else {
271     Geom2dGcc_QCurve Qc1(C1,Qualified1.Qualifier());
272     Geom2dGcc_QCurve Qc2(C2,Qualified2.Qualifier());
273     if ((Type3 == GeomAbs_Circle || Type3 == GeomAbs_Line)) {
274       if (Type3 == GeomAbs_Circle) {
275         Handle(Geom2d_Circle) CCon = Handle(Geom2d_Circle)::DownCast(Con);
276         Geom2dGcc_Circ2d2TanOnIter Circ(Qc1,Qc2,CCon->Circ2d(),
277                                    Param1,Param2,ParamOn,Tolerance);
278         WellDone = Circ.IsDone();
279         NbrSol = 1;
280         cirsol(1)   = Circ.ThisSolution();
281         if (Circ.IsTheSame1()) { TheSame1(1) = 1; }
282         else {TheSame1(1) = 0; }
283         if (Circ.IsTheSame2()) { TheSame2(1) = 1; }
284         else {TheSame2(1) = 0; }
285         Circ.Tangency1(par1sol(1),pararg1(1),pnttg1sol(1));
286         Circ.Tangency2(par2sol(1),pararg2(1),pnttg2sol(1));
287       }
288       else {
289         Handle(Geom2d_Line) LLon = Handle(Geom2d_Line)::DownCast(Con);
290         Geom2dGcc_Circ2d2TanOnIter Circ(Qc1,Qc2,LLon->Lin2d(),
291                                        Param1,Param2,ParamOn,Tolerance);
292         WellDone = Circ.IsDone();
293         NbrSol = 1;
294         cirsol(1)   = Circ.ThisSolution();
295         if (Circ.IsTheSame1()) { TheSame1(1) = 1; }
296         else {TheSame1(1) = 0; }
297         if (Circ.IsTheSame2()) { TheSame2(1) = 1; }
298         else {TheSame2(1) = 0; }
299         Circ.WhichQualifier(qualifier1(1),qualifier2(1));
300         Circ.Tangency1(par1sol(1),pararg1(1),pnttg1sol(1));
301         Circ.Tangency2(par2sol(1),pararg2(1),pnttg2sol(1));
302       }
303     }
304     Geom2dGcc_Circ2d2TanOnIter Circ(Qc1,Qc2,OnCurve,
305                                    Param1,Param2,ParamOn,Tolerance);
306     WellDone = Circ.IsDone();
307     NbrSol = 1;
308     cirsol(1)   = Circ.ThisSolution();
309     if (Circ.IsTheSame1()) { TheSame1(1) = 1; }
310     else {TheSame1(1) = 0; }
311     if (Circ.IsTheSame2()) { TheSame2(1) = 1; }
312     else {TheSame2(1) = 0; }
313     Circ.WhichQualifier(qualifier1(1),qualifier2(1));
314     Circ.Tangency1(par1sol(1),pararg1(1),pnttg1sol(1));
315     Circ.Tangency2(par2sol(1),pararg2(1),pnttg2sol(1));
316   }
317 }
318
319 Geom2dGcc_Circ2d2TanOn::
320    Geom2dGcc_Circ2d2TanOn (const Geom2dGcc_QualifiedCurve&    Qualified1 , 
321                            const Handle(Geom2d_Point)&        Point      , 
322                            const Geom2dAdaptor_Curve&         OnCurve    ,
323                            const Standard_Real                Tolerance  ,
324                            const Standard_Real                Param1     ,
325                            const Standard_Real                ParamOn    ):
326   cirsol(1,8)   ,
327   qualifier1(1,8),
328   qualifier2(1,8),
329   TheSame1(1,8) ,
330   TheSame2(1,8) ,
331   pnttg1sol(1,8),
332   pnttg2sol(1,8),
333   pntcen(1,8)   ,
334   par1sol(1,8)  ,
335   par2sol(1,8)  ,
336   pararg1(1,8)  ,
337   pararg2(1,8)  ,
338   parcen3(1,8)  
339 {
340   Geom2dAdaptor_Curve C1 = Qualified1.Qualified();
341   GeomAbs_CurveType Type1 = C1.GetType();
342   GeomAbs_CurveType Type3 = OnCurve.GetType();
343   Handle(Geom2d_Curve) CC1 = C1.Curve();
344   Handle(Geom2d_Curve) Con = OnCurve.Curve();
345
346 //=============================================================================
347 //                            Appel a GccAna.                                 +
348 //=============================================================================
349
350   Invert = Standard_False;
351   NbrSol = 0;
352   if (Type1 == GeomAbs_Line || Type1 == GeomAbs_Circle) {
353     if (Type3 == GeomAbs_Line || Type3 == GeomAbs_Circle) {
354       gp_Pnt2d pnt(Point->Pnt2d());
355       if (Type1 == GeomAbs_Circle) {
356         Handle(Geom2d_Circle) CCC1 = Handle(Geom2d_Circle)::DownCast(CC1);
357         gp_Circ2d c1(CCC1->Circ2d());
358         GccEnt_QualifiedCirc Qc1(c1,Qualified1.Qualifier());
359         if (Type3 == GeomAbs_Circle) {
360           Handle(Geom2d_Circle) CCon = Handle(Geom2d_Circle)::DownCast(Con);
361           GccAna_Circ2d2TanOn CircAna(Qc1,pnt,CCon->Circ2d(),Tolerance);
362           WellDone = CircAna.IsDone();
363           NbrSol = CircAna.NbSolutions();
364           for(Standard_Integer i=1; i<=NbrSol; i++) {
365             CircAna.WhichQualifier(i,qualifier1(i),qualifier2(i));
366           }
367           Results(CircAna);
368         }
369         else if (Type3 == GeomAbs_Line) {
370           Handle(Geom2d_Line) CCon = Handle(Geom2d_Line)::DownCast(Con);
371           GccAna_Circ2d2TanOn CircAna(Qc1,pnt,CCon->Lin2d(),Tolerance);
372           WellDone = CircAna.IsDone();
373           NbrSol = CircAna.NbSolutions();
374           for(Standard_Integer i=1; i<=NbrSol; i++) {
375             CircAna.WhichQualifier(i,qualifier1(i),qualifier2(i));
376           }
377           Results(CircAna);
378         }
379       }
380       else {
381         Handle(Geom2d_Line) LLL1 = Handle(Geom2d_Line)::DownCast(CC1);
382         gp_Lin2d l1(LLL1->Lin2d());
383         GccEnt_QualifiedLin Ql1(l1,Qualified1.Qualifier());
384         if (Type3 == GeomAbs_Circle) {
385           Handle(Geom2d_Circle) CCon = Handle(Geom2d_Circle)::DownCast(Con);
386           GccAna_Circ2d2TanOn CircAna(Ql1,pnt,CCon->Circ2d(),Tolerance);
387           WellDone = CircAna.IsDone();
388           NbrSol = CircAna.NbSolutions();
389           for(Standard_Integer i=1; i<=NbrSol; i++) {
390             CircAna.WhichQualifier(i,qualifier1(i),qualifier2(i));
391           }
392           Results(CircAna);
393         }
394         else if (Type3 == GeomAbs_Line) {
395           Handle(Geom2d_Line) LLon = Handle(Geom2d_Line)::DownCast(Con);
396           GccAna_Circ2d2TanOn CircAna(Ql1,pnt,LLon->Lin2d(),Tolerance);
397           WellDone = CircAna.IsDone();
398           NbrSol = CircAna.NbSolutions();
399           for(Standard_Integer i=1; i<=NbrSol; i++) {
400             CircAna.WhichQualifier(i,qualifier1(i),qualifier2(i));
401           }
402           Results(CircAna);
403         }
404       }
405     }
406 //=============================================================================
407 //                            Appel a GccGeo.                                 +
408 //=============================================================================
409
410     else {
411       if (Type1 == GeomAbs_Circle) {
412         Handle(Geom2d_Circle) CCC1 = Handle(Geom2d_Circle)::DownCast(CC1);
413         gp_Circ2d c1(CCC1->Circ2d());
414         GccEnt_QualifiedCirc Qc1(c1,Qualified1.Qualifier());
415         Geom2dGcc_Circ2d2TanOnGeo CircGeo(Qc1,Point->Pnt2d(),OnCurve,Tolerance);
416         WellDone = CircGeo.IsDone();
417         NbrSol = CircGeo.NbSolutions();
418         for(Standard_Integer i=1; i<=NbrSol; i++) {
419           CircGeo.WhichQualifier(i,qualifier1(i),qualifier2(i));
420         }
421         Results(CircGeo);
422       }
423       else {
424         Handle(Geom2d_Line) LLL1 = Handle(Geom2d_Line)::DownCast(CC1);
425         gp_Lin2d l1(LLL1->Lin2d());
426         GccEnt_QualifiedLin Ql1(l1,Qualified1.Qualifier());
427         Geom2dGcc_Circ2d2TanOnGeo CircGeo(Ql1,Point->Pnt2d(),OnCurve,Tolerance);
428         WellDone = CircGeo.IsDone();
429         NbrSol = CircGeo.NbSolutions();
430         for(Standard_Integer i=1; i<=NbrSol; i++) {
431           CircGeo.WhichQualifier(i,qualifier1(i),qualifier2(i));
432         }
433         Results(CircGeo);
434       }
435     }
436   }                                   
437   else {
438     Geom2dGcc_QCurve Qc1(C1,Qualified1.Qualifier());
439     if ((Type3 == GeomAbs_Circle || Type3 == GeomAbs_Line)) {
440       if (Type3 == GeomAbs_Circle) {
441         Handle(Geom2d_Circle) CCon = Handle(Geom2d_Circle)::DownCast(Con);
442         Geom2dGcc_Circ2d2TanOnIter Circ(Qc1,Point->Pnt2d(),CCon->Circ2d(),
443                                    Param1,ParamOn,Tolerance);
444         WellDone = Circ.IsDone();
445         NbrSol = 1;
446         cirsol(1)   = Circ.ThisSolution();
447         if (Circ.IsTheSame1()) { TheSame1(1) = 1; }
448         else {TheSame1(1) = 0; }
449         Circ.WhichQualifier(qualifier1(1),qualifier2(1));
450         Circ.Tangency1(par1sol(1),pararg1(1),pnttg1sol(1));
451         Circ.Tangency2(par2sol(1),pararg2(1),pnttg2sol(1));
452       }
453       else {
454         Handle(Geom2d_Line) LLon = Handle(Geom2d_Line)::DownCast(Con);
455         Geom2dGcc_Circ2d2TanOnIter Circ(Qc1,Point->Pnt2d(),LLon->Lin2d(),
456                                        Param1,ParamOn,Tolerance);
457         WellDone = Circ.IsDone();
458         NbrSol = 1;
459         cirsol(1)   = Circ.ThisSolution();
460         if (Circ.IsTheSame1()) { TheSame1(1) = 1; }
461         else {TheSame1(1) = 0; }
462         Circ.WhichQualifier(qualifier1(1),qualifier2(1));
463         Circ.Tangency1(par1sol(1),pararg1(1),pnttg1sol(1));
464         Circ.Tangency2(par2sol(1),pararg2(1),pnttg2sol(1));
465       }
466     }
467     else {
468       Geom2dGcc_Circ2d2TanOnIter Circ(Qc1,Point->Pnt2d(),OnCurve,
469                                  Param1,ParamOn,Tolerance);
470       WellDone = Circ.IsDone();
471       NbrSol = 1;
472       cirsol(1)   = Circ.ThisSolution();
473       if (Circ.IsTheSame1()) { TheSame1(1) = 1; }
474       else {TheSame1(1) = 0; }
475       if (Circ.IsTheSame2()) { TheSame2(1) = 1; }
476       else {TheSame2(1) = 0; }
477       Circ.WhichQualifier(qualifier1(1),qualifier2(1));
478       Circ.Tangency1(par1sol(1),pararg1(1),pnttg1sol(1));
479       Circ.Tangency2(par2sol(1),pararg2(1),pnttg2sol(1));
480     }
481   }
482 }
483
484 Geom2dGcc_Circ2d2TanOn::
485    Geom2dGcc_Circ2d2TanOn (const Handle(Geom2d_Point)&        Point1     , 
486                            const Handle(Geom2d_Point)&        Point2     , 
487                            const Geom2dAdaptor_Curve&         OnCurve    ,
488                            const Standard_Real                Tolerance  ):
489   cirsol(1,8)   ,
490   qualifier1(1,8),
491   qualifier2(1,8),
492   TheSame1(1,8) ,
493   TheSame2(1,8) ,
494   pnttg1sol(1,8),
495   pnttg2sol(1,8),
496   pntcen(1,8)   ,
497   par1sol(1,8)  ,
498   par2sol(1,8)  ,
499   pararg1(1,8)  ,
500   pararg2(1,8)  ,
501   parcen3(1,8)  
502
503 {
504   GeomAbs_CurveType Type3 = OnCurve.GetType();
505   Handle(Geom2d_Curve) Con = OnCurve.Curve();
506
507 //=============================================================================
508 //                            Appel a GccAna.                                 +
509 //=============================================================================
510
511   Invert = Standard_False;
512   NbrSol = 0;
513   if (Type3 == GeomAbs_Line || Type3 == GeomAbs_Circle) {
514     gp_Pnt2d pnt1(Point1->Pnt2d());
515     gp_Pnt2d pnt2(Point2->Pnt2d());
516     if (Type3 == GeomAbs_Circle) {
517       Handle(Geom2d_Circle) CCon = Handle(Geom2d_Circle)::DownCast(Con);
518       GccAna_Circ2d2TanOn CircAna(pnt1,pnt2,CCon->Circ2d(),Tolerance);
519       WellDone = CircAna.IsDone();
520       NbrSol = CircAna.NbSolutions();
521       for(Standard_Integer i=1; i<=NbrSol; i++) {
522         CircAna.WhichQualifier(i,qualifier1(i),qualifier2(i));
523       }
524       Results(CircAna);
525     }
526     else {
527       Handle(Geom2d_Line) LLon = Handle(Geom2d_Line)::DownCast(Con);
528       GccAna_Circ2d2TanOn CircAna(pnt1,pnt2,LLon->Lin2d(),Tolerance);
529       WellDone = CircAna.IsDone();
530       NbrSol = CircAna.NbSolutions();
531       for(Standard_Integer i=1; i<=NbrSol; i++) {
532         CircAna.WhichQualifier(i,qualifier1(i),qualifier2(i));
533       }
534       Results(CircAna);
535     }
536   }
537
538 //=============================================================================
539 //                            Appel a GccGeo.                                 +
540 //=============================================================================
541
542   else {
543     Geom2dGcc_Circ2d2TanOnGeo CircGeo(Point1->Pnt2d(),Point2->Pnt2d(),
544                                      OnCurve,Tolerance);
545     WellDone = CircGeo.IsDone();
546     NbrSol = CircGeo.NbSolutions();
547     for(Standard_Integer i=1; i<=NbrSol; i++) {
548       CircGeo.WhichQualifier(i,qualifier1(i),qualifier2(i));
549     }
550     Results(CircGeo);
551   }
552 }
553
554 void Geom2dGcc_Circ2d2TanOn::Results(const GccAna_Circ2d2TanOn& Circ)
555 {
556   for (Standard_Integer j = 1; j <= NbrSol; j++) {
557     cirsol(j)   = Circ.ThisSolution(j);
558     if (Circ.IsTheSame1(j)) { TheSame1(j) = 1; }
559     else {TheSame1(j) = 0; }
560     if (Circ.IsTheSame2(j)) { TheSame2(j) = 1; }
561     else {TheSame2(j) = 0; }
562     Circ.WhichQualifier(j,qualifier1(j),qualifier2(j));
563     Circ.Tangency1(j,par1sol(j),pararg1(j),pnttg1sol(j));
564     Circ.Tangency2(j,par2sol(j),pararg2(j),pnttg2sol(j));
565     Circ.CenterOn3(j,parcen3(j),pntcen(j));
566   }
567 }
568
569 void Geom2dGcc_Circ2d2TanOn::Results(const Geom2dGcc_Circ2d2TanOnGeo& Circ)
570 {
571   for (Standard_Integer j = 1; j <= NbrSol; j++) {
572     cirsol(j)   = Circ.ThisSolution(j);
573     if (Circ.IsTheSame1(j)) { TheSame1(j) = 1; }
574     else {TheSame1(j) = 0; }
575     if (Circ.IsTheSame2(j)) { TheSame2(j) = 1; }
576     else {TheSame2(j) = 0; }
577     Circ.WhichQualifier(j,qualifier1(j),qualifier2(j));
578     Circ.Tangency1(j,par1sol(j),pararg1(j),pnttg1sol(j));
579     Circ.Tangency2(j,par2sol(j),pararg2(j),pnttg2sol(j));
580     Circ.CenterOn3(j,parcen3(j),pntcen(j));
581   }
582 }
583
584 Standard_Boolean Geom2dGcc_Circ2d2TanOn::
585    IsDone () const { return WellDone; }
586
587 Standard_Integer Geom2dGcc_Circ2d2TanOn::
588   NbSolutions () const 
589
590   return NbrSol;
591 }
592
593 gp_Circ2d Geom2dGcc_Circ2d2TanOn::
594   ThisSolution (const Standard_Integer Index) const 
595 {
596   if (!WellDone) { StdFail_NotDone::Raise(); }
597   if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); }
598   return cirsol(Index);
599 }
600
601 void Geom2dGcc_Circ2d2TanOn::
602   WhichQualifier (const Standard_Integer Index   ,
603                         GccEnt_Position& Qualif1 ,
604                         GccEnt_Position& Qualif2) const
605 {
606   if (!WellDone) { StdFail_NotDone::Raise(); }
607   else if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); }
608   else {
609     if (Invert) {
610       Qualif1 = qualifier2(Index);
611       Qualif2 = qualifier1(Index);
612     }
613     else {
614       Qualif1 = qualifier1(Index);
615       Qualif2 = qualifier2(Index);
616     }
617   }
618 }
619
620 void Geom2dGcc_Circ2d2TanOn::
621   Tangency1 (const Standard_Integer Index,
622                    Standard_Real&   ParSol,
623                    Standard_Real&   ParArg,
624                    gp_Pnt2d&        PntSol) const
625 {
626   if (!WellDone) { StdFail_NotDone::Raise(); }
627   else if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); }
628   else {
629     if (Invert) {
630       if (TheSame2(Index) == 0) {
631         ParSol = par2sol(Index);
632         ParArg = pararg2(Index);
633         PntSol = pnttg2sol(Index);
634       }
635       else { StdFail_NotDone::Raise(); }
636     }
637     else {
638       if (TheSame1(Index) == 0) {
639         ParSol = par1sol(Index);
640         ParArg = pararg1(Index);
641         PntSol = pnttg1sol(Index);
642       }
643       else { StdFail_NotDone::Raise(); }
644     }
645   }
646 }
647
648 void Geom2dGcc_Circ2d2TanOn::
649    Tangency2 (const Standard_Integer Index,
650               Standard_Real& ParSol,
651               Standard_Real& ParArg,
652               gp_Pnt2d& PntSol) const
653 {
654   if (!WellDone) { StdFail_NotDone::Raise(); }
655   else if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); }
656   else {
657     if (!Invert) {
658       if (TheSame2(Index) == 0) {
659         ParSol = par2sol(Index);
660         ParArg = pararg2(Index);
661         PntSol = pnttg2sol(Index);
662       }
663       else { StdFail_NotDone::Raise(); }
664     }
665     else {
666       if (TheSame1(Index) == 0) {
667         ParSol = par1sol(Index);
668         ParArg = pararg1(Index);
669         PntSol = pnttg1sol(Index);
670       }
671       else { StdFail_NotDone::Raise(); }
672     }
673   }
674 }
675
676 void Geom2dGcc_Circ2d2TanOn::
677    CenterOn3 (const Standard_Integer Index,
678               Standard_Real& ParArg,
679               gp_Pnt2d& PntSol) const
680 {
681   if (!WellDone) { StdFail_NotDone::Raise(); }
682   else if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); }
683   else {
684     ParArg = parcen3(Index);
685     PntSol = pntcen(Index);
686   }
687 }
688
689 Standard_Boolean Geom2dGcc_Circ2d2TanOn::
690    IsTheSame1 (const Standard_Integer Index) const
691 {
692   if (!WellDone) { StdFail_NotDone::Raise(); }
693   if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); }
694   if (Invert) {
695     if (TheSame2(Index) == 0) { return Standard_False; }
696     else { return Standard_True; }
697   }
698   else {
699     if (TheSame1(Index) == 0) { return Standard_False; }
700     else { return Standard_True; }
701   }
702 }
703
704 Standard_Boolean Geom2dGcc_Circ2d2TanOn::
705    IsTheSame2 (const Standard_Integer Index) const
706 {
707   if (!WellDone) { StdFail_NotDone::Raise(); }
708   if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); }
709   if (!Invert) {
710     if (TheSame2(Index) == 0) { return Standard_False; }
711     else { return Standard_True; }
712     }
713   else {
714     if (TheSame1(Index) == 0) { return Standard_False; }
715     else { return Standard_True; }
716   }
717 //  return Standard_True;
718 }