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