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