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