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