b311480e |
1 | // Created on: 2004-05-18 |
2 | // Created by: Sergey ZARITCHNY |
3 | // Copyright (c) 2004-2012 OPEN CASCADE SAS |
4 | // |
5 | // The content of this file is subject to the Open CASCADE Technology Public |
6 | // License Version 6.5 (the "License"). You may not use the content of this file |
7 | // except in compliance with the License. Please obtain a copy of the License |
8 | // at http://www.opencascade.org and read it completely before using this file. |
9 | // |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
12 | // |
13 | // The Original Code and all software distributed under the License is |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
15 | // Initial Developer hereby disclaims all such warranties, including without |
16 | // limitation, any warranties of merchantability, fitness for a particular |
17 | // purpose or non-infringement. Please see the License for the specific terms |
18 | // and conditions governing the rights and limitations under the License. |
19 | |
7fd59977 |
20 | |
21 | #include <BinTools_Curve2dSet.ixx> |
22 | #include <Standard_Stream.hxx> |
23 | #include <Geom2d_Circle.hxx> |
24 | #include <Geom2d_Line.hxx> |
25 | #include <Geom2d_Ellipse.hxx> |
26 | #include <Geom2d_Parabola.hxx> |
27 | #include <Geom2d_Hyperbola.hxx> |
28 | #include <Geom2d_BezierCurve.hxx> |
29 | #include <Geom2d_BSplineCurve.hxx> |
30 | #include <Geom2d_TrimmedCurve.hxx> |
31 | #include <Geom2d_OffsetCurve.hxx> |
32 | |
33 | #include <gp_Lin2d.hxx> |
34 | #include <gp_Circ2d.hxx> |
35 | #include <gp_Elips2d.hxx> |
36 | #include <gp_Parab2d.hxx> |
37 | #include <gp_Hypr2d.hxx> |
38 | |
39 | #include <TColStd_Array1OfReal.hxx> |
40 | #include <TColStd_Array1OfInteger.hxx> |
41 | #include <TColgp_Array1OfPnt2d.hxx> |
42 | #include <Standard_Failure.hxx> |
43 | #include <Standard_ErrorHandler.hxx> |
44 | |
45 | #include <BinTools.hxx> |
46 | |
47 | #define LINE 1 |
48 | #define CIRCLE 2 |
49 | #define ELLIPSE 3 |
50 | #define PARABOLA 4 |
51 | #define HYPERBOLA 5 |
52 | #define BEZIER 6 |
53 | #define BSPLINE 7 |
54 | #define TRIMMED 8 |
55 | #define OFFSET 9 |
56 | |
57 | //======================================================================= |
58 | //function : BinTools_Curve2dSet |
59 | //purpose : |
60 | //======================================================================= |
61 | |
62 | BinTools_Curve2dSet::BinTools_Curve2dSet() |
63 | { |
64 | } |
65 | |
66 | |
67 | //======================================================================= |
68 | //function : Clear |
69 | //purpose : |
70 | //======================================================================= |
71 | |
72 | void BinTools_Curve2dSet::Clear() |
73 | { |
74 | myMap.Clear(); |
75 | } |
76 | |
77 | |
78 | //======================================================================= |
79 | //function : Add |
80 | //purpose : |
81 | //======================================================================= |
82 | |
83 | Standard_Integer BinTools_Curve2dSet::Add(const Handle(Geom2d_Curve)& S) |
84 | { |
85 | return myMap.Add(S); |
86 | } |
87 | |
88 | |
89 | //======================================================================= |
90 | //function : Curve2d |
91 | //purpose : |
92 | //======================================================================= |
93 | |
94 | Handle(Geom2d_Curve) BinTools_Curve2dSet::Curve2d |
95 | (const Standard_Integer I)const |
96 | { |
97 | return Handle(Geom2d_Curve)::DownCast(myMap(I)); |
98 | } |
99 | |
100 | |
101 | //======================================================================= |
102 | //function : Index |
103 | //purpose : |
104 | //======================================================================= |
105 | |
106 | Standard_Integer BinTools_Curve2dSet::Index |
107 | (const Handle(Geom2d_Curve)& S)const |
108 | { |
109 | return myMap.FindIndex(S); |
110 | } |
111 | |
112 | //======================================================================= |
113 | //function : operator << (gp_Pnt2d) |
114 | //purpose : |
115 | //======================================================================= |
116 | |
117 | static Standard_OStream& operator <<(Standard_OStream& OS, const gp_Pnt2d P) |
118 | |
119 | { |
120 | BinTools::PutReal(OS, P.X()); |
121 | return BinTools::PutReal(OS, P.Y()); |
122 | } |
123 | |
124 | //======================================================================= |
125 | //function : operator << (gp_Dir2d D) |
126 | //purpose : |
127 | //======================================================================= |
128 | |
129 | static Standard_OStream& operator <<(Standard_OStream& OS, const gp_Dir2d D) |
130 | { |
131 | BinTools::PutReal(OS, D.X()); |
132 | return BinTools::PutReal(OS, D.Y()); |
133 | } |
134 | |
135 | //======================================================================= |
136 | //function : operator << ((Geom2d_Line)& L) |
137 | //purpose : |
138 | //======================================================================= |
139 | |
140 | static Standard_OStream& operator <<(Standard_OStream& OS, const Handle(Geom2d_Line)& L) |
141 | { |
142 | |
143 | OS << (Standard_Byte)LINE; |
144 | gp_Lin2d C2d = L->Lin2d(); |
145 | OS << C2d.Location();//Pnt2d |
146 | OS << C2d.Direction();//Dir2d |
147 | return OS; |
148 | } |
149 | |
150 | //======================================================================= |
151 | //function : operator << ((Geom2d_Circle)& C) |
152 | //purpose : |
153 | //======================================================================= |
154 | |
155 | static Standard_OStream& operator <<(Standard_OStream& OS, const Handle(Geom2d_Circle)& C) |
156 | { |
157 | OS << (Standard_Byte)CIRCLE; |
158 | gp_Circ2d C2d = C->Circ2d(); |
159 | OS << C2d.Location(); |
160 | OS << C2d.XAxis().Direction(); |
161 | OS << C2d.YAxis().Direction(); |
162 | BinTools::PutReal(OS, C2d.Radius()); |
163 | return OS; |
164 | } |
165 | |
166 | //======================================================================= |
167 | //function : operator <<(Geom2d_Ellipse) |
168 | //purpose : |
169 | //======================================================================= |
170 | |
171 | static Standard_OStream& operator <<(Standard_OStream& OS, const Handle(Geom2d_Ellipse)& E) |
172 | { |
173 | OS << (Standard_Byte)ELLIPSE; |
174 | gp_Elips2d C2d = E->Elips2d(); |
175 | OS << C2d.Location(); |
176 | OS << C2d.XAxis().Direction(); |
177 | OS << C2d.YAxis().Direction(); |
178 | BinTools::PutReal(OS, C2d.MajorRadius()); |
179 | BinTools::PutReal(OS, C2d.MinorRadius()); |
180 | return OS; |
181 | } |
182 | |
183 | //======================================================================= |
184 | //function : operator << (Geom2d_Parabola) |
185 | //purpose : |
186 | //======================================================================= |
187 | |
188 | static Standard_OStream& operator <<(Standard_OStream& OS, const Handle(Geom2d_Parabola)& P) |
189 | { |
190 | OS << (Standard_Byte)PARABOLA; |
191 | gp_Parab2d C2d = P->Parab2d(); |
192 | OS << C2d.Location();//Loc |
193 | OS << C2d.Axis().XAxis().Direction();//XDir |
194 | OS << C2d.Axis().YAxis().Direction();//YDir |
195 | BinTools::PutReal(OS, C2d.Focal());//Focal |
196 | return OS; |
197 | } |
198 | |
199 | //======================================================================= |
200 | //function : operator <<(Geom2d_Hyperbola) |
201 | //purpose : |
202 | //======================================================================= |
203 | |
204 | static Standard_OStream& operator <<(Standard_OStream& OS, const Handle(Geom2d_Hyperbola)& H) |
205 | { |
206 | OS << (Standard_Byte)HYPERBOLA; |
207 | gp_Hypr2d C2d = H->Hypr2d(); |
208 | OS << C2d.Location(); //Loc |
209 | OS << C2d.XAxis().Direction();//XDir |
210 | OS << C2d.YAxis().Direction();//YDir |
211 | BinTools::PutReal(OS, C2d.MajorRadius());//MajR |
212 | BinTools::PutReal(OS, C2d.MinorRadius()); |
213 | return OS; |
214 | } |
215 | |
216 | //======================================================================= |
217 | //function : operator <<(Geom2d_BezierCurve) |
218 | //purpose : |
219 | //======================================================================= |
220 | |
221 | static Standard_OStream& operator <<(Standard_OStream& OS, const Handle(Geom2d_BezierCurve)& B) |
222 | { |
223 | OS << (Standard_Byte)BEZIER; |
224 | Standard_Boolean aRational = B->IsRational() ? 1:0; |
225 | BinTools::PutBool(OS, aRational); //rational |
226 | // poles and weights |
227 | Standard_Integer i,aDegree = B->Degree(); |
228 | BinTools::PutExtChar(OS, (Standard_ExtCharacter)aDegree); //Degree |
229 | for (i = 1; i <= aDegree+1; i++) { |
230 | OS << B->Pole(i); //Pnt2d |
231 | if (aRational) |
232 | BinTools::PutReal(OS, B->Weight(i));//Real |
233 | } |
234 | return OS; |
235 | } |
236 | |
237 | //======================================================================= |
238 | //function : operator <<(Geom2d_BSplineCurve) |
239 | //purpose : |
240 | //======================================================================= |
241 | |
242 | static Standard_OStream& operator <<(Standard_OStream& OS, const Handle(Geom2d_BSplineCurve)& B) |
243 | { |
244 | OS << (Standard_Byte)BSPLINE; |
245 | Standard_Boolean aRational = B->IsRational() ? 1:0; |
246 | BinTools::PutBool(OS, aRational); //rational |
247 | Standard_Boolean aPeriodic = B->IsPeriodic() ? 1:0; |
248 | BinTools::PutBool(OS, aPeriodic); //periodic |
249 | // poles and weights |
250 | Standard_Integer i,aDegree,aNbPoles,aNbKnots; |
251 | aDegree = B->Degree(); |
252 | aNbPoles = B->NbPoles(); |
253 | aNbKnots = B->NbKnots(); |
254 | BinTools::PutExtChar(OS, (Standard_ExtCharacter) aDegree); |
255 | BinTools::PutInteger(OS, aNbPoles); |
256 | BinTools::PutInteger(OS, aNbKnots); |
257 | for (i = 1; i <= aNbPoles; i++) { |
258 | OS << B->Pole(i); // Pnt2d |
259 | if (aRational) |
260 | BinTools::PutReal(OS, B->Weight(i)); |
261 | } |
262 | |
263 | for (i = 1; i <= aNbKnots; i++) { |
264 | BinTools::PutReal(OS, B->Knot(i)); |
265 | BinTools::PutInteger(OS, B->Multiplicity(i)); |
266 | } |
267 | |
268 | return OS; |
269 | } |
270 | |
271 | //======================================================================= |
272 | //function : operator <<(Geom2d_TrimmedCurve) |
273 | //purpose : |
274 | //======================================================================= |
275 | |
276 | static Standard_OStream& operator <<(Standard_OStream& OS, const Handle(Geom2d_TrimmedCurve)& C) |
277 | { |
278 | OS << (Standard_Byte)TRIMMED; |
279 | BinTools::PutReal(OS, C->FirstParameter()); |
280 | BinTools::PutReal(OS, C->LastParameter()); |
281 | BinTools_Curve2dSet::WriteCurve2d(C->BasisCurve(),OS); |
282 | return OS; |
283 | } |
284 | |
285 | //======================================================================= |
286 | //function : operator <<(Geom2d_OffsetCurve) |
287 | //purpose : |
288 | //======================================================================= |
289 | |
290 | static Standard_OStream& operator <<(Standard_OStream& OS, const Handle(Geom2d_OffsetCurve)& C) |
291 | { |
292 | OS << (Standard_Byte)OFFSET; |
293 | BinTools::PutReal(OS,C->Offset());//Offset |
294 | BinTools_Curve2dSet::WriteCurve2d(C->BasisCurve(),OS); |
295 | return OS; |
296 | } |
297 | |
298 | //======================================================================= |
299 | //function : WriteCurve2d |
300 | //purpose : |
301 | //======================================================================= |
302 | |
303 | void BinTools_Curve2dSet::WriteCurve2d(const Handle(Geom2d_Curve)& C, |
304 | Standard_OStream& OS) |
305 | { |
306 | Standard_SStream aMsg; |
307 | Handle(Standard_Type) TheType = C->DynamicType(); |
308 | try { |
309 | OCC_CATCH_SIGNALS |
310 | if ( TheType == STANDARD_TYPE(Geom2d_Circle)) { |
311 | OS << Handle(Geom2d_Circle)::DownCast(C); |
312 | } |
313 | else if ( TheType ==STANDARD_TYPE(Geom2d_Line)) { |
314 | OS << Handle(Geom2d_Line)::DownCast(C); |
315 | } |
316 | else if ( TheType == STANDARD_TYPE(Geom2d_Ellipse)) { |
317 | OS << Handle(Geom2d_Ellipse)::DownCast(C); |
318 | } |
319 | else if ( TheType == STANDARD_TYPE(Geom2d_Parabola)) { |
320 | OS << Handle(Geom2d_Parabola)::DownCast(C); |
321 | } |
322 | else if ( TheType == STANDARD_TYPE(Geom2d_Hyperbola)) { |
323 | OS << Handle(Geom2d_Hyperbola)::DownCast(C); |
324 | } |
325 | else if ( TheType == STANDARD_TYPE(Geom2d_BezierCurve)) { |
326 | OS << Handle(Geom2d_BezierCurve)::DownCast(C); |
327 | } |
328 | else if ( TheType == STANDARD_TYPE(Geom2d_BSplineCurve)) { |
329 | OS << Handle(Geom2d_BSplineCurve)::DownCast(C); |
330 | } |
331 | else if ( TheType == STANDARD_TYPE(Geom2d_TrimmedCurve)) { |
332 | OS << Handle(Geom2d_TrimmedCurve)::DownCast(C); |
333 | } |
334 | else if ( TheType == STANDARD_TYPE(Geom2d_OffsetCurve)) { |
335 | OS << Handle(Geom2d_OffsetCurve)::DownCast(C); |
336 | } |
337 | else { |
338 | aMsg << "UNKNOWN CURVE2d TYPE" << endl; |
339 | Standard_Failure::Raise(aMsg); |
340 | } |
341 | } |
342 | catch(Standard_Failure) { |
343 | aMsg << "EXCEPTION in BinTools_Curve2dSet::WriteCurve2d(..)" << endl; |
344 | Handle(Standard_Failure) anExc = Standard_Failure::Caught(); |
345 | aMsg << anExc << endl; |
346 | Standard_Failure::Raise(aMsg); |
347 | } |
348 | } |
349 | |
350 | //======================================================================= |
351 | //function : Write |
352 | //purpose : |
353 | //======================================================================= |
354 | |
355 | void BinTools_Curve2dSet::Write(Standard_OStream& OS)const |
356 | { |
357 | Standard_Integer i, aNbCurves = myMap.Extent(); |
358 | OS << "Curve2ds "<< aNbCurves << "\n"; |
359 | for (i = 1; i <= aNbCurves; i++) { |
360 | WriteCurve2d(Handle(Geom2d_Curve)::DownCast(myMap(i)),OS); |
361 | } |
362 | } |
363 | |
364 | |
365 | //======================================================================= |
366 | //function : ReadPnt2d |
367 | //purpose : |
368 | //======================================================================= |
369 | |
370 | static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt2d& P) |
371 | { |
372 | Standard_Real X=0.,Y=0.; |
373 | BinTools::GetReal(IS, X); |
374 | BinTools::GetReal(IS, Y); |
375 | P.SetCoord(X,Y); |
376 | return IS; |
377 | } |
378 | |
379 | //======================================================================= |
380 | //function : ReadDir2d |
381 | //purpose : |
382 | //======================================================================= |
383 | |
384 | static Standard_IStream& operator>>(Standard_IStream& IS, gp_Dir2d& D) |
385 | { |
386 | Standard_Real X=0.,Y=0.; |
387 | BinTools::GetReal(IS, X); |
388 | BinTools::GetReal(IS, Y); |
389 | D.SetCoord(X,Y); |
390 | return IS; |
391 | } |
392 | |
393 | |
394 | //======================================================================= |
395 | //function : ReadCurve2d |
396 | //purpose : |
397 | //======================================================================= |
398 | |
399 | static Standard_IStream& operator>>(Standard_IStream& IS, |
400 | Handle(Geom2d_Line)& L) |
401 | { |
402 | gp_Pnt2d P(0.,0.); |
403 | gp_Dir2d AX(1.,0.); |
404 | IS >> P >> AX; |
405 | L = new Geom2d_Line(P,AX); |
406 | return IS; |
407 | } |
408 | |
409 | //======================================================================= |
410 | //function : ReadCurve2d |
411 | //purpose : |
412 | //======================================================================= |
413 | static Standard_IStream& operator>>(Standard_IStream& IS, |
414 | Handle(Geom2d_Circle)& C) |
415 | { |
416 | gp_Pnt2d P(0.,0.); |
417 | gp_Dir2d AX(1.,0.),AY(1.,0.); |
418 | Standard_Real R=0.; |
419 | IS >> P >> AX >> AY; |
420 | BinTools::GetReal(IS, R); |
421 | C = new Geom2d_Circle(gp_Ax22d(P,AX,AY),R); |
422 | return IS; |
423 | } |
424 | |
425 | //======================================================================= |
426 | //function : ReadCurve2d |
427 | //purpose : |
428 | //======================================================================= |
429 | |
430 | static Standard_IStream& operator>>(Standard_IStream& IS, |
431 | Handle(Geom2d_Ellipse)& E) |
432 | { |
433 | gp_Pnt2d P(0.,0.); |
434 | gp_Dir2d AX(1.,0.),AY(1.,0.); |
435 | Standard_Real R1=0., R2=0.; |
436 | IS >> P >> AX >> AY; |
437 | BinTools::GetReal(IS, R1); |
438 | BinTools::GetReal(IS, R2); |
439 | E = new Geom2d_Ellipse(gp_Ax22d(P,AX,AY),R1,R2); |
440 | return IS; |
441 | } |
442 | |
443 | //======================================================================= |
444 | //function : ReadCurve2d |
445 | //purpose : |
446 | //======================================================================= |
447 | |
448 | static Standard_IStream& operator>>(Standard_IStream& IS, |
449 | Handle(Geom2d_Parabola)& C) |
450 | { |
451 | gp_Pnt2d P(0.,0.); |
452 | gp_Dir2d AX(1.,0.),AY(1.,0.); |
453 | Standard_Real R1=0.; |
454 | IS >> P >> AX >> AY; |
455 | BinTools::GetReal(IS, R1); |
456 | C = new Geom2d_Parabola(gp_Ax22d(P,AX,AY),R1); |
457 | return IS; |
458 | } |
459 | |
460 | //======================================================================= |
461 | //function : ReadCurve2d |
462 | //purpose : |
463 | //======================================================================= |
464 | |
465 | static Standard_IStream& operator>>(Standard_IStream& IS, |
466 | Handle(Geom2d_Hyperbola)& H) |
467 | { |
468 | gp_Pnt2d P(0.,0.); |
469 | gp_Dir2d AX(1.,0.),AY(1.,0.); |
470 | Standard_Real R1=0.,R2=0.; |
471 | IS >> P >> AX >> AY; |
472 | BinTools::GetReal(IS, R1); |
473 | BinTools::GetReal(IS, R2); |
474 | H = new Geom2d_Hyperbola(gp_Ax22d(P,AX,AY),R1,R2); |
475 | return IS; |
476 | } |
477 | |
478 | //======================================================================= |
479 | //function : ReadCurve2d |
480 | //purpose : |
481 | //======================================================================= |
482 | |
483 | static Standard_IStream& operator>>(Standard_IStream& IS, |
484 | Handle(Geom2d_BezierCurve)& B) |
485 | { |
486 | Standard_Boolean rational=Standard_False; |
487 | BinTools::GetBool(IS, rational); |
488 | |
489 | // poles and weights |
490 | Standard_Integer i=0,degree=0; |
491 | // degree; |
492 | Standard_ExtCharacter aVal='\0'; |
493 | BinTools::GetExtChar(IS, aVal); |
494 | degree = (Standard_Integer)aVal; |
495 | |
496 | TColgp_Array1OfPnt2d poles(1,degree+1); |
497 | TColStd_Array1OfReal weights(1,degree+1); |
498 | |
499 | for (i = 1; i <= degree+1; i++) { |
500 | IS >> poles(i);//Pnt2d |
501 | if (rational) |
502 | BinTools::GetReal(IS, weights(i)); |
503 | } |
504 | |
505 | if (rational) |
506 | B = new Geom2d_BezierCurve(poles,weights); |
507 | else |
508 | B = new Geom2d_BezierCurve(poles); |
509 | |
510 | return IS; |
511 | } |
512 | |
513 | //======================================================================= |
514 | //function : ReadCurve2d |
515 | //purpose : |
516 | //======================================================================= |
517 | |
518 | static Standard_IStream& operator>>(Standard_IStream& IS, |
519 | Handle(Geom2d_BSplineCurve)& B) |
520 | { |
521 | |
522 | Standard_Boolean rational=Standard_False,periodic=Standard_False; |
523 | BinTools::GetBool(IS, rational); |
524 | BinTools::GetBool(IS, periodic); |
525 | // poles and weights |
526 | Standard_Integer i=0,degree=0,nbpoles=0,nbknots=0; |
527 | Standard_ExtCharacter aVal='\0'; |
528 | |
529 | BinTools::GetExtChar(IS, aVal); |
530 | degree = (Standard_Integer)aVal; |
531 | |
532 | BinTools::GetInteger(IS, nbpoles); |
533 | |
534 | BinTools::GetInteger(IS, nbknots); |
535 | |
536 | TColgp_Array1OfPnt2d poles(1,nbpoles); |
537 | TColStd_Array1OfReal weights(1,nbpoles); |
538 | |
539 | for (i = 1; i <= nbpoles; i++) { |
540 | IS >> poles(i);//Pnt2d |
541 | if (rational) |
542 | BinTools::GetReal(IS, weights(i)); |
543 | } |
544 | |
545 | TColStd_Array1OfReal knots(1,nbknots); |
546 | TColStd_Array1OfInteger mults(1,nbknots); |
547 | |
548 | for (i = 1; i <= nbknots; i++) { |
549 | BinTools::GetReal(IS, knots(i)); |
550 | BinTools::GetInteger(IS, mults(i)); |
551 | } |
552 | |
553 | if (rational) |
554 | B = new Geom2d_BSplineCurve(poles,weights,knots,mults,degree,periodic); |
555 | else |
556 | B = new Geom2d_BSplineCurve(poles,knots,mults,degree,periodic); |
557 | |
558 | return IS; |
559 | } |
560 | |
561 | //======================================================================= |
562 | //function : ReadCurve2d |
563 | //purpose : |
564 | //======================================================================= |
565 | |
566 | static Standard_IStream& operator>>(Standard_IStream& IS, |
567 | Handle(Geom2d_TrimmedCurve)& C) |
568 | { |
569 | Standard_Real p1=0.,p2=0.; |
570 | BinTools::GetReal(IS, p1);//FirstParameter |
571 | BinTools::GetReal(IS, p2);//LastParameter |
572 | Handle(Geom2d_Curve) BC; |
573 | BinTools_Curve2dSet::ReadCurve2d(IS,BC); |
574 | C = new Geom2d_TrimmedCurve(BC,p1,p2); |
575 | return IS; |
576 | } |
577 | |
578 | //======================================================================= |
579 | //function : ReadCurve2d |
580 | //purpose : |
581 | //======================================================================= |
582 | |
583 | static Standard_IStream& operator>>(Standard_IStream& IS, |
584 | Handle(Geom2d_OffsetCurve)& C) |
585 | { |
586 | Standard_Real p=0.; |
587 | BinTools::GetReal(IS, p);//Offset |
588 | Handle(Geom2d_Curve) BC; |
589 | BinTools_Curve2dSet::ReadCurve2d(IS,BC); |
590 | C = new Geom2d_OffsetCurve(BC,p); |
591 | return IS; |
592 | } |
593 | |
594 | //======================================================================= |
595 | //function : ReadCurve2d |
596 | //purpose : |
597 | //======================================================================= |
598 | |
599 | Standard_IStream& BinTools_Curve2dSet::ReadCurve2d(Standard_IStream& IS, |
600 | Handle(Geom2d_Curve)& C) |
601 | { |
602 | Standard_SStream aMsg; |
603 | try { |
604 | OCC_CATCH_SIGNALS |
605 | const Standard_Byte ctype = (Standard_Byte) IS.get(); |
606 | switch (ctype) { |
607 | |
608 | case LINE : |
609 | { |
610 | Handle(Geom2d_Line) CC; |
611 | IS >> CC; |
612 | C = CC; |
613 | } |
614 | break; |
615 | |
616 | case CIRCLE : |
617 | { |
618 | Handle(Geom2d_Circle) CC; |
619 | IS >> CC; |
620 | C = CC; |
621 | } |
622 | break; |
623 | |
624 | case ELLIPSE : |
625 | { |
626 | Handle(Geom2d_Ellipse) CC; |
627 | IS >> CC; |
628 | C = CC; |
629 | } |
630 | break; |
631 | |
632 | case PARABOLA : |
633 | { |
634 | Handle(Geom2d_Parabola) CC; |
635 | IS >> CC; |
636 | C = CC; |
637 | } |
638 | break; |
639 | |
640 | case HYPERBOLA : |
641 | { |
642 | Handle(Geom2d_Hyperbola) CC; |
643 | IS >> CC; |
644 | C = CC; |
645 | } |
646 | break; |
647 | |
648 | case BEZIER : |
649 | { |
650 | Handle(Geom2d_BezierCurve) CC; |
651 | IS >> CC; |
652 | C = CC; |
653 | } |
654 | break; |
655 | |
656 | case BSPLINE : |
657 | { |
658 | Handle(Geom2d_BSplineCurve) CC; |
659 | IS >> CC; |
660 | C = CC; |
661 | } |
662 | break; |
663 | |
664 | case TRIMMED : |
665 | { |
666 | Handle(Geom2d_TrimmedCurve) CC; |
667 | IS >> CC; |
668 | C = CC; |
669 | } |
670 | break; |
671 | |
672 | case OFFSET : |
673 | { |
674 | Handle(Geom2d_OffsetCurve) CC; |
675 | IS >> CC; |
676 | C = CC; |
677 | } |
678 | break; |
679 | |
680 | default: |
681 | { |
682 | C = NULL; |
683 | aMsg << "UNKNOWN CURVE2d TYPE" << endl; |
684 | Standard_Failure::Raise(aMsg); |
685 | } |
686 | break; |
687 | } |
688 | } |
689 | catch(Standard_Failure) { |
690 | C = NULL; |
691 | aMsg <<"EXCEPTION in BinTools_Curve2dSet::ReadCurve2d(...)" << endl; |
692 | Handle(Standard_Failure) anExc = Standard_Failure::Caught(); |
693 | aMsg << anExc << endl; |
694 | Standard_Failure::Raise(aMsg); |
695 | } |
696 | return IS; |
697 | } |
698 | |
699 | //======================================================================= |
700 | //function : Read |
701 | //purpose : |
702 | //======================================================================= |
703 | |
704 | void BinTools_Curve2dSet::Read(Standard_IStream& IS) |
705 | { |
706 | char buffer[255]; |
707 | #ifdef DEB |
708 | // const Standard_Integer aPos = IS.tellg(); |
709 | // cout << "\tPosition of Curves2d section = " << aPos << endl; |
710 | #endif |
711 | IS >> buffer; |
712 | if (IS.fail() || strcmp(buffer,"Curve2ds")) { |
713 | Standard_SStream aMsg; |
714 | aMsg << "BinTools_Curve2dSet::Read: Not a Curve2d table"<<endl; |
715 | #ifdef DEB |
716 | cout <<"Curve2dSet buffer: " << buffer << endl; |
717 | #endif |
718 | Standard_Failure::Raise(aMsg); |
719 | return; |
720 | } |
721 | |
722 | Handle(Geom2d_Curve) C; |
723 | Standard_Integer i, aNbCurves; |
724 | IS >> aNbCurves; |
725 | IS.get();//remove <lf> |
726 | for (i = 1; i <= aNbCurves; i++) { |
727 | BinTools_Curve2dSet::ReadCurve2d(IS,C); |
728 | myMap.Add(C); |
729 | } |
730 | } |
731 | |
732 | |
733 | |