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 ):
40 Paral2(Standard_False),
50 Geom2dAdaptor_Curve C1 = Qualified1.Qualified();
51 Handle(Geom2d_Curve) CC1 = C1.Curve();
52 GeomAbs_CurveType Type1 = C1.GetType();
54 //=============================================================================
56 //=============================================================================
58 WellDone = Standard_False;
60 if (Type1 == GeomAbs_Circle ) {
61 Handle(Geom2d_Circle) CCC1 = Handle(Geom2d_Circle)::DownCast(CC1);
62 gp_Circ2d c1(CCC1->Circ2d());
63 GccEnt_QualifiedCirc Qc1=GccEnt_QualifiedCirc(c1,Qualified1.Qualifier());
64 GccAna_Lin2dTanObl Lin(Qc1,TheLine,Angle);
65 WellDone = Lin.IsDone();
67 NbrSol = Lin.NbSolutions();
68 for (Standard_Integer i = 1 ; i <= NbrSol ; i++) {
69 linsol(i) = Lin.ThisSolution(i);
70 Lin.Tangency1(i,par1sol(i),pararg1(i),pnttg1sol(i));
71 Lin.Intersection2(i,par2sol(i),pararg2(i),pntint2sol(i));
72 Lin.WhichQualifier(i,qualifier1(i));
77 Geom2dGcc_QCurve Qc1(C1,Qualified1.Qualifier());
78 Standard_Real aFirstPar = Geom2dGcc_CurveTool::FirstParameter(C1);
79 Standard_Real aLastPar = Geom2dGcc_CurveTool::LastParameter(C1);
80 Standard_Integer aNbSamples = Geom2dGcc_CurveTool::NbSamples(C1);
81 Standard_Real aStep = (aLastPar - aFirstPar)/aNbSamples;
82 Standard_Real Param1 = aFirstPar;
85 for (i = 0; i <= aNbSamples && NbrSol < 2; i++) {
86 Geom2dGcc_Lin2dTanOblIter Lin(Qc1,TheLine,Param1,TolAng,Angle);
89 if (Add(NbrSol + 1, Lin, TolAng, C1))
96 WellDone = (NbrSol > 0);
100 Geom2dGcc_Lin2dTanObl::
101 Geom2dGcc_Lin2dTanObl (const Geom2dGcc_QualifiedCurve& Qualified1 ,
102 const gp_Lin2d& TheLine ,
103 const Standard_Real TolAng ,
104 const Standard_Real Param1 ,
105 const Standard_Real Angle ):
106 Paral2(Standard_False),
116 Geom2dAdaptor_Curve C1 = Qualified1.Qualified();
117 Handle(Geom2d_Curve) CC1 = C1.Curve();
118 GeomAbs_CurveType Type1 = C1.GetType();
120 //=============================================================================
122 //=============================================================================
124 WellDone = Standard_False;
126 if (Type1 == GeomAbs_Circle ) {
127 Handle(Geom2d_Circle) CCC1 = Handle(Geom2d_Circle)::DownCast(CC1);
128 gp_Circ2d c1(CCC1->Circ2d());
129 GccEnt_QualifiedCirc Qc1=GccEnt_QualifiedCirc(c1,Qualified1.Qualifier());
130 GccAna_Lin2dTanObl Lin(Qc1,TheLine,Angle);
131 WellDone = Lin.IsDone();
133 NbrSol = Lin.NbSolutions();
134 for (Standard_Integer i = 1 ; i <= NbrSol ; i++) {
135 linsol(i) = Lin.ThisSolution(i);
136 Lin.Tangency1(i,par1sol(i),pararg1(i),pnttg1sol(i));
137 Lin.Intersection2(i,par2sol(i),pararg2(i),pntint2sol(i));
138 Lin.WhichQualifier(i,qualifier1(i));
143 Geom2dGcc_QCurve Qc1(C1,Qualified1.Qualifier());
144 Geom2dGcc_Lin2dTanOblIter Lin(Qc1,TheLine,TolAng,Param1,Angle);
145 WellDone = Lin.IsDone();
147 linsol(1) = Lin.ThisSolution();
148 Lin.Tangency1(par1sol(1),pararg1(1),pnttg1sol(1));
149 Lin.Intersection2(par2sol(1),pararg2(1),pntint2sol(1));
150 Lin.WhichQualifier(qualifier1(1));
155 Standard_Boolean Geom2dGcc_Lin2dTanObl::
156 IsDone () const { return WellDone; }
158 Standard_Integer Geom2dGcc_Lin2dTanObl::
159 NbSolutions () const { return NbrSol; }
161 gp_Lin2d Geom2dGcc_Lin2dTanObl::
162 ThisSolution (const Standard_Integer Index) const {
164 if (Index > NbrSol || Index <= 0) { throw Standard_OutOfRange(); }
165 return linsol(Index);
168 void Geom2dGcc_Lin2dTanObl::
169 WhichQualifier (const Standard_Integer Index,
170 GccEnt_Position& Qualif1) const
172 if (!WellDone) { throw StdFail_NotDone(); }
173 else if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
174 else { Qualif1 = qualifier1(Index); }
177 void Geom2dGcc_Lin2dTanObl::
178 Tangency1 (const Standard_Integer Index,
179 Standard_Real& ParSol,
180 Standard_Real& ParArg,
181 gp_Pnt2d& PntSol) const {
182 if (!WellDone) { throw StdFail_NotDone(); }
183 else if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
185 ParSol = par1sol(Index);
186 ParArg = pararg1(Index);
187 PntSol = pnttg1sol(Index);
191 void Geom2dGcc_Lin2dTanObl::
192 Intersection2 (const Standard_Integer Index ,
193 Standard_Real& ParSol ,
194 Standard_Real& ParArg ,
195 gp_Pnt2d& PntSol ) const {
196 if (!WellDone) { throw StdFail_NotDone(); }
197 else if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
199 ParSol = par2sol(Index);
200 ParArg = pararg2(Index);
201 PntSol = pntint2sol(Index);
205 Standard_Boolean Geom2dGcc_Lin2dTanObl::Add
206 (const Standard_Integer theIndex,
207 const Geom2dGcc_Lin2dTanOblIter &theLin,
208 const Standard_Real theTol,
209 const Geom2dAdaptor_Curve &theC1)
212 Standard_Real aPar1sol;
213 Standard_Real aPar2sol;
214 Standard_Real aPar1arg;
215 Standard_Real aPar2arg;
218 gp_Lin2d aLin = theLin.ThisSolution();
220 theLin.Tangency1(aPar1sol, aPar1arg, aPnt1Sol);
221 theLin.Intersection2(aPar2sol, aPar2arg, aPnt2Sol);
223 for(i = 1; i < theIndex; i++) {
224 if (Abs(aPar1arg - pararg1(i)) <= theTol &&
225 Abs(aPar2arg - pararg2(i)) <= theTol)
226 return Standard_False;
229 gp_Dir2d aLinDir = aLin.Direction();
233 Geom2dGcc_CurveTool::D1(theC1, aPar1arg, aPoint, aVTan);
235 if (Abs(aLinDir.Crossed(gp_Dir2d(aVTan))) > theTol)
236 return Standard_False;
238 linsol(theIndex) = aLin;
239 par1sol(theIndex) = aPar1sol;
240 pararg1(theIndex) = aPar1arg;
241 pnttg1sol(theIndex) = aPnt1Sol;
242 par2sol(theIndex) = aPar2sol;
243 pararg2(theIndex) = aPar2arg;
244 pntint2sol(theIndex) = aPnt2Sol;
246 theLin.WhichQualifier(qualifier1(theIndex));
248 return Standard_True;