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