b311480e |
1 | // Created on: 1993-07-19 |
2 | // Created by: Remi LEQUETTE |
3 | // Copyright (c) 1993-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <Geom2d_BezierCurve.hxx> |
19 | #include <Geom2d_BSplineCurve.hxx> |
7fd59977 |
20 | #include <Geom2d_Circle.hxx> |
42cf5bc1 |
21 | #include <Geom2d_Curve.hxx> |
7fd59977 |
22 | #include <Geom2d_Ellipse.hxx> |
7fd59977 |
23 | #include <Geom2d_Hyperbola.hxx> |
42cf5bc1 |
24 | #include <Geom2d_Line.hxx> |
7fd59977 |
25 | #include <Geom2d_OffsetCurve.hxx> |
42cf5bc1 |
26 | #include <Geom2d_Parabola.hxx> |
27 | #include <Geom2d_TrimmedCurve.hxx> |
28 | #include <GeomTools.hxx> |
29 | #include <GeomTools_Curve2dSet.hxx> |
30 | #include <GeomTools_UndefinedTypeHandler.hxx> |
7fd59977 |
31 | #include <gp_Circ2d.hxx> |
32 | #include <gp_Elips2d.hxx> |
7fd59977 |
33 | #include <gp_Hypr2d.hxx> |
42cf5bc1 |
34 | #include <gp_Lin2d.hxx> |
35 | #include <gp_Parab2d.hxx> |
7e785937 |
36 | #include <Message_ProgressScope.hxx> |
42cf5bc1 |
37 | #include <Standard_ErrorHandler.hxx> |
38 | #include <Standard_Failure.hxx> |
39 | #include <Standard_OutOfRange.hxx> |
40 | #include <Standard_Stream.hxx> |
41 | #include <TColgp_Array1OfPnt2d.hxx> |
42 | #include <TColStd_Array1OfInteger.hxx> |
43 | #include <TColStd_Array1OfReal.hxx> |
7fd59977 |
44 | |
45 | #define LINE 1 |
46 | #define CIRCLE 2 |
47 | #define ELLIPSE 3 |
48 | #define PARABOLA 4 |
49 | #define HYPERBOLA 5 |
50 | #define BEZIER 6 |
51 | #define BSPLINE 7 |
52 | #define TRIMMED 8 |
53 | #define OFFSET 9 |
54 | |
55 | |
56 | //======================================================================= |
57 | //function : GeomTools_Curve2dSet |
58 | //purpose : |
59 | //======================================================================= |
60 | |
61 | GeomTools_Curve2dSet::GeomTools_Curve2dSet() |
62 | { |
63 | } |
64 | |
65 | |
66 | //======================================================================= |
67 | //function : Clear |
68 | //purpose : |
69 | //======================================================================= |
70 | |
71 | void GeomTools_Curve2dSet::Clear() |
72 | { |
73 | myMap.Clear(); |
74 | } |
75 | |
76 | |
77 | //======================================================================= |
78 | //function : Add |
79 | //purpose : |
80 | //======================================================================= |
81 | |
82 | Standard_Integer GeomTools_Curve2dSet::Add(const Handle(Geom2d_Curve)& S) |
83 | { |
84 | return myMap.Add(S); |
85 | } |
86 | |
87 | |
88 | //======================================================================= |
89 | //function : Curve2d |
90 | //purpose : |
91 | //======================================================================= |
92 | |
93 | Handle(Geom2d_Curve) GeomTools_Curve2dSet::Curve2d |
94 | (const Standard_Integer I)const |
95 | { |
96 | if (I <= 0 || I > myMap.Extent()) |
97 | return Handle(Geom2d_Curve)(); |
98 | |
99 | return Handle(Geom2d_Curve)::DownCast(myMap(I)); |
100 | } |
101 | |
102 | |
103 | //======================================================================= |
104 | //function : Index |
105 | //purpose : |
106 | //======================================================================= |
107 | |
108 | Standard_Integer GeomTools_Curve2dSet::Index |
109 | (const Handle(Geom2d_Curve)& S)const |
110 | { |
111 | return myMap.FindIndex(S); |
112 | } |
113 | |
114 | //======================================================================= |
115 | //function : Print |
116 | //purpose : |
117 | //======================================================================= |
118 | |
119 | static void Print(const gp_Pnt2d P, |
120 | Standard_OStream& OS, |
121 | const Standard_Boolean compact) |
122 | { |
123 | OS << P.X(); |
124 | if (!compact) OS << ","; |
125 | OS << " "; |
126 | OS << P.Y(); |
127 | OS << " "; |
128 | } |
129 | |
130 | //======================================================================= |
131 | //function : Print |
132 | //purpose : |
133 | //======================================================================= |
134 | |
135 | static void Print(const gp_Dir2d D, |
136 | Standard_OStream& OS, |
137 | const Standard_Boolean compact) |
138 | { |
139 | OS << D.X(); |
140 | if (!compact) OS << ","; |
141 | OS << " "; |
142 | OS << D.Y(); |
143 | OS << " "; |
144 | } |
145 | |
146 | //======================================================================= |
147 | //function : Print |
148 | //purpose : |
149 | //======================================================================= |
150 | |
151 | static void Print(const Handle(Geom2d_Line)& L, |
152 | Standard_OStream& OS, |
153 | const Standard_Boolean compact) |
154 | { |
155 | if (compact) |
156 | OS << LINE << " "; |
157 | else |
158 | OS << "Line"; |
159 | |
160 | gp_Lin2d C2d = L->Lin2d(); |
161 | if (!compact) OS << "\n Origin :"; |
162 | Print(C2d.Location(),OS,compact); |
163 | if (!compact) OS << "\n Axis :"; |
164 | Print(C2d.Direction(),OS,compact); |
165 | if (!compact) OS << "\n"; |
166 | OS << "\n"; |
167 | } |
168 | |
169 | //======================================================================= |
170 | //function : Print |
171 | //purpose : |
172 | //======================================================================= |
173 | |
174 | static void Print(const Handle(Geom2d_Circle)& C, |
175 | Standard_OStream& OS, |
176 | const Standard_Boolean compact) |
177 | { |
178 | if (compact) |
179 | OS << CIRCLE << " "; |
180 | else |
181 | OS << "Circle"; |
182 | |
183 | gp_Circ2d C2d = C->Circ2d(); |
184 | if (!compact) OS << "\n Center :"; |
185 | Print(C2d.Location(),OS,compact); |
186 | if (!compact) OS << "\n XAxis :"; |
187 | Print(C2d.XAxis().Direction(),OS,compact); |
188 | if (!compact) OS << "\n YAxis :"; |
189 | Print(C2d.YAxis().Direction(),OS,compact); |
190 | if (!compact) OS << "\n Radius :"; |
191 | OS << C2d.Radius(); |
192 | if (!compact) OS << "\n"; |
193 | OS << "\n"; |
194 | } |
195 | |
196 | //======================================================================= |
197 | //function : Print |
198 | //purpose : |
199 | //======================================================================= |
200 | |
201 | static void Print(const Handle(Geom2d_Ellipse)& E, |
202 | Standard_OStream& OS, |
203 | const Standard_Boolean compact) |
204 | { |
205 | if (compact) |
206 | OS << ELLIPSE << " "; |
207 | else |
208 | OS << "Ellipse"; |
209 | |
210 | gp_Elips2d C2d = E->Elips2d(); |
211 | if (!compact) OS << "\n Center :"; |
212 | Print(C2d.Location(),OS,compact); |
213 | if (!compact) OS << "\n XAxis :"; |
214 | Print(C2d.XAxis().Direction(),OS,compact); |
215 | if (!compact) OS << "\n YAxis :"; |
216 | Print(C2d.YAxis().Direction(),OS,compact); |
217 | if (!compact) OS << "\n Radii :"; |
218 | OS << C2d.MajorRadius(); |
219 | if (!compact) OS << ","; |
220 | OS << " "; |
221 | OS << C2d.MinorRadius(); |
222 | if (!compact) OS << "\n"; |
223 | OS << "\n"; |
224 | } |
225 | |
226 | //======================================================================= |
227 | //function : Print |
228 | //purpose : |
229 | //======================================================================= |
230 | |
231 | static void Print(const Handle(Geom2d_Parabola)& P, |
232 | Standard_OStream& OS, |
233 | const Standard_Boolean compact) |
234 | { |
235 | if (compact) |
236 | OS << PARABOLA << " "; |
237 | else |
238 | OS << "Parabola"; |
239 | |
240 | gp_Parab2d C2d = P->Parab2d(); |
241 | if (!compact) OS << "\n Center :"; |
242 | Print(C2d.Location(),OS,compact); |
243 | if (!compact) OS << "\n XAxis :"; |
244 | Print(C2d.Axis().XAxis().Direction(),OS,compact); |
245 | if (!compact) OS << "\n YAxis :"; |
246 | Print(C2d.Axis().YAxis().Direction(),OS,compact); |
247 | if (!compact) OS << "\n Focal :"; |
248 | OS << C2d.Focal(); |
249 | if (!compact) OS << "\n"; |
250 | OS << "\n"; |
251 | } |
252 | |
253 | //======================================================================= |
254 | //function : Print |
255 | //purpose : |
256 | //======================================================================= |
257 | |
258 | static void Print(const Handle(Geom2d_Hyperbola)& H, |
259 | Standard_OStream& OS, |
260 | const Standard_Boolean compact) |
261 | { |
262 | if (compact) |
263 | OS << HYPERBOLA << " "; |
264 | else |
265 | OS << "Hyperbola"; |
266 | |
267 | gp_Hypr2d C2d = H->Hypr2d(); |
268 | if (!compact) OS << "\n Center :"; |
269 | Print(C2d.Location(),OS,compact); |
270 | if (!compact) OS << "\n XAxis :"; |
271 | Print(C2d.XAxis().Direction(),OS,compact); |
272 | if (!compact) OS << "\n YAxis :"; |
273 | Print(C2d.YAxis().Direction(),OS,compact); |
274 | if (!compact) OS << "\n Radii :"; |
275 | OS << C2d.MajorRadius(); |
276 | if (!compact) OS << ","; |
277 | OS << " "; |
278 | OS << C2d.MinorRadius(); |
279 | if (!compact) OS << "\n"; |
280 | OS << "\n"; |
281 | } |
282 | |
283 | //======================================================================= |
284 | //function : Print |
285 | //purpose : |
286 | //======================================================================= |
287 | |
288 | static void Print(const Handle(Geom2d_BezierCurve)& B, |
289 | Standard_OStream& OS, |
290 | const Standard_Boolean compact) |
291 | { |
292 | if (compact) |
293 | OS << BEZIER << " "; |
294 | else |
295 | OS << "BezierCurve"; |
296 | |
297 | Standard_Boolean rational = B->IsRational(); |
298 | if (compact) |
299 | OS << (rational ? 1 : 0) << " "; |
300 | else { |
301 | if (rational) |
302 | OS << " rational"; |
303 | } |
304 | |
305 | // poles and weights |
306 | Standard_Integer i,degree = B->Degree(); |
307 | if (!compact) OS << "\n Degree :"; |
308 | OS << degree << " "; |
309 | |
310 | for (i = 1; i <= degree+1; i++) { |
04232180 |
311 | if (!compact) OS << "\n "<<std::setw(2)<<i<<" : "; |
7fd59977 |
312 | Print(B->Pole(i),OS,compact); |
313 | if (rational) |
314 | OS << " " << B->Weight(i); |
315 | if (compact) |
316 | OS << " "; |
317 | } |
318 | if (!compact) OS << "\n"; |
319 | OS << "\n"; |
320 | } |
321 | |
322 | //======================================================================= |
323 | //function : Print |
324 | //purpose : |
325 | //======================================================================= |
326 | |
327 | static void Print(const Handle(Geom2d_BSplineCurve)& B, |
328 | Standard_OStream& OS, |
329 | const Standard_Boolean compact) |
330 | { |
331 | if (compact) |
332 | OS << BSPLINE << " "; |
333 | else |
334 | OS << "BSplineCurve"; |
335 | |
336 | |
337 | Standard_Boolean rational = B->IsRational(); |
338 | if (compact) |
339 | OS << (rational ? 1 : 0) << " "; |
340 | else { |
341 | if (rational) |
342 | OS << " rational"; |
343 | } |
344 | |
345 | Standard_Boolean periodic = B->IsPeriodic(); |
346 | if (compact) |
347 | OS << (periodic ? 1 : 0) << " "; |
348 | else { |
349 | if (periodic) |
350 | OS << " periodic"; |
351 | } |
352 | |
353 | // poles and weights |
354 | Standard_Integer i,degree,nbpoles,nbknots; |
355 | degree = B->Degree(); |
356 | nbpoles = B->NbPoles(); |
357 | nbknots = B->NbKnots(); |
358 | if (!compact) OS << "\n Degree "; |
359 | else OS << " "; |
360 | OS << degree; |
361 | if (!compact) OS << ","; |
362 | OS << " "; |
363 | OS << nbpoles; |
364 | if (!compact) OS << " Poles,"; |
365 | OS << " "; |
366 | OS << nbknots << " "; |
367 | if (!compact) OS << " Knots"; |
368 | |
369 | if (!compact) OS << "Poles :\n"; |
370 | for (i = 1; i <= nbpoles; i++) { |
04232180 |
371 | if (!compact) OS << "\n "<<std::setw(2)<<i<<" : "; |
7fd59977 |
372 | else OS << " "; |
373 | Print(B->Pole(i),OS,compact); |
374 | if (rational) |
375 | OS << " " << B->Weight(i); |
376 | } |
377 | OS << "\n"; |
378 | |
379 | if (!compact) OS << "Knots :\n"; |
380 | for (i = 1; i <= nbknots; i++) { |
04232180 |
381 | if (!compact) OS << "\n "<<std::setw(2)<<i<<" : "; |
7fd59977 |
382 | else OS << " "; |
383 | OS << B->Knot(i) << " " << B->Multiplicity(i); |
384 | } |
385 | if (!compact) OS << "\n"; |
386 | OS << "\n"; |
387 | } |
388 | |
389 | //======================================================================= |
390 | //function : Print |
391 | //purpose : |
392 | //======================================================================= |
393 | |
394 | static void Print(const Handle(Geom2d_TrimmedCurve)& C, |
395 | Standard_OStream& OS, |
396 | const Standard_Boolean compact) |
397 | { |
398 | if (compact) |
399 | OS << TRIMMED << " "; |
400 | else |
401 | OS << "Trimmed curve\n"; |
402 | if (!compact) OS << "Parameters : "; |
403 | OS << C->FirstParameter() << " " << C->LastParameter() << "\n"; |
404 | if (!compact) OS << "Basis curve :\n"; |
405 | GeomTools_Curve2dSet::PrintCurve2d(C->BasisCurve(),OS,compact); |
406 | } |
407 | |
408 | //======================================================================= |
409 | //function : Print |
410 | //purpose : |
411 | //======================================================================= |
412 | |
413 | static void Print(const Handle(Geom2d_OffsetCurve)& C, |
414 | Standard_OStream& OS, |
415 | const Standard_Boolean compact) |
416 | { |
417 | if (compact) |
418 | OS << OFFSET << " "; |
419 | else |
420 | OS << "OffsetCurve"; |
421 | if (!compact) OS << "Offset : "; |
422 | OS << C->Offset() << "\n"; |
423 | if (!compact) OS << "Basis curve :\n"; |
424 | GeomTools_Curve2dSet::PrintCurve2d(C->BasisCurve(),OS,compact); |
425 | } |
426 | |
427 | //======================================================================= |
428 | //function : PrintCurve2d |
429 | //purpose : |
430 | //======================================================================= |
431 | |
432 | void GeomTools_Curve2dSet::PrintCurve2d(const Handle(Geom2d_Curve)& C, |
433 | Standard_OStream& OS, |
434 | const Standard_Boolean compact) |
435 | { |
436 | Handle(Standard_Type) TheType = C->DynamicType(); |
437 | |
438 | if ( TheType == STANDARD_TYPE(Geom2d_Circle)) { |
439 | Print(Handle(Geom2d_Circle)::DownCast(C),OS,compact); |
440 | } |
441 | else if ( TheType ==STANDARD_TYPE(Geom2d_Line)) { |
442 | Print(Handle(Geom2d_Line)::DownCast(C),OS,compact); |
443 | } |
444 | else if ( TheType == STANDARD_TYPE(Geom2d_Ellipse)) { |
445 | Print(Handle(Geom2d_Ellipse)::DownCast(C),OS,compact); |
446 | } |
447 | else if ( TheType == STANDARD_TYPE(Geom2d_Parabola)) { |
448 | Print(Handle(Geom2d_Parabola)::DownCast(C),OS,compact); |
449 | } |
450 | else if ( TheType == STANDARD_TYPE(Geom2d_Hyperbola)) { |
451 | Print(Handle(Geom2d_Hyperbola)::DownCast(C),OS,compact); |
452 | } |
453 | else if ( TheType == STANDARD_TYPE(Geom2d_BezierCurve)) { |
454 | Print(Handle(Geom2d_BezierCurve)::DownCast(C),OS,compact); |
455 | } |
456 | else if ( TheType == STANDARD_TYPE(Geom2d_BSplineCurve)) { |
457 | Print(Handle(Geom2d_BSplineCurve)::DownCast(C),OS,compact); |
458 | } |
459 | else if ( TheType == STANDARD_TYPE(Geom2d_TrimmedCurve)) { |
460 | Print(Handle(Geom2d_TrimmedCurve)::DownCast(C),OS,compact); |
461 | } |
462 | else if ( TheType == STANDARD_TYPE(Geom2d_OffsetCurve)) { |
463 | Print(Handle(Geom2d_OffsetCurve)::DownCast(C),OS,compact); |
464 | } |
465 | else { |
466 | GeomTools::GetUndefinedTypeHandler()->PrintCurve2d(C,OS,compact); |
467 | //if (!compact) |
468 | // OS << "****** UNKNOWN CURVE2d TYPE ******\n"; |
469 | //else |
04232180 |
470 | // std::cout << "****** UNKNOWN CURVE2d TYPE ******" << std::endl; |
7fd59977 |
471 | } |
472 | } |
473 | |
474 | //======================================================================= |
475 | //function : Dump |
476 | //purpose : |
477 | //======================================================================= |
478 | |
479 | void GeomTools_Curve2dSet::Dump(Standard_OStream& OS)const |
480 | { |
481 | Standard_Integer i, nbsurf = myMap.Extent(); |
482 | OS << "\n -------\n"; |
483 | OS << "Dump of "<< nbsurf << " Curve2ds "; |
484 | OS << "\n -------\n\n"; |
485 | |
486 | for (i = 1; i <= nbsurf; i++) { |
04232180 |
487 | OS << std::setw(4) << i << " : "; |
7fd59977 |
488 | PrintCurve2d(Handle(Geom2d_Curve)::DownCast(myMap(i)),OS,Standard_False); |
489 | } |
490 | } |
491 | |
492 | |
493 | //======================================================================= |
494 | //function : Write |
495 | //purpose : |
496 | //======================================================================= |
497 | |
7e785937 |
498 | void GeomTools_Curve2dSet::Write(Standard_OStream& OS, const Message_ProgressRange& theProgress)const |
7fd59977 |
499 | { |
60be1f9b |
500 | std::streamsize prec = OS.precision(17); |
7fd59977 |
501 | |
502 | Standard_Integer i, nbsurf = myMap.Extent(); |
503 | OS << "Curve2ds "<< nbsurf << "\n"; |
7e785937 |
504 | Message_ProgressScope aPS(theProgress, "2D Curves", nbsurf); |
505 | for (i = 1; i <= nbsurf && aPS.More(); i++, aPS.Next()) { |
7fd59977 |
506 | PrintCurve2d(Handle(Geom2d_Curve)::DownCast(myMap(i)),OS,Standard_True); |
507 | } |
7fd59977 |
508 | OS.precision(prec); |
509 | } |
510 | |
511 | |
512 | //======================================================================= |
513 | //function : ReadPnt2d |
514 | //purpose : |
515 | //======================================================================= |
516 | |
517 | static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt2d& P) |
518 | { |
519 | Standard_Real X=0.,Y=0.; |
71598a83 |
520 | GeomTools::GetReal(IS, X); |
521 | GeomTools::GetReal(IS, Y); |
7fd59977 |
522 | P.SetCoord(X,Y); |
523 | return IS; |
524 | } |
525 | |
526 | //======================================================================= |
527 | //function : ReadDir2d |
528 | //purpose : |
529 | //======================================================================= |
530 | |
531 | static Standard_IStream& operator>>(Standard_IStream& IS, gp_Dir2d& D) |
532 | { |
533 | Standard_Real X=0.,Y=0.; |
71598a83 |
534 | GeomTools::GetReal(IS, X); |
535 | GeomTools::GetReal(IS, Y); |
7fd59977 |
536 | D.SetCoord(X,Y); |
537 | return IS; |
538 | } |
539 | |
540 | |
541 | //======================================================================= |
542 | //function : ReadCurve2d |
543 | //purpose : |
544 | //======================================================================= |
545 | |
546 | static Standard_IStream& operator>>(Standard_IStream& IS, |
547 | Handle(Geom2d_Line)& L) |
548 | { |
549 | gp_Pnt2d P(0.,0.); |
550 | gp_Dir2d AX(1.,0.); |
551 | IS >> P >> AX; |
552 | L = new Geom2d_Line(P,AX); |
553 | return IS; |
554 | } |
555 | |
556 | //======================================================================= |
557 | //function : ReadCurve2d |
558 | //purpose : |
559 | //======================================================================= |
560 | |
561 | static Standard_IStream& operator>>(Standard_IStream& IS, |
562 | Handle(Geom2d_Circle)& C) |
563 | { |
564 | gp_Pnt2d P(0.,0.); |
565 | gp_Dir2d AX(1.,0.),AY(1.,0.); |
566 | Standard_Real R=0.; |
71598a83 |
567 | IS >> P >> AX >> AY; |
568 | GeomTools::GetReal(IS, R); |
7fd59977 |
569 | C = new Geom2d_Circle(gp_Ax22d(P,AX,AY),R); |
570 | return IS; |
571 | } |
572 | |
573 | //======================================================================= |
574 | //function : ReadCurve2d |
575 | //purpose : |
576 | //======================================================================= |
577 | |
578 | static Standard_IStream& operator>>(Standard_IStream& IS, |
579 | Handle(Geom2d_Ellipse)& E) |
580 | { |
581 | gp_Pnt2d P(0.,0.); |
582 | gp_Dir2d AX(1.,0.),AY(1.,0.); |
583 | Standard_Real R1=0.,R2=0.; |
71598a83 |
584 | IS >> P >> AX >> AY; |
585 | GeomTools::GetReal(IS, R1); |
586 | GeomTools::GetReal(IS, R2); |
7fd59977 |
587 | E = new Geom2d_Ellipse(gp_Ax22d(P,AX,AY),R1,R2); |
588 | return IS; |
589 | } |
590 | |
591 | //======================================================================= |
592 | //function : ReadCurve2d |
593 | //purpose : |
594 | //======================================================================= |
595 | |
596 | static Standard_IStream& operator>>(Standard_IStream& IS, |
597 | Handle(Geom2d_Parabola)& C) |
598 | { |
599 | gp_Pnt2d P(0.,0.); |
600 | gp_Dir2d AX(1.,0.),AY(1.,0.); |
601 | Standard_Real R1=0.; |
71598a83 |
602 | IS >> P >> AX >> AY; |
603 | GeomTools::GetReal(IS, R1); |
7fd59977 |
604 | C = new Geom2d_Parabola(gp_Ax22d(P,AX,AY),R1); |
605 | return IS; |
606 | } |
607 | |
608 | //======================================================================= |
609 | //function : ReadCurve2d |
610 | //purpose : |
611 | //======================================================================= |
612 | |
613 | static Standard_IStream& operator>>(Standard_IStream& IS, |
614 | Handle(Geom2d_Hyperbola)& H) |
615 | { |
616 | gp_Pnt2d P(0.,0.); |
617 | gp_Dir2d AX(1.,0.),AY(1.,0.); |
618 | Standard_Real R1=0.,R2=0.; |
71598a83 |
619 | IS >> P >> AX >> AY; |
620 | GeomTools::GetReal(IS, R1); |
621 | GeomTools::GetReal(IS, R2); |
7fd59977 |
622 | H = new Geom2d_Hyperbola(gp_Ax22d(P,AX,AY),R1,R2); |
623 | return IS; |
624 | } |
625 | |
626 | //======================================================================= |
627 | //function : ReadCurve2d |
628 | //purpose : |
629 | //======================================================================= |
630 | |
631 | static Standard_IStream& operator>>(Standard_IStream& IS, |
632 | Handle(Geom2d_BezierCurve)& B) |
633 | { |
634 | Standard_Boolean rational=Standard_False; |
635 | IS >> rational; |
636 | |
637 | // poles and weights |
638 | Standard_Integer i=0,degree=0; |
639 | IS >> degree; |
640 | |
641 | TColgp_Array1OfPnt2d poles(1,degree+1); |
642 | TColStd_Array1OfReal weights(1,degree+1); |
643 | |
644 | for (i = 1; i <= degree+1; i++) { |
645 | IS >> poles(i); |
646 | if (rational) |
71598a83 |
647 | GeomTools::GetReal(IS, weights(i)); |
7fd59977 |
648 | } |
649 | |
650 | if (rational) |
651 | B = new Geom2d_BezierCurve(poles,weights); |
652 | else |
653 | B = new Geom2d_BezierCurve(poles); |
654 | |
655 | return IS; |
656 | } |
657 | |
658 | //======================================================================= |
659 | //function : ReadCurve2d |
660 | //purpose : |
661 | //======================================================================= |
662 | |
663 | static Standard_IStream& operator>>(Standard_IStream& IS, |
664 | Handle(Geom2d_BSplineCurve)& B) |
665 | { |
666 | Standard_Boolean rational=Standard_False,periodic=Standard_False; |
667 | IS >> rational >> periodic; |
668 | |
669 | // poles and weights |
670 | Standard_Integer i=0,degree=0,nbpoles=0,nbknots=0; |
671 | IS >> degree >> nbpoles >> nbknots; |
672 | |
673 | TColgp_Array1OfPnt2d poles(1,nbpoles); |
674 | TColStd_Array1OfReal weights(1,nbpoles); |
675 | |
676 | for (i = 1; i <= nbpoles; i++) { |
677 | IS >> poles(i); |
678 | if (rational) |
71598a83 |
679 | GeomTools::GetReal(IS, weights(i)); |
7fd59977 |
680 | } |
681 | |
682 | TColStd_Array1OfReal knots(1,nbknots); |
683 | TColStd_Array1OfInteger mults(1,nbknots); |
684 | |
685 | for (i = 1; i <= nbknots; i++) { |
71598a83 |
686 | GeomTools::GetReal(IS, knots(i)); |
687 | IS >> mults(i); |
7fd59977 |
688 | } |
689 | |
690 | if (rational) |
691 | B = new Geom2d_BSplineCurve(poles,weights,knots,mults,degree,periodic); |
692 | else |
693 | B = new Geom2d_BSplineCurve(poles,knots,mults,degree,periodic); |
694 | |
695 | return IS; |
696 | } |
697 | |
698 | //======================================================================= |
699 | //function : ReadCurve2d |
700 | //purpose : |
701 | //======================================================================= |
702 | |
703 | static Standard_IStream& operator>>(Standard_IStream& IS, |
704 | Handle(Geom2d_TrimmedCurve)& C) |
705 | { |
706 | Standard_Real p1=0.,p2=0.; |
71598a83 |
707 | GeomTools::GetReal(IS, p1); |
708 | GeomTools::GetReal(IS, p2); |
aa00364d |
709 | Handle(Geom2d_Curve) BC = GeomTools_Curve2dSet::ReadCurve2d(IS); |
7fd59977 |
710 | C = new Geom2d_TrimmedCurve(BC,p1,p2); |
711 | return IS; |
712 | } |
713 | |
714 | //======================================================================= |
715 | //function : ReadCurve2d |
716 | //purpose : |
717 | //======================================================================= |
718 | |
719 | static Standard_IStream& operator>>(Standard_IStream& IS, |
720 | Handle(Geom2d_OffsetCurve)& C) |
721 | { |
722 | Standard_Real p=0.; |
71598a83 |
723 | GeomTools::GetReal(IS, p); |
aa00364d |
724 | Handle(Geom2d_Curve) BC = GeomTools_Curve2dSet::ReadCurve2d(IS); |
7fd59977 |
725 | C = new Geom2d_OffsetCurve(BC,p); |
726 | return IS; |
727 | } |
728 | |
729 | //======================================================================= |
730 | //function : ReadCurve2d |
731 | //purpose : |
732 | //======================================================================= |
733 | |
aa00364d |
734 | Handle(Geom2d_Curve) GeomTools_Curve2dSet::ReadCurve2d(Standard_IStream& IS) |
7fd59977 |
735 | { |
736 | Standard_Integer ctype; |
737 | |
aa00364d |
738 | Handle(Geom2d_Curve) C; |
7fd59977 |
739 | try { |
740 | OCC_CATCH_SIGNALS |
741 | IS >> ctype; |
742 | switch (ctype) { |
743 | |
744 | case LINE : |
745 | { |
746 | Handle(Geom2d_Line) CC; |
747 | IS >> CC; |
748 | C = CC; |
749 | } |
750 | break; |
751 | |
752 | case CIRCLE : |
753 | { |
754 | Handle(Geom2d_Circle) CC; |
755 | IS >> CC; |
756 | C = CC; |
757 | } |
758 | break; |
759 | |
760 | case ELLIPSE : |
761 | { |
762 | Handle(Geom2d_Ellipse) CC; |
763 | IS >> CC; |
764 | C = CC; |
765 | } |
766 | break; |
767 | |
768 | case PARABOLA : |
769 | { |
770 | Handle(Geom2d_Parabola) CC; |
771 | IS >> CC; |
772 | C = CC; |
773 | } |
774 | break; |
775 | |
776 | case HYPERBOLA : |
777 | { |
778 | Handle(Geom2d_Hyperbola) CC; |
779 | IS >> CC; |
780 | C = CC; |
781 | } |
782 | break; |
783 | |
784 | case BEZIER : |
785 | { |
786 | Handle(Geom2d_BezierCurve) CC; |
787 | IS >> CC; |
788 | C = CC; |
789 | } |
790 | break; |
791 | |
792 | case BSPLINE : |
793 | { |
794 | Handle(Geom2d_BSplineCurve) CC; |
795 | IS >> CC; |
796 | C = CC; |
797 | } |
798 | break; |
799 | |
800 | case TRIMMED : |
801 | { |
802 | Handle(Geom2d_TrimmedCurve) CC; |
803 | IS >> CC; |
804 | C = CC; |
805 | } |
806 | break; |
807 | |
808 | case OFFSET : |
809 | { |
810 | Handle(Geom2d_OffsetCurve) CC; |
811 | IS >> CC; |
812 | C = CC; |
813 | } |
814 | break; |
815 | |
816 | default: |
817 | { |
818 | Handle(Geom2d_Curve) CC; |
819 | GeomTools::GetUndefinedTypeHandler()->ReadCurve2d(ctype,IS,CC); |
820 | C = CC; |
821 | } |
822 | break; |
823 | } |
824 | } |
9775fa61 |
825 | catch(Standard_Failure const& anException) { |
0797d9d3 |
826 | #ifdef OCCT_DEBUG |
04232180 |
827 | std::cout <<"EXCEPTION in GeomTools_Curve2dSet::ReadCurve2d(..)!!!" << std::endl; |
828 | std::cout << anException << std::endl; |
7fd59977 |
829 | #endif |
9775fa61 |
830 | (void)anException; |
7fd59977 |
831 | } |
aa00364d |
832 | return C; |
7fd59977 |
833 | } |
834 | |
835 | //======================================================================= |
836 | //function : Read |
837 | //purpose : |
838 | //======================================================================= |
839 | |
7e785937 |
840 | void GeomTools_Curve2dSet::Read(Standard_IStream& IS, const Message_ProgressRange& theProgress) |
7fd59977 |
841 | { |
842 | char buffer[255]; |
843 | IS >> buffer; |
844 | if (strcmp(buffer,"Curve2ds")) { |
04232180 |
845 | std::cout << "Not a Curve2d table"<<std::endl; |
7fd59977 |
846 | return; |
847 | } |
848 | |
7fd59977 |
849 | Standard_Integer i, nbcurve; |
850 | IS >> nbcurve; |
7e785937 |
851 | Message_ProgressScope aPS(theProgress, "2D Curves", nbcurve); |
852 | for (i = 1; i <= nbcurve && aPS.More(); i++, aPS.Next()) { |
aa00364d |
853 | Handle(Geom2d_Curve) C = GeomTools_Curve2dSet::ReadCurve2d (IS); |
7fd59977 |
854 | myMap.Add(C); |
855 | } |
856 | } |