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 parameter for triangulation).
83 //=======================================================================
84 //function : BRepTools_ShapeSet
86 //=======================================================================
87 BRepTools_ShapeSet::BRepTools_ShapeSet (const Standard_Boolean theWithTriangles,
88 const Standard_Boolean theWithNormals)
89 : myWithTriangles (theWithTriangles),
90 myWithNormals (theWithNormals)
94 //=======================================================================
95 //function : BRepTools_ShapeSet
97 //=======================================================================
98 BRepTools_ShapeSet::BRepTools_ShapeSet (const BRep_Builder& theBuilder,
99 const Standard_Boolean theWithTriangles,
100 const Standard_Boolean theWithNormals)
101 : myBuilder (theBuilder),
102 myWithTriangles (theWithTriangles),
103 myWithNormals(theWithNormals)
107 //=======================================================================
108 //function : ~BRepTools_ShapeSet
110 //=======================================================================
111 BRepTools_ShapeSet::~BRepTools_ShapeSet()
116 //=======================================================================
119 //=======================================================================
121 void BRepTools_ShapeSet::Clear()
126 myPolygons3D.Clear();
127 myPolygons2D.Clear();
129 myTriangulations.Clear();
130 TopTools_ShapeSet::Clear();
134 //=======================================================================
135 //function : AddGeometry
137 //=======================================================================
139 void BRepTools_ShapeSet::AddGeometry(const TopoDS_Shape& S)
143 if (S.ShapeType() == TopAbs_VERTEX) {
145 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
146 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
148 while (itrp.More()) {
149 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
151 if (PR->IsPointOnCurve()) {
152 myCurves.Add(PR->Curve());
155 else if (PR->IsPointOnCurveOnSurface()) {
156 myCurves2d.Add(PR->PCurve());
157 mySurfaces.Add(PR->Surface());
160 else if (PR->IsPointOnSurface()) {
161 mySurfaces.Add(PR->Surface());
164 ChangeLocations().Add(PR->Location());
169 else if (S.ShapeType() == TopAbs_EDGE) {
171 // Add the curve geometry
172 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
173 BRep_ListIteratorOfListOfCurveRepresentation itrc(TE->Curves());
175 while (itrc.More()) {
176 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
177 if (CR->IsCurve3D()) {
178 if (!CR->Curve3D().IsNull()) {
179 myCurves.Add(CR->Curve3D());
180 ChangeLocations().Add(CR->Location());
183 else if (CR->IsCurveOnSurface()) {
184 mySurfaces.Add(CR->Surface());
185 myCurves2d.Add(CR->PCurve());
186 ChangeLocations().Add(CR->Location());
187 if (CR->IsCurveOnClosedSurface())
188 myCurves2d.Add(CR->PCurve2());
190 else if (CR->IsRegularity()) {
191 mySurfaces.Add(CR->Surface());
192 ChangeLocations().Add(CR->Location());
193 mySurfaces.Add(CR->Surface2());
194 ChangeLocations().Add(CR->Location2());
196 else if (myWithTriangles) { // for XML Persistence
197 if (CR->IsPolygon3D()) {
198 if (!CR->Polygon3D().IsNull()) {
199 myPolygons3D.Add(CR->Polygon3D());
200 ChangeLocations().Add(CR->Location());
203 else if (CR->IsPolygonOnTriangulation()) {
204 // NCollection_IndexedDataMap::Add() function use is correct because
205 // Bin(Brep)Tools_ShapeSet::AddGeometry() is called from Bin(Brep)Tools_ShapeSet::Add()
206 // that processes shapes recursively from complex to elementary ones.
207 // As a result, the TopAbs_FACE's will be processed earlier than the TopAbs_EDGE's.
208 myTriangulations.Add(CR->Triangulation(), Standard_False); // edge triangulation does not need normals
209 myNodes.Add(CR->PolygonOnTriangulation());
210 ChangeLocations().Add(CR->Location());
211 if (CR->IsPolygonOnClosedTriangulation())
212 myNodes.Add(CR->PolygonOnTriangulation2());
214 else if (CR->IsPolygonOnSurface()) {
215 mySurfaces.Add(CR->Surface());
216 myPolygons2D.Add(CR->Polygon());
217 ChangeLocations().Add(CR->Location());
218 if (CR->IsPolygonOnClosedSurface())
219 myPolygons2D.Add(CR->Polygon2());
226 else if (S.ShapeType() == TopAbs_FACE) {
228 // Add the surface geometry
229 Standard_Boolean needNormals(myWithNormals);
230 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
231 if (!TF->Surface().IsNull())
233 mySurfaces.Add(TF->Surface());
237 needNormals = Standard_True;
239 if (myWithTriangles || TF->Surface().IsNull()) { // for XML Persistence
240 Handle(Poly_Triangulation) Tr = TF->Triangulation();
241 if (!Tr.IsNull()) myTriangulations.Add(Tr, needNormals);
244 ChangeLocations().Add(TF->Location());
249 //=======================================================================
250 //function : DumpGeometry
252 //=======================================================================
254 void BRepTools_ShapeSet::DumpGeometry (Standard_OStream& OS)const
259 DumpPolygonOnTriangulation(OS);
261 DumpTriangulation(OS);
265 //=======================================================================
266 //function : WriteGeometry
268 //=======================================================================
270 void BRepTools_ShapeSet::WriteGeometry(Standard_OStream& OS, const Message_ProgressRange& theProgress)
272 // Make nested progress scope for processing geometry
273 Message_ProgressScope aPS(theProgress, "Geometry", 100);
275 myCurves2d.Write(OS, aPS.Next(20));
276 if (aPS.UserBreak()) return;
278 myCurves.Write(OS, aPS.Next(20));
279 if (aPS.UserBreak()) return;
281 WritePolygon3D(OS, Standard_True, aPS.Next(10));
282 if (aPS.UserBreak()) return;
284 WritePolygonOnTriangulation(OS, Standard_True, aPS.Next(10));
285 if (aPS.UserBreak()) return;
287 mySurfaces.Write(OS, aPS.Next(20));
288 if (aPS.UserBreak()) return;
290 WriteTriangulation(OS, Standard_True, aPS.Next(20));
294 //=======================================================================
295 //function : ReadGeometry
297 //=======================================================================
299 void BRepTools_ShapeSet::ReadGeometry(Standard_IStream& IS, const Message_ProgressRange& theProgress)
301 // Make nested progress scope for processing geometry
302 Message_ProgressScope aPS(theProgress, "Geometry", 100);
304 myCurves2d.Read(IS, aPS.Next(20));
305 if (aPS.UserBreak()) return;
307 myCurves.Read(IS, aPS.Next(20));
308 if (aPS.UserBreak()) return;
310 ReadPolygon3D(IS, aPS.Next(15));
311 if (aPS.UserBreak()) return;
313 ReadPolygonOnTriangulation(IS, aPS.Next(15));
314 if (aPS.UserBreak()) return;
316 mySurfaces.Read(IS, aPS.Next(15));
317 if (aPS.UserBreak()) return;
319 ReadTriangulation(IS, aPS.Next(15));
322 //=======================================================================
323 //function : PrintRegularity
325 //=======================================================================
327 static void PrintRegularity(const GeomAbs_Shape C,
328 Standard_OStream& OS)
363 //=======================================================================
364 //function : DumpGeometry
366 //=======================================================================
368 void BRepTools_ShapeSet::DumpGeometry(const TopoDS_Shape& S,
369 Standard_OStream& OS)const
373 if (S.ShapeType() == TopAbs_VERTEX) {
375 // Dump the point geometry
376 TopoDS_Vertex V = TopoDS::Vertex(S);
377 OS << " Tolerance : " << BRep_Tool::Tolerance(V) << "\n";
378 gp_Pnt p = BRep_Tool::Pnt(V);
379 OS << " - Point 3D : "<<p.X()<<", "<<p.Y()<<", "<<p.Z()<<"\n";
381 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
382 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
384 while (itrp.More()) {
385 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
387 OS << " - Parameter : "<< PR->Parameter();
388 if (PR->IsPointOnCurve()) {
389 OS << " on curve " << myCurves.Index(PR->Curve());
392 else if (PR->IsPointOnCurveOnSurface()) {
393 OS << " on pcurve " << myCurves2d.Index(PR->PCurve());
394 OS << " on surface " << mySurfaces.Index(PR->Surface());
397 else if (PR->IsPointOnSurface()) {
398 OS << ", " << PR->Parameter2() << " on surface ";
399 OS << mySurfaces.Index(PR->Surface());
402 if (!PR->Location().IsIdentity())
403 OS << " location " << Locations().Index(PR->Location());
411 else if (S.ShapeType() == TopAbs_EDGE) {
413 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
416 // Dump the curve geometry
417 OS << " Tolerance : " << TE->Tolerance() << "\n";
418 if (TE->SameParameter()) OS << " same parametrisation of curves\n";
419 if (TE->SameRange()) OS << " same range on curves\n";
420 if (TE->Degenerated()) OS << " degenerated\n";
422 Standard_Real first, last;
423 BRep_ListIteratorOfListOfCurveRepresentation itrc = TE->Curves();
424 while (itrc.More()) {
425 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
426 if (CR->IsCurve3D()) {
427 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
428 GC->Range(first, last);
429 if (!CR->Curve3D().IsNull()) {
430 OS << " - Curve 3D : "<<myCurves.Index(CR->Curve3D());
431 if (!CR->Location().IsIdentity())
432 OS << " location "<<Locations().Index(CR->Location());
433 OS <<", range : " << first << " " << last <<"\n";
436 else if (CR->IsCurveOnSurface()) {
437 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
438 GC->Range(first, last);
439 OS <<" - PCurve : "<<myCurves2d.Index(CR->PCurve());
440 if (CR->IsCurveOnClosedSurface()) {
441 OS <<", " << myCurves2d.Index(CR->PCurve2());
443 PrintRegularity(CR->Continuity(),OS);
446 OS << " on surface "<<mySurfaces.Index(CR->Surface());
447 if (!CR->Location().IsIdentity())
448 OS << " location "<<Locations().Index(CR->Location());
449 OS <<", range : " << first << " " << last <<"\n";
451 Handle(BRep_CurveOnSurface) COS =
452 Handle(BRep_CurveOnSurface)::DownCast(CR);
453 COS->UVPoints(Pf,Pl);
454 OS << " UV Points : " <<Pf.X()<<", "<<Pf.Y()<<" ";
455 OS << Pl.X()<<", "<<Pl.Y()<<"\n";
456 if (CR->IsCurveOnClosedSurface()) {
457 Handle(BRep_CurveOnClosedSurface) COCS =
458 Handle(BRep_CurveOnClosedSurface)::DownCast(CR);
459 COCS->UVPoints2(Pf,Pl);
460 OS << " UV Points : " <<Pf.X()<<", "<<Pf.Y()<<" ";
461 OS << Pl.X()<<", "<<Pl.Y()<<"\n";
464 else if (CR->IsRegularity()) {
465 OS << " - Regularity ";
466 PrintRegularity(CR->Continuity(),OS);
467 OS << " on surfaces : "<<mySurfaces.Index(CR->Surface());
468 if (!CR->Location().IsIdentity())
469 OS << " location "<<Locations().Index(CR->Location());
470 OS << ", "<<mySurfaces.Index(CR->Surface2());
471 if (!CR->Location2().IsIdentity())
472 OS << " location "<<Locations().Index(CR->Location2());
475 else if (CR->IsPolygon3D()) {
476 Handle(BRep_Polygon3D) GC = Handle(BRep_Polygon3D)::DownCast(itrc.Value());
477 if (!GC->Polygon3D().IsNull()) {
478 OS << " - Polygon 3D : "<<myPolygons3D.FindIndex(CR->Polygon3D());
479 if (!CR->Location().IsIdentity())
480 OS << " location "<<Locations().Index(CR->Location());
483 else if (CR->IsPolygonOnTriangulation()) {
484 OS << " - PolygonOnTriangulation " << myNodes.FindIndex(CR->PolygonOnTriangulation());
485 if (CR->IsPolygonOnClosedTriangulation()) {
486 OS << " " << myNodes.FindIndex(CR->PolygonOnTriangulation2());
488 OS << " on triangulation " << myTriangulations.FindIndex(CR->Triangulation());
489 if (!CR->Location().IsIdentity())
490 OS << " location "<<Locations().Index(CR->Location());
497 else if (S.ShapeType() == TopAbs_FACE) {
499 const TopoDS_Face& F = TopoDS::Face(S);
500 if (BRep_Tool::NaturalRestriction(F))
501 OS << "NaturalRestriction\n";
503 // Dump the surface geometry
504 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
505 if (!TF->Surface().IsNull()) {
506 OS << " Tolerance : " <<TF->Tolerance() << "\n";
507 OS << " - Surface : "<<mySurfaces.Index(TF->Surface());
508 if (!S.Location().IsIdentity())
509 OS << " location "<<Locations().Index(S.Location());
512 if (!(TF->Triangulation()).IsNull()) {
513 // Dump the triangulation
514 OS << " - Triangulation : " <<myTriangulations.FindIndex(TF->Triangulation());
515 if (!S.Location().IsIdentity())
516 OS << " location " <<Locations().Index(TF->Location());
525 //=======================================================================
526 //function : WriteGeometry
528 //=======================================================================
530 void BRepTools_ShapeSet::WriteGeometry (const TopoDS_Shape& S, Standard_OStream& OS)const
532 // Write the geometry
534 if (S.ShapeType() == TopAbs_VERTEX) {
536 // Write the point geometry
537 TopoDS_Vertex V = TopoDS::Vertex(S);
538 OS << BRep_Tool::Tolerance(V) << "\n";
539 gp_Pnt p = BRep_Tool::Pnt(V);
540 OS<<p.X()<<" "<<p.Y()<<" "<<p.Z()<<"\n";
542 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
543 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
545 while (itrp.More()) {
546 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
548 OS << PR->Parameter();
549 if (PR->IsPointOnCurve()) {
550 OS << " 1 " << myCurves.Index(PR->Curve());
553 else if (PR->IsPointOnCurveOnSurface()) {
554 OS << " 2 " << myCurves2d.Index(PR->PCurve());
555 OS << " " << mySurfaces.Index(PR->Surface());
558 else if (PR->IsPointOnSurface()) {
559 OS << " 3 " << PR->Parameter2() << " ";
560 OS << mySurfaces.Index(PR->Surface());
563 OS << " " << Locations().Index(PR->Location());
569 OS << "0 0\n"; // end representations
573 else if (S.ShapeType() == TopAbs_EDGE) {
575 // Write the curve geometry
577 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
579 OS << " " << TE->Tolerance() << " ";
580 OS << ((TE->SameParameter()) ? 1 : 0) << " ";
581 OS << ((TE->SameRange()) ? 1 : 0) << " ";
582 OS << ((TE->Degenerated()) ? 1 : 0) << "\n";
584 Standard_Real first, last;
585 BRep_ListIteratorOfListOfCurveRepresentation itrc = TE->Curves();
586 while (itrc.More()) {
587 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
588 if (CR->IsCurve3D()) {
589 if (!CR->Curve3D().IsNull()) {
590 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
591 GC->Range(first, last);
592 OS << "1 "; // -1- Curve 3D
593 OS << " "<<myCurves.Index(CR->Curve3D());
594 OS << " "<<Locations().Index(CR->Location());
595 OS << " "<<first<<" "<<last;
599 else if (CR->IsCurveOnSurface()) {
600 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
601 GC->Range(first, last);
602 if (!CR->IsCurveOnClosedSurface())
603 OS << "2 "; // -2- Curve on surf
605 OS << "3 "; // -3- Curve on closed surf
606 OS <<" "<<myCurves2d.Index(CR->PCurve());
607 if (CR->IsCurveOnClosedSurface()) {
608 OS <<" " << myCurves2d.Index(CR->PCurve2());
609 PrintRegularity(CR->Continuity(),OS);
611 OS << " " << mySurfaces.Index(CR->Surface());
612 OS << " " << Locations().Index(CR->Location());
613 OS << " "<<first<<" "<<last;
616 // Write UV Points // for XML Persistence higher performance
617 if (FormatNb() == TopTools_FormatVersion_VERSION_2)
620 if (CR->IsCurveOnClosedSurface()) {
621 Handle(BRep_CurveOnClosedSurface) COCS =
622 Handle(BRep_CurveOnClosedSurface)::DownCast(CR);
623 COCS->UVPoints2(Pf,Pl);
626 Handle(BRep_CurveOnSurface) COS =
627 Handle(BRep_CurveOnSurface)::DownCast(CR);
628 COS->UVPoints(Pf,Pl);
630 OS << Pf.X() << " " << Pf.Y() << " " << Pl.X() << " " << Pl.Y() << "\n";
633 else if (CR->IsRegularity()) {
634 OS << "4 "; // -4- Regularity
635 PrintRegularity(CR->Continuity(),OS);
636 OS << " "<<mySurfaces.Index(CR->Surface());
637 OS << " "<<Locations().Index(CR->Location());
638 OS << " "<<mySurfaces.Index(CR->Surface2());
639 OS << " "<<Locations().Index(CR->Location2());
643 else if (myWithTriangles) { // for XML Persistence
644 if (CR->IsPolygon3D()) {
645 Handle(BRep_Polygon3D) GC = Handle(BRep_Polygon3D)::DownCast(itrc.Value());
646 if (!GC->Polygon3D().IsNull()) {
647 OS << "5 "; // -5- Polygon3D
648 OS << " "<<myPolygons3D.FindIndex(CR->Polygon3D());
649 OS << " "<<Locations().Index(CR->Location());
653 else if (CR->IsPolygonOnTriangulation()) {
654 Handle(BRep_PolygonOnTriangulation) PT =
655 Handle(BRep_PolygonOnTriangulation)::DownCast(itrc.Value());
656 if (!CR->IsPolygonOnClosedTriangulation())
657 OS << "6 "; // -6- Polygon on triangulation
659 OS << "7 "; // -7- Polygon on closed triangulation
660 OS << " " << myNodes.FindIndex(PT->PolygonOnTriangulation());
661 if (CR->IsPolygonOnClosedTriangulation()) {
662 OS << " " << myNodes.FindIndex(PT->PolygonOnTriangulation2());
664 OS << " " << myTriangulations.FindIndex(PT->Triangulation());
665 OS << " "<<Locations().Index(CR->Location());
672 OS << "0\n"; // end of the list of representations
675 else if (S.ShapeType() == TopAbs_FACE) {
677 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
678 const TopoDS_Face& F = TopoDS::Face(S);
680 if (!(TF->Surface()).IsNull()) {
681 OS << ((BRep_Tool::NaturalRestriction(F)) ? 1 : 0);
683 // Write the surface geometry
684 OS << " " <<TF->Tolerance();
685 OS << " " <<mySurfaces.Index(TF->Surface());
686 OS << " " <<Locations().Index(TF->Location());
689 else //For correct reading of null face
693 OS << " " <<TF->Tolerance();
698 if (myWithTriangles || TF->Surface().IsNull()) { // for XML Persistence
699 if (!(TF->Triangulation()).IsNull()) {
702 // Write the triangulation
703 OS << " " <<myTriangulations.FindIndex(TF->Triangulation());
710 //=======================================================================
711 //function : ReadRegularity
713 //=======================================================================
715 static GeomAbs_Shape ReadRegularity(Standard_IStream& IS)
756 //=======================================================================
757 //function : ReadGeometry
759 //=======================================================================
761 void BRepTools_ShapeSet::ReadGeometry (const TopAbs_ShapeEnum T,
762 Standard_IStream& IS,
767 Standard_Integer val,c,pc,pc2 = 0,s,s2,l,l2,t, pt, pt2 = 0;
768 Standard_Real tol,X,Y,Z,first,last,p1,p2;
769 Standard_Real PfX,PfY,PlX,PlY;
771 Standard_Boolean closed;
772 GeomAbs_Shape reg = GeomAbs_C0;
782 TopoDS_Vertex& V = TopoDS::Vertex(S);
784 // Read the point geometry
785 GeomTools::GetReal(IS, tol);
786 GeomTools::GetReal(IS, X);
787 GeomTools::GetReal(IS, Y);
788 GeomTools::GetReal(IS, Z);
789 myBuilder.MakeVertex(V,gp_Pnt(X,Y,Z),tol);
790 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(V.TShape());
792 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
796 GeomTools::GetReal(IS, p1);
799 Handle(BRep_PointRepresentation) PR;
806 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
807 if (myCurves.Curve(c).IsNull())
809 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
811 Handle(BRep_PointOnCurve) POC =
812 new BRep_PointOnCurve(p1,
823 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
824 if (myCurves2d.Curve2d(pc).IsNull() ||
825 mySurfaces.Surface(s).IsNull())
827 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
829 Handle(BRep_PointOnCurveOnSurface) POC =
830 new BRep_PointOnCurveOnSurface(p1,
831 myCurves2d.Curve2d(pc),
832 mySurfaces.Surface(s),
840 GeomTools::GetReal(IS, p2);
843 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
844 if (mySurfaces.Surface(s).IsNull())
846 // Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
848 Handle(BRep_PointOnSurface) POC =
849 new BRep_PointOnSurface(p1,p2,
850 mySurfaces.Surface(s),
860 PR->Location(Locations().Location(l));
878 TopoDS_Edge& E = TopoDS::Edge(S);
880 myBuilder.MakeEdge(E);
882 // Read the curve geometry
883 GeomTools::GetReal(IS, tol);
885 myBuilder.SameParameter(E,(val == 1));
887 myBuilder.SameRange(E,(val == 1));
889 myBuilder.Degenerated(E,(val == 1));
895 case 1 : // -1- Curve 3D
897 if (!myCurves.Curve(c).IsNull()) {
898 myBuilder.UpdateEdge(E,myCurves.Curve(c),
899 Locations().Location(l),tol);
901 GeomTools::GetReal(IS, first);
902 GeomTools::GetReal(IS, last);
903 if (!myCurves.Curve(c).IsNull()) {
904 Standard_Boolean Only3d = Standard_True;
905 myBuilder.Range(E,first,last,Only3d);
910 case 2 : // -2- Curve on surf
911 case 3 : // -3- Curve on closed surf
916 reg = ReadRegularity(IS);
923 GeomTools::GetReal(IS, first);
924 GeomTools::GetReal(IS, last);
926 // read UV Points // for XML Persistence higher performance
927 if (FormatNb() == TopTools_FormatVersion_VERSION_2)
929 GeomTools::GetReal(IS, PfX);
930 GeomTools::GetReal(IS, PfY);
931 GeomTools::GetReal(IS, PlX);
932 GeomTools::GetReal(IS, PlY);
933 aPf = gp_Pnt2d(PfX,PfY);
934 aPl = gp_Pnt2d(PlX,PlY);
937 // Modified by Sergey KHROMOV - Wed Apr 24 12:11:16 2002 Begin
938 if (myCurves2d.Curve2d(pc).IsNull() ||
939 (closed && myCurves2d.Curve2d(pc2).IsNull()) ||
940 mySurfaces.Surface(s).IsNull())
942 // Modified by Sergey KHROMOV - Wed Apr 24 12:11:17 2002 End
945 if (FormatNb() == TopTools_FormatVersion_VERSION_2)
946 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
947 myCurves2d.Curve2d(pc2),
948 mySurfaces.Surface(s),
949 Locations().Location(l),tol,
952 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
953 myCurves2d.Curve2d(pc2),
954 mySurfaces.Surface(s),
955 Locations().Location(l),tol);
957 myBuilder.Continuity(E,
958 mySurfaces.Surface(s),
959 mySurfaces.Surface(s),
960 Locations().Location(l),
961 Locations().Location(l),
966 if (FormatNb() == TopTools_FormatVersion_VERSION_2)
967 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
968 mySurfaces.Surface(s),
969 Locations().Location(l),tol,
972 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
973 mySurfaces.Surface(s),
974 Locations().Location(l),tol);
977 mySurfaces.Surface(s),
978 Locations().Location(l),
982 case 4 : // -4- Regularity
983 reg = ReadRegularity(IS);
984 IS >> s >> l >> s2 >> l2;
985 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:13 2002 Begin
986 if (mySurfaces.Surface(s).IsNull() ||
987 mySurfaces.Surface(s2).IsNull())
989 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:14 2002 End
990 myBuilder.Continuity(E,
991 mySurfaces.Surface(s),
992 mySurfaces.Surface(s2),
993 Locations().Location(l),
994 Locations().Location(l2),
998 case 5 : // -5- Polygon3D
1000 //szy-02.05.2004 myBuilder.UpdateEdge(E,Handle(Poly_Polygon3D)::DownCast(myPolygons3D(c)));
1001 if (c > 0 && c <= myPolygons3D.Extent())
1002 myBuilder.UpdateEdge(E,Handle(Poly_Polygon3D)::DownCast(myPolygons3D(c)), Locations().Location(l));
1007 closed = (val == 7);
1014 if (t > 0 && t <= myTriangulations.Extent() &&
1015 pt > 0 && pt <= myNodes.Extent() &&
1016 pt2 > 0 && pt2 <= myNodes.Extent())
1017 myBuilder.UpdateEdge
1018 (E, Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
1019 Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt2)),
1020 myTriangulations.FindKey(t),
1021 Locations().Location(l));
1024 if (t > 0 && t <= myTriangulations.Extent() &&
1025 pt > 0 && pt <= myNodes.Extent())
1026 myBuilder.UpdateEdge
1027 (E,Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
1028 myTriangulations.FindKey(t),
1029 Locations().Location(l));
1046 myBuilder.MakeWire(TopoDS::Wire(S));
1057 TopoDS_Face& F = TopoDS::Face(S);
1058 // std::streampos pos;
1059 myBuilder.MakeFace(F);
1061 IS >> val; // natural restriction
1062 if (val == 0 || val == 1) {
1063 GeomTools::GetReal(IS, tol);
1065 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:13 2002 Begin
1066 if (!mySurfaces.Surface(s).IsNull()) {
1067 // Modified by Sergey KHROMOV - Wed Apr 24 12:39:14 2002 End
1068 myBuilder.UpdateFace(TopoDS::Face(S),
1069 mySurfaces.Surface(s),
1070 Locations().Location(l),tol);
1071 myBuilder.NaturalRestriction(TopoDS::Face(S),(val == 1));
1073 // pos = IS.tellg();
1077 //only triangulation
1079 myBuilder.UpdateFace(TopoDS::Face(S),
1080 myTriangulations.FindKey(s));
1082 // else pos = IS.tellg();
1089 IS.getline ( string, 256, '\n' );
1090 IS.getline ( string, 256, '\n' );
1092 if (string[0] == '2') {
1093 // cas triangulation
1094 s = atoi ( &string[2] );
1095 if (s > 0 && s <= myTriangulations.Extent())
1096 myBuilder.UpdateFace(TopoDS::Face(S),
1097 myTriangulations.FindKey(s));
1099 // else IS.seekg(pos);
1109 myBuilder.MakeShell(TopoDS::Shell(S));
1118 myBuilder.MakeSolid(TopoDS::Solid(S));
1126 case TopAbs_COMPSOLID :
1127 myBuilder.MakeCompSolid(TopoDS::CompSolid(S));
1135 case TopAbs_COMPOUND :
1136 myBuilder.MakeCompound(TopoDS::Compound(S));
1147 //=======================================================================
1148 //function : AddShapes
1150 //=======================================================================
1152 void BRepTools_ShapeSet::AddShapes(TopoDS_Shape& S1,
1153 const TopoDS_Shape& S2)
1155 myBuilder.Add(S1,S2);
1158 //=======================================================================
1161 //=======================================================================
1163 void BRepTools_ShapeSet::Check(const TopAbs_ShapeEnum T,
1166 if (T == TopAbs_FACE) {
1167 const TopoDS_Face& F = TopoDS::Face(S);
1168 BRepTools::Update(F);
1174 //=======================================================================
1175 //function : WritePolygonOnTriangulation
1177 //=======================================================================
1179 void BRepTools_ShapeSet::WritePolygonOnTriangulation(Standard_OStream& OS,
1180 const Standard_Boolean Compact,
1181 const Message_ProgressRange& theProgress)const
1183 Standard_Integer i, j, nbpOntri = myNodes.Extent();
1185 Message_ProgressScope aPS(theProgress, "Polygons On Triangulation", nbpOntri);
1187 OS << "PolygonOnTriangulations " << nbpOntri << "\n";
1190 OS <<"Dump of " << nbpOntri << " PolygonOnTriangulations\n";
1194 Handle(Poly_PolygonOnTriangulation) Poly;
1195 Handle(TColStd_HArray1OfReal) Param;
1196 for (i=1; i<=nbpOntri && aPS.More(); i++, aPS.Next()) {
1197 Poly = Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(i));
1198 const TColStd_Array1OfInteger& Nodes = Poly->Nodes();
1200 OS << " "<< i << " : PolygonOnTriangulation with " << Nodes.Length() << " Nodes\n";
1202 else OS << Nodes.Length()<<" ";
1203 if (!Compact) OS <<" ";
1204 for (j=1; j <= Nodes.Length(); j++) OS << Nodes.Value(j) << " ";
1207 // writing parameters:
1208 Param = Poly->Parameters();
1209 if (Compact) OS <<"p ";
1211 // write the deflection
1212 if (!Compact) OS << " Deflection : ";
1213 OS <<Poly->Deflection() << " ";
1214 if (!Compact) OS << "\n";
1216 if (!Param.IsNull()) {
1218 OS << " Parameters :";
1221 if (!Compact) OS <<" ";
1222 for (j=1; j <= Param->Length(); j++) OS << Param->Value(j) << " ";
1229 //=======================================================================
1230 //function : DumpPolygonOnTriangulation
1232 //=======================================================================
1234 void BRepTools_ShapeSet::DumpPolygonOnTriangulation(Standard_OStream& OS)const
1236 WritePolygonOnTriangulation(OS, Standard_False);
1239 //=======================================================================
1240 //function : ReadPolygonOnTriangulation
1242 //=======================================================================
1244 void BRepTools_ShapeSet::ReadPolygonOnTriangulation(Standard_IStream& IS,
1245 const Message_ProgressRange& theProgress)
1249 if (strstr(buffer,"PolygonOnTriangulations") == NULL) return;
1250 Standard_Integer i, j, val, nbpol = 0, nbnodes =0;
1251 Standard_Integer hasparameters;
1253 Handle(TColStd_HArray1OfReal) Param;
1254 Handle(Poly_PolygonOnTriangulation) Poly;
1257 Message_ProgressScope aPS(theProgress, "Polygons On Triangulation", nbpol);
1258 for (i=1; i<=nbpol&& aPS.More(); i++, aPS.Next()) {
1260 TColStd_Array1OfInteger Nodes(1, nbnodes);
1261 for (j = 1; j <= nbnodes; j++) {
1266 // if (!strcasecmp(buffer, "p")) {
1268 GeomTools::GetReal(IS, def);
1269 IS >> hasparameters;
1270 if (hasparameters) {
1271 TColStd_Array1OfReal Param1(1, nbnodes);
1272 for (j = 1; j <= nbnodes; j++) {
1273 GeomTools::GetReal(IS, par);
1276 Poly = new Poly_PolygonOnTriangulation(Nodes, Param1);
1278 else Poly = new Poly_PolygonOnTriangulation(Nodes);
1279 Poly->Deflection(def);
1283 // Poly = new Poly_PolygonOnTriangulation(Nodes);
1288 // else IS.seekg(pos);
1293 //=======================================================================
1294 //function : WritePolygon3D
1296 //=======================================================================
1298 void BRepTools_ShapeSet::WritePolygon3D(Standard_OStream& OS,
1299 const Standard_Boolean Compact,
1300 const Message_ProgressRange& theProgress)const
1302 Standard_Integer i, j, nbpol = myPolygons3D.Extent();
1304 Message_ProgressScope aPS(theProgress, "3D Polygons", nbpol);
1307 OS << "Polygon3D " << nbpol << "\n";
1310 OS <<"Dump of " << nbpol << " Polygon3Ds\n";
1314 Handle(Poly_Polygon3D) P;
1315 for (i = 1; i <= nbpol && aPS.More(); i++, aPS.Next()) {
1316 P = Handle(Poly_Polygon3D)::DownCast(myPolygons3D(i));
1318 OS << P->NbNodes() << " ";
1319 OS << ((P->HasParameters()) ? "1" : "0") << "\n";
1322 OS << " "<< i << " : Polygon3D with " << P->NbNodes() << " Nodes\n";
1323 OS << ((P->HasParameters()) ? "with" : "without") << " parameters\n";
1327 // write the deflection
1328 if (!Compact) OS << "Deflection : ";
1329 OS << P->Deflection() << "\n";
1332 if (!Compact) OS << "\nNodes :\n";
1334 Standard_Integer i1, nbNodes = P->NbNodes();
1335 const TColgp_Array1OfPnt& Nodes = P->Nodes();
1336 for (j = 1; j <= nbNodes; j++) {
1337 if (!Compact) OS << std::setw(10) << j << " : ";
1338 if (!Compact) OS << std::setw(17);
1339 OS << Nodes(j).X() << " ";
1340 if (!Compact) OS << std::setw(17);
1341 OS << Nodes(j).Y() << " ";
1342 if (!Compact) OS << std::setw(17);
1344 if (!Compact) OS << "\n";
1349 if (P->HasParameters()) {
1350 if (!Compact) OS << "\nParameters :\n";
1351 const TColStd_Array1OfReal& Param = P->Parameters();
1352 for ( i1 = 1; i1 <= nbNodes; i1++ ) {
1353 OS << Param(i1) << " ";
1360 //=======================================================================
1361 //function : DumpPolygon3D
1363 //=======================================================================
1365 void BRepTools_ShapeSet::DumpPolygon3D(Standard_OStream& OS)const
1367 WritePolygon3D(OS, Standard_False);
1371 //=======================================================================
1372 //function : ReadPolygon3D
1374 //=======================================================================
1376 void BRepTools_ShapeSet::ReadPolygon3D(Standard_IStream& IS, const Message_ProgressRange& theProgress)
1379 // Standard_Integer i, j, p, val, nbpol, nbnodes, hasparameters;
1380 Standard_Integer i, j, p, nbpol=0, nbnodes =0, hasparameters = Standard_False;
1381 Standard_Real d, x, y, z;
1384 if (strstr(buffer,"Polygon3D") == NULL) return;
1385 Handle(Poly_Polygon3D) P;
1388 Message_ProgressScope aPS(theProgress, "3D Polygons", nbpol);
1389 for (i=1; i<=nbpol && aPS.More(); i++, aPS.Next()) {
1391 IS >> hasparameters;
1392 TColgp_Array1OfPnt Nodes(1, nbnodes);
1393 GeomTools::GetReal(IS, d);
1394 for (j = 1; j <= nbnodes; j++) {
1395 GeomTools::GetReal(IS, x);
1396 GeomTools::GetReal(IS, y);
1397 GeomTools::GetReal(IS, z);
1398 Nodes(j).SetCoord(x,y,z);
1400 if (hasparameters) {
1401 TColStd_Array1OfReal Param(1,nbnodes);
1402 for (p = 1; p <= nbnodes; p++) {
1403 GeomTools::GetReal(IS, Param(p));
1405 P = new Poly_Polygon3D(Nodes, Param);
1407 else P = new Poly_Polygon3D(Nodes);
1409 myPolygons3D.Add(P);
1415 //=======================================================================
1416 //function : WriteTriangulation
1418 //=======================================================================
1420 void BRepTools_ShapeSet::WriteTriangulation(Standard_OStream& OS,
1421 const Standard_Boolean Compact,
1422 const Message_ProgressRange& theProgress)const
1424 Standard_Integer i, j, nbNodes, nbtri = myTriangulations.Extent();
1425 Standard_Integer nbTriangles = 0, n1, n2, n3;
1427 Message_ProgressScope aPS(theProgress, "Triangulations", nbtri);
1430 OS << "Triangulations " << nbtri << "\n";
1433 OS <<"Dump of " << nbtri << " Triangulations\n";
1437 Handle(Poly_Triangulation) T;
1438 for (i = 1; i <= nbtri && aPS.More(); i++, aPS.Next()) {
1440 T = myTriangulations.FindKey(i);
1441 const Standard_Boolean toWriteNormals = myTriangulations(i);
1443 OS << T->NbNodes() << " " << T->NbTriangles() << " ";
1444 OS << ((T->HasUVNodes()) ? "1" : "0") << " ";
1445 if (FormatNb() >= TopTools_FormatVersion_VERSION_3)
1447 OS << ((T->HasNormals() && toWriteNormals) ? "1" : "0") << " ";
1451 OS << " "<< i << " : Triangulation with " << T->NbNodes() << " Nodes and "
1452 << T->NbTriangles() <<" Triangles\n";
1453 OS << " "<<((T->HasUVNodes()) ? "with" : "without") << " UV nodes\n";
1454 if (FormatNb() >= TopTools_FormatVersion_VERSION_3)
1456 OS << " " << ((T->HasNormals() && toWriteNormals) ? "with" : "without") << " normals\n";
1460 // write the deflection
1462 if (!Compact) OS << " Deflection : ";
1463 OS <<T->Deflection() << "\n";
1465 // write the 3d nodes
1467 if (!Compact) OS << "\n3D Nodes :\n";
1469 nbNodes = T->NbNodes();
1470 const TColgp_Array1OfPnt& Nodes = T->Nodes();
1471 for (j = 1; j <= nbNodes; j++) {
1472 if (!Compact) OS << std::setw(10) << j << " : ";
1473 if (!Compact) OS << std::setw(17);
1474 OS << Nodes(j).X() << " ";
1475 if (!Compact) OS << std::setw(17);
1476 OS << Nodes(j).Y() << " ";
1477 if (!Compact) OS << std::setw(17);
1479 if (!Compact) OS << "\n";
1483 if (T->HasUVNodes()) {
1484 if (!Compact) OS << "\nUV Nodes :\n";
1485 const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes();
1486 for (j = 1; j <= nbNodes; j++) {
1487 if (!Compact) OS << std::setw(10) << j << " : ";
1488 if (!Compact) OS << std::setw(17);
1489 OS << UVNodes(j).X() << " ";
1490 if (!Compact) OS << std::setw(17);
1491 OS << UVNodes(j).Y();
1492 if (!Compact) OS << "\n";
1497 if (!Compact) OS << "\nTriangles :\n";
1498 nbTriangles = T->NbTriangles();
1499 const Poly_Array1OfTriangle& Triangles = T->Triangles();
1500 for (j = 1; j <= nbTriangles; j++) {
1501 if (!Compact) OS << std::setw(10) << j << " : ";
1502 Triangles(j).Get(n1, n2, n3);
1503 if (!Compact) OS << std::setw(10);
1505 if (!Compact) OS << std::setw(10);
1507 if (!Compact) OS << std::setw(10);
1509 if (!Compact) OS << "\n";
1513 if (FormatNb() >= TopTools_FormatVersion_VERSION_3)
1515 if (T->HasNormals() && toWriteNormals)
1517 if (!Compact) OS << "\nNormals :\n";
1518 const TShort_Array1OfShortReal& Normals = T->Normals();
1519 for (j = 1; j <= nbNodes * 3; j++)
1523 OS << std::setw(10) << j << " : ";
1524 OS << std::setw(17);
1526 OS << Normals(j) << " ";
1542 //=======================================================================
1543 //function : DumpTriangulation
1545 //=======================================================================
1547 void BRepTools_ShapeSet::DumpTriangulation(Standard_OStream& OS)const
1549 WriteTriangulation(OS, Standard_False);
1553 //=======================================================================
1554 //function : ReadTriangulation
1556 //=======================================================================
1558 void BRepTools_ShapeSet::ReadTriangulation(Standard_IStream& IS, const Message_ProgressRange& theProgress)
1561 // Standard_Integer i, j, val, nbtri;
1562 Standard_Integer i, j, nbtri =0;
1563 Standard_Real d, x, y, z;
1564 Standard_Real normal;
1565 Standard_Integer nbNodes =0, nbTriangles=0;
1566 Standard_Boolean hasUV= Standard_False;
1567 Standard_Boolean hasNormals= Standard_False;
1569 Handle(Poly_Triangulation) T;
1572 if (strstr(buffer,"Triangulations") == NULL) return;
1576 Message_ProgressScope aPS(theProgress, "Triangulations", nbtri);
1577 for (i=1; i<=nbtri && aPS.More();i++, aPS.Next()) {
1579 IS >> nbNodes >> nbTriangles >> hasUV;
1580 if (FormatNb() >= TopTools_FormatVersion_VERSION_3)
1584 GeomTools::GetReal(IS, d);
1586 TColgp_Array1OfPnt Nodes(1, nbNodes);
1587 TColgp_Array1OfPnt2d UVNodes(1, nbNodes);
1588 Handle(TShort_HArray1OfShortReal) Normals;
1591 Normals = new TShort_HArray1OfShortReal(1, nbNodes * 3);
1593 for (j = 1; j <= nbNodes; j++) {
1594 GeomTools::GetReal(IS, x);
1595 GeomTools::GetReal(IS, y);
1596 GeomTools::GetReal(IS, z);
1597 Nodes(j).SetCoord(x,y,z);
1601 for (j = 1; j <= nbNodes; j++) {
1602 GeomTools::GetReal(IS, x);
1603 GeomTools::GetReal(IS, y);
1604 UVNodes(j).SetCoord(x,y);
1608 // read the triangles
1609 Standard_Integer n1,n2,n3;
1610 Poly_Array1OfTriangle Triangles(1, nbTriangles);
1611 for (j = 1; j <= nbTriangles; j++) {
1612 IS >> n1 >> n2 >> n3;
1613 Triangles(j).Set(n1,n2,n3);
1618 for (j = 1; j <= nbNodes * 3; j++)
1620 GeomTools::GetReal(IS, normal);
1621 Normals->SetValue(j, static_cast<Standard_ShortReal>(normal));
1625 if (hasUV) T = new Poly_Triangulation(Nodes,UVNodes,Triangles);
1626 else T = new Poly_Triangulation(Nodes,Triangles);
1631 T->SetNormals(Normals);
1633 myTriangulations.Add(T, hasNormals);