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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <GccAna_Circ2dTanOnRad.hxx>
19 #include <GccEnt_BadQualifier.hxx>
20 #include <GccEnt_QualifiedCirc.hxx>
21 #include <GccEnt_QualifiedLin.hxx>
22 #include <Geom2d_Circle.hxx>
23 #include <Geom2d_Line.hxx>
24 #include <Geom2d_Point.hxx>
25 #include <Geom2dAdaptor_Curve.hxx>
26 #include <Geom2dGcc_Circ2dTanOnRad.hxx>
27 #include <Geom2dGcc_Circ2dTanOnRadGeo.hxx>
28 #include <Geom2dGcc_QCurve.hxx>
29 #include <Geom2dGcc_QualifiedCurve.hxx>
30 #include <gp_Circ2d.hxx>
31 #include <gp_Pnt2d.hxx>
32 #include <Standard_NegativeValue.hxx>
33 #include <Standard_OutOfRange.hxx>
34 #include <StdFail_NotDone.hxx>
36 Geom2dGcc_Circ2dTanOnRad::
37 Geom2dGcc_Circ2dTanOnRad (const Geom2dGcc_QualifiedCurve& Qualified1 ,
38 const Geom2dAdaptor_Curve& OnCurve ,
39 const Standard_Real Radius ,
40 const Standard_Real Tolerance ):
51 throw Standard_NegativeValue();
54 Geom2dAdaptor_Curve C1 = Qualified1.Qualified();
55 GeomAbs_CurveType Type1 = C1.GetType();
56 GeomAbs_CurveType Type2 = OnCurve.GetType();
57 Handle(Geom2d_Curve) CC1 = C1.Curve();
58 Handle(Geom2d_Curve) Con = OnCurve.Curve();
60 //=============================================================================
62 //=============================================================================
65 if ((Type1 == GeomAbs_Line || Type1 == GeomAbs_Circle) &&
66 (Type2 == GeomAbs_Line || Type2 == GeomAbs_Circle)) {
67 if (Type1 == GeomAbs_Circle) {
68 Handle(Geom2d_Circle) CCC1 = Handle(Geom2d_Circle)::DownCast(CC1);
69 gp_Circ2d c1(CCC1->Circ2d());
70 GccEnt_QualifiedCirc Qc1=GccEnt_QualifiedCirc(c1,
71 Qualified1.Qualifier());
72 if (Type2 == GeomAbs_Circle) {
73 Handle(Geom2d_Circle) CCon = Handle(Geom2d_Circle)::DownCast(Con);
74 gp_Circ2d con(CCon->Circ2d());
75 GccAna_Circ2dTanOnRad Circ(Qc1,con,Radius,Tolerance);
76 WellDone = Circ.IsDone();
77 NbrSol = Circ.NbSolutions();
81 Handle(Geom2d_Line) LLon = Handle(Geom2d_Line)::DownCast(Con);
82 gp_Lin2d lon(LLon->Lin2d());
83 GccAna_Circ2dTanOnRad Circ(Qc1,lon,Radius,Tolerance);
84 WellDone = Circ.IsDone();
85 NbrSol = Circ.NbSolutions();
90 Handle(Geom2d_Line) LL1 = Handle(Geom2d_Line)::DownCast(CC1);
91 gp_Lin2d l1(LL1->Lin2d());
92 GccEnt_QualifiedLin Ql1=GccEnt_QualifiedLin(l1,Qualified1.Qualifier());
93 if (Type2 == GeomAbs_Circle) {
94 Handle(Geom2d_Circle) CCon = Handle(Geom2d_Circle)::DownCast(Con);
95 gp_Circ2d con(CCon->Circ2d());
96 GccAna_Circ2dTanOnRad Circ(Ql1,con,Radius,Tolerance);
97 WellDone = Circ.IsDone();
98 NbrSol = Circ.NbSolutions();
102 Handle(Geom2d_Line) LLon = Handle(Geom2d_Line)::DownCast(Con);
103 gp_Lin2d lon(LLon->Lin2d());
104 GccAna_Circ2dTanOnRad Circ(Ql1,lon,Radius,Tolerance);
105 WellDone = Circ.IsDone();
106 NbrSol = Circ.NbSolutions();
112 //=============================================================================
114 //=============================================================================
117 if (Type1 == GeomAbs_Circle) {
118 Handle(Geom2d_Circle) CCC1 = Handle(Geom2d_Circle)::DownCast(CC1);
119 gp_Circ2d c1(CCC1->Circ2d());
120 GccEnt_QualifiedCirc Qc1=GccEnt_QualifiedCirc(c1,
121 Qualified1.Qualifier());
122 Geom2dGcc_Circ2dTanOnRadGeo CircGeo(Qc1,OnCurve,Radius,Tolerance);
123 WellDone = CircGeo.IsDone();
124 NbrSol = CircGeo.NbSolutions();
127 else if (Type1 == GeomAbs_Line) {
128 Handle(Geom2d_Line) LL1 = Handle(Geom2d_Line)::DownCast(CC1);
129 gp_Lin2d l1(LL1->Lin2d());
130 GccEnt_QualifiedLin Ql1=GccEnt_QualifiedLin(l1,Qualified1.Qualifier());
131 Geom2dGcc_Circ2dTanOnRadGeo CircGeo(Ql1,OnCurve,Radius,Tolerance);
132 WellDone = CircGeo.IsDone();
133 NbrSol = CircGeo.NbSolutions();
137 Geom2dGcc_QCurve Qc1(C1,Qualified1.Qualifier());
138 Geom2dGcc_Circ2dTanOnRadGeo CircGeo(Qc1,OnCurve,Radius,Tolerance);
139 WellDone = CircGeo.IsDone();
140 NbrSol = CircGeo.NbSolutions();
147 Geom2dGcc_Circ2dTanOnRad::
148 Geom2dGcc_Circ2dTanOnRad (const Handle(Geom2d_Point)& Point1 ,
149 const Geom2dAdaptor_Curve& OnCurve ,
150 const Standard_Real Radius ,
151 const Standard_Real Tolerance ):
162 throw Standard_NegativeValue();
165 gp_Pnt2d point1(Point1->Pnt2d());
166 GeomAbs_CurveType Type2 = OnCurve.GetType();
167 Handle(Geom2d_Curve) Con = OnCurve.Curve();
169 //=============================================================================
171 //=============================================================================
174 if (Type2 == GeomAbs_Line || Type2 == GeomAbs_Circle) {
175 if (Type2 == GeomAbs_Circle) {
176 Handle(Geom2d_Circle) CCon = Handle(Geom2d_Circle)::DownCast(Con);
177 gp_Circ2d con(CCon->Circ2d());
178 GccAna_Circ2dTanOnRad Circ(point1,con,Radius,Tolerance);
179 WellDone = Circ.IsDone();
180 NbrSol = Circ.NbSolutions();
184 Handle(Geom2d_Line) LLon = Handle(Geom2d_Line)::DownCast(Con);
185 gp_Lin2d lon(LLon->Lin2d());
186 GccAna_Circ2dTanOnRad Circ(point1,lon,Radius,Tolerance);
187 WellDone = Circ.IsDone();
188 NbrSol = Circ.NbSolutions();
193 //=============================================================================
195 //=============================================================================
198 Geom2dGcc_Circ2dTanOnRadGeo CircGeo(point1,OnCurve,Radius,Tolerance);
199 WellDone = CircGeo.IsDone();
200 NbrSol = CircGeo.NbSolutions();
206 void Geom2dGcc_Circ2dTanOnRad::Results(const GccAna_Circ2dTanOnRad& Circ)
208 for (Standard_Integer j = 1; j <= NbrSol; j++) {
209 cirsol(j) = Circ.ThisSolution(j);
210 if (Circ.IsTheSame1(j)) { TheSame1(j) = 1; }
211 else {TheSame1(j) = 0; }
212 Circ.Tangency1(j,par1sol(j),pararg1(j),pnttg1sol(j));
213 Circ.CenterOn3(j,parcen3(j),pntcen3(j));
214 Circ.WhichQualifier(j,qualifier1(j));
218 void Geom2dGcc_Circ2dTanOnRad::Results(const Geom2dGcc_Circ2dTanOnRadGeo& Circ)
220 for (Standard_Integer j = 1; j <= NbrSol; j++) {
221 cirsol(j) = Circ.ThisSolution(j);
222 if (Circ.IsTheSame1(j)) { TheSame1(j) = 1; }
223 else {TheSame1(j) = 0; }
224 Circ.Tangency1(j,par1sol(j),pararg1(j),pnttg1sol(j));
225 Circ.CenterOn3(j,parcen3(j),pntcen3(j));
226 Circ.WhichQualifier(j,qualifier1(j));
230 Standard_Boolean Geom2dGcc_Circ2dTanOnRad::
231 IsDone () const { return WellDone; }
233 Standard_Integer Geom2dGcc_Circ2dTanOnRad::
239 gp_Circ2d Geom2dGcc_Circ2dTanOnRad::
240 ThisSolution (const Standard_Integer Index) const
242 if (!WellDone) { throw StdFail_NotDone(); }
243 if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
244 return cirsol(Index);
247 void Geom2dGcc_Circ2dTanOnRad::
248 WhichQualifier (const Standard_Integer Index,
249 GccEnt_Position& Qualif1) const
251 if (!WellDone) { throw StdFail_NotDone(); }
252 else if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
253 else { Qualif1 = qualifier1(Index); }
256 void Geom2dGcc_Circ2dTanOnRad::
257 Tangency1 (const Standard_Integer Index,
258 Standard_Real& ParSol,
259 Standard_Real& ParArg,
260 gp_Pnt2d& PntSol) const
262 if (!WellDone) { throw StdFail_NotDone(); }
263 else if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
265 if (TheSame1(Index) == 0) {
266 ParSol = par1sol(Index);
267 ParArg = pararg1(Index);
268 PntSol = pnttg1sol(Index);
270 else { throw StdFail_NotDone(); }
274 void Geom2dGcc_Circ2dTanOnRad::
275 CenterOn3 (const Standard_Integer Index,
276 Standard_Real& ParArg,
277 gp_Pnt2d& PntSol) const
279 if (!WellDone) { throw StdFail_NotDone(); }
280 else if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
282 ParArg = parcen3(Index);
283 PntSol = pntcen3(Index);
287 Standard_Boolean Geom2dGcc_Circ2dTanOnRad::
288 IsTheSame1 (const Standard_Integer Index) const
290 if (!WellDone) { throw StdFail_NotDone(); }
291 if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
292 if (TheSame1(Index) == 0) { return Standard_False; }
293 return Standard_True;