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 | |
17 | #include <Standard_Stream.hxx> |
18 | #include <GeomTools_SurfaceSet.ixx> |
19 | #include <GeomTools.hxx> |
20 | #include <GeomTools_UndefinedTypeHandler.hxx> |
21 | |
22 | #include <GeomTools_CurveSet.hxx> |
23 | #include <Geom_Plane.hxx> |
24 | #include <Geom_CylindricalSurface.hxx> |
25 | #include <Geom_ConicalSurface.hxx> |
26 | #include <Geom_SphericalSurface.hxx> |
27 | #include <Geom_ToroidalSurface.hxx> |
28 | #include <Geom_SurfaceOfLinearExtrusion.hxx> |
29 | #include <Geom_SurfaceOfRevolution.hxx> |
30 | #include <Geom_BezierSurface.hxx> |
31 | #include <Geom_BSplineSurface.hxx> |
32 | #include <Geom_RectangularTrimmedSurface.hxx> |
33 | #include <Geom_OffsetSurface.hxx> |
34 | |
35 | #include <gp_Pln.hxx> |
36 | #include <gp_Cylinder.hxx> |
37 | #include <gp_Cone.hxx> |
38 | #include <gp_Sphere.hxx> |
39 | #include <gp_Torus.hxx> |
40 | |
41 | #include <TColStd_Array1OfReal.hxx> |
42 | #include <TColStd_Array1OfInteger.hxx> |
43 | #include <TColgp_Array1OfPnt.hxx> |
44 | #include <TColStd_Array2OfReal.hxx> |
45 | #include <TColgp_Array2OfPnt.hxx> |
46 | #include <Standard_Failure.hxx> |
47 | #include <Standard_ErrorHandler.hxx> |
48 | #include <Message_ProgressSentry.hxx> |
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++) { |
402 | if (!compact) OS << "\n "<<setw(2)<<i<<", "<<setw(2)<<j<<" : "; |
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++) { |
488 | if (!compact) OS << "\n "<<setw(2)<<i<<", "<<setw(2)<<j<<" : "; |
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++) { |
500 | if (!compact) OS << "\n "<<setw(2)<<i<<" : "; |
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++) { |
506 | if (!compact) OS << "\n "<<setw(2)<<i<<" : "; |
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 |
607 | // cout << "***** Unknown Surface ********"<<endl; |
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++) { |
624 | OS << setw(4) << i << " : "; |
625 | PrintSurface(Handle(Geom_Surface)::DownCast(myMap(i)),OS,Standard_False); |
626 | } |
627 | } |
628 | |
629 | |
630 | //======================================================================= |
631 | //function : Write |
632 | //purpose : |
633 | //======================================================================= |
634 | |
635 | void GeomTools_SurfaceSet::Write(Standard_OStream& OS)const |
636 | { |
60be1f9b |
637 | std::streamsize prec = OS.precision(17); |
7fd59977 |
638 | |
639 | Standard_Integer i, nbsurf = myMap.Extent(); |
640 | OS << "Surfaces "<< nbsurf << "\n"; |
641 | //OCC19559 |
642 | Handle(Message_ProgressIndicator) progress = GetProgress(); |
643 | Message_ProgressSentry PS(progress, "Surfaces", 0, nbsurf, 1); |
644 | |
645 | for (i = 1; i <= nbsurf && PS.More(); i++, PS.Next()) { |
646 | if ( !progress.IsNull() ) |
647 | progress->Show(); |
648 | |
649 | PrintSurface(Handle(Geom_Surface)::DownCast(myMap(i)),OS,Standard_True); |
650 | } |
651 | |
652 | OS.precision(prec); |
653 | } |
654 | |
655 | |
656 | //======================================================================= |
657 | //function : ReadPnt |
658 | //purpose : |
659 | //======================================================================= |
660 | |
661 | static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt& P) |
662 | { |
663 | Standard_Real X=0.,Y=0.,Z=0.; |
664 | IS >> X >> Y >> Z; |
665 | P.SetCoord(X,Y,Z); |
666 | return IS; |
667 | } |
668 | |
669 | //======================================================================= |
670 | //function : ReadDir |
671 | //purpose : |
672 | //======================================================================= |
673 | |
674 | static Standard_IStream& operator>>(Standard_IStream& IS, gp_Dir& D) |
675 | { |
676 | Standard_Real X=0.,Y=0.,Z=0.; |
677 | IS >> X >> Y >> Z; |
678 | D.SetCoord(X,Y,Z); |
679 | return IS; |
680 | } |
681 | |
682 | //======================================================================= |
683 | //function : ReadAx3 |
684 | //purpose : |
685 | //======================================================================= |
686 | |
687 | static Standard_IStream& operator>>(Standard_IStream& IS, gp_Ax3& A3) |
688 | { |
689 | gp_Pnt P(0.,0.,0.); |
690 | gp_Dir A(1.,0.,0.),AX(1.,0.,0.),AY(1.,0.,0.); |
691 | IS >> P >> A >> AX >> AY; |
692 | gp_Ax3 ax3(P,A,AX); |
693 | if (AY.DotCross(A,AX) < 0) |
694 | ax3.YReverse(); |
695 | A3 = ax3; |
696 | return IS; |
697 | } |
698 | |
699 | |
700 | //======================================================================= |
701 | //function : operator>> |
702 | //purpose : |
703 | //======================================================================= |
704 | |
705 | static Standard_IStream& operator>>(Standard_IStream& IS, |
706 | Handle(Geom_Plane)& S) |
707 | { |
708 | gp_Ax3 A; |
709 | IS >> A; |
710 | S = new Geom_Plane(A); |
711 | return IS; |
712 | } |
713 | |
714 | //======================================================================= |
715 | //function : operator>> |
716 | //purpose : |
717 | //======================================================================= |
718 | |
719 | static Standard_IStream& operator>>(Standard_IStream& IS, |
720 | Handle(Geom_CylindricalSurface)& S) |
721 | { |
722 | gp_Ax3 A; |
723 | Standard_Real R=0.; |
724 | IS >> A >> R; |
725 | S = new Geom_CylindricalSurface(A,R); |
726 | return IS; |
727 | } |
728 | |
729 | //======================================================================= |
730 | //function : operator>> |
731 | //purpose : |
732 | //======================================================================= |
733 | |
734 | static Standard_IStream& operator>>(Standard_IStream& IS, |
735 | Handle(Geom_ConicalSurface)& S) |
736 | { |
737 | gp_Ax3 A; |
738 | Standard_Real R=0.,Ang=0.; |
739 | IS >> A >> R >> Ang; |
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.; |
754 | IS >> A >> R; |
755 | S = new Geom_SphericalSurface(A,R); |
756 | return IS; |
757 | } |
758 | |
759 | //======================================================================= |
760 | //function : operator>> |
761 | //purpose : |
762 | //======================================================================= |
763 | |
764 | static Standard_IStream& operator>>(Standard_IStream& IS, |
765 | Handle(Geom_ToroidalSurface)& S) |
766 | { |
767 | gp_Ax3 A; |
768 | Standard_Real R1=0.,R2=0.; |
769 | IS >> A >> R1 >> R2; |
770 | S = new Geom_ToroidalSurface(A,R1,R2); |
771 | return IS; |
772 | } |
773 | |
774 | //======================================================================= |
775 | //function : operator>> |
776 | //purpose : |
777 | //======================================================================= |
778 | |
779 | static Standard_IStream& operator>>(Standard_IStream& IS, |
780 | Handle(Geom_SurfaceOfLinearExtrusion)& S) |
781 | { |
782 | gp_Dir D(1.,0.,0.); |
783 | Handle(Geom_Curve) C; |
784 | IS >> D; |
785 | GeomTools_CurveSet::ReadCurve(IS,C); |
786 | S = new Geom_SurfaceOfLinearExtrusion(C,D); |
787 | return IS; |
788 | } |
789 | |
790 | //======================================================================= |
791 | //function : operator>> |
792 | //purpose : |
793 | //======================================================================= |
794 | |
795 | static Standard_IStream& operator>>(Standard_IStream& IS, |
796 | Handle(Geom_SurfaceOfRevolution)& S) |
797 | { |
798 | gp_Pnt P(0.,0.,0.); |
799 | gp_Dir D(1.,0.,0.); |
800 | Handle(Geom_Curve) C; |
801 | IS >> P >> D; |
802 | GeomTools_CurveSet::ReadCurve(IS,C); |
803 | S = new Geom_SurfaceOfRevolution(C,gp_Ax1(P,D)); |
804 | return IS; |
805 | } |
806 | |
807 | //======================================================================= |
808 | //function : operator>> |
809 | //purpose : |
810 | //======================================================================= |
811 | |
812 | static Standard_IStream& operator>>(Standard_IStream& IS, |
813 | Handle(Geom_BezierSurface)& S) |
814 | { |
815 | Standard_Boolean urational=Standard_False, vrational=Standard_False; |
816 | IS >> urational >> vrational; |
817 | Standard_Integer udegree=0, vdegree=0; |
818 | IS >> udegree >> vdegree; |
819 | TColgp_Array2OfPnt poles(1,udegree+1,1,vdegree+1); |
820 | TColStd_Array2OfReal weights(1,udegree+1,1,vdegree+1); |
821 | |
822 | Standard_Integer i,j; |
823 | for (i = 1; i <= udegree+1; i++) { |
824 | for (j = 1; j <= vdegree+1; j++) { |
825 | IS >> poles(i,j); |
826 | if (urational || vrational) |
827 | IS >> weights(i,j); |
828 | } |
829 | } |
830 | |
831 | if (urational || vrational) |
832 | S = new Geom_BezierSurface(poles,weights); |
833 | else |
834 | S = new Geom_BezierSurface(poles); |
835 | return IS; |
836 | } |
837 | |
838 | //======================================================================= |
839 | //function : operator>> |
840 | //purpose : |
841 | //======================================================================= |
842 | |
843 | static Standard_IStream& operator>>(Standard_IStream& IS, |
844 | Handle(Geom_BSplineSurface)& S) |
845 | { |
846 | Standard_Boolean urational=Standard_False, vrational=Standard_False, |
847 | uperiodic=Standard_False, vperiodic=Standard_False; |
848 | IS >> urational >> vrational; |
849 | IS >> uperiodic >> vperiodic; |
850 | Standard_Integer udegree=0, vdegree=0,nbupoles=0,nbvpoles=0,nbuknots=0,nbvknots=0; |
851 | IS >> udegree >> vdegree; |
852 | IS >> nbupoles >> nbvpoles; |
853 | IS >> nbuknots >> nbvknots; |
854 | |
855 | TColgp_Array2OfPnt poles(1,nbupoles,1,nbvpoles); |
856 | TColStd_Array2OfReal weights(1,nbupoles,1,nbvpoles); |
857 | |
858 | Standard_Integer i,j; |
859 | for (i = 1; i <= nbupoles; i++) { |
860 | for (j = 1; j <= nbvpoles; j++) { |
861 | IS >> poles(i,j); |
862 | if (urational || vrational) |
863 | IS >> weights(i,j); |
864 | } |
865 | } |
866 | |
867 | TColStd_Array1OfReal uknots(1,nbuknots); |
868 | TColStd_Array1OfInteger umults(1,nbuknots); |
869 | for (i = 1; i <= nbuknots; i++) { |
870 | IS >> uknots(i) >> umults(i); |
871 | } |
872 | |
873 | TColStd_Array1OfReal vknots(1,nbvknots); |
874 | TColStd_Array1OfInteger vmults(1,nbvknots); |
875 | for (i = 1; i <= nbvknots; i++) { |
876 | IS >> vknots(i) >> vmults(i); |
877 | } |
878 | |
879 | if (urational || vrational) |
880 | S = new Geom_BSplineSurface(poles,weights,uknots,vknots,umults,vmults, |
881 | udegree,vdegree,uperiodic,vperiodic); |
882 | else |
883 | S = new Geom_BSplineSurface(poles,uknots,vknots,umults,vmults, |
884 | udegree,vdegree,uperiodic,vperiodic); |
885 | return IS; |
886 | } |
887 | |
888 | //======================================================================= |
889 | //function : operator>> |
890 | //purpose : |
891 | //======================================================================= |
892 | |
893 | static Standard_IStream& operator>>(Standard_IStream& IS, |
894 | Handle(Geom_RectangularTrimmedSurface)& S) |
895 | { |
896 | Standard_Real U1=0.,U2=0.,V1=0.,V2=0.; |
897 | IS >> U1 >> U2 >> V1 >> V2; |
898 | Handle(Geom_Surface) BS; |
899 | GeomTools_SurfaceSet::ReadSurface(IS,BS); |
900 | S = new Geom_RectangularTrimmedSurface(BS,U1,U2,V1,V2); |
901 | return IS; |
902 | } |
903 | |
904 | //======================================================================= |
905 | //function : operator>> |
906 | //purpose : |
907 | //======================================================================= |
908 | |
909 | static Standard_IStream& operator>>(Standard_IStream& IS, |
910 | Handle(Geom_OffsetSurface)& S) |
911 | { |
912 | Standard_Real O=0.; |
913 | IS >> O; |
914 | Handle(Geom_Surface) BS; |
915 | GeomTools_SurfaceSet::ReadSurface(IS,BS); |
916 | S = new Geom_OffsetSurface(BS,O); |
917 | return IS; |
918 | } |
919 | |
920 | |
921 | //======================================================================= |
922 | //function : ReadSurface |
923 | //purpose : |
924 | //======================================================================= |
925 | |
926 | Standard_IStream& GeomTools_SurfaceSet::ReadSurface(Standard_IStream& IS, |
927 | Handle(Geom_Surface)& S) |
928 | { |
929 | Standard_Integer stype; |
930 | |
931 | try { |
932 | OCC_CATCH_SIGNALS |
933 | IS >> stype; |
934 | switch (stype) { |
935 | |
936 | case PLANE : |
937 | { |
938 | Handle(Geom_Plane) SS; |
939 | IS >> SS; |
940 | S = SS; |
941 | } |
942 | break; |
943 | |
944 | case CYLINDER : |
945 | { |
946 | Handle(Geom_CylindricalSurface) SS; |
947 | IS >> SS; |
948 | S = SS; |
949 | } |
950 | break; |
951 | |
952 | case CONE : |
953 | { |
954 | Handle(Geom_ConicalSurface) SS; |
955 | IS >> SS; |
956 | S = SS; |
957 | } |
958 | break; |
959 | |
960 | case SPHERE : |
961 | { |
962 | Handle(Geom_SphericalSurface) SS; |
963 | IS >> SS; |
964 | S = SS; |
965 | } |
966 | break; |
967 | |
968 | case TORUS : |
969 | { |
970 | Handle(Geom_ToroidalSurface) SS; |
971 | IS >> SS; |
972 | S = SS; |
973 | } |
974 | break; |
975 | |
976 | case LINEAREXTRUSION : |
977 | { |
978 | Handle(Geom_SurfaceOfLinearExtrusion) SS; |
979 | IS >> SS; |
980 | S = SS; |
981 | } |
982 | break; |
983 | |
984 | case REVOLUTION : |
985 | { |
986 | Handle(Geom_SurfaceOfRevolution) SS; |
987 | IS >> SS; |
988 | S = SS; |
989 | } |
990 | break; |
991 | |
992 | case BEZIER : |
993 | { |
994 | Handle(Geom_BezierSurface) SS; |
995 | IS >> SS; |
996 | S = SS; |
997 | } |
998 | break; |
999 | |
1000 | case BSPLINE : |
1001 | { |
1002 | Handle(Geom_BSplineSurface) SS; |
1003 | IS >> SS; |
1004 | S = SS; |
1005 | } |
1006 | break; |
1007 | |
1008 | case RECTANGULAR : |
1009 | { |
1010 | Handle(Geom_RectangularTrimmedSurface) SS; |
1011 | IS >> SS; |
1012 | S = SS; |
1013 | } |
1014 | break; |
1015 | |
1016 | case OFFSET : |
1017 | { |
1018 | Handle(Geom_OffsetSurface) SS; |
1019 | IS >> SS; |
1020 | S = SS; |
1021 | } |
1022 | break; |
1023 | |
1024 | default : |
1025 | { |
1026 | Handle(Geom_Surface) SS; |
1027 | GeomTools::GetUndefinedTypeHandler()->ReadSurface(stype,IS,SS); |
1028 | S = SS; |
1029 | } |
1030 | break; |
1031 | } |
1032 | } |
1033 | catch(Standard_Failure) { |
1034 | #ifdef DEB |
1035 | Handle(Standard_Failure) anExc = Standard_Failure::Caught(); |
1036 | cout <<"EXCEPTION in GeomTools_SurfaceSet::ReadSurface(..)!!!" << endl; |
1037 | cout << anExc << endl; |
1038 | #endif |
1039 | S = NULL; |
1040 | } |
1041 | return IS; |
1042 | } |
1043 | |
1044 | //======================================================================= |
1045 | //function : Read |
1046 | //purpose : |
1047 | //======================================================================= |
1048 | |
1049 | void GeomTools_SurfaceSet::Read(Standard_IStream& IS) |
1050 | { |
1051 | char buffer[255]; |
1052 | IS >> buffer; |
1053 | if (strcmp(buffer,"Surfaces")) { |
1054 | cout << "Not a surface table"<<endl; |
1055 | return; |
1056 | } |
1057 | |
1058 | Handle(Geom_Surface) S; |
1059 | Standard_Integer i, nbsurf; |
1060 | IS >> nbsurf; |
1061 | //OCC19559 |
1062 | Handle(Message_ProgressIndicator) progress = GetProgress(); |
1063 | Message_ProgressSentry PS(progress, "Surfaces", 0, nbsurf, 1); |
1064 | for (i = 1; i <= nbsurf && PS.More(); i++, PS.Next()) { |
1065 | if ( !progress.IsNull() ) |
1066 | progress->Show(); |
1067 | |
1068 | GeomTools_SurfaceSet::ReadSurface(IS,S); |
1069 | myMap.Add(S); |
1070 | } |
1071 | } |
1072 | |
1073 | //======================================================================= |
1074 | //function : GetProgress |
1075 | //purpose : |
1076 | //======================================================================= |
1077 | |
1078 | Handle(Message_ProgressIndicator) GeomTools_SurfaceSet::GetProgress() const |
1079 | { |
1080 | return myProgress; |
1081 | } |
1082 | |
1083 | //======================================================================= |
1084 | //function : SetProgress |
1085 | //purpose : |
1086 | //======================================================================= |
1087 | |
1088 | void GeomTools_SurfaceSet::SetProgress(const Handle(Message_ProgressIndicator)& PR) |
1089 | { |
1090 | myProgress = PR; |
1091 | } |
1092 | |
1093 | |
1094 | |