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>
26 #include <TColStd_HArray1OfInteger.hxx>
27 #include <BRep_TFace.hxx>
28 #include <BRep_TEdge.hxx>
29 #include <BRep_TVertex.hxx>
30 #include <BRep_Tool.hxx>
31 #include <BRep_CurveRepresentation.hxx>
32 #include <Poly_Polygon3D.hxx>
33 #include <BRep_Polygon3D.hxx>
34 #include <BRep_PolygonOnSurface.hxx>
35 #include <BRep_PolygonOnClosedSurface.hxx>
36 #include <BRep_PolygonOnTriangulation.hxx>
37 #include <BRep_PolygonOnClosedTriangulation.hxx>
38 #include <BRep_CurveOnSurface.hxx>
39 #include <BRep_CurveOnClosedSurface.hxx>
40 #include <BRep_ListOfCurveRepresentation.hxx>
41 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
42 #include <BRep_PointOnCurve.hxx>
43 #include <BRep_PointOnCurveOnSurface.hxx>
44 #include <BRep_PointOnSurface.hxx>
45 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
47 #include <TopoDS_Vertex.hxx>
49 #include <TColgp_HArray1OfPnt.hxx>
50 #include <TColgp_HArray1OfPnt2d.hxx>
51 #include <TColStd_HArray1OfReal.hxx>
52 #include <Poly_Triangulation.hxx>
53 #include <Poly_PolygonOnTriangulation.hxx>
55 #include <Message_ProgressIndicator.hxx>
56 #include <Message_ProgressSentry.hxx>
59 #define strcasecmp(p,q) strcmp(p,q)
61 #define strcasecmp strcmp
66 // Modified: 02 Nov 2000: BUC60769. JMB, PTV. In order to be able to read BRep
67 // files that came from a platform different from where CasCade
68 // is run, we need the following modifications.
70 // On NT platforms (in BRepTools_ShapeSet):
72 // In Visual C++ 5 (or higher) the fstream::tellg method is not
73 // conform to Standard C++ because it modifies the file pointer
74 // position and returns a wrong position. After that the next
75 // readings are shifted and the reading process stop with errors.
77 // Workaround is following: Now we don`t use tellg for get position in stream.
78 // Now able to read file (when reading TopAbs_FACE) without tellg.
79 // We simple check the next string if there are value that equal 2
80 // (It means a parametr for triangulation).
83 //=======================================================================
84 //function : BRepTools_ShapeSet
86 //=======================================================================
88 BRepTools_ShapeSet::BRepTools_ShapeSet(const Standard_Boolean isWithTriangles)
89 :myWithTriangles(isWithTriangles)
93 //=======================================================================
94 //function : BRepTools_ShapeSet
96 //=======================================================================
98 BRepTools_ShapeSet::BRepTools_ShapeSet (const BRep_Builder& B,
99 const Standard_Boolean isWithTriangles) :
100 myBuilder(B), myWithTriangles(isWithTriangles)
105 //=======================================================================
108 //=======================================================================
110 void BRepTools_ShapeSet::Clear()
115 myPolygons3D.Clear();
116 myPolygons2D.Clear();
118 myTriangulations.Clear();
119 TopTools_ShapeSet::Clear();
123 //=======================================================================
124 //function : AddGeometry
126 //=======================================================================
128 void BRepTools_ShapeSet::AddGeometry(const TopoDS_Shape& S)
132 if (S.ShapeType() == TopAbs_VERTEX) {
134 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
135 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
137 while (itrp.More()) {
138 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
140 if (PR->IsPointOnCurve()) {
141 myCurves.Add(PR->Curve());
144 else if (PR->IsPointOnCurveOnSurface()) {
145 myCurves2d.Add(PR->PCurve());
146 mySurfaces.Add(PR->Surface());
149 else if (PR->IsPointOnSurface()) {
150 mySurfaces.Add(PR->Surface());
153 ChangeLocations().Add(PR->Location());
158 else if (S.ShapeType() == TopAbs_EDGE) {
160 // Add the curve geometry
161 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
162 BRep_ListIteratorOfListOfCurveRepresentation itrc(TE->Curves());
164 while (itrc.More()) {
165 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
166 if (CR->IsCurve3D()) {
167 if (!CR->Curve3D().IsNull()) {
168 myCurves.Add(CR->Curve3D());
169 ChangeLocations().Add(CR->Location());
172 else if (CR->IsCurveOnSurface()) {
173 mySurfaces.Add(CR->Surface());
174 myCurves2d.Add(CR->PCurve());
175 ChangeLocations().Add(CR->Location());
176 if (CR->IsCurveOnClosedSurface())
177 myCurves2d.Add(CR->PCurve2());
179 else if (CR->IsRegularity()) {
180 mySurfaces.Add(CR->Surface());
181 ChangeLocations().Add(CR->Location());
182 mySurfaces.Add(CR->Surface2());
183 ChangeLocations().Add(CR->Location2());
185 else if (myWithTriangles) { // for XML Persistence
186 if (CR->IsPolygon3D()) {
187 if (!CR->Polygon3D().IsNull()) {
188 myPolygons3D.Add(CR->Polygon3D());
189 ChangeLocations().Add(CR->Location());
192 else if (CR->IsPolygonOnTriangulation()) {
193 myTriangulations.Add(CR->Triangulation());
194 myNodes.Add(CR->PolygonOnTriangulation());
195 ChangeLocations().Add(CR->Location());
196 if (CR->IsPolygonOnClosedTriangulation())
197 myNodes.Add(CR->PolygonOnTriangulation2());
199 else if (CR->IsPolygonOnSurface()) {
200 mySurfaces.Add(CR->Surface());
201 myPolygons2D.Add(CR->Polygon());
202 ChangeLocations().Add(CR->Location());
203 if (CR->IsPolygonOnClosedSurface())
204 myPolygons2D.Add(CR->Polygon2());
211 else if (S.ShapeType() == TopAbs_FACE) {
213 // Add the surface geometry
214 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
215 if (!TF->Surface().IsNull()) mySurfaces.Add(TF->Surface());
217 if (myWithTriangles) { // for XML Persistence
218 Handle(Poly_Triangulation) Tr = TF->Triangulation();
219 if (!Tr.IsNull()) myTriangulations.Add(Tr);
222 ChangeLocations().Add(TF->Location());
227 //=======================================================================
228 //function : DumpGeometry
230 //=======================================================================
232 void BRepTools_ShapeSet::DumpGeometry(Standard_OStream& OS)const
237 DumpPolygonOnTriangulation(OS);
239 DumpTriangulation(OS);
243 //=======================================================================
244 //function : WriteGeometry
246 //=======================================================================
248 void BRepTools_ShapeSet::WriteGeometry(Standard_OStream& OS)
251 myCurves2d.SetProgress(GetProgress());
252 myCurves.SetProgress(GetProgress());
253 mySurfaces.SetProgress(GetProgress());
255 if ( !GetProgress().IsNull()) {
256 if(GetProgress()->UserBreak() ) return;
257 GetProgress()->NewScope ( 15, "2D Curves" );
259 myCurves2d.Write(OS);
261 if ( !GetProgress().IsNull()) {
262 if( GetProgress()->UserBreak() ) return;
263 GetProgress()->EndScope();
264 GetProgress()->Show();
266 GetProgress()->NewScope ( 15, "3D Curves" );
270 if ( !GetProgress().IsNull()) {
271 if( GetProgress()->UserBreak() ) return;
272 GetProgress()->EndScope();
273 GetProgress()->Show();
275 GetProgress()->NewScope ( 10, "3D Polygons" );
278 if ( !GetProgress().IsNull()) {
279 if( GetProgress()->UserBreak() ) return;
280 GetProgress()->EndScope();
281 GetProgress()->Show();
283 GetProgress()->NewScope ( 10, "Polygons On Triangulation" );
285 WritePolygonOnTriangulation(OS);
286 if ( !GetProgress().IsNull()) {
287 if( GetProgress()->UserBreak() ) return;
288 GetProgress()->EndScope();
289 GetProgress()->Show();
291 GetProgress()->NewScope ( 10, "Surfaces" );
293 mySurfaces.Write(OS);
294 if ( !GetProgress().IsNull()) {
295 if( GetProgress()->UserBreak() ) return;
296 GetProgress()->EndScope();
297 GetProgress()->Show();
299 GetProgress()->NewScope ( 15, "Triangulations" );
301 WriteTriangulation(OS);
302 if ( !GetProgress().IsNull()) {
303 if( GetProgress()->UserBreak() ) return;
304 GetProgress()->EndScope();
305 GetProgress()->Show();
310 //=======================================================================
311 //function : ReadGeometry
313 //=======================================================================
315 void BRepTools_ShapeSet::ReadGeometry(Standard_IStream& IS)
318 myCurves2d.SetProgress(GetProgress());
319 myCurves.SetProgress(GetProgress());
320 mySurfaces.SetProgress(GetProgress());
322 if ( !GetProgress().IsNull()) {
323 if( GetProgress()->UserBreak() ) return;
324 GetProgress()->NewScope ( 15, "2D Curves" );
328 if ( !GetProgress().IsNull()) {
329 if( GetProgress()->UserBreak() ) return;
330 GetProgress()->EndScope();
331 GetProgress()->Show();
333 GetProgress()->NewScope ( 15, "3D Curves" );
337 if ( !GetProgress().IsNull()) {
338 if( GetProgress()->UserBreak() ) return;
339 GetProgress()->EndScope();
340 GetProgress()->Show();
342 GetProgress()->NewScope ( 10, "3D Polygons" );
345 if ( !GetProgress().IsNull() ) {
346 if( GetProgress()->UserBreak() ) return;
347 GetProgress()->EndScope();
348 GetProgress()->Show();
350 GetProgress()->NewScope ( 10, "Polygons On Triangulation" );
352 ReadPolygonOnTriangulation(IS);
353 if ( !GetProgress().IsNull()) {
354 if( GetProgress()->UserBreak() ) return;
355 GetProgress()->EndScope();
356 GetProgress()->Show();
358 GetProgress()->NewScope ( 10, "Surfaces" );
361 if ( !GetProgress().IsNull() ) {
362 if( GetProgress()->UserBreak() ) return;
363 GetProgress()->EndScope();
364 GetProgress()->Show();
366 GetProgress()->NewScope ( 15, "Triangulations" );
368 ReadTriangulation(IS);
369 if ( !GetProgress().IsNull()) {
370 if( GetProgress()->UserBreak() ) return;
371 GetProgress()->EndScope();
372 GetProgress()->Show();
376 //=======================================================================
377 //function : PrintRegularity
379 //=======================================================================
381 static void PrintRegularity(const GeomAbs_Shape C,
382 Standard_OStream& OS)
417 //=======================================================================
418 //function : DumpGeometry
420 //=======================================================================
422 void BRepTools_ShapeSet::DumpGeometry(const TopoDS_Shape& S,
423 Standard_OStream& OS)const
427 if (S.ShapeType() == TopAbs_VERTEX) {
429 // Dump the point geometry
430 TopoDS_Vertex V = TopoDS::Vertex(S);
431 OS << " Tolerance : " << BRep_Tool::Tolerance(V) << "\n";
432 gp_Pnt p = BRep_Tool::Pnt(V);
433 OS << " - Point 3D : "<<p.X()<<", "<<p.Y()<<", "<<p.Z()<<"\n";
435 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
436 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
438 while (itrp.More()) {
439 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
441 OS << " - Parameter : "<< PR->Parameter();
442 if (PR->IsPointOnCurve()) {
443 OS << " on curve " << myCurves.Index(PR->Curve());
446 else if (PR->IsPointOnCurveOnSurface()) {
447 OS << " on pcurve " << myCurves2d.Index(PR->PCurve());
448 OS << " on surface " << mySurfaces.Index(PR->Surface());
451 else if (PR->IsPointOnSurface()) {
452 OS << ", " << PR->Parameter2() << " on surface ";
453 OS << mySurfaces.Index(PR->Surface());
456 if (!PR->Location().IsIdentity())
457 OS << " location " << Locations().Index(PR->Location());
465 else if (S.ShapeType() == TopAbs_EDGE) {
467 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
470 // Dump the curve geometry
471 OS << " Tolerance : " << TE->Tolerance() << "\n";
472 if (TE->SameParameter()) OS << " same parametrisation of curves\n";
473 if (TE->SameRange()) OS << " same range on curves\n";
474 if (TE->Degenerated()) OS << " degenerated\n";
476 Standard_Real first, last;
477 BRep_ListIteratorOfListOfCurveRepresentation itrc = TE->Curves();
478 while (itrc.More()) {
479 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
480 if (CR->IsCurve3D()) {
481 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
482 GC->Range(first, last);
483 if (!CR->Curve3D().IsNull()) {
484 OS << " - Curve 3D : "<<myCurves.Index(CR->Curve3D());
485 if (!CR->Location().IsIdentity())
486 OS << " location "<<Locations().Index(CR->Location());
487 OS <<", range : " << first << " " << last <<"\n";
490 else if (CR->IsCurveOnSurface()) {
491 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
492 GC->Range(first, last);
493 OS <<" - PCurve : "<<myCurves2d.Index(CR->PCurve());
494 if (CR->IsCurveOnClosedSurface()) {
495 OS <<", " << myCurves2d.Index(CR->PCurve2());
497 PrintRegularity(CR->Continuity(),OS);
500 OS << " on surface "<<mySurfaces.Index(CR->Surface());
501 if (!CR->Location().IsIdentity())
502 OS << " location "<<Locations().Index(CR->Location());
503 OS <<", range : " << first << " " << last <<"\n";
505 Handle(BRep_CurveOnSurface) COS =
506 Handle(BRep_CurveOnSurface)::DownCast(CR);
507 COS->UVPoints(Pf,Pl);
508 OS << " UV Points : " <<Pf.X()<<", "<<Pf.Y()<<" ";
509 OS << Pl.X()<<", "<<Pl.Y()<<"\n";
510 if (CR->IsCurveOnClosedSurface()) {
511 Handle(BRep_CurveOnClosedSurface) COCS =
512 Handle(BRep_CurveOnClosedSurface)::DownCast(CR);
513 COCS->UVPoints2(Pf,Pl);
514 OS << " UV Points : " <<Pf.X()<<", "<<Pf.Y()<<" ";
515 OS << Pl.X()<<", "<<Pl.Y()<<"\n";
518 else if (CR->IsRegularity()) {
519 OS << " - Regularity ";
520 PrintRegularity(CR->Continuity(),OS);
521 OS << " on surfaces : "<<mySurfaces.Index(CR->Surface());
522 if (!CR->Location().IsIdentity())
523 OS << " location "<<Locations().Index(CR->Location());
524 OS << ", "<<mySurfaces.Index(CR->Surface2());
525 if (!CR->Location2().IsIdentity())
526 OS << " location "<<Locations().Index(CR->Location2());
529 else if (CR->IsPolygon3D()) {
530 Handle(BRep_Polygon3D) GC = Handle(BRep_Polygon3D)::DownCast(itrc.Value());
531 if (!GC->Polygon3D().IsNull()) {
532 OS << " - Polygon 3D : "<<myPolygons3D.FindIndex(CR->Polygon3D());
533 if (!CR->Location().IsIdentity())
534 OS << " location "<<Locations().Index(CR->Location());
537 else if (CR->IsPolygonOnTriangulation()) {
538 OS << " - PolygonOnTriangulation " << myNodes.FindIndex(CR->PolygonOnTriangulation());
539 if (CR->IsPolygonOnClosedTriangulation()) {
540 OS << " " << myNodes.FindIndex(CR->PolygonOnTriangulation2());
542 OS << " on triangulation " << myTriangulations.FindIndex(CR->Triangulation());
543 if (!CR->Location().IsIdentity())
544 OS << " location "<<Locations().Index(CR->Location());
551 else if (S.ShapeType() == TopAbs_FACE) {
553 const TopoDS_Face& F = TopoDS::Face(S);
554 if (BRep_Tool::NaturalRestriction(F))
555 OS << "NaturalRestriction\n";
557 // Dump the surface geometry
558 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
559 if (!TF->Surface().IsNull()) {
560 OS << " Tolerance : " <<TF->Tolerance() << "\n";
561 OS << " - Surface : "<<mySurfaces.Index(TF->Surface());
562 if (!S.Location().IsIdentity())
563 OS << " location "<<Locations().Index(S.Location());
566 if (!(TF->Triangulation()).IsNull()) {
567 // Dump the triangulation
568 OS << " - Triangulation : " <<myTriangulations.FindIndex(TF->Triangulation());
569 if (!S.Location().IsIdentity())
570 OS << " location " <<Locations().Index(TF->Location());
579 //=======================================================================
580 //function : WriteGeometry
582 //=======================================================================
584 void BRepTools_ShapeSet::WriteGeometry(const TopoDS_Shape& S,
585 Standard_OStream& OS)const
587 // Write the geometry
589 if (S.ShapeType() == TopAbs_VERTEX) {
591 // Write the point geometry
592 TopoDS_Vertex V = TopoDS::Vertex(S);
593 OS << BRep_Tool::Tolerance(V) << "\n";
594 gp_Pnt p = BRep_Tool::Pnt(V);
595 OS<<p.X()<<" "<<p.Y()<<" "<<p.Z()<<"\n";
597 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
598 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
600 while (itrp.More()) {
601 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
603 OS << PR->Parameter();
604 if (PR->IsPointOnCurve()) {
605 OS << " 1 " << myCurves.Index(PR->Curve());
608 else if (PR->IsPointOnCurveOnSurface()) {
609 OS << " 2 " << myCurves2d.Index(PR->PCurve());
610 OS << " " << mySurfaces.Index(PR->Surface());
613 else if (PR->IsPointOnSurface()) {
614 OS << " 3 " << PR->Parameter2() << " ";
615 OS << mySurfaces.Index(PR->Surface());
618 OS << " " << Locations().Index(PR->Location());
624 OS << "0 0\n"; // end representations
628 else if (S.ShapeType() == TopAbs_EDGE) {
630 // Write the curve geometry
632 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
634 OS << " " << TE->Tolerance() << " ";
635 OS << ((TE->SameParameter()) ? 1 : 0) << " ";
636 OS << ((TE->SameRange()) ? 1 : 0) << " ";
637 OS << ((TE->Degenerated()) ? 1 : 0) << "\n";
639 Standard_Real first, last;
640 BRep_ListIteratorOfListOfCurveRepresentation itrc = TE->Curves();
641 while (itrc.More()) {
642 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
643 if (CR->IsCurve3D()) {
644 if (!CR->Curve3D().IsNull()) {
645 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
646 GC->Range(first, last);
647 OS << "1 "; // -1- Curve 3D
648 OS << " "<<myCurves.Index(CR->Curve3D());
649 OS << " "<<Locations().Index(CR->Location());
650 OS << " "<<first<<" "<<last;
654 else if (CR->IsCurveOnSurface()) {
655 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
656 GC->Range(first, last);
657 if (!CR->IsCurveOnClosedSurface())
658 OS << "2 "; // -2- Curve on surf
660 OS << "3 "; // -3- Curve on closed surf
661 OS <<" "<<myCurves2d.Index(CR->PCurve());
662 if (CR->IsCurveOnClosedSurface()) {
663 OS <<" " << myCurves2d.Index(CR->PCurve2());
664 PrintRegularity(CR->Continuity(),OS);
666 OS << " " << mySurfaces.Index(CR->Surface());
667 OS << " " << Locations().Index(CR->Location());
668 OS << " "<<first<<" "<<last;
671 // Write UV Points // for XML Persistence higher performance
675 if (CR->IsCurveOnClosedSurface()) {
676 Handle(BRep_CurveOnClosedSurface) COCS =
677 Handle(BRep_CurveOnClosedSurface)::DownCast(CR);
678 COCS->UVPoints2(Pf,Pl);
681 Handle(BRep_CurveOnSurface) COS =
682 Handle(BRep_CurveOnSurface)::DownCast(CR);
683 COS->UVPoints(Pf,Pl);
685 OS << Pf.X() << " " << Pf.Y() << " " << Pl.X() << " " << Pl.Y() << "\n";
688 else if (CR->IsRegularity()) {
689 OS << "4 "; // -4- Regularity
690 PrintRegularity(CR->Continuity(),OS);
691 OS << " "<<mySurfaces.Index(CR->Surface());
692 OS << " "<<Locations().Index(CR->Location());
693 OS << " "<<mySurfaces.Index(CR->Surface2());
694 OS << " "<<Locations().Index(CR->Location2());
698 else if (myWithTriangles) { // for XML Persistence
699 if (CR->IsPolygon3D()) {
700 Handle(BRep_Polygon3D) GC = Handle(BRep_Polygon3D)::DownCast(itrc.Value());
701 if (!GC->Polygon3D().IsNull()) {
702 OS << "5 "; // -5- Polygon3D
703 OS << " "<<myPolygons3D.FindIndex(CR->Polygon3D());
704 OS << " "<<Locations().Index(CR->Location());
708 else if (CR->IsPolygonOnTriangulation()) {
709 Handle(BRep_PolygonOnTriangulation) PT =
710 Handle(BRep_PolygonOnTriangulation)::DownCast(itrc.Value());
711 if (!CR->IsPolygonOnClosedTriangulation())
712 OS << "6 "; // -6- Polygon on triangulation
714 OS << "7 "; // -7- Polygon on closed triangulation
715 OS << " " << myNodes.FindIndex(PT->PolygonOnTriangulation());
716 if (CR->IsPolygonOnClosedTriangulation()) {
717 OS << " " << myNodes.FindIndex(PT->PolygonOnTriangulation2());
719 OS << " " << myTriangulations.FindIndex(PT->Triangulation());
720 OS << " "<<Locations().Index(CR->Location());
727 OS << "0\n"; // end of the list of representations
730 else if (S.ShapeType() == TopAbs_FACE) {
732 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
733 const TopoDS_Face& F = TopoDS::Face(S);
735 if (!(TF->Surface()).IsNull()) {
736 OS << ((BRep_Tool::NaturalRestriction(F)) ? 1 : 0);
738 // Write the surface geometry
739 OS << " " <<TF->Tolerance();
740 OS << " " <<mySurfaces.Index(TF->Surface());
741 OS << " " <<Locations().Index(TF->Location());
744 else //For correct reading of null face
748 OS << " " <<TF->Tolerance();
753 if (myWithTriangles) { // for XML Persistence
754 if (!(TF->Triangulation()).IsNull()) {
757 // Write the triangulation
758 OS << " " <<myTriangulations.FindIndex(TF->Triangulation());
765 //=======================================================================
766 //function : ReadRegularity
768 //=======================================================================
770 static GeomAbs_Shape ReadRegularity(Standard_IStream& IS)
811 //=======================================================================
812 //function : ReadGeometry
814 //=======================================================================
816 void BRepTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T,
817 Standard_IStream& IS,
822 Standard_Integer val,c,pc,pc2 = 0,s,s2,l,l2,t, pt, pt2 = 0;
823 Standard_Real tol,X,Y,Z,first,last,p1,p2;
824 Standard_Real PfX,PfY,PlX,PlY;
826 Standard_Boolean closed;
827 GeomAbs_Shape reg = GeomAbs_C0;
837 TopoDS_Vertex& V = TopoDS::Vertex(S);
839 // Read the point geometry
842 myBuilder.MakeVertex(V,gp_Pnt(X,Y,Z),tol);
843 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(V.TShape());
845 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
851 Handle(BRep_PointRepresentation) PR;
858 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
859 if (myCurves.Curve(c).IsNull())
861 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
863 Handle(BRep_PointOnCurve) POC =
864 new BRep_PointOnCurve(p1,
875 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
876 if (myCurves2d.Curve2d(pc).IsNull() ||
877 mySurfaces.Surface(s).IsNull())
879 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
881 Handle(BRep_PointOnCurveOnSurface) POC =
882 new BRep_PointOnCurveOnSurface(p1,
883 myCurves2d.Curve2d(pc),
884 mySurfaces.Surface(s),
894 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
895 if (mySurfaces.Surface(s).IsNull())
897 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
899 Handle(BRep_PointOnSurface) POC =
900 new BRep_PointOnSurface(p1,p2,
901 mySurfaces.Surface(s),
911 PR->Location(Locations().Location(l));
929 TopoDS_Edge& E = TopoDS::Edge(S);
931 myBuilder.MakeEdge(E);
933 // Read the curve geometry
936 myBuilder.SameParameter(E,(val == 1));
938 myBuilder.SameRange(E,(val == 1));
940 myBuilder.Degenerated(E,(val == 1));
946 case 1 : // -1- Curve 3D
948 if (!myCurves.Curve(c).IsNull()) {
949 myBuilder.UpdateEdge(E,myCurves.Curve(c),
950 Locations().Location(l),tol);
953 if (!myCurves.Curve(c).IsNull()) {
954 Standard_Boolean Only3d = Standard_True;
955 myBuilder.Range(E,first,last,Only3d);
960 case 2 : // -2- Curve on surf
961 case 3 : // -3- Curve on closed surf
966 reg = ReadRegularity(IS);
975 // read UV Points // for XML Persistence higher performance
978 IS >> PfX >> PfY >> PlX >> PlY;
979 aPf = gp_Pnt2d(PfX,PfY);
980 aPl = gp_Pnt2d(PlX,PlY);
983 // Modified by Sergey KHROMOV - Wed Apr 24 12:11:16 2002 Begin
984 if (myCurves2d.Curve2d(pc).IsNull() ||
985 (closed && myCurves2d.Curve2d(pc2).IsNull()) ||
986 mySurfaces.Surface(s).IsNull())
988 // Modified by Sergey KHROMOV - Wed Apr 24 12:11:17 2002 End
992 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
993 myCurves2d.Curve2d(pc2),
994 mySurfaces.Surface(s),
995 Locations().Location(l),tol,
998 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
999 myCurves2d.Curve2d(pc2),
1000 mySurfaces.Surface(s),
1001 Locations().Location(l),tol);
1003 myBuilder.Continuity(E,
1004 mySurfaces.Surface(s),
1005 mySurfaces.Surface(s),
1006 Locations().Location(l),
1007 Locations().Location(l),
1012 if (FormatNb() == 2)
1013 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1014 mySurfaces.Surface(s),
1015 Locations().Location(l),tol,
1018 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1019 mySurfaces.Surface(s),
1020 Locations().Location(l),tol);
1023 mySurfaces.Surface(s),
1024 Locations().Location(l),
1028 case 4 : // -4- Regularity
1029 reg = ReadRegularity(IS);
1030 IS >> s >> l >> s2 >> l2;
1031 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:13 2002 Begin
1032 if (mySurfaces.Surface(s).IsNull() ||
1033 mySurfaces.Surface(s2).IsNull())
1035 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:14 2002 End
1036 myBuilder.Continuity(E,
1037 mySurfaces.Surface(s),
1038 mySurfaces.Surface(s2),
1039 Locations().Location(l),
1040 Locations().Location(l2),
1044 case 5 : // -5- Polygon3D
1046 //szy-02.05.2004 myBuilder.UpdateEdge(E,Handle(Poly_Polygon3D)::DownCast(myPolygons3D(c)));
1047 if (c > 0 && c <= myPolygons3D.Extent())
1048 myBuilder.UpdateEdge(E,Handle(Poly_Polygon3D)::DownCast(myPolygons3D(c)), Locations().Location(l));
1053 closed = (val == 7);
1060 if (t > 0 && t <= myTriangulations.Extent() &&
1061 pt > 0 && pt <= myNodes.Extent() &&
1062 pt2 > 0 && pt2 <= myNodes.Extent())
1063 myBuilder.UpdateEdge
1064 (E, Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
1065 Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt2)),
1066 Handle(Poly_Triangulation)::DownCast(myTriangulations(t)),
1067 Locations().Location(l));
1070 if (t > 0 && t <= myTriangulations.Extent() &&
1071 pt > 0 && pt <= myNodes.Extent())
1072 myBuilder.UpdateEdge
1073 (E,Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
1074 Handle(Poly_Triangulation)::DownCast(myTriangulations(t)),
1075 Locations().Location(l));
1092 myBuilder.MakeWire(TopoDS::Wire(S));
1103 TopoDS_Face& F = TopoDS::Face(S);
1105 myBuilder.MakeFace(F);
1107 IS >> val; // natural restriction
1108 if (val == 0 || val == 1) {
1109 IS >> tol >> s >> l;
1110 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:13 2002 Begin
1111 if (!mySurfaces.Surface(s).IsNull()) {
1112 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:14 2002 End
1113 myBuilder.UpdateFace(TopoDS::Face(S),
1114 mySurfaces.Surface(s),
1115 Locations().Location(l),tol);
1116 myBuilder.NaturalRestriction(TopoDS::Face(S),(val == 1));
1118 // pos = IS.tellg();
1122 //only triangulation
1124 myBuilder.UpdateFace(TopoDS::Face(S),
1125 Handle(Poly_Triangulation)::DownCast(myTriangulations(s)));
1127 // else pos = IS.tellg();
1134 IS.getline ( string, 256, '\n' );
1135 IS.getline ( string, 256, '\n' );
1137 if (string[0] == '2') {
1138 // cas triangulation
1139 s = atoi ( &string[2] );
1140 if (s > 0 && s <= myTriangulations.Extent())
1141 myBuilder.UpdateFace(TopoDS::Face(S),
1142 Handle(Poly_Triangulation)::DownCast(myTriangulations(s)));
1144 // else IS.seekg(pos);
1154 myBuilder.MakeShell(TopoDS::Shell(S));
1163 myBuilder.MakeSolid(TopoDS::Solid(S));
1171 case TopAbs_COMPSOLID :
1172 myBuilder.MakeCompSolid(TopoDS::CompSolid(S));
1180 case TopAbs_COMPOUND :
1181 myBuilder.MakeCompound(TopoDS::Compound(S));
1192 //=======================================================================
1193 //function : AddShapes
1195 //=======================================================================
1197 void BRepTools_ShapeSet::AddShapes(TopoDS_Shape& S1,
1198 const TopoDS_Shape& S2)
1200 myBuilder.Add(S1,S2);
1203 //=======================================================================
1206 //=======================================================================
1208 void BRepTools_ShapeSet::Check(const TopAbs_ShapeEnum T,
1211 if (T == TopAbs_FACE) {
1212 const TopoDS_Face& F = TopoDS::Face(S);
1213 BRepTools::Update(F);
1219 //=======================================================================
1220 //function : WritePolygonOnTriangulation
1222 //=======================================================================
1224 void BRepTools_ShapeSet::WritePolygonOnTriangulation(Standard_OStream& OS,
1225 const Standard_Boolean Compact)const
1227 Standard_Integer i, j, nbpOntri = myNodes.Extent();
1229 Handle(Message_ProgressIndicator) progress = GetProgress();
1230 Message_ProgressSentry PS(progress, "Polygons On Triangulation", 0, nbpOntri, 1);
1232 OS << "PolygonOnTriangulations " << nbpOntri << endl;
1235 OS <<"Dump of " << nbpOntri << " PolygonOnTriangulations\n";
1239 Handle(Poly_PolygonOnTriangulation) Poly;
1240 Handle(TColStd_HArray1OfReal) Param;
1241 for (i=1; i<=nbpOntri && PS.More(); i++, PS.Next()) {
1242 Poly = Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(i));
1243 const TColStd_Array1OfInteger& Nodes = Poly->Nodes();
1245 OS << " "<< i << " : PolygonOnTriangulation with " << Nodes.Length() << " Nodes\n";
1247 else OS << Nodes.Length()<<" ";
1248 if (!Compact) OS <<" ";
1249 for (j=1; j <= Nodes.Length(); j++) OS << Nodes.Value(j) << " ";
1252 // writing parameters:
1253 Param = Poly->Parameters();
1254 if (Compact) OS <<"p ";
1256 // write the deflection
1257 if (!Compact) OS << " Deflection : ";
1258 OS <<Poly->Deflection() << " ";
1259 if (!Compact) OS << "\n";
1261 if (!Param.IsNull()) {
1263 OS << " "<< "Parameters :";
1266 if (!Compact) OS <<" ";
1267 for (j=1; j <= Param->Length(); j++) OS << Param->Value(j) << " ";
1274 //=======================================================================
1275 //function : DumpPolygonOnTriangulation
1277 //=======================================================================
1279 void BRepTools_ShapeSet::DumpPolygonOnTriangulation(Standard_OStream& OS)const
1281 WritePolygonOnTriangulation(OS, Standard_False);
1284 //=======================================================================
1285 //function : ReadPolygonOnTriangulation
1287 //=======================================================================
1289 void BRepTools_ShapeSet::ReadPolygonOnTriangulation(Standard_IStream& IS)
1293 if (strstr(buffer,"PolygonOnTriangulations") == NULL) return;
1294 Standard_Integer i, j, val, nbpol = 0, nbnodes =0;
1295 Standard_Integer hasparameters;
1297 Handle(TColStd_HArray1OfReal) Param;
1298 Handle(Poly_PolygonOnTriangulation) Poly;
1301 Handle(Message_ProgressIndicator) progress = GetProgress();
1302 Message_ProgressSentry PS(progress, "Polygons On Triangulation", 0, nbpol, 1);
1303 for (i=1; i<=nbpol&& PS.More(); i++, PS.Next()) {
1305 TColStd_Array1OfInteger Nodes(1, nbnodes);
1306 for (j = 1; j <= nbnodes; j++) {
1311 // if (!strcasecmp(buffer, "p")) {
1314 IS >> hasparameters;
1315 if (hasparameters) {
1316 TColStd_Array1OfReal Param1(1, nbnodes);
1317 for (j = 1; j <= nbnodes; j++) {
1321 Poly = new Poly_PolygonOnTriangulation(Nodes, Param1);
1323 else Poly = new Poly_PolygonOnTriangulation(Nodes);
1324 Poly->Deflection(def);
1328 // Poly = new Poly_PolygonOnTriangulation(Nodes);
1333 // else IS.seekg(pos);
1338 //=======================================================================
1339 //function : WritePolygon3D
1341 //=======================================================================
1343 void BRepTools_ShapeSet::WritePolygon3D(Standard_OStream& OS,
1344 const Standard_Boolean Compact)const
1346 Standard_Integer i, j, nbpol = myPolygons3D.Extent();
1348 Handle(Message_ProgressIndicator) progress = GetProgress();
1349 Message_ProgressSentry PS(progress, "3D Poligons", 0, nbpol, 1);
1352 OS << "Polygon3D " << nbpol << endl;
1355 OS <<"Dump of " << nbpol << " Polygon3Ds\n";
1359 Handle(Poly_Polygon3D) P;
1360 for (i = 1; i <= nbpol && PS.More(); i++, PS.Next()) {
1361 P = Handle(Poly_Polygon3D)::DownCast(myPolygons3D(i));
1363 OS << P->NbNodes() << " ";
1364 OS << ((P->HasParameters()) ? "1" : "0") << "\n";
1367 OS << " "<< i << " : Polygon3D with " << P->NbNodes() << " Nodes\n";
1368 OS << ((P->HasParameters()) ? "with" : "without") << " parameters\n";
1372 // write the deflection
1373 if (!Compact) OS << "Deflection : ";
1374 OS << P->Deflection() << "\n";
1377 if (!Compact) OS << "\nNodes :\n";
1379 Standard_Integer i1, nbNodes = P->NbNodes();
1380 const TColgp_Array1OfPnt& Nodes = P->Nodes();
1381 for (j = 1; j <= nbNodes; j++) {
1382 if (!Compact) OS << setw(10) << j << " : ";
1383 if (!Compact) OS << setw(17);
1384 OS << Nodes(j).X() << " ";
1385 if (!Compact) OS << setw(17);
1386 OS << Nodes(j).Y() << " ";
1387 if (!Compact) OS << setw(17);
1389 if (!Compact) OS << "\n";
1394 if (P->HasParameters()) {
1395 if (!Compact) OS << "\nParameters :\n";
1396 const TColStd_Array1OfReal& Param = P->Parameters();
1397 for ( i1 = 1; i1 <= nbNodes; i1++ ) {
1398 OS << Param(i1) << " ";
1405 //=======================================================================
1406 //function : DumpPolygon3D
1408 //=======================================================================
1410 void BRepTools_ShapeSet::DumpPolygon3D(Standard_OStream& OS)const
1412 WritePolygon3D(OS, Standard_False);
1416 //=======================================================================
1417 //function : ReadPolygon3D
1419 //=======================================================================
1421 void BRepTools_ShapeSet::ReadPolygon3D(Standard_IStream& IS)
1424 // Standard_Integer i, j, p, val, nbpol, nbnodes, hasparameters;
1425 Standard_Integer i, j, p, nbpol=0, nbnodes =0, hasparameters = Standard_False;
1426 Standard_Real d, x, y, z;
1429 if (strstr(buffer,"Polygon3D") == NULL) return;
1430 Handle(Poly_Polygon3D) P;
1433 Handle(Message_ProgressIndicator) progress = GetProgress();
1434 Message_ProgressSentry PS(progress, "3D Polygons", 0, nbpol, 1);
1435 for (i=1; i<=nbpol && PS.More(); i++, PS.Next()) {
1437 IS >> hasparameters;
1438 TColgp_Array1OfPnt Nodes(1, nbnodes);
1440 for (j = 1; j <= nbnodes; j++) {
1442 Nodes(j).SetCoord(x,y,z);
1444 if (hasparameters) {
1445 TColStd_Array1OfReal Param(1,nbnodes);
1446 for (p = 1; p <= nbnodes; p++) {
1449 P = new Poly_Polygon3D(Nodes, Param);
1451 else P = new Poly_Polygon3D(Nodes);
1453 myPolygons3D.Add(P);
1459 //=======================================================================
1460 //function : WriteTriangulation
1462 //=======================================================================
1464 void BRepTools_ShapeSet::WriteTriangulation(Standard_OStream& OS,
1465 const Standard_Boolean Compact)const
1467 Standard_Integer i, j, nbNodes, nbtri = myTriangulations.Extent();
1468 Standard_Integer nbTriangles = 0, n1, n2, n3;
1470 Handle(Message_ProgressIndicator) progress = GetProgress();
1471 Message_ProgressSentry PS(progress, "Triangulations", 0, nbtri, 1);
1474 OS << "Triangulations " << nbtri << endl;
1477 OS <<"Dump of " << nbtri << " Triangulations\n";
1481 Handle(Poly_Triangulation) T;
1482 for (i = 1; i <= nbtri && PS.More(); i++, PS.Next()) {
1484 T = Handle(Poly_Triangulation)::DownCast(myTriangulations(i));
1486 OS << T->NbNodes() << " " << T->NbTriangles() << " ";
1487 OS << ((T->HasUVNodes()) ? "1" : "0") << " ";
1490 OS << " "<< i << " : Triangulation with " << T->NbNodes() << " Nodes and "
1491 << T->NbTriangles() <<" Triangles\n";
1492 OS << " "<<((T->HasUVNodes()) ? "with" : "without") << " UV nodes\n";
1496 // write the deflection
1498 if (!Compact) OS << " Deflection : ";
1499 OS <<T->Deflection() << "\n";
1501 // write the 3d nodes
1503 if (!Compact) OS << "\n3D Nodes :\n";
1505 nbNodes = T->NbNodes();
1506 const TColgp_Array1OfPnt& Nodes = T->Nodes();
1507 for (j = 1; j <= nbNodes; j++) {
1508 if (!Compact) OS << setw(10) << j << " : ";
1509 if (!Compact) OS << setw(17);
1510 OS << Nodes(j).X() << " ";
1511 if (!Compact) OS << setw(17);
1512 OS << Nodes(j).Y() << " ";
1513 if (!Compact) OS << setw(17);
1515 if (!Compact) OS << "\n";
1519 if (T->HasUVNodes()) {
1520 if (!Compact) OS << "\nUV Nodes :\n";
1521 const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes();
1522 for (j = 1; j <= nbNodes; j++) {
1523 if (!Compact) OS << setw(10) << j << " : ";
1524 if (!Compact) OS << setw(17);
1525 OS << UVNodes(j).X() << " ";
1526 if (!Compact) OS << setw(17);
1527 OS << UVNodes(j).Y();
1528 if (!Compact) OS << "\n";
1533 if (!Compact) OS << "\nTriangles :\n";
1534 nbTriangles = T->NbTriangles();
1535 const Poly_Array1OfTriangle& Triangles = T->Triangles();
1536 for (j = 1; j <= nbTriangles; j++) {
1537 if (!Compact) OS << setw(10) << j << " : ";
1538 Triangles(j).Get(n1, n2, n3);
1539 if (!Compact) OS << setw(10);
1541 if (!Compact) OS << setw(10);
1543 if (!Compact) OS << setw(10);
1545 if (!Compact) OS << "\n";
1552 //=======================================================================
1553 //function : DumpTriangulation
1555 //=======================================================================
1557 void BRepTools_ShapeSet::DumpTriangulation(Standard_OStream& OS)const
1559 WriteTriangulation(OS, Standard_False);
1563 //=======================================================================
1564 //function : ReadTriangulation
1566 //=======================================================================
1568 void BRepTools_ShapeSet::ReadTriangulation(Standard_IStream& IS)
1571 // Standard_Integer i, j, val, nbtri;
1572 Standard_Integer i, j, nbtri =0;
1573 Standard_Real d, x, y, z;
1574 Standard_Integer nbNodes =0, nbTriangles=0;
1575 Standard_Boolean hasUV= Standard_False;
1577 Handle(Poly_Triangulation) T;
1580 if (strstr(buffer,"Triangulations") == NULL) return;
1584 Handle(Message_ProgressIndicator) progress = GetProgress();
1585 Message_ProgressSentry PS(progress, "Triangulations", 0, nbtri, 1);
1586 for (i=1; i<=nbtri && PS.More();i++, PS.Next()) {
1588 IS >> nbNodes >> nbTriangles >> hasUV;
1591 TColgp_Array1OfPnt Nodes(1, nbNodes);
1592 TColgp_Array1OfPnt2d UVNodes(1, nbNodes);
1594 for (j = 1; j <= nbNodes; j++) {
1596 Nodes(j).SetCoord(x,y,z);
1600 for (j = 1; j <= nbNodes; j++) {
1602 UVNodes(j).SetCoord(x,y);
1606 // read the triangles
1607 Standard_Integer n1,n2,n3;
1608 Poly_Array1OfTriangle Triangles(1, nbTriangles);
1609 for (j = 1; j <= nbTriangles; j++) {
1610 IS >> n1 >> n2 >> n3;
1611 Triangles(j).Set(n1,n2,n3);
1614 if (hasUV) T = new Poly_Triangulation(Nodes,UVNodes,Triangles);
1615 else T = new Poly_Triangulation(Nodes,Triangles);
1619 myTriangulations.Add(T);