Commit | Line | Data |
---|---|---|
b311480e | 1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 | 2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 3 | // |
973c2be1 | 4 | // This file is part of Open CASCADE Technology software library. |
b311480e | 5 | // |
d5f74e42 | 6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
10 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 11 | // |
973c2be1 | 12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. | |
7fd59977 | 14 | |
15 | //======================================================================== | |
0d969553 Y |
16 | // CREATION of a LINE TANGENT to a CIRCLE or PASSING by a POINT + |
17 | // and PARALLEL to a STRAIGHT DROITE. + | |
7fd59977 | 18 | //======================================================================== |
19 | ||
7fd59977 | 20 | #include <ElCLib.hxx> |
42cf5bc1 | 21 | #include <GccAna_Lin2dTanPar.hxx> |
22 | #include <GccEnt_BadQualifier.hxx> | |
23 | #include <GccEnt_QualifiedCirc.hxx> | |
24 | #include <gp_Circ2d.hxx> | |
7fd59977 | 25 | #include <gp_Dir2d.hxx> |
42cf5bc1 | 26 | #include <gp_Lin2d.hxx> |
27 | #include <gp_Pnt2d.hxx> | |
42cf5bc1 | 28 | #include <gp_XY.hxx> |
7fd59977 | 29 | #include <Standard_OutOfRange.hxx> |
42cf5bc1 | 30 | #include <StdFail_NotDone.hxx> |
7fd59977 | 31 | |
32 | //======================================================================== | |
0d969553 Y |
33 | // Passing by a point : + |
34 | // Create the straight line with origin ThePoint and + | |
35 | // direction Lin1.Direction(). + | |
7fd59977 | 36 | //======================================================================== |
7fd59977 | 37 | GccAna_Lin2dTanPar:: |
38 | GccAna_Lin2dTanPar (const gp_Pnt2d& ThePoint , | |
39 | const gp_Lin2d& Lin1 ): | |
40 | linsol(1,1), | |
41 | qualifier1(1,1) , | |
42 | pnttg1sol(1,1), | |
43 | par1sol(1,1), | |
44 | pararg1(1,1) | |
45 | { | |
46 | ||
47 | linsol(1) = gp_Lin2d(ThePoint,Lin1.Direction()); | |
48 | // =============================================== | |
49 | qualifier1(1) = GccEnt_noqualifier; | |
50 | pnttg1sol(1) = ThePoint; | |
51 | par1sol(1) = 0.; | |
52 | pararg1(1) = 0.; | |
53 | NbrSol = 1; | |
54 | WellDone = Standard_True; | |
55 | } | |
56 | ||
57 | //======================================================================== | |
0d969553 Y |
58 | // Tangent to a circle : + |
59 | // Create following the qualifier the straight line + | |
60 | // - with origin P1 (P1 is a point of intersection between C1 and + | |
61 | // a straight line passing by the center of C1 and + | |
62 | // direction the normal to Lin1). + | |
63 | // the choice of the point of intersection depends + | |
64 | // on the qualifier. + | |
65 | // - with direction the direction of Lin1. + | |
7fd59977 | 66 | //======================================================================== |
67 | ||
68 | GccAna_Lin2dTanPar:: | |
69 | GccAna_Lin2dTanPar (const GccEnt_QualifiedCirc& Qualified1, | |
70 | const gp_Lin2d& Lin1 ): | |
71 | linsol(1,2), | |
72 | qualifier1(1,2) , | |
73 | pnttg1sol(1,2), | |
74 | par1sol(1,2), | |
75 | pararg1(1,2) | |
76 | { | |
77 | ||
78 | WellDone = Standard_False; | |
79 | Standard_Integer signe = 0; | |
80 | Standard_Integer nbsol = 0; | |
81 | NbrSol = 0; | |
82 | if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() || | |
83 | Qualified1.IsOutside() || Qualified1.IsUnqualified())) { | |
9775fa61 | 84 | throw GccEnt_BadQualifier(); |
7fd59977 | 85 | return; |
86 | } | |
87 | gp_Circ2d C1 = Qualified1.Qualified(); | |
88 | Standard_Real xdir = (Lin1.Direction()).X(); | |
89 | Standard_Real ydir = (Lin1.Direction()).Y(); | |
90 | ||
9775fa61 | 91 | if (Qualified1.IsEnclosed()) { throw GccEnt_BadQualifier(); } |
7fd59977 | 92 | // ============================ |
93 | else if (Qualified1.IsEnclosing()) { | |
94 | // ================================== | |
95 | nbsol = 1; | |
96 | signe = 1; | |
97 | qualifier1(1) = GccEnt_enclosing; | |
98 | } | |
99 | else if (Qualified1.IsOutside()) { | |
100 | // =================================== | |
101 | nbsol = 1; | |
102 | signe = -1; | |
103 | qualifier1(1) = GccEnt_outside; | |
104 | } | |
105 | else { | |
106 | nbsol = 2; | |
107 | signe = -1; | |
108 | qualifier1(1) = GccEnt_outside; | |
109 | qualifier1(2) = GccEnt_enclosing; | |
110 | } | |
111 | gp_XY xy(-C1.Radius()*ydir,C1.Radius()*xdir); | |
112 | for (Standard_Integer j = 1 ; j <= nbsol ; j++) { | |
113 | signe = -signe; | |
114 | NbrSol++; | |
115 | linsol(NbrSol) = gp_Lin2d(gp_Pnt2d((C1.Location().XY()).Added(signe*xy)), | |
116 | // ========================================================================= | |
117 | Lin1.Direction()); | |
118 | // ================= | |
119 | pnttg1sol(NbrSol) = gp_Pnt2d((C1.Location().XY()).Added(signe*xy)); | |
120 | par1sol(NbrSol) = 0.; | |
121 | pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol)); | |
122 | WellDone = Standard_True; | |
123 | } | |
124 | } | |
125 | ||
126 | Standard_Boolean GccAna_Lin2dTanPar:: | |
127 | IsDone () const { return WellDone; } | |
128 | ||
129 | Standard_Integer GccAna_Lin2dTanPar::NbSolutions () const | |
130 | { | |
131 | if (!WellDone) | |
9775fa61 | 132 | throw StdFail_NotDone(); |
7fd59977 | 133 | return NbrSol; |
134 | } | |
135 | ||
136 | gp_Lin2d GccAna_Lin2dTanPar::ThisSolution (const Standard_Integer Index) const | |
137 | { | |
9775fa61 | 138 | if (!WellDone) { throw StdFail_NotDone(); } |
139 | else if (Index <= 0 || Index > NbrSol) { throw Standard_OutOfRange(); } | |
7fd59977 | 140 | return linsol(Index); |
141 | } | |
142 | ||
143 | void GccAna_Lin2dTanPar:: | |
144 | WhichQualifier(const Standard_Integer Index , | |
145 | GccEnt_Position& Qualif1 ) const | |
146 | { | |
9775fa61 | 147 | if (!WellDone) { throw StdFail_NotDone(); } |
148 | else if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); } | |
7fd59977 | 149 | else { |
150 | Qualif1 = qualifier1(Index); | |
151 | } | |
152 | } | |
153 | ||
154 | void GccAna_Lin2dTanPar:: | |
155 | Tangency1 (const Standard_Integer Index, | |
156 | Standard_Real& ParSol, | |
157 | Standard_Real& ParArg, | |
158 | gp_Pnt2d& Pnt) const { | |
9775fa61 | 159 | if (!WellDone) { throw StdFail_NotDone(); } |
160 | else if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); } | |
7fd59977 | 161 | else { |
162 | ParSol = par1sol(Index); | |
163 | ParArg = pararg1(Index); | |
164 | Pnt = gp_Pnt2d(pnttg1sol(Index)); | |
165 | } | |
166 | } |