0025748: Parallel version of progress indicator
[occt.git] / src / BRepTools / BRepTools_ShapeSet.cxx
CommitLineData
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.
b311480e 16
7fd59977 17// Modifed: Portage NT 7-5-97 DPF (strcasecmp)
18
42cf5bc1 19#include <BRep_Builder.hxx>
7fd59977 20#include <BRep_CurveOnClosedSurface.hxx>
42cf5bc1 21#include <BRep_CurveOnSurface.hxx>
22#include <BRep_CurveRepresentation.hxx>
23#include <BRep_GCurve.hxx>
7fd59977 24#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
42cf5bc1 25#include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
26#include <BRep_ListOfCurveRepresentation.hxx>
7fd59977 27#include <BRep_PointOnCurve.hxx>
28#include <BRep_PointOnCurveOnSurface.hxx>
29#include <BRep_PointOnSurface.hxx>
42cf5bc1 30#include <BRep_Polygon3D.hxx>
31#include <BRep_PolygonOnClosedSurface.hxx>
32#include <BRep_PolygonOnClosedTriangulation.hxx>
33#include <BRep_PolygonOnSurface.hxx>
34#include <BRep_PolygonOnTriangulation.hxx>
35#include <BRep_TEdge.hxx>
36#include <BRep_TFace.hxx>
37#include <BRep_Tool.hxx>
38#include <BRep_TVertex.hxx>
39#include <BRepTools.hxx>
40#include <BRepTools_ShapeSet.hxx>
41#include <GeomTools.hxx>
7e785937 42#include <Message_ProgressScope.hxx>
42cf5bc1 43#include <Poly.hxx>
44#include <Poly_Polygon2D.hxx>
45#include <Poly_Polygon3D.hxx>
46#include <Poly_PolygonOnTriangulation.hxx>
47#include <Poly_Triangulation.hxx>
48#include <Precision.hxx>
49#include <Standard_Stream.hxx>
7fd59977 50#include <TColgp_HArray1OfPnt.hxx>
51#include <TColgp_HArray1OfPnt2d.hxx>
42cf5bc1 52#include <TColStd_HArray1OfInteger.hxx>
7fd59977 53#include <TColStd_HArray1OfReal.hxx>
42cf5bc1 54#include <TopoDS.hxx>
55#include <TopoDS_Shape.hxx>
56#include <TopoDS_Vertex.hxx>
7fd59977 57
58#ifdef MacOS
59#define strcasecmp(p,q) strcmp(p,q)
57c28b61 60#elseif _WIN32
7fd59977 61#define strcasecmp strcmp
62#elseif AIX
63#include <string.h>
64#endif
65
66// Modified: 02 Nov 2000: BUC60769. JMB, PTV. In order to be able to read BRep
67// files that came from a platform different from where CasCade
68// is run, we need the following modifications.
69//
70// On NT platforms (in BRepTools_ShapeSet):
71// ----------------
04232180 72// In Visual C++ 5 (or higher) the std::fstream::tellg method is not
7fd59977 73// conform to Standard C++ because it modifies the file pointer
74// position and returns a wrong position. After that the next
75// readings are shifted and the reading process stop with errors.
76//
77// Workaround is following: Now we don`t use tellg for get position in stream.
78// Now able to read file (when reading TopAbs_FACE) without tellg.
79// We simple check the next string if there are value that equal 2
80// (It means a parametr for triangulation).
81
82
83//=======================================================================
84//function : BRepTools_ShapeSet
85//purpose :
86//=======================================================================
87
88BRepTools_ShapeSet::BRepTools_ShapeSet(const Standard_Boolean isWithTriangles)
89 :myWithTriangles(isWithTriangles)
90{
91}
92
93//=======================================================================
94//function : BRepTools_ShapeSet
95//purpose :
96//=======================================================================
97
98BRepTools_ShapeSet::BRepTools_ShapeSet (const BRep_Builder& B,
99 const Standard_Boolean isWithTriangles) :
100 myBuilder(B), myWithTriangles(isWithTriangles)
101{
102}
103
104
105//=======================================================================
106//function : Clear
107//purpose :
108//=======================================================================
109
110void BRepTools_ShapeSet::Clear()
111{
112 mySurfaces.Clear();
113 myCurves.Clear();
114 myCurves2d.Clear();
115 myPolygons3D.Clear();
116 myPolygons2D.Clear();
117 myNodes.Clear();
118 myTriangulations.Clear();
119 TopTools_ShapeSet::Clear();
120}
121
122
123//=======================================================================
124//function : AddGeometry
125//purpose :
126//=======================================================================
127
128void BRepTools_ShapeSet::AddGeometry(const TopoDS_Shape& S)
129{
130 // Add the geometry
131
132 if (S.ShapeType() == TopAbs_VERTEX) {
133
134 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
135 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
136
137 while (itrp.More()) {
138 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
139
140 if (PR->IsPointOnCurve()) {
141 myCurves.Add(PR->Curve());
142 }
143
144 else if (PR->IsPointOnCurveOnSurface()) {
145 myCurves2d.Add(PR->PCurve());
146 mySurfaces.Add(PR->Surface());
147 }
148
149 else if (PR->IsPointOnSurface()) {
150 mySurfaces.Add(PR->Surface());
151 }
152
153 ChangeLocations().Add(PR->Location());
154 itrp.Next();
155 }
156
157 }
158 else if (S.ShapeType() == TopAbs_EDGE) {
159
160 // Add the curve geometry
161 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
162 BRep_ListIteratorOfListOfCurveRepresentation itrc(TE->Curves());
163
164 while (itrc.More()) {
165 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
166 if (CR->IsCurve3D()) {
167 if (!CR->Curve3D().IsNull()) {
168 myCurves.Add(CR->Curve3D());
169 ChangeLocations().Add(CR->Location());
170 }
171 }
172 else if (CR->IsCurveOnSurface()) {
173 mySurfaces.Add(CR->Surface());
174 myCurves2d.Add(CR->PCurve());
175 ChangeLocations().Add(CR->Location());
176 if (CR->IsCurveOnClosedSurface())
177 myCurves2d.Add(CR->PCurve2());
178 }
179 else if (CR->IsRegularity()) {
180 mySurfaces.Add(CR->Surface());
181 ChangeLocations().Add(CR->Location());
182 mySurfaces.Add(CR->Surface2());
183 ChangeLocations().Add(CR->Location2());
184 }
185 else if (myWithTriangles) { // for XML Persistence
186 if (CR->IsPolygon3D()) {
187 if (!CR->Polygon3D().IsNull()) {
188 myPolygons3D.Add(CR->Polygon3D());
189 ChangeLocations().Add(CR->Location());
190 }
191 }
192 else if (CR->IsPolygonOnTriangulation()) {
193 myTriangulations.Add(CR->Triangulation());
194 myNodes.Add(CR->PolygonOnTriangulation());
195 ChangeLocations().Add(CR->Location());
196 if (CR->IsPolygonOnClosedTriangulation())
197 myNodes.Add(CR->PolygonOnTriangulation2());
198 }
199 else if (CR->IsPolygonOnSurface()) {
200 mySurfaces.Add(CR->Surface());
201 myPolygons2D.Add(CR->Polygon());
202 ChangeLocations().Add(CR->Location());
203 if (CR->IsPolygonOnClosedSurface())
204 myPolygons2D.Add(CR->Polygon2());
205 }
206 }
207 itrc.Next();
208 }
209 }
210
211 else if (S.ShapeType() == TopAbs_FACE) {
212
213 // Add the surface geometry
214 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
215 if (!TF->Surface().IsNull()) mySurfaces.Add(TF->Surface());
216
8c787b5f 217 if (myWithTriangles || TF->Surface().IsNull()) { // for XML Persistence
7fd59977 218 Handle(Poly_Triangulation) Tr = TF->Triangulation();
219 if (!Tr.IsNull()) myTriangulations.Add(Tr);
220 }
221
222 ChangeLocations().Add(TF->Location());
223 }
224}
225
226
227//=======================================================================
228//function : DumpGeometry
229//purpose :
230//=======================================================================
231
6d8f9f4a 232void BRepTools_ShapeSet::DumpGeometry (Standard_OStream& OS)const
7fd59977 233{
234 myCurves2d.Dump(OS);
235 myCurves.Dump(OS);
236 DumpPolygon3D(OS);
237 DumpPolygonOnTriangulation(OS);
238 mySurfaces.Dump(OS);
239 DumpTriangulation(OS);
240}
241
242
243//=======================================================================
244//function : WriteGeometry
245//purpose :
246//=======================================================================
247
7e785937 248void BRepTools_ShapeSet::WriteGeometry(Standard_OStream& OS, const Message_ProgressRange& theProgress)
7fd59977 249{
7e785937 250 // Make nested progress scope for processing geometry
251 Message_ProgressScope aPS(theProgress, "Geometry", 100);
252
253 myCurves2d.Write(OS, aPS.Next(20));
254 if (aPS.UserBreak()) return;
255
256 myCurves.Write(OS, aPS.Next(20));
257 if (aPS.UserBreak()) return;
258
259 WritePolygon3D(OS, Standard_True, aPS.Next(10));
260 if (aPS.UserBreak()) return;
261
262 WritePolygonOnTriangulation(OS, Standard_True, aPS.Next(10));
263 if (aPS.UserBreak()) return;
264
265 mySurfaces.Write(OS, aPS.Next(20));
266 if (aPS.UserBreak()) return;
267
268 WriteTriangulation(OS, Standard_True, aPS.Next(20));
7fd59977 269}
270
271
272//=======================================================================
273//function : ReadGeometry
274//purpose :
275//=======================================================================
276
7e785937 277void BRepTools_ShapeSet::ReadGeometry(Standard_IStream& IS, const Message_ProgressRange& theProgress)
7fd59977 278{
7e785937 279 // Make nested progress scope for processing geometry
280 Message_ProgressScope aPS(theProgress, "Geometry", 100);
281
282 myCurves2d.Read(IS, aPS.Next(20));
283 if (aPS.UserBreak()) return;
284
285 myCurves.Read(IS, aPS.Next(20));
286 if (aPS.UserBreak()) return;
287
288 ReadPolygon3D(IS, aPS.Next(15));
289 if (aPS.UserBreak()) return;
290
291 ReadPolygonOnTriangulation(IS, aPS.Next(15));
292 if (aPS.UserBreak()) return;
293
294 mySurfaces.Read(IS, aPS.Next(15));
295 if (aPS.UserBreak()) return;
296
297 ReadTriangulation(IS, aPS.Next(15));
7fd59977 298}
299
300//=======================================================================
301//function : PrintRegularity
302//purpose :
303//=======================================================================
304
305static void PrintRegularity(const GeomAbs_Shape C,
306 Standard_OStream& OS)
307{
308 switch (C) {
309
310 case GeomAbs_C0 :
311 OS << "C0";
312 break;
313
314 case GeomAbs_G1 :
315 OS << "G1";
316 break;
317
318 case GeomAbs_C1 :
319 OS << "C1";
320 break;
321
322 case GeomAbs_G2 :
323 OS << "G2";
324 break;
325
326 case GeomAbs_C2 :
327 OS << "C2";
328 break;
329
330 case GeomAbs_C3 :
331 OS << "C3";
332 break;
333
334 case GeomAbs_CN :
335 OS << "CN";
336 break;
337
338 }
339}
340
341//=======================================================================
342//function : DumpGeometry
343//purpose :
344//=======================================================================
345
346void BRepTools_ShapeSet::DumpGeometry(const TopoDS_Shape& S,
347 Standard_OStream& OS)const
348{
349 // Dump the geometry
350
351 if (S.ShapeType() == TopAbs_VERTEX) {
352
353 // Dump the point geometry
354 TopoDS_Vertex V = TopoDS::Vertex(S);
355 OS << " Tolerance : " << BRep_Tool::Tolerance(V) << "\n";
356 gp_Pnt p = BRep_Tool::Pnt(V);
357 OS << " - Point 3D : "<<p.X()<<", "<<p.Y()<<", "<<p.Z()<<"\n";
358
359 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
360 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
361
362 while (itrp.More()) {
363 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
364
365 OS << " - Parameter : "<< PR->Parameter();
366 if (PR->IsPointOnCurve()) {
367 OS << " on curve " << myCurves.Index(PR->Curve());
368 }
369
370 else if (PR->IsPointOnCurveOnSurface()) {
371 OS << " on pcurve " << myCurves2d.Index(PR->PCurve());
372 OS << " on surface " << mySurfaces.Index(PR->Surface());
373 }
374
375 else if (PR->IsPointOnSurface()) {
376 OS << ", " << PR->Parameter2() << " on surface ";
377 OS << mySurfaces.Index(PR->Surface());
378 }
379
380 if (!PR->Location().IsIdentity())
381 OS << " location " << Locations().Index(PR->Location());
382 OS << "\n";
383
384 itrp.Next();
385 }
386
387 }
388
389 else if (S.ShapeType() == TopAbs_EDGE) {
390
391 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
392 gp_Pnt2d Pf,Pl;
393
394 // Dump the curve geometry
395 OS << " Tolerance : " << TE->Tolerance() << "\n";
396 if (TE->SameParameter()) OS << " same parametrisation of curves\n";
397 if (TE->SameRange()) OS << " same range on curves\n";
398 if (TE->Degenerated()) OS << " degenerated\n";
399
400 Standard_Real first, last;
401 BRep_ListIteratorOfListOfCurveRepresentation itrc = TE->Curves();
402 while (itrc.More()) {
403 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
404 if (CR->IsCurve3D()) {
405 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
406 GC->Range(first, last);
407 if (!CR->Curve3D().IsNull()) {
408 OS << " - Curve 3D : "<<myCurves.Index(CR->Curve3D());
409 if (!CR->Location().IsIdentity())
410 OS << " location "<<Locations().Index(CR->Location());
411 OS <<", range : " << first << " " << last <<"\n";
412 }
413 }
414 else if (CR->IsCurveOnSurface()) {
415 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
416 GC->Range(first, last);
417 OS <<" - PCurve : "<<myCurves2d.Index(CR->PCurve());
418 if (CR->IsCurveOnClosedSurface()) {
419 OS <<", " << myCurves2d.Index(CR->PCurve2());
420 OS << " (";
421 PrintRegularity(CR->Continuity(),OS);
422 OS <<")";
423 }
424 OS << " on surface "<<mySurfaces.Index(CR->Surface());
425 if (!CR->Location().IsIdentity())
426 OS << " location "<<Locations().Index(CR->Location());
427 OS <<", range : " << first << " " << last <<"\n";
428
429 Handle(BRep_CurveOnSurface) COS =
430 Handle(BRep_CurveOnSurface)::DownCast(CR);
431 COS->UVPoints(Pf,Pl);
432 OS << " UV Points : " <<Pf.X()<<", "<<Pf.Y()<<" ";
433 OS << Pl.X()<<", "<<Pl.Y()<<"\n";
434 if (CR->IsCurveOnClosedSurface()) {
435 Handle(BRep_CurveOnClosedSurface) COCS =
436 Handle(BRep_CurveOnClosedSurface)::DownCast(CR);
437 COCS->UVPoints2(Pf,Pl);
438 OS << " UV Points : " <<Pf.X()<<", "<<Pf.Y()<<" ";
439 OS << Pl.X()<<", "<<Pl.Y()<<"\n";
440 }
441 }
442 else if (CR->IsRegularity()) {
443 OS << " - Regularity ";
444 PrintRegularity(CR->Continuity(),OS);
445 OS << " on surfaces : "<<mySurfaces.Index(CR->Surface());
446 if (!CR->Location().IsIdentity())
447 OS << " location "<<Locations().Index(CR->Location());
448 OS << ", "<<mySurfaces.Index(CR->Surface2());
449 if (!CR->Location2().IsIdentity())
450 OS << " location "<<Locations().Index(CR->Location2());
451 OS << "\n";
452 }
453 else if (CR->IsPolygon3D()) {
454 Handle(BRep_Polygon3D) GC = Handle(BRep_Polygon3D)::DownCast(itrc.Value());
455 if (!GC->Polygon3D().IsNull()) {
456 OS << " - Polygon 3D : "<<myPolygons3D.FindIndex(CR->Polygon3D());
457 if (!CR->Location().IsIdentity())
458 OS << " location "<<Locations().Index(CR->Location());
459 }
460 }
461 else if (CR->IsPolygonOnTriangulation()) {
462 OS << " - PolygonOnTriangulation " << myNodes.FindIndex(CR->PolygonOnTriangulation());
463 if (CR->IsPolygonOnClosedTriangulation()) {
464 OS << " " << myNodes.FindIndex(CR->PolygonOnTriangulation2());
465 }
466 OS << " on triangulation " << myTriangulations.FindIndex(CR->Triangulation());
467 if (!CR->Location().IsIdentity())
468 OS << " location "<<Locations().Index(CR->Location());
586db386 469 OS << "\n";
7fd59977 470 }
471 itrc.Next();
472 }
473 }
474
475 else if (S.ShapeType() == TopAbs_FACE) {
476
477 const TopoDS_Face& F = TopoDS::Face(S);
478 if (BRep_Tool::NaturalRestriction(F))
479 OS << "NaturalRestriction\n";
480
481 // Dump the surface geometry
482 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
483 if (!TF->Surface().IsNull()) {
484 OS << " Tolerance : " <<TF->Tolerance() << "\n";
485 OS << " - Surface : "<<mySurfaces.Index(TF->Surface());
486 if (!S.Location().IsIdentity())
487 OS << " location "<<Locations().Index(S.Location());
488 OS << "\n";
489 }
490 if (!(TF->Triangulation()).IsNull()) {
491 // Dump the triangulation
492 OS << " - Triangulation : " <<myTriangulations.FindIndex(TF->Triangulation());
493 if (!S.Location().IsIdentity())
494 OS << " location " <<Locations().Index(TF->Location());
495 OS << "\n";
496 }
497 }
498
499 OS << "\n";
500}
501
502
503//=======================================================================
504//function : WriteGeometry
505//purpose :
506//=======================================================================
507
6d8f9f4a 508void BRepTools_ShapeSet::WriteGeometry (const TopoDS_Shape& S, Standard_OStream& OS)const
7fd59977 509{
510 // Write the geometry
511
512 if (S.ShapeType() == TopAbs_VERTEX) {
513
514 // Write the point geometry
515 TopoDS_Vertex V = TopoDS::Vertex(S);
516 OS << BRep_Tool::Tolerance(V) << "\n";
517 gp_Pnt p = BRep_Tool::Pnt(V);
518 OS<<p.X()<<" "<<p.Y()<<" "<<p.Z()<<"\n";
519
520 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
521 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
522
523 while (itrp.More()) {
524 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
525
526 OS << PR->Parameter();
527 if (PR->IsPointOnCurve()) {
528 OS << " 1 " << myCurves.Index(PR->Curve());
529 }
530
531 else if (PR->IsPointOnCurveOnSurface()) {
532 OS << " 2 " << myCurves2d.Index(PR->PCurve());
533 OS << " " << mySurfaces.Index(PR->Surface());
534 }
535
536 else if (PR->IsPointOnSurface()) {
537 OS << " 3 " << PR->Parameter2() << " ";
538 OS << mySurfaces.Index(PR->Surface());
539 }
540
541 OS << " " << Locations().Index(PR->Location());
542 OS << "\n";
543
544 itrp.Next();
545 }
546
547 OS << "0 0\n"; // end representations
548
549 }
550
551 else if (S.ShapeType() == TopAbs_EDGE) {
552
553 // Write the curve geometry
554
555 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
556
557 OS << " " << TE->Tolerance() << " ";
558 OS << ((TE->SameParameter()) ? 1 : 0) << " ";
559 OS << ((TE->SameRange()) ? 1 : 0) << " ";
560 OS << ((TE->Degenerated()) ? 1 : 0) << "\n";
561
562 Standard_Real first, last;
563 BRep_ListIteratorOfListOfCurveRepresentation itrc = TE->Curves();
564 while (itrc.More()) {
565 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
566 if (CR->IsCurve3D()) {
567 if (!CR->Curve3D().IsNull()) {
568 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
569 GC->Range(first, last);
570 OS << "1 "; // -1- Curve 3D
571 OS << " "<<myCurves.Index(CR->Curve3D());
572 OS << " "<<Locations().Index(CR->Location());
573 OS << " "<<first<<" "<<last;
574 OS << "\n";
575 }
576 }
577 else if (CR->IsCurveOnSurface()) {
578 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
579 GC->Range(first, last);
580 if (!CR->IsCurveOnClosedSurface())
581 OS << "2 "; // -2- Curve on surf
582 else
583 OS << "3 "; // -3- Curve on closed surf
584 OS <<" "<<myCurves2d.Index(CR->PCurve());
585 if (CR->IsCurveOnClosedSurface()) {
586 OS <<" " << myCurves2d.Index(CR->PCurve2());
587 PrintRegularity(CR->Continuity(),OS);
588 }
589 OS << " " << mySurfaces.Index(CR->Surface());
590 OS << " " << Locations().Index(CR->Location());
591 OS << " "<<first<<" "<<last;
592 OS << "\n";
593
594 // Write UV Points // for XML Persistence higher performance
595 if (FormatNb() == 2)
596 {
597 gp_Pnt2d Pf,Pl;
598 if (CR->IsCurveOnClosedSurface()) {
599 Handle(BRep_CurveOnClosedSurface) COCS =
600 Handle(BRep_CurveOnClosedSurface)::DownCast(CR);
601 COCS->UVPoints2(Pf,Pl);
602 }
603 else {
604 Handle(BRep_CurveOnSurface) COS =
605 Handle(BRep_CurveOnSurface)::DownCast(CR);
606 COS->UVPoints(Pf,Pl);
607 }
608 OS << Pf.X() << " " << Pf.Y() << " " << Pl.X() << " " << Pl.Y() << "\n";
609 }
610 }
611 else if (CR->IsRegularity()) {
612 OS << "4 "; // -4- Regularity
613 PrintRegularity(CR->Continuity(),OS);
614 OS << " "<<mySurfaces.Index(CR->Surface());
615 OS << " "<<Locations().Index(CR->Location());
616 OS << " "<<mySurfaces.Index(CR->Surface2());
617 OS << " "<<Locations().Index(CR->Location2());
618 OS << "\n";
619 }
620
621 else if (myWithTriangles) { // for XML Persistence
622 if (CR->IsPolygon3D()) {
623 Handle(BRep_Polygon3D) GC = Handle(BRep_Polygon3D)::DownCast(itrc.Value());
624 if (!GC->Polygon3D().IsNull()) {
625 OS << "5 "; // -5- Polygon3D
626 OS << " "<<myPolygons3D.FindIndex(CR->Polygon3D());
627 OS << " "<<Locations().Index(CR->Location());
628 OS << "\n";
629 }
630 }
631 else if (CR->IsPolygonOnTriangulation()) {
632 Handle(BRep_PolygonOnTriangulation) PT =
633 Handle(BRep_PolygonOnTriangulation)::DownCast(itrc.Value());
634 if (!CR->IsPolygonOnClosedTriangulation())
635 OS << "6 "; // -6- Polygon on triangulation
636 else
637 OS << "7 "; // -7- Polygon on closed triangulation
638 OS << " " << myNodes.FindIndex(PT->PolygonOnTriangulation());
639 if (CR->IsPolygonOnClosedTriangulation()) {
640 OS << " " << myNodes.FindIndex(PT->PolygonOnTriangulation2());
641 }
642 OS << " " << myTriangulations.FindIndex(PT->Triangulation());
643 OS << " "<<Locations().Index(CR->Location());
644 OS << "\n";
645 }
646 }
647
648 itrc.Next();
649 }
650 OS << "0\n"; // end of the list of representations
651 }
652
653 else if (S.ShapeType() == TopAbs_FACE) {
654
655 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
656 const TopoDS_Face& F = TopoDS::Face(S);
657
658 if (!(TF->Surface()).IsNull()) {
659 OS << ((BRep_Tool::NaturalRestriction(F)) ? 1 : 0);
660 OS << " ";
661 // Write the surface geometry
662 OS << " " <<TF->Tolerance();
663 OS << " " <<mySurfaces.Index(TF->Surface());
664 OS << " " <<Locations().Index(TF->Location());
665 OS << "\n";
666 }
667 else //For correct reading of null face
668 {
669 OS << 0;
670 OS << " ";
671 OS << " " <<TF->Tolerance();
672 OS << " " << 0;
673 OS << " " << 0;
674 OS << "\n";
675 }
8c787b5f 676 if (myWithTriangles || TF->Surface().IsNull()) { // for XML Persistence
7fd59977 677 if (!(TF->Triangulation()).IsNull()) {
678 OS << 2;
679 OS << " ";
680 // Write the triangulation
681 OS << " " <<myTriangulations.FindIndex(TF->Triangulation());
682 }
683 }
684 }
685
686}
687
688//=======================================================================
689//function : ReadRegularity
690//purpose :
691//=======================================================================
692
693static GeomAbs_Shape ReadRegularity(Standard_IStream& IS)
694{
695 char buffer[255];
696 IS >> buffer;
697 switch (buffer[0]) {
698
699 case 'C' :
700 switch (buffer[1]) {
701
702 case '0' :
703 return GeomAbs_C0;
704
705 case '1' :
706 return GeomAbs_C1;
707
708 case '2' :
709 return GeomAbs_C2;
710
711 case '3' :
712 return GeomAbs_C3;
713
714 case 'N' :
715 return GeomAbs_CN;
716 }
717 break;
718
719 case 'G' :
720 switch (buffer[1]) {
721
722 case '1' :
723 return GeomAbs_G1;
724
725 case '2' :
726 return GeomAbs_G2;
727
728 }
729 break;
730 }
731 return GeomAbs_C0;
732}
733
734//=======================================================================
735//function : ReadGeometry
736//purpose :
737//=======================================================================
738
6d8f9f4a 739void BRepTools_ShapeSet::ReadGeometry (const TopAbs_ShapeEnum T,
740 Standard_IStream& IS,
741 TopoDS_Shape& S)
7fd59977 742{
743 // Read the geometry
744
1d47d8d0 745 Standard_Integer val,c,pc,pc2 = 0,s,s2,l,l2,t, pt, pt2 = 0;
7fd59977 746 Standard_Real tol,X,Y,Z,first,last,p1,p2;
747 Standard_Real PfX,PfY,PlX,PlY;
748 gp_Pnt2d aPf, aPl;
749 Standard_Boolean closed;
7fd59977 750 GeomAbs_Shape reg = GeomAbs_C0;
7fd59977 751 switch (T) {
752
753
754 //---------
755 // vertex
756 //---------
757
758 case TopAbs_VERTEX :
759 {
760 TopoDS_Vertex& V = TopoDS::Vertex(S);
761
762 // Read the point geometry
71598a83 763 GeomTools::GetReal(IS, tol);
764 GeomTools::GetReal(IS, X);
765 GeomTools::GetReal(IS, Y);
766 GeomTools::GetReal(IS, Z);
7fd59977 767 myBuilder.MakeVertex(V,gp_Pnt(X,Y,Z),tol);
768 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(V.TShape());
769
770 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
771 TopLoc_Location L;
772
773 do {
71598a83 774 GeomTools::GetReal(IS, p1);
775 IS >> val;
7fd59977 776
777 Handle(BRep_PointRepresentation) PR;
778 switch (val) {
779
780 case 1 :
781 {
782 IS >> c;
783
784// Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
785 if (myCurves.Curve(c).IsNull())
786 break;
787// Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
788
789 Handle(BRep_PointOnCurve) POC =
790 new BRep_PointOnCurve(p1,
791 myCurves.Curve(c),
792 L);
793 PR = POC;
794 }
795 break;
796
797 case 2 :
798 {
799 IS >> pc >> s;
800
801// Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
802 if (myCurves2d.Curve2d(pc).IsNull() ||
803 mySurfaces.Surface(s).IsNull())
804 break;
805// Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
806
807 Handle(BRep_PointOnCurveOnSurface) POC =
808 new BRep_PointOnCurveOnSurface(p1,
809 myCurves2d.Curve2d(pc),
810 mySurfaces.Surface(s),
811 L);
812 PR = POC;
813 }
814 break;
815
816 case 3 :
817 {
71598a83 818 GeomTools::GetReal(IS, p2);
819 IS >> s;
7fd59977 820
821// Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
822 if (mySurfaces.Surface(s).IsNull())
823 break;
824// Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
825
826 Handle(BRep_PointOnSurface) POC =
827 new BRep_PointOnSurface(p1,p2,
828 mySurfaces.Surface(s),
829 L);
830 PR = POC;
831 }
832 break;
833 }
834
835 if (val > 0) {
836 IS >> l;
837 if (!PR.IsNull()) {
838 PR->Location(Locations().Location(l));
839 lpr.Append(PR);
840 }
841 }
842 } while (val > 0);
843 }
844 break;
845
846
847 //---------
848 // edge
849 //---------
850
851
852 case TopAbs_EDGE :
853
854 // Create an edge
855 {
856 TopoDS_Edge& E = TopoDS::Edge(S);
857
858 myBuilder.MakeEdge(E);
859
860 // Read the curve geometry
71598a83 861 GeomTools::GetReal(IS, tol);
7fd59977 862 IS >> val;
863 myBuilder.SameParameter(E,(val == 1));
864 IS >> val;
865 myBuilder.SameRange(E,(val == 1));
866 IS >> val;
867 myBuilder.Degenerated(E,(val == 1));
868
869 do {
870 IS >> val;
871 switch (val) {
872
873 case 1 : // -1- Curve 3D
874 IS >> c >> l;
875 if (!myCurves.Curve(c).IsNull()) {
876 myBuilder.UpdateEdge(E,myCurves.Curve(c),
877 Locations().Location(l),tol);
878 }
71598a83 879 GeomTools::GetReal(IS, first);
880 GeomTools::GetReal(IS, last);
7fd59977 881 if (!myCurves.Curve(c).IsNull()) {
882 Standard_Boolean Only3d = Standard_True;
883 myBuilder.Range(E,first,last,Only3d);
884 }
885 break;
886
887
888 case 2 : // -2- Curve on surf
889 case 3 : // -3- Curve on closed surf
890 closed = (val == 3);
891 IS >> pc;
892 if (closed) {
893 IS >> pc2;
894 reg = ReadRegularity(IS);
895 }
896
897 // surface, location
898 IS >> s >> l;
899
900 // range
71598a83 901 GeomTools::GetReal(IS, first);
902 GeomTools::GetReal(IS, last);
7fd59977 903
904 // read UV Points // for XML Persistence higher performance
905 if (FormatNb() == 2)
906 {
71598a83 907 GeomTools::GetReal(IS, PfX);
908 GeomTools::GetReal(IS, PfY);
909 GeomTools::GetReal(IS, PlX);
910 GeomTools::GetReal(IS, PlY);
7fd59977 911 aPf = gp_Pnt2d(PfX,PfY);
912 aPl = gp_Pnt2d(PlX,PlY);
913 }
914
915// Modified by Sergey KHROMOV - Wed Apr 24 12:11:16 2002 Begin
916 if (myCurves2d.Curve2d(pc).IsNull() ||
917 (closed && myCurves2d.Curve2d(pc2).IsNull()) ||
918 mySurfaces.Surface(s).IsNull())
919 break;
920// Modified by Sergey KHROMOV - Wed Apr 24 12:11:17 2002 End
921
922 if (closed) {
923 if (FormatNb() == 2)
924 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
925 myCurves2d.Curve2d(pc2),
926 mySurfaces.Surface(s),
927 Locations().Location(l),tol,
928 aPf, aPl);
929 else
930 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
931 myCurves2d.Curve2d(pc2),
932 mySurfaces.Surface(s),
933 Locations().Location(l),tol);
934
935 myBuilder.Continuity(E,
936 mySurfaces.Surface(s),
937 mySurfaces.Surface(s),
938 Locations().Location(l),
939 Locations().Location(l),
940 reg);
941 }
942 else
943 {
944 if (FormatNb() == 2)
945 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
946 mySurfaces.Surface(s),
947 Locations().Location(l),tol,
948 aPf, aPl);
949 else
950 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
951 mySurfaces.Surface(s),
952 Locations().Location(l),tol);
953 }
954 myBuilder.Range(E,
955 mySurfaces.Surface(s),
956 Locations().Location(l),
957 first,last);
958 break;
959
960 case 4 : // -4- Regularity
961 reg = ReadRegularity(IS);
962 IS >> s >> l >> s2 >> l2;
963// Modified by Sergey KHROMOV - Wed Apr 24 12:39:13 2002 Begin
964 if (mySurfaces.Surface(s).IsNull() ||
965 mySurfaces.Surface(s2).IsNull())
966 break;
967// Modified by Sergey KHROMOV - Wed Apr 24 12:39:14 2002 End
968 myBuilder.Continuity(E,
969 mySurfaces.Surface(s),
970 mySurfaces.Surface(s2),
971 Locations().Location(l),
972 Locations().Location(l2),
973 reg);
974 break;
975
976 case 5 : // -5- Polygon3D
977 IS >> c >> l;
978//szy-02.05.2004 myBuilder.UpdateEdge(E,Handle(Poly_Polygon3D)::DownCast(myPolygons3D(c)));
979 if (c > 0 && c <= myPolygons3D.Extent())
980 myBuilder.UpdateEdge(E,Handle(Poly_Polygon3D)::DownCast(myPolygons3D(c)), Locations().Location(l));
981 break;
982
983 case 6 :
984 case 7 :
985 closed = (val == 7);
986 IS >> pt;
987 if (closed) {
988 IS >> pt2;
989 }
990 IS >> t >> l;
991 if (closed) {
992 if (t > 0 && t <= myTriangulations.Extent() &&
993 pt > 0 && pt <= myNodes.Extent() &&
994 pt2 > 0 && pt2 <= myNodes.Extent())
995 myBuilder.UpdateEdge
996 (E, Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
997 Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt2)),
998 Handle(Poly_Triangulation)::DownCast(myTriangulations(t)),
999 Locations().Location(l));
1000 }
1001 else {
1002 if (t > 0 && t <= myTriangulations.Extent() &&
1003 pt > 0 && pt <= myNodes.Extent())
1004 myBuilder.UpdateEdge
1005 (E,Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
1006 Handle(Poly_Triangulation)::DownCast(myTriangulations(t)),
1007 Locations().Location(l));
1008 }
1009 // range
1010
1011 break;
1012
1013 }
1014 } while (val > 0);
1015 }
1016 break;
1017
1018
1019 //---------
1020 // wire
1021 //---------
1022
1023 case TopAbs_WIRE :
1024 myBuilder.MakeWire(TopoDS::Wire(S));
1025 break;
1026
1027
1028 //---------
1029 // face
1030 //---------
1031
1032 case TopAbs_FACE :
1033 {
1034 // create a face :
1035 TopoDS_Face& F = TopoDS::Face(S);
04232180 1036// std::streampos pos;
7fd59977 1037 myBuilder.MakeFace(F);
1038
1039 IS >> val; // natural restriction
1040 if (val == 0 || val == 1) {
71598a83 1041 GeomTools::GetReal(IS, tol);
1042 IS >> s >> l;
7fd59977 1043// Modified by Sergey KHROMOV - Wed Apr 24 12:39:13 2002 Begin
1044 if (!mySurfaces.Surface(s).IsNull()) {
1045// Modified by Sergey KHROMOV - Wed Apr 24 12:39:14 2002 End
1046 myBuilder.UpdateFace(TopoDS::Face(S),
1047 mySurfaces.Surface(s),
1048 Locations().Location(l),tol);
1049 myBuilder.NaturalRestriction(TopoDS::Face(S),(val == 1));
1050 }
1051// pos = IS.tellg();
1052// IS >> val;
1053 }
1054 else if(val == 2) {
1055 //only triangulation
1056 IS >> s;
1057 myBuilder.UpdateFace(TopoDS::Face(S),
1058 Handle(Poly_Triangulation)::DownCast(myTriangulations(s)));
1059 }
1060// else pos = IS.tellg();
1061
1062 // BUC60769
1063
1064 if(val == 2) break;
1065
1066 char string[260];
1067 IS.getline ( string, 256, '\n' );
1068 IS.getline ( string, 256, '\n' );
1069
1070 if (string[0] == '2') {
1071 // cas triangulation
1072 s = atoi ( &string[2] );
1073 if (s > 0 && s <= myTriangulations.Extent())
1074 myBuilder.UpdateFace(TopoDS::Face(S),
1075 Handle(Poly_Triangulation)::DownCast(myTriangulations(s)));
1076 }
1077// else IS.seekg(pos);
1078 }
1079 break;
1080
1081
1082 //---------
1083 // shell
1084 //---------
1085
1086 case TopAbs_SHELL :
1087 myBuilder.MakeShell(TopoDS::Shell(S));
1088 break;
1089
1090
1091 //---------
1092 // solid
1093 //---------
1094
1095 case TopAbs_SOLID :
1096 myBuilder.MakeSolid(TopoDS::Solid(S));
1097 break;
1098
1099
1100 //---------
1101 // compsolid
1102 //---------
1103
1104 case TopAbs_COMPSOLID :
1105 myBuilder.MakeCompSolid(TopoDS::CompSolid(S));
1106 break;
1107
1108
1109 //---------
1110 // compound
1111 //---------
1112
1113 case TopAbs_COMPOUND :
1114 myBuilder.MakeCompound(TopoDS::Compound(S));
1115 break;
1116
1117 default:
1118 break;
1119 }
1120
1121}
1122
1123
1124
1125//=======================================================================
1126//function : AddShapes
1127//purpose :
1128//=======================================================================
1129
1130void BRepTools_ShapeSet::AddShapes(TopoDS_Shape& S1,
1131 const TopoDS_Shape& S2)
1132{
1133 myBuilder.Add(S1,S2);
1134}
1135
1136//=======================================================================
1137//function : Check
1138//purpose :
1139//=======================================================================
1140
1141void BRepTools_ShapeSet::Check(const TopAbs_ShapeEnum T,
1142 TopoDS_Shape& S)
1143{
1144 if (T == TopAbs_FACE) {
1145 const TopoDS_Face& F = TopoDS::Face(S);
1146 BRepTools::Update(F);
1147 }
1148}
1149
1150
1151
1152//=======================================================================
1153//function : WritePolygonOnTriangulation
1154//purpose :
1155//=======================================================================
1156
7e785937 1157void BRepTools_ShapeSet::WritePolygonOnTriangulation(Standard_OStream& OS,
1158 const Standard_Boolean Compact,
1159 const Message_ProgressRange& theProgress)const
7fd59977 1160{
1161 Standard_Integer i, j, nbpOntri = myNodes.Extent();
1162
7e785937 1163 Message_ProgressScope aPS(theProgress, "Polygons On Triangulation", nbpOntri);
7fd59977 1164 if (Compact)
586db386 1165 OS << "PolygonOnTriangulations " << nbpOntri << "\n";
7fd59977 1166 else {
1167 OS << " -------\n";
1168 OS <<"Dump of " << nbpOntri << " PolygonOnTriangulations\n";
1169 OS << " -------\n";
1170 }
1171
1172 Handle(Poly_PolygonOnTriangulation) Poly;
1173 Handle(TColStd_HArray1OfReal) Param;
7e785937 1174 for (i=1; i<=nbpOntri && aPS.More(); i++, aPS.Next()) {
7fd59977 1175 Poly = Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(i));
1176 const TColStd_Array1OfInteger& Nodes = Poly->Nodes();
1177 if (!Compact) {
1178 OS << " "<< i << " : PolygonOnTriangulation with " << Nodes.Length() << " Nodes\n";
1179 }
1180 else OS << Nodes.Length()<<" ";
1181 if (!Compact) OS <<" ";
1182 for (j=1; j <= Nodes.Length(); j++) OS << Nodes.Value(j) << " ";
1183 OS << "\n";
1184
1185 // writing parameters:
1186 Param = Poly->Parameters();
1187 if (Compact) OS <<"p ";
1188
1189 // write the deflection
1190 if (!Compact) OS << " Deflection : ";
1191 OS <<Poly->Deflection() << " ";
1192 if (!Compact) OS << "\n";
1193
1194 if (!Param.IsNull()) {
1195 if (!Compact) {
586db386 1196 OS << " Parameters :";
7fd59977 1197 }
1198 else OS << "1 " ;
1199 if (!Compact) OS <<" ";
1200 for (j=1; j <= Param->Length(); j++) OS << Param->Value(j) << " ";
1201 OS << "\n";
1202 }
1203 else OS <<"0 \n";
1204 }
1205}
1206
1207//=======================================================================
1208//function : DumpPolygonOnTriangulation
1209//purpose :
1210//=======================================================================
1211
1212void BRepTools_ShapeSet::DumpPolygonOnTriangulation(Standard_OStream& OS)const
1213{
1214 WritePolygonOnTriangulation(OS, Standard_False);
1215}
1216
1217//=======================================================================
1218//function : ReadPolygonOnTriangulation
1219//purpose :
1220//=======================================================================
1221
7e785937 1222void BRepTools_ShapeSet::ReadPolygonOnTriangulation(Standard_IStream& IS,
1223 const Message_ProgressRange& theProgress)
7fd59977 1224{
1225 char buffer[255];
1226 IS >> buffer;
1227 if (strstr(buffer,"PolygonOnTriangulations") == NULL) return;
1228 Standard_Integer i, j, val, nbpol = 0, nbnodes =0;
1229 Standard_Integer hasparameters;
1230 Standard_Real par;
1231 Handle(TColStd_HArray1OfReal) Param;
1232 Handle(Poly_PolygonOnTriangulation) Poly;
1233 IS >> nbpol;
1234 //OCC19559
7e785937 1235 Message_ProgressScope aPS(theProgress, "Polygons On Triangulation", nbpol);
1236 for (i=1; i<=nbpol&& aPS.More(); i++, aPS.Next()) {
7fd59977 1237 IS >> nbnodes;
1238 TColStd_Array1OfInteger Nodes(1, nbnodes);
1239 for (j = 1; j <= nbnodes; j++) {
1240 IS >> val;
1241 Nodes(j) = val;
1242 }
1243 IS >> buffer;
1244// if (!strcasecmp(buffer, "p")) {
1245 Standard_Real def;
71598a83 1246 GeomTools::GetReal(IS, def);
7fd59977 1247 IS >> hasparameters;
1248 if (hasparameters) {
1249 TColStd_Array1OfReal Param1(1, nbnodes);
1250 for (j = 1; j <= nbnodes; j++) {
71598a83 1251 GeomTools::GetReal(IS, par);
7fd59977 1252 Param1(j) = par;
1253 }
1254 Poly = new Poly_PolygonOnTriangulation(Nodes, Param1);
1255 }
1256 else Poly = new Poly_PolygonOnTriangulation(Nodes);
1257 Poly->Deflection(def);
1258// }
1259// else {
1260// IS.seekg(ppp);
1261// Poly = new Poly_PolygonOnTriangulation(Nodes);
1262// }
1263 myNodes.Add(Poly);
1264 }
1265// }
1266// else IS.seekg(pos);
1267}
1268
1269
1270
1271//=======================================================================
1272//function : WritePolygon3D
1273//purpose :
1274//=======================================================================
1275
7e785937 1276void BRepTools_ShapeSet::WritePolygon3D(Standard_OStream& OS,
1277 const Standard_Boolean Compact,
1278 const Message_ProgressRange& theProgress)const
7fd59977 1279{
1280 Standard_Integer i, j, nbpol = myPolygons3D.Extent();
1281
7e785937 1282 Message_ProgressScope aPS(theProgress, "3D Polygons", nbpol);
7fd59977 1283
1284 if (Compact)
586db386 1285 OS << "Polygon3D " << nbpol << "\n";
7fd59977 1286 else {
1287 OS << " -------\n";
1288 OS <<"Dump of " << nbpol << " Polygon3Ds\n";
1289 OS << " -------\n";
1290 }
1291
1292 Handle(Poly_Polygon3D) P;
7e785937 1293 for (i = 1; i <= nbpol && aPS.More(); i++, aPS.Next()) {
7fd59977 1294 P = Handle(Poly_Polygon3D)::DownCast(myPolygons3D(i));
1295 if (Compact) {
1296 OS << P->NbNodes() << " ";
1297 OS << ((P->HasParameters()) ? "1" : "0") << "\n";
1298 }
1299 else {
1300 OS << " "<< i << " : Polygon3D with " << P->NbNodes() << " Nodes\n";
1301 OS << ((P->HasParameters()) ? "with" : "without") << " parameters\n";
1302 }
1303
1304
1305 // write the deflection
1306 if (!Compact) OS << "Deflection : ";
1307 OS << P->Deflection() << "\n";
1308
1309 // write the nodes
1310 if (!Compact) OS << "\nNodes :\n";
1311
1312 Standard_Integer i1, nbNodes = P->NbNodes();
1313 const TColgp_Array1OfPnt& Nodes = P->Nodes();
1314 for (j = 1; j <= nbNodes; j++) {
04232180 1315 if (!Compact) OS << std::setw(10) << j << " : ";
1316 if (!Compact) OS << std::setw(17);
7fd59977 1317 OS << Nodes(j).X() << " ";
04232180 1318 if (!Compact) OS << std::setw(17);
7fd59977 1319 OS << Nodes(j).Y() << " ";
04232180 1320 if (!Compact) OS << std::setw(17);
7fd59977 1321 OS << Nodes(j).Z();
1322 if (!Compact) OS << "\n";
1323 else OS << " ";
1324 }
1325 OS <<"\n";
1326
1327 if (P->HasParameters()) {
1328 if (!Compact) OS << "\nParameters :\n";
1329 const TColStd_Array1OfReal& Param = P->Parameters();
1330 for ( i1 = 1; i1 <= nbNodes; i1++ ) {
1331 OS << Param(i1) << " ";
1332 }
1333 OS <<"\n";
1334 }
1335 }
1336}
1337
1338//=======================================================================
1339//function : DumpPolygon3D
1340//purpose :
1341//=======================================================================
1342
1343void BRepTools_ShapeSet::DumpPolygon3D(Standard_OStream& OS)const
1344{
1345 WritePolygon3D(OS, Standard_False);
1346}
1347
1348
1349//=======================================================================
1350//function : ReadPolygon3D
1351//purpose :
1352//=======================================================================
1353
7e785937 1354void BRepTools_ShapeSet::ReadPolygon3D(Standard_IStream& IS, const Message_ProgressRange& theProgress)
7fd59977 1355{
1356 char buffer[255];
1357 // Standard_Integer i, j, p, val, nbpol, nbnodes, hasparameters;
1358 Standard_Integer i, j, p, nbpol=0, nbnodes =0, hasparameters = Standard_False;
1359 Standard_Real d, x, y, z;
1360
1361 IS >> buffer;
1362 if (strstr(buffer,"Polygon3D") == NULL) return;
1363 Handle(Poly_Polygon3D) P;
1364 IS >> nbpol;
1365 //OCC19559
7e785937 1366 Message_ProgressScope aPS(theProgress, "3D Polygons", nbpol);
1367 for (i=1; i<=nbpol && aPS.More(); i++, aPS.Next()) {
7fd59977 1368 IS >> nbnodes;
1369 IS >> hasparameters;
1370 TColgp_Array1OfPnt Nodes(1, nbnodes);
71598a83 1371 GeomTools::GetReal(IS, d);
7fd59977 1372 for (j = 1; j <= nbnodes; j++) {
71598a83 1373 GeomTools::GetReal(IS, x);
1374 GeomTools::GetReal(IS, y);
1375 GeomTools::GetReal(IS, z);
7fd59977 1376 Nodes(j).SetCoord(x,y,z);
1377 }
1378 if (hasparameters) {
1379 TColStd_Array1OfReal Param(1,nbnodes);
1380 for (p = 1; p <= nbnodes; p++) {
71598a83 1381 GeomTools::GetReal(IS, Param(p));
7fd59977 1382 }
1383 P = new Poly_Polygon3D(Nodes, Param);
1384 }
1385 else P = new Poly_Polygon3D(Nodes);
1386 P->Deflection(d);
1387 myPolygons3D.Add(P);
1388 }
1389}
1390
1391
1392
1393//=======================================================================
1394//function : WriteTriangulation
1395//purpose :
1396//=======================================================================
1397
1398void BRepTools_ShapeSet::WriteTriangulation(Standard_OStream& OS,
6d8f9f4a 1399 const Standard_Boolean Compact,
7e785937 1400 const Message_ProgressRange& theProgress)const
7fd59977 1401{
1402 Standard_Integer i, j, nbNodes, nbtri = myTriangulations.Extent();
1403 Standard_Integer nbTriangles = 0, n1, n2, n3;
6d8f9f4a 1404
7e785937 1405 Message_ProgressScope aPS(theProgress, "Triangulations", nbtri);
7fd59977 1406
1407 if (Compact)
586db386 1408 OS << "Triangulations " << nbtri << "\n";
7fd59977 1409 else {
1410 OS << " -------\n";
1411 OS <<"Dump of " << nbtri << " Triangulations\n";
1412 OS << " -------\n";
1413 }
616d8d0a 1414
7fd59977 1415 Handle(Poly_Triangulation) T;
7e785937 1416 for (i = 1; i <= nbtri && aPS.More(); i++, aPS.Next()) {
7fd59977 1417
1418 T = Handle(Poly_Triangulation)::DownCast(myTriangulations(i));
1419 if (Compact) {
1420 OS << T->NbNodes() << " " << T->NbTriangles() << " ";
1421 OS << ((T->HasUVNodes()) ? "1" : "0") << " ";
1422 }
1423 else {
1424 OS << " "<< i << " : Triangulation with " << T->NbNodes() << " Nodes and "
1425 << T->NbTriangles() <<" Triangles\n";
1426 OS << " "<<((T->HasUVNodes()) ? "with" : "without") << " UV nodes\n";
1427
1428 }
1429
1430 // write the deflection
1431
1432 if (!Compact) OS << " Deflection : ";
1433 OS <<T->Deflection() << "\n";
1434
1435 // write the 3d nodes
1436
1437 if (!Compact) OS << "\n3D Nodes :\n";
1438
1439 nbNodes = T->NbNodes();
1440 const TColgp_Array1OfPnt& Nodes = T->Nodes();
1441 for (j = 1; j <= nbNodes; j++) {
04232180 1442 if (!Compact) OS << std::setw(10) << j << " : ";
1443 if (!Compact) OS << std::setw(17);
7fd59977 1444 OS << Nodes(j).X() << " ";
04232180 1445 if (!Compact) OS << std::setw(17);
7fd59977 1446 OS << Nodes(j).Y() << " ";
04232180 1447 if (!Compact) OS << std::setw(17);
7fd59977 1448 OS << Nodes(j).Z();
1449 if (!Compact) OS << "\n";
1450 else OS << " ";
1451 }
1452
1453 if (T->HasUVNodes()) {
1454 if (!Compact) OS << "\nUV Nodes :\n";
1455 const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes();
1456 for (j = 1; j <= nbNodes; j++) {
04232180 1457 if (!Compact) OS << std::setw(10) << j << " : ";
1458 if (!Compact) OS << std::setw(17);
7fd59977 1459 OS << UVNodes(j).X() << " ";
04232180 1460 if (!Compact) OS << std::setw(17);
7fd59977 1461 OS << UVNodes(j).Y();
1462 if (!Compact) OS << "\n";
1463 else OS << " ";
1464 }
1465 }
1466
1467 if (!Compact) OS << "\nTriangles :\n";
1468 nbTriangles = T->NbTriangles();
1469 const Poly_Array1OfTriangle& Triangles = T->Triangles();
1470 for (j = 1; j <= nbTriangles; j++) {
04232180 1471 if (!Compact) OS << std::setw(10) << j << " : ";
7fd59977 1472 Triangles(j).Get(n1, n2, n3);
04232180 1473 if (!Compact) OS << std::setw(10);
7fd59977 1474 OS << n1 << " ";
04232180 1475 if (!Compact) OS << std::setw(10);
7fd59977 1476 OS << n2 << " ";
04232180 1477 if (!Compact) OS << std::setw(10);
7fd59977 1478 OS << n3;
1479 if (!Compact) OS << "\n";
1480 else OS << " ";
1481 }
1482 OS << "\n";
1483 }
1484}
1485
1486//=======================================================================
1487//function : DumpTriangulation
1488//purpose :
1489//=======================================================================
1490
1491void BRepTools_ShapeSet::DumpTriangulation(Standard_OStream& OS)const
1492{
1493 WriteTriangulation(OS, Standard_False);
1494}
1495
1496
1497//=======================================================================
1498//function : ReadTriangulation
1499//purpose :
1500//=======================================================================
1501
7e785937 1502void BRepTools_ShapeSet::ReadTriangulation(Standard_IStream& IS, const Message_ProgressRange& theProgress)
7fd59977 1503{
1504 char buffer[255];
1505 // Standard_Integer i, j, val, nbtri;
1506 Standard_Integer i, j, nbtri =0;
1507 Standard_Real d, x, y, z;
1508 Standard_Integer nbNodes =0, nbTriangles=0;
1509 Standard_Boolean hasUV= Standard_False;
1510
1511 Handle(Poly_Triangulation) T;
1512
1513 IS >> buffer;
1514 if (strstr(buffer,"Triangulations") == NULL) return;
1515
1516 IS >> nbtri;
1517 //OCC19559
7e785937 1518 Message_ProgressScope aPS(theProgress, "Triangulations", nbtri);
1519 for (i=1; i<=nbtri && aPS.More();i++, aPS.Next()) {
7fd59977 1520
1521 IS >> nbNodes >> nbTriangles >> hasUV;
71598a83 1522 GeomTools::GetReal(IS, d);
7fd59977 1523
1524 TColgp_Array1OfPnt Nodes(1, nbNodes);
1525 TColgp_Array1OfPnt2d UVNodes(1, nbNodes);
1526
1527 for (j = 1; j <= nbNodes; j++) {
71598a83 1528 GeomTools::GetReal(IS, x);
1529 GeomTools::GetReal(IS, y);
1530 GeomTools::GetReal(IS, z);
7fd59977 1531 Nodes(j).SetCoord(x,y,z);
1532 }
1533
1534 if (hasUV) {
1535 for (j = 1; j <= nbNodes; j++) {
71598a83 1536 GeomTools::GetReal(IS, x);
1537 GeomTools::GetReal(IS, y);
7fd59977 1538 UVNodes(j).SetCoord(x,y);
1539 }
1540 }
1541
1542 // read the triangles
1543 Standard_Integer n1,n2,n3;
1544 Poly_Array1OfTriangle Triangles(1, nbTriangles);
1545 for (j = 1; j <= nbTriangles; j++) {
1546 IS >> n1 >> n2 >> n3;
1547 Triangles(j).Set(n1,n2,n3);
1548 }
1549
1550 if (hasUV) T = new Poly_Triangulation(Nodes,UVNodes,Triangles);
1551 else T = new Poly_Triangulation(Nodes,Triangles);
1552
1553 T->Deflection(d);
1554
1555 myTriangulations.Add(T);
1556 }
1557}