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 // Modified: Portage NT 7-5-97 DPF (strcasecmp)
19 #include <BRep_Builder.hxx>
20 #include <BRep_CurveOnClosedSurface.hxx>
21 #include <BRep_CurveOnSurface.hxx>
22 #include <BRep_CurveRepresentation.hxx>
23 #include <BRep_GCurve.hxx>
24 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
25 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
26 #include <BRep_ListOfCurveRepresentation.hxx>
27 #include <BRep_PointOnCurve.hxx>
28 #include <BRep_PointOnCurveOnSurface.hxx>
29 #include <BRep_PointOnSurface.hxx>
30 #include <BRep_Polygon3D.hxx>
31 #include <BRep_PolygonOnClosedSurface.hxx>
32 #include <BRep_PolygonOnClosedTriangulation.hxx>
33 #include <BRep_PolygonOnSurface.hxx>
34 #include <BRep_PolygonOnTriangulation.hxx>
35 #include <BRep_TEdge.hxx>
36 #include <BRep_TFace.hxx>
37 #include <BRep_Tool.hxx>
38 #include <BRep_TVertex.hxx>
39 #include <BRepTools.hxx>
40 #include <BRepTools_ShapeSet.hxx>
41 #include <GeomTools.hxx>
42 #include <Message_ProgressScope.hxx>
44 #include <Poly_Polygon2D.hxx>
45 #include <Poly_Polygon3D.hxx>
46 #include <Poly_PolygonOnTriangulation.hxx>
47 #include <Poly_Triangulation.hxx>
48 #include <Precision.hxx>
49 #include <Standard_Stream.hxx>
50 #include <TColgp_HArray1OfPnt.hxx>
51 #include <TColgp_HArray1OfPnt2d.hxx>
52 #include <TColStd_HArray1OfInteger.hxx>
53 #include <TColStd_HArray1OfReal.hxx>
55 #include <TopoDS_Shape.hxx>
56 #include <TopoDS_Vertex.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 std::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 //=======================================================================
87 BRepTools_ShapeSet::BRepTools_ShapeSet (const Standard_Boolean theWithTriangles)
88 : myWithTriangles (theWithTriangles)
92 //=======================================================================
93 //function : BRepTools_ShapeSet
95 //=======================================================================
96 BRepTools_ShapeSet::BRepTools_ShapeSet (const BRep_Builder& theBuilder,
97 const Standard_Boolean theWithTriangles)
98 : myBuilder (theBuilder),
99 myWithTriangles (theWithTriangles)
103 //=======================================================================
104 //function : ~BRepTools_ShapeSet
106 //=======================================================================
107 BRepTools_ShapeSet::~BRepTools_ShapeSet()
112 //=======================================================================
115 //=======================================================================
117 void BRepTools_ShapeSet::Clear()
122 myPolygons3D.Clear();
123 myPolygons2D.Clear();
125 myTriangulations.Clear();
126 TopTools_ShapeSet::Clear();
130 //=======================================================================
131 //function : AddGeometry
133 //=======================================================================
135 void BRepTools_ShapeSet::AddGeometry(const TopoDS_Shape& S)
139 if (S.ShapeType() == TopAbs_VERTEX) {
141 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
142 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
144 while (itrp.More()) {
145 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
147 if (PR->IsPointOnCurve()) {
148 myCurves.Add(PR->Curve());
151 else if (PR->IsPointOnCurveOnSurface()) {
152 myCurves2d.Add(PR->PCurve());
153 mySurfaces.Add(PR->Surface());
156 else if (PR->IsPointOnSurface()) {
157 mySurfaces.Add(PR->Surface());
160 ChangeLocations().Add(PR->Location());
165 else if (S.ShapeType() == TopAbs_EDGE) {
167 // Add the curve geometry
168 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
169 BRep_ListIteratorOfListOfCurveRepresentation itrc(TE->Curves());
171 while (itrc.More()) {
172 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
173 if (CR->IsCurve3D()) {
174 if (!CR->Curve3D().IsNull()) {
175 myCurves.Add(CR->Curve3D());
176 ChangeLocations().Add(CR->Location());
179 else if (CR->IsCurveOnSurface()) {
180 mySurfaces.Add(CR->Surface());
181 myCurves2d.Add(CR->PCurve());
182 ChangeLocations().Add(CR->Location());
183 if (CR->IsCurveOnClosedSurface())
184 myCurves2d.Add(CR->PCurve2());
186 else if (CR->IsRegularity()) {
187 mySurfaces.Add(CR->Surface());
188 ChangeLocations().Add(CR->Location());
189 mySurfaces.Add(CR->Surface2());
190 ChangeLocations().Add(CR->Location2());
192 else if (myWithTriangles) { // for XML Persistence
193 if (CR->IsPolygon3D()) {
194 if (!CR->Polygon3D().IsNull()) {
195 myPolygons3D.Add(CR->Polygon3D());
196 ChangeLocations().Add(CR->Location());
199 else if (CR->IsPolygonOnTriangulation()) {
200 myTriangulations.Add(CR->Triangulation());
201 myNodes.Add(CR->PolygonOnTriangulation());
202 ChangeLocations().Add(CR->Location());
203 if (CR->IsPolygonOnClosedTriangulation())
204 myNodes.Add(CR->PolygonOnTriangulation2());
206 else if (CR->IsPolygonOnSurface()) {
207 mySurfaces.Add(CR->Surface());
208 myPolygons2D.Add(CR->Polygon());
209 ChangeLocations().Add(CR->Location());
210 if (CR->IsPolygonOnClosedSurface())
211 myPolygons2D.Add(CR->Polygon2());
218 else if (S.ShapeType() == TopAbs_FACE) {
220 // Add the surface geometry
221 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
222 if (!TF->Surface().IsNull()) mySurfaces.Add(TF->Surface());
224 if (myWithTriangles || TF->Surface().IsNull()) { // for XML Persistence
225 Handle(Poly_Triangulation) Tr = TF->Triangulation();
226 if (!Tr.IsNull()) myTriangulations.Add(Tr);
229 ChangeLocations().Add(TF->Location());
234 //=======================================================================
235 //function : DumpGeometry
237 //=======================================================================
239 void BRepTools_ShapeSet::DumpGeometry (Standard_OStream& OS)const
244 DumpPolygonOnTriangulation(OS);
246 DumpTriangulation(OS);
250 //=======================================================================
251 //function : WriteGeometry
253 //=======================================================================
255 void BRepTools_ShapeSet::WriteGeometry(Standard_OStream& OS, const Message_ProgressRange& theProgress)
257 // Make nested progress scope for processing geometry
258 Message_ProgressScope aPS(theProgress, "Geometry", 100);
260 myCurves2d.Write(OS, aPS.Next(20));
261 if (aPS.UserBreak()) return;
263 myCurves.Write(OS, aPS.Next(20));
264 if (aPS.UserBreak()) return;
266 WritePolygon3D(OS, Standard_True, aPS.Next(10));
267 if (aPS.UserBreak()) return;
269 WritePolygonOnTriangulation(OS, Standard_True, aPS.Next(10));
270 if (aPS.UserBreak()) return;
272 mySurfaces.Write(OS, aPS.Next(20));
273 if (aPS.UserBreak()) return;
275 WriteTriangulation(OS, Standard_True, aPS.Next(20));
279 //=======================================================================
280 //function : ReadGeometry
282 //=======================================================================
284 void BRepTools_ShapeSet::ReadGeometry(Standard_IStream& IS, const Message_ProgressRange& theProgress)
286 // Make nested progress scope for processing geometry
287 Message_ProgressScope aPS(theProgress, "Geometry", 100);
289 myCurves2d.Read(IS, aPS.Next(20));
290 if (aPS.UserBreak()) return;
292 myCurves.Read(IS, aPS.Next(20));
293 if (aPS.UserBreak()) return;
295 ReadPolygon3D(IS, aPS.Next(15));
296 if (aPS.UserBreak()) return;
298 ReadPolygonOnTriangulation(IS, aPS.Next(15));
299 if (aPS.UserBreak()) return;
301 mySurfaces.Read(IS, aPS.Next(15));
302 if (aPS.UserBreak()) return;
304 ReadTriangulation(IS, aPS.Next(15));
307 //=======================================================================
308 //function : PrintRegularity
310 //=======================================================================
312 static void PrintRegularity(const GeomAbs_Shape C,
313 Standard_OStream& OS)
348 //=======================================================================
349 //function : DumpGeometry
351 //=======================================================================
353 void BRepTools_ShapeSet::DumpGeometry(const TopoDS_Shape& S,
354 Standard_OStream& OS)const
358 if (S.ShapeType() == TopAbs_VERTEX) {
360 // Dump the point geometry
361 TopoDS_Vertex V = TopoDS::Vertex(S);
362 OS << " Tolerance : " << BRep_Tool::Tolerance(V) << "\n";
363 gp_Pnt p = BRep_Tool::Pnt(V);
364 OS << " - Point 3D : "<<p.X()<<", "<<p.Y()<<", "<<p.Z()<<"\n";
366 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
367 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
369 while (itrp.More()) {
370 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
372 OS << " - Parameter : "<< PR->Parameter();
373 if (PR->IsPointOnCurve()) {
374 OS << " on curve " << myCurves.Index(PR->Curve());
377 else if (PR->IsPointOnCurveOnSurface()) {
378 OS << " on pcurve " << myCurves2d.Index(PR->PCurve());
379 OS << " on surface " << mySurfaces.Index(PR->Surface());
382 else if (PR->IsPointOnSurface()) {
383 OS << ", " << PR->Parameter2() << " on surface ";
384 OS << mySurfaces.Index(PR->Surface());
387 if (!PR->Location().IsIdentity())
388 OS << " location " << Locations().Index(PR->Location());
396 else if (S.ShapeType() == TopAbs_EDGE) {
398 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
401 // Dump the curve geometry
402 OS << " Tolerance : " << TE->Tolerance() << "\n";
403 if (TE->SameParameter()) OS << " same parametrisation of curves\n";
404 if (TE->SameRange()) OS << " same range on curves\n";
405 if (TE->Degenerated()) OS << " degenerated\n";
407 Standard_Real first, last;
408 BRep_ListIteratorOfListOfCurveRepresentation itrc = TE->Curves();
409 while (itrc.More()) {
410 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
411 if (CR->IsCurve3D()) {
412 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
413 GC->Range(first, last);
414 if (!CR->Curve3D().IsNull()) {
415 OS << " - Curve 3D : "<<myCurves.Index(CR->Curve3D());
416 if (!CR->Location().IsIdentity())
417 OS << " location "<<Locations().Index(CR->Location());
418 OS <<", range : " << first << " " << last <<"\n";
421 else if (CR->IsCurveOnSurface()) {
422 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
423 GC->Range(first, last);
424 OS <<" - PCurve : "<<myCurves2d.Index(CR->PCurve());
425 if (CR->IsCurveOnClosedSurface()) {
426 OS <<", " << myCurves2d.Index(CR->PCurve2());
428 PrintRegularity(CR->Continuity(),OS);
431 OS << " on surface "<<mySurfaces.Index(CR->Surface());
432 if (!CR->Location().IsIdentity())
433 OS << " location "<<Locations().Index(CR->Location());
434 OS <<", range : " << first << " " << last <<"\n";
436 Handle(BRep_CurveOnSurface) COS =
437 Handle(BRep_CurveOnSurface)::DownCast(CR);
438 COS->UVPoints(Pf,Pl);
439 OS << " UV Points : " <<Pf.X()<<", "<<Pf.Y()<<" ";
440 OS << Pl.X()<<", "<<Pl.Y()<<"\n";
441 if (CR->IsCurveOnClosedSurface()) {
442 Handle(BRep_CurveOnClosedSurface) COCS =
443 Handle(BRep_CurveOnClosedSurface)::DownCast(CR);
444 COCS->UVPoints2(Pf,Pl);
445 OS << " UV Points : " <<Pf.X()<<", "<<Pf.Y()<<" ";
446 OS << Pl.X()<<", "<<Pl.Y()<<"\n";
449 else if (CR->IsRegularity()) {
450 OS << " - Regularity ";
451 PrintRegularity(CR->Continuity(),OS);
452 OS << " on surfaces : "<<mySurfaces.Index(CR->Surface());
453 if (!CR->Location().IsIdentity())
454 OS << " location "<<Locations().Index(CR->Location());
455 OS << ", "<<mySurfaces.Index(CR->Surface2());
456 if (!CR->Location2().IsIdentity())
457 OS << " location "<<Locations().Index(CR->Location2());
460 else if (CR->IsPolygon3D()) {
461 Handle(BRep_Polygon3D) GC = Handle(BRep_Polygon3D)::DownCast(itrc.Value());
462 if (!GC->Polygon3D().IsNull()) {
463 OS << " - Polygon 3D : "<<myPolygons3D.FindIndex(CR->Polygon3D());
464 if (!CR->Location().IsIdentity())
465 OS << " location "<<Locations().Index(CR->Location());
468 else if (CR->IsPolygonOnTriangulation()) {
469 OS << " - PolygonOnTriangulation " << myNodes.FindIndex(CR->PolygonOnTriangulation());
470 if (CR->IsPolygonOnClosedTriangulation()) {
471 OS << " " << myNodes.FindIndex(CR->PolygonOnTriangulation2());
473 OS << " on triangulation " << myTriangulations.FindIndex(CR->Triangulation());
474 if (!CR->Location().IsIdentity())
475 OS << " location "<<Locations().Index(CR->Location());
482 else if (S.ShapeType() == TopAbs_FACE) {
484 const TopoDS_Face& F = TopoDS::Face(S);
485 if (BRep_Tool::NaturalRestriction(F))
486 OS << "NaturalRestriction\n";
488 // Dump the surface geometry
489 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
490 if (!TF->Surface().IsNull()) {
491 OS << " Tolerance : " <<TF->Tolerance() << "\n";
492 OS << " - Surface : "<<mySurfaces.Index(TF->Surface());
493 if (!S.Location().IsIdentity())
494 OS << " location "<<Locations().Index(S.Location());
497 if (!(TF->Triangulation()).IsNull()) {
498 // Dump the triangulation
499 OS << " - Triangulation : " <<myTriangulations.FindIndex(TF->Triangulation());
500 if (!S.Location().IsIdentity())
501 OS << " location " <<Locations().Index(TF->Location());
510 //=======================================================================
511 //function : WriteGeometry
513 //=======================================================================
515 void BRepTools_ShapeSet::WriteGeometry (const TopoDS_Shape& S, Standard_OStream& OS)const
517 // Write the geometry
519 if (S.ShapeType() == TopAbs_VERTEX) {
521 // Write the point geometry
522 TopoDS_Vertex V = TopoDS::Vertex(S);
523 OS << BRep_Tool::Tolerance(V) << "\n";
524 gp_Pnt p = BRep_Tool::Pnt(V);
525 OS<<p.X()<<" "<<p.Y()<<" "<<p.Z()<<"\n";
527 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
528 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
530 while (itrp.More()) {
531 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
533 OS << PR->Parameter();
534 if (PR->IsPointOnCurve()) {
535 OS << " 1 " << myCurves.Index(PR->Curve());
538 else if (PR->IsPointOnCurveOnSurface()) {
539 OS << " 2 " << myCurves2d.Index(PR->PCurve());
540 OS << " " << mySurfaces.Index(PR->Surface());
543 else if (PR->IsPointOnSurface()) {
544 OS << " 3 " << PR->Parameter2() << " ";
545 OS << mySurfaces.Index(PR->Surface());
548 OS << " " << Locations().Index(PR->Location());
554 OS << "0 0\n"; // end representations
558 else if (S.ShapeType() == TopAbs_EDGE) {
560 // Write the curve geometry
562 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
564 OS << " " << TE->Tolerance() << " ";
565 OS << ((TE->SameParameter()) ? 1 : 0) << " ";
566 OS << ((TE->SameRange()) ? 1 : 0) << " ";
567 OS << ((TE->Degenerated()) ? 1 : 0) << "\n";
569 Standard_Real first, last;
570 BRep_ListIteratorOfListOfCurveRepresentation itrc = TE->Curves();
571 while (itrc.More()) {
572 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
573 if (CR->IsCurve3D()) {
574 if (!CR->Curve3D().IsNull()) {
575 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
576 GC->Range(first, last);
577 OS << "1 "; // -1- Curve 3D
578 OS << " "<<myCurves.Index(CR->Curve3D());
579 OS << " "<<Locations().Index(CR->Location());
580 OS << " "<<first<<" "<<last;
584 else if (CR->IsCurveOnSurface()) {
585 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
586 GC->Range(first, last);
587 if (!CR->IsCurveOnClosedSurface())
588 OS << "2 "; // -2- Curve on surf
590 OS << "3 "; // -3- Curve on closed surf
591 OS <<" "<<myCurves2d.Index(CR->PCurve());
592 if (CR->IsCurveOnClosedSurface()) {
593 OS <<" " << myCurves2d.Index(CR->PCurve2());
594 PrintRegularity(CR->Continuity(),OS);
596 OS << " " << mySurfaces.Index(CR->Surface());
597 OS << " " << Locations().Index(CR->Location());
598 OS << " "<<first<<" "<<last;
601 // Write UV Points // for XML Persistence higher performance
602 if (FormatNb() == TopTools_FormatVersion_VERSION_2)
605 if (CR->IsCurveOnClosedSurface()) {
606 Handle(BRep_CurveOnClosedSurface) COCS =
607 Handle(BRep_CurveOnClosedSurface)::DownCast(CR);
608 COCS->UVPoints2(Pf,Pl);
611 Handle(BRep_CurveOnSurface) COS =
612 Handle(BRep_CurveOnSurface)::DownCast(CR);
613 COS->UVPoints(Pf,Pl);
615 OS << Pf.X() << " " << Pf.Y() << " " << Pl.X() << " " << Pl.Y() << "\n";
618 else if (CR->IsRegularity()) {
619 OS << "4 "; // -4- Regularity
620 PrintRegularity(CR->Continuity(),OS);
621 OS << " "<<mySurfaces.Index(CR->Surface());
622 OS << " "<<Locations().Index(CR->Location());
623 OS << " "<<mySurfaces.Index(CR->Surface2());
624 OS << " "<<Locations().Index(CR->Location2());
628 else if (myWithTriangles) { // for XML Persistence
629 if (CR->IsPolygon3D()) {
630 Handle(BRep_Polygon3D) GC = Handle(BRep_Polygon3D)::DownCast(itrc.Value());
631 if (!GC->Polygon3D().IsNull()) {
632 OS << "5 "; // -5- Polygon3D
633 OS << " "<<myPolygons3D.FindIndex(CR->Polygon3D());
634 OS << " "<<Locations().Index(CR->Location());
638 else if (CR->IsPolygonOnTriangulation()) {
639 Handle(BRep_PolygonOnTriangulation) PT =
640 Handle(BRep_PolygonOnTriangulation)::DownCast(itrc.Value());
641 if (!CR->IsPolygonOnClosedTriangulation())
642 OS << "6 "; // -6- Polygon on triangulation
644 OS << "7 "; // -7- Polygon on closed triangulation
645 OS << " " << myNodes.FindIndex(PT->PolygonOnTriangulation());
646 if (CR->IsPolygonOnClosedTriangulation()) {
647 OS << " " << myNodes.FindIndex(PT->PolygonOnTriangulation2());
649 OS << " " << myTriangulations.FindIndex(PT->Triangulation());
650 OS << " "<<Locations().Index(CR->Location());
657 OS << "0\n"; // end of the list of representations
660 else if (S.ShapeType() == TopAbs_FACE) {
662 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
663 const TopoDS_Face& F = TopoDS::Face(S);
665 if (!(TF->Surface()).IsNull()) {
666 OS << ((BRep_Tool::NaturalRestriction(F)) ? 1 : 0);
668 // Write the surface geometry
669 OS << " " <<TF->Tolerance();
670 OS << " " <<mySurfaces.Index(TF->Surface());
671 OS << " " <<Locations().Index(TF->Location());
674 else //For correct reading of null face
678 OS << " " <<TF->Tolerance();
683 if (myWithTriangles || TF->Surface().IsNull()) { // for XML Persistence
684 if (!(TF->Triangulation()).IsNull()) {
687 // Write the triangulation
688 OS << " " <<myTriangulations.FindIndex(TF->Triangulation());
695 //=======================================================================
696 //function : ReadRegularity
698 //=======================================================================
700 static GeomAbs_Shape ReadRegularity(Standard_IStream& IS)
741 //=======================================================================
742 //function : ReadGeometry
744 //=======================================================================
746 void BRepTools_ShapeSet::ReadGeometry (const TopAbs_ShapeEnum T,
747 Standard_IStream& IS,
752 Standard_Integer val,c,pc,pc2 = 0,s,s2,l,l2,t, pt, pt2 = 0;
753 Standard_Real tol,X,Y,Z,first,last,p1,p2;
754 Standard_Real PfX,PfY,PlX,PlY;
756 Standard_Boolean closed;
757 GeomAbs_Shape reg = GeomAbs_C0;
767 TopoDS_Vertex& V = TopoDS::Vertex(S);
769 // Read the point geometry
770 GeomTools::GetReal(IS, tol);
771 GeomTools::GetReal(IS, X);
772 GeomTools::GetReal(IS, Y);
773 GeomTools::GetReal(IS, Z);
774 myBuilder.MakeVertex(V,gp_Pnt(X,Y,Z),tol);
775 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(V.TShape());
777 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
781 GeomTools::GetReal(IS, p1);
784 Handle(BRep_PointRepresentation) PR;
791 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
792 if (myCurves.Curve(c).IsNull())
794 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
796 Handle(BRep_PointOnCurve) POC =
797 new BRep_PointOnCurve(p1,
808 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
809 if (myCurves2d.Curve2d(pc).IsNull() ||
810 mySurfaces.Surface(s).IsNull())
812 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
814 Handle(BRep_PointOnCurveOnSurface) POC =
815 new BRep_PointOnCurveOnSurface(p1,
816 myCurves2d.Curve2d(pc),
817 mySurfaces.Surface(s),
825 GeomTools::GetReal(IS, p2);
828 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
829 if (mySurfaces.Surface(s).IsNull())
831 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
833 Handle(BRep_PointOnSurface) POC =
834 new BRep_PointOnSurface(p1,p2,
835 mySurfaces.Surface(s),
845 PR->Location(Locations().Location(l));
863 TopoDS_Edge& E = TopoDS::Edge(S);
865 myBuilder.MakeEdge(E);
867 // Read the curve geometry
868 GeomTools::GetReal(IS, tol);
870 myBuilder.SameParameter(E,(val == 1));
872 myBuilder.SameRange(E,(val == 1));
874 myBuilder.Degenerated(E,(val == 1));
880 case 1 : // -1- Curve 3D
882 if (!myCurves.Curve(c).IsNull()) {
883 myBuilder.UpdateEdge(E,myCurves.Curve(c),
884 Locations().Location(l),tol);
886 GeomTools::GetReal(IS, first);
887 GeomTools::GetReal(IS, last);
888 if (!myCurves.Curve(c).IsNull()) {
889 Standard_Boolean Only3d = Standard_True;
890 myBuilder.Range(E,first,last,Only3d);
895 case 2 : // -2- Curve on surf
896 case 3 : // -3- Curve on closed surf
901 reg = ReadRegularity(IS);
908 GeomTools::GetReal(IS, first);
909 GeomTools::GetReal(IS, last);
911 // read UV Points // for XML Persistence higher performance
912 if (FormatNb() == TopTools_FormatVersion_VERSION_2)
914 GeomTools::GetReal(IS, PfX);
915 GeomTools::GetReal(IS, PfY);
916 GeomTools::GetReal(IS, PlX);
917 GeomTools::GetReal(IS, PlY);
918 aPf = gp_Pnt2d(PfX,PfY);
919 aPl = gp_Pnt2d(PlX,PlY);
922 // Modified by Sergey KHROMOV - Wed Apr 24 12:11:16 2002 Begin
923 if (myCurves2d.Curve2d(pc).IsNull() ||
924 (closed && myCurves2d.Curve2d(pc2).IsNull()) ||
925 mySurfaces.Surface(s).IsNull())
927 // Modified by Sergey KHROMOV - Wed Apr 24 12:11:17 2002 End
930 if (FormatNb() == TopTools_FormatVersion_VERSION_2)
931 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
932 myCurves2d.Curve2d(pc2),
933 mySurfaces.Surface(s),
934 Locations().Location(l),tol,
937 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
938 myCurves2d.Curve2d(pc2),
939 mySurfaces.Surface(s),
940 Locations().Location(l),tol);
942 myBuilder.Continuity(E,
943 mySurfaces.Surface(s),
944 mySurfaces.Surface(s),
945 Locations().Location(l),
946 Locations().Location(l),
951 if (FormatNb() == TopTools_FormatVersion_VERSION_2)
952 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
953 mySurfaces.Surface(s),
954 Locations().Location(l),tol,
957 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
958 mySurfaces.Surface(s),
959 Locations().Location(l),tol);
962 mySurfaces.Surface(s),
963 Locations().Location(l),
967 case 4 : // -4- Regularity
968 reg = ReadRegularity(IS);
969 IS >> s >> l >> s2 >> l2;
970 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:13 2002 Begin
971 if (mySurfaces.Surface(s).IsNull() ||
972 mySurfaces.Surface(s2).IsNull())
974 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:14 2002 End
975 myBuilder.Continuity(E,
976 mySurfaces.Surface(s),
977 mySurfaces.Surface(s2),
978 Locations().Location(l),
979 Locations().Location(l2),
983 case 5 : // -5- Polygon3D
985 //szy-02.05.2004 myBuilder.UpdateEdge(E,Handle(Poly_Polygon3D)::DownCast(myPolygons3D(c)));
986 if (c > 0 && c <= myPolygons3D.Extent())
987 myBuilder.UpdateEdge(E,Handle(Poly_Polygon3D)::DownCast(myPolygons3D(c)), Locations().Location(l));
999 if (t > 0 && t <= myTriangulations.Extent() &&
1000 pt > 0 && pt <= myNodes.Extent() &&
1001 pt2 > 0 && pt2 <= myNodes.Extent())
1002 myBuilder.UpdateEdge
1003 (E, Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
1004 Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt2)),
1005 Handle(Poly_Triangulation)::DownCast(myTriangulations(t)),
1006 Locations().Location(l));
1009 if (t > 0 && t <= myTriangulations.Extent() &&
1010 pt > 0 && pt <= myNodes.Extent())
1011 myBuilder.UpdateEdge
1012 (E,Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
1013 Handle(Poly_Triangulation)::DownCast(myTriangulations(t)),
1014 Locations().Location(l));
1031 myBuilder.MakeWire(TopoDS::Wire(S));
1042 TopoDS_Face& F = TopoDS::Face(S);
1043 // std::streampos pos;
1044 myBuilder.MakeFace(F);
1046 IS >> val; // natural restriction
1047 if (val == 0 || val == 1) {
1048 GeomTools::GetReal(IS, tol);
1050 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:13 2002 Begin
1051 if (!mySurfaces.Surface(s).IsNull()) {
1052 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:14 2002 End
1053 myBuilder.UpdateFace(TopoDS::Face(S),
1054 mySurfaces.Surface(s),
1055 Locations().Location(l),tol);
1056 myBuilder.NaturalRestriction(TopoDS::Face(S),(val == 1));
1058 // pos = IS.tellg();
1062 //only triangulation
1064 myBuilder.UpdateFace(TopoDS::Face(S),
1065 Handle(Poly_Triangulation)::DownCast(myTriangulations(s)));
1067 // else pos = IS.tellg();
1074 IS.getline ( string, 256, '\n' );
1075 IS.getline ( string, 256, '\n' );
1077 if (string[0] == '2') {
1078 // cas triangulation
1079 s = atoi ( &string[2] );
1080 if (s > 0 && s <= myTriangulations.Extent())
1081 myBuilder.UpdateFace(TopoDS::Face(S),
1082 Handle(Poly_Triangulation)::DownCast(myTriangulations(s)));
1084 // else IS.seekg(pos);
1094 myBuilder.MakeShell(TopoDS::Shell(S));
1103 myBuilder.MakeSolid(TopoDS::Solid(S));
1111 case TopAbs_COMPSOLID :
1112 myBuilder.MakeCompSolid(TopoDS::CompSolid(S));
1120 case TopAbs_COMPOUND :
1121 myBuilder.MakeCompound(TopoDS::Compound(S));
1132 //=======================================================================
1133 //function : AddShapes
1135 //=======================================================================
1137 void BRepTools_ShapeSet::AddShapes(TopoDS_Shape& S1,
1138 const TopoDS_Shape& S2)
1140 myBuilder.Add(S1,S2);
1143 //=======================================================================
1146 //=======================================================================
1148 void BRepTools_ShapeSet::Check(const TopAbs_ShapeEnum T,
1151 if (T == TopAbs_FACE) {
1152 const TopoDS_Face& F = TopoDS::Face(S);
1153 BRepTools::Update(F);
1159 //=======================================================================
1160 //function : WritePolygonOnTriangulation
1162 //=======================================================================
1164 void BRepTools_ShapeSet::WritePolygonOnTriangulation(Standard_OStream& OS,
1165 const Standard_Boolean Compact,
1166 const Message_ProgressRange& theProgress)const
1168 Standard_Integer i, j, nbpOntri = myNodes.Extent();
1170 Message_ProgressScope aPS(theProgress, "Polygons On Triangulation", nbpOntri);
1172 OS << "PolygonOnTriangulations " << nbpOntri << "\n";
1175 OS <<"Dump of " << nbpOntri << " PolygonOnTriangulations\n";
1179 Handle(Poly_PolygonOnTriangulation) Poly;
1180 Handle(TColStd_HArray1OfReal) Param;
1181 for (i=1; i<=nbpOntri && aPS.More(); i++, aPS.Next()) {
1182 Poly = Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(i));
1183 const TColStd_Array1OfInteger& Nodes = Poly->Nodes();
1185 OS << " "<< i << " : PolygonOnTriangulation with " << Nodes.Length() << " Nodes\n";
1187 else OS << Nodes.Length()<<" ";
1188 if (!Compact) OS <<" ";
1189 for (j=1; j <= Nodes.Length(); j++) OS << Nodes.Value(j) << " ";
1192 // writing parameters:
1193 Param = Poly->Parameters();
1194 if (Compact) OS <<"p ";
1196 // write the deflection
1197 if (!Compact) OS << " Deflection : ";
1198 OS <<Poly->Deflection() << " ";
1199 if (!Compact) OS << "\n";
1201 if (!Param.IsNull()) {
1203 OS << " Parameters :";
1206 if (!Compact) OS <<" ";
1207 for (j=1; j <= Param->Length(); j++) OS << Param->Value(j) << " ";
1214 //=======================================================================
1215 //function : DumpPolygonOnTriangulation
1217 //=======================================================================
1219 void BRepTools_ShapeSet::DumpPolygonOnTriangulation(Standard_OStream& OS)const
1221 WritePolygonOnTriangulation(OS, Standard_False);
1224 //=======================================================================
1225 //function : ReadPolygonOnTriangulation
1227 //=======================================================================
1229 void BRepTools_ShapeSet::ReadPolygonOnTriangulation(Standard_IStream& IS,
1230 const Message_ProgressRange& theProgress)
1234 if (strstr(buffer,"PolygonOnTriangulations") == NULL) return;
1235 Standard_Integer i, j, val, nbpol = 0, nbnodes =0;
1236 Standard_Integer hasparameters;
1238 Handle(TColStd_HArray1OfReal) Param;
1239 Handle(Poly_PolygonOnTriangulation) Poly;
1242 Message_ProgressScope aPS(theProgress, "Polygons On Triangulation", nbpol);
1243 for (i=1; i<=nbpol&& aPS.More(); i++, aPS.Next()) {
1245 TColStd_Array1OfInteger Nodes(1, nbnodes);
1246 for (j = 1; j <= nbnodes; j++) {
1251 // if (!strcasecmp(buffer, "p")) {
1253 GeomTools::GetReal(IS, def);
1254 IS >> hasparameters;
1255 if (hasparameters) {
1256 TColStd_Array1OfReal Param1(1, nbnodes);
1257 for (j = 1; j <= nbnodes; j++) {
1258 GeomTools::GetReal(IS, par);
1261 Poly = new Poly_PolygonOnTriangulation(Nodes, Param1);
1263 else Poly = new Poly_PolygonOnTriangulation(Nodes);
1264 Poly->Deflection(def);
1268 // Poly = new Poly_PolygonOnTriangulation(Nodes);
1273 // else IS.seekg(pos);
1278 //=======================================================================
1279 //function : WritePolygon3D
1281 //=======================================================================
1283 void BRepTools_ShapeSet::WritePolygon3D(Standard_OStream& OS,
1284 const Standard_Boolean Compact,
1285 const Message_ProgressRange& theProgress)const
1287 Standard_Integer i, j, nbpol = myPolygons3D.Extent();
1289 Message_ProgressScope aPS(theProgress, "3D Polygons", nbpol);
1292 OS << "Polygon3D " << nbpol << "\n";
1295 OS <<"Dump of " << nbpol << " Polygon3Ds\n";
1299 Handle(Poly_Polygon3D) P;
1300 for (i = 1; i <= nbpol && aPS.More(); i++, aPS.Next()) {
1301 P = Handle(Poly_Polygon3D)::DownCast(myPolygons3D(i));
1303 OS << P->NbNodes() << " ";
1304 OS << ((P->HasParameters()) ? "1" : "0") << "\n";
1307 OS << " "<< i << " : Polygon3D with " << P->NbNodes() << " Nodes\n";
1308 OS << ((P->HasParameters()) ? "with" : "without") << " parameters\n";
1312 // write the deflection
1313 if (!Compact) OS << "Deflection : ";
1314 OS << P->Deflection() << "\n";
1317 if (!Compact) OS << "\nNodes :\n";
1319 Standard_Integer i1, nbNodes = P->NbNodes();
1320 const TColgp_Array1OfPnt& Nodes = P->Nodes();
1321 for (j = 1; j <= nbNodes; j++) {
1322 if (!Compact) OS << std::setw(10) << j << " : ";
1323 if (!Compact) OS << std::setw(17);
1324 OS << Nodes(j).X() << " ";
1325 if (!Compact) OS << std::setw(17);
1326 OS << Nodes(j).Y() << " ";
1327 if (!Compact) OS << std::setw(17);
1329 if (!Compact) OS << "\n";
1334 if (P->HasParameters()) {
1335 if (!Compact) OS << "\nParameters :\n";
1336 const TColStd_Array1OfReal& Param = P->Parameters();
1337 for ( i1 = 1; i1 <= nbNodes; i1++ ) {
1338 OS << Param(i1) << " ";
1345 //=======================================================================
1346 //function : DumpPolygon3D
1348 //=======================================================================
1350 void BRepTools_ShapeSet::DumpPolygon3D(Standard_OStream& OS)const
1352 WritePolygon3D(OS, Standard_False);
1356 //=======================================================================
1357 //function : ReadPolygon3D
1359 //=======================================================================
1361 void BRepTools_ShapeSet::ReadPolygon3D(Standard_IStream& IS, const Message_ProgressRange& theProgress)
1364 // Standard_Integer i, j, p, val, nbpol, nbnodes, hasparameters;
1365 Standard_Integer i, j, p, nbpol=0, nbnodes =0, hasparameters = Standard_False;
1366 Standard_Real d, x, y, z;
1369 if (strstr(buffer,"Polygon3D") == NULL) return;
1370 Handle(Poly_Polygon3D) P;
1373 Message_ProgressScope aPS(theProgress, "3D Polygons", nbpol);
1374 for (i=1; i<=nbpol && aPS.More(); i++, aPS.Next()) {
1376 IS >> hasparameters;
1377 TColgp_Array1OfPnt Nodes(1, nbnodes);
1378 GeomTools::GetReal(IS, d);
1379 for (j = 1; j <= nbnodes; j++) {
1380 GeomTools::GetReal(IS, x);
1381 GeomTools::GetReal(IS, y);
1382 GeomTools::GetReal(IS, z);
1383 Nodes(j).SetCoord(x,y,z);
1385 if (hasparameters) {
1386 TColStd_Array1OfReal Param(1,nbnodes);
1387 for (p = 1; p <= nbnodes; p++) {
1388 GeomTools::GetReal(IS, Param(p));
1390 P = new Poly_Polygon3D(Nodes, Param);
1392 else P = new Poly_Polygon3D(Nodes);
1394 myPolygons3D.Add(P);
1400 //=======================================================================
1401 //function : WriteTriangulation
1403 //=======================================================================
1405 void BRepTools_ShapeSet::WriteTriangulation(Standard_OStream& OS,
1406 const Standard_Boolean Compact,
1407 const Message_ProgressRange& theProgress)const
1409 Standard_Integer i, j, nbNodes, nbtri = myTriangulations.Extent();
1410 Standard_Integer nbTriangles = 0, n1, n2, n3;
1412 Message_ProgressScope aPS(theProgress, "Triangulations", nbtri);
1415 OS << "Triangulations " << nbtri << "\n";
1418 OS <<"Dump of " << nbtri << " Triangulations\n";
1422 Handle(Poly_Triangulation) T;
1423 for (i = 1; i <= nbtri && aPS.More(); i++, aPS.Next()) {
1425 T = Handle(Poly_Triangulation)::DownCast(myTriangulations(i));
1427 OS << T->NbNodes() << " " << T->NbTriangles() << " ";
1428 OS << ((T->HasUVNodes()) ? "1" : "0") << " ";
1431 OS << " "<< i << " : Triangulation with " << T->NbNodes() << " Nodes and "
1432 << T->NbTriangles() <<" Triangles\n";
1433 OS << " "<<((T->HasUVNodes()) ? "with" : "without") << " UV nodes\n";
1437 // write the deflection
1439 if (!Compact) OS << " Deflection : ";
1440 OS <<T->Deflection() << "\n";
1442 // write the 3d nodes
1444 if (!Compact) OS << "\n3D Nodes :\n";
1446 nbNodes = T->NbNodes();
1447 const TColgp_Array1OfPnt& Nodes = T->Nodes();
1448 for (j = 1; j <= nbNodes; j++) {
1449 if (!Compact) OS << std::setw(10) << j << " : ";
1450 if (!Compact) OS << std::setw(17);
1451 OS << Nodes(j).X() << " ";
1452 if (!Compact) OS << std::setw(17);
1453 OS << Nodes(j).Y() << " ";
1454 if (!Compact) OS << std::setw(17);
1456 if (!Compact) OS << "\n";
1460 if (T->HasUVNodes()) {
1461 if (!Compact) OS << "\nUV Nodes :\n";
1462 const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes();
1463 for (j = 1; j <= nbNodes; j++) {
1464 if (!Compact) OS << std::setw(10) << j << " : ";
1465 if (!Compact) OS << std::setw(17);
1466 OS << UVNodes(j).X() << " ";
1467 if (!Compact) OS << std::setw(17);
1468 OS << UVNodes(j).Y();
1469 if (!Compact) OS << "\n";
1474 if (!Compact) OS << "\nTriangles :\n";
1475 nbTriangles = T->NbTriangles();
1476 const Poly_Array1OfTriangle& Triangles = T->Triangles();
1477 for (j = 1; j <= nbTriangles; j++) {
1478 if (!Compact) OS << std::setw(10) << j << " : ";
1479 Triangles(j).Get(n1, n2, n3);
1480 if (!Compact) OS << std::setw(10);
1482 if (!Compact) OS << std::setw(10);
1484 if (!Compact) OS << std::setw(10);
1486 if (!Compact) OS << "\n";
1493 //=======================================================================
1494 //function : DumpTriangulation
1496 //=======================================================================
1498 void BRepTools_ShapeSet::DumpTriangulation(Standard_OStream& OS)const
1500 WriteTriangulation(OS, Standard_False);
1504 //=======================================================================
1505 //function : ReadTriangulation
1507 //=======================================================================
1509 void BRepTools_ShapeSet::ReadTriangulation(Standard_IStream& IS, const Message_ProgressRange& theProgress)
1512 // Standard_Integer i, j, val, nbtri;
1513 Standard_Integer i, j, nbtri =0;
1514 Standard_Real d, x, y, z;
1515 Standard_Integer nbNodes =0, nbTriangles=0;
1516 Standard_Boolean hasUV= Standard_False;
1518 Handle(Poly_Triangulation) T;
1521 if (strstr(buffer,"Triangulations") == NULL) return;
1525 Message_ProgressScope aPS(theProgress, "Triangulations", nbtri);
1526 for (i=1; i<=nbtri && aPS.More();i++, aPS.Next()) {
1528 IS >> nbNodes >> nbTriangles >> hasUV;
1529 GeomTools::GetReal(IS, d);
1531 TColgp_Array1OfPnt Nodes(1, nbNodes);
1532 TColgp_Array1OfPnt2d UVNodes(1, nbNodes);
1534 for (j = 1; j <= nbNodes; j++) {
1535 GeomTools::GetReal(IS, x);
1536 GeomTools::GetReal(IS, y);
1537 GeomTools::GetReal(IS, z);
1538 Nodes(j).SetCoord(x,y,z);
1542 for (j = 1; j <= nbNodes; j++) {
1543 GeomTools::GetReal(IS, x);
1544 GeomTools::GetReal(IS, y);
1545 UVNodes(j).SetCoord(x,y);
1549 // read the triangles
1550 Standard_Integer n1,n2,n3;
1551 Poly_Array1OfTriangle Triangles(1, nbTriangles);
1552 for (j = 1; j <= nbTriangles; j++) {
1553 IS >> n1 >> n2 >> n3;
1554 Triangles(j).Set(n1,n2,n3);
1557 if (hasUV) T = new Poly_Triangulation(Nodes,UVNodes,Triangles);
1558 else T = new Poly_Triangulation(Nodes,Triangles);
1562 myTriangulations.Add(T);