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