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