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 <Standard_Stream.hxx>
20 #include <Precision.hxx>
21 #include <BRepTools_ShapeSet.ixx>
23 #include <BRepTools.hxx>
24 #include <GeomTools.hxx>
27 #include <TColStd_HArray1OfInteger.hxx>
28 #include <BRep_TFace.hxx>
29 #include <BRep_TEdge.hxx>
30 #include <BRep_TVertex.hxx>
31 #include <BRep_Tool.hxx>
32 #include <BRep_CurveRepresentation.hxx>
33 #include <Poly_Polygon3D.hxx>
34 #include <BRep_Polygon3D.hxx>
35 #include <BRep_PolygonOnSurface.hxx>
36 #include <BRep_PolygonOnClosedSurface.hxx>
37 #include <BRep_PolygonOnTriangulation.hxx>
38 #include <BRep_PolygonOnClosedTriangulation.hxx>
39 #include <BRep_CurveOnSurface.hxx>
40 #include <BRep_CurveOnClosedSurface.hxx>
41 #include <BRep_ListOfCurveRepresentation.hxx>
42 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
43 #include <BRep_PointOnCurve.hxx>
44 #include <BRep_PointOnCurveOnSurface.hxx>
45 #include <BRep_PointOnSurface.hxx>
46 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
48 #include <TopoDS_Vertex.hxx>
50 #include <TColgp_HArray1OfPnt.hxx>
51 #include <TColgp_HArray1OfPnt2d.hxx>
52 #include <TColStd_HArray1OfReal.hxx>
53 #include <Poly_Triangulation.hxx>
54 #include <Poly_PolygonOnTriangulation.hxx>
56 #include <Message_ProgressIndicator.hxx>
57 #include <Message_ProgressSentry.hxx>
58 #include <BRep_GCurve.hxx>
61 #define strcasecmp(p,q) strcmp(p,q)
63 #define strcasecmp strcmp
68 // Modified: 02 Nov 2000: BUC60769. JMB, PTV. In order to be able to read BRep
69 // files that came from a platform different from where CasCade
70 // is run, we need the following modifications.
72 // On NT platforms (in BRepTools_ShapeSet):
74 // In Visual C++ 5 (or higher) the fstream::tellg method is not
75 // conform to Standard C++ because it modifies the file pointer
76 // position and returns a wrong position. After that the next
77 // readings are shifted and the reading process stop with errors.
79 // Workaround is following: Now we don`t use tellg for get position in stream.
80 // Now able to read file (when reading TopAbs_FACE) without tellg.
81 // We simple check the next string if there are value that equal 2
82 // (It means a parametr for triangulation).
85 //=======================================================================
86 //function : BRepTools_ShapeSet
88 //=======================================================================
90 BRepTools_ShapeSet::BRepTools_ShapeSet(const Standard_Boolean isWithTriangles)
91 :myWithTriangles(isWithTriangles)
95 //=======================================================================
96 //function : BRepTools_ShapeSet
98 //=======================================================================
100 BRepTools_ShapeSet::BRepTools_ShapeSet (const BRep_Builder& B,
101 const Standard_Boolean isWithTriangles) :
102 myBuilder(B), myWithTriangles(isWithTriangles)
107 //=======================================================================
110 //=======================================================================
112 void BRepTools_ShapeSet::Clear()
117 myPolygons3D.Clear();
118 myPolygons2D.Clear();
120 myTriangulations.Clear();
121 TopTools_ShapeSet::Clear();
125 //=======================================================================
126 //function : AddGeometry
128 //=======================================================================
130 void BRepTools_ShapeSet::AddGeometry(const TopoDS_Shape& S)
134 if (S.ShapeType() == TopAbs_VERTEX) {
136 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
137 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
139 while (itrp.More()) {
140 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
142 if (PR->IsPointOnCurve()) {
143 myCurves.Add(PR->Curve());
146 else if (PR->IsPointOnCurveOnSurface()) {
147 myCurves2d.Add(PR->PCurve());
148 mySurfaces.Add(PR->Surface());
151 else if (PR->IsPointOnSurface()) {
152 mySurfaces.Add(PR->Surface());
155 ChangeLocations().Add(PR->Location());
160 else if (S.ShapeType() == TopAbs_EDGE) {
162 // Add the curve geometry
163 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
164 BRep_ListIteratorOfListOfCurveRepresentation itrc(TE->Curves());
166 while (itrc.More()) {
167 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
168 if (CR->IsCurve3D()) {
169 if (!CR->Curve3D().IsNull()) {
170 myCurves.Add(CR->Curve3D());
171 ChangeLocations().Add(CR->Location());
174 else if (CR->IsCurveOnSurface()) {
175 mySurfaces.Add(CR->Surface());
176 myCurves2d.Add(CR->PCurve());
177 ChangeLocations().Add(CR->Location());
178 if (CR->IsCurveOnClosedSurface())
179 myCurves2d.Add(CR->PCurve2());
181 else if (CR->IsRegularity()) {
182 mySurfaces.Add(CR->Surface());
183 ChangeLocations().Add(CR->Location());
184 mySurfaces.Add(CR->Surface2());
185 ChangeLocations().Add(CR->Location2());
187 else if (myWithTriangles) { // for XML Persistence
188 if (CR->IsPolygon3D()) {
189 if (!CR->Polygon3D().IsNull()) {
190 myPolygons3D.Add(CR->Polygon3D());
191 ChangeLocations().Add(CR->Location());
194 else if (CR->IsPolygonOnTriangulation()) {
195 myTriangulations.Add(CR->Triangulation());
196 myNodes.Add(CR->PolygonOnTriangulation());
197 ChangeLocations().Add(CR->Location());
198 if (CR->IsPolygonOnClosedTriangulation())
199 myNodes.Add(CR->PolygonOnTriangulation2());
201 else if (CR->IsPolygonOnSurface()) {
202 mySurfaces.Add(CR->Surface());
203 myPolygons2D.Add(CR->Polygon());
204 ChangeLocations().Add(CR->Location());
205 if (CR->IsPolygonOnClosedSurface())
206 myPolygons2D.Add(CR->Polygon2());
213 else if (S.ShapeType() == TopAbs_FACE) {
215 // Add the surface geometry
216 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
217 if (!TF->Surface().IsNull()) mySurfaces.Add(TF->Surface());
219 if (myWithTriangles) { // for XML Persistence
220 Handle(Poly_Triangulation) Tr = TF->Triangulation();
221 if (!Tr.IsNull()) myTriangulations.Add(Tr);
224 ChangeLocations().Add(TF->Location());
229 //=======================================================================
230 //function : DumpGeometry
232 //=======================================================================
234 void BRepTools_ShapeSet::DumpGeometry(Standard_OStream& OS)const
239 DumpPolygonOnTriangulation(OS);
241 DumpTriangulation(OS);
245 //=======================================================================
246 //function : WriteGeometry
248 //=======================================================================
250 void BRepTools_ShapeSet::WriteGeometry(Standard_OStream& OS)
253 myCurves2d.SetProgress(GetProgress());
254 myCurves.SetProgress(GetProgress());
255 mySurfaces.SetProgress(GetProgress());
257 if ( !GetProgress().IsNull()) {
258 if(GetProgress()->UserBreak() ) return;
259 GetProgress()->NewScope ( 15, "2D Curves" );
261 myCurves2d.Write(OS);
263 if ( !GetProgress().IsNull()) {
264 if( GetProgress()->UserBreak() ) return;
265 GetProgress()->EndScope();
266 GetProgress()->Show();
268 GetProgress()->NewScope ( 15, "3D Curves" );
272 if ( !GetProgress().IsNull()) {
273 if( GetProgress()->UserBreak() ) return;
274 GetProgress()->EndScope();
275 GetProgress()->Show();
277 GetProgress()->NewScope ( 10, "3D Polygons" );
280 if ( !GetProgress().IsNull()) {
281 if( GetProgress()->UserBreak() ) return;
282 GetProgress()->EndScope();
283 GetProgress()->Show();
285 GetProgress()->NewScope ( 10, "Polygons On Triangulation" );
287 WritePolygonOnTriangulation(OS);
288 if ( !GetProgress().IsNull()) {
289 if( GetProgress()->UserBreak() ) return;
290 GetProgress()->EndScope();
291 GetProgress()->Show();
293 GetProgress()->NewScope ( 10, "Surfaces" );
295 mySurfaces.Write(OS);
296 if ( !GetProgress().IsNull()) {
297 if( GetProgress()->UserBreak() ) return;
298 GetProgress()->EndScope();
299 GetProgress()->Show();
301 GetProgress()->NewScope ( 15, "Triangulations" );
303 WriteTriangulation(OS);
304 if ( !GetProgress().IsNull()) {
305 if( GetProgress()->UserBreak() ) return;
306 GetProgress()->EndScope();
307 GetProgress()->Show();
312 //=======================================================================
313 //function : ReadGeometry
315 //=======================================================================
317 void BRepTools_ShapeSet::ReadGeometry(Standard_IStream& IS)
320 myCurves2d.SetProgress(GetProgress());
321 myCurves.SetProgress(GetProgress());
322 mySurfaces.SetProgress(GetProgress());
324 if ( !GetProgress().IsNull()) {
325 if( GetProgress()->UserBreak() ) return;
326 GetProgress()->NewScope ( 15, "2D Curves" );
330 if ( !GetProgress().IsNull()) {
331 if( GetProgress()->UserBreak() ) return;
332 GetProgress()->EndScope();
333 GetProgress()->Show();
335 GetProgress()->NewScope ( 15, "3D Curves" );
339 if ( !GetProgress().IsNull()) {
340 if( GetProgress()->UserBreak() ) return;
341 GetProgress()->EndScope();
342 GetProgress()->Show();
344 GetProgress()->NewScope ( 10, "3D Polygons" );
347 if ( !GetProgress().IsNull() ) {
348 if( GetProgress()->UserBreak() ) return;
349 GetProgress()->EndScope();
350 GetProgress()->Show();
352 GetProgress()->NewScope ( 10, "Polygons On Triangulation" );
354 ReadPolygonOnTriangulation(IS);
355 if ( !GetProgress().IsNull()) {
356 if( GetProgress()->UserBreak() ) return;
357 GetProgress()->EndScope();
358 GetProgress()->Show();
360 GetProgress()->NewScope ( 10, "Surfaces" );
363 if ( !GetProgress().IsNull() ) {
364 if( GetProgress()->UserBreak() ) return;
365 GetProgress()->EndScope();
366 GetProgress()->Show();
368 GetProgress()->NewScope ( 15, "Triangulations" );
370 ReadTriangulation(IS);
371 if ( !GetProgress().IsNull()) {
372 if( GetProgress()->UserBreak() ) return;
373 GetProgress()->EndScope();
374 GetProgress()->Show();
378 //=======================================================================
379 //function : PrintRegularity
381 //=======================================================================
383 static void PrintRegularity(const GeomAbs_Shape C,
384 Standard_OStream& OS)
419 //=======================================================================
420 //function : DumpGeometry
422 //=======================================================================
424 void BRepTools_ShapeSet::DumpGeometry(const TopoDS_Shape& S,
425 Standard_OStream& OS)const
429 if (S.ShapeType() == TopAbs_VERTEX) {
431 // Dump the point geometry
432 TopoDS_Vertex V = TopoDS::Vertex(S);
433 OS << " Tolerance : " << BRep_Tool::Tolerance(V) << "\n";
434 gp_Pnt p = BRep_Tool::Pnt(V);
435 OS << " - Point 3D : "<<p.X()<<", "<<p.Y()<<", "<<p.Z()<<"\n";
437 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
438 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
440 while (itrp.More()) {
441 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
443 OS << " - Parameter : "<< PR->Parameter();
444 if (PR->IsPointOnCurve()) {
445 OS << " on curve " << myCurves.Index(PR->Curve());
448 else if (PR->IsPointOnCurveOnSurface()) {
449 OS << " on pcurve " << myCurves2d.Index(PR->PCurve());
450 OS << " on surface " << mySurfaces.Index(PR->Surface());
453 else if (PR->IsPointOnSurface()) {
454 OS << ", " << PR->Parameter2() << " on surface ";
455 OS << mySurfaces.Index(PR->Surface());
458 if (!PR->Location().IsIdentity())
459 OS << " location " << Locations().Index(PR->Location());
467 else if (S.ShapeType() == TopAbs_EDGE) {
469 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
472 // Dump the curve geometry
473 OS << " Tolerance : " << TE->Tolerance() << "\n";
474 if (TE->SameParameter()) OS << " same parametrisation of curves\n";
475 if (TE->SameRange()) OS << " same range on curves\n";
476 if (TE->Degenerated()) OS << " degenerated\n";
478 Standard_Real first, last;
479 BRep_ListIteratorOfListOfCurveRepresentation itrc = TE->Curves();
480 while (itrc.More()) {
481 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
482 if (CR->IsCurve3D()) {
483 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
484 GC->Range(first, last);
485 if (!CR->Curve3D().IsNull()) {
486 OS << " - Curve 3D : "<<myCurves.Index(CR->Curve3D());
487 if (!CR->Location().IsIdentity())
488 OS << " location "<<Locations().Index(CR->Location());
489 OS <<", range : " << first << " " << last <<"\n";
492 else if (CR->IsCurveOnSurface()) {
493 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
494 GC->Range(first, last);
495 OS <<" - PCurve : "<<myCurves2d.Index(CR->PCurve());
496 if (CR->IsCurveOnClosedSurface()) {
497 OS <<", " << myCurves2d.Index(CR->PCurve2());
499 PrintRegularity(CR->Continuity(),OS);
502 OS << " on surface "<<mySurfaces.Index(CR->Surface());
503 if (!CR->Location().IsIdentity())
504 OS << " location "<<Locations().Index(CR->Location());
505 OS <<", range : " << first << " " << last <<"\n";
507 Handle(BRep_CurveOnSurface) COS =
508 Handle(BRep_CurveOnSurface)::DownCast(CR);
509 COS->UVPoints(Pf,Pl);
510 OS << " UV Points : " <<Pf.X()<<", "<<Pf.Y()<<" ";
511 OS << Pl.X()<<", "<<Pl.Y()<<"\n";
512 if (CR->IsCurveOnClosedSurface()) {
513 Handle(BRep_CurveOnClosedSurface) COCS =
514 Handle(BRep_CurveOnClosedSurface)::DownCast(CR);
515 COCS->UVPoints2(Pf,Pl);
516 OS << " UV Points : " <<Pf.X()<<", "<<Pf.Y()<<" ";
517 OS << Pl.X()<<", "<<Pl.Y()<<"\n";
520 else if (CR->IsRegularity()) {
521 OS << " - Regularity ";
522 PrintRegularity(CR->Continuity(),OS);
523 OS << " on surfaces : "<<mySurfaces.Index(CR->Surface());
524 if (!CR->Location().IsIdentity())
525 OS << " location "<<Locations().Index(CR->Location());
526 OS << ", "<<mySurfaces.Index(CR->Surface2());
527 if (!CR->Location2().IsIdentity())
528 OS << " location "<<Locations().Index(CR->Location2());
531 else if (CR->IsPolygon3D()) {
532 Handle(BRep_Polygon3D) GC = Handle(BRep_Polygon3D)::DownCast(itrc.Value());
533 if (!GC->Polygon3D().IsNull()) {
534 OS << " - Polygon 3D : "<<myPolygons3D.FindIndex(CR->Polygon3D());
535 if (!CR->Location().IsIdentity())
536 OS << " location "<<Locations().Index(CR->Location());
539 else if (CR->IsPolygonOnTriangulation()) {
540 OS << " - PolygonOnTriangulation " << myNodes.FindIndex(CR->PolygonOnTriangulation());
541 if (CR->IsPolygonOnClosedTriangulation()) {
542 OS << " " << myNodes.FindIndex(CR->PolygonOnTriangulation2());
544 OS << " on triangulation " << myTriangulations.FindIndex(CR->Triangulation());
545 if (!CR->Location().IsIdentity())
546 OS << " location "<<Locations().Index(CR->Location());
553 else if (S.ShapeType() == TopAbs_FACE) {
555 const TopoDS_Face& F = TopoDS::Face(S);
556 if (BRep_Tool::NaturalRestriction(F))
557 OS << "NaturalRestriction\n";
559 // Dump the surface geometry
560 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
561 if (!TF->Surface().IsNull()) {
562 OS << " Tolerance : " <<TF->Tolerance() << "\n";
563 OS << " - Surface : "<<mySurfaces.Index(TF->Surface());
564 if (!S.Location().IsIdentity())
565 OS << " location "<<Locations().Index(S.Location());
568 if (!(TF->Triangulation()).IsNull()) {
569 // Dump the triangulation
570 OS << " - Triangulation : " <<myTriangulations.FindIndex(TF->Triangulation());
571 if (!S.Location().IsIdentity())
572 OS << " location " <<Locations().Index(TF->Location());
581 //=======================================================================
582 //function : WriteGeometry
584 //=======================================================================
586 void BRepTools_ShapeSet::WriteGeometry(const TopoDS_Shape& S,
587 Standard_OStream& OS)const
589 // Write the geometry
591 if (S.ShapeType() == TopAbs_VERTEX) {
593 // Write the point geometry
594 TopoDS_Vertex V = TopoDS::Vertex(S);
595 OS << BRep_Tool::Tolerance(V) << "\n";
596 gp_Pnt p = BRep_Tool::Pnt(V);
597 OS<<p.X()<<" "<<p.Y()<<" "<<p.Z()<<"\n";
599 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
600 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
602 while (itrp.More()) {
603 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
605 OS << PR->Parameter();
606 if (PR->IsPointOnCurve()) {
607 OS << " 1 " << myCurves.Index(PR->Curve());
610 else if (PR->IsPointOnCurveOnSurface()) {
611 OS << " 2 " << myCurves2d.Index(PR->PCurve());
612 OS << " " << mySurfaces.Index(PR->Surface());
615 else if (PR->IsPointOnSurface()) {
616 OS << " 3 " << PR->Parameter2() << " ";
617 OS << mySurfaces.Index(PR->Surface());
620 OS << " " << Locations().Index(PR->Location());
626 OS << "0 0\n"; // end representations
630 else if (S.ShapeType() == TopAbs_EDGE) {
632 // Write the curve geometry
634 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
636 OS << " " << TE->Tolerance() << " ";
637 OS << ((TE->SameParameter()) ? 1 : 0) << " ";
638 OS << ((TE->SameRange()) ? 1 : 0) << " ";
639 OS << ((TE->Degenerated()) ? 1 : 0) << "\n";
641 Standard_Real first, last;
642 BRep_ListIteratorOfListOfCurveRepresentation itrc = TE->Curves();
643 while (itrc.More()) {
644 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
645 if (CR->IsCurve3D()) {
646 if (!CR->Curve3D().IsNull()) {
647 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
648 GC->Range(first, last);
649 OS << "1 "; // -1- Curve 3D
650 OS << " "<<myCurves.Index(CR->Curve3D());
651 OS << " "<<Locations().Index(CR->Location());
652 OS << " "<<first<<" "<<last;
656 else if (CR->IsCurveOnSurface()) {
657 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
658 GC->Range(first, last);
659 if (!CR->IsCurveOnClosedSurface())
660 OS << "2 "; // -2- Curve on surf
662 OS << "3 "; // -3- Curve on closed surf
663 OS <<" "<<myCurves2d.Index(CR->PCurve());
664 if (CR->IsCurveOnClosedSurface()) {
665 OS <<" " << myCurves2d.Index(CR->PCurve2());
666 PrintRegularity(CR->Continuity(),OS);
668 OS << " " << mySurfaces.Index(CR->Surface());
669 OS << " " << Locations().Index(CR->Location());
670 OS << " "<<first<<" "<<last;
673 // Write UV Points // for XML Persistence higher performance
677 if (CR->IsCurveOnClosedSurface()) {
678 Handle(BRep_CurveOnClosedSurface) COCS =
679 Handle(BRep_CurveOnClosedSurface)::DownCast(CR);
680 COCS->UVPoints2(Pf,Pl);
683 Handle(BRep_CurveOnSurface) COS =
684 Handle(BRep_CurveOnSurface)::DownCast(CR);
685 COS->UVPoints(Pf,Pl);
687 OS << Pf.X() << " " << Pf.Y() << " " << Pl.X() << " " << Pl.Y() << "\n";
690 else if (CR->IsRegularity()) {
691 OS << "4 "; // -4- Regularity
692 PrintRegularity(CR->Continuity(),OS);
693 OS << " "<<mySurfaces.Index(CR->Surface());
694 OS << " "<<Locations().Index(CR->Location());
695 OS << " "<<mySurfaces.Index(CR->Surface2());
696 OS << " "<<Locations().Index(CR->Location2());
700 else if (myWithTriangles) { // for XML Persistence
701 if (CR->IsPolygon3D()) {
702 Handle(BRep_Polygon3D) GC = Handle(BRep_Polygon3D)::DownCast(itrc.Value());
703 if (!GC->Polygon3D().IsNull()) {
704 OS << "5 "; // -5- Polygon3D
705 OS << " "<<myPolygons3D.FindIndex(CR->Polygon3D());
706 OS << " "<<Locations().Index(CR->Location());
710 else if (CR->IsPolygonOnTriangulation()) {
711 Handle(BRep_PolygonOnTriangulation) PT =
712 Handle(BRep_PolygonOnTriangulation)::DownCast(itrc.Value());
713 if (!CR->IsPolygonOnClosedTriangulation())
714 OS << "6 "; // -6- Polygon on triangulation
716 OS << "7 "; // -7- Polygon on closed triangulation
717 OS << " " << myNodes.FindIndex(PT->PolygonOnTriangulation());
718 if (CR->IsPolygonOnClosedTriangulation()) {
719 OS << " " << myNodes.FindIndex(PT->PolygonOnTriangulation2());
721 OS << " " << myTriangulations.FindIndex(PT->Triangulation());
722 OS << " "<<Locations().Index(CR->Location());
729 OS << "0\n"; // end of the list of representations
732 else if (S.ShapeType() == TopAbs_FACE) {
734 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
735 const TopoDS_Face& F = TopoDS::Face(S);
737 if (!(TF->Surface()).IsNull()) {
738 OS << ((BRep_Tool::NaturalRestriction(F)) ? 1 : 0);
740 // Write the surface geometry
741 OS << " " <<TF->Tolerance();
742 OS << " " <<mySurfaces.Index(TF->Surface());
743 OS << " " <<Locations().Index(TF->Location());
746 else //For correct reading of null face
750 OS << " " <<TF->Tolerance();
755 if (myWithTriangles) { // for XML Persistence
756 if (!(TF->Triangulation()).IsNull()) {
759 // Write the triangulation
760 OS << " " <<myTriangulations.FindIndex(TF->Triangulation());
767 //=======================================================================
768 //function : ReadRegularity
770 //=======================================================================
772 static GeomAbs_Shape ReadRegularity(Standard_IStream& IS)
813 //=======================================================================
814 //function : ReadGeometry
816 //=======================================================================
818 void BRepTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T,
819 Standard_IStream& IS,
824 Standard_Integer val,c,pc,pc2 = 0,s,s2,l,l2,t, pt, pt2 = 0;
825 Standard_Real tol,X,Y,Z,first,last,p1,p2;
826 Standard_Real PfX,PfY,PlX,PlY;
828 Standard_Boolean closed;
829 GeomAbs_Shape reg = GeomAbs_C0;
839 TopoDS_Vertex& V = TopoDS::Vertex(S);
841 // Read the point geometry
842 GeomTools::GetReal(IS, tol);
843 GeomTools::GetReal(IS, X);
844 GeomTools::GetReal(IS, Y);
845 GeomTools::GetReal(IS, Z);
846 myBuilder.MakeVertex(V,gp_Pnt(X,Y,Z),tol);
847 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(V.TShape());
849 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
853 GeomTools::GetReal(IS, p1);
856 Handle(BRep_PointRepresentation) PR;
863 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
864 if (myCurves.Curve(c).IsNull())
866 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
868 Handle(BRep_PointOnCurve) POC =
869 new BRep_PointOnCurve(p1,
880 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
881 if (myCurves2d.Curve2d(pc).IsNull() ||
882 mySurfaces.Surface(s).IsNull())
884 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
886 Handle(BRep_PointOnCurveOnSurface) POC =
887 new BRep_PointOnCurveOnSurface(p1,
888 myCurves2d.Curve2d(pc),
889 mySurfaces.Surface(s),
897 GeomTools::GetReal(IS, p2);
900 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
901 if (mySurfaces.Surface(s).IsNull())
903 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
905 Handle(BRep_PointOnSurface) POC =
906 new BRep_PointOnSurface(p1,p2,
907 mySurfaces.Surface(s),
917 PR->Location(Locations().Location(l));
935 TopoDS_Edge& E = TopoDS::Edge(S);
937 myBuilder.MakeEdge(E);
939 // Read the curve geometry
940 GeomTools::GetReal(IS, tol);
942 myBuilder.SameParameter(E,(val == 1));
944 myBuilder.SameRange(E,(val == 1));
946 myBuilder.Degenerated(E,(val == 1));
952 case 1 : // -1- Curve 3D
954 if (!myCurves.Curve(c).IsNull()) {
955 myBuilder.UpdateEdge(E,myCurves.Curve(c),
956 Locations().Location(l),tol);
958 GeomTools::GetReal(IS, first);
959 GeomTools::GetReal(IS, last);
960 if (!myCurves.Curve(c).IsNull()) {
961 Standard_Boolean Only3d = Standard_True;
962 myBuilder.Range(E,first,last,Only3d);
967 case 2 : // -2- Curve on surf
968 case 3 : // -3- Curve on closed surf
973 reg = ReadRegularity(IS);
980 GeomTools::GetReal(IS, first);
981 GeomTools::GetReal(IS, last);
983 // read UV Points // for XML Persistence higher performance
986 GeomTools::GetReal(IS, PfX);
987 GeomTools::GetReal(IS, PfY);
988 GeomTools::GetReal(IS, PlX);
989 GeomTools::GetReal(IS, PlY);
990 aPf = gp_Pnt2d(PfX,PfY);
991 aPl = gp_Pnt2d(PlX,PlY);
994 // Modified by Sergey KHROMOV - Wed Apr 24 12:11:16 2002 Begin
995 if (myCurves2d.Curve2d(pc).IsNull() ||
996 (closed && myCurves2d.Curve2d(pc2).IsNull()) ||
997 mySurfaces.Surface(s).IsNull())
999 // Modified by Sergey KHROMOV - Wed Apr 24 12:11:17 2002 End
1002 if (FormatNb() == 2)
1003 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1004 myCurves2d.Curve2d(pc2),
1005 mySurfaces.Surface(s),
1006 Locations().Location(l),tol,
1009 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1010 myCurves2d.Curve2d(pc2),
1011 mySurfaces.Surface(s),
1012 Locations().Location(l),tol);
1014 myBuilder.Continuity(E,
1015 mySurfaces.Surface(s),
1016 mySurfaces.Surface(s),
1017 Locations().Location(l),
1018 Locations().Location(l),
1023 if (FormatNb() == 2)
1024 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1025 mySurfaces.Surface(s),
1026 Locations().Location(l),tol,
1029 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1030 mySurfaces.Surface(s),
1031 Locations().Location(l),tol);
1034 mySurfaces.Surface(s),
1035 Locations().Location(l),
1039 case 4 : // -4- Regularity
1040 reg = ReadRegularity(IS);
1041 IS >> s >> l >> s2 >> l2;
1042 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:13 2002 Begin
1043 if (mySurfaces.Surface(s).IsNull() ||
1044 mySurfaces.Surface(s2).IsNull())
1046 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:14 2002 End
1047 myBuilder.Continuity(E,
1048 mySurfaces.Surface(s),
1049 mySurfaces.Surface(s2),
1050 Locations().Location(l),
1051 Locations().Location(l2),
1055 case 5 : // -5- Polygon3D
1057 //szy-02.05.2004 myBuilder.UpdateEdge(E,Handle(Poly_Polygon3D)::DownCast(myPolygons3D(c)));
1058 if (c > 0 && c <= myPolygons3D.Extent())
1059 myBuilder.UpdateEdge(E,Handle(Poly_Polygon3D)::DownCast(myPolygons3D(c)), Locations().Location(l));
1064 closed = (val == 7);
1071 if (t > 0 && t <= myTriangulations.Extent() &&
1072 pt > 0 && pt <= myNodes.Extent() &&
1073 pt2 > 0 && pt2 <= myNodes.Extent())
1074 myBuilder.UpdateEdge
1075 (E, Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
1076 Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt2)),
1077 Handle(Poly_Triangulation)::DownCast(myTriangulations(t)),
1078 Locations().Location(l));
1081 if (t > 0 && t <= myTriangulations.Extent() &&
1082 pt > 0 && pt <= myNodes.Extent())
1083 myBuilder.UpdateEdge
1084 (E,Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
1085 Handle(Poly_Triangulation)::DownCast(myTriangulations(t)),
1086 Locations().Location(l));
1103 myBuilder.MakeWire(TopoDS::Wire(S));
1114 TopoDS_Face& F = TopoDS::Face(S);
1116 myBuilder.MakeFace(F);
1118 IS >> val; // natural restriction
1119 if (val == 0 || val == 1) {
1120 GeomTools::GetReal(IS, tol);
1122 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:13 2002 Begin
1123 if (!mySurfaces.Surface(s).IsNull()) {
1124 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:14 2002 End
1125 myBuilder.UpdateFace(TopoDS::Face(S),
1126 mySurfaces.Surface(s),
1127 Locations().Location(l),tol);
1128 myBuilder.NaturalRestriction(TopoDS::Face(S),(val == 1));
1130 // pos = IS.tellg();
1134 //only triangulation
1136 myBuilder.UpdateFace(TopoDS::Face(S),
1137 Handle(Poly_Triangulation)::DownCast(myTriangulations(s)));
1139 // else pos = IS.tellg();
1146 IS.getline ( string, 256, '\n' );
1147 IS.getline ( string, 256, '\n' );
1149 if (string[0] == '2') {
1150 // cas triangulation
1151 s = atoi ( &string[2] );
1152 if (s > 0 && s <= myTriangulations.Extent())
1153 myBuilder.UpdateFace(TopoDS::Face(S),
1154 Handle(Poly_Triangulation)::DownCast(myTriangulations(s)));
1156 // else IS.seekg(pos);
1166 myBuilder.MakeShell(TopoDS::Shell(S));
1175 myBuilder.MakeSolid(TopoDS::Solid(S));
1183 case TopAbs_COMPSOLID :
1184 myBuilder.MakeCompSolid(TopoDS::CompSolid(S));
1192 case TopAbs_COMPOUND :
1193 myBuilder.MakeCompound(TopoDS::Compound(S));
1204 //=======================================================================
1205 //function : AddShapes
1207 //=======================================================================
1209 void BRepTools_ShapeSet::AddShapes(TopoDS_Shape& S1,
1210 const TopoDS_Shape& S2)
1212 myBuilder.Add(S1,S2);
1215 //=======================================================================
1218 //=======================================================================
1220 void BRepTools_ShapeSet::Check(const TopAbs_ShapeEnum T,
1223 if (T == TopAbs_FACE) {
1224 const TopoDS_Face& F = TopoDS::Face(S);
1225 BRepTools::Update(F);
1231 //=======================================================================
1232 //function : WritePolygonOnTriangulation
1234 //=======================================================================
1236 void BRepTools_ShapeSet::WritePolygonOnTriangulation(Standard_OStream& OS,
1237 const Standard_Boolean Compact)const
1239 Standard_Integer i, j, nbpOntri = myNodes.Extent();
1241 Handle(Message_ProgressIndicator) progress = GetProgress();
1242 Message_ProgressSentry PS(progress, "Polygons On Triangulation", 0, nbpOntri, 1);
1244 OS << "PolygonOnTriangulations " << nbpOntri << endl;
1247 OS <<"Dump of " << nbpOntri << " PolygonOnTriangulations\n";
1251 Handle(Poly_PolygonOnTriangulation) Poly;
1252 Handle(TColStd_HArray1OfReal) Param;
1253 for (i=1; i<=nbpOntri && PS.More(); i++, PS.Next()) {
1254 Poly = Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(i));
1255 const TColStd_Array1OfInteger& Nodes = Poly->Nodes();
1257 OS << " "<< i << " : PolygonOnTriangulation with " << Nodes.Length() << " Nodes\n";
1259 else OS << Nodes.Length()<<" ";
1260 if (!Compact) OS <<" ";
1261 for (j=1; j <= Nodes.Length(); j++) OS << Nodes.Value(j) << " ";
1264 // writing parameters:
1265 Param = Poly->Parameters();
1266 if (Compact) OS <<"p ";
1268 // write the deflection
1269 if (!Compact) OS << " Deflection : ";
1270 OS <<Poly->Deflection() << " ";
1271 if (!Compact) OS << "\n";
1273 if (!Param.IsNull()) {
1275 OS << " "<< "Parameters :";
1278 if (!Compact) OS <<" ";
1279 for (j=1; j <= Param->Length(); j++) OS << Param->Value(j) << " ";
1286 //=======================================================================
1287 //function : DumpPolygonOnTriangulation
1289 //=======================================================================
1291 void BRepTools_ShapeSet::DumpPolygonOnTriangulation(Standard_OStream& OS)const
1293 WritePolygonOnTriangulation(OS, Standard_False);
1296 //=======================================================================
1297 //function : ReadPolygonOnTriangulation
1299 //=======================================================================
1301 void BRepTools_ShapeSet::ReadPolygonOnTriangulation(Standard_IStream& IS)
1305 if (strstr(buffer,"PolygonOnTriangulations") == NULL) return;
1306 Standard_Integer i, j, val, nbpol = 0, nbnodes =0;
1307 Standard_Integer hasparameters;
1309 Handle(TColStd_HArray1OfReal) Param;
1310 Handle(Poly_PolygonOnTriangulation) Poly;
1313 Handle(Message_ProgressIndicator) progress = GetProgress();
1314 Message_ProgressSentry PS(progress, "Polygons On Triangulation", 0, nbpol, 1);
1315 for (i=1; i<=nbpol&& PS.More(); i++, PS.Next()) {
1317 TColStd_Array1OfInteger Nodes(1, nbnodes);
1318 for (j = 1; j <= nbnodes; j++) {
1323 // if (!strcasecmp(buffer, "p")) {
1325 GeomTools::GetReal(IS, def);
1326 IS >> hasparameters;
1327 if (hasparameters) {
1328 TColStd_Array1OfReal Param1(1, nbnodes);
1329 for (j = 1; j <= nbnodes; j++) {
1330 GeomTools::GetReal(IS, par);
1333 Poly = new Poly_PolygonOnTriangulation(Nodes, Param1);
1335 else Poly = new Poly_PolygonOnTriangulation(Nodes);
1336 Poly->Deflection(def);
1340 // Poly = new Poly_PolygonOnTriangulation(Nodes);
1345 // else IS.seekg(pos);
1350 //=======================================================================
1351 //function : WritePolygon3D
1353 //=======================================================================
1355 void BRepTools_ShapeSet::WritePolygon3D(Standard_OStream& OS,
1356 const Standard_Boolean Compact)const
1358 Standard_Integer i, j, nbpol = myPolygons3D.Extent();
1360 Handle(Message_ProgressIndicator) progress = GetProgress();
1361 Message_ProgressSentry PS(progress, "3D Poligons", 0, nbpol, 1);
1364 OS << "Polygon3D " << nbpol << endl;
1367 OS <<"Dump of " << nbpol << " Polygon3Ds\n";
1371 Handle(Poly_Polygon3D) P;
1372 for (i = 1; i <= nbpol && PS.More(); i++, PS.Next()) {
1373 P = Handle(Poly_Polygon3D)::DownCast(myPolygons3D(i));
1375 OS << P->NbNodes() << " ";
1376 OS << ((P->HasParameters()) ? "1" : "0") << "\n";
1379 OS << " "<< i << " : Polygon3D with " << P->NbNodes() << " Nodes\n";
1380 OS << ((P->HasParameters()) ? "with" : "without") << " parameters\n";
1384 // write the deflection
1385 if (!Compact) OS << "Deflection : ";
1386 OS << P->Deflection() << "\n";
1389 if (!Compact) OS << "\nNodes :\n";
1391 Standard_Integer i1, nbNodes = P->NbNodes();
1392 const TColgp_Array1OfPnt& Nodes = P->Nodes();
1393 for (j = 1; j <= nbNodes; j++) {
1394 if (!Compact) OS << setw(10) << j << " : ";
1395 if (!Compact) OS << setw(17);
1396 OS << Nodes(j).X() << " ";
1397 if (!Compact) OS << setw(17);
1398 OS << Nodes(j).Y() << " ";
1399 if (!Compact) OS << setw(17);
1401 if (!Compact) OS << "\n";
1406 if (P->HasParameters()) {
1407 if (!Compact) OS << "\nParameters :\n";
1408 const TColStd_Array1OfReal& Param = P->Parameters();
1409 for ( i1 = 1; i1 <= nbNodes; i1++ ) {
1410 OS << Param(i1) << " ";
1417 //=======================================================================
1418 //function : DumpPolygon3D
1420 //=======================================================================
1422 void BRepTools_ShapeSet::DumpPolygon3D(Standard_OStream& OS)const
1424 WritePolygon3D(OS, Standard_False);
1428 //=======================================================================
1429 //function : ReadPolygon3D
1431 //=======================================================================
1433 void BRepTools_ShapeSet::ReadPolygon3D(Standard_IStream& IS)
1436 // Standard_Integer i, j, p, val, nbpol, nbnodes, hasparameters;
1437 Standard_Integer i, j, p, nbpol=0, nbnodes =0, hasparameters = Standard_False;
1438 Standard_Real d, x, y, z;
1441 if (strstr(buffer,"Polygon3D") == NULL) return;
1442 Handle(Poly_Polygon3D) P;
1445 Handle(Message_ProgressIndicator) progress = GetProgress();
1446 Message_ProgressSentry PS(progress, "3D Polygons", 0, nbpol, 1);
1447 for (i=1; i<=nbpol && PS.More(); i++, PS.Next()) {
1449 IS >> hasparameters;
1450 TColgp_Array1OfPnt Nodes(1, nbnodes);
1451 GeomTools::GetReal(IS, d);
1452 for (j = 1; j <= nbnodes; j++) {
1453 GeomTools::GetReal(IS, x);
1454 GeomTools::GetReal(IS, y);
1455 GeomTools::GetReal(IS, z);
1456 Nodes(j).SetCoord(x,y,z);
1458 if (hasparameters) {
1459 TColStd_Array1OfReal Param(1,nbnodes);
1460 for (p = 1; p <= nbnodes; p++) {
1461 GeomTools::GetReal(IS, Param(p));
1463 P = new Poly_Polygon3D(Nodes, Param);
1465 else P = new Poly_Polygon3D(Nodes);
1467 myPolygons3D.Add(P);
1473 //=======================================================================
1474 //function : WriteTriangulation
1476 //=======================================================================
1478 void BRepTools_ShapeSet::WriteTriangulation(Standard_OStream& OS,
1479 const Standard_Boolean Compact)const
1481 Standard_Integer i, j, nbNodes, nbtri = myTriangulations.Extent();
1482 Standard_Integer nbTriangles = 0, n1, n2, n3;
1484 Handle(Message_ProgressIndicator) progress = GetProgress();
1485 Message_ProgressSentry PS(progress, "Triangulations", 0, nbtri, 1);
1488 OS << "Triangulations " << nbtri << endl;
1491 OS <<"Dump of " << nbtri << " Triangulations\n";
1495 Handle(Poly_Triangulation) T;
1496 for (i = 1; i <= nbtri && PS.More(); i++, PS.Next()) {
1498 T = Handle(Poly_Triangulation)::DownCast(myTriangulations(i));
1500 OS << T->NbNodes() << " " << T->NbTriangles() << " ";
1501 OS << ((T->HasUVNodes()) ? "1" : "0") << " ";
1504 OS << " "<< i << " : Triangulation with " << T->NbNodes() << " Nodes and "
1505 << T->NbTriangles() <<" Triangles\n";
1506 OS << " "<<((T->HasUVNodes()) ? "with" : "without") << " UV nodes\n";
1510 // write the deflection
1512 if (!Compact) OS << " Deflection : ";
1513 OS <<T->Deflection() << "\n";
1515 // write the 3d nodes
1517 if (!Compact) OS << "\n3D Nodes :\n";
1519 nbNodes = T->NbNodes();
1520 const TColgp_Array1OfPnt& Nodes = T->Nodes();
1521 for (j = 1; j <= nbNodes; j++) {
1522 if (!Compact) OS << setw(10) << j << " : ";
1523 if (!Compact) OS << setw(17);
1524 OS << Nodes(j).X() << " ";
1525 if (!Compact) OS << setw(17);
1526 OS << Nodes(j).Y() << " ";
1527 if (!Compact) OS << setw(17);
1529 if (!Compact) OS << "\n";
1533 if (T->HasUVNodes()) {
1534 if (!Compact) OS << "\nUV Nodes :\n";
1535 const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes();
1536 for (j = 1; j <= nbNodes; j++) {
1537 if (!Compact) OS << setw(10) << j << " : ";
1538 if (!Compact) OS << setw(17);
1539 OS << UVNodes(j).X() << " ";
1540 if (!Compact) OS << setw(17);
1541 OS << UVNodes(j).Y();
1542 if (!Compact) OS << "\n";
1547 if (!Compact) OS << "\nTriangles :\n";
1548 nbTriangles = T->NbTriangles();
1549 const Poly_Array1OfTriangle& Triangles = T->Triangles();
1550 for (j = 1; j <= nbTriangles; j++) {
1551 if (!Compact) OS << setw(10) << j << " : ";
1552 Triangles(j).Get(n1, n2, n3);
1553 if (!Compact) OS << setw(10);
1555 if (!Compact) OS << setw(10);
1557 if (!Compact) OS << setw(10);
1559 if (!Compact) OS << "\n";
1566 //=======================================================================
1567 //function : DumpTriangulation
1569 //=======================================================================
1571 void BRepTools_ShapeSet::DumpTriangulation(Standard_OStream& OS)const
1573 WriteTriangulation(OS, Standard_False);
1577 //=======================================================================
1578 //function : ReadTriangulation
1580 //=======================================================================
1582 void BRepTools_ShapeSet::ReadTriangulation(Standard_IStream& IS)
1585 // Standard_Integer i, j, val, nbtri;
1586 Standard_Integer i, j, nbtri =0;
1587 Standard_Real d, x, y, z;
1588 Standard_Integer nbNodes =0, nbTriangles=0;
1589 Standard_Boolean hasUV= Standard_False;
1591 Handle(Poly_Triangulation) T;
1594 if (strstr(buffer,"Triangulations") == NULL) return;
1598 Handle(Message_ProgressIndicator) progress = GetProgress();
1599 Message_ProgressSentry PS(progress, "Triangulations", 0, nbtri, 1);
1600 for (i=1; i<=nbtri && PS.More();i++, PS.Next()) {
1602 IS >> nbNodes >> nbTriangles >> hasUV;
1603 GeomTools::GetReal(IS, d);
1605 TColgp_Array1OfPnt Nodes(1, nbNodes);
1606 TColgp_Array1OfPnt2d UVNodes(1, nbNodes);
1608 for (j = 1; j <= nbNodes; j++) {
1609 GeomTools::GetReal(IS, x);
1610 GeomTools::GetReal(IS, y);
1611 GeomTools::GetReal(IS, z);
1612 Nodes(j).SetCoord(x,y,z);
1616 for (j = 1; j <= nbNodes; j++) {
1617 GeomTools::GetReal(IS, x);
1618 GeomTools::GetReal(IS, y);
1619 UVNodes(j).SetCoord(x,y);
1623 // read the triangles
1624 Standard_Integer n1,n2,n3;
1625 Poly_Array1OfTriangle Triangles(1, nbTriangles);
1626 for (j = 1; j <= nbTriangles; j++) {
1627 IS >> n1 >> n2 >> n3;
1628 Triangles(j).Set(n1,n2,n3);
1631 if (hasUV) T = new Poly_Triangulation(Nodes,UVNodes,Triangles);
1632 else T = new Poly_Triangulation(Nodes,Triangles);
1636 myTriangulations.Add(T);