0025418: Debug output to be limited to OCC development environment
[occt.git] / src / GccAna / GccAna_Circ2d3Tan_8.cxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #include <GccAna_Circ2d3Tan.jxx>
16
17 #include <ElCLib.hxx>
18 #include <IntAna2d_AnaIntersection.hxx>
19 #include <IntAna2d_IntPoint.hxx>
20 #include <gp_Lin2d.hxx>
21 #include <gp_Circ2d.hxx>
22 #include <gp_Dir2d.hxx>
23 #include <GccAna_LinPnt2dBisec.hxx>
24 #include <GccAna_Lin2dBisec.hxx>
25 #include <GccAna_Pnt2dBisec.hxx>
26 #include <GccInt_Bisec.hxx>
27 #include <GccInt_IType.hxx>
28 #include <IntAna2d_Conic.hxx>
29 #include <GccEnt_BadQualifier.hxx>
30 #include <Precision.hxx>
31 //=========================================================================
32 //   Creation of a circle tangent to a straight line and two points.      +
33 //=========================================================================
34
35 GccAna_Circ2d3Tan::
36    GccAna_Circ2d3Tan (const GccEnt_QualifiedLin& Qualified1,
37                       const gp_Pnt2d&            Point2    ,
38                       const gp_Pnt2d&            Point3    ,
39                       const Standard_Real        Tolerance ):
40
41    cirsol(1,2)     ,
42    qualifier1(1,2) ,
43    qualifier2(1,2) ,
44    qualifier3(1,2) ,
45    TheSame1(1,2)   ,
46    TheSame2(1,2)   ,
47    TheSame3(1,2)   ,
48    pnttg1sol(1,2)  ,
49    pnttg2sol(1,2)  ,
50    pnttg3sol(1,2)  ,
51    par1sol(1,2)    ,
52    par2sol(1,2)    ,
53    par3sol(1,2)    ,
54    pararg1(1,2)    ,
55    pararg2(1,2)    ,
56    pararg3(1,2)    
57 {
58
59    WellDone = Standard_False;
60    Standard_Real Tol = Abs(Tolerance);
61    gp_Dir2d dirx(1.0,0.0);
62    NbrSol = 0;
63    if (!(Qualified1.IsEnclosed() ||
64          Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
65      GccEnt_BadQualifier::Raise();
66      return;
67    }
68
69 //=========================================================================
70 //   Processing.                                                          +
71 //=========================================================================
72
73    gp_Lin2d L1  = Qualified1.Qualified();
74    gp_Pnt2d origin1(L1.Location());
75    gp_Dir2d dir1(L1.Direction());
76    gp_Dir2d normL1(-dir1.Y(),dir1.X());
77
78    if (Point2.IsEqual(Point3,Precision::Confusion())) {
79      WellDone = Standard_False;
80      return ;
81    }
82
83    GccAna_Pnt2dBisec Bis1(Point2,Point3);
84    GccAna_LinPnt2dBisec Bis2(L1,Point2);
85    if (Bis1.IsDone() && Bis2.IsDone()) {
86      gp_Lin2d linint1(Bis1.ThisSolution());
87      Handle(GccInt_Bisec) Sol2 = Bis2.ThisSolution();
88      GccInt_IType typ2 = Sol2->ArcType();
89 #ifdef OCCT_DEBUG
90      gp_Lin2d linintb(Bis1.ThisSolution());
91 #else
92      Bis1.ThisSolution() ;
93 #endif
94      IntAna2d_AnaIntersection Intp;
95      if (typ2 == GccInt_Lin) {
96        gp_Lin2d linint2(Sol2->Line());
97        Intp.Perform (linint1,linint2);
98      }
99      else if (typ2 == GccInt_Par) {
100        Intp.Perform (linint1,IntAna2d_Conic(Sol2->Parabola()));
101      }
102      if (Intp.IsDone()) {
103        if ((!Intp.IsEmpty())&&(!Intp.ParallelElements())&&
104            (!Intp.IdenticalElements())) {
105          for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
106            gp_Pnt2d Center(Intp.Point(j).Value());
107            Standard_Real dist1 = L1.Distance(Center);
108            Standard_Real dist2 = Center.Distance(Point2);
109
110            Standard_Real Radius=0;
111            Standard_Integer nbsol3 = 0;
112            Standard_Boolean ok = Standard_False;
113      Standard_Real  difference = (((origin1.X()-Center.X())*(-dir1.Y())) + ((origin1.Y()-Center.Y())*(dir1.X())));
114      if ((Qualified1.IsEnclosed() && difference <= 0) ||
115          (Qualified1.IsOutside() && difference >= 0) ||
116          (Qualified1.IsUnqualified()))
117      {
118        ok = Standard_True;
119        Radius = dist1;
120      }
121            if (ok) {
122              if (Abs(dist2-Radius)<=Tol) { 
123                nbsol3 = 1;
124              }
125              else { ok = Standard_False; }
126            }
127            if (ok) {
128              for (Standard_Integer k = 1 ; k <= nbsol3 ; k++) {
129                NbrSol++;
130                cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
131 //             =======================================================
132                gp_Dir2d dc1(origin1.XY()-Center.XY());
133                if (!Qualified1.IsUnqualified()) { 
134                  qualifier1(NbrSol) = Qualified1.Qualifier();
135                }
136                else if (dc1.Dot(normL1) > 0.0) {
137                  qualifier1(NbrSol) = GccEnt_outside;
138                }
139                else { qualifier1(NbrSol) = GccEnt_enclosed; }
140                qualifier2(NbrSol) = GccEnt_noqualifier;
141                qualifier3(NbrSol) = GccEnt_noqualifier;
142                TheSame1(NbrSol) = 0;
143                gp_Dir2d dc(origin1.XY()-Center.XY());
144                Standard_Real sign = dc.Dot(gp_Dir2d(-dir1.Y(),dir1.X()));
145                dc = gp_Dir2d(sign*gp_XY(-dir1.Y(),dir1.X()));
146                pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius*dc.XY());
147                par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
148                                                 pnttg1sol(NbrSol));
149                pararg1(NbrSol)=ElCLib::Parameter(L1,pnttg1sol(NbrSol));
150                TheSame2(NbrSol) = 0;
151                pnttg2sol(NbrSol) = Point2;
152                par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
153                                                 pnttg2sol(NbrSol));
154                pararg2(NbrSol) = 0.;
155                TheSame3(NbrSol) = 0;
156                pnttg3sol(NbrSol) = Point3;
157                par3sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
158                                                 pnttg3sol(NbrSol));
159                pararg3(NbrSol) = 0.;
160              }
161            }
162          }
163        }
164        WellDone = Standard_True;
165      }
166    }
167  }
168