1 // File: BRepTools_ShapeSet.cxx
2 // Created: Mon Jul 19 17:00:04 1993
3 // Author: Remi LEQUETTE
5 // Modifed: Portage NT 7-5-97 DPF (strcasecmp)
7 #include <Standard_Stream.hxx>
9 #include <BRepTools_ShapeSet.ixx>
11 #include <BRepTools.hxx>
14 #include <TColStd_HArray1OfInteger.hxx>
15 #include <BRep_TFace.hxx>
16 #include <BRep_TEdge.hxx>
17 #include <BRep_TVertex.hxx>
18 #include <BRep_Tool.hxx>
19 #include <BRep_CurveRepresentation.hxx>
20 #include <Poly_Polygon3D.hxx>
21 #include <BRep_Polygon3D.hxx>
22 #include <BRep_PolygonOnSurface.hxx>
23 #include <BRep_PolygonOnClosedSurface.hxx>
24 #include <BRep_PolygonOnTriangulation.hxx>
25 #include <BRep_PolygonOnClosedTriangulation.hxx>
26 #include <BRep_CurveOnSurface.hxx>
27 #include <BRep_CurveOnClosedSurface.hxx>
28 #include <BRep_ListOfCurveRepresentation.hxx>
29 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
30 #include <BRep_PointOnCurve.hxx>
31 #include <BRep_PointOnCurveOnSurface.hxx>
32 #include <BRep_PointOnSurface.hxx>
33 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
35 #include <TopoDS_Vertex.hxx>
37 #include <TColgp_HArray1OfPnt.hxx>
38 #include <TColgp_HArray1OfPnt2d.hxx>
39 #include <TColStd_HArray1OfReal.hxx>
40 #include <Poly_Triangulation.hxx>
41 #include <Poly_PolygonOnTriangulation.hxx>
43 #include <Message_ProgressIndicator.hxx>
44 #include <Message_ProgressSentry.hxx>
47 #define strcasecmp(p,q) strcmp(p,q)
49 #define strcasecmp strcmp
54 // Modified: 02 Nov 2000: BUC60769. JMB, PTV. In order to be able to read BRep
55 // files that came from a platform different from where CasCade
56 // is run, we need the following modifications.
58 // On NT platforms (in BRepTools_ShapeSet):
60 // In Visual C++ 5 (or higher) the fstream::tellg method is not
61 // conform to Standard C++ because it modifies the file pointer
62 // position and returns a wrong position. After that the next
63 // readings are shifted and the reading process stop with errors.
65 // Workaround is following: Now we don`t use tellg for get position in stream.
66 // Now able to read file (when reading TopAbs_FACE) without tellg.
67 // We simple check the next string if there are value that equal 2
68 // (It means a parametr for triangulation).
71 //=======================================================================
72 //function : BRepTools_ShapeSet
74 //=======================================================================
76 BRepTools_ShapeSet::BRepTools_ShapeSet(const Standard_Boolean isWithTriangles)
77 :myWithTriangles(isWithTriangles)
81 //=======================================================================
82 //function : BRepTools_ShapeSet
84 //=======================================================================
86 BRepTools_ShapeSet::BRepTools_ShapeSet (const BRep_Builder& B,
87 const Standard_Boolean isWithTriangles) :
88 myBuilder(B), myWithTriangles(isWithTriangles)
93 //=======================================================================
96 //=======================================================================
98 void BRepTools_ShapeSet::Clear()
103 myPolygons3D.Clear();
104 myPolygons2D.Clear();
106 myTriangulations.Clear();
107 TopTools_ShapeSet::Clear();
111 //=======================================================================
112 //function : AddGeometry
114 //=======================================================================
116 void BRepTools_ShapeSet::AddGeometry(const TopoDS_Shape& S)
120 if (S.ShapeType() == TopAbs_VERTEX) {
122 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
123 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
125 while (itrp.More()) {
126 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
128 if (PR->IsPointOnCurve()) {
129 myCurves.Add(PR->Curve());
132 else if (PR->IsPointOnCurveOnSurface()) {
133 myCurves2d.Add(PR->PCurve());
134 mySurfaces.Add(PR->Surface());
137 else if (PR->IsPointOnSurface()) {
138 mySurfaces.Add(PR->Surface());
141 ChangeLocations().Add(PR->Location());
146 else if (S.ShapeType() == TopAbs_EDGE) {
148 // Add the curve geometry
149 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
150 BRep_ListIteratorOfListOfCurveRepresentation itrc(TE->Curves());
152 while (itrc.More()) {
153 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
154 if (CR->IsCurve3D()) {
155 if (!CR->Curve3D().IsNull()) {
156 myCurves.Add(CR->Curve3D());
157 ChangeLocations().Add(CR->Location());
160 else if (CR->IsCurveOnSurface()) {
161 mySurfaces.Add(CR->Surface());
162 myCurves2d.Add(CR->PCurve());
163 ChangeLocations().Add(CR->Location());
164 if (CR->IsCurveOnClosedSurface())
165 myCurves2d.Add(CR->PCurve2());
167 else if (CR->IsRegularity()) {
168 mySurfaces.Add(CR->Surface());
169 ChangeLocations().Add(CR->Location());
170 mySurfaces.Add(CR->Surface2());
171 ChangeLocations().Add(CR->Location2());
173 else if (myWithTriangles) { // for XML Persistence
174 if (CR->IsPolygon3D()) {
175 if (!CR->Polygon3D().IsNull()) {
176 myPolygons3D.Add(CR->Polygon3D());
177 ChangeLocations().Add(CR->Location());
180 else if (CR->IsPolygonOnTriangulation()) {
181 myTriangulations.Add(CR->Triangulation());
182 myNodes.Add(CR->PolygonOnTriangulation());
183 ChangeLocations().Add(CR->Location());
184 if (CR->IsPolygonOnClosedTriangulation())
185 myNodes.Add(CR->PolygonOnTriangulation2());
187 else if (CR->IsPolygonOnSurface()) {
188 mySurfaces.Add(CR->Surface());
189 myPolygons2D.Add(CR->Polygon());
190 ChangeLocations().Add(CR->Location());
191 if (CR->IsPolygonOnClosedSurface())
192 myPolygons2D.Add(CR->Polygon2());
199 else if (S.ShapeType() == TopAbs_FACE) {
201 // Add the surface geometry
202 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
203 if (!TF->Surface().IsNull()) mySurfaces.Add(TF->Surface());
205 if (myWithTriangles) { // for XML Persistence
206 Handle(Poly_Triangulation) Tr = TF->Triangulation();
207 if (!Tr.IsNull()) myTriangulations.Add(Tr);
210 ChangeLocations().Add(TF->Location());
215 //=======================================================================
216 //function : DumpGeometry
218 //=======================================================================
220 void BRepTools_ShapeSet::DumpGeometry(Standard_OStream& OS)const
225 DumpPolygonOnTriangulation(OS);
227 DumpTriangulation(OS);
231 //=======================================================================
232 //function : WriteGeometry
234 //=======================================================================
236 void BRepTools_ShapeSet::WriteGeometry(Standard_OStream& OS)
239 myCurves2d.SetProgress(GetProgress());
240 myCurves.SetProgress(GetProgress());
241 mySurfaces.SetProgress(GetProgress());
243 if ( !GetProgress().IsNull()) {
244 if(GetProgress()->UserBreak() ) return;
245 GetProgress()->NewScope ( 15, "2D Curves" );
247 myCurves2d.Write(OS);
249 if ( !GetProgress().IsNull()) {
250 if( GetProgress()->UserBreak() ) return;
251 GetProgress()->EndScope();
252 GetProgress()->Show();
254 GetProgress()->NewScope ( 15, "3D Curves" );
258 if ( !GetProgress().IsNull()) {
259 if( GetProgress()->UserBreak() ) return;
260 GetProgress()->EndScope();
261 GetProgress()->Show();
263 GetProgress()->NewScope ( 10, "3D Polygons" );
266 if ( !GetProgress().IsNull()) {
267 if( GetProgress()->UserBreak() ) return;
268 GetProgress()->EndScope();
269 GetProgress()->Show();
271 GetProgress()->NewScope ( 10, "Polygons On Triangulation" );
273 WritePolygonOnTriangulation(OS);
274 if ( !GetProgress().IsNull()) {
275 if( GetProgress()->UserBreak() ) return;
276 GetProgress()->EndScope();
277 GetProgress()->Show();
279 GetProgress()->NewScope ( 10, "Surfaces" );
281 mySurfaces.Write(OS);
282 if ( !GetProgress().IsNull()) {
283 if( GetProgress()->UserBreak() ) return;
284 GetProgress()->EndScope();
285 GetProgress()->Show();
287 GetProgress()->NewScope ( 15, "Triangulations" );
289 WriteTriangulation(OS);
290 if ( !GetProgress().IsNull()) {
291 if( GetProgress()->UserBreak() ) return;
292 GetProgress()->EndScope();
293 GetProgress()->Show();
298 //=======================================================================
299 //function : ReadGeometry
301 //=======================================================================
303 void BRepTools_ShapeSet::ReadGeometry(Standard_IStream& IS)
306 myCurves2d.SetProgress(GetProgress());
307 myCurves.SetProgress(GetProgress());
308 mySurfaces.SetProgress(GetProgress());
310 if ( !GetProgress().IsNull()) {
311 if( GetProgress()->UserBreak() ) return;
312 GetProgress()->NewScope ( 15, "2D Curves" );
316 if ( !GetProgress().IsNull()) {
317 if( GetProgress()->UserBreak() ) return;
318 GetProgress()->EndScope();
319 GetProgress()->Show();
321 GetProgress()->NewScope ( 15, "3D Curves" );
325 if ( !GetProgress().IsNull()) {
326 if( GetProgress()->UserBreak() ) return;
327 GetProgress()->EndScope();
328 GetProgress()->Show();
330 GetProgress()->NewScope ( 10, "3D Polygons" );
333 if ( !GetProgress().IsNull() ) {
334 if( GetProgress()->UserBreak() ) return;
335 GetProgress()->EndScope();
336 GetProgress()->Show();
338 GetProgress()->NewScope ( 10, "Polygons On Triangulation" );
340 ReadPolygonOnTriangulation(IS);
341 if ( !GetProgress().IsNull()) {
342 if( GetProgress()->UserBreak() ) return;
343 GetProgress()->EndScope();
344 GetProgress()->Show();
346 GetProgress()->NewScope ( 10, "Surfaces" );
349 if ( !GetProgress().IsNull() ) {
350 if( GetProgress()->UserBreak() ) return;
351 GetProgress()->EndScope();
352 GetProgress()->Show();
354 GetProgress()->NewScope ( 15, "Triangulations" );
356 ReadTriangulation(IS);
357 if ( !GetProgress().IsNull()) {
358 if( GetProgress()->UserBreak() ) return;
359 GetProgress()->EndScope();
360 GetProgress()->Show();
364 //=======================================================================
365 //function : PrintRegularity
367 //=======================================================================
369 static void PrintRegularity(const GeomAbs_Shape C,
370 Standard_OStream& OS)
405 //=======================================================================
406 //function : DumpGeometry
408 //=======================================================================
410 void BRepTools_ShapeSet::DumpGeometry(const TopoDS_Shape& S,
411 Standard_OStream& OS)const
415 if (S.ShapeType() == TopAbs_VERTEX) {
417 // Dump the point geometry
418 TopoDS_Vertex V = TopoDS::Vertex(S);
419 OS << " Tolerance : " << BRep_Tool::Tolerance(V) << "\n";
420 gp_Pnt p = BRep_Tool::Pnt(V);
421 OS << " - Point 3D : "<<p.X()<<", "<<p.Y()<<", "<<p.Z()<<"\n";
423 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
424 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
426 while (itrp.More()) {
427 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
429 OS << " - Parameter : "<< PR->Parameter();
430 if (PR->IsPointOnCurve()) {
431 OS << " on curve " << myCurves.Index(PR->Curve());
434 else if (PR->IsPointOnCurveOnSurface()) {
435 OS << " on pcurve " << myCurves2d.Index(PR->PCurve());
436 OS << " on surface " << mySurfaces.Index(PR->Surface());
439 else if (PR->IsPointOnSurface()) {
440 OS << ", " << PR->Parameter2() << " on surface ";
441 OS << mySurfaces.Index(PR->Surface());
444 if (!PR->Location().IsIdentity())
445 OS << " location " << Locations().Index(PR->Location());
453 else if (S.ShapeType() == TopAbs_EDGE) {
455 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
458 // Dump the curve geometry
459 OS << " Tolerance : " << TE->Tolerance() << "\n";
460 if (TE->SameParameter()) OS << " same parametrisation of curves\n";
461 if (TE->SameRange()) OS << " same range on curves\n";
462 if (TE->Degenerated()) OS << " degenerated\n";
464 Standard_Real first, last;
465 BRep_ListIteratorOfListOfCurveRepresentation itrc = TE->Curves();
466 while (itrc.More()) {
467 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
468 if (CR->IsCurve3D()) {
469 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
470 GC->Range(first, last);
471 if (!CR->Curve3D().IsNull()) {
472 OS << " - Curve 3D : "<<myCurves.Index(CR->Curve3D());
473 if (!CR->Location().IsIdentity())
474 OS << " location "<<Locations().Index(CR->Location());
475 OS <<", range : " << first << " " << last <<"\n";
478 else if (CR->IsCurveOnSurface()) {
479 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
480 GC->Range(first, last);
481 OS <<" - PCurve : "<<myCurves2d.Index(CR->PCurve());
482 if (CR->IsCurveOnClosedSurface()) {
483 OS <<", " << myCurves2d.Index(CR->PCurve2());
485 PrintRegularity(CR->Continuity(),OS);
488 OS << " on surface "<<mySurfaces.Index(CR->Surface());
489 if (!CR->Location().IsIdentity())
490 OS << " location "<<Locations().Index(CR->Location());
491 OS <<", range : " << first << " " << last <<"\n";
493 Handle(BRep_CurveOnSurface) COS =
494 Handle(BRep_CurveOnSurface)::DownCast(CR);
495 COS->UVPoints(Pf,Pl);
496 OS << " UV Points : " <<Pf.X()<<", "<<Pf.Y()<<" ";
497 OS << Pl.X()<<", "<<Pl.Y()<<"\n";
498 if (CR->IsCurveOnClosedSurface()) {
499 Handle(BRep_CurveOnClosedSurface) COCS =
500 Handle(BRep_CurveOnClosedSurface)::DownCast(CR);
501 COCS->UVPoints2(Pf,Pl);
502 OS << " UV Points : " <<Pf.X()<<", "<<Pf.Y()<<" ";
503 OS << Pl.X()<<", "<<Pl.Y()<<"\n";
506 else if (CR->IsRegularity()) {
507 OS << " - Regularity ";
508 PrintRegularity(CR->Continuity(),OS);
509 OS << " on surfaces : "<<mySurfaces.Index(CR->Surface());
510 if (!CR->Location().IsIdentity())
511 OS << " location "<<Locations().Index(CR->Location());
512 OS << ", "<<mySurfaces.Index(CR->Surface2());
513 if (!CR->Location2().IsIdentity())
514 OS << " location "<<Locations().Index(CR->Location2());
517 else if (CR->IsPolygon3D()) {
518 Handle(BRep_Polygon3D) GC = Handle(BRep_Polygon3D)::DownCast(itrc.Value());
519 if (!GC->Polygon3D().IsNull()) {
520 OS << " - Polygon 3D : "<<myPolygons3D.FindIndex(CR->Polygon3D());
521 if (!CR->Location().IsIdentity())
522 OS << " location "<<Locations().Index(CR->Location());
525 else if (CR->IsPolygonOnTriangulation()) {
526 OS << " - PolygonOnTriangulation " << myNodes.FindIndex(CR->PolygonOnTriangulation());
527 if (CR->IsPolygonOnClosedTriangulation()) {
528 OS << " " << myNodes.FindIndex(CR->PolygonOnTriangulation2());
530 OS << " on triangulation " << myTriangulations.FindIndex(CR->Triangulation());
531 if (!CR->Location().IsIdentity())
532 OS << " location "<<Locations().Index(CR->Location());
539 else if (S.ShapeType() == TopAbs_FACE) {
541 const TopoDS_Face& F = TopoDS::Face(S);
542 if (BRep_Tool::NaturalRestriction(F))
543 OS << "NaturalRestriction\n";
545 // Dump the surface geometry
546 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
547 if (!TF->Surface().IsNull()) {
548 OS << " Tolerance : " <<TF->Tolerance() << "\n";
549 OS << " - Surface : "<<mySurfaces.Index(TF->Surface());
550 if (!S.Location().IsIdentity())
551 OS << " location "<<Locations().Index(S.Location());
554 if (!(TF->Triangulation()).IsNull()) {
555 // Dump the triangulation
556 OS << " - Triangulation : " <<myTriangulations.FindIndex(TF->Triangulation());
557 if (!S.Location().IsIdentity())
558 OS << " location " <<Locations().Index(TF->Location());
567 //=======================================================================
568 //function : WriteGeometry
570 //=======================================================================
572 void BRepTools_ShapeSet::WriteGeometry(const TopoDS_Shape& S,
573 Standard_OStream& OS)const
575 // Write the geometry
577 if (S.ShapeType() == TopAbs_VERTEX) {
579 // Write the point geometry
580 TopoDS_Vertex V = TopoDS::Vertex(S);
581 OS << BRep_Tool::Tolerance(V) << "\n";
582 gp_Pnt p = BRep_Tool::Pnt(V);
583 OS<<p.X()<<" "<<p.Y()<<" "<<p.Z()<<"\n";
585 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
586 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
588 while (itrp.More()) {
589 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
591 OS << PR->Parameter();
592 if (PR->IsPointOnCurve()) {
593 OS << " 1 " << myCurves.Index(PR->Curve());
596 else if (PR->IsPointOnCurveOnSurface()) {
597 OS << " 2 " << myCurves2d.Index(PR->PCurve());
598 OS << " " << mySurfaces.Index(PR->Surface());
601 else if (PR->IsPointOnSurface()) {
602 OS << " 3 " << PR->Parameter2() << " ";
603 OS << mySurfaces.Index(PR->Surface());
606 OS << " " << Locations().Index(PR->Location());
612 OS << "0 0\n"; // end representations
616 else if (S.ShapeType() == TopAbs_EDGE) {
618 // Write the curve geometry
620 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
622 OS << " " << TE->Tolerance() << " ";
623 OS << ((TE->SameParameter()) ? 1 : 0) << " ";
624 OS << ((TE->SameRange()) ? 1 : 0) << " ";
625 OS << ((TE->Degenerated()) ? 1 : 0) << "\n";
627 Standard_Real first, last;
628 BRep_ListIteratorOfListOfCurveRepresentation itrc = TE->Curves();
629 while (itrc.More()) {
630 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
631 if (CR->IsCurve3D()) {
632 if (!CR->Curve3D().IsNull()) {
633 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
634 GC->Range(first, last);
635 OS << "1 "; // -1- Curve 3D
636 OS << " "<<myCurves.Index(CR->Curve3D());
637 OS << " "<<Locations().Index(CR->Location());
638 OS << " "<<first<<" "<<last;
642 else if (CR->IsCurveOnSurface()) {
643 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
644 GC->Range(first, last);
645 if (!CR->IsCurveOnClosedSurface())
646 OS << "2 "; // -2- Curve on surf
648 OS << "3 "; // -3- Curve on closed surf
649 OS <<" "<<myCurves2d.Index(CR->PCurve());
650 if (CR->IsCurveOnClosedSurface()) {
651 OS <<" " << myCurves2d.Index(CR->PCurve2());
652 PrintRegularity(CR->Continuity(),OS);
654 OS << " " << mySurfaces.Index(CR->Surface());
655 OS << " " << Locations().Index(CR->Location());
656 OS << " "<<first<<" "<<last;
659 // Write UV Points // for XML Persistence higher performance
663 if (CR->IsCurveOnClosedSurface()) {
664 Handle(BRep_CurveOnClosedSurface) COCS =
665 Handle(BRep_CurveOnClosedSurface)::DownCast(CR);
666 COCS->UVPoints2(Pf,Pl);
669 Handle(BRep_CurveOnSurface) COS =
670 Handle(BRep_CurveOnSurface)::DownCast(CR);
671 COS->UVPoints(Pf,Pl);
673 OS << Pf.X() << " " << Pf.Y() << " " << Pl.X() << " " << Pl.Y() << "\n";
676 else if (CR->IsRegularity()) {
677 OS << "4 "; // -4- Regularity
678 PrintRegularity(CR->Continuity(),OS);
679 OS << " "<<mySurfaces.Index(CR->Surface());
680 OS << " "<<Locations().Index(CR->Location());
681 OS << " "<<mySurfaces.Index(CR->Surface2());
682 OS << " "<<Locations().Index(CR->Location2());
686 else if (myWithTriangles) { // for XML Persistence
687 if (CR->IsPolygon3D()) {
688 Handle(BRep_Polygon3D) GC = Handle(BRep_Polygon3D)::DownCast(itrc.Value());
689 if (!GC->Polygon3D().IsNull()) {
690 OS << "5 "; // -5- Polygon3D
691 OS << " "<<myPolygons3D.FindIndex(CR->Polygon3D());
692 OS << " "<<Locations().Index(CR->Location());
696 else if (CR->IsPolygonOnTriangulation()) {
697 Handle(BRep_PolygonOnTriangulation) PT =
698 Handle(BRep_PolygonOnTriangulation)::DownCast(itrc.Value());
699 if (!CR->IsPolygonOnClosedTriangulation())
700 OS << "6 "; // -6- Polygon on triangulation
702 OS << "7 "; // -7- Polygon on closed triangulation
703 OS << " " << myNodes.FindIndex(PT->PolygonOnTriangulation());
704 if (CR->IsPolygonOnClosedTriangulation()) {
705 OS << " " << myNodes.FindIndex(PT->PolygonOnTriangulation2());
707 OS << " " << myTriangulations.FindIndex(PT->Triangulation());
708 OS << " "<<Locations().Index(CR->Location());
715 OS << "0\n"; // end of the list of representations
718 else if (S.ShapeType() == TopAbs_FACE) {
720 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
721 const TopoDS_Face& F = TopoDS::Face(S);
723 if (!(TF->Surface()).IsNull()) {
724 OS << ((BRep_Tool::NaturalRestriction(F)) ? 1 : 0);
726 // Write the surface geometry
727 OS << " " <<TF->Tolerance();
728 OS << " " <<mySurfaces.Index(TF->Surface());
729 OS << " " <<Locations().Index(TF->Location());
732 else //For correct reading of null face
736 OS << " " <<TF->Tolerance();
741 if (myWithTriangles) { // for XML Persistence
742 if (!(TF->Triangulation()).IsNull()) {
745 // Write the triangulation
746 OS << " " <<myTriangulations.FindIndex(TF->Triangulation());
753 //=======================================================================
754 //function : ReadRegularity
756 //=======================================================================
758 static GeomAbs_Shape ReadRegularity(Standard_IStream& IS)
799 //=======================================================================
800 //function : ReadGeometry
802 //=======================================================================
804 void BRepTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T,
805 Standard_IStream& IS,
810 Standard_Integer val,c,pc,pc2,s,s2,l,l2,t, pt, pt2;
811 Standard_Real tol,X,Y,Z,first,last,p1,p2;
812 Standard_Real PfX,PfY,PlX,PlY;
814 Standard_Boolean closed;
816 GeomAbs_Shape reg = GeomAbs_C0;
829 TopoDS_Vertex& V = TopoDS::Vertex(S);
831 // Read the point geometry
834 myBuilder.MakeVertex(V,gp_Pnt(X,Y,Z),tol);
835 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(V.TShape());
837 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
843 Handle(BRep_PointRepresentation) PR;
850 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
851 if (myCurves.Curve(c).IsNull())
853 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
855 Handle(BRep_PointOnCurve) POC =
856 new BRep_PointOnCurve(p1,
867 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
868 if (myCurves2d.Curve2d(pc).IsNull() ||
869 mySurfaces.Surface(s).IsNull())
871 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
873 Handle(BRep_PointOnCurveOnSurface) POC =
874 new BRep_PointOnCurveOnSurface(p1,
875 myCurves2d.Curve2d(pc),
876 mySurfaces.Surface(s),
886 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
887 if (mySurfaces.Surface(s).IsNull())
889 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
891 Handle(BRep_PointOnSurface) POC =
892 new BRep_PointOnSurface(p1,p2,
893 mySurfaces.Surface(s),
903 PR->Location(Locations().Location(l));
921 TopoDS_Edge& E = TopoDS::Edge(S);
923 myBuilder.MakeEdge(E);
925 // Read the curve geometry
928 myBuilder.SameParameter(E,(val == 1));
930 myBuilder.SameRange(E,(val == 1));
932 myBuilder.Degenerated(E,(val == 1));
938 case 1 : // -1- Curve 3D
940 if (!myCurves.Curve(c).IsNull()) {
941 myBuilder.UpdateEdge(E,myCurves.Curve(c),
942 Locations().Location(l),tol);
945 if (!myCurves.Curve(c).IsNull()) {
946 Standard_Boolean Only3d = Standard_True;
947 myBuilder.Range(E,first,last,Only3d);
952 case 2 : // -2- Curve on surf
953 case 3 : // -3- Curve on closed surf
958 reg = ReadRegularity(IS);
967 // read UV Points // for XML Persistence higher performance
970 IS >> PfX >> PfY >> PlX >> PlY;
971 aPf = gp_Pnt2d(PfX,PfY);
972 aPl = gp_Pnt2d(PlX,PlY);
975 // Modified by Sergey KHROMOV - Wed Apr 24 12:11:16 2002 Begin
976 if (myCurves2d.Curve2d(pc).IsNull() ||
977 (closed && myCurves2d.Curve2d(pc2).IsNull()) ||
978 mySurfaces.Surface(s).IsNull())
980 // Modified by Sergey KHROMOV - Wed Apr 24 12:11:17 2002 End
984 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
985 myCurves2d.Curve2d(pc2),
986 mySurfaces.Surface(s),
987 Locations().Location(l),tol,
990 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
991 myCurves2d.Curve2d(pc2),
992 mySurfaces.Surface(s),
993 Locations().Location(l),tol);
995 myBuilder.Continuity(E,
996 mySurfaces.Surface(s),
997 mySurfaces.Surface(s),
998 Locations().Location(l),
999 Locations().Location(l),
1004 if (FormatNb() == 2)
1005 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1006 mySurfaces.Surface(s),
1007 Locations().Location(l),tol,
1010 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1011 mySurfaces.Surface(s),
1012 Locations().Location(l),tol);
1015 mySurfaces.Surface(s),
1016 Locations().Location(l),
1020 case 4 : // -4- Regularity
1021 reg = ReadRegularity(IS);
1022 IS >> s >> l >> s2 >> l2;
1023 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:13 2002 Begin
1024 if (mySurfaces.Surface(s).IsNull() ||
1025 mySurfaces.Surface(s2).IsNull())
1027 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:14 2002 End
1028 myBuilder.Continuity(E,
1029 mySurfaces.Surface(s),
1030 mySurfaces.Surface(s2),
1031 Locations().Location(l),
1032 Locations().Location(l2),
1036 case 5 : // -5- Polygon3D
1038 //szy-02.05.2004 myBuilder.UpdateEdge(E,Handle(Poly_Polygon3D)::DownCast(myPolygons3D(c)));
1039 if (c > 0 && c <= myPolygons3D.Extent())
1040 myBuilder.UpdateEdge(E,Handle(Poly_Polygon3D)::DownCast(myPolygons3D(c)), Locations().Location(l));
1045 closed = (val == 7);
1052 if (t > 0 && t <= myTriangulations.Extent() &&
1053 pt > 0 && pt <= myNodes.Extent() &&
1054 pt2 > 0 && pt2 <= myNodes.Extent())
1055 myBuilder.UpdateEdge
1056 (E, Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
1057 Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt2)),
1058 Handle(Poly_Triangulation)::DownCast(myTriangulations(t)),
1059 Locations().Location(l));
1062 if (t > 0 && t <= myTriangulations.Extent() &&
1063 pt > 0 && pt <= myNodes.Extent())
1064 myBuilder.UpdateEdge
1065 (E,Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
1066 Handle(Poly_Triangulation)::DownCast(myTriangulations(t)),
1067 Locations().Location(l));
1084 myBuilder.MakeWire(TopoDS::Wire(S));
1095 TopoDS_Face& F = TopoDS::Face(S);
1097 myBuilder.MakeFace(F);
1099 IS >> val; // natural restriction
1100 if (val == 0 || val == 1) {
1101 IS >> tol >> s >> l;
1102 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:13 2002 Begin
1103 if (!mySurfaces.Surface(s).IsNull()) {
1104 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:14 2002 End
1105 myBuilder.UpdateFace(TopoDS::Face(S),
1106 mySurfaces.Surface(s),
1107 Locations().Location(l),tol);
1108 myBuilder.NaturalRestriction(TopoDS::Face(S),(val == 1));
1110 // pos = IS.tellg();
1114 //only triangulation
1116 myBuilder.UpdateFace(TopoDS::Face(S),
1117 Handle(Poly_Triangulation)::DownCast(myTriangulations(s)));
1119 // else pos = IS.tellg();
1126 IS.getline ( string, 256, '\n' );
1127 IS.getline ( string, 256, '\n' );
1129 if (string[0] == '2') {
1130 // cas triangulation
1131 s = atoi ( &string[2] );
1132 if (s > 0 && s <= myTriangulations.Extent())
1133 myBuilder.UpdateFace(TopoDS::Face(S),
1134 Handle(Poly_Triangulation)::DownCast(myTriangulations(s)));
1136 // else IS.seekg(pos);
1146 myBuilder.MakeShell(TopoDS::Shell(S));
1155 myBuilder.MakeSolid(TopoDS::Solid(S));
1163 case TopAbs_COMPSOLID :
1164 myBuilder.MakeCompSolid(TopoDS::CompSolid(S));
1172 case TopAbs_COMPOUND :
1173 myBuilder.MakeCompound(TopoDS::Compound(S));
1184 //=======================================================================
1185 //function : AddShapes
1187 //=======================================================================
1189 void BRepTools_ShapeSet::AddShapes(TopoDS_Shape& S1,
1190 const TopoDS_Shape& S2)
1192 myBuilder.Add(S1,S2);
1195 //=======================================================================
1198 //=======================================================================
1200 void BRepTools_ShapeSet::Check(const TopAbs_ShapeEnum T,
1203 if (T == TopAbs_FACE) {
1204 const TopoDS_Face& F = TopoDS::Face(S);
1205 BRepTools::Update(F);
1211 //=======================================================================
1212 //function : WritePolygonOnTriangulation
1214 //=======================================================================
1216 void BRepTools_ShapeSet::WritePolygonOnTriangulation(Standard_OStream& OS,
1217 const Standard_Boolean Compact)const
1219 Standard_Integer i, j, nbpOntri = myNodes.Extent();
1221 Handle(Message_ProgressIndicator) progress = GetProgress();
1222 Message_ProgressSentry PS(progress, "Polygons On Triangulation", 0, nbpOntri, 1);
1224 OS << "PolygonOnTriangulations " << nbpOntri << endl;
1227 OS <<"Dump of " << nbpOntri << " PolygonOnTriangulations\n";
1231 Handle(Poly_PolygonOnTriangulation) Poly;
1232 Handle(TColStd_HArray1OfReal) Param;
1234 for (i=1; i<=nbpOntri && PS.More(); i++, PS.Next()) {
1235 if ( !progress.IsNull() )
1238 Poly = Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(i));
1239 const TColStd_Array1OfInteger& Nodes = Poly->Nodes();
1241 OS << " "<< i << " : PolygonOnTriangulation with " << Nodes.Length() << " Nodes\n";
1243 else OS << Nodes.Length()<<" ";
1244 if (!Compact) OS <<" ";
1245 for (j=1; j <= Nodes.Length(); j++) OS << Nodes.Value(j) << " ";
1248 // writing parameters:
1249 Param = Poly->Parameters();
1250 if (Compact) OS <<"p ";
1252 // write the deflection
1253 if (!Compact) OS << " Deflection : ";
1254 OS <<Poly->Deflection() << " ";
1255 if (!Compact) OS << "\n";
1257 if (!Param.IsNull()) {
1259 OS << " "<< "Parameters :";
1262 if (!Compact) OS <<" ";
1263 for (j=1; j <= Param->Length(); j++) OS << Param->Value(j) << " ";
1270 //=======================================================================
1271 //function : DumpPolygonOnTriangulation
1273 //=======================================================================
1275 void BRepTools_ShapeSet::DumpPolygonOnTriangulation(Standard_OStream& OS)const
1277 WritePolygonOnTriangulation(OS, Standard_False);
1280 //=======================================================================
1281 //function : ReadPolygonOnTriangulation
1283 //=======================================================================
1285 void BRepTools_ShapeSet::ReadPolygonOnTriangulation(Standard_IStream& IS)
1289 if (strstr(buffer,"PolygonOnTriangulations") == NULL) return;
1290 Standard_Integer i, j, val, nbpol = 0, nbnodes =0;
1291 Standard_Integer hasparameters;
1293 Handle(TColStd_HArray1OfReal) Param;
1294 Handle(Poly_PolygonOnTriangulation) Poly;
1297 Handle(Message_ProgressIndicator) progress = GetProgress();
1298 Message_ProgressSentry PS(progress, "Polygons On Triangulation", 0, nbpol, 1);
1299 for (i=1; i<=nbpol&& PS.More(); i++, PS.Next()) {
1300 if ( !progress.IsNull() )
1304 TColStd_Array1OfInteger Nodes(1, nbnodes);
1305 for (j = 1; j <= nbnodes; j++) {
1310 // if (!strcasecmp(buffer, "p")) {
1313 IS >> hasparameters;
1314 if (hasparameters) {
1315 TColStd_Array1OfReal Param1(1, nbnodes);
1316 for (j = 1; j <= nbnodes; j++) {
1320 Poly = new Poly_PolygonOnTriangulation(Nodes, Param1);
1322 else Poly = new Poly_PolygonOnTriangulation(Nodes);
1323 Poly->Deflection(def);
1327 // Poly = new Poly_PolygonOnTriangulation(Nodes);
1332 // else IS.seekg(pos);
1337 //=======================================================================
1338 //function : WritePolygon3D
1340 //=======================================================================
1342 void BRepTools_ShapeSet::WritePolygon3D(Standard_OStream& OS,
1343 const Standard_Boolean Compact)const
1345 Standard_Integer i, j, nbpol = myPolygons3D.Extent();
1347 Handle(Message_ProgressIndicator) progress = GetProgress();
1348 Message_ProgressSentry PS(progress, "3D Poligons", 0, nbpol, 1);
1351 OS << "Polygon3D " << nbpol << endl;
1354 OS <<"Dump of " << nbpol << " Polygon3Ds\n";
1358 Handle(Poly_Polygon3D) P;
1359 for (i = 1; i <= nbpol && PS.More(); i++, PS.Next()) {
1360 if ( !progress.IsNull() )
1363 P = Handle(Poly_Polygon3D)::DownCast(myPolygons3D(i));
1365 OS << P->NbNodes() << " ";
1366 OS << ((P->HasParameters()) ? "1" : "0") << "\n";
1369 OS << " "<< i << " : Polygon3D with " << P->NbNodes() << " Nodes\n";
1370 OS << ((P->HasParameters()) ? "with" : "without") << " parameters\n";
1374 // write the deflection
1375 if (!Compact) OS << "Deflection : ";
1376 OS << P->Deflection() << "\n";
1379 if (!Compact) OS << "\nNodes :\n";
1381 Standard_Integer i1, nbNodes = P->NbNodes();
1382 const TColgp_Array1OfPnt& Nodes = P->Nodes();
1383 for (j = 1; j <= nbNodes; j++) {
1384 if (!Compact) OS << setw(10) << j << " : ";
1385 if (!Compact) OS << setw(17);
1386 OS << Nodes(j).X() << " ";
1387 if (!Compact) OS << setw(17);
1388 OS << Nodes(j).Y() << " ";
1389 if (!Compact) OS << setw(17);
1391 if (!Compact) OS << "\n";
1396 if (P->HasParameters()) {
1397 if (!Compact) OS << "\nParameters :\n";
1398 const TColStd_Array1OfReal& Param = P->Parameters();
1399 for ( i1 = 1; i1 <= nbNodes; i1++ ) {
1400 OS << Param(i1) << " ";
1407 //=======================================================================
1408 //function : DumpPolygon3D
1410 //=======================================================================
1412 void BRepTools_ShapeSet::DumpPolygon3D(Standard_OStream& OS)const
1414 WritePolygon3D(OS, Standard_False);
1418 //=======================================================================
1419 //function : ReadPolygon3D
1421 //=======================================================================
1423 void BRepTools_ShapeSet::ReadPolygon3D(Standard_IStream& IS)
1426 // Standard_Integer i, j, p, val, nbpol, nbnodes, hasparameters;
1427 Standard_Integer i, j, p, nbpol=0, nbnodes =0, hasparameters = Standard_False;
1428 Standard_Real d, x, y, z;
1431 if (strstr(buffer,"Polygon3D") == NULL) return;
1432 Handle(Poly_Polygon3D) P;
1435 Handle(Message_ProgressIndicator) progress = GetProgress();
1436 Message_ProgressSentry PS(progress, "3D Polygons", 0, nbpol, 1);
1437 for (i=1; i<=nbpol && PS.More(); i++, PS.Next()) {
1438 if ( !progress.IsNull() )
1442 IS >> hasparameters;
1443 TColgp_Array1OfPnt Nodes(1, nbnodes);
1445 for (j = 1; j <= nbnodes; j++) {
1447 Nodes(j).SetCoord(x,y,z);
1449 if (hasparameters) {
1450 TColStd_Array1OfReal Param(1,nbnodes);
1451 for (p = 1; p <= nbnodes; p++) {
1454 P = new Poly_Polygon3D(Nodes, Param);
1456 else P = new Poly_Polygon3D(Nodes);
1458 myPolygons3D.Add(P);
1464 //=======================================================================
1465 //function : WriteTriangulation
1467 //=======================================================================
1469 void BRepTools_ShapeSet::WriteTriangulation(Standard_OStream& OS,
1470 const Standard_Boolean Compact)const
1472 Standard_Integer i, j, nbNodes, nbtri = myTriangulations.Extent();
1473 Standard_Integer nbTriangles = 0, n1, n2, n3;
1475 Handle(Message_ProgressIndicator) progress = GetProgress();
1476 Message_ProgressSentry PS(progress, "Triangulations", 0, nbtri, 1);
1479 OS << "Triangulations " << nbtri << endl;
1482 OS <<"Dump of " << nbtri << " Triangulations\n";
1486 Handle(Poly_Triangulation) T;
1487 for (i = 1; i <= nbtri && PS.More(); i++, PS.Next()) {
1488 if ( !progress.IsNull() )
1491 T = Handle(Poly_Triangulation)::DownCast(myTriangulations(i));
1493 OS << T->NbNodes() << " " << T->NbTriangles() << " ";
1494 OS << ((T->HasUVNodes()) ? "1" : "0") << " ";
1497 OS << " "<< i << " : Triangulation with " << T->NbNodes() << " Nodes and "
1498 << T->NbTriangles() <<" Triangles\n";
1499 OS << " "<<((T->HasUVNodes()) ? "with" : "without") << " UV nodes\n";
1503 // write the deflection
1505 if (!Compact) OS << " Deflection : ";
1506 OS <<T->Deflection() << "\n";
1508 // write the 3d nodes
1510 if (!Compact) OS << "\n3D Nodes :\n";
1512 nbNodes = T->NbNodes();
1513 const TColgp_Array1OfPnt& Nodes = T->Nodes();
1514 for (j = 1; j <= nbNodes; j++) {
1515 if (!Compact) OS << setw(10) << j << " : ";
1516 if (!Compact) OS << setw(17);
1517 OS << Nodes(j).X() << " ";
1518 if (!Compact) OS << setw(17);
1519 OS << Nodes(j).Y() << " ";
1520 if (!Compact) OS << setw(17);
1522 if (!Compact) OS << "\n";
1526 if (T->HasUVNodes()) {
1527 if (!Compact) OS << "\nUV Nodes :\n";
1528 const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes();
1529 for (j = 1; j <= nbNodes; j++) {
1530 if (!Compact) OS << setw(10) << j << " : ";
1531 if (!Compact) OS << setw(17);
1532 OS << UVNodes(j).X() << " ";
1533 if (!Compact) OS << setw(17);
1534 OS << UVNodes(j).Y();
1535 if (!Compact) OS << "\n";
1540 if (!Compact) OS << "\nTriangles :\n";
1541 nbTriangles = T->NbTriangles();
1542 const Poly_Array1OfTriangle& Triangles = T->Triangles();
1543 for (j = 1; j <= nbTriangles; j++) {
1544 if (!Compact) OS << setw(10) << j << " : ";
1545 Triangles(j).Get(n1, n2, n3);
1546 if (!Compact) OS << setw(10);
1548 if (!Compact) OS << setw(10);
1550 if (!Compact) OS << setw(10);
1552 if (!Compact) OS << "\n";
1559 //=======================================================================
1560 //function : DumpTriangulation
1562 //=======================================================================
1564 void BRepTools_ShapeSet::DumpTriangulation(Standard_OStream& OS)const
1566 WriteTriangulation(OS, Standard_False);
1570 //=======================================================================
1571 //function : ReadTriangulation
1573 //=======================================================================
1575 void BRepTools_ShapeSet::ReadTriangulation(Standard_IStream& IS)
1578 // Standard_Integer i, j, val, nbtri;
1579 Standard_Integer i, j, nbtri =0;
1580 Standard_Real d, x, y, z;
1581 Standard_Integer nbNodes =0, nbTriangles=0;
1582 Standard_Boolean hasUV= Standard_False;
1584 Handle(Poly_Triangulation) T;
1587 if (strstr(buffer,"Triangulations") == NULL) return;
1591 Handle(Message_ProgressIndicator) progress = GetProgress();
1592 Message_ProgressSentry PS(progress, "Triangulations", 0, nbtri, 1);
1593 for (i=1; i<=nbtri && PS.More();i++, PS.Next()) {
1594 if ( !progress.IsNull() )
1597 IS >> nbNodes >> nbTriangles >> hasUV;
1600 TColgp_Array1OfPnt Nodes(1, nbNodes);
1601 TColgp_Array1OfPnt2d UVNodes(1, nbNodes);
1603 for (j = 1; j <= nbNodes; j++) {
1605 Nodes(j).SetCoord(x,y,z);
1609 for (j = 1; j <= nbNodes; j++) {
1611 UVNodes(j).SetCoord(x,y);
1615 // read the triangles
1616 Standard_Integer n1,n2,n3;
1617 Poly_Array1OfTriangle Triangles(1, nbTriangles);
1618 for (j = 1; j <= nbTriangles; j++) {
1619 IS >> n1 >> n2 >> n3;
1620 Triangles(j).Set(n1,n2,n3);
1623 if (hasUV) T = new Poly_Triangulation(Nodes,UVNodes,Triangles);
1624 else T = new Poly_Triangulation(Nodes,Triangles);
1628 myTriangulations.Add(T);