0023703: Projection algorithm produces incomplete 2D-Curve
[occt.git] / src / ProjLib / ProjLib_Projector.cxx
1 // Created on: 1993-08-24
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 //  Modified by skv - Wed Aug 11 15:45:58 2004 OCC6272
23
24
25 #include <ProjLib_Projector.ixx>
26
27 #include <ElCLib.hxx>
28
29
30 //=======================================================================
31 //function : ProjLib_Projector
32 //purpose  : 
33 //=======================================================================
34
35 ProjLib_Projector::ProjLib_Projector()
36 {}
37
38
39 //=======================================================================
40 void ProjLib_Projector::Delete()
41 {}
42
43
44
45 //=======================================================================
46 //function : IsDone
47 //purpose  : 
48 //=======================================================================
49
50 Standard_Boolean ProjLib_Projector::IsDone() const
51 {
52   return isDone;
53 }
54
55
56 //=======================================================================
57 //function : Done
58 //purpose  : 
59 //=======================================================================
60
61 void ProjLib_Projector::Done()
62 {
63   isDone = Standard_True;
64 }
65
66
67 //=======================================================================
68 //function : GetType
69 //purpose  : 
70 //=======================================================================
71
72 GeomAbs_CurveType  ProjLib_Projector::GetType() const 
73 {
74   return myType;
75 }
76
77
78 //=======================================================================
79 //function : SetType
80 //purpose  : 
81 //=======================================================================
82
83 void ProjLib_Projector::SetType( const GeomAbs_CurveType Type)
84 {
85   myType = Type;
86 }
87
88
89 //=======================================================================
90 //function : IsPeriodic
91 //purpose  : 
92 //=======================================================================
93
94 Standard_Boolean ProjLib_Projector::IsPeriodic() const 
95 {
96   return myIsPeriodic;
97 }
98
99
100 //=======================================================================
101 //function : SetPeriodic
102 //purpose  : 
103 //=======================================================================
104
105 void ProjLib_Projector::SetPeriodic()
106 {
107   myIsPeriodic = Standard_True;
108 }
109
110
111 //=======================================================================
112 //function : Line
113 //purpose  : 
114 //=======================================================================
115
116 const gp_Lin2d&  ProjLib_Projector::Line()const 
117 {
118   if (myType != GeomAbs_Line)
119     Standard_NoSuchObject::Raise("ProjLib_Projector::Line");
120   return myLin;
121 }
122
123
124 //=======================================================================
125 //function : Circle
126 //purpose  : 
127 //=======================================================================
128
129 const gp_Circ2d&  ProjLib_Projector::Circle()const 
130 {
131   if (myType != GeomAbs_Circle)
132     Standard_NoSuchObject::Raise("ProjLib_Projector::Circle");
133   return myCirc;
134 }
135
136
137 //=======================================================================
138 //function : Ellipse
139 //purpose  : 
140 //=======================================================================
141
142 const gp_Elips2d&  ProjLib_Projector::Ellipse()const 
143 {
144   if (myType != GeomAbs_Ellipse)
145     Standard_NoSuchObject::Raise("ProjLib_Projector::Ellipse");
146   return myElips;
147 }
148
149
150 //=======================================================================
151 //function : Hyperbola
152 //purpose  : 
153 //=======================================================================
154
155 const gp_Hypr2d&  ProjLib_Projector::Hyperbola()const 
156 {
157   if (myType != GeomAbs_Hyperbola)
158     Standard_NoSuchObject::Raise("ProjLib_Projector::Hyperbola");
159   return myHypr;
160 }
161
162
163 //=======================================================================
164 //function : Parabola
165 //purpose  : 
166 //=======================================================================
167
168 const gp_Parab2d&  ProjLib_Projector::Parabola()const 
169 {
170   if (myType != GeomAbs_Parabola)
171     Standard_NoSuchObject::Raise("ProjLib_Projector::Parabola");
172   return myParab;
173 }
174
175
176
177
178 //=======================================================================
179 //function : Project
180 //purpose  : 
181 //=======================================================================
182
183 void  ProjLib_Projector::Project(const gp_Lin& )
184 {
185   myType = GeomAbs_OtherCurve;
186 }
187
188
189 //=======================================================================
190 //function : Project
191 //purpose  : 
192 //=======================================================================
193
194 void  ProjLib_Projector::Project(const gp_Circ& )
195 {
196   myType = GeomAbs_OtherCurve;
197 }
198
199
200 //=======================================================================
201 //function : Project
202 //purpose  : 
203 //=======================================================================
204
205 void  ProjLib_Projector::Project(const gp_Elips& )
206 {
207   myType = GeomAbs_OtherCurve;
208 }
209
210
211 //=======================================================================
212 //function : Project
213 //purpose  : 
214 //=======================================================================
215
216 void  ProjLib_Projector::Project(const gp_Parab& )
217 {
218   myType = GeomAbs_OtherCurve;
219 }
220
221
222 //=======================================================================
223 //function : Project
224 //purpose  : 
225 //=======================================================================
226
227 void  ProjLib_Projector::Project(const gp_Hypr& )
228 {
229   myType = GeomAbs_OtherCurve;
230 }
231
232
233 //=======================================================================
234 //function : UFrame
235 //purpose  : 
236 //=======================================================================
237
238 void ProjLib_Projector::UFrame(const Standard_Real CFirst, 
239 //                             const Standard_Real CLast, 
240                                const Standard_Real , 
241                                const Standard_Real UFirst, 
242                                const Standard_Real Period)
243 {
244   if (myType == GeomAbs_Line) {
245 //  Modified by skv - Wed Aug 11 15:45:58 2004 OCC6272 Begin
246 //     if ( myLin.Direction().Y() == 0.) {
247 //  Modified by skv - Wed Aug 11 15:45:58 2004 OCC6272 End
248 //      gp_Pnt2d PFirst, PLast;
249     gp_Pnt2d PFirst;
250     PFirst = ElCLib::Value(CFirst,myLin);
251     //PLast  = ElCLib::Value(CLast ,myLin);
252     //Standard_Real U = Min( PFirst.X(), PLast.X());
253     Standard_Real U = PFirst.X();
254     Standard_Real NewU = ElCLib::InPeriod(U,UFirst, UFirst + Period);
255     myLin.Translate(gp_Vec2d(NewU-U,0.));
256   }
257 }
258
259 //=======================================================================
260 //function : VFrame
261 //purpose  : 
262 //=======================================================================
263
264 void ProjLib_Projector::VFrame(const Standard_Real CFirst,
265 //                             const Standard_Real CLast, 
266                                const Standard_Real , 
267                                const Standard_Real VFirst, 
268                                const Standard_Real Period)
269 {
270   if (myType == GeomAbs_Line) {
271 //  Modified by skv - Wed Aug 11 15:45:58 2004 OCC6272 Begin
272 //     if ( myLin.Direction().X() == 0.) {
273 //  Modified by skv - Wed Aug 11 15:45:58 2004 OCC6272 End
274 //      gp_Pnt2d PFirst, PLast;
275     gp_Pnt2d PFirst;
276     PFirst = ElCLib::Value(CFirst,myLin);
277     //PLast  = ElCLib::Value(CLast ,myLin);
278     //Standard_Real V = Min( PFirst.Y(), PLast.Y());
279     Standard_Real V = PFirst.Y();
280     Standard_Real NewV = ElCLib::InPeriod(V,VFirst, VFirst + Period);
281     myLin.Translate(gp_Vec2d(0.,NewV-V));
282   }
283 }
284
285 //=======================================================================
286 //function : SetBezier
287 //purpose  : 
288 //=======================================================================
289
290 void  ProjLib_Projector::SetBezier(const Handle(Geom2d_BezierCurve)&  C) 
291 {
292  myBezier = C ;
293 }
294 //=======================================================================
295 //function : Bezier
296 //purpose  : 
297 //=======================================================================
298
299 Handle(Geom2d_BezierCurve)ProjLib_Projector::Bezier() const 
300
301   return myBezier ;
302 }
303 //=======================================================================
304 //function : SetBSpline
305 //purpose  : 
306 //=======================================================================
307
308 void  ProjLib_Projector::SetBSpline(const Handle(Geom2d_BSplineCurve)&  C) 
309 {
310  myBSpline = C ;
311 }
312 //=======================================================================
313 //function : BSpline
314 //purpose  : 
315 //=======================================================================
316
317 Handle(Geom2d_BSplineCurve) ProjLib_Projector::BSpline()  const 
318
319  return myBSpline ;
320 }