0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / GccAna / GccAna_Circ2d2TanOn_10.cxx
1 // Created on: 1992-01-02
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
18 #include <ElCLib.hxx>
19 #include <GccAna_Circ2d2TanOn.hxx>
20 #include <GccAna_LinPnt2dBisec.hxx>
21 #include <GccEnt_BadQualifier.hxx>
22 #include <GccEnt_QualifiedCirc.hxx>
23 #include <GccEnt_QualifiedLin.hxx>
24 #include <GccInt_Bisec.hxx>
25 #include <GccInt_BLine.hxx>
26 #include <GccInt_IType.hxx>
27 #include <gp_Ax2d.hxx>
28 #include <gp_Circ2d.hxx>
29 #include <gp_Dir2d.hxx>
30 #include <gp_Lin2d.hxx>
31 #include <gp_Pnt2d.hxx>
32 #include <IntAna2d_AnaIntersection.hxx>
33 #include <IntAna2d_Conic.hxx>
34 #include <IntAna2d_IntPoint.hxx>
35 #include <Standard_OutOfRange.hxx>
36 #include <StdFail_NotDone.hxx>
37
38 //=========================================================================
39 //   Creation of a circle tangent to straight line L1 and a point Point2.   +
40 //                        centered on a circle.                           +
41 //  We start by making difference between boundary cases that will be    +
42 //  processed separately.                                            +
43 //  In general case:                                                  +
44 //  ====================                                                  +
45 //  We calculate bissectrices to L1 and Point2 that give us all        +
46 //  all possible locations of centers of all circles        +
47 //  tangent to L1 and Point2.                                              +
48 //  We intersect these bissectrices with circle OnCirc which gives us +
49 //  points among which we'll choose the solutions.   +
50 //  The choice is made using Qualifiers of L1.        +
51 //=========================================================================
52 GccAna_Circ2d2TanOn::
53    GccAna_Circ2d2TanOn (const GccEnt_QualifiedLin&  Qualified1 ,
54                         const gp_Pnt2d&             Point2     ,
55                         const gp_Circ2d&            OnCirc     ,
56                         const Standard_Real         Tolerance  ):
57    cirsol(1,4)     ,
58    qualifier1(1,4) ,
59    qualifier2(1,4) ,
60    TheSame1(1,4) ,
61    TheSame2(1,4) ,
62    pnttg1sol(1,4)  ,
63    pnttg2sol(1,4)  ,
64    pntcen(1,4)     ,
65    par1sol(1,4)    ,
66    par2sol(1,4)    ,
67    pararg1(1,4)    ,
68    pararg2(1,4)    ,
69    parcen3(1,4)
70 {
71
72   TheSame1.Init(0);
73   TheSame2.Init(0);
74   WellDone = Standard_False;
75   NbrSol = 0;
76   if (!(Qualified1.IsEnclosed() ||
77         Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
78   throw GccEnt_BadQualifier();
79     return;
80   }
81   Standard_Real Tol = Abs(Tolerance);
82   gp_Dir2d dirx(1.,0.);
83   gp_Lin2d L1 = Qualified1.Qualified();
84   gp_Pnt2d originL1(L1.Location());
85   gp_Dir2d dirL1(L1.Direction());
86   gp_Dir2d normL1(-dirL1.Y(),dirL1.X());
87
88 //=========================================================================
89 //   Processing of boundary cases.                                          +
90 //=========================================================================
91
92   Standard_Real Ron = OnCirc.Radius();
93   Standard_Real distpc = OnCirc.Location().Distance(Point2);
94   gp_Dir2d dir(OnCirc.Location().XY()-Point2.XY());
95   gp_Pnt2d pinterm(Point2.XY()+(distpc+Ron)*dir.XY());
96   Standard_Real dist1 = L1.Distance(pinterm);
97
98   if (Abs(dist1-distpc+Ron) <= Tol) {
99     dir = gp_Dir2d(-dirL1.Y(),dirL1.X());
100     gp_Dir2d direc(originL1.XY()-pinterm.XY());
101     if (Qualified1.IsOutside()) {
102       if (direc.Dot(dir) >= 0.0) { WellDone = Standard_True; }
103     }
104     else if (Qualified1.IsEnclosed()) {
105       if (direc.Dot(dir) <= 0.0) { WellDone = Standard_True; }
106     }
107     else { WellDone = Standard_True; }
108     if (WellDone) {
109       NbrSol++;
110       cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(pinterm,dirx),dist1);
111 //    =======================================================
112       gp_Dir2d dc1(originL1.XY()-pinterm.XY());
113       Standard_Real sign = dc1.Dot(normL1);
114       if (!Qualified1.IsUnqualified()) { 
115         qualifier1(NbrSol) = Qualified1.Qualifier();
116       }
117       else if (dc1.Dot(normL1) > 0.0) { qualifier1(NbrSol) = GccEnt_outside; }
118       else { qualifier1(NbrSol) = GccEnt_enclosed; }
119       qualifier2(NbrSol) = GccEnt_noqualifier;
120       dc1 = gp_Dir2d(sign*gp_XY(-dirL1.Y(),dirL1.X()));
121       pnttg1sol(NbrSol) = gp_Pnt2d(pinterm.XY()+dist1*dc1.XY());
122       par1sol(NbrSol) = ElCLib::Parameter(cirsol(NbrSol),pnttg1sol(NbrSol));
123       pararg1(NbrSol)=ElCLib::Parameter(L1,pnttg1sol(NbrSol));
124       pntcen(NbrSol) = pinterm;
125       parcen3(NbrSol)=ElCLib::Parameter(OnCirc,pntcen(NbrSol));
126       parcen3(NbrSol) = 0.;
127       pnttg2sol(NbrSol) = Point2;
128       pararg2(NbrSol) = 0.;
129       par2sol(NbrSol) = ElCLib::Parameter(cirsol(NbrSol),pnttg2sol(NbrSol));
130       return;
131     }
132   }
133
134 //=========================================================================
135 //   General case.                                                         +
136 //=========================================================================
137
138   GccAna_LinPnt2dBisec Bis(L1,Point2);
139   if (Bis.IsDone()) {
140     Handle(GccInt_Bisec) Sol = Bis.ThisSolution();
141     GccInt_IType type = Sol->ArcType();
142     IntAna2d_AnaIntersection Intp;
143     if (type == GccInt_Lin) {
144       Intp.Perform(Sol->Line(),OnCirc);
145     }
146     if (type == GccInt_Par) {
147       Intp.Perform(OnCirc,IntAna2d_Conic(Sol->Parabola()));
148     }
149     if (Intp.IsDone()) {
150       if (!Intp.IsEmpty()) {
151         for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
152           gp_Pnt2d Center(Intp.Point(j).Value());
153           Standard_Real Radius = L1.Distance(Center);
154 //        Standard_Integer nbsol = 1;
155           Standard_Boolean ok = Standard_False;
156           if (Qualified1.IsEnclosed()) {
157             if ((((originL1.X()-Center.X())*(-dirL1.Y()))+
158                  ((originL1.Y()-Center.Y())*(dirL1.X())))<=0){
159               ok = Standard_True;
160             }
161           }
162           else if (Qualified1.IsOutside()) {
163             if ((((originL1.X()-Center.X())*(-dirL1.Y()))+
164                  ((originL1.Y()-Center.Y())*(dirL1.X())))>=0){
165               ok = Standard_True;
166             }
167           }
168           else if (Qualified1.IsUnqualified()) {
169             ok = Standard_True;
170           }
171           if (ok) {
172             NbrSol++;
173             cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
174 //          =======================================================
175             TheSame1(NbrSol) = 0;
176             TheSame2(NbrSol) = 0;
177             gp_Dir2d dc1(originL1.XY()-Center.XY());
178             Standard_Real sign = dc1.Dot(normL1);
179             if (!Qualified1.IsUnqualified()) { 
180               qualifier1(NbrSol) = Qualified1.Qualifier();
181             }
182             else if (dc1.Dot(normL1) > 0.0) {   
183               qualifier1(NbrSol) = GccEnt_outside; 
184             }
185             else { qualifier1(NbrSol) = GccEnt_enclosed; }
186             qualifier2(NbrSol) = GccEnt_noqualifier;
187             dc1=gp_Dir2d(sign*gp_XY(-dirL1.Y(),dirL1.X()));
188             pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()+dist1*dc1.XY());
189             par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
190                                               pnttg1sol(NbrSol));
191             pararg1(NbrSol)=ElCLib::Parameter(L1,pnttg1sol(NbrSol));
192             pntcen(NbrSol) = Center;
193             parcen3(NbrSol) = ElCLib::Parameter(OnCirc,pntcen(NbrSol));
194             pnttg2sol(NbrSol) = Point2;
195             pararg2(NbrSol) = 0.;
196             par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
197                                               pnttg2sol(NbrSol));
198             qualifier2(NbrSol) = GccEnt_noqualifier;
199            }
200         }
201       }
202       WellDone = Standard_True;
203     }
204   }
205 }
206