0030675: Visualization - remove redundant proxy classes in hierarchy of PrsMgr_Presen...
[occt.git] / src / ProjLib / ProjLib_Plane.cxx
1 // Created on: 1993-08-24
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <gp_Circ.hxx>
19 #include <gp_Elips.hxx>
20 #include <gp_Hypr.hxx>
21 #include <gp_Lin.hxx>
22 #include <gp_Parab.hxx>
23 #include <gp_Pln.hxx>
24 #include <gp_Vec.hxx>
25 #include <ProjLib_Plane.hxx>
26 #include <Standard_NoSuchObject.hxx>
27
28 //=======================================================================
29 //function : ProjLib_Plane
30 //purpose  : 
31 //=======================================================================
32 ProjLib_Plane::ProjLib_Plane()
33 {
34 }
35
36
37 //=======================================================================
38 //function : ProjLib_Plane
39 //purpose  : 
40 //=======================================================================
41
42 ProjLib_Plane::ProjLib_Plane(const gp_Pln& Pl)
43 {
44   Init(Pl);
45 }
46
47
48 //=======================================================================
49 //function : ProjLib_Plane
50 //purpose  : 
51 //=======================================================================
52
53 ProjLib_Plane::ProjLib_Plane(const gp_Pln& Pl, const gp_Lin& L)
54 {
55   Init(Pl);
56   Project(L);
57 }
58
59
60 //=======================================================================
61 //function : ProjLib_Plane
62 //purpose  : 
63 //=======================================================================
64
65 ProjLib_Plane::ProjLib_Plane(const gp_Pln& Pl, const gp_Circ& C)
66 {
67   Init(Pl);
68   Project(C);
69 }
70
71
72 //=======================================================================
73 //function : ProjLib_Plane
74 //purpose  : 
75 //=======================================================================
76
77 ProjLib_Plane::ProjLib_Plane(const gp_Pln& Pl, const gp_Elips& E)
78 {
79   Init(Pl);
80   Project(E);
81 }
82
83
84 //=======================================================================
85 //function : ProjLib_Plane
86 //purpose  : 
87 //=======================================================================
88
89 ProjLib_Plane::ProjLib_Plane(const gp_Pln& Pl, const gp_Parab& P)
90 {
91   Init(Pl);
92   Project(P);
93 }
94
95
96 //=======================================================================
97 //function : ProjLib_Plane
98 //purpose  : 
99 //=======================================================================
100
101 ProjLib_Plane::ProjLib_Plane(const gp_Pln& Pl, const gp_Hypr& H)
102 {
103   Init(Pl);
104   Project(H);
105 }
106
107
108 //=======================================================================
109 //function : Init
110 //purpose  : 
111 //=======================================================================
112
113 void  ProjLib_Plane::Init(const gp_Pln& Pl)
114 {
115   myType  = GeomAbs_OtherCurve;
116   isDone  = Standard_False;
117   myIsPeriodic = Standard_False;
118   myPlane = Pl;
119 }
120
121 //=======================================================================
122 //function : EvalPnt2d / EvalDir2d
123 //purpose  : returns the Projected Pnt / Dir in the parametrization range
124 //           of myPlane.
125 //=======================================================================
126
127 static gp_Pnt2d EvalPnt2d( const gp_Pnt P, const gp_Pln& Pl)
128 {
129   gp_Vec OP( Pl.Location(),P);
130   return gp_Pnt2d( OP.Dot(gp_Vec(Pl.Position().XDirection())),
131                    OP.Dot(gp_Vec(Pl.Position().YDirection())));
132 }
133
134 static gp_Dir2d EvalDir2d( const gp_Dir& D, const gp_Pln& Pl)
135 {
136   return gp_Dir2d( D.Dot(Pl.Position().XDirection()),
137                    D.Dot(Pl.Position().YDirection()));
138 }
139
140
141 //=======================================================================
142 //function : Project
143 //purpose  : 
144 //=======================================================================
145
146 void  ProjLib_Plane::Project(const gp_Lin& L)
147 {
148   myType = GeomAbs_Line;
149   myLin  = gp_Lin2d(EvalPnt2d(L.Location() ,myPlane),
150                     EvalDir2d(L.Direction(),myPlane) );
151   isDone = Standard_True;
152 }
153
154
155 //=======================================================================
156 //function : Project
157 //purpose  : 
158 //=======================================================================
159
160 void  ProjLib_Plane::Project(const gp_Circ& C)
161 {
162
163   myType = GeomAbs_Circle;
164
165   gp_Pnt2d P2d = EvalPnt2d(C.Location(),myPlane);
166   gp_Dir2d X2d = EvalDir2d(C.Position().XDirection(),myPlane);
167   gp_Dir2d Y2d = EvalDir2d(C.Position().YDirection(),myPlane);
168   gp_Ax22d Ax(P2d,X2d,Y2d);
169
170   myCirc = gp_Circ2d(Ax, C.Radius());
171   myIsPeriodic = Standard_True;
172   isDone = Standard_True;
173 }
174
175
176 //=======================================================================
177 //function : Project
178 //purpose  : 
179 //=======================================================================
180
181 void  ProjLib_Plane::Project(const gp_Elips& E)
182 {
183   myType = GeomAbs_Ellipse;
184
185   gp_Pnt2d P2d = EvalPnt2d(E.Location(),myPlane);
186   gp_Dir2d X2d = EvalDir2d(E.Position().XDirection(),myPlane);
187   gp_Dir2d Y2d = EvalDir2d(E.Position().YDirection(),myPlane);
188   gp_Ax22d Ax(P2d,X2d,Y2d);
189
190   myElips = gp_Elips2d(Ax,E.MajorRadius(),E.MinorRadius());
191   myIsPeriodic = Standard_True;
192   isDone = Standard_True;
193 }
194
195
196 //=======================================================================
197 //function : Project
198 //purpose  : 
199 //=======================================================================
200
201 void  ProjLib_Plane::Project(const gp_Parab& P)
202 {
203   myType = GeomAbs_Parabola;
204
205   gp_Pnt2d P2d = EvalPnt2d(P.Location(),myPlane);
206   gp_Dir2d X2d = EvalDir2d(P.Position().XDirection(),myPlane);
207   gp_Dir2d Y2d = EvalDir2d(P.Position().YDirection(),myPlane);
208   gp_Ax22d Ax(P2d,X2d,Y2d);
209
210   myParab = gp_Parab2d(Ax,P.Focal());
211   isDone = Standard_True;
212 }
213
214
215 //=======================================================================
216 //function : Project
217 //purpose  : 
218 //=======================================================================
219
220 void  ProjLib_Plane::Project(const gp_Hypr& H)
221 {
222   myType = GeomAbs_Hyperbola;
223
224   gp_Pnt2d P2d = EvalPnt2d(H.Location(),myPlane);
225   gp_Dir2d X2d = EvalDir2d(H.Position().XDirection(),myPlane);
226   gp_Dir2d Y2d = EvalDir2d(H.Position().YDirection(),myPlane);
227   gp_Ax22d Ax(P2d,X2d,Y2d);
228
229   myHypr = gp_Hypr2d(Ax,H.MajorRadius(),H.MinorRadius());
230   isDone = Standard_True;
231 }