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_Lin2dTanObl.hxx>
19 #include <GccEnt_BadQualifier.hxx>
20 #include <GccEnt_QualifiedCirc.hxx>
21 #include <Geom2d_Circle.hxx>
22 #include <Geom2dAdaptor_Curve.hxx>
23 #include <Geom2dGcc_CurveTool.hxx>
24 #include <Geom2dGcc_IsParallel.hxx>
25 #include <Geom2dGcc_Lin2dTanObl.hxx>
26 #include <Geom2dGcc_Lin2dTanOblIter.hxx>
27 #include <Geom2dGcc_QCurve.hxx>
28 #include <Geom2dGcc_QualifiedCurve.hxx>
29 #include <gp_Lin2d.hxx>
30 #include <gp_Pnt2d.hxx>
31 #include <Standard_NegativeValue.hxx>
32 #include <Standard_OutOfRange.hxx>
33 #include <StdFail_NotDone.hxx>
35 Geom2dGcc_Lin2dTanObl::
36 Geom2dGcc_Lin2dTanObl (const Geom2dGcc_QualifiedCurve& Qualified1 ,
37 const gp_Lin2d& TheLine ,
38 const Standard_Real TolAng ,
39 const Standard_Real Angle ):
49 Geom2dAdaptor_Curve C1 = Qualified1.Qualified();
50 Handle(Geom2d_Curve) CC1 = C1.Curve();
51 GeomAbs_CurveType Type1 = C1.GetType();
53 //=============================================================================
55 //=============================================================================
57 WellDone = Standard_False;
59 if (Type1 == GeomAbs_Circle ) {
60 Handle(Geom2d_Circle) CCC1 = Handle(Geom2d_Circle)::DownCast(CC1);
61 gp_Circ2d c1(CCC1->Circ2d());
62 GccEnt_QualifiedCirc Qc1=GccEnt_QualifiedCirc(c1,Qualified1.Qualifier());
63 GccAna_Lin2dTanObl Lin(Qc1,TheLine,Angle);
64 WellDone = Lin.IsDone();
66 NbrSol = Lin.NbSolutions();
67 for (Standard_Integer i = 1 ; i <= NbrSol ; i++) {
68 linsol(i) = Lin.ThisSolution(i);
69 Lin.Tangency1(i,par1sol(i),pararg1(i),pnttg1sol(i));
70 Lin.Intersection2(i,par2sol(i),pararg2(i),pntint2sol(i));
71 Lin.WhichQualifier(i,qualifier1(i));
76 Geom2dGcc_QCurve Qc1(C1,Qualified1.Qualifier());
77 Standard_Real aFirstPar = Geom2dGcc_CurveTool::FirstParameter(C1);
78 Standard_Real aLastPar = Geom2dGcc_CurveTool::LastParameter(C1);
79 Standard_Integer aNbSamples = Geom2dGcc_CurveTool::NbSamples(C1);
80 Standard_Real aStep = (aLastPar - aFirstPar)/aNbSamples;
81 Standard_Real Param1 = aFirstPar;
84 for (i = 0; i <= aNbSamples && NbrSol < 2; i++) {
85 Geom2dGcc_Lin2dTanOblIter Lin(Qc1,TheLine,Param1,TolAng,Angle);
88 if (Add(NbrSol + 1, Lin, TolAng, C1))
95 WellDone = (NbrSol > 0);
99 Geom2dGcc_Lin2dTanObl::
100 Geom2dGcc_Lin2dTanObl (const Geom2dGcc_QualifiedCurve& Qualified1 ,
101 const gp_Lin2d& TheLine ,
102 const Standard_Real TolAng ,
103 const Standard_Real Param1 ,
104 const Standard_Real Angle ):
114 Geom2dAdaptor_Curve C1 = Qualified1.Qualified();
115 Handle(Geom2d_Curve) CC1 = C1.Curve();
116 GeomAbs_CurveType Type1 = C1.GetType();
118 //=============================================================================
120 //=============================================================================
122 WellDone = Standard_False;
124 if (Type1 == GeomAbs_Circle ) {
125 Handle(Geom2d_Circle) CCC1 = Handle(Geom2d_Circle)::DownCast(CC1);
126 gp_Circ2d c1(CCC1->Circ2d());
127 GccEnt_QualifiedCirc Qc1=GccEnt_QualifiedCirc(c1,Qualified1.Qualifier());
128 GccAna_Lin2dTanObl Lin(Qc1,TheLine,Angle);
129 WellDone = Lin.IsDone();
131 NbrSol = Lin.NbSolutions();
132 for (Standard_Integer i = 1 ; i <= NbrSol ; i++) {
133 linsol(i) = Lin.ThisSolution(i);
134 Lin.Tangency1(i,par1sol(i),pararg1(i),pnttg1sol(i));
135 Lin.Intersection2(i,par2sol(i),pararg2(i),pntint2sol(i));
136 Lin.WhichQualifier(i,qualifier1(i));
141 Geom2dGcc_QCurve Qc1(C1,Qualified1.Qualifier());
142 Geom2dGcc_Lin2dTanOblIter Lin(Qc1,TheLine,TolAng,Param1,Angle);
143 WellDone = Lin.IsDone();
145 linsol(1) = Lin.ThisSolution();
146 Lin.Tangency1(par1sol(1),pararg1(1),pnttg1sol(1));
147 Lin.Intersection2(par2sol(1),pararg2(1),pntint2sol(1));
148 Lin.WhichQualifier(qualifier1(1));
153 Standard_Boolean Geom2dGcc_Lin2dTanObl::
154 IsDone () const { return WellDone; }
156 Standard_Integer Geom2dGcc_Lin2dTanObl::
157 NbSolutions () const { return NbrSol; }
159 gp_Lin2d Geom2dGcc_Lin2dTanObl::
160 ThisSolution (const Standard_Integer Index) const {
162 if (Index > NbrSol || Index <= 0) { throw Standard_OutOfRange(); }
163 return linsol(Index);
166 void Geom2dGcc_Lin2dTanObl::
167 WhichQualifier (const Standard_Integer Index,
168 GccEnt_Position& Qualif1) const
170 if (!WellDone) { throw StdFail_NotDone(); }
171 else if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
172 else { Qualif1 = qualifier1(Index); }
175 void Geom2dGcc_Lin2dTanObl::
176 Tangency1 (const Standard_Integer Index,
177 Standard_Real& ParSol,
178 Standard_Real& ParArg,
179 gp_Pnt2d& PntSol) const {
180 if (!WellDone) { throw StdFail_NotDone(); }
181 else if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
183 ParSol = par1sol(Index);
184 ParArg = pararg1(Index);
185 PntSol = pnttg1sol(Index);
189 void Geom2dGcc_Lin2dTanObl::
190 Intersection2 (const Standard_Integer Index ,
191 Standard_Real& ParSol ,
192 Standard_Real& ParArg ,
193 gp_Pnt2d& PntSol ) const {
194 if (!WellDone) { throw StdFail_NotDone(); }
195 else if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
197 ParSol = par2sol(Index);
198 ParArg = pararg2(Index);
199 PntSol = pntint2sol(Index);
203 Standard_Boolean Geom2dGcc_Lin2dTanObl::Add
204 (const Standard_Integer theIndex,
205 const Geom2dGcc_Lin2dTanOblIter &theLin,
206 const Standard_Real theTol,
207 const Geom2dAdaptor_Curve &theC1)
210 Standard_Real aPar1sol;
211 Standard_Real aPar2sol;
212 Standard_Real aPar1arg;
213 Standard_Real aPar2arg;
216 gp_Lin2d aLin = theLin.ThisSolution();
218 theLin.Tangency1(aPar1sol, aPar1arg, aPnt1Sol);
219 theLin.Intersection2(aPar2sol, aPar2arg, aPnt2Sol);
221 for(i = 1; i < theIndex; i++) {
222 if (Abs(aPar1arg - pararg1(i)) <= theTol &&
223 Abs(aPar2arg - pararg2(i)) <= theTol)
224 return Standard_False;
227 gp_Dir2d aLinDir = aLin.Direction();
231 Geom2dGcc_CurveTool::D1(theC1, aPar1arg, aPoint, aVTan);
233 if (Abs(aLinDir.Crossed(gp_Dir2d(aVTan))) > theTol)
234 return Standard_False;
236 linsol(theIndex) = aLin;
237 par1sol(theIndex) = aPar1sol;
238 pararg1(theIndex) = aPar1arg;
239 pnttg1sol(theIndex) = aPnt1Sol;
240 par2sol(theIndex) = aPar2sol;
241 pararg2(theIndex) = aPar2arg;
242 pntint2sol(theIndex) = aPnt2Sol;
244 theLin.WhichQualifier(qualifier1(theIndex));
246 return Standard_True;