b311480e |
1 | // Created on: 1993-07-19 |
2 | // Created by: Remi LEQUETTE |
3 | // Copyright (c) 1993-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <Geom_BezierSurface.hxx> |
19 | #include <Geom_BSplineSurface.hxx> |
7fd59977 |
20 | #include <Geom_ConicalSurface.hxx> |
42cf5bc1 |
21 | #include <Geom_CylindricalSurface.hxx> |
22 | #include <Geom_OffsetSurface.hxx> |
23 | #include <Geom_Plane.hxx> |
24 | #include <Geom_RectangularTrimmedSurface.hxx> |
7fd59977 |
25 | #include <Geom_SphericalSurface.hxx> |
42cf5bc1 |
26 | #include <Geom_Surface.hxx> |
7fd59977 |
27 | #include <Geom_SurfaceOfLinearExtrusion.hxx> |
28 | #include <Geom_SurfaceOfRevolution.hxx> |
42cf5bc1 |
29 | #include <Geom_ToroidalSurface.hxx> |
30 | #include <GeomTools.hxx> |
31 | #include <GeomTools_CurveSet.hxx> |
32 | #include <GeomTools_SurfaceSet.hxx> |
33 | #include <GeomTools_UndefinedTypeHandler.hxx> |
7fd59977 |
34 | #include <gp_Cone.hxx> |
42cf5bc1 |
35 | #include <gp_Cylinder.hxx> |
36 | #include <gp_Pln.hxx> |
7fd59977 |
37 | #include <gp_Sphere.hxx> |
38 | #include <gp_Torus.hxx> |
7e785937 |
39 | #include <Message_ProgressScope.hxx> |
42cf5bc1 |
40 | #include <Standard_ErrorHandler.hxx> |
41 | #include <Standard_Failure.hxx> |
42 | #include <Standard_OutOfRange.hxx> |
43 | #include <Standard_Stream.hxx> |
7fd59977 |
44 | #include <TColgp_Array1OfPnt.hxx> |
7fd59977 |
45 | #include <TColgp_Array2OfPnt.hxx> |
42cf5bc1 |
46 | #include <TColStd_Array1OfInteger.hxx> |
47 | #include <TColStd_Array1OfReal.hxx> |
48 | #include <TColStd_Array2OfReal.hxx> |
7fd59977 |
49 | |
50 | #define PLANE 1 |
51 | #define CYLINDER 2 |
52 | #define CONE 3 |
53 | #define SPHERE 4 |
54 | #define TORUS 5 |
55 | #define LINEAREXTRUSION 6 |
56 | #define REVOLUTION 7 |
57 | #define BEZIER 8 |
58 | #define BSPLINE 9 |
59 | #define RECTANGULAR 10 |
60 | #define OFFSET 11 |
61 | |
62 | //======================================================================= |
63 | //function : GeomTools_SurfaceSet |
64 | //purpose : |
65 | //======================================================================= |
66 | |
67 | GeomTools_SurfaceSet::GeomTools_SurfaceSet() |
68 | { |
69 | } |
70 | |
71 | |
72 | //======================================================================= |
73 | //function : Clear |
74 | //purpose : |
75 | //======================================================================= |
76 | |
77 | void GeomTools_SurfaceSet::Clear() |
78 | { |
79 | myMap.Clear(); |
80 | } |
81 | |
82 | |
83 | //======================================================================= |
84 | //function : Add |
85 | //purpose : |
86 | //======================================================================= |
87 | |
88 | Standard_Integer GeomTools_SurfaceSet::Add(const Handle(Geom_Surface)& S) |
89 | { |
90 | return myMap.Add(S); |
91 | } |
92 | |
93 | |
94 | //======================================================================= |
95 | //function : Surface |
96 | //purpose : |
97 | //======================================================================= |
98 | |
99 | Handle(Geom_Surface) GeomTools_SurfaceSet::Surface |
100 | (const Standard_Integer I)const |
101 | { |
102 | if (I <= 0 || I > myMap.Extent()) |
103 | return Handle(Geom_Surface)(); |
104 | return Handle(Geom_Surface)::DownCast(myMap(I)); |
105 | } |
106 | |
107 | |
108 | //======================================================================= |
109 | //function : Index |
110 | //purpose : |
111 | //======================================================================= |
112 | |
113 | Standard_Integer GeomTools_SurfaceSet::Index |
114 | (const Handle(Geom_Surface)& S)const |
115 | { |
116 | return myMap.FindIndex(S); |
117 | } |
118 | |
119 | //======================================================================= |
120 | //function : Print |
121 | //purpose : |
122 | //======================================================================= |
123 | |
124 | static void Print(const gp_Pnt P, |
125 | Standard_OStream& OS, |
126 | const Standard_Boolean compact) |
127 | { |
128 | OS << P.X(); |
129 | if (!compact) OS << ","; |
130 | OS << " "; |
131 | OS << P.Y(); |
132 | if (!compact) OS << ","; |
133 | OS << " "; |
134 | OS << P.Z(); |
135 | OS << " "; |
136 | } |
137 | |
138 | //======================================================================= |
139 | //function : Print |
140 | //purpose : |
141 | //======================================================================= |
142 | |
143 | static void Print(const gp_Dir D, |
144 | Standard_OStream& OS, |
145 | const Standard_Boolean compact) |
146 | { |
147 | OS << D.X(); |
148 | if (!compact) OS << ","; |
149 | OS << " "; |
150 | OS << D.Y(); |
151 | if (!compact) OS << ","; |
152 | OS << " "; |
153 | OS << D.Z(); |
154 | OS << " "; |
155 | } |
156 | |
157 | //======================================================================= |
158 | //function : Print |
159 | //purpose : |
160 | //======================================================================= |
161 | |
162 | static void Print(const Handle(Geom_Plane)& S, |
163 | Standard_OStream& OS, |
164 | const Standard_Boolean compact) |
165 | { |
166 | if (compact) |
167 | OS << PLANE << " "; |
168 | else |
169 | OS << "Plane"; |
170 | |
171 | gp_Pln P = S->Pln(); |
172 | if (!compact) OS << "\n Origin :"; |
173 | Print(P.Location(),OS,compact); |
174 | if (!compact) OS << "\n Axis :"; |
175 | Print(P.Axis().Direction(),OS,compact); |
176 | if (!compact) OS << "\n XAxis :"; |
177 | Print(P.XAxis().Direction(),OS,compact); |
178 | if (!compact) OS << "\n YAxis :"; |
179 | Print(P.YAxis().Direction(),OS,compact); |
180 | OS << "\n"; |
181 | if (!compact) OS << "\n"; |
182 | } |
183 | |
184 | |
185 | //======================================================================= |
186 | //function : Print |
187 | //purpose : |
188 | //======================================================================= |
189 | |
190 | static void Print(const Handle(Geom_CylindricalSurface)& S, |
191 | Standard_OStream& OS, |
192 | const Standard_Boolean compact) |
193 | { |
194 | if (compact) |
195 | OS << CYLINDER << " "; |
196 | else |
197 | OS << "CylindricalSurface"; |
198 | |
199 | gp_Cylinder P = S->Cylinder(); |
200 | if (!compact) OS << "\n Origin :"; |
201 | Print(P.Location(),OS,compact); |
202 | if (!compact) OS << "\n Axis :"; |
203 | Print(P.Axis().Direction(),OS,compact); |
204 | if (!compact) OS << "\n XAxis :"; |
205 | Print(P.XAxis().Direction(),OS,compact); |
206 | if (!compact) OS << "\n YAxis :"; |
207 | Print(P.YAxis().Direction(),OS,compact); |
208 | if (!compact) OS << "\n Radius :"; |
209 | OS << P.Radius(); |
210 | OS << "\n"; |
211 | if (!compact) OS << "\n"; |
212 | } |
213 | |
214 | |
215 | //======================================================================= |
216 | //function : Print |
217 | //purpose : |
218 | //======================================================================= |
219 | |
220 | static void Print(const Handle(Geom_ConicalSurface)& S, |
221 | Standard_OStream& OS, |
222 | const Standard_Boolean compact) |
223 | { |
224 | if (compact) |
225 | OS << CONE << " "; |
226 | else |
227 | OS << "ConicalSurface"; |
228 | |
229 | gp_Cone P = S->Cone(); |
230 | if (!compact) OS << "\n Origin :"; |
231 | Print(P.Location(),OS,compact); |
232 | if (!compact) OS << "\n Axis :"; |
233 | Print(P.Axis().Direction(),OS,compact); |
234 | if (!compact) OS << "\n XAxis :"; |
235 | Print(P.XAxis().Direction(),OS,compact); |
236 | if (!compact) OS << "\n YAxis :"; |
237 | Print(P.YAxis().Direction(),OS,compact); |
238 | if (!compact) OS << "\n Radius :"; |
239 | OS << P.RefRadius(); |
240 | OS << "\n"; |
241 | if (!compact) OS << "\n Angle :"; |
242 | OS << P.SemiAngle(); |
243 | OS << "\n"; |
244 | if (!compact) OS << "\n"; |
245 | } |
246 | |
247 | |
248 | //======================================================================= |
249 | //function : Print |
250 | //purpose : |
251 | //======================================================================= |
252 | |
253 | static void Print(const Handle(Geom_SphericalSurface)& S, |
254 | Standard_OStream& OS, |
255 | const Standard_Boolean compact) |
256 | { |
257 | if (compact) |
258 | OS << SPHERE << " "; |
259 | else |
260 | OS << "SphericalSurface"; |
261 | |
262 | gp_Sphere P = S->Sphere(); |
263 | if (!compact) OS << "\n Center :"; |
264 | Print(P.Location(),OS,compact); |
265 | if (!compact) OS << "\n Axis :"; |
266 | Print(P.Position().Axis().Direction(),OS,compact); |
267 | if (!compact) OS << "\n XAxis :"; |
268 | Print(P.XAxis().Direction(),OS,compact); |
269 | if (!compact) OS << "\n YAxis :"; |
270 | Print(P.YAxis().Direction(),OS,compact); |
271 | if (!compact) OS << "\n Radius :"; |
272 | OS << P.Radius(); |
273 | OS << "\n"; |
274 | if (!compact) OS << "\n"; |
275 | } |
276 | |
277 | |
278 | //======================================================================= |
279 | //function : Print |
280 | //purpose : |
281 | //======================================================================= |
282 | |
283 | static void Print(const Handle(Geom_ToroidalSurface)& S, |
284 | Standard_OStream& OS, |
285 | const Standard_Boolean compact) |
286 | { |
287 | if (compact) |
288 | OS << TORUS << " "; |
289 | else |
290 | OS << "ToroidalSurface"; |
291 | |
292 | gp_Torus P = S->Torus(); |
293 | if (!compact) OS << "\n Origin :"; |
294 | Print(P.Location(),OS,compact); |
295 | if (!compact) OS << "\n Axis :"; |
296 | Print(P.Axis().Direction(),OS,compact); |
297 | if (!compact) OS << "\n XAxis :"; |
298 | Print(P.XAxis().Direction(),OS,compact); |
299 | if (!compact) OS << "\n YAxis :"; |
300 | Print(P.YAxis().Direction(),OS,compact); |
301 | if (!compact) OS << "\n Radii :"; |
302 | OS << P.MajorRadius() << " " << P.MinorRadius(); |
303 | OS << "\n"; |
304 | if (!compact) OS << "\n"; |
305 | } |
306 | |
307 | |
308 | //======================================================================= |
309 | //function : Print |
310 | //purpose : |
311 | //======================================================================= |
312 | |
313 | static void Print(const Handle(Geom_SurfaceOfLinearExtrusion)& S, |
314 | Standard_OStream& OS, |
315 | const Standard_Boolean compact) |
316 | { |
317 | if (compact) |
318 | OS << LINEAREXTRUSION << " "; |
319 | else |
320 | OS << "SurfaceOfLinearExtrusion"; |
321 | |
322 | if (!compact) OS << "\n Direction :"; |
323 | Print(S->Direction(),OS,compact); |
324 | if (!compact) OS << "\n Basis curve : "; |
325 | OS << "\n"; |
326 | GeomTools_CurveSet::PrintCurve(S->BasisCurve(),OS,compact); |
327 | } |
328 | |
329 | |
330 | //======================================================================= |
331 | //function : Print |
332 | //purpose : |
333 | //======================================================================= |
334 | |
335 | static void Print(const Handle(Geom_SurfaceOfRevolution)& S, |
336 | Standard_OStream& OS, |
337 | const Standard_Boolean compact) |
338 | { |
339 | if (compact) |
340 | OS << REVOLUTION <<" "; |
341 | else |
342 | OS << "SurfaceOfRevolution"; |
343 | |
344 | if (!compact) OS << "\n Origin :"; |
345 | Print(S->Location(),OS,compact); |
346 | if (!compact) OS << "\n Direction :"; |
347 | Print(S->Direction(),OS,compact); |
348 | if (!compact) OS << "\n Basis curve : "; |
349 | OS << "\n"; |
350 | GeomTools_CurveSet::PrintCurve(S->BasisCurve(),OS,compact); |
351 | } |
352 | |
353 | |
354 | //======================================================================= |
355 | //function : Print |
356 | //purpose : |
357 | //======================================================================= |
358 | |
359 | static void Print(const Handle(Geom_BezierSurface)& S, |
360 | Standard_OStream& OS, |
361 | const Standard_Boolean compact) |
362 | { |
363 | if (compact) |
364 | OS << BEZIER << " "; |
365 | else |
366 | OS << "BezierSurface"; |
367 | |
368 | |
369 | Standard_Boolean urational = S->IsURational(); |
370 | Standard_Boolean vrational = S->IsVRational(); |
371 | if (compact) |
372 | OS << (urational ? 1 : 0) << " "; |
373 | else { |
374 | if (urational) |
375 | OS << " urational"; |
376 | } |
377 | if (compact) |
378 | OS << (vrational ? 1 : 0) << " "; |
379 | else { |
380 | if (vrational) |
381 | OS << " vrational"; |
382 | } |
383 | |
384 | if (!compact) { |
385 | Standard_Boolean uclosed = S->IsUClosed(); |
386 | Standard_Boolean vclosed = S->IsVClosed(); |
387 | if (uclosed) |
388 | OS << " uclosed"; |
389 | if (vclosed) |
390 | OS << " vclosed"; |
391 | } |
392 | |
393 | // poles and weights |
394 | Standard_Integer i,j,udegree,vdegree; |
395 | udegree = S->UDegree(); |
396 | vdegree = S->VDegree(); |
397 | if (!compact) OS << "\n Degrees :"; |
398 | OS << udegree << " " << vdegree << " "; |
399 | |
400 | for (i = 1; i <= udegree+1; i++) { |
401 | for (j = 1; j <= vdegree+1; j++) { |
04232180 |
402 | if (!compact) OS << "\n "<<std::setw(2)<<i<<", "<<std::setw(2)<<j<<" : "; |
7fd59977 |
403 | Print(S->Pole(i,j),OS,compact); |
404 | if (urational || vrational) |
405 | OS << " " << S->Weight(i,j); |
406 | if (compact) |
407 | OS << " "; |
408 | } |
409 | OS << "\n"; |
410 | } |
411 | OS << "\n"; |
412 | if (!compact) OS << "\n"; |
413 | } |
414 | |
415 | |
416 | //======================================================================= |
417 | //function : Print |
418 | //purpose : |
419 | //======================================================================= |
420 | |
421 | static void Print(const Handle(Geom_BSplineSurface)& S, |
422 | Standard_OStream& OS, |
423 | const Standard_Boolean compact) |
424 | { |
425 | if (compact) |
426 | OS << BSPLINE << " "; |
427 | else |
428 | OS << "BSplineSurface"; |
429 | |
430 | Standard_Boolean urational = S->IsURational(); |
431 | Standard_Boolean vrational = S->IsVRational(); |
432 | if (compact) |
433 | OS << (urational ? 1 : 0) << " "; |
434 | else { |
435 | if (urational) |
436 | OS << " urational"; |
437 | } |
438 | if (compact) |
439 | OS << (vrational ? 1 : 0) << " "; |
440 | else { |
441 | if (vrational) |
442 | OS << " vrational"; |
443 | } |
444 | |
445 | Standard_Boolean uperiodic = S->IsUPeriodic(); |
446 | Standard_Boolean vperiodic = S->IsVPeriodic(); |
447 | if (compact) |
448 | OS << (uperiodic ? 1 : 0) << " "; |
449 | else { |
450 | if (uperiodic) |
451 | OS << " uperiodic"; |
452 | } |
453 | if (compact) |
454 | OS << (vperiodic ? 1 : 0) << " "; |
455 | else { |
456 | if (vperiodic) |
457 | OS << " vperiodic"; |
458 | } |
459 | |
460 | if (!compact) { |
461 | Standard_Boolean uclosed = S->IsUClosed(); |
462 | Standard_Boolean vclosed = S->IsVClosed(); |
463 | if (uclosed) |
464 | OS << " uclosed"; |
465 | if (vclosed) |
466 | OS << " vclosed"; |
467 | } |
468 | |
469 | |
470 | // poles and weights |
471 | Standard_Integer i,j,udegree,vdegree,nbupoles,nbvpoles,nbuknots,nbvknots; |
472 | udegree = S->UDegree(); |
473 | vdegree = S->VDegree(); |
474 | nbupoles = S->NbUPoles(); |
475 | nbvpoles = S->NbVPoles(); |
476 | nbuknots = S->NbUKnots(); |
477 | nbvknots = S->NbVKnots(); |
478 | if (!compact) OS << "\n Degrees :"; |
479 | OS << udegree << " " << vdegree << " "; |
480 | if (!compact) OS << "\n NbPoles :"; |
481 | OS << nbupoles << " " << nbvpoles << " "; |
482 | if (!compact) OS << "\n NbKnots :"; |
483 | OS << nbuknots << " " << nbvknots << " "; |
484 | |
485 | if (!compact) OS << "\n Poles :\n"; |
486 | for (i = 1; i <= nbupoles; i++) { |
487 | for (j = 1; j <= nbvpoles; j++) { |
04232180 |
488 | if (!compact) OS << "\n "<<std::setw(2)<<i<<", "<<std::setw(2)<<j<<" : "; |
7fd59977 |
489 | Print(S->Pole(i,j),OS,compact); |
490 | if (urational || vrational) |
491 | OS << " " << S->Weight(i,j); |
492 | if (compact) |
493 | OS << " "; |
494 | } |
495 | OS << "\n"; |
496 | } |
497 | OS << "\n"; |
498 | if (!compact) OS << "\n UKnots :\n"; |
499 | for (i = 1; i <= nbuknots; i++) { |
04232180 |
500 | if (!compact) OS << "\n "<<std::setw(2)<<i<<" : "; |
7fd59977 |
501 | OS << S->UKnot(i) << " " << S->UMultiplicity(i) <<"\n"; |
502 | } |
503 | OS << "\n"; |
504 | if (!compact) OS << "\n VKnots :\n"; |
505 | for (i = 1; i <= nbvknots; i++) { |
04232180 |
506 | if (!compact) OS << "\n "<<std::setw(2)<<i<<" : "; |
7fd59977 |
507 | OS << S->VKnot(i) << " " << S->VMultiplicity(i) <<"\n"; |
508 | } |
509 | OS << "\n"; |
510 | if (!compact) OS << "\n"; |
511 | } |
512 | |
513 | |
514 | //======================================================================= |
515 | //function : Print |
516 | //purpose : |
517 | //======================================================================= |
518 | |
519 | static void Print(const Handle(Geom_RectangularTrimmedSurface)& S, |
520 | Standard_OStream& OS, |
521 | const Standard_Boolean compact) |
522 | { |
523 | if (compact) |
524 | OS << RECTANGULAR << " "; |
525 | else |
526 | OS << "RectangularTrimmedSurface"; |
527 | |
528 | Standard_Real U1,U2,V1,V2; |
529 | S->Bounds(U1,U2,V1,V2); |
530 | if (!compact) OS << "\nParameters : "; |
531 | OS << U1 << " " << U2 << " " << V1 << " " << V2 <<"\n"; |
532 | if (!compact) OS << "BasisSurface :\n"; |
533 | GeomTools_SurfaceSet::PrintSurface(S->BasisSurface(),OS,compact); |
534 | } |
535 | |
536 | |
537 | //======================================================================= |
538 | //function : Print |
539 | //purpose : |
540 | //======================================================================= |
541 | |
542 | static void Print(const Handle(Geom_OffsetSurface)& S, |
543 | Standard_OStream& OS, |
544 | const Standard_Boolean compact) |
545 | { |
546 | if (compact) |
547 | OS << OFFSET << " "; |
548 | else |
549 | OS << "OffsetSurface"; |
550 | |
551 | if (!compact) OS << "\nOffset : "; |
552 | OS << S->Offset() <<"\n"; |
553 | if (!compact) OS << "BasisSurface :\n"; |
554 | GeomTools_SurfaceSet::PrintSurface(S->BasisSurface(),OS,compact); |
555 | } |
556 | |
557 | |
558 | //======================================================================= |
559 | //function : PrintSurface |
560 | //purpose : |
561 | //======================================================================= |
562 | |
563 | void GeomTools_SurfaceSet::PrintSurface(const Handle(Geom_Surface)& S, |
564 | Standard_OStream& OS, |
565 | const Standard_Boolean compact) |
566 | { |
567 | Handle(Standard_Type) TheType = S->DynamicType(); |
568 | |
569 | if ( TheType == STANDARD_TYPE(Geom_Plane)) { |
570 | Print(Handle(Geom_Plane)::DownCast(S),OS,compact); |
571 | } |
572 | else if ( TheType == STANDARD_TYPE(Geom_CylindricalSurface)) { |
573 | Print(Handle(Geom_CylindricalSurface)::DownCast(S),OS,compact); |
574 | } |
575 | else if ( TheType == STANDARD_TYPE(Geom_ConicalSurface)) { |
576 | Print(Handle(Geom_ConicalSurface)::DownCast(S),OS,compact); |
577 | } |
578 | else if ( TheType == STANDARD_TYPE(Geom_SphericalSurface)) { |
579 | Print(Handle(Geom_SphericalSurface)::DownCast(S),OS,compact); |
580 | } |
581 | else if ( TheType == STANDARD_TYPE(Geom_ToroidalSurface)) { |
582 | Print(Handle(Geom_ToroidalSurface)::DownCast(S),OS,compact); |
583 | } |
584 | else if ( TheType == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion)) { |
585 | Print(Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(S),OS,compact); |
586 | } |
587 | else if ( TheType == STANDARD_TYPE(Geom_SurfaceOfRevolution)) { |
588 | Print(Handle(Geom_SurfaceOfRevolution)::DownCast(S),OS,compact); |
589 | } |
590 | else if ( TheType == STANDARD_TYPE(Geom_BezierSurface)) { |
591 | Print(Handle(Geom_BezierSurface)::DownCast(S),OS,compact); |
592 | } |
593 | else if ( TheType == STANDARD_TYPE(Geom_BSplineSurface)) { |
594 | Print(Handle(Geom_BSplineSurface)::DownCast(S),OS,compact); |
595 | } |
596 | else if ( TheType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { |
597 | Print(Handle(Geom_RectangularTrimmedSurface)::DownCast(S),OS,compact); |
598 | } |
599 | else if ( TheType == STANDARD_TYPE(Geom_OffsetSurface)) { |
600 | Print(Handle(Geom_OffsetSurface)::DownCast(S),OS,compact); |
601 | } |
602 | else { |
603 | GeomTools::GetUndefinedTypeHandler()->PrintSurface(S,OS,compact); |
604 | //if (!compact) |
605 | // OS << "***** Unknown Surface ********\n"; |
606 | //else |
04232180 |
607 | // std::cout << "***** Unknown Surface ********"<<std::endl; |
7fd59977 |
608 | } |
609 | } |
610 | |
611 | //======================================================================= |
612 | //function : Dump |
613 | //purpose : |
614 | //======================================================================= |
615 | |
616 | void GeomTools_SurfaceSet::Dump(Standard_OStream& OS)const |
617 | { |
618 | Standard_Integer i, nbsurf = myMap.Extent(); |
619 | OS << "\n -------\n"; |
620 | OS << "Dump of "<< nbsurf << " surfaces "; |
621 | OS << "\n -------\n\n"; |
622 | |
623 | for (i = 1; i <= nbsurf; i++) { |
04232180 |
624 | OS << std::setw(4) << i << " : "; |
7fd59977 |
625 | PrintSurface(Handle(Geom_Surface)::DownCast(myMap(i)),OS,Standard_False); |
626 | } |
627 | } |
628 | |
629 | |
630 | //======================================================================= |
631 | //function : Write |
632 | //purpose : |
633 | //======================================================================= |
634 | |
7e785937 |
635 | void GeomTools_SurfaceSet::Write(Standard_OStream& OS, const Message_ProgressRange& theProgress)const |
7fd59977 |
636 | { |
60be1f9b |
637 | std::streamsize prec = OS.precision(17); |
7fd59977 |
638 | |
639 | Standard_Integer i, nbsurf = myMap.Extent(); |
640 | OS << "Surfaces "<< nbsurf << "\n"; |
7e785937 |
641 | Message_ProgressScope aPS(theProgress, "Surfaces", nbsurf); |
642 | for (i = 1; i <= nbsurf && aPS.More(); i++, aPS.Next()) { |
7fd59977 |
643 | PrintSurface(Handle(Geom_Surface)::DownCast(myMap(i)),OS,Standard_True); |
644 | } |
7fd59977 |
645 | OS.precision(prec); |
646 | } |
647 | |
648 | |
649 | //======================================================================= |
650 | //function : ReadPnt |
651 | //purpose : |
652 | //======================================================================= |
653 | |
654 | static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt& P) |
655 | { |
656 | Standard_Real X=0.,Y=0.,Z=0.; |
71598a83 |
657 | GeomTools::GetReal(IS, X); |
658 | GeomTools::GetReal(IS, Y); |
659 | GeomTools::GetReal(IS, Z); |
7fd59977 |
660 | P.SetCoord(X,Y,Z); |
661 | return IS; |
662 | } |
663 | |
664 | //======================================================================= |
665 | //function : ReadDir |
666 | //purpose : |
667 | //======================================================================= |
668 | |
669 | static Standard_IStream& operator>>(Standard_IStream& IS, gp_Dir& D) |
670 | { |
671 | Standard_Real X=0.,Y=0.,Z=0.; |
71598a83 |
672 | GeomTools::GetReal(IS, X); |
673 | GeomTools::GetReal(IS, Y); |
674 | GeomTools::GetReal(IS, Z); |
7fd59977 |
675 | D.SetCoord(X,Y,Z); |
676 | return IS; |
677 | } |
678 | |
679 | //======================================================================= |
680 | //function : ReadAx3 |
681 | //purpose : |
682 | //======================================================================= |
683 | |
684 | static Standard_IStream& operator>>(Standard_IStream& IS, gp_Ax3& A3) |
685 | { |
686 | gp_Pnt P(0.,0.,0.); |
687 | gp_Dir A(1.,0.,0.),AX(1.,0.,0.),AY(1.,0.,0.); |
688 | IS >> P >> A >> AX >> AY; |
689 | gp_Ax3 ax3(P,A,AX); |
690 | if (AY.DotCross(A,AX) < 0) |
691 | ax3.YReverse(); |
692 | A3 = ax3; |
693 | return IS; |
694 | } |
695 | |
696 | |
697 | //======================================================================= |
698 | //function : operator>> |
699 | //purpose : |
700 | //======================================================================= |
701 | |
702 | static Standard_IStream& operator>>(Standard_IStream& IS, |
703 | Handle(Geom_Plane)& S) |
704 | { |
705 | gp_Ax3 A; |
706 | IS >> A; |
707 | S = new Geom_Plane(A); |
708 | return IS; |
709 | } |
710 | |
711 | //======================================================================= |
712 | //function : operator>> |
713 | //purpose : |
714 | //======================================================================= |
715 | |
716 | static Standard_IStream& operator>>(Standard_IStream& IS, |
717 | Handle(Geom_CylindricalSurface)& S) |
718 | { |
719 | gp_Ax3 A; |
720 | Standard_Real R=0.; |
71598a83 |
721 | IS >> A; |
722 | GeomTools::GetReal(IS, R); |
7fd59977 |
723 | S = new Geom_CylindricalSurface(A,R); |
724 | return IS; |
725 | } |
726 | |
727 | //======================================================================= |
728 | //function : operator>> |
729 | //purpose : |
730 | //======================================================================= |
731 | |
732 | static Standard_IStream& operator>>(Standard_IStream& IS, |
733 | Handle(Geom_ConicalSurface)& S) |
734 | { |
735 | gp_Ax3 A; |
736 | Standard_Real R=0.,Ang=0.; |
71598a83 |
737 | IS >> A; |
738 | GeomTools::GetReal(IS, R); |
739 | GeomTools::GetReal(IS, Ang); |
7fd59977 |
740 | S = new Geom_ConicalSurface(A,Ang,R); |
741 | return IS; |
742 | } |
743 | |
744 | //======================================================================= |
745 | //function : operator>> |
746 | //purpose : |
747 | //======================================================================= |
748 | |
749 | static Standard_IStream& operator>>(Standard_IStream& IS, |
750 | Handle(Geom_SphericalSurface)& S) |
751 | { |
752 | gp_Ax3 A; |
753 | Standard_Real R=0.; |
71598a83 |
754 | IS >> A; |
755 | GeomTools::GetReal(IS, R); |
7fd59977 |
756 | S = new Geom_SphericalSurface(A,R); |
757 | return IS; |
758 | } |
759 | |
760 | //======================================================================= |
761 | //function : operator>> |
762 | //purpose : |
763 | //======================================================================= |
764 | |
765 | static Standard_IStream& operator>>(Standard_IStream& IS, |
766 | Handle(Geom_ToroidalSurface)& S) |
767 | { |
768 | gp_Ax3 A; |
769 | Standard_Real R1=0.,R2=0.; |
71598a83 |
770 | IS >> A; |
771 | GeomTools::GetReal(IS, R1); |
772 | GeomTools::GetReal(IS, R2); |
7fd59977 |
773 | S = new Geom_ToroidalSurface(A,R1,R2); |
774 | return IS; |
775 | } |
776 | |
777 | //======================================================================= |
778 | //function : operator>> |
779 | //purpose : |
780 | //======================================================================= |
781 | |
782 | static Standard_IStream& operator>>(Standard_IStream& IS, |
783 | Handle(Geom_SurfaceOfLinearExtrusion)& S) |
784 | { |
785 | gp_Dir D(1.,0.,0.); |
7fd59977 |
786 | IS >> D; |
aa00364d |
787 | Handle(Geom_Curve) C = GeomTools_CurveSet::ReadCurve(IS); |
7fd59977 |
788 | S = new Geom_SurfaceOfLinearExtrusion(C,D); |
789 | return IS; |
790 | } |
791 | |
792 | //======================================================================= |
793 | //function : operator>> |
794 | //purpose : |
795 | //======================================================================= |
796 | |
797 | static Standard_IStream& operator>>(Standard_IStream& IS, |
798 | Handle(Geom_SurfaceOfRevolution)& S) |
799 | { |
800 | gp_Pnt P(0.,0.,0.); |
801 | gp_Dir D(1.,0.,0.); |
7fd59977 |
802 | IS >> P >> D; |
aa00364d |
803 | Handle(Geom_Curve) C = GeomTools_CurveSet::ReadCurve(IS); |
7fd59977 |
804 | S = new Geom_SurfaceOfRevolution(C,gp_Ax1(P,D)); |
805 | return IS; |
806 | } |
807 | |
808 | //======================================================================= |
809 | //function : operator>> |
810 | //purpose : |
811 | //======================================================================= |
812 | |
813 | static Standard_IStream& operator>>(Standard_IStream& IS, |
814 | Handle(Geom_BezierSurface)& S) |
815 | { |
816 | Standard_Boolean urational=Standard_False, vrational=Standard_False; |
817 | IS >> urational >> vrational; |
818 | Standard_Integer udegree=0, vdegree=0; |
819 | IS >> udegree >> vdegree; |
820 | TColgp_Array2OfPnt poles(1,udegree+1,1,vdegree+1); |
821 | TColStd_Array2OfReal weights(1,udegree+1,1,vdegree+1); |
822 | |
823 | Standard_Integer i,j; |
824 | for (i = 1; i <= udegree+1; i++) { |
825 | for (j = 1; j <= vdegree+1; j++) { |
826 | IS >> poles(i,j); |
827 | if (urational || vrational) |
71598a83 |
828 | GeomTools::GetReal(IS, weights(i,j)); |
7fd59977 |
829 | } |
830 | } |
831 | |
832 | if (urational || vrational) |
833 | S = new Geom_BezierSurface(poles,weights); |
834 | else |
835 | S = new Geom_BezierSurface(poles); |
836 | return IS; |
837 | } |
838 | |
839 | //======================================================================= |
840 | //function : operator>> |
841 | //purpose : |
842 | //======================================================================= |
843 | |
844 | static Standard_IStream& operator>>(Standard_IStream& IS, |
845 | Handle(Geom_BSplineSurface)& S) |
846 | { |
847 | Standard_Boolean urational=Standard_False, vrational=Standard_False, |
848 | uperiodic=Standard_False, vperiodic=Standard_False; |
849 | IS >> urational >> vrational; |
850 | IS >> uperiodic >> vperiodic; |
851 | Standard_Integer udegree=0, vdegree=0,nbupoles=0,nbvpoles=0,nbuknots=0,nbvknots=0; |
852 | IS >> udegree >> vdegree; |
853 | IS >> nbupoles >> nbvpoles; |
854 | IS >> nbuknots >> nbvknots; |
855 | |
856 | TColgp_Array2OfPnt poles(1,nbupoles,1,nbvpoles); |
857 | TColStd_Array2OfReal weights(1,nbupoles,1,nbvpoles); |
858 | |
859 | Standard_Integer i,j; |
860 | for (i = 1; i <= nbupoles; i++) { |
861 | for (j = 1; j <= nbvpoles; j++) { |
862 | IS >> poles(i,j); |
863 | if (urational || vrational) |
71598a83 |
864 | GeomTools::GetReal(IS, weights(i,j)); |
7fd59977 |
865 | } |
866 | } |
867 | |
868 | TColStd_Array1OfReal uknots(1,nbuknots); |
869 | TColStd_Array1OfInteger umults(1,nbuknots); |
870 | for (i = 1; i <= nbuknots; i++) { |
71598a83 |
871 | GeomTools::GetReal(IS, uknots(i)); |
872 | IS >> umults(i); |
7fd59977 |
873 | } |
874 | |
875 | TColStd_Array1OfReal vknots(1,nbvknots); |
876 | TColStd_Array1OfInteger vmults(1,nbvknots); |
877 | for (i = 1; i <= nbvknots; i++) { |
71598a83 |
878 | GeomTools::GetReal(IS, vknots(i)); |
879 | IS >> vmults(i); |
7fd59977 |
880 | } |
881 | |
882 | if (urational || vrational) |
883 | S = new Geom_BSplineSurface(poles,weights,uknots,vknots,umults,vmults, |
884 | udegree,vdegree,uperiodic,vperiodic); |
885 | else |
886 | S = new Geom_BSplineSurface(poles,uknots,vknots,umults,vmults, |
887 | udegree,vdegree,uperiodic,vperiodic); |
888 | return IS; |
889 | } |
890 | |
891 | //======================================================================= |
892 | //function : operator>> |
893 | //purpose : |
894 | //======================================================================= |
895 | |
896 | static Standard_IStream& operator>>(Standard_IStream& IS, |
897 | Handle(Geom_RectangularTrimmedSurface)& S) |
898 | { |
899 | Standard_Real U1=0.,U2=0.,V1=0.,V2=0.; |
71598a83 |
900 | GeomTools::GetReal(IS, U1); |
901 | GeomTools::GetReal(IS, U2); |
902 | GeomTools::GetReal(IS, V1); |
903 | GeomTools::GetReal(IS, V2); |
aa00364d |
904 | Handle(Geom_Surface) BS = GeomTools_SurfaceSet::ReadSurface(IS); |
7fd59977 |
905 | S = new Geom_RectangularTrimmedSurface(BS,U1,U2,V1,V2); |
906 | return IS; |
907 | } |
908 | |
909 | //======================================================================= |
910 | //function : operator>> |
911 | //purpose : |
912 | //======================================================================= |
913 | |
914 | static Standard_IStream& operator>>(Standard_IStream& IS, |
915 | Handle(Geom_OffsetSurface)& S) |
916 | { |
917 | Standard_Real O=0.; |
71598a83 |
918 | GeomTools::GetReal(IS, O); |
aa00364d |
919 | Handle(Geom_Surface) BS = GeomTools_SurfaceSet::ReadSurface(IS); |
9f4cd8eb |
920 | S = new Geom_OffsetSurface(BS,O,Standard_True); |
7fd59977 |
921 | return IS; |
922 | } |
923 | |
924 | |
925 | //======================================================================= |
926 | //function : ReadSurface |
927 | //purpose : |
928 | //======================================================================= |
929 | |
6d8f9f4a |
930 | Handle(Geom_Surface) GeomTools_SurfaceSet::ReadSurface (Standard_IStream& IS) |
7fd59977 |
931 | { |
932 | Standard_Integer stype; |
933 | |
aa00364d |
934 | Handle(Geom_Surface) S; |
7fd59977 |
935 | try { |
936 | OCC_CATCH_SIGNALS |
937 | IS >> stype; |
938 | switch (stype) { |
939 | |
940 | case PLANE : |
941 | { |
942 | Handle(Geom_Plane) SS; |
943 | IS >> SS; |
944 | S = SS; |
945 | } |
946 | break; |
947 | |
948 | case CYLINDER : |
949 | { |
950 | Handle(Geom_CylindricalSurface) SS; |
951 | IS >> SS; |
952 | S = SS; |
953 | } |
954 | break; |
955 | |
956 | case CONE : |
957 | { |
958 | Handle(Geom_ConicalSurface) SS; |
959 | IS >> SS; |
960 | S = SS; |
961 | } |
962 | break; |
963 | |
964 | case SPHERE : |
965 | { |
966 | Handle(Geom_SphericalSurface) SS; |
967 | IS >> SS; |
968 | S = SS; |
969 | } |
970 | break; |
971 | |
972 | case TORUS : |
973 | { |
974 | Handle(Geom_ToroidalSurface) SS; |
975 | IS >> SS; |
976 | S = SS; |
977 | } |
978 | break; |
979 | |
980 | case LINEAREXTRUSION : |
981 | { |
982 | Handle(Geom_SurfaceOfLinearExtrusion) SS; |
983 | IS >> SS; |
984 | S = SS; |
985 | } |
986 | break; |
987 | |
988 | case REVOLUTION : |
989 | { |
990 | Handle(Geom_SurfaceOfRevolution) SS; |
991 | IS >> SS; |
992 | S = SS; |
993 | } |
994 | break; |
995 | |
996 | case BEZIER : |
997 | { |
998 | Handle(Geom_BezierSurface) SS; |
999 | IS >> SS; |
1000 | S = SS; |
1001 | } |
1002 | break; |
1003 | |
1004 | case BSPLINE : |
1005 | { |
1006 | Handle(Geom_BSplineSurface) SS; |
1007 | IS >> SS; |
1008 | S = SS; |
1009 | } |
1010 | break; |
1011 | |
1012 | case RECTANGULAR : |
1013 | { |
1014 | Handle(Geom_RectangularTrimmedSurface) SS; |
1015 | IS >> SS; |
1016 | S = SS; |
1017 | } |
1018 | break; |
1019 | |
1020 | case OFFSET : |
1021 | { |
1022 | Handle(Geom_OffsetSurface) SS; |
1023 | IS >> SS; |
1024 | S = SS; |
1025 | } |
1026 | break; |
1027 | |
1028 | default : |
1029 | { |
1030 | Handle(Geom_Surface) SS; |
1031 | GeomTools::GetUndefinedTypeHandler()->ReadSurface(stype,IS,SS); |
1032 | S = SS; |
1033 | } |
1034 | break; |
1035 | } |
1036 | } |
9775fa61 |
1037 | catch(Standard_Failure const& anException) { |
0797d9d3 |
1038 | #ifdef OCCT_DEBUG |
04232180 |
1039 | std::cout <<"EXCEPTION in GeomTools_SurfaceSet::ReadSurface(..)!!!" << std::endl; |
1040 | std::cout << anException << std::endl; |
7fd59977 |
1041 | #endif |
9775fa61 |
1042 | (void)anException; |
7fd59977 |
1043 | } |
aa00364d |
1044 | return S; |
7fd59977 |
1045 | } |
1046 | |
1047 | //======================================================================= |
1048 | //function : Read |
1049 | //purpose : |
1050 | //======================================================================= |
1051 | |
7e785937 |
1052 | void GeomTools_SurfaceSet::Read(Standard_IStream& IS, const Message_ProgressRange& theProgress) |
7fd59977 |
1053 | { |
1054 | char buffer[255]; |
1055 | IS >> buffer; |
1056 | if (strcmp(buffer,"Surfaces")) { |
04232180 |
1057 | std::cout << "Not a surface table"<<std::endl; |
7fd59977 |
1058 | return; |
1059 | } |
1060 | |
7fd59977 |
1061 | Standard_Integer i, nbsurf; |
1062 | IS >> nbsurf; |
7e785937 |
1063 | Message_ProgressScope aPS(theProgress, "Surfaces", nbsurf); |
1064 | for (i = 1; i <= nbsurf && aPS.More(); i++, aPS.Next()) { |
aa00364d |
1065 | Handle(Geom_Surface) S = GeomTools_SurfaceSet::ReadSurface (IS); |
7fd59977 |
1066 | myMap.Add(S); |
1067 | } |
1068 | } |