b311480e |
1 | // Created on: 1993-07-02 |
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 | // Modified: 02 Nov 2000: BUC60769. JMB, PTV. In order to be able to read BRep |
7fd59977 |
18 | // is run, we need the following modifications. |
7fd59977 |
19 | // On Unix platforms: |
20 | // ------------------ |
21 | // In method Read(Standard_IStream &IS), during the version |
22 | // authentification we cut last '\r' in the line (which will |
23 | // be present if file is in DOS coding) |
24 | |
25 | #include <TopTools_ShapeSet.ixx> |
26 | |
27 | #include <TopoDS_Iterator.hxx> |
28 | #include <TopoDS_Shape.hxx> |
29 | #include <locale.h> |
30 | #include <string.h> |
31 | |
32 | #include <Message_ProgressSentry.hxx> |
33 | |
34 | const char* Version = "CASCADE Topology V1, (c) Matra-Datavision"; |
35 | const char* Version2 = "CASCADE Topology V2, (c) Matra-Datavision"; |
36 | |
37 | //======================================================================= |
38 | //function : TopTools_ShapeSet |
39 | //purpose : |
40 | //======================================================================= |
41 | |
42 | TopTools_ShapeSet::TopTools_ShapeSet() : myFormatNb(1) |
43 | { |
44 | } |
45 | |
46 | void TopTools_ShapeSet::Delete() |
47 | {} |
48 | |
49 | //======================================================================= |
50 | //function : SetFormatNb |
51 | //purpose : |
52 | //======================================================================= |
53 | void TopTools_ShapeSet::SetFormatNb(const Standard_Integer theFormatNb) |
54 | { |
55 | myFormatNb = theFormatNb; |
56 | } |
57 | |
58 | //======================================================================= |
59 | //function : FormatNb |
60 | //purpose : |
61 | //======================================================================= |
62 | Standard_Integer TopTools_ShapeSet::FormatNb() const |
63 | { |
64 | return myFormatNb; |
65 | } |
66 | |
67 | //======================================================================= |
68 | //function : Clear |
69 | //purpose : |
70 | //======================================================================= |
71 | |
72 | void TopTools_ShapeSet::Clear() |
73 | { |
74 | myShapes.Clear(); |
75 | myLocations.Clear(); |
76 | } |
77 | |
78 | |
79 | //======================================================================= |
80 | //function : Add |
81 | //purpose : |
82 | //======================================================================= |
83 | |
84 | Standard_Integer TopTools_ShapeSet::Add(const TopoDS_Shape& S) |
85 | { |
86 | if (S.IsNull()) return 0; |
87 | myLocations.Add(S.Location()); |
88 | TopoDS_Shape S2 = S; |
89 | S2.Location(TopLoc_Location()); |
90 | Standard_Integer index = myShapes.FindIndex(S2); |
91 | if (index == 0) { |
92 | AddGeometry(S2); |
93 | |
94 | for (TopoDS_Iterator its(S2,Standard_False,Standard_False); |
95 | its.More(); its.Next()) |
96 | Add(its.Value()); |
97 | index = myShapes.Add(S2); |
98 | } |
99 | return index; |
100 | } |
101 | |
102 | |
103 | //======================================================================= |
104 | //function : Shape |
105 | //purpose : |
106 | //======================================================================= |
107 | |
108 | const TopoDS_Shape& TopTools_ShapeSet::Shape(const Standard_Integer I)const |
109 | { |
110 | return myShapes(I); |
111 | } |
112 | |
113 | //======================================================================= |
114 | //function : Index |
115 | //purpose : |
116 | //======================================================================= |
117 | |
118 | Standard_Integer TopTools_ShapeSet::Index(const TopoDS_Shape& S) const |
119 | { |
120 | return myShapes.FindIndex(S); |
121 | } |
122 | |
123 | //======================================================================= |
124 | //function : Locations |
125 | //purpose : |
126 | //======================================================================= |
127 | |
128 | const TopTools_LocationSet& TopTools_ShapeSet::Locations()const |
129 | { |
130 | return myLocations; |
131 | } |
132 | |
133 | |
134 | //======================================================================= |
135 | //function : ChangeLocations |
136 | //purpose : |
137 | //======================================================================= |
138 | |
139 | TopTools_LocationSet& TopTools_ShapeSet::ChangeLocations() |
140 | { |
141 | return myLocations; |
142 | } |
143 | |
144 | //======================================================================= |
145 | //function : PrintShapeEnum |
146 | //purpose : |
147 | //======================================================================= |
148 | |
149 | static void PrintShapeEnum(const TopAbs_ShapeEnum T, |
150 | Standard_OStream& S, |
151 | Standard_Boolean C) |
152 | { |
153 | switch(T) { |
154 | |
155 | case TopAbs_VERTEX : |
156 | if (C) S << "Ve"; else S << "VERTEX "; |
157 | break; |
158 | |
159 | case TopAbs_EDGE : |
160 | if (C) S << "Ed"; else S << "EDGE "; |
161 | break; |
162 | |
163 | case TopAbs_WIRE : |
164 | if (C) S << "Wi"; else S << "WIRE "; |
165 | break; |
166 | |
167 | case TopAbs_FACE : |
168 | if (C) S << "Fa"; else S << "FACE "; |
169 | break; |
170 | |
171 | case TopAbs_SHELL : |
172 | if (C) S << "Sh"; else S << "SHELL "; |
173 | break; |
174 | |
175 | case TopAbs_SOLID : |
176 | if (C) S << "So"; else S << "SOLID "; |
177 | break; |
178 | |
179 | case TopAbs_COMPSOLID : |
180 | if (C) S << "CS"; else S << "COMPSOLID"; |
181 | break; |
182 | |
183 | case TopAbs_COMPOUND : |
184 | if (C) S << "Co"; else S << "COMPOUND "; |
185 | break; |
186 | |
187 | case TopAbs_SHAPE : |
188 | if (C) S << "Sp"; else S << "SHAPE"; |
189 | break; |
190 | } |
191 | } |
192 | |
193 | //======================================================================= |
194 | //function : PrintOrientation |
195 | //purpose : |
196 | //======================================================================= |
197 | |
198 | static void PrintOrientation(const TopAbs_Orientation O, |
199 | Standard_OStream& S, |
200 | Standard_Boolean C) |
201 | { |
202 | switch(O) { |
203 | |
204 | case TopAbs_FORWARD : |
205 | if (C) S << "+"; else S << "FORWARD"; |
206 | break; |
207 | |
208 | case TopAbs_REVERSED : |
209 | if (C) S << "-"; else S << "REVERSED"; |
210 | break; |
211 | |
212 | case TopAbs_INTERNAL : |
213 | if (C) S << "i"; else S << "INTERNAL"; |
214 | break; |
215 | |
216 | case TopAbs_EXTERNAL : |
217 | if (C) S << "e"; else S << "EXTERNAL"; |
218 | break; |
219 | } |
220 | } |
221 | |
222 | //======================================================================= |
223 | //function : DumpExtent |
224 | //purpose : Dump number of shapes. |
225 | //======================================================================= |
226 | |
227 | Standard_OStream& TopTools_ShapeSet::DumpExtent(Standard_OStream& OS)const |
228 | { |
229 | |
230 | Standard_Integer nbVERTEX = 0; |
231 | Standard_Integer nbEDGE = 0; |
232 | Standard_Integer nbWIRE = 0; |
233 | Standard_Integer nbFACE = 0; |
234 | Standard_Integer nbSHELL = 0; |
235 | Standard_Integer nbSOLID = 0; |
236 | Standard_Integer nbCOMPSOLID = 0; |
237 | Standard_Integer nbCOMPOUND = 0; |
238 | Standard_Integer nbSHAPE = myShapes.Extent(); |
239 | |
240 | for (Standard_Integer i = 1; i <= nbSHAPE; i++) { |
241 | |
242 | switch(myShapes(i).ShapeType()) { |
243 | |
244 | case TopAbs_VERTEX : |
245 | nbVERTEX++; |
246 | break; |
247 | |
248 | case TopAbs_EDGE : |
249 | nbEDGE++; |
250 | break; |
251 | |
252 | case TopAbs_WIRE : |
253 | nbWIRE++; |
254 | break; |
255 | |
256 | case TopAbs_FACE : |
257 | nbFACE++; |
258 | break; |
259 | |
260 | case TopAbs_SHELL : |
261 | nbSHELL++; |
262 | break; |
263 | |
264 | case TopAbs_SOLID : |
265 | nbSOLID++; |
266 | break; |
267 | |
268 | case TopAbs_COMPSOLID : |
269 | nbCOMPSOLID++; |
270 | break; |
271 | |
272 | case TopAbs_COMPOUND : |
273 | nbCOMPOUND++; |
274 | break; |
275 | |
276 | case TopAbs_SHAPE : |
277 | break; |
278 | } |
279 | } |
280 | |
281 | |
282 | OS << " VERTEX : " << nbVERTEX << "\n"; |
283 | OS << " EDGE : " << nbEDGE << "\n"; |
284 | OS << " WIRE : " << nbWIRE << "\n"; |
285 | OS << " FACE : " << nbFACE << "\n"; |
286 | OS << " SHELL : " << nbSHELL << "\n"; |
287 | OS << " SOLID : " << nbSOLID << "\n"; |
288 | OS << " COMPSOLID : " << nbCOMPSOLID << "\n"; |
289 | OS << " COMPOUND : " << nbCOMPOUND << "\n"; |
290 | OS << " SHAPE : " << nbSHAPE << "\n"; |
291 | |
292 | return OS; |
293 | } |
294 | |
295 | //======================================================================= |
296 | //function : DumpExtent |
297 | //purpose : Dump number of shapes. |
298 | //======================================================================= |
299 | |
300 | void TopTools_ShapeSet::DumpExtent(TCollection_AsciiString& S)const |
301 | { |
302 | |
303 | Standard_Integer nbVERTEX = 0; |
304 | Standard_Integer nbEDGE = 0; |
305 | Standard_Integer nbWIRE = 0; |
306 | Standard_Integer nbFACE = 0; |
307 | Standard_Integer nbSHELL = 0; |
308 | Standard_Integer nbSOLID = 0; |
309 | Standard_Integer nbCOMPSOLID = 0; |
310 | Standard_Integer nbCOMPOUND = 0; |
311 | Standard_Integer nbSHAPE = myShapes.Extent(); |
312 | |
313 | for (Standard_Integer i = 1; i <= nbSHAPE; i++) { |
314 | |
315 | switch(myShapes(i).ShapeType()) { |
316 | |
317 | case TopAbs_VERTEX : |
318 | nbVERTEX++; |
319 | break; |
320 | |
321 | case TopAbs_EDGE : |
322 | nbEDGE++; |
323 | break; |
324 | |
325 | case TopAbs_WIRE : |
326 | nbWIRE++; |
327 | break; |
328 | |
329 | case TopAbs_FACE : |
330 | nbFACE++; |
331 | break; |
332 | |
333 | case TopAbs_SHELL : |
334 | nbSHELL++; |
335 | break; |
336 | |
337 | case TopAbs_SOLID : |
338 | nbSOLID++; |
339 | break; |
340 | |
341 | case TopAbs_COMPSOLID : |
342 | nbCOMPSOLID++; |
343 | break; |
344 | |
345 | case TopAbs_COMPOUND : |
346 | nbCOMPOUND++; |
347 | break; |
348 | |
349 | case TopAbs_SHAPE : |
350 | break; |
351 | } |
352 | } |
353 | |
354 | S = S + " VERTEX : " + TCollection_AsciiString(nbVERTEX) + "\n"; |
355 | S = S + " EDGE : " + TCollection_AsciiString(nbEDGE) + "\n"; |
356 | S = S + " WIRE : " + TCollection_AsciiString(nbWIRE) + "\n"; |
357 | S = S + " FACE : " + TCollection_AsciiString(nbFACE) + "\n"; |
358 | S = S + " SHELL : " + TCollection_AsciiString(nbSHELL) + "\n"; |
359 | S = S + " SOLID : " + TCollection_AsciiString(nbSOLID) + "\n"; |
360 | S = S + " COMPSOLID : " + TCollection_AsciiString(nbCOMPSOLID) + "\n"; |
361 | S = S + " COMPOUND : " + TCollection_AsciiString(nbCOMPOUND) + "\n"; |
362 | S = S + " SHAPE : " + TCollection_AsciiString(nbSHAPE) + "\n"; |
363 | } |
364 | |
365 | |
366 | //======================================================================= |
367 | //function : Dump |
368 | //purpose : |
369 | //======================================================================= |
370 | |
371 | void TopTools_ShapeSet::Dump(Standard_OStream& OS)const |
372 | { |
373 | //----------------------------------------- |
374 | // dump the shapes |
375 | //----------------------------------------- |
376 | |
377 | Standard_Integer i, nbShapes = myShapes.Extent(); |
378 | |
379 | OS << "\nDump of " << nbShapes << " TShapes"; |
380 | OS << "\n\n-----------------\n\n"; |
381 | |
382 | OS << "Flags : Free, Modified, Checked, Orientable, Closed, Infinite, Convex"; |
383 | OS << "\n\n"; |
384 | |
385 | for (i = nbShapes; i >= 1; i--) { |
386 | |
387 | const TopoDS_Shape& S = myShapes(i); |
388 | OS << "TShape # " << nbShapes - i + 1 << " : "; |
389 | |
390 | // Type and flags |
391 | |
392 | PrintShapeEnum(S.ShapeType(),OS,Standard_False); |
393 | OS << " "; |
394 | OS << (S.Free() ? 1 : 0); |
395 | OS << (S.Modified() ? 1 : 0); |
396 | OS << (S.Checked() ? 1 : 0); |
397 | OS << (S.Orientable() ? 1 : 0); |
398 | OS << (S.Closed() ? 1 : 0); |
399 | OS << (S.Infinite() ? 1 : 0); |
400 | OS << (S.Convex() ? 1 : 0); |
401 | OS << " " << (void*) &(*S.TShape()) <<"\n"; |
402 | |
403 | // sub-shapes |
404 | OS << " "; |
405 | TopoDS_Iterator its(S,Standard_False,Standard_False); |
406 | while (its.More()) { |
407 | const TopoDS_Shape& sub = its.Value(); |
408 | PrintOrientation(sub.Orientation(),OS,Standard_True); |
409 | OS<<nbShapes - myShapes.FindIndex(sub.Located(TopLoc_Location())) + 1; |
410 | if (!sub.Location().IsIdentity()) |
411 | OS << "(L" << myLocations.Index(sub.Location()) << ")"; |
412 | OS << " "; |
413 | its.Next(); |
414 | } |
415 | OS << "\n"; |
416 | |
417 | // Geometry |
418 | |
419 | DumpGeometry(S,OS); |
420 | } |
421 | |
422 | |
423 | //----------------------------------------- |
424 | // dump the geometry |
425 | //----------------------------------------- |
426 | |
427 | DumpGeometry(OS); |
428 | |
429 | //----------------------------------------- |
430 | // dump the locations |
431 | //----------------------------------------- |
432 | |
433 | myLocations.Dump(OS); |
434 | |
435 | OS << endl; |
436 | } |
437 | |
438 | |
439 | //======================================================================= |
440 | //function : Write |
441 | //purpose : |
442 | //======================================================================= |
443 | |
444 | void TopTools_ShapeSet::Write(Standard_OStream& OS) |
445 | { |
91322f44 |
446 | // always use C locale for writing shapes |
447 | std::locale anOldLocale = OS.imbue (std::locale::classic()); |
7fd59977 |
448 | |
91322f44 |
449 | // use 15-digit precision |
60be1f9b |
450 | std::streamsize prec = OS.precision(15); |
7fd59977 |
451 | |
452 | // write the copyright |
453 | if (myFormatNb == 2) |
454 | OS << "\n" << Version2 << endl; |
455 | else |
456 | OS << "\n" << Version << endl; |
457 | |
458 | //----------------------------------------- |
459 | // write the locations |
460 | //----------------------------------------- |
461 | |
7fd59977 |
462 | if ( !myProgress.IsNull() ) |
463 | myProgress->NewScope ( 10, "Locations" ); |
464 | myLocations.SetProgress(myProgress); |
465 | myLocations.Write(OS); |
466 | if ( !myProgress.IsNull() ) { |
467 | myProgress->EndScope(); |
468 | myProgress->Show(); |
469 | } |
470 | |
7fd59977 |
471 | if (!myProgress.IsNull() && myProgress->UserBreak()) { |
91322f44 |
472 | OS << "Interrupted by the user"<<endl; |
473 | OS.imbue (anOldLocale); |
7fd59977 |
474 | return; |
475 | } |
476 | |
477 | //----------------------------------------- |
478 | // write the geometry |
479 | //----------------------------------------- |
480 | |
481 | if ( !myProgress.IsNull() ) |
482 | myProgress->NewScope ( 75, "Geometry" ); |
483 | WriteGeometry(OS); |
484 | if ( !myProgress.IsNull() ) { |
485 | myProgress->EndScope(); |
486 | myProgress->Show(); |
487 | } |
488 | |
489 | //----------------------------------------- |
490 | // write the shapes |
491 | //----------------------------------------- |
492 | |
493 | Standard_Integer i, nbShapes = myShapes.Extent(); |
494 | |
495 | OS << "\nTShapes " << nbShapes << "\n"; |
7fd59977 |
496 | |
497 | // subshapes are written first |
498 | //OCC19559 |
499 | if ( !myProgress.IsNull() ) |
500 | myProgress->NewScope ( 15, "Shapes" ); |
501 | Message_ProgressSentry PS(myProgress, "Shapes", 0, nbShapes, 1); |
7fd59977 |
502 | for (i = 1; i <= nbShapes && PS.More(); i++, PS.Next()) { |
7fd59977 |
503 | const TopoDS_Shape& S = myShapes(i); |
504 | |
505 | // Type |
506 | PrintShapeEnum(S.ShapeType(),OS,Standard_True); |
507 | OS << "\n"; |
508 | |
509 | // Geometry |
510 | WriteGeometry(S,OS); |
511 | |
512 | // Flags |
513 | OS << "\n"; |
514 | OS << (S.Free() ? 1 : 0); |
515 | OS << (S.Modified() ? 1 : 0); |
516 | OS << (S.Checked() ? 1 : 0); |
517 | OS << (S.Orientable() ? 1 : 0); |
518 | OS << (S.Closed() ? 1 : 0); |
519 | OS << (S.Infinite() ? 1 : 0); |
520 | OS << (S.Convex() ? 1 : 0); |
521 | OS << "\n"; |
522 | |
523 | // sub-shapes |
524 | |
525 | Standard_Integer l = 0; |
526 | TopoDS_Iterator its(S,Standard_False,Standard_False); |
527 | while (its.More()) { |
528 | Write(its.Value(),OS); |
529 | l++; |
530 | if (l == 10) { |
531 | OS << "\n"; |
532 | l = 0; |
533 | } |
534 | its.Next(); |
535 | } |
536 | Write(TopoDS_Shape(),OS); // Null shape to end the list |
537 | OS << "\n"; |
538 | } |
539 | |
540 | OS << endl; |
541 | OS.precision(prec); |
91322f44 |
542 | OS.imbue (anOldLocale); |
543 | |
7fd59977 |
544 | PS.Relieve(); |
545 | if (!myProgress.IsNull()) { |
546 | myProgress->EndScope(); |
547 | myProgress->Show(); |
91322f44 |
548 | if (myProgress->UserBreak()) |
549 | OS << "Interrupted by the user"<<endl; |
7fd59977 |
550 | } |
7fd59977 |
551 | } |
552 | |
553 | //======================================================================= |
554 | //function : ReadShapeEnum |
555 | //purpose : |
556 | //======================================================================= |
557 | |
558 | static TopAbs_ShapeEnum ReadShapeEnum(Standard_IStream& IS) |
559 | { |
560 | char buffer[255]; |
561 | IS >> buffer; |
562 | |
563 | switch (buffer[0]) { |
564 | |
565 | case 'V' : |
566 | return TopAbs_VERTEX; |
567 | |
568 | case 'E' : |
569 | return TopAbs_EDGE; |
570 | |
571 | case 'W' : |
572 | return TopAbs_WIRE; |
573 | |
574 | case 'F' : |
575 | return TopAbs_FACE; |
576 | |
577 | case 'S' : |
578 | if (buffer[1] == 'h') |
579 | return TopAbs_SHELL; |
580 | else |
581 | return TopAbs_SOLID; |
582 | |
583 | case 'C' : |
584 | if (buffer[1] == 'S') |
585 | return TopAbs_COMPSOLID; |
586 | else |
587 | return TopAbs_COMPOUND; |
588 | |
589 | } |
590 | return TopAbs_COMPOUND; |
591 | } |
592 | |
593 | //======================================================================= |
594 | //function : Read |
595 | //purpose : |
596 | //======================================================================= |
597 | |
598 | void TopTools_ShapeSet::Read(Standard_IStream& IS) |
599 | { |
91322f44 |
600 | // always use C locale for reading shapes |
601 | std::locale anOldLocale = IS.imbue (std::locale::classic()); |
7fd59977 |
602 | |
603 | Clear(); |
604 | |
605 | // Check the version |
606 | char vers[101]; |
607 | do { |
608 | IS.getline(vers,100,'\n'); |
609 | // BUC60769 PTV 18.10.2000: remove possible '\r' at the end of the line |
610 | //Standard_Integer lv = strlen(vers); |
611 | //char *pm; |
612 | //if(pm = strchr(vers,'\r')) |
613 | // *pm ='\0'; |
614 | |
5149c3f3 |
615 | Standard_Size lv = strlen(vers); |
616 | if (lv > 0) { |
617 | for (lv--; lv > 0 && (vers[lv] == '\r' || vers[lv] == '\n') ;lv--) |
618 | vers[lv] = '\0'; |
619 | } |
7fd59977 |
620 | |
621 | } while ( ! IS.fail() && strcmp(vers,Version) && strcmp(vers,Version2) ); |
622 | if (IS.fail()) { |
623 | cout << "File was not written with this version of the topology"<<endl; |
91322f44 |
624 | IS.imbue (anOldLocale); |
7fd59977 |
625 | return; |
626 | } |
627 | if (strcmp(vers,Version2) == 0) SetFormatNb(2); |
628 | else SetFormatNb(1); |
629 | |
630 | //----------------------------------------- |
631 | // read the locations |
632 | //----------------------------------------- |
633 | |
634 | //OCC19559 |
635 | if (!myProgress.IsNull() && myProgress->UserBreak()) { |
636 | cout << "Interrupted by the user"<<endl; |
637 | // on remet le LC_NUMERIC a la precedente valeur |
91322f44 |
638 | IS.imbue (anOldLocale); |
7fd59977 |
639 | return; |
640 | } |
641 | if ( !myProgress.IsNull() ) |
642 | myProgress->NewScope ( 10, "Locations" ); |
643 | myLocations.SetProgress(myProgress); |
644 | myLocations.Read(IS); |
645 | if ( !myProgress.IsNull() ) { |
646 | myProgress->EndScope(); |
647 | myProgress->Show(); |
648 | } |
649 | //OCC19559 |
650 | if (!myProgress.IsNull() && myProgress->UserBreak()) { |
651 | cout << "Interrupted by the user"<<endl; |
652 | // on remet le LC_NUMERIC a la precedente valeur |
91322f44 |
653 | IS.imbue (anOldLocale); |
7fd59977 |
654 | return; |
655 | } |
656 | |
657 | //----------------------------------------- |
658 | // read the geometry |
659 | //----------------------------------------- |
660 | if ( !myProgress.IsNull() ) |
661 | myProgress->NewScope ( 75, "Geometry" ); |
662 | ReadGeometry(IS); |
663 | if ( !myProgress.IsNull() ) { |
664 | myProgress->EndScope(); |
665 | myProgress->Show(); |
666 | } |
667 | |
668 | //----------------------------------------- |
669 | // read the shapes |
670 | //----------------------------------------- |
671 | |
672 | char buffer[255]; |
673 | IS >> buffer; |
674 | if (strcmp(buffer,"TShapes")) { |
675 | cout << "Not a TShape table"<<endl; |
676 | // on remet le LC_NUMERIC a la precedente valeur |
91322f44 |
677 | IS.imbue (anOldLocale); |
7fd59977 |
678 | return; |
679 | } |
680 | |
681 | Standard_Integer i, nbShapes; |
682 | IS >> nbShapes; |
683 | |
684 | //OCC19559 |
685 | if ( !myProgress.IsNull() ) |
686 | myProgress->NewScope ( 15, "Shapes" ); |
687 | Message_ProgressSentry PS(myProgress, "Shapes", 0, nbShapes, 1); |
688 | for (i = 1; i <= nbShapes && PS.More(); i++, PS.Next() ) { |
7fd59977 |
689 | TopoDS_Shape S; |
690 | |
691 | //Read type and create empty shape. |
692 | |
693 | TopAbs_ShapeEnum T = ReadShapeEnum(IS); |
694 | ReadGeometry(T,IS,S); |
695 | |
696 | // Set the flags |
697 | IS >> buffer; |
698 | |
699 | // sub-shapes |
700 | TopoDS_Shape SS; |
701 | do { |
702 | Read(SS,IS,nbShapes); |
703 | if (!SS.IsNull()) |
704 | AddShapes(S,SS); |
705 | } while(!SS.IsNull()); |
706 | |
707 | S.Free (buffer[0] == '1'); |
708 | S.Modified (buffer[1] == '1'); |
709 | |
710 | if (myFormatNb == 2) |
711 | S.Checked (buffer[2] == '1'); |
712 | else |
713 | S.Checked (Standard_False); // force check at reading.. |
714 | |
715 | S.Orientable(buffer[3] == '1'); |
716 | S.Closed (buffer[4] == '1'); |
717 | S.Infinite (buffer[5] == '1'); |
718 | S.Convex (buffer[6] == '1'); |
719 | |
720 | // check |
721 | |
722 | if (myFormatNb == 1) |
723 | Check(T,S); |
724 | |
725 | myShapes.Add(S); |
726 | } |
727 | if (!myProgress.IsNull()) { |
728 | myProgress->EndScope(); |
729 | myProgress->Show(); |
730 | } |
731 | |
732 | // on remet le LC_NUMERIC a la precedente valeur |
91322f44 |
733 | IS.imbue (anOldLocale); |
7fd59977 |
734 | } |
735 | |
736 | //======================================================================= |
737 | //function : Dump |
738 | //purpose : |
739 | //======================================================================= |
740 | |
741 | void TopTools_ShapeSet::Dump(const TopoDS_Shape& S, |
742 | Standard_OStream& OS)const |
743 | { |
744 | if (S.IsNull()) OS << "Null shape\n"; |
745 | OS << "Shape : " << myShapes.FindIndex(S.Located(TopLoc_Location())); |
746 | OS << ", "; |
747 | PrintOrientation(S.Orientation(),OS,Standard_False); |
748 | if (!S.Location().IsIdentity()) |
749 | OS <<", location : " << myLocations.Index(S.Location()); |
750 | OS << "\n"; |
751 | } |
752 | |
753 | |
754 | //======================================================================= |
755 | //function : Write |
756 | //purpose : |
757 | //======================================================================= |
758 | |
759 | void TopTools_ShapeSet::Write(const TopoDS_Shape& S, |
760 | Standard_OStream& OS)const |
761 | { |
762 | if (S.IsNull()) OS << "*"; |
763 | else { |
764 | PrintOrientation(S.Orientation(),OS,Standard_True); |
765 | OS << myShapes.Extent() - myShapes.FindIndex(S.Located(TopLoc_Location())) + 1; |
766 | OS << " " << myLocations.Index(S.Location()) << " "; |
767 | } |
768 | } |
769 | |
770 | //======================================================================= |
771 | //function : Read |
772 | //purpose : |
773 | //======================================================================= |
774 | |
775 | void TopTools_ShapeSet::Read(TopoDS_Shape& S, |
776 | Standard_IStream& IS)const |
777 | { |
778 | Read(S,IS,myShapes.Extent()); |
779 | } |
780 | |
781 | //======================================================================= |
782 | //function : Read |
783 | //purpose : |
784 | //======================================================================= |
785 | |
786 | void TopTools_ShapeSet::Read(TopoDS_Shape& S, |
787 | Standard_IStream& IS, |
788 | const Standard_Integer nbshapes)const |
789 | { |
790 | if(nbshapes < 1) |
791 | { |
792 | S = TopoDS_Shape(); |
793 | return; |
794 | } |
795 | char buffer[255]; |
796 | IS >> buffer; |
797 | if (buffer[0] == '*') |
798 | S = TopoDS_Shape(); |
799 | else { |
800 | S = myShapes(nbshapes - atoi(buffer+1) + 1); |
801 | switch (buffer[0]) { |
802 | |
803 | case '+' : |
804 | S.Orientation(TopAbs_FORWARD); |
805 | break; |
806 | |
807 | case '-' : |
808 | S.Orientation(TopAbs_REVERSED); |
809 | break; |
810 | |
811 | case 'i' : |
812 | S.Orientation(TopAbs_INTERNAL); |
813 | break; |
814 | |
815 | case 'e' : |
816 | S.Orientation(TopAbs_EXTERNAL); |
817 | break; |
818 | } |
819 | |
820 | Standard_Integer l; |
821 | IS >> l; |
822 | S.Location(myLocations.Location(l)); |
823 | } |
824 | } |
825 | |
826 | //======================================================================= |
827 | //function : AddGeometry |
828 | //purpose : |
829 | //======================================================================= |
830 | |
831 | void TopTools_ShapeSet::AddGeometry(const TopoDS_Shape&) |
832 | { |
833 | } |
834 | |
835 | //======================================================================= |
836 | //function : DumpGeometry |
837 | //purpose : |
838 | //======================================================================= |
839 | |
840 | void TopTools_ShapeSet::DumpGeometry(Standard_OStream&) const |
841 | { |
842 | } |
843 | |
844 | |
845 | //======================================================================= |
846 | //function : WriteGeometry |
847 | //purpose : |
848 | //======================================================================= |
849 | |
850 | void TopTools_ShapeSet::WriteGeometry(Standard_OStream&) |
851 | { |
852 | } |
853 | |
854 | |
855 | //======================================================================= |
856 | //function : ReadGeometry |
857 | //purpose : |
858 | //======================================================================= |
859 | |
860 | void TopTools_ShapeSet::ReadGeometry(Standard_IStream&) |
861 | { |
862 | } |
863 | |
864 | |
865 | //======================================================================= |
866 | //function : DumpGeometry |
867 | //purpose : |
868 | //======================================================================= |
869 | |
870 | void TopTools_ShapeSet::DumpGeometry(const TopoDS_Shape&, |
871 | Standard_OStream&)const |
872 | { |
873 | } |
874 | |
875 | |
876 | //======================================================================= |
877 | //function : WriteGeometry |
878 | //purpose : |
879 | //======================================================================= |
880 | |
881 | void TopTools_ShapeSet::WriteGeometry(const TopoDS_Shape&, |
882 | Standard_OStream&)const |
883 | { |
884 | } |
885 | |
886 | |
887 | //======================================================================= |
888 | //function : ReadGeometry |
889 | //purpose : |
890 | //======================================================================= |
891 | |
892 | void TopTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum, |
893 | Standard_IStream& , |
894 | TopoDS_Shape&) |
895 | { |
896 | } |
897 | |
898 | |
899 | |
900 | |
901 | //======================================================================= |
902 | //function : AddShapes |
903 | //purpose : |
904 | //======================================================================= |
905 | |
906 | void TopTools_ShapeSet::AddShapes(TopoDS_Shape&, |
907 | const TopoDS_Shape&) |
908 | { |
909 | } |
910 | |
911 | |
912 | |
913 | //======================================================================= |
914 | //function : Check |
915 | //purpose : |
916 | //======================================================================= |
917 | |
918 | void TopTools_ShapeSet::Check(const TopAbs_ShapeEnum, |
919 | TopoDS_Shape&) |
920 | { |
921 | } |
922 | |
923 | //======================================================================= |
924 | //function : NbShapes |
925 | //purpose : |
926 | //======================================================================= |
927 | |
928 | Standard_Integer TopTools_ShapeSet::NbShapes() const |
929 | { |
930 | return myShapes.Extent(); |
931 | } |
932 | |
933 | //======================================================================= |
934 | //function : GetProgress |
935 | //purpose : |
936 | //======================================================================= |
937 | |
938 | Handle(Message_ProgressIndicator) TopTools_ShapeSet::GetProgress() const |
939 | { |
940 | return myProgress; |
941 | } |
942 | |
943 | //======================================================================= |
944 | //function : SetProgress |
945 | //purpose : |
946 | //======================================================================= |
947 | |
948 | void TopTools_ShapeSet::SetProgress(const Handle(Message_ProgressIndicator)& PR) |
949 | { |
950 | myProgress = PR; |
951 | } |
952 | |
953 | |