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