0030675: Visualization - remove redundant proxy classes in hierarchy of PrsMgr_Presen...
[occt.git] / src / GccAna / GccAna_Lin2dTanPar.cxx
CommitLineData
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>
7fd59977 28#include <gp_Vec2d.hxx>
42cf5bc1 29#include <gp_XY.hxx>
7fd59977 30#include <Standard_OutOfRange.hxx>
42cf5bc1 31#include <StdFail_NotDone.hxx>
7fd59977 32
33//========================================================================
0d969553
Y
34// Passing by a point : +
35// Create the straight line with origin ThePoint and +
36// direction Lin1.Direction(). +
7fd59977 37//========================================================================
7fd59977 38GccAna_Lin2dTanPar::
39 GccAna_Lin2dTanPar (const gp_Pnt2d& ThePoint ,
40 const gp_Lin2d& Lin1 ):
41 linsol(1,1),
42 qualifier1(1,1) ,
43 pnttg1sol(1,1),
44 par1sol(1,1),
45 pararg1(1,1)
46{
47
48 linsol(1) = gp_Lin2d(ThePoint,Lin1.Direction());
49// ===============================================
50 qualifier1(1) = GccEnt_noqualifier;
51 pnttg1sol(1) = ThePoint;
52 par1sol(1) = 0.;
53 pararg1(1) = 0.;
54 NbrSol = 1;
55 WellDone = Standard_True;
56}
57
58//========================================================================
0d969553
Y
59// Tangent to a circle : +
60// Create following the qualifier the straight line +
61// - with origin P1 (P1 is a point of intersection between C1 and +
62// a straight line passing by the center of C1 and +
63// direction the normal to Lin1). +
64// the choice of the point of intersection depends +
65// on the qualifier. +
66// - with direction the direction of Lin1. +
7fd59977 67//========================================================================
68
69GccAna_Lin2dTanPar::
70 GccAna_Lin2dTanPar (const GccEnt_QualifiedCirc& Qualified1,
71 const gp_Lin2d& Lin1 ):
72 linsol(1,2),
73 qualifier1(1,2) ,
74 pnttg1sol(1,2),
75 par1sol(1,2),
76 pararg1(1,2)
77{
78
79 WellDone = Standard_False;
80 Standard_Integer signe = 0;
81 Standard_Integer nbsol = 0;
82 NbrSol = 0;
83 if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() ||
84 Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
9775fa61 85 throw GccEnt_BadQualifier();
7fd59977 86 return;
87 }
88 gp_Circ2d C1 = Qualified1.Qualified();
89 Standard_Real xdir = (Lin1.Direction()).X();
90 Standard_Real ydir = (Lin1.Direction()).Y();
91
9775fa61 92 if (Qualified1.IsEnclosed()) { throw GccEnt_BadQualifier(); }
7fd59977 93// ============================
94 else if (Qualified1.IsEnclosing()) {
95// ==================================
96 nbsol = 1;
97 signe = 1;
98 qualifier1(1) = GccEnt_enclosing;
99 }
100 else if (Qualified1.IsOutside()) {
101// ===================================
102 nbsol = 1;
103 signe = -1;
104 qualifier1(1) = GccEnt_outside;
105 }
106 else {
107 nbsol = 2;
108 signe = -1;
109 qualifier1(1) = GccEnt_outside;
110 qualifier1(2) = GccEnt_enclosing;
111 }
112 gp_XY xy(-C1.Radius()*ydir,C1.Radius()*xdir);
113 for (Standard_Integer j = 1 ; j <= nbsol ; j++) {
114 signe = -signe;
115 NbrSol++;
116 linsol(NbrSol) = gp_Lin2d(gp_Pnt2d((C1.Location().XY()).Added(signe*xy)),
117// =========================================================================
118 Lin1.Direction());
119// =================
120 pnttg1sol(NbrSol) = gp_Pnt2d((C1.Location().XY()).Added(signe*xy));
121 par1sol(NbrSol) = 0.;
122 pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
123 WellDone = Standard_True;
124 }
125 }
126
127Standard_Boolean GccAna_Lin2dTanPar::
128 IsDone () const { return WellDone; }
129
130Standard_Integer GccAna_Lin2dTanPar::NbSolutions () const
131{
132 if (!WellDone)
9775fa61 133 throw StdFail_NotDone();
7fd59977 134 return NbrSol;
135}
136
137gp_Lin2d GccAna_Lin2dTanPar::ThisSolution (const Standard_Integer Index) const
138{
9775fa61 139 if (!WellDone) { throw StdFail_NotDone(); }
140 else if (Index <= 0 || Index > NbrSol) { throw Standard_OutOfRange(); }
7fd59977 141 return linsol(Index);
142}
143
144void GccAna_Lin2dTanPar::
145 WhichQualifier(const Standard_Integer Index ,
146 GccEnt_Position& Qualif1 ) const
147{
9775fa61 148 if (!WellDone) { throw StdFail_NotDone(); }
149 else if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
7fd59977 150 else {
151 Qualif1 = qualifier1(Index);
152 }
153}
154
155void GccAna_Lin2dTanPar::
156 Tangency1 (const Standard_Integer Index,
157 Standard_Real& ParSol,
158 Standard_Real& ParArg,
159 gp_Pnt2d& Pnt) const {
9775fa61 160 if (!WellDone) { throw StdFail_NotDone(); }
161 else if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
7fd59977 162 else {
163 ParSol = par1sol(Index);
164 ParArg = pararg1(Index);
165 Pnt = gp_Pnt2d(pnttg1sol(Index));
166 }
167 }