1 // Created on: 1993-07-19
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modifed: Portage NT 7-5-97 DPF (strcasecmp)
19 #include <BRep_Builder.hxx>
20 #include <BRep_CurveOnClosedSurface.hxx>
21 #include <BRep_CurveOnSurface.hxx>
22 #include <BRep_CurveRepresentation.hxx>
23 #include <BRep_GCurve.hxx>
24 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
25 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
26 #include <BRep_ListOfCurveRepresentation.hxx>
27 #include <BRep_PointOnCurve.hxx>
28 #include <BRep_PointOnCurveOnSurface.hxx>
29 #include <BRep_PointOnSurface.hxx>
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>
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>
51 #include <TColgp_HArray1OfPnt.hxx>
52 #include <TColgp_HArray1OfPnt2d.hxx>
53 #include <TColStd_HArray1OfInteger.hxx>
54 #include <TColStd_HArray1OfReal.hxx>
56 #include <TopoDS_Shape.hxx>
57 #include <TopoDS_Vertex.hxx>
60 #define strcasecmp(p,q) strcmp(p,q)
62 #define strcasecmp strcmp
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.
71 // On NT platforms (in BRepTools_ShapeSet):
73 // In Visual C++ 5 (or higher) the std::fstream::tellg method is not
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.
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).
84 //=======================================================================
85 //function : BRepTools_ShapeSet
87 //=======================================================================
89 BRepTools_ShapeSet::BRepTools_ShapeSet(const Standard_Boolean isWithTriangles)
90 :myWithTriangles(isWithTriangles)
94 //=======================================================================
95 //function : BRepTools_ShapeSet
97 //=======================================================================
99 BRepTools_ShapeSet::BRepTools_ShapeSet (const BRep_Builder& B,
100 const Standard_Boolean isWithTriangles) :
101 myBuilder(B), myWithTriangles(isWithTriangles)
106 //=======================================================================
109 //=======================================================================
111 void BRepTools_ShapeSet::Clear()
116 myPolygons3D.Clear();
117 myPolygons2D.Clear();
119 myTriangulations.Clear();
120 TopTools_ShapeSet::Clear();
124 //=======================================================================
125 //function : AddGeometry
127 //=======================================================================
129 void BRepTools_ShapeSet::AddGeometry(const TopoDS_Shape& S)
133 if (S.ShapeType() == TopAbs_VERTEX) {
135 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
136 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
138 while (itrp.More()) {
139 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
141 if (PR->IsPointOnCurve()) {
142 myCurves.Add(PR->Curve());
145 else if (PR->IsPointOnCurveOnSurface()) {
146 myCurves2d.Add(PR->PCurve());
147 mySurfaces.Add(PR->Surface());
150 else if (PR->IsPointOnSurface()) {
151 mySurfaces.Add(PR->Surface());
154 ChangeLocations().Add(PR->Location());
159 else if (S.ShapeType() == TopAbs_EDGE) {
161 // Add the curve geometry
162 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
163 BRep_ListIteratorOfListOfCurveRepresentation itrc(TE->Curves());
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());
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());
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());
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());
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());
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());
212 else if (S.ShapeType() == TopAbs_FACE) {
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());
218 if (myWithTriangles || TF->Surface().IsNull()) { // for XML Persistence
219 Handle(Poly_Triangulation) Tr = TF->Triangulation();
220 if (!Tr.IsNull()) myTriangulations.Add(Tr);
223 ChangeLocations().Add(TF->Location());
228 //=======================================================================
229 //function : DumpGeometry
231 //=======================================================================
233 void BRepTools_ShapeSet::DumpGeometry(Standard_OStream& OS)const
238 DumpPolygonOnTriangulation(OS);
240 DumpTriangulation(OS);
244 //=======================================================================
245 //function : WriteGeometry
247 //=======================================================================
249 void BRepTools_ShapeSet::WriteGeometry(Standard_OStream& OS)
252 myCurves2d.SetProgress(GetProgress());
253 myCurves.SetProgress(GetProgress());
254 mySurfaces.SetProgress(GetProgress());
256 if ( !GetProgress().IsNull()) {
257 if(GetProgress()->UserBreak() ) return;
258 GetProgress()->NewScope ( 15, "2D Curves" );
260 myCurves2d.Write(OS);
262 if ( !GetProgress().IsNull()) {
263 if( GetProgress()->UserBreak() ) return;
264 GetProgress()->EndScope();
265 GetProgress()->Show();
267 GetProgress()->NewScope ( 15, "3D Curves" );
271 if ( !GetProgress().IsNull()) {
272 if( GetProgress()->UserBreak() ) return;
273 GetProgress()->EndScope();
274 GetProgress()->Show();
276 GetProgress()->NewScope ( 10, "3D Polygons" );
279 if ( !GetProgress().IsNull()) {
280 if( GetProgress()->UserBreak() ) return;
281 GetProgress()->EndScope();
282 GetProgress()->Show();
284 GetProgress()->NewScope ( 10, "Polygons On Triangulation" );
286 WritePolygonOnTriangulation(OS);
287 if ( !GetProgress().IsNull()) {
288 if( GetProgress()->UserBreak() ) return;
289 GetProgress()->EndScope();
290 GetProgress()->Show();
292 GetProgress()->NewScope ( 10, "Surfaces" );
294 mySurfaces.Write(OS);
295 if ( !GetProgress().IsNull()) {
296 if( GetProgress()->UserBreak() ) return;
297 GetProgress()->EndScope();
298 GetProgress()->Show();
300 GetProgress()->NewScope ( 15, "Triangulations" );
302 WriteTriangulation(OS);
303 if ( !GetProgress().IsNull()) {
304 if( GetProgress()->UserBreak() ) return;
305 GetProgress()->EndScope();
306 GetProgress()->Show();
311 //=======================================================================
312 //function : ReadGeometry
314 //=======================================================================
316 void BRepTools_ShapeSet::ReadGeometry(Standard_IStream& IS)
319 myCurves2d.SetProgress(GetProgress());
320 myCurves.SetProgress(GetProgress());
321 mySurfaces.SetProgress(GetProgress());
323 if ( !GetProgress().IsNull()) {
324 if( GetProgress()->UserBreak() ) return;
325 GetProgress()->NewScope ( 15, "2D Curves" );
329 if ( !GetProgress().IsNull()) {
330 if( GetProgress()->UserBreak() ) return;
331 GetProgress()->EndScope();
332 GetProgress()->Show();
334 GetProgress()->NewScope ( 15, "3D Curves" );
338 if ( !GetProgress().IsNull()) {
339 if( GetProgress()->UserBreak() ) return;
340 GetProgress()->EndScope();
341 GetProgress()->Show();
343 GetProgress()->NewScope ( 10, "3D Polygons" );
346 if ( !GetProgress().IsNull() ) {
347 if( GetProgress()->UserBreak() ) return;
348 GetProgress()->EndScope();
349 GetProgress()->Show();
351 GetProgress()->NewScope ( 10, "Polygons On Triangulation" );
353 ReadPolygonOnTriangulation(IS);
354 if ( !GetProgress().IsNull()) {
355 if( GetProgress()->UserBreak() ) return;
356 GetProgress()->EndScope();
357 GetProgress()->Show();
359 GetProgress()->NewScope ( 10, "Surfaces" );
362 if ( !GetProgress().IsNull() ) {
363 if( GetProgress()->UserBreak() ) return;
364 GetProgress()->EndScope();
365 GetProgress()->Show();
367 GetProgress()->NewScope ( 15, "Triangulations" );
369 ReadTriangulation(IS);
370 if ( !GetProgress().IsNull()) {
371 if( GetProgress()->UserBreak() ) return;
372 GetProgress()->EndScope();
373 GetProgress()->Show();
377 //=======================================================================
378 //function : PrintRegularity
380 //=======================================================================
382 static void PrintRegularity(const GeomAbs_Shape C,
383 Standard_OStream& OS)
418 //=======================================================================
419 //function : DumpGeometry
421 //=======================================================================
423 void BRepTools_ShapeSet::DumpGeometry(const TopoDS_Shape& S,
424 Standard_OStream& OS)const
428 if (S.ShapeType() == TopAbs_VERTEX) {
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";
436 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
437 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
439 while (itrp.More()) {
440 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
442 OS << " - Parameter : "<< PR->Parameter();
443 if (PR->IsPointOnCurve()) {
444 OS << " on curve " << myCurves.Index(PR->Curve());
447 else if (PR->IsPointOnCurveOnSurface()) {
448 OS << " on pcurve " << myCurves2d.Index(PR->PCurve());
449 OS << " on surface " << mySurfaces.Index(PR->Surface());
452 else if (PR->IsPointOnSurface()) {
453 OS << ", " << PR->Parameter2() << " on surface ";
454 OS << mySurfaces.Index(PR->Surface());
457 if (!PR->Location().IsIdentity())
458 OS << " location " << Locations().Index(PR->Location());
466 else if (S.ShapeType() == TopAbs_EDGE) {
468 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
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";
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";
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());
498 PrintRegularity(CR->Continuity(),OS);
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";
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";
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());
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());
538 else if (CR->IsPolygonOnTriangulation()) {
539 OS << " - PolygonOnTriangulation " << myNodes.FindIndex(CR->PolygonOnTriangulation());
540 if (CR->IsPolygonOnClosedTriangulation()) {
541 OS << " " << myNodes.FindIndex(CR->PolygonOnTriangulation2());
543 OS << " on triangulation " << myTriangulations.FindIndex(CR->Triangulation());
544 if (!CR->Location().IsIdentity())
545 OS << " location "<<Locations().Index(CR->Location());
552 else if (S.ShapeType() == TopAbs_FACE) {
554 const TopoDS_Face& F = TopoDS::Face(S);
555 if (BRep_Tool::NaturalRestriction(F))
556 OS << "NaturalRestriction\n";
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());
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());
580 //=======================================================================
581 //function : WriteGeometry
583 //=======================================================================
585 void BRepTools_ShapeSet::WriteGeometry(const TopoDS_Shape& S,
586 Standard_OStream& OS)const
588 // Write the geometry
590 if (S.ShapeType() == TopAbs_VERTEX) {
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";
598 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
599 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
601 while (itrp.More()) {
602 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
604 OS << PR->Parameter();
605 if (PR->IsPointOnCurve()) {
606 OS << " 1 " << myCurves.Index(PR->Curve());
609 else if (PR->IsPointOnCurveOnSurface()) {
610 OS << " 2 " << myCurves2d.Index(PR->PCurve());
611 OS << " " << mySurfaces.Index(PR->Surface());
614 else if (PR->IsPointOnSurface()) {
615 OS << " 3 " << PR->Parameter2() << " ";
616 OS << mySurfaces.Index(PR->Surface());
619 OS << " " << Locations().Index(PR->Location());
625 OS << "0 0\n"; // end representations
629 else if (S.ShapeType() == TopAbs_EDGE) {
631 // Write the curve geometry
633 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
635 OS << " " << TE->Tolerance() << " ";
636 OS << ((TE->SameParameter()) ? 1 : 0) << " ";
637 OS << ((TE->SameRange()) ? 1 : 0) << " ";
638 OS << ((TE->Degenerated()) ? 1 : 0) << "\n";
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;
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
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);
667 OS << " " << mySurfaces.Index(CR->Surface());
668 OS << " " << Locations().Index(CR->Location());
669 OS << " "<<first<<" "<<last;
672 // Write UV Points // for XML Persistence higher performance
676 if (CR->IsCurveOnClosedSurface()) {
677 Handle(BRep_CurveOnClosedSurface) COCS =
678 Handle(BRep_CurveOnClosedSurface)::DownCast(CR);
679 COCS->UVPoints2(Pf,Pl);
682 Handle(BRep_CurveOnSurface) COS =
683 Handle(BRep_CurveOnSurface)::DownCast(CR);
684 COS->UVPoints(Pf,Pl);
686 OS << Pf.X() << " " << Pf.Y() << " " << Pl.X() << " " << Pl.Y() << "\n";
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());
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());
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
715 OS << "7 "; // -7- Polygon on closed triangulation
716 OS << " " << myNodes.FindIndex(PT->PolygonOnTriangulation());
717 if (CR->IsPolygonOnClosedTriangulation()) {
718 OS << " " << myNodes.FindIndex(PT->PolygonOnTriangulation2());
720 OS << " " << myTriangulations.FindIndex(PT->Triangulation());
721 OS << " "<<Locations().Index(CR->Location());
728 OS << "0\n"; // end of the list of representations
731 else if (S.ShapeType() == TopAbs_FACE) {
733 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
734 const TopoDS_Face& F = TopoDS::Face(S);
736 if (!(TF->Surface()).IsNull()) {
737 OS << ((BRep_Tool::NaturalRestriction(F)) ? 1 : 0);
739 // Write the surface geometry
740 OS << " " <<TF->Tolerance();
741 OS << " " <<mySurfaces.Index(TF->Surface());
742 OS << " " <<Locations().Index(TF->Location());
745 else //For correct reading of null face
749 OS << " " <<TF->Tolerance();
754 if (myWithTriangles || TF->Surface().IsNull()) { // for XML Persistence
755 if (!(TF->Triangulation()).IsNull()) {
758 // Write the triangulation
759 OS << " " <<myTriangulations.FindIndex(TF->Triangulation());
766 //=======================================================================
767 //function : ReadRegularity
769 //=======================================================================
771 static GeomAbs_Shape ReadRegularity(Standard_IStream& IS)
812 //=======================================================================
813 //function : ReadGeometry
815 //=======================================================================
817 void BRepTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T,
818 Standard_IStream& IS,
823 Standard_Integer val,c,pc,pc2 = 0,s,s2,l,l2,t, pt, pt2 = 0;
824 Standard_Real tol,X,Y,Z,first,last,p1,p2;
825 Standard_Real PfX,PfY,PlX,PlY;
827 Standard_Boolean closed;
828 GeomAbs_Shape reg = GeomAbs_C0;
838 TopoDS_Vertex& V = TopoDS::Vertex(S);
840 // Read the point geometry
841 GeomTools::GetReal(IS, tol);
842 GeomTools::GetReal(IS, X);
843 GeomTools::GetReal(IS, Y);
844 GeomTools::GetReal(IS, Z);
845 myBuilder.MakeVertex(V,gp_Pnt(X,Y,Z),tol);
846 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(V.TShape());
848 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
852 GeomTools::GetReal(IS, p1);
855 Handle(BRep_PointRepresentation) PR;
862 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
863 if (myCurves.Curve(c).IsNull())
865 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
867 Handle(BRep_PointOnCurve) POC =
868 new BRep_PointOnCurve(p1,
879 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
880 if (myCurves2d.Curve2d(pc).IsNull() ||
881 mySurfaces.Surface(s).IsNull())
883 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
885 Handle(BRep_PointOnCurveOnSurface) POC =
886 new BRep_PointOnCurveOnSurface(p1,
887 myCurves2d.Curve2d(pc),
888 mySurfaces.Surface(s),
896 GeomTools::GetReal(IS, p2);
899 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
900 if (mySurfaces.Surface(s).IsNull())
902 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
904 Handle(BRep_PointOnSurface) POC =
905 new BRep_PointOnSurface(p1,p2,
906 mySurfaces.Surface(s),
916 PR->Location(Locations().Location(l));
934 TopoDS_Edge& E = TopoDS::Edge(S);
936 myBuilder.MakeEdge(E);
938 // Read the curve geometry
939 GeomTools::GetReal(IS, tol);
941 myBuilder.SameParameter(E,(val == 1));
943 myBuilder.SameRange(E,(val == 1));
945 myBuilder.Degenerated(E,(val == 1));
951 case 1 : // -1- Curve 3D
953 if (!myCurves.Curve(c).IsNull()) {
954 myBuilder.UpdateEdge(E,myCurves.Curve(c),
955 Locations().Location(l),tol);
957 GeomTools::GetReal(IS, first);
958 GeomTools::GetReal(IS, last);
959 if (!myCurves.Curve(c).IsNull()) {
960 Standard_Boolean Only3d = Standard_True;
961 myBuilder.Range(E,first,last,Only3d);
966 case 2 : // -2- Curve on surf
967 case 3 : // -3- Curve on closed surf
972 reg = ReadRegularity(IS);
979 GeomTools::GetReal(IS, first);
980 GeomTools::GetReal(IS, last);
982 // read UV Points // for XML Persistence higher performance
985 GeomTools::GetReal(IS, PfX);
986 GeomTools::GetReal(IS, PfY);
987 GeomTools::GetReal(IS, PlX);
988 GeomTools::GetReal(IS, PlY);
989 aPf = gp_Pnt2d(PfX,PfY);
990 aPl = gp_Pnt2d(PlX,PlY);
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())
998 // Modified by Sergey KHROMOV - Wed Apr 24 12:11:17 2002 End
1001 if (FormatNb() == 2)
1002 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1003 myCurves2d.Curve2d(pc2),
1004 mySurfaces.Surface(s),
1005 Locations().Location(l),tol,
1008 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1009 myCurves2d.Curve2d(pc2),
1010 mySurfaces.Surface(s),
1011 Locations().Location(l),tol);
1013 myBuilder.Continuity(E,
1014 mySurfaces.Surface(s),
1015 mySurfaces.Surface(s),
1016 Locations().Location(l),
1017 Locations().Location(l),
1022 if (FormatNb() == 2)
1023 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1024 mySurfaces.Surface(s),
1025 Locations().Location(l),tol,
1028 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1029 mySurfaces.Surface(s),
1030 Locations().Location(l),tol);
1033 mySurfaces.Surface(s),
1034 Locations().Location(l),
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())
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),
1054 case 5 : // -5- Polygon3D
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));
1063 closed = (val == 7);
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));
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));
1102 myBuilder.MakeWire(TopoDS::Wire(S));
1113 TopoDS_Face& F = TopoDS::Face(S);
1114 // std::streampos pos;
1115 myBuilder.MakeFace(F);
1117 IS >> val; // natural restriction
1118 if (val == 0 || val == 1) {
1119 GeomTools::GetReal(IS, tol);
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));
1129 // pos = IS.tellg();
1133 //only triangulation
1135 myBuilder.UpdateFace(TopoDS::Face(S),
1136 Handle(Poly_Triangulation)::DownCast(myTriangulations(s)));
1138 // else pos = IS.tellg();
1145 IS.getline ( string, 256, '\n' );
1146 IS.getline ( string, 256, '\n' );
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)));
1155 // else IS.seekg(pos);
1165 myBuilder.MakeShell(TopoDS::Shell(S));
1174 myBuilder.MakeSolid(TopoDS::Solid(S));
1182 case TopAbs_COMPSOLID :
1183 myBuilder.MakeCompSolid(TopoDS::CompSolid(S));
1191 case TopAbs_COMPOUND :
1192 myBuilder.MakeCompound(TopoDS::Compound(S));
1203 //=======================================================================
1204 //function : AddShapes
1206 //=======================================================================
1208 void BRepTools_ShapeSet::AddShapes(TopoDS_Shape& S1,
1209 const TopoDS_Shape& S2)
1211 myBuilder.Add(S1,S2);
1214 //=======================================================================
1217 //=======================================================================
1219 void BRepTools_ShapeSet::Check(const TopAbs_ShapeEnum T,
1222 if (T == TopAbs_FACE) {
1223 const TopoDS_Face& F = TopoDS::Face(S);
1224 BRepTools::Update(F);
1230 //=======================================================================
1231 //function : WritePolygonOnTriangulation
1233 //=======================================================================
1235 void BRepTools_ShapeSet::WritePolygonOnTriangulation(Standard_OStream& OS,
1236 const Standard_Boolean Compact)const
1238 Standard_Integer i, j, nbpOntri = myNodes.Extent();
1240 Handle(Message_ProgressIndicator) progress = GetProgress();
1241 Message_ProgressSentry PS(progress, "Polygons On Triangulation", 0, nbpOntri, 1);
1243 OS << "PolygonOnTriangulations " << nbpOntri << "\n";
1246 OS <<"Dump of " << nbpOntri << " PolygonOnTriangulations\n";
1250 Handle(Poly_PolygonOnTriangulation) Poly;
1251 Handle(TColStd_HArray1OfReal) Param;
1252 for (i=1; i<=nbpOntri && PS.More(); i++, PS.Next()) {
1253 Poly = Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(i));
1254 const TColStd_Array1OfInteger& Nodes = Poly->Nodes();
1256 OS << " "<< i << " : PolygonOnTriangulation with " << Nodes.Length() << " Nodes\n";
1258 else OS << Nodes.Length()<<" ";
1259 if (!Compact) OS <<" ";
1260 for (j=1; j <= Nodes.Length(); j++) OS << Nodes.Value(j) << " ";
1263 // writing parameters:
1264 Param = Poly->Parameters();
1265 if (Compact) OS <<"p ";
1267 // write the deflection
1268 if (!Compact) OS << " Deflection : ";
1269 OS <<Poly->Deflection() << " ";
1270 if (!Compact) OS << "\n";
1272 if (!Param.IsNull()) {
1274 OS << " Parameters :";
1277 if (!Compact) OS <<" ";
1278 for (j=1; j <= Param->Length(); j++) OS << Param->Value(j) << " ";
1285 //=======================================================================
1286 //function : DumpPolygonOnTriangulation
1288 //=======================================================================
1290 void BRepTools_ShapeSet::DumpPolygonOnTriangulation(Standard_OStream& OS)const
1292 WritePolygonOnTriangulation(OS, Standard_False);
1295 //=======================================================================
1296 //function : ReadPolygonOnTriangulation
1298 //=======================================================================
1300 void BRepTools_ShapeSet::ReadPolygonOnTriangulation(Standard_IStream& IS)
1304 if (strstr(buffer,"PolygonOnTriangulations") == NULL) return;
1305 Standard_Integer i, j, val, nbpol = 0, nbnodes =0;
1306 Standard_Integer hasparameters;
1308 Handle(TColStd_HArray1OfReal) Param;
1309 Handle(Poly_PolygonOnTriangulation) Poly;
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()) {
1316 TColStd_Array1OfInteger Nodes(1, nbnodes);
1317 for (j = 1; j <= nbnodes; j++) {
1322 // if (!strcasecmp(buffer, "p")) {
1324 GeomTools::GetReal(IS, def);
1325 IS >> hasparameters;
1326 if (hasparameters) {
1327 TColStd_Array1OfReal Param1(1, nbnodes);
1328 for (j = 1; j <= nbnodes; j++) {
1329 GeomTools::GetReal(IS, par);
1332 Poly = new Poly_PolygonOnTriangulation(Nodes, Param1);
1334 else Poly = new Poly_PolygonOnTriangulation(Nodes);
1335 Poly->Deflection(def);
1339 // Poly = new Poly_PolygonOnTriangulation(Nodes);
1344 // else IS.seekg(pos);
1349 //=======================================================================
1350 //function : WritePolygon3D
1352 //=======================================================================
1354 void BRepTools_ShapeSet::WritePolygon3D(Standard_OStream& OS,
1355 const Standard_Boolean Compact)const
1357 Standard_Integer i, j, nbpol = myPolygons3D.Extent();
1359 Handle(Message_ProgressIndicator) progress = GetProgress();
1360 Message_ProgressSentry PS(progress, "3D Poligons", 0, nbpol, 1);
1363 OS << "Polygon3D " << nbpol << "\n";
1366 OS <<"Dump of " << nbpol << " Polygon3Ds\n";
1370 Handle(Poly_Polygon3D) P;
1371 for (i = 1; i <= nbpol && PS.More(); i++, PS.Next()) {
1372 P = Handle(Poly_Polygon3D)::DownCast(myPolygons3D(i));
1374 OS << P->NbNodes() << " ";
1375 OS << ((P->HasParameters()) ? "1" : "0") << "\n";
1378 OS << " "<< i << " : Polygon3D with " << P->NbNodes() << " Nodes\n";
1379 OS << ((P->HasParameters()) ? "with" : "without") << " parameters\n";
1383 // write the deflection
1384 if (!Compact) OS << "Deflection : ";
1385 OS << P->Deflection() << "\n";
1388 if (!Compact) OS << "\nNodes :\n";
1390 Standard_Integer i1, nbNodes = P->NbNodes();
1391 const TColgp_Array1OfPnt& Nodes = P->Nodes();
1392 for (j = 1; j <= nbNodes; j++) {
1393 if (!Compact) OS << std::setw(10) << j << " : ";
1394 if (!Compact) OS << std::setw(17);
1395 OS << Nodes(j).X() << " ";
1396 if (!Compact) OS << std::setw(17);
1397 OS << Nodes(j).Y() << " ";
1398 if (!Compact) OS << std::setw(17);
1400 if (!Compact) OS << "\n";
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) << " ";
1416 //=======================================================================
1417 //function : DumpPolygon3D
1419 //=======================================================================
1421 void BRepTools_ShapeSet::DumpPolygon3D(Standard_OStream& OS)const
1423 WritePolygon3D(OS, Standard_False);
1427 //=======================================================================
1428 //function : ReadPolygon3D
1430 //=======================================================================
1432 void BRepTools_ShapeSet::ReadPolygon3D(Standard_IStream& IS)
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;
1440 if (strstr(buffer,"Polygon3D") == NULL) return;
1441 Handle(Poly_Polygon3D) P;
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()) {
1448 IS >> hasparameters;
1449 TColgp_Array1OfPnt Nodes(1, nbnodes);
1450 GeomTools::GetReal(IS, d);
1451 for (j = 1; j <= nbnodes; j++) {
1452 GeomTools::GetReal(IS, x);
1453 GeomTools::GetReal(IS, y);
1454 GeomTools::GetReal(IS, z);
1455 Nodes(j).SetCoord(x,y,z);
1457 if (hasparameters) {
1458 TColStd_Array1OfReal Param(1,nbnodes);
1459 for (p = 1; p <= nbnodes; p++) {
1460 GeomTools::GetReal(IS, Param(p));
1462 P = new Poly_Polygon3D(Nodes, Param);
1464 else P = new Poly_Polygon3D(Nodes);
1466 myPolygons3D.Add(P);
1472 //=======================================================================
1473 //function : WriteTriangulation
1475 //=======================================================================
1477 void BRepTools_ShapeSet::WriteTriangulation(Standard_OStream& OS,
1478 const Standard_Boolean Compact)const
1480 Standard_Integer i, j, nbNodes, nbtri = myTriangulations.Extent();
1481 Standard_Integer nbTriangles = 0, n1, n2, n3;
1483 Handle(Message_ProgressIndicator) progress = GetProgress();
1484 Message_ProgressSentry PS(progress, "Triangulations", 0, nbtri, 1);
1487 OS << "Triangulations " << nbtri << "\n";
1490 OS <<"Dump of " << nbtri << " Triangulations\n";
1494 Handle(Poly_Triangulation) T;
1495 for (i = 1; i <= nbtri && PS.More(); i++, PS.Next()) {
1497 T = Handle(Poly_Triangulation)::DownCast(myTriangulations(i));
1499 OS << T->NbNodes() << " " << T->NbTriangles() << " ";
1500 OS << ((T->HasUVNodes()) ? "1" : "0") << " ";
1503 OS << " "<< i << " : Triangulation with " << T->NbNodes() << " Nodes and "
1504 << T->NbTriangles() <<" Triangles\n";
1505 OS << " "<<((T->HasUVNodes()) ? "with" : "without") << " UV nodes\n";
1509 // write the deflection
1511 if (!Compact) OS << " Deflection : ";
1512 OS <<T->Deflection() << "\n";
1514 // write the 3d nodes
1516 if (!Compact) OS << "\n3D Nodes :\n";
1518 nbNodes = T->NbNodes();
1519 const TColgp_Array1OfPnt& Nodes = T->Nodes();
1520 for (j = 1; j <= nbNodes; j++) {
1521 if (!Compact) OS << std::setw(10) << j << " : ";
1522 if (!Compact) OS << std::setw(17);
1523 OS << Nodes(j).X() << " ";
1524 if (!Compact) OS << std::setw(17);
1525 OS << Nodes(j).Y() << " ";
1526 if (!Compact) OS << std::setw(17);
1528 if (!Compact) OS << "\n";
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++) {
1536 if (!Compact) OS << std::setw(10) << j << " : ";
1537 if (!Compact) OS << std::setw(17);
1538 OS << UVNodes(j).X() << " ";
1539 if (!Compact) OS << std::setw(17);
1540 OS << UVNodes(j).Y();
1541 if (!Compact) OS << "\n";
1546 if (!Compact) OS << "\nTriangles :\n";
1547 nbTriangles = T->NbTriangles();
1548 const Poly_Array1OfTriangle& Triangles = T->Triangles();
1549 for (j = 1; j <= nbTriangles; j++) {
1550 if (!Compact) OS << std::setw(10) << j << " : ";
1551 Triangles(j).Get(n1, n2, n3);
1552 if (!Compact) OS << std::setw(10);
1554 if (!Compact) OS << std::setw(10);
1556 if (!Compact) OS << std::setw(10);
1558 if (!Compact) OS << "\n";
1565 //=======================================================================
1566 //function : DumpTriangulation
1568 //=======================================================================
1570 void BRepTools_ShapeSet::DumpTriangulation(Standard_OStream& OS)const
1572 WriteTriangulation(OS, Standard_False);
1576 //=======================================================================
1577 //function : ReadTriangulation
1579 //=======================================================================
1581 void BRepTools_ShapeSet::ReadTriangulation(Standard_IStream& IS)
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;
1590 Handle(Poly_Triangulation) T;
1593 if (strstr(buffer,"Triangulations") == NULL) return;
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()) {
1601 IS >> nbNodes >> nbTriangles >> hasUV;
1602 GeomTools::GetReal(IS, d);
1604 TColgp_Array1OfPnt Nodes(1, nbNodes);
1605 TColgp_Array1OfPnt2d UVNodes(1, nbNodes);
1607 for (j = 1; j <= nbNodes; j++) {
1608 GeomTools::GetReal(IS, x);
1609 GeomTools::GetReal(IS, y);
1610 GeomTools::GetReal(IS, z);
1611 Nodes(j).SetCoord(x,y,z);
1615 for (j = 1; j <= nbNodes; j++) {
1616 GeomTools::GetReal(IS, x);
1617 GeomTools::GetReal(IS, y);
1618 UVNodes(j).SetCoord(x,y);
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);
1630 if (hasUV) T = new Poly_Triangulation(Nodes,UVNodes,Triangles);
1631 else T = new Poly_Triangulation(Nodes,Triangles);
1635 myTriangulations.Add(T);