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