0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / GccAna / GccAna_Circ2d2TanOn_1.cxx
CommitLineData
b311480e 1// Created on: 1992-01-02
2// Created by: Remi GILET
3// Copyright (c) 1992-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22#include <GccAna_Circ2d2TanOn.jxx>
23
24#include <ElCLib.hxx>
25#include <gp_Dir2d.hxx>
26#include <gp_Ax2d.hxx>
27#include <IntAna2d_AnaIntersection.hxx>
28#include <IntAna2d_IntPoint.hxx>
29#include <GccAna_CircLin2dBisec.hxx>
30#include <GccInt_IType.hxx>
31#include <GccInt_BCirc.hxx>
32#include <IntAna2d_Conic.hxx>
33#include <GccEnt_BadQualifier.hxx>
34
35//=========================================================================
0d969553
Y
36// Creation of a circle tangent to Circle C1 and a straight line L2. +
37// centered on a straight line. +
38// We start by making difference between cases that we are going to +
39// proceess separately. +
40// In general case: +
7fd59977 41// ==================== +
0d969553
Y
42// We calculate bissectrices to C1 and L2 that give us +
43// all possibles locations of centers of all circles tangent to C1 and L2+ +
44// We intersect these bissectrices with straight line OnLine which gives +
45// us points among which we'll choose the solutions. +
46// The choices are made basing on Qualifiers of C1 and L2. +
7fd59977 47//=========================================================================
48
49GccAna_Circ2d2TanOn::
50 GccAna_Circ2d2TanOn (const GccEnt_QualifiedCirc& Qualified1 ,
51 const GccEnt_QualifiedLin& Qualified2 ,
52 const gp_Lin2d& OnLine ,
53 const Standard_Real Tolerance ):
54 cirsol(1,4) ,
55 qualifier1(1,4) ,
56 qualifier2(1,4),
57 TheSame1(1,4) ,
58 TheSame2(1,4) ,
59 pnttg1sol(1,4) ,
60 pnttg2sol(1,4) ,
61 pntcen(1,4) ,
62 par1sol(1,4) ,
63 par2sol(1,4) ,
64 pararg1(1,4) ,
65 pararg2(1,4) ,
66 parcen3(1,4)
67{
68
69 TheSame1.Init(0);
70 TheSame2.Init(0);
71 WellDone = Standard_False;
72 NbrSol = 0;
73 if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() ||
74 Qualified1.IsOutside() || Qualified1.IsUnqualified()) ||
75 !(Qualified2.IsEnclosed() ||
76 Qualified2.IsOutside() || Qualified2.IsUnqualified())) {
77 GccEnt_BadQualifier::Raise();
78 return;
79 }
80 Standard_Real Tol = Abs(Tolerance);
81 Standard_Real Radius=0;
82 Standard_Boolean ok = Standard_False;
83 gp_Dir2d dirx(1.,0.);
84 gp_Circ2d C1 = Qualified1.Qualified();
85 gp_Lin2d L2 = Qualified2.Qualified();
86 Standard_Real R1 = C1.Radius();
87 gp_Pnt2d center1(C1.Location());
88 gp_Pnt2d origin2(L2.Location());
89 gp_Dir2d dirL2(L2.Direction());
90 gp_Dir2d normL2(-dirL2.Y(),dirL2.X());
91
92//=========================================================================
0d969553 93// Processing of limit cases. +
7fd59977 94//=========================================================================
95
96 Standard_Real distcl = OnLine.Distance(center1);
97 gp_Pnt2d pinterm(center1.XY()+distcl*
98 gp_XY(-OnLine.Direction().Y(),OnLine.Direction().X()));
99 if (OnLine.Distance(pinterm) > Tolerance) {
100 pinterm = gp_Pnt2d(center1.XY()+distcl*
101 gp_XY(-OnLine.Direction().Y(),OnLine.Direction().X()));
102 }
103 Standard_Real dist2 = L2.Distance(pinterm);
104 if (Qualified1.IsEnclosed() || Qualified1.IsOutside()) {
105 if (Abs(distcl-R1-dist2) <= Tol) { ok = Standard_True; }
106 }
107 else if (Qualified1.IsEnclosing()) {
108 if (Abs(dist2-distcl-R1) <= Tol) { ok = Standard_True; }
109 }
110 else if (Qualified1.IsUnqualified()) { ok = Standard_True; }
111 else {
112 GccEnt_BadQualifier::Raise();
113 return;
114 }
115 if (ok) {
116 if (Qualified2.IsOutside()) {
117 gp_Pnt2d pbid(pinterm.XY()+dist2*gp_XY(-dirL2.Y(),dirL2.X()));
118 if (L2.Distance(pbid) <= Tol) { WellDone = Standard_True; }
119 }
120 else if (Qualified2.IsEnclosed()) {
121 gp_Pnt2d pbid(pinterm.XY()-dist2*gp_XY(-dirL2.Y(),dirL2.X()));
122 if (L2.Distance(pbid) <= Tol) { WellDone = Standard_True; }
123 }
124 else if (Qualified2.IsUnqualified()) { WellDone = Standard_False; }
125 else {
126 GccEnt_BadQualifier::Raise();
127 return;
128 }
129 }
130 if (WellDone) {
131 NbrSol++;
132 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(pinterm,dirx),dist2);
133// =======================================================
134 gp_Dir2d dc1(center1.XY()-pinterm.XY());
135 gp_Dir2d dc2(origin2.XY()-pinterm.XY());
136 Standard_Real distcc1 = pinterm.Distance(center1);
137 if (!Qualified1.IsUnqualified()) {
138 qualifier1(NbrSol) = Qualified1.Qualifier();
139 }
140 else if (Abs(distcc1+dist2-R1) < Tol) {
141 qualifier1(NbrSol) = GccEnt_enclosed;
142 }
143 else if (Abs(distcc1-R1-dist2) < Tol) {
144 qualifier1(NbrSol) = GccEnt_outside;
145 }
146 else { qualifier1(NbrSol) = GccEnt_enclosing; }
147 if (!Qualified2.IsUnqualified()) {
148 qualifier2(NbrSol) = Qualified2.Qualifier();
149 }
150 else if (dc2.Dot(normL2) > 0.0) {
151 qualifier2(NbrSol) = GccEnt_outside;
152 }
153 else { qualifier2(NbrSol) = GccEnt_enclosed; }
154
155 Standard_Real sign = dc2.Dot(gp_Dir2d(-dirL2.Y(),dirL2.X()));
156 dc2 = gp_Dir2d(sign*gp_XY(-dirL2.Y(),dirL2.X()));
157 pnttg1sol(NbrSol) = gp_Pnt2d(pinterm.XY()+dist2*dc1.XY());
158 pnttg2sol(NbrSol) = gp_Pnt2d(pinterm.XY()+dist2*dc2.XY());
159 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg1sol(NbrSol));
160 pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
161 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg2sol(NbrSol));
162 pararg2(NbrSol)=ElCLib::Parameter(L2,pnttg2sol(NbrSol));
163 pntcen(NbrSol) = cirsol(NbrSol).Location();
164 parcen3(NbrSol)=ElCLib::Parameter(OnLine,pntcen(NbrSol));
165 return;
166 }
167
168//=========================================================================
0d969553 169// General case. +
7fd59977 170//=========================================================================
171
172 GccAna_CircLin2dBisec Bis(C1,L2);
173 if (Bis.IsDone()) {
174 Standard_Integer nbsolution = Bis.NbSolutions();
175 for (Standard_Integer i = 1 ; i <= nbsolution; i++) {
176 Handle(GccInt_Bisec) Sol = Bis.ThisSolution(i);
177 GccInt_IType type = Sol->ArcType();
178 IntAna2d_AnaIntersection Intp;
179 if (type == GccInt_Lin) {
180 Intp.Perform(OnLine,Sol->Line());
181 }
182 else if (type == GccInt_Par) {
183 Intp.Perform(OnLine,IntAna2d_Conic(Sol->Parabola()));
184 }
185 if (Intp.IsDone()) {
186 if (!Intp.IsEmpty()) {
187 for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
188 gp_Pnt2d Center(Intp.Point(j).Value());
189 Standard_Real dist1 = Center.Distance(center1);
190 dist2 = L2.Distance(Center);
191// Standard_Integer nbsol = 1;
192 ok = Standard_False;
193 if (Qualified1.IsEnclosed()) {
194 if (dist1-R1 < Tolerance) {
195 if (Abs(Abs(R1-dist1)-dist2)<Tolerance) { ok=Standard_True; }
196 }
197 }
198 else if (Qualified1.IsOutside()) {
199 if (R1-dist1 < Tolerance) {
200 if (Abs(Abs(R1-dist1)-dist2)<Tolerance) { ok=Standard_True; }
201 }
202 }
203 else if (Qualified1.IsEnclosing() || Qualified1.IsUnqualified()) {
204 ok = Standard_True;
205 }
206 if (Qualified2.IsEnclosed() && ok) {
207 if ((((origin2.X()-Center.X())*(-dirL2.Y()))+
208 ((origin2.Y()-Center.Y())*(dirL2.X())))<=0){
209 ok = Standard_True;
210 Radius = dist2;
211 }
212 }
213 else if (Qualified2.IsOutside() && ok) {
214 if ((((origin2.X()-Center.X())*(-dirL2.Y()))+
215 ((origin2.Y()-Center.Y())*(dirL2.X())))>=0){
216 ok = Standard_True;
217 Radius = dist2;
218 }
219 }
220 else if (Qualified2.IsUnqualified() && ok) {
221 ok = Standard_True;
222 Radius = dist2;
223 }
224 if (ok) {
225 NbrSol++;
226 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
227// =======================================================
228 gp_Dir2d dc1(center1.XY()-Center.XY());
229 gp_Dir2d dc2(origin2.XY()-Center.XY());
230 Standard_Real distcc1 = Center.Distance(center1);
231 if (!Qualified1.IsUnqualified()) {
232 qualifier1(NbrSol) = Qualified1.Qualifier();
233 }
234 else if (Abs(distcc1+Radius-R1) < Tol) {
235 qualifier1(NbrSol) = GccEnt_enclosed;
236 }
237 else if (Abs(distcc1-R1-Radius) < Tol) {
238 qualifier1(NbrSol) = GccEnt_outside;
239 }
240 else { qualifier1(NbrSol) = GccEnt_enclosing; }
241 if (!Qualified2.IsUnqualified()) {
242 qualifier2(NbrSol) = Qualified2.Qualifier();
243 }
244 else if (dc2.Dot(normL2) > 0.0) {
245 qualifier2(NbrSol) = GccEnt_outside;
246 }
247 else { qualifier2(NbrSol) = GccEnt_enclosed; }
248 if (Center.Distance(center1) <= Tolerance &&
249 Abs(Radius-C1.Radius()) <= Tolerance) {
250 TheSame1(NbrSol) = 1;
251 }
252 else {
253 TheSame1(NbrSol) = 0;
254 pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius*dc1.XY());
255 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
256 pnttg1sol(NbrSol));
257 pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
258 }
259 TheSame2(NbrSol) = 0;
260 Standard_Real sign = dc2.Dot(gp_Dir2d(-dirL2.Y(),dirL2.X()));
261 dc2 = gp_Dir2d(sign*gp_XY(-dirL2.Y(),dirL2.X()));
262 pnttg2sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius*dc2.XY());
263 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
264 pnttg2sol(NbrSol));
265 pararg2(NbrSol)=ElCLib::Parameter(L2,pnttg2sol(NbrSol));
266 pntcen(NbrSol) = Center;
267 parcen3(NbrSol)=ElCLib::Parameter(OnLine,pntcen(NbrSol));
268 }
269 }
270 }
271 WellDone = Standard_True;
272 }
273 }
274 }
275 }
276
277
278
279
280
281