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