0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / GccAna / GccAna_Circ2d2TanRad_4.cxx
1 // Created on: 1991-09-24
2 // Created by: Remi GILET
3 // Copyright (c) 1991-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_Circ2d2TanRad.hxx>
20 #include <GccEnt_BadQualifier.hxx>
21 #include <GccEnt_QualifiedLin.hxx>
22 #include <gp_Ax2d.hxx>
23 #include <gp_Circ2d.hxx>
24 #include <gp_Lin2d.hxx>
25 #include <gp_Pnt2d.hxx>
26 #include <IntAna2d_AnaIntersection.hxx>
27 #include <IntAna2d_IntPoint.hxx>
28 #include <Precision.hxx>
29 #include <Standard_NegativeValue.hxx>
30 #include <TColStd_Array1OfReal.hxx>
31
32 // circular tangent to two lines of given radius
33 //===============================================
34 //========================================================================
35 // Initialize WellDone to false.                                       +
36 // Return two lines L1 and L2.                                 +
37 // Leave with error if the construction is impossible.     +
38 // Create parallel lines to L1 and L2 in the proper direction.                   +
39 // Intersect parallels ==> The center point of the solution.   +
40 // Create the solution to be added to the already found solutions.         +
41 // Fill the fields.                                                +
42 //========================================================================
43 GccAna_Circ2d2TanRad::
44    GccAna_Circ2d2TanRad (const GccEnt_QualifiedLin&  Qualified1 ,
45                          const GccEnt_QualifiedLin&  Qualified2 ,
46                          const Standard_Real         Radius     ,
47                          const Standard_Real                    ):
48    qualifier1(1,4) ,
49    qualifier2(1,4),
50    TheSame1(1,4)   ,
51    TheSame2(1,4)   ,
52    cirsol(1,4)     ,
53    pnttg1sol(1,4)  ,
54    pnttg2sol(1,4)  ,
55    par1sol(1,4)    ,
56    par2sol(1,4)    ,
57    pararg1(1,4)    ,
58    pararg2(1,4)    
59 {
60
61   gp_Dir2d dirx(1.0,0.0);
62   TColStd_Array1OfReal cote1(1,2);
63   TColStd_Array1OfReal cote2(1,2);
64   Standard_Integer nbrcote1=0;
65   Standard_Integer nbrcote2=0;
66   NbrSol = 0;
67   WellDone = Standard_False;
68   if (!(Qualified1.IsEnclosed() || 
69         Qualified1.IsOutside() || Qualified1.IsUnqualified()) ||
70       !(Qualified2.IsEnclosed() ||
71         Qualified2.IsOutside() || Qualified2.IsUnqualified())) {
72     throw GccEnt_BadQualifier();
73     return;
74   }
75   gp_Lin2d L1 = Qualified1.Qualified();
76   gp_Lin2d L2 = Qualified2.Qualified();
77   Standard_Real x1dir = (L1.Direction()).X();
78   Standard_Real y1dir = (L1.Direction()).Y();
79   Standard_Real lx1loc = (L1.Location()).X();
80   Standard_Real ly1loc = (L1.Location()).Y();
81   Standard_Real x2dir = (L2.Direction()).X();
82   Standard_Real y2dir = (L2.Direction()).Y();
83   Standard_Real lx2loc = (L2.Location()).X();
84   Standard_Real ly2loc = (L2.Location()).Y();
85   gp_Pnt2d origin1(lx1loc,ly1loc);
86   gp_Pnt2d origin2(lx2loc,ly2loc);
87   gp_Dir2d normL1(x1dir,y1dir);
88   gp_Dir2d normL2(x2dir,y2dir);
89   if (Radius < 0.0) { throw Standard_NegativeValue(); }
90   else {
91     if (L1.Direction().IsParallel(L2.Direction(),Precision::Angular())) { 
92       WellDone = Standard_True;
93     }
94     else {
95       if (Qualified1.IsEnclosed() && Qualified2.IsEnclosed()) {
96 //    =======================================================
97         nbrcote1 = 1;
98         nbrcote2 = 1;
99         cote1(1) = 1.0;
100         cote2(1) = 1.0;
101       }
102       else if(Qualified1.IsEnclosed() && Qualified2.IsOutside()) {
103 //    ==========================================================
104         nbrcote1 = 1;
105         nbrcote2 = 1;
106         cote1(1) = 1.0;
107         cote2(1) = -1.0;
108       }
109       else if (Qualified1.IsOutside() && Qualified2.IsEnclosed()) {
110 //    ===========================================================
111         nbrcote1 = 1;
112         nbrcote2 = 1;
113         cote1(1) = -1.0;
114         cote2(1) = 1.0;
115       }
116       else if(Qualified1.IsOutside() && Qualified2.IsOutside()) {
117 //    =========================================================
118         nbrcote1 = 1;
119         nbrcote2 = 1;
120         cote1(1) = -1.0;
121         cote2(1) = -1.0;
122       }
123       if(Qualified1.IsEnclosed() && Qualified2.IsUnqualified()) {
124 //    =========================================================
125         nbrcote1 = 1;
126         nbrcote2 = 2;
127         cote1(1) = 1.0;
128         cote2(1) = 1.0;
129         cote2(2) = -1.0;
130       }
131       if(Qualified1.IsUnqualified() && Qualified2.IsEnclosed()) {
132 //    =========================================================
133         nbrcote1 = 2;
134         nbrcote2 = 1;
135         cote1(1) = 1.0;
136         cote1(2) = -1.0;
137         cote2(1) = 1.0;
138       }
139       else if(Qualified1.IsOutside() && Qualified2.IsUnqualified()) {
140 //    =============================================================
141         nbrcote1 = 1;
142         nbrcote2 = 2;
143         cote1(1) = -1.0;
144         cote2(1) = 1.0;
145         cote2(2) = -1.0;
146       }
147       if(Qualified1.IsUnqualified() && Qualified2.IsOutside()) {
148 //    ========================================================
149         nbrcote1 = 2;
150         nbrcote2 = 1;
151         cote1(1) = 1.0;
152         cote1(2) = -1.0;
153         cote2(1) = -1.0;
154       }
155       else if(Qualified1.IsUnqualified() && Qualified2.IsUnqualified()) {
156 //    =================================================================
157         nbrcote1 = 2;
158         nbrcote2 = 2;
159         cote1(1) = 1.0;
160         cote1(2) = -1.0;
161         cote2(1) = 1.0;
162         cote2(2) = -1.0;
163       }
164       for (Standard_Integer jcote1 = 1 ; jcote1 <= nbrcote1 ; jcote1++) {
165         for (Standard_Integer jcote2 = 1 ; jcote2 <= nbrcote2 ; jcote2++) {
166           gp_Lin2d linint1(gp_Pnt2d(lx1loc-cote1(jcote1)*y1dir*Radius,
167                                     ly1loc+cote1(jcote1)*x1dir*Radius),
168                            L1.Direction());
169           gp_Lin2d linint2(gp_Pnt2d(lx2loc-cote2(jcote2)*y2dir*Radius,
170                                     ly2loc+cote2(jcote2)*x2dir*Radius),
171                            L2.Direction());
172           IntAna2d_AnaIntersection Intp(linint1,linint2);
173           if (Intp.IsDone()) {
174             if (!Intp.IsEmpty()) {
175               for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
176                 NbrSol++;
177                 gp_Pnt2d Center(Intp.Point(i).Value());
178                 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
179 //              =======================================================
180                 gp_Dir2d dc1(origin1.XY()-Center.XY());
181                 gp_Dir2d dc2(origin2.XY()-Center.XY());
182                 if (!Qualified1.IsUnqualified()) { 
183                   qualifier1(NbrSol) = Qualified1.Qualifier();
184                 }
185                 else if (dc1.Dot(normL1) > 0.0) {
186                   qualifier1(NbrSol) = GccEnt_outside;
187                 }
188                 else { qualifier1(NbrSol) = GccEnt_enclosed; }
189                 if (!Qualified2.IsUnqualified()) { 
190                   qualifier2(NbrSol) = Qualified2.Qualifier();
191                 }
192                 else if (dc2.Dot(normL2) > 0.0) {
193                   qualifier2(NbrSol) = GccEnt_outside;
194                 }
195                 else { qualifier2(NbrSol) = GccEnt_enclosed; }
196                 TheSame1(NbrSol) = 0;
197                 TheSame2(NbrSol) = 0;
198                 pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()+
199                                      cote1(jcote1)*Radius*gp_XY(y1dir,-x1dir));
200                 pnttg2sol(NbrSol) = gp_Pnt2d(Center.XY()+
201                                      cote2(jcote2)*Radius*gp_XY(y2dir,-x2dir));
202               }
203             }
204             WellDone = Standard_True;
205           }
206         }
207       }
208     }
209   }
210   for (Standard_Integer i = 1 ; i <= NbrSol ; i++) {
211     par1sol(i)=ElCLib::Parameter(cirsol(i),pnttg1sol(i));
212     pararg1(i)=ElCLib::Parameter(L1,pnttg1sol(i));
213     par2sol(i)=ElCLib::Parameter(cirsol(i),pnttg2sol(i));
214     pararg2(i)=ElCLib::Parameter(L2,pnttg2sol(i));
215   }
216 }
217
218
219