1 // Created on: 1993-07-19
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
21 // Modifed: Portage NT 7-5-97 DPF (strcasecmp)
23 #include <Standard_Stream.hxx>
24 #include <Precision.hxx>
25 #include <BRepTools_ShapeSet.ixx>
27 #include <BRepTools.hxx>
30 #include <TColStd_HArray1OfInteger.hxx>
31 #include <BRep_TFace.hxx>
32 #include <BRep_TEdge.hxx>
33 #include <BRep_TVertex.hxx>
34 #include <BRep_Tool.hxx>
35 #include <BRep_CurveRepresentation.hxx>
36 #include <Poly_Polygon3D.hxx>
37 #include <BRep_Polygon3D.hxx>
38 #include <BRep_PolygonOnSurface.hxx>
39 #include <BRep_PolygonOnClosedSurface.hxx>
40 #include <BRep_PolygonOnTriangulation.hxx>
41 #include <BRep_PolygonOnClosedTriangulation.hxx>
42 #include <BRep_CurveOnSurface.hxx>
43 #include <BRep_CurveOnClosedSurface.hxx>
44 #include <BRep_ListOfCurveRepresentation.hxx>
45 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
46 #include <BRep_PointOnCurve.hxx>
47 #include <BRep_PointOnCurveOnSurface.hxx>
48 #include <BRep_PointOnSurface.hxx>
49 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
51 #include <TopoDS_Vertex.hxx>
53 #include <TColgp_HArray1OfPnt.hxx>
54 #include <TColgp_HArray1OfPnt2d.hxx>
55 #include <TColStd_HArray1OfReal.hxx>
56 #include <Poly_Triangulation.hxx>
57 #include <Poly_PolygonOnTriangulation.hxx>
59 #include <Message_ProgressIndicator.hxx>
60 #include <Message_ProgressSentry.hxx>
63 #define strcasecmp(p,q) strcmp(p,q)
65 #define strcasecmp strcmp
70 // Modified: 02 Nov 2000: BUC60769. JMB, PTV. In order to be able to read BRep
71 // files that came from a platform different from where CasCade
72 // is run, we need the following modifications.
74 // On NT platforms (in BRepTools_ShapeSet):
76 // In Visual C++ 5 (or higher) the fstream::tellg method is not
77 // conform to Standard C++ because it modifies the file pointer
78 // position and returns a wrong position. After that the next
79 // readings are shifted and the reading process stop with errors.
81 // Workaround is following: Now we don`t use tellg for get position in stream.
82 // Now able to read file (when reading TopAbs_FACE) without tellg.
83 // We simple check the next string if there are value that equal 2
84 // (It means a parametr for triangulation).
87 //=======================================================================
88 //function : BRepTools_ShapeSet
90 //=======================================================================
92 BRepTools_ShapeSet::BRepTools_ShapeSet(const Standard_Boolean isWithTriangles)
93 :myWithTriangles(isWithTriangles)
97 //=======================================================================
98 //function : BRepTools_ShapeSet
100 //=======================================================================
102 BRepTools_ShapeSet::BRepTools_ShapeSet (const BRep_Builder& B,
103 const Standard_Boolean isWithTriangles) :
104 myBuilder(B), myWithTriangles(isWithTriangles)
109 //=======================================================================
112 //=======================================================================
114 void BRepTools_ShapeSet::Clear()
119 myPolygons3D.Clear();
120 myPolygons2D.Clear();
122 myTriangulations.Clear();
123 TopTools_ShapeSet::Clear();
127 //=======================================================================
128 //function : AddGeometry
130 //=======================================================================
132 void BRepTools_ShapeSet::AddGeometry(const TopoDS_Shape& S)
136 if (S.ShapeType() == TopAbs_VERTEX) {
138 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
139 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
141 while (itrp.More()) {
142 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
144 if (PR->IsPointOnCurve()) {
145 myCurves.Add(PR->Curve());
148 else if (PR->IsPointOnCurveOnSurface()) {
149 myCurves2d.Add(PR->PCurve());
150 mySurfaces.Add(PR->Surface());
153 else if (PR->IsPointOnSurface()) {
154 mySurfaces.Add(PR->Surface());
157 ChangeLocations().Add(PR->Location());
162 else if (S.ShapeType() == TopAbs_EDGE) {
164 // Add the curve geometry
165 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
166 BRep_ListIteratorOfListOfCurveRepresentation itrc(TE->Curves());
168 while (itrc.More()) {
169 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
170 if (CR->IsCurve3D()) {
171 if (!CR->Curve3D().IsNull()) {
172 myCurves.Add(CR->Curve3D());
173 ChangeLocations().Add(CR->Location());
176 else if (CR->IsCurveOnSurface()) {
177 mySurfaces.Add(CR->Surface());
178 myCurves2d.Add(CR->PCurve());
179 ChangeLocations().Add(CR->Location());
180 if (CR->IsCurveOnClosedSurface())
181 myCurves2d.Add(CR->PCurve2());
183 else if (CR->IsRegularity()) {
184 mySurfaces.Add(CR->Surface());
185 ChangeLocations().Add(CR->Location());
186 mySurfaces.Add(CR->Surface2());
187 ChangeLocations().Add(CR->Location2());
189 else if (myWithTriangles) { // for XML Persistence
190 if (CR->IsPolygon3D()) {
191 if (!CR->Polygon3D().IsNull()) {
192 myPolygons3D.Add(CR->Polygon3D());
193 ChangeLocations().Add(CR->Location());
196 else if (CR->IsPolygonOnTriangulation()) {
197 myTriangulations.Add(CR->Triangulation());
198 myNodes.Add(CR->PolygonOnTriangulation());
199 ChangeLocations().Add(CR->Location());
200 if (CR->IsPolygonOnClosedTriangulation())
201 myNodes.Add(CR->PolygonOnTriangulation2());
203 else if (CR->IsPolygonOnSurface()) {
204 mySurfaces.Add(CR->Surface());
205 myPolygons2D.Add(CR->Polygon());
206 ChangeLocations().Add(CR->Location());
207 if (CR->IsPolygonOnClosedSurface())
208 myPolygons2D.Add(CR->Polygon2());
215 else if (S.ShapeType() == TopAbs_FACE) {
217 // Add the surface geometry
218 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
219 if (!TF->Surface().IsNull()) mySurfaces.Add(TF->Surface());
221 if (myWithTriangles) { // for XML Persistence
222 Handle(Poly_Triangulation) Tr = TF->Triangulation();
223 if (!Tr.IsNull()) myTriangulations.Add(Tr);
226 ChangeLocations().Add(TF->Location());
231 //=======================================================================
232 //function : DumpGeometry
234 //=======================================================================
236 void BRepTools_ShapeSet::DumpGeometry(Standard_OStream& OS)const
241 DumpPolygonOnTriangulation(OS);
243 DumpTriangulation(OS);
247 //=======================================================================
248 //function : WriteGeometry
250 //=======================================================================
252 void BRepTools_ShapeSet::WriteGeometry(Standard_OStream& OS)
255 myCurves2d.SetProgress(GetProgress());
256 myCurves.SetProgress(GetProgress());
257 mySurfaces.SetProgress(GetProgress());
259 if ( !GetProgress().IsNull()) {
260 if(GetProgress()->UserBreak() ) return;
261 GetProgress()->NewScope ( 15, "2D Curves" );
263 myCurves2d.Write(OS);
265 if ( !GetProgress().IsNull()) {
266 if( GetProgress()->UserBreak() ) return;
267 GetProgress()->EndScope();
268 GetProgress()->Show();
270 GetProgress()->NewScope ( 15, "3D Curves" );
274 if ( !GetProgress().IsNull()) {
275 if( GetProgress()->UserBreak() ) return;
276 GetProgress()->EndScope();
277 GetProgress()->Show();
279 GetProgress()->NewScope ( 10, "3D Polygons" );
282 if ( !GetProgress().IsNull()) {
283 if( GetProgress()->UserBreak() ) return;
284 GetProgress()->EndScope();
285 GetProgress()->Show();
287 GetProgress()->NewScope ( 10, "Polygons On Triangulation" );
289 WritePolygonOnTriangulation(OS);
290 if ( !GetProgress().IsNull()) {
291 if( GetProgress()->UserBreak() ) return;
292 GetProgress()->EndScope();
293 GetProgress()->Show();
295 GetProgress()->NewScope ( 10, "Surfaces" );
297 mySurfaces.Write(OS);
298 if ( !GetProgress().IsNull()) {
299 if( GetProgress()->UserBreak() ) return;
300 GetProgress()->EndScope();
301 GetProgress()->Show();
303 GetProgress()->NewScope ( 15, "Triangulations" );
305 WriteTriangulation(OS);
306 if ( !GetProgress().IsNull()) {
307 if( GetProgress()->UserBreak() ) return;
308 GetProgress()->EndScope();
309 GetProgress()->Show();
314 //=======================================================================
315 //function : ReadGeometry
317 //=======================================================================
319 void BRepTools_ShapeSet::ReadGeometry(Standard_IStream& IS)
322 myCurves2d.SetProgress(GetProgress());
323 myCurves.SetProgress(GetProgress());
324 mySurfaces.SetProgress(GetProgress());
326 if ( !GetProgress().IsNull()) {
327 if( GetProgress()->UserBreak() ) return;
328 GetProgress()->NewScope ( 15, "2D Curves" );
332 if ( !GetProgress().IsNull()) {
333 if( GetProgress()->UserBreak() ) return;
334 GetProgress()->EndScope();
335 GetProgress()->Show();
337 GetProgress()->NewScope ( 15, "3D Curves" );
341 if ( !GetProgress().IsNull()) {
342 if( GetProgress()->UserBreak() ) return;
343 GetProgress()->EndScope();
344 GetProgress()->Show();
346 GetProgress()->NewScope ( 10, "3D Polygons" );
349 if ( !GetProgress().IsNull() ) {
350 if( GetProgress()->UserBreak() ) return;
351 GetProgress()->EndScope();
352 GetProgress()->Show();
354 GetProgress()->NewScope ( 10, "Polygons On Triangulation" );
356 ReadPolygonOnTriangulation(IS);
357 if ( !GetProgress().IsNull()) {
358 if( GetProgress()->UserBreak() ) return;
359 GetProgress()->EndScope();
360 GetProgress()->Show();
362 GetProgress()->NewScope ( 10, "Surfaces" );
365 if ( !GetProgress().IsNull() ) {
366 if( GetProgress()->UserBreak() ) return;
367 GetProgress()->EndScope();
368 GetProgress()->Show();
370 GetProgress()->NewScope ( 15, "Triangulations" );
372 ReadTriangulation(IS);
373 if ( !GetProgress().IsNull()) {
374 if( GetProgress()->UserBreak() ) return;
375 GetProgress()->EndScope();
376 GetProgress()->Show();
380 //=======================================================================
381 //function : PrintRegularity
383 //=======================================================================
385 static void PrintRegularity(const GeomAbs_Shape C,
386 Standard_OStream& OS)
421 //=======================================================================
422 //function : DumpGeometry
424 //=======================================================================
426 void BRepTools_ShapeSet::DumpGeometry(const TopoDS_Shape& S,
427 Standard_OStream& OS)const
431 if (S.ShapeType() == TopAbs_VERTEX) {
433 // Dump the point geometry
434 TopoDS_Vertex V = TopoDS::Vertex(S);
435 OS << " Tolerance : " << BRep_Tool::Tolerance(V) << "\n";
436 gp_Pnt p = BRep_Tool::Pnt(V);
437 OS << " - Point 3D : "<<p.X()<<", "<<p.Y()<<", "<<p.Z()<<"\n";
439 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
440 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
442 while (itrp.More()) {
443 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
445 OS << " - Parameter : "<< PR->Parameter();
446 if (PR->IsPointOnCurve()) {
447 OS << " on curve " << myCurves.Index(PR->Curve());
450 else if (PR->IsPointOnCurveOnSurface()) {
451 OS << " on pcurve " << myCurves2d.Index(PR->PCurve());
452 OS << " on surface " << mySurfaces.Index(PR->Surface());
455 else if (PR->IsPointOnSurface()) {
456 OS << ", " << PR->Parameter2() << " on surface ";
457 OS << mySurfaces.Index(PR->Surface());
460 if (!PR->Location().IsIdentity())
461 OS << " location " << Locations().Index(PR->Location());
469 else if (S.ShapeType() == TopAbs_EDGE) {
471 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
474 // Dump the curve geometry
475 OS << " Tolerance : " << TE->Tolerance() << "\n";
476 if (TE->SameParameter()) OS << " same parametrisation of curves\n";
477 if (TE->SameRange()) OS << " same range on curves\n";
478 if (TE->Degenerated()) OS << " degenerated\n";
480 Standard_Real first, last;
481 BRep_ListIteratorOfListOfCurveRepresentation itrc = TE->Curves();
482 while (itrc.More()) {
483 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
484 if (CR->IsCurve3D()) {
485 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
486 GC->Range(first, last);
487 if (!CR->Curve3D().IsNull()) {
488 OS << " - Curve 3D : "<<myCurves.Index(CR->Curve3D());
489 if (!CR->Location().IsIdentity())
490 OS << " location "<<Locations().Index(CR->Location());
491 OS <<", range : " << first << " " << last <<"\n";
494 else if (CR->IsCurveOnSurface()) {
495 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
496 GC->Range(first, last);
497 OS <<" - PCurve : "<<myCurves2d.Index(CR->PCurve());
498 if (CR->IsCurveOnClosedSurface()) {
499 OS <<", " << myCurves2d.Index(CR->PCurve2());
501 PrintRegularity(CR->Continuity(),OS);
504 OS << " on surface "<<mySurfaces.Index(CR->Surface());
505 if (!CR->Location().IsIdentity())
506 OS << " location "<<Locations().Index(CR->Location());
507 OS <<", range : " << first << " " << last <<"\n";
509 Handle(BRep_CurveOnSurface) COS =
510 Handle(BRep_CurveOnSurface)::DownCast(CR);
511 COS->UVPoints(Pf,Pl);
512 OS << " UV Points : " <<Pf.X()<<", "<<Pf.Y()<<" ";
513 OS << Pl.X()<<", "<<Pl.Y()<<"\n";
514 if (CR->IsCurveOnClosedSurface()) {
515 Handle(BRep_CurveOnClosedSurface) COCS =
516 Handle(BRep_CurveOnClosedSurface)::DownCast(CR);
517 COCS->UVPoints2(Pf,Pl);
518 OS << " UV Points : " <<Pf.X()<<", "<<Pf.Y()<<" ";
519 OS << Pl.X()<<", "<<Pl.Y()<<"\n";
522 else if (CR->IsRegularity()) {
523 OS << " - Regularity ";
524 PrintRegularity(CR->Continuity(),OS);
525 OS << " on surfaces : "<<mySurfaces.Index(CR->Surface());
526 if (!CR->Location().IsIdentity())
527 OS << " location "<<Locations().Index(CR->Location());
528 OS << ", "<<mySurfaces.Index(CR->Surface2());
529 if (!CR->Location2().IsIdentity())
530 OS << " location "<<Locations().Index(CR->Location2());
533 else if (CR->IsPolygon3D()) {
534 Handle(BRep_Polygon3D) GC = Handle(BRep_Polygon3D)::DownCast(itrc.Value());
535 if (!GC->Polygon3D().IsNull()) {
536 OS << " - Polygon 3D : "<<myPolygons3D.FindIndex(CR->Polygon3D());
537 if (!CR->Location().IsIdentity())
538 OS << " location "<<Locations().Index(CR->Location());
541 else if (CR->IsPolygonOnTriangulation()) {
542 OS << " - PolygonOnTriangulation " << myNodes.FindIndex(CR->PolygonOnTriangulation());
543 if (CR->IsPolygonOnClosedTriangulation()) {
544 OS << " " << myNodes.FindIndex(CR->PolygonOnTriangulation2());
546 OS << " on triangulation " << myTriangulations.FindIndex(CR->Triangulation());
547 if (!CR->Location().IsIdentity())
548 OS << " location "<<Locations().Index(CR->Location());
555 else if (S.ShapeType() == TopAbs_FACE) {
557 const TopoDS_Face& F = TopoDS::Face(S);
558 if (BRep_Tool::NaturalRestriction(F))
559 OS << "NaturalRestriction\n";
561 // Dump the surface geometry
562 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
563 if (!TF->Surface().IsNull()) {
564 OS << " Tolerance : " <<TF->Tolerance() << "\n";
565 OS << " - Surface : "<<mySurfaces.Index(TF->Surface());
566 if (!S.Location().IsIdentity())
567 OS << " location "<<Locations().Index(S.Location());
570 if (!(TF->Triangulation()).IsNull()) {
571 // Dump the triangulation
572 OS << " - Triangulation : " <<myTriangulations.FindIndex(TF->Triangulation());
573 if (!S.Location().IsIdentity())
574 OS << " location " <<Locations().Index(TF->Location());
583 //=======================================================================
584 //function : WriteGeometry
586 //=======================================================================
588 void BRepTools_ShapeSet::WriteGeometry(const TopoDS_Shape& S,
589 Standard_OStream& OS)const
591 // Write the geometry
593 if (S.ShapeType() == TopAbs_VERTEX) {
595 // Write the point geometry
596 TopoDS_Vertex V = TopoDS::Vertex(S);
597 OS << BRep_Tool::Tolerance(V) << "\n";
598 gp_Pnt p = BRep_Tool::Pnt(V);
599 OS<<p.X()<<" "<<p.Y()<<" "<<p.Z()<<"\n";
601 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
602 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
604 while (itrp.More()) {
605 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
607 OS << PR->Parameter();
608 if (PR->IsPointOnCurve()) {
609 OS << " 1 " << myCurves.Index(PR->Curve());
612 else if (PR->IsPointOnCurveOnSurface()) {
613 OS << " 2 " << myCurves2d.Index(PR->PCurve());
614 OS << " " << mySurfaces.Index(PR->Surface());
617 else if (PR->IsPointOnSurface()) {
618 OS << " 3 " << PR->Parameter2() << " ";
619 OS << mySurfaces.Index(PR->Surface());
622 OS << " " << Locations().Index(PR->Location());
628 OS << "0 0\n"; // end representations
632 else if (S.ShapeType() == TopAbs_EDGE) {
634 // Write the curve geometry
636 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
638 OS << " " << TE->Tolerance() << " ";
639 OS << ((TE->SameParameter()) ? 1 : 0) << " ";
640 OS << ((TE->SameRange()) ? 1 : 0) << " ";
641 OS << ((TE->Degenerated()) ? 1 : 0) << "\n";
643 Standard_Real first, last;
644 BRep_ListIteratorOfListOfCurveRepresentation itrc = TE->Curves();
645 while (itrc.More()) {
646 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
647 if (CR->IsCurve3D()) {
648 if (!CR->Curve3D().IsNull()) {
649 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
650 GC->Range(first, last);
651 OS << "1 "; // -1- Curve 3D
652 OS << " "<<myCurves.Index(CR->Curve3D());
653 OS << " "<<Locations().Index(CR->Location());
654 OS << " "<<first<<" "<<last;
658 else if (CR->IsCurveOnSurface()) {
659 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
660 GC->Range(first, last);
661 if (!CR->IsCurveOnClosedSurface())
662 OS << "2 "; // -2- Curve on surf
664 OS << "3 "; // -3- Curve on closed surf
665 OS <<" "<<myCurves2d.Index(CR->PCurve());
666 if (CR->IsCurveOnClosedSurface()) {
667 OS <<" " << myCurves2d.Index(CR->PCurve2());
668 PrintRegularity(CR->Continuity(),OS);
670 OS << " " << mySurfaces.Index(CR->Surface());
671 OS << " " << Locations().Index(CR->Location());
672 OS << " "<<first<<" "<<last;
675 // Write UV Points // for XML Persistence higher performance
679 if (CR->IsCurveOnClosedSurface()) {
680 Handle(BRep_CurveOnClosedSurface) COCS =
681 Handle(BRep_CurveOnClosedSurface)::DownCast(CR);
682 COCS->UVPoints2(Pf,Pl);
685 Handle(BRep_CurveOnSurface) COS =
686 Handle(BRep_CurveOnSurface)::DownCast(CR);
687 COS->UVPoints(Pf,Pl);
689 OS << Pf.X() << " " << Pf.Y() << " " << Pl.X() << " " << Pl.Y() << "\n";
692 else if (CR->IsRegularity()) {
693 OS << "4 "; // -4- Regularity
694 PrintRegularity(CR->Continuity(),OS);
695 OS << " "<<mySurfaces.Index(CR->Surface());
696 OS << " "<<Locations().Index(CR->Location());
697 OS << " "<<mySurfaces.Index(CR->Surface2());
698 OS << " "<<Locations().Index(CR->Location2());
702 else if (myWithTriangles) { // for XML Persistence
703 if (CR->IsPolygon3D()) {
704 Handle(BRep_Polygon3D) GC = Handle(BRep_Polygon3D)::DownCast(itrc.Value());
705 if (!GC->Polygon3D().IsNull()) {
706 OS << "5 "; // -5- Polygon3D
707 OS << " "<<myPolygons3D.FindIndex(CR->Polygon3D());
708 OS << " "<<Locations().Index(CR->Location());
712 else if (CR->IsPolygonOnTriangulation()) {
713 Handle(BRep_PolygonOnTriangulation) PT =
714 Handle(BRep_PolygonOnTriangulation)::DownCast(itrc.Value());
715 if (!CR->IsPolygonOnClosedTriangulation())
716 OS << "6 "; // -6- Polygon on triangulation
718 OS << "7 "; // -7- Polygon on closed triangulation
719 OS << " " << myNodes.FindIndex(PT->PolygonOnTriangulation());
720 if (CR->IsPolygonOnClosedTriangulation()) {
721 OS << " " << myNodes.FindIndex(PT->PolygonOnTriangulation2());
723 OS << " " << myTriangulations.FindIndex(PT->Triangulation());
724 OS << " "<<Locations().Index(CR->Location());
731 OS << "0\n"; // end of the list of representations
734 else if (S.ShapeType() == TopAbs_FACE) {
736 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
737 const TopoDS_Face& F = TopoDS::Face(S);
739 if (!(TF->Surface()).IsNull()) {
740 OS << ((BRep_Tool::NaturalRestriction(F)) ? 1 : 0);
742 // Write the surface geometry
743 OS << " " <<TF->Tolerance();
744 OS << " " <<mySurfaces.Index(TF->Surface());
745 OS << " " <<Locations().Index(TF->Location());
748 else //For correct reading of null face
752 OS << " " <<TF->Tolerance();
757 if (myWithTriangles) { // for XML Persistence
758 if (!(TF->Triangulation()).IsNull()) {
761 // Write the triangulation
762 OS << " " <<myTriangulations.FindIndex(TF->Triangulation());
769 //=======================================================================
770 //function : ReadRegularity
772 //=======================================================================
774 static GeomAbs_Shape ReadRegularity(Standard_IStream& IS)
815 //=======================================================================
816 //function : ReadGeometry
818 //=======================================================================
820 void BRepTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T,
821 Standard_IStream& IS,
826 Standard_Integer val,c,pc,pc2 = 0,s,s2,l,l2,t, pt, pt2 = 0;
827 Standard_Real tol,X,Y,Z,first,last,p1,p2;
828 Standard_Real PfX,PfY,PlX,PlY;
830 Standard_Boolean closed;
831 GeomAbs_Shape reg = GeomAbs_C0;
841 TopoDS_Vertex& V = TopoDS::Vertex(S);
843 // Read the point geometry
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();
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),
898 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
899 if (mySurfaces.Surface(s).IsNull())
901 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
903 Handle(BRep_PointOnSurface) POC =
904 new BRep_PointOnSurface(p1,p2,
905 mySurfaces.Surface(s),
915 PR->Location(Locations().Location(l));
933 TopoDS_Edge& E = TopoDS::Edge(S);
935 myBuilder.MakeEdge(E);
937 // Read the curve geometry
940 myBuilder.SameParameter(E,(val == 1));
942 myBuilder.SameRange(E,(val == 1));
944 myBuilder.Degenerated(E,(val == 1));
950 case 1 : // -1- Curve 3D
952 if (!myCurves.Curve(c).IsNull()) {
953 myBuilder.UpdateEdge(E,myCurves.Curve(c),
954 Locations().Location(l),tol);
957 if (!myCurves.Curve(c).IsNull()) {
958 Standard_Boolean Only3d = Standard_True;
959 myBuilder.Range(E,first,last,Only3d);
964 case 2 : // -2- Curve on surf
965 case 3 : // -3- Curve on closed surf
970 reg = ReadRegularity(IS);
979 // read UV Points // for XML Persistence higher performance
982 IS >> PfX >> PfY >> PlX >> PlY;
983 aPf = gp_Pnt2d(PfX,PfY);
984 aPl = gp_Pnt2d(PlX,PlY);
987 // Modified by Sergey KHROMOV - Wed Apr 24 12:11:16 2002 Begin
988 if (myCurves2d.Curve2d(pc).IsNull() ||
989 (closed && myCurves2d.Curve2d(pc2).IsNull()) ||
990 mySurfaces.Surface(s).IsNull())
992 // Modified by Sergey KHROMOV - Wed Apr 24 12:11:17 2002 End
996 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
997 myCurves2d.Curve2d(pc2),
998 mySurfaces.Surface(s),
999 Locations().Location(l),tol,
1002 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1003 myCurves2d.Curve2d(pc2),
1004 mySurfaces.Surface(s),
1005 Locations().Location(l),tol);
1007 myBuilder.Continuity(E,
1008 mySurfaces.Surface(s),
1009 mySurfaces.Surface(s),
1010 Locations().Location(l),
1011 Locations().Location(l),
1016 if (FormatNb() == 2)
1017 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1018 mySurfaces.Surface(s),
1019 Locations().Location(l),tol,
1022 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1023 mySurfaces.Surface(s),
1024 Locations().Location(l),tol);
1027 mySurfaces.Surface(s),
1028 Locations().Location(l),
1032 case 4 : // -4- Regularity
1033 reg = ReadRegularity(IS);
1034 IS >> s >> l >> s2 >> l2;
1035 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:13 2002 Begin
1036 if (mySurfaces.Surface(s).IsNull() ||
1037 mySurfaces.Surface(s2).IsNull())
1039 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:14 2002 End
1040 myBuilder.Continuity(E,
1041 mySurfaces.Surface(s),
1042 mySurfaces.Surface(s2),
1043 Locations().Location(l),
1044 Locations().Location(l2),
1048 case 5 : // -5- Polygon3D
1050 //szy-02.05.2004 myBuilder.UpdateEdge(E,Handle(Poly_Polygon3D)::DownCast(myPolygons3D(c)));
1051 if (c > 0 && c <= myPolygons3D.Extent())
1052 myBuilder.UpdateEdge(E,Handle(Poly_Polygon3D)::DownCast(myPolygons3D(c)), Locations().Location(l));
1057 closed = (val == 7);
1064 if (t > 0 && t <= myTriangulations.Extent() &&
1065 pt > 0 && pt <= myNodes.Extent() &&
1066 pt2 > 0 && pt2 <= myNodes.Extent())
1067 myBuilder.UpdateEdge
1068 (E, Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
1069 Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt2)),
1070 Handle(Poly_Triangulation)::DownCast(myTriangulations(t)),
1071 Locations().Location(l));
1074 if (t > 0 && t <= myTriangulations.Extent() &&
1075 pt > 0 && pt <= myNodes.Extent())
1076 myBuilder.UpdateEdge
1077 (E,Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
1078 Handle(Poly_Triangulation)::DownCast(myTriangulations(t)),
1079 Locations().Location(l));
1096 myBuilder.MakeWire(TopoDS::Wire(S));
1107 TopoDS_Face& F = TopoDS::Face(S);
1109 myBuilder.MakeFace(F);
1111 IS >> val; // natural restriction
1112 if (val == 0 || val == 1) {
1113 IS >> tol >> s >> l;
1114 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:13 2002 Begin
1115 if (!mySurfaces.Surface(s).IsNull()) {
1116 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:14 2002 End
1117 myBuilder.UpdateFace(TopoDS::Face(S),
1118 mySurfaces.Surface(s),
1119 Locations().Location(l),tol);
1120 myBuilder.NaturalRestriction(TopoDS::Face(S),(val == 1));
1122 // pos = IS.tellg();
1126 //only triangulation
1128 myBuilder.UpdateFace(TopoDS::Face(S),
1129 Handle(Poly_Triangulation)::DownCast(myTriangulations(s)));
1131 // else pos = IS.tellg();
1138 IS.getline ( string, 256, '\n' );
1139 IS.getline ( string, 256, '\n' );
1141 if (string[0] == '2') {
1142 // cas triangulation
1143 s = atoi ( &string[2] );
1144 if (s > 0 && s <= myTriangulations.Extent())
1145 myBuilder.UpdateFace(TopoDS::Face(S),
1146 Handle(Poly_Triangulation)::DownCast(myTriangulations(s)));
1148 // else IS.seekg(pos);
1158 myBuilder.MakeShell(TopoDS::Shell(S));
1167 myBuilder.MakeSolid(TopoDS::Solid(S));
1175 case TopAbs_COMPSOLID :
1176 myBuilder.MakeCompSolid(TopoDS::CompSolid(S));
1184 case TopAbs_COMPOUND :
1185 myBuilder.MakeCompound(TopoDS::Compound(S));
1196 //=======================================================================
1197 //function : AddShapes
1199 //=======================================================================
1201 void BRepTools_ShapeSet::AddShapes(TopoDS_Shape& S1,
1202 const TopoDS_Shape& S2)
1204 myBuilder.Add(S1,S2);
1207 //=======================================================================
1210 //=======================================================================
1212 void BRepTools_ShapeSet::Check(const TopAbs_ShapeEnum T,
1215 if (T == TopAbs_FACE) {
1216 const TopoDS_Face& F = TopoDS::Face(S);
1217 BRepTools::Update(F);
1223 //=======================================================================
1224 //function : WritePolygonOnTriangulation
1226 //=======================================================================
1228 void BRepTools_ShapeSet::WritePolygonOnTriangulation(Standard_OStream& OS,
1229 const Standard_Boolean Compact)const
1231 Standard_Integer i, j, nbpOntri = myNodes.Extent();
1233 Handle(Message_ProgressIndicator) progress = GetProgress();
1234 Message_ProgressSentry PS(progress, "Polygons On Triangulation", 0, nbpOntri, 1);
1236 OS << "PolygonOnTriangulations " << nbpOntri << endl;
1239 OS <<"Dump of " << nbpOntri << " PolygonOnTriangulations\n";
1243 Handle(Poly_PolygonOnTriangulation) Poly;
1244 Handle(TColStd_HArray1OfReal) Param;
1246 for (i=1; i<=nbpOntri && PS.More(); i++, PS.Next()) {
1247 if ( !progress.IsNull() )
1250 Poly = Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(i));
1251 const TColStd_Array1OfInteger& Nodes = Poly->Nodes();
1253 OS << " "<< i << " : PolygonOnTriangulation with " << Nodes.Length() << " Nodes\n";
1255 else OS << Nodes.Length()<<" ";
1256 if (!Compact) OS <<" ";
1257 for (j=1; j <= Nodes.Length(); j++) OS << Nodes.Value(j) << " ";
1260 // writing parameters:
1261 Param = Poly->Parameters();
1262 if (Compact) OS <<"p ";
1264 // write the deflection
1265 if (!Compact) OS << " Deflection : ";
1266 OS <<Poly->Deflection() << " ";
1267 if (!Compact) OS << "\n";
1269 if (!Param.IsNull()) {
1271 OS << " "<< "Parameters :";
1274 if (!Compact) OS <<" ";
1275 for (j=1; j <= Param->Length(); j++) OS << Param->Value(j) << " ";
1282 //=======================================================================
1283 //function : DumpPolygonOnTriangulation
1285 //=======================================================================
1287 void BRepTools_ShapeSet::DumpPolygonOnTriangulation(Standard_OStream& OS)const
1289 WritePolygonOnTriangulation(OS, Standard_False);
1292 //=======================================================================
1293 //function : ReadPolygonOnTriangulation
1295 //=======================================================================
1297 void BRepTools_ShapeSet::ReadPolygonOnTriangulation(Standard_IStream& IS)
1301 if (strstr(buffer,"PolygonOnTriangulations") == NULL) return;
1302 Standard_Integer i, j, val, nbpol = 0, nbnodes =0;
1303 Standard_Integer hasparameters;
1305 Handle(TColStd_HArray1OfReal) Param;
1306 Handle(Poly_PolygonOnTriangulation) Poly;
1309 Handle(Message_ProgressIndicator) progress = GetProgress();
1310 Message_ProgressSentry PS(progress, "Polygons On Triangulation", 0, nbpol, 1);
1311 for (i=1; i<=nbpol&& PS.More(); i++, PS.Next()) {
1312 if ( !progress.IsNull() )
1316 TColStd_Array1OfInteger Nodes(1, nbnodes);
1317 for (j = 1; j <= nbnodes; j++) {
1322 // if (!strcasecmp(buffer, "p")) {
1325 IS >> hasparameters;
1326 if (hasparameters) {
1327 TColStd_Array1OfReal Param1(1, nbnodes);
1328 for (j = 1; j <= nbnodes; j++) {
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 << endl;
1366 OS <<"Dump of " << nbpol << " Polygon3Ds\n";
1370 Handle(Poly_Polygon3D) P;
1371 for (i = 1; i <= nbpol && PS.More(); i++, PS.Next()) {
1372 if ( !progress.IsNull() )
1375 P = Handle(Poly_Polygon3D)::DownCast(myPolygons3D(i));
1377 OS << P->NbNodes() << " ";
1378 OS << ((P->HasParameters()) ? "1" : "0") << "\n";
1381 OS << " "<< i << " : Polygon3D with " << P->NbNodes() << " Nodes\n";
1382 OS << ((P->HasParameters()) ? "with" : "without") << " parameters\n";
1386 // write the deflection
1387 if (!Compact) OS << "Deflection : ";
1388 OS << P->Deflection() << "\n";
1391 if (!Compact) OS << "\nNodes :\n";
1393 Standard_Integer i1, nbNodes = P->NbNodes();
1394 const TColgp_Array1OfPnt& Nodes = P->Nodes();
1395 for (j = 1; j <= nbNodes; j++) {
1396 if (!Compact) OS << setw(10) << j << " : ";
1397 if (!Compact) OS << setw(17);
1398 OS << Nodes(j).X() << " ";
1399 if (!Compact) OS << setw(17);
1400 OS << Nodes(j).Y() << " ";
1401 if (!Compact) OS << setw(17);
1403 if (!Compact) OS << "\n";
1408 if (P->HasParameters()) {
1409 if (!Compact) OS << "\nParameters :\n";
1410 const TColStd_Array1OfReal& Param = P->Parameters();
1411 for ( i1 = 1; i1 <= nbNodes; i1++ ) {
1412 OS << Param(i1) << " ";
1419 //=======================================================================
1420 //function : DumpPolygon3D
1422 //=======================================================================
1424 void BRepTools_ShapeSet::DumpPolygon3D(Standard_OStream& OS)const
1426 WritePolygon3D(OS, Standard_False);
1430 //=======================================================================
1431 //function : ReadPolygon3D
1433 //=======================================================================
1435 void BRepTools_ShapeSet::ReadPolygon3D(Standard_IStream& IS)
1438 // Standard_Integer i, j, p, val, nbpol, nbnodes, hasparameters;
1439 Standard_Integer i, j, p, nbpol=0, nbnodes =0, hasparameters = Standard_False;
1440 Standard_Real d, x, y, z;
1443 if (strstr(buffer,"Polygon3D") == NULL) return;
1444 Handle(Poly_Polygon3D) P;
1447 Handle(Message_ProgressIndicator) progress = GetProgress();
1448 Message_ProgressSentry PS(progress, "3D Polygons", 0, nbpol, 1);
1449 for (i=1; i<=nbpol && PS.More(); i++, PS.Next()) {
1450 if ( !progress.IsNull() )
1454 IS >> hasparameters;
1455 TColgp_Array1OfPnt Nodes(1, nbnodes);
1457 for (j = 1; j <= nbnodes; j++) {
1459 Nodes(j).SetCoord(x,y,z);
1461 if (hasparameters) {
1462 TColStd_Array1OfReal Param(1,nbnodes);
1463 for (p = 1; p <= nbnodes; p++) {
1466 P = new Poly_Polygon3D(Nodes, Param);
1468 else P = new Poly_Polygon3D(Nodes);
1470 myPolygons3D.Add(P);
1476 //=======================================================================
1477 //function : WriteTriangulation
1479 //=======================================================================
1481 void BRepTools_ShapeSet::WriteTriangulation(Standard_OStream& OS,
1482 const Standard_Boolean Compact)const
1484 Standard_Integer i, j, nbNodes, nbtri = myTriangulations.Extent();
1485 Standard_Integer nbTriangles = 0, n1, n2, n3;
1487 Handle(Message_ProgressIndicator) progress = GetProgress();
1488 Message_ProgressSentry PS(progress, "Triangulations", 0, nbtri, 1);
1491 OS << "Triangulations " << nbtri << endl;
1494 OS <<"Dump of " << nbtri << " Triangulations\n";
1498 Handle(Poly_Triangulation) T;
1499 for (i = 1; i <= nbtri && PS.More(); i++, PS.Next()) {
1500 if ( !progress.IsNull() )
1503 T = Handle(Poly_Triangulation)::DownCast(myTriangulations(i));
1505 OS << T->NbNodes() << " " << T->NbTriangles() << " ";
1506 OS << ((T->HasUVNodes()) ? "1" : "0") << " ";
1509 OS << " "<< i << " : Triangulation with " << T->NbNodes() << " Nodes and "
1510 << T->NbTriangles() <<" Triangles\n";
1511 OS << " "<<((T->HasUVNodes()) ? "with" : "without") << " UV nodes\n";
1515 // write the deflection
1517 if (!Compact) OS << " Deflection : ";
1518 OS <<T->Deflection() << "\n";
1520 // write the 3d nodes
1522 if (!Compact) OS << "\n3D Nodes :\n";
1524 nbNodes = T->NbNodes();
1525 const TColgp_Array1OfPnt& Nodes = T->Nodes();
1526 for (j = 1; j <= nbNodes; j++) {
1527 if (!Compact) OS << setw(10) << j << " : ";
1528 if (!Compact) OS << setw(17);
1529 OS << Nodes(j).X() << " ";
1530 if (!Compact) OS << setw(17);
1531 OS << Nodes(j).Y() << " ";
1532 if (!Compact) OS << setw(17);
1534 if (!Compact) OS << "\n";
1538 if (T->HasUVNodes()) {
1539 if (!Compact) OS << "\nUV Nodes :\n";
1540 const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes();
1541 for (j = 1; j <= nbNodes; j++) {
1542 if (!Compact) OS << setw(10) << j << " : ";
1543 if (!Compact) OS << setw(17);
1544 OS << UVNodes(j).X() << " ";
1545 if (!Compact) OS << setw(17);
1546 OS << UVNodes(j).Y();
1547 if (!Compact) OS << "\n";
1552 if (!Compact) OS << "\nTriangles :\n";
1553 nbTriangles = T->NbTriangles();
1554 const Poly_Array1OfTriangle& Triangles = T->Triangles();
1555 for (j = 1; j <= nbTriangles; j++) {
1556 if (!Compact) OS << setw(10) << j << " : ";
1557 Triangles(j).Get(n1, n2, n3);
1558 if (!Compact) OS << setw(10);
1560 if (!Compact) OS << setw(10);
1562 if (!Compact) OS << setw(10);
1564 if (!Compact) OS << "\n";
1571 //=======================================================================
1572 //function : DumpTriangulation
1574 //=======================================================================
1576 void BRepTools_ShapeSet::DumpTriangulation(Standard_OStream& OS)const
1578 WriteTriangulation(OS, Standard_False);
1582 //=======================================================================
1583 //function : ReadTriangulation
1585 //=======================================================================
1587 void BRepTools_ShapeSet::ReadTriangulation(Standard_IStream& IS)
1590 // Standard_Integer i, j, val, nbtri;
1591 Standard_Integer i, j, nbtri =0;
1592 Standard_Real d, x, y, z;
1593 Standard_Integer nbNodes =0, nbTriangles=0;
1594 Standard_Boolean hasUV= Standard_False;
1596 Handle(Poly_Triangulation) T;
1599 if (strstr(buffer,"Triangulations") == NULL) return;
1603 Handle(Message_ProgressIndicator) progress = GetProgress();
1604 Message_ProgressSentry PS(progress, "Triangulations", 0, nbtri, 1);
1605 for (i=1; i<=nbtri && PS.More();i++, PS.Next()) {
1606 if ( !progress.IsNull() )
1609 IS >> nbNodes >> nbTriangles >> hasUV;
1612 TColgp_Array1OfPnt Nodes(1, nbNodes);
1613 TColgp_Array1OfPnt2d UVNodes(1, nbNodes);
1615 for (j = 1; j <= nbNodes; j++) {
1617 Nodes(j).SetCoord(x,y,z);
1621 for (j = 1; j <= nbNodes; j++) {
1623 UVNodes(j).SetCoord(x,y);
1627 // read the triangles
1628 Standard_Integer n1,n2,n3;
1629 Poly_Array1OfTriangle Triangles(1, nbTriangles);
1630 for (j = 1; j <= nbTriangles; j++) {
1631 IS >> n1 >> n2 >> n3;
1632 Triangles(j).Set(n1,n2,n3);
1635 if (hasUV) T = new Poly_Triangulation(Nodes,UVNodes,Triangles);
1636 else T = new Poly_Triangulation(Nodes,Triangles);
1640 myTriangulations.Add(T);