1 // Created on: 2004-05-11
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2004-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
22 #include <BinTools_ShapeSet.ixx>
23 #include <Standard_ErrorHandler.hxx>
24 #include <Precision.hxx>
25 #include <TColStd_HArray1OfReal.hxx>
26 #include <TColStd_HArray1OfInteger.hxx>
27 #include <TColgp_Array1OfPnt2d.hxx>
28 #include <gp_Trsf.hxx>
29 #include <Poly_PolygonOnTriangulation.hxx>
30 #include <Poly_Polygon3D.hxx>
31 #include <Poly_Triangulation.hxx>
32 #include <BRepTools.hxx>
33 #include <BRep_Tool.hxx>
34 #include <BRep_TVertex.hxx>
35 #include <BRep_TEdge.hxx>
36 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
37 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
38 #include <BRep_PointRepresentation.hxx>
39 #include <BRep_CurveRepresentation.hxx>
40 #include <BRep_CurveOnClosedSurface.hxx>
41 #include <BRep_Polygon3D.hxx>
42 #include <BRep_PolygonOnTriangulation.hxx>
43 #include <BRep_PointOnCurve.hxx>
44 #include <BRep_PointOnCurveOnSurface.hxx>
45 #include <BRep_PointOnSurface.hxx>
46 #include <BRep_GCurve.hxx>
47 #include <BRep_TFace.hxx>
49 #include <TopoDS_Iterator.hxx>
50 #include <TopoDS_Vertex.hxx>
51 #include <BinTools.hxx>
52 #include <BinTools_Curve2dSet.hxx>
53 #include <BinTools_CurveSet.hxx>
54 #include <BinTools_SurfaceSet.hxx>
57 const char* Version_1 = "Open CASCADE Topology V1 (c)";
58 const char* Version_2 = "Open CASCADE Topology V2 (c)";
59 const char* Version_3 = "Open CASCADE Topology V3 (c)";
60 //=======================================================================
61 //function : operator << (gp_Pnt)
63 //=======================================================================
65 static Standard_OStream& operator <<(Standard_OStream& OS, const gp_Pnt P)
67 BinTools::PutReal(OS, P.X());
68 BinTools::PutReal(OS, P.Y());
69 BinTools::PutReal(OS, P.Z());
72 //=======================================================================
73 //function : BinTools_ShapeSet
75 //=======================================================================
77 BinTools_ShapeSet::BinTools_ShapeSet(const Standard_Boolean isWithTriangles)
78 :myWithTriangles(isWithTriangles), myFormatNb(3)
81 //=======================================================================
84 //=======================================================================
86 void BinTools_ShapeSet::Delete()
89 //=======================================================================
90 //function : SetFormatNb
92 //=======================================================================
93 void BinTools_ShapeSet::SetFormatNb(const Standard_Integer theFormatNb)
95 myFormatNb = theFormatNb;
98 //=======================================================================
101 //=======================================================================
102 Standard_Integer BinTools_ShapeSet::FormatNb() const
107 //=======================================================================
110 //=======================================================================
112 void BinTools_ShapeSet::Clear()
117 myPolygons3D.Clear();
118 myPolygons2D.Clear();
120 myTriangulations.Clear();
124 //=======================================================================
127 //=======================================================================
129 Standard_Integer BinTools_ShapeSet::Add(const TopoDS_Shape& theShape)
131 if (theShape.IsNull()) return 0;
132 myLocations.Add(theShape.Location());
133 TopoDS_Shape aS2 = theShape;
134 aS2.Location(TopLoc_Location());
135 Standard_Integer anIndex = myShapes.FindIndex(aS2);
138 for (TopoDS_Iterator its(aS2,Standard_False,Standard_False);its.More(); its.Next())
140 anIndex = myShapes.Add(aS2);
146 //=======================================================================
149 //=======================================================================
151 const TopoDS_Shape& BinTools_ShapeSet::Shape(const Standard_Integer theIndx)const
153 return myShapes(theIndx);
156 //=======================================================================
159 //=======================================================================
161 Standard_Integer BinTools_ShapeSet::Index(const TopoDS_Shape& theShape) const
163 return myShapes.FindIndex(theShape);
166 //=======================================================================
167 //function : Locations
169 //=======================================================================
171 const BinTools_LocationSet& BinTools_ShapeSet::Locations()const
177 //=======================================================================
178 //function : ChangeLocations
180 //=======================================================================
182 BinTools_LocationSet& BinTools_ShapeSet::ChangeLocations()
187 //=======================================================================
188 //function : AddGeometry
190 //=======================================================================
192 void BinTools_ShapeSet::AddGeometry(const TopoDS_Shape& S)
196 if (S.ShapeType() == TopAbs_VERTEX) {
198 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
199 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
201 while (itrp.More()) {
202 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
204 if (PR->IsPointOnCurve()) {
205 myCurves.Add(PR->Curve());
208 else if (PR->IsPointOnCurveOnSurface()) {
209 myCurves2d.Add(PR->PCurve());
210 mySurfaces.Add(PR->Surface());
213 else if (PR->IsPointOnSurface()) {
214 mySurfaces.Add(PR->Surface());
217 ChangeLocations().Add(PR->Location());
222 else if (S.ShapeType() == TopAbs_EDGE) {
224 // Add the curve geometry
225 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
226 BRep_ListIteratorOfListOfCurveRepresentation itrc(TE->Curves());
228 while (itrc.More()) {
229 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
230 if (CR->IsCurve3D()) {
231 if (!CR->Curve3D().IsNull()) {
232 myCurves.Add(CR->Curve3D());
233 ChangeLocations().Add(CR->Location());
236 else if (CR->IsCurveOnSurface()) {
237 mySurfaces.Add(CR->Surface());
238 myCurves2d.Add(CR->PCurve());
239 ChangeLocations().Add(CR->Location());
240 if (CR->IsCurveOnClosedSurface())
241 myCurves2d.Add(CR->PCurve2());
243 else if (CR->IsRegularity()) {
244 mySurfaces.Add(CR->Surface());
245 ChangeLocations().Add(CR->Location());
246 mySurfaces.Add(CR->Surface2());
247 ChangeLocations().Add(CR->Location2());
249 else if (myWithTriangles) {
250 if (CR->IsPolygon3D()) {
251 if (!CR->Polygon3D().IsNull()) {
252 myPolygons3D.Add(CR->Polygon3D());
253 ChangeLocations().Add(CR->Location());
256 else if (CR->IsPolygonOnTriangulation()) {
257 myTriangulations.Add(CR->Triangulation());
258 myNodes.Add(CR->PolygonOnTriangulation());
259 ChangeLocations().Add(CR->Location());
260 if (CR->IsPolygonOnClosedTriangulation())
261 myNodes.Add(CR->PolygonOnTriangulation2());
263 else if (CR->IsPolygonOnSurface()) {
264 mySurfaces.Add(CR->Surface());
265 myPolygons2D.Add(CR->Polygon());
266 ChangeLocations().Add(CR->Location());
267 if (CR->IsPolygonOnClosedSurface())
268 myPolygons2D.Add(CR->Polygon2());
275 else if (S.ShapeType() == TopAbs_FACE) {
277 // Add the surface geometry
278 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
279 if (!TF->Surface().IsNull()) mySurfaces.Add(TF->Surface());
281 if (myWithTriangles) {
282 Handle(Poly_Triangulation) Tr = TF->Triangulation();
283 if (!Tr.IsNull()) myTriangulations.Add(Tr);
286 ChangeLocations().Add(TF->Location());
290 //=======================================================================
291 //function : WriteGeometry
293 //=======================================================================
295 void BinTools_ShapeSet::WriteGeometry(Standard_OStream& OS)const
297 myCurves2d.Write(OS);
300 WritePolygonOnTriangulation(OS);
301 mySurfaces.Write(OS);
302 WriteTriangulation(OS);
305 //=======================================================================
308 //=======================================================================
310 void BinTools_ShapeSet::Write(Standard_OStream& OS)const
313 // write the copyright
315 OS << "\n" << Version_3 << endl;
316 else if (myFormatNb == 2)
317 OS << "\n" << Version_2 << endl;
319 OS << "\n" << Version_1 << endl;
321 //-----------------------------------------
322 // write the locations
323 //-----------------------------------------
325 myLocations.Write(OS);
327 //-----------------------------------------
328 // write the geometry
329 //-----------------------------------------
333 //-----------------------------------------
335 //-----------------------------------------
337 Standard_Integer i, nbShapes = myShapes.Extent();
339 OS << "\nTShapes " << nbShapes << "\n";
341 // subshapes are written first
342 for (i = 1; i <= nbShapes; i++) {
344 const TopoDS_Shape& S = myShapes(i);
347 OS << (Standard_Byte)S.ShapeType();
353 BinTools::PutBool(OS, S.Free()? 1:0);
354 BinTools::PutBool(OS, S.Modified()? 1:0);
355 BinTools::PutBool(OS, S.Checked()? 1:0);
356 BinTools::PutBool(OS, S.Orientable()? 1:0);
357 BinTools::PutBool(OS, S.Closed()? 1:0);
358 BinTools::PutBool(OS, S.Infinite()? 1:0);
359 BinTools::PutBool(OS, S.Convex()? 1:0);
363 TopoDS_Iterator its(S,Standard_False,Standard_False);
365 Write(its.Value(),OS);
368 Write(TopoDS_Shape(),OS); // Null shape to end the list
373 //=======================================================================
376 //=======================================================================
378 void BinTools_ShapeSet::Read(Standard_IStream& IS)
386 IS.getline(vers,100,'\n');
387 // BUC60769 PTV 18.10.2000: remove possible '\r' at the end of the line
389 for (Standard_Integer lv = (strlen(vers)- 1); lv > 1 && (vers[lv] == '\r' || vers[lv] == '\n') ;lv--)
392 } while ( ! IS.fail() && strcmp(vers,Version_1) && strcmp(vers,Version_2) &&
393 strcmp(vers,Version_3));
395 cout << "BinTools_ShapeSet::Read: File was not written with this version of the topology"<<endl;
399 if (strcmp(vers,Version_3) == 0) SetFormatNb(3);
400 else if (strcmp(vers,Version_2) == 0) SetFormatNb(2);
403 //-----------------------------------------
404 // read the locations
405 //-----------------------------------------
407 myLocations.Read(IS);
408 //-----------------------------------------
410 //-----------------------------------------
414 //-----------------------------------------
416 //-----------------------------------------
420 if (IS.fail() || strcmp(buffer,"TShapes")) {
421 Standard_SStream aMsg;
422 aMsg << "BinTools_ShapeSet::Read: Not a TShape table"<<endl;
423 Standard_Failure::Raise(aMsg);
427 Standard_Integer i, nbShapes;
431 for (i = 1; i <= nbShapes; i++) {
435 //Read type and create empty shape.
437 TopAbs_ShapeEnum T = (TopAbs_ShapeEnum) IS.get();
439 ReadGeometry(T,IS,S);
442 Standard_Boolean aFree, aMod, aChecked, anOrient, aClosed, anInf, aConv;
443 BinTools::GetBool(IS, aFree);
444 BinTools::GetBool(IS, aMod);
445 BinTools::GetBool(IS, aChecked);
446 BinTools::GetBool(IS, anOrient);
447 BinTools::GetBool(IS, aClosed);
448 BinTools::GetBool(IS, anInf);
449 BinTools::GetBool(IS, aConv);
454 Read(SS,IS,nbShapes);
457 } while(!SS.IsNull());
464 S.Checked (Standard_False); // force check at reading..
465 S.Orientable(anOrient);
472 if(T == TopAbs_FACE) {
473 const TopoDS_Face& F = TopoDS::Face(S);
474 BRepTools::Update(F);
480 //=======================================================================
483 //=======================================================================
485 void BinTools_ShapeSet::Write(const TopoDS_Shape& S, Standard_OStream& OS)const
491 // {TopAbs_FORWARD, TopAbs_REVERSED, TopAbs_INTERNAL, TopAbs_EXTERNAL}
492 OS << (Standard_Byte) S.Orientation();
493 BinTools::PutInteger(OS, myShapes.Extent() - myShapes.FindIndex(S.Located(TopLoc_Location())) + 1);
494 BinTools::PutInteger(OS, Locations().Index(S.Location()));
498 //=======================================================================
501 //=======================================================================
503 void BinTools_ShapeSet::Read(TopoDS_Shape& S, Standard_IStream& IS,
504 const Standard_Integer nbshapes)const
506 Standard_Character aChar;
511 TopAbs_Orientation anOrient;
512 anOrient = (TopAbs_Orientation)aChar;
513 Standard_Integer anIndx;
514 BinTools::GetInteger(IS, anIndx);
515 S = myShapes(nbshapes - anIndx + 1);
516 S.Orientation(anOrient);
519 BinTools::GetInteger(IS, l);
520 S.Location(myLocations.Location(l));
524 //=======================================================================
525 //function : ReadGeometry
527 //=======================================================================
529 void BinTools_ShapeSet::ReadGeometry(Standard_IStream& IS)
534 ReadPolygonOnTriangulation(IS);
536 ReadTriangulation(IS);
539 //=======================================================================
540 //function : WriteGeometry
542 //=======================================================================
544 void BinTools_ShapeSet::WriteGeometry(const TopoDS_Shape& S,
545 Standard_OStream& OS)const
547 // Write the geometry
550 if (S.ShapeType() == TopAbs_VERTEX) {
552 // Write the point geometry
553 TopoDS_Vertex V = TopoDS::Vertex(S);
554 BinTools::PutReal(OS, BRep_Tool::Tolerance(V));
555 gp_Pnt p = BRep_Tool::Pnt(V);
558 Standard_Integer aPos;
560 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
561 BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
562 while (itrp.More()) {
563 const Handle(BRep_PointRepresentation)& PR = itrp.Value();
564 // BinTools::PutReal(OS, PR->Parameter());
565 if (PR->IsPointOnCurve()) {
569 OS << (Standard_Byte)1; // 1
570 BinTools::PutReal(OS, PR->Parameter());
571 BinTools::PutInteger(OS, myCurves.Index(PR->Curve()));
574 else if (PR->IsPointOnCurveOnSurface()) {
578 OS << (Standard_Byte)2;// 2
579 BinTools::PutReal(OS, PR->Parameter());
580 BinTools::PutInteger(OS, myCurves2d.Index(PR->PCurve()));
581 BinTools::PutInteger(OS, mySurfaces.Index(PR->Surface()));
584 else if (PR->IsPointOnSurface()) {
588 OS << (Standard_Byte)3;// 3
589 BinTools::PutReal(OS, PR->Parameter2());
590 BinTools::PutReal(OS, PR->Parameter());
591 BinTools::PutInteger(OS, mySurfaces.Index(PR->Surface()));
593 BinTools::PutInteger(OS, Locations().Index(PR->Location()));
597 // OS << "0 0\n"; // end representations
598 OS.put((Standard_Byte)0);
601 else if (S.ShapeType() == TopAbs_EDGE) {
603 // Write the curve geometry
605 Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
607 BinTools::PutReal(OS, TE->Tolerance());
609 Standard_Boolean aVal = (TE->SameParameter()) ? Standard_True : Standard_False;
610 BinTools::PutBool(OS, aVal);
611 aVal = (TE->SameRange()) ? Standard_True : Standard_False;
612 BinTools::PutBool(OS, aVal);
613 aVal = (TE->Degenerated()) ? Standard_True : Standard_False;
614 BinTools::PutBool(OS, aVal);
616 Standard_Real first, last;
617 BRep_ListIteratorOfListOfCurveRepresentation itrc = TE->Curves();
618 while (itrc.More()) {
619 const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
620 if (CR->IsCurve3D()) {
621 if (!CR->Curve3D().IsNull()) {
622 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
623 GC->Range(first, last);
624 OS << (Standard_Byte)1;//CURVE_3D;
625 BinTools::PutInteger(OS, myCurves.Index(CR->Curve3D()));
626 BinTools::PutInteger(OS, Locations().Index(CR->Location()));
627 BinTools::PutReal(OS, first);
628 BinTools::PutReal(OS, last);
631 else if (CR->IsCurveOnSurface()) {
632 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
633 GC->Range(first, last);
634 if (!CR->IsCurveOnClosedSurface())
636 OS << (Standard_Byte)2;
638 // -3- Curve on closed surf
639 OS << (Standard_Byte)3;
640 BinTools::PutInteger(OS, myCurves2d.Index(CR->PCurve()));
641 if (CR->IsCurveOnClosedSurface()) {//+ int|char
642 BinTools::PutInteger(OS, myCurves2d.Index(CR->PCurve2()));
643 OS << (Standard_Byte)CR->Continuity();
645 BinTools::PutInteger(OS, mySurfaces.Index(CR->Surface()));
646 BinTools::PutInteger(OS, Locations().Index(CR->Location()));
647 BinTools::PutReal(OS, first);
648 BinTools::PutReal(OS, last);
650 // Write UV Points for higher performance
654 if (CR->IsCurveOnClosedSurface()) {
655 Handle(BRep_CurveOnClosedSurface) COCS =
656 Handle(BRep_CurveOnClosedSurface)::DownCast(CR);
657 COCS->UVPoints2(Pf,Pl);
660 Handle(BRep_CurveOnSurface) COS =
661 Handle(BRep_CurveOnSurface)::DownCast(CR);
662 COS->UVPoints(Pf,Pl);
664 BinTools::PutReal(OS, Pf.X());
665 BinTools::PutReal(OS, Pf.Y());
666 BinTools::PutReal(OS, Pl.X());
667 BinTools::PutReal(OS, Pl.Y());
670 else if (CR->IsRegularity()) {
672 OS << (Standard_Byte)4;
673 OS << (Standard_Byte)CR->Continuity();
674 BinTools::PutInteger(OS, mySurfaces.Index(CR->Surface()));
675 BinTools::PutInteger(OS, Locations().Index(CR->Location()));
676 BinTools::PutInteger(OS, mySurfaces.Index(CR->Surface2()));
677 BinTools::PutInteger(OS, Locations().Index(CR->Location2()));
681 else if (myWithTriangles) {
682 if (CR->IsPolygon3D()) {
683 Handle(BRep_Polygon3D) GC = Handle(BRep_Polygon3D)::DownCast(itrc.Value());
684 if (!GC->Polygon3D().IsNull()) {
686 OS << (Standard_Byte)5;
687 BinTools::PutInteger(OS, myPolygons3D.FindIndex(CR->Polygon3D()));
688 BinTools::PutInteger(OS, Locations().Index(CR->Location()));
691 else if (CR->IsPolygonOnTriangulation()) {
692 Handle(BRep_PolygonOnTriangulation) PT =
693 Handle(BRep_PolygonOnTriangulation)::DownCast(itrc.Value());
694 if (!CR->IsPolygonOnClosedTriangulation())
695 // -6- Polygon on triangulation
696 OS << (Standard_Byte)6;
698 // -7- Polygon on closed triangulation
699 OS << (Standard_Byte)7;
700 BinTools::PutInteger(OS, myNodes.FindIndex(PT->PolygonOnTriangulation()));
702 if (CR->IsPolygonOnClosedTriangulation()) {
703 BinTools::PutInteger(OS, myNodes.FindIndex(PT->PolygonOnTriangulation2()));
705 BinTools::PutInteger(OS, myTriangulations.FindIndex(PT->Triangulation()));
706 BinTools::PutInteger(OS, Locations().Index(CR->Location()));
712 // OS << "0\n"; // end of the list of representations
714 OS << (Standard_Byte)0;
717 else if (S.ShapeType() == TopAbs_FACE) {
719 Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
720 const TopoDS_Face& F = TopoDS::Face(S);
722 if (!(TF->Surface()).IsNull()) {
723 Standard_Boolean aNatRes = (BRep_Tool::NaturalRestriction(F)) ? Standard_True : Standard_False;
724 BinTools::PutBool(OS, aNatRes);
726 // Write the surface geometry
727 BinTools::PutReal(OS, TF->Tolerance());
728 BinTools::PutInteger(OS, mySurfaces.Index(TF->Surface()));
729 BinTools::PutInteger(OS, Locations().Index(TF->Location()));
731 if (myWithTriangles) {
732 if (!(TF->Triangulation()).IsNull()) {
733 OS << (Standard_Byte) 2;
734 // Write the triangulation
735 BinTools::PutInteger(OS, myTriangulations.FindIndex(TF->Triangulation()));
737 OS << (Standard_Byte) 1;
739 OS << (Standard_Byte) 0;//without triangulation
742 catch(Standard_Failure) {
743 Standard_SStream aMsg;
744 aMsg << "EXCEPTION in BinTools_ShapeSet::WriteGeometry(S,OS)" << endl;
745 Handle(Standard_Failure) anExc = Standard_Failure::Caught();
746 aMsg << anExc << endl;
747 Standard_Failure::Raise(aMsg);
751 //=======================================================================
752 //function : ReadGeometry
754 //=======================================================================
756 void BinTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T,
757 Standard_IStream& IS,
762 Standard_Integer val, c,pc,pc2,s,s2,l,l2,t, pt, pt2;
763 Standard_Real tol,X,Y,Z,first,last,p1,p2;
764 Standard_Real PfX,PfY,PlX,PlY;
766 Standard_Boolean closed, bval;
767 Standard_SStream aMsg;
769 GeomAbs_Shape reg = GeomAbs_C0;
784 // Standard_Integer aPos = IS.tellg();
785 // cout << "\nPOS = " << aPos << endl;
786 TopoDS_Vertex& V = TopoDS::Vertex(S);
788 // Read the point geometry
789 BinTools::GetReal(IS, tol);
790 BinTools::GetReal(IS, X);
791 BinTools::GetReal(IS, Y);
792 BinTools::GetReal(IS, Z);
793 myBuilder.MakeVertex(V,gp_Pnt(X,Y,Z),tol);
794 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(V.TShape());
796 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
798 Standard_Boolean aNewF = (myFormatNb > 2) ? Standard_True : Standard_False;
800 gp_Pnt aPnt = gp_Pnt(X,Y,Z);
804 val = (Standard_Integer)IS.get();//case {0|1|2|3}
805 if (val > 0 && val <= 3)
806 BinTools::GetReal(IS, p1);
808 Standard_Integer aPos = IS.tellg();
809 BinTools::GetReal(IS, p1);
810 val = (Standard_Integer)IS.get();//case {0|1|2|3}
812 cout << "\nVal = " << val <<endl;
814 if(val != 1 && val !=2 && val !=3){
816 val = (Standard_Integer)IS.get();
817 if (val > 0 && val <= 3)
818 BinTools::GetReal(IS, p1);
821 Handle(BRep_PointRepresentation) PR;
828 BinTools::GetInteger(IS, c);
829 if (myCurves.Curve(c).IsNull())
831 Handle(BRep_PointOnCurve) POC =
832 new BRep_PointOnCurve(p1,
841 BinTools::GetInteger(IS, pc);
842 BinTools::GetInteger(IS, s);
843 if (myCurves2d.Curve2d(pc).IsNull() ||
844 mySurfaces.Surface(s).IsNull())
847 Handle(BRep_PointOnCurveOnSurface) POC =
848 new BRep_PointOnCurveOnSurface(p1,
849 myCurves2d.Curve2d(pc),
850 mySurfaces.Surface(s),
858 BinTools::GetReal(IS, p2);
859 BinTools::GetInteger(IS, s);
860 if (mySurfaces.Surface(s).IsNull())
863 Handle(BRep_PointOnSurface) POC =
864 new BRep_PointOnSurface(p1,p2,
865 mySurfaces.Surface(s),
873 aMsg << "BinTools_SurfaceSet::ReadGeometry: UnExpected BRep_PointRepresentation = "<< val <<endl;
874 Standard_Failure::Raise(aMsg);
879 BinTools::GetInteger(IS, l);//Locations index
882 PR->Location(Locations().Location(l));
900 TopoDS_Edge& E = TopoDS::Edge(S);
902 myBuilder.MakeEdge(E);
904 // Read the curve geometry
905 BinTools::GetReal(IS, tol);
906 BinTools::GetBool(IS, bval);
907 myBuilder.SameParameter(E, bval);
909 BinTools::GetBool(IS, bval);
910 myBuilder.SameRange(E,bval);
912 BinTools::GetBool(IS, bval);
913 myBuilder.Degenerated(E,bval);
916 val = (Standard_Integer)IS.get();//{0|1|2|3|4|5|6|7}
917 // -0- no representation
920 // -3- Curve on closed surf
923 // -6- Polygon on triangulation
924 // -7- Polygon on closed triangulation
930 case 1 : // -1- Curve 3D
931 BinTools::GetInteger(IS, c);
932 BinTools::GetInteger(IS, l);
933 if (!myCurves.Curve(c).IsNull()) {
934 myBuilder.UpdateEdge(E,myCurves.Curve(c),
935 Locations().Location(l),tol);
937 BinTools::GetReal(IS, first);
938 BinTools::GetReal(IS, last);
939 if (!myCurves.Curve(c).IsNull()) {
940 Standard_Boolean Only3d = Standard_True;
941 myBuilder.Range(E,first,last,Only3d);
946 case 2 : // -2- Curve on surf
947 case 3 : // -3- Curve on closed surf
949 BinTools::GetInteger(IS, pc);
951 BinTools::GetInteger(IS, pc2);
952 reg = (GeomAbs_Shape)IS.get();
956 BinTools::GetInteger(IS, s);
957 BinTools::GetInteger(IS, l);
960 BinTools::GetReal(IS, first);
961 BinTools::GetReal(IS, last);
963 // read UV Points // for XML Persistence higher performance
966 BinTools::GetReal(IS, PfX);
967 BinTools::GetReal(IS, PfY);
968 BinTools::GetReal(IS, PlX);
969 BinTools::GetReal(IS, PlY);
970 aPf = gp_Pnt2d(PfX,PfY);
971 aPl = gp_Pnt2d(PlX,PlY);
974 if (myCurves2d.Curve2d(pc).IsNull() ||
975 (closed && myCurves2d.Curve2d(pc2).IsNull()) ||
976 mySurfaces.Surface(s).IsNull())
981 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
982 myCurves2d.Curve2d(pc2),
983 mySurfaces.Surface(s),
984 Locations().Location(l),tol,
987 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
988 myCurves2d.Curve2d(pc2),
989 mySurfaces.Surface(s),
990 Locations().Location(l),tol);
992 myBuilder.Continuity(E,
993 mySurfaces.Surface(s),
994 mySurfaces.Surface(s),
995 Locations().Location(l),
996 Locations().Location(l),
1001 if (FormatNb() >= 2)
1002 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1003 mySurfaces.Surface(s),
1004 Locations().Location(l),tol,
1007 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1008 mySurfaces.Surface(s),
1009 Locations().Location(l),tol);
1012 mySurfaces.Surface(s),
1013 Locations().Location(l),
1017 case 4 : // -4- Regularity
1018 reg = (GeomAbs_Shape)IS.get();
1019 BinTools::GetInteger(IS, s);
1020 BinTools::GetInteger(IS, l);
1021 BinTools::GetInteger(IS, s2);
1022 BinTools::GetInteger(IS, l2);
1023 if (mySurfaces.Surface(s).IsNull() ||
1024 mySurfaces.Surface(s2).IsNull())
1026 myBuilder.Continuity(E,
1027 mySurfaces.Surface(s),
1028 mySurfaces.Surface(s2),
1029 Locations().Location(l),
1030 Locations().Location(l2),
1034 case 5 : // -5- Polygon3D
1035 BinTools::GetInteger(IS, c);
1036 BinTools::GetInteger(IS, l);
1037 //??? Bug? myBuilder.UpdateEdge(E,Handle(Poly_Polygon3D)::DownCast(myPolygons3D(c)));
1038 myBuilder.UpdateEdge(E,Handle(Poly_Polygon3D)::DownCast(myPolygons3D(c)), Locations().Location(l));
1041 case 6 : // -6- Polygon on triangulation
1042 case 7 : // -7- Polygon on closed triangulation
1043 closed = (val == 7);
1044 BinTools::GetInteger(IS, pt);
1046 BinTools::GetInteger(IS, pt2);
1048 BinTools::GetInteger(IS, t);
1049 BinTools::GetInteger(IS, l);
1051 myBuilder.UpdateEdge
1052 (E, Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
1053 Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt2)),
1054 Handle(Poly_Triangulation)::DownCast(myTriangulations(t)),
1055 Locations().Location(l));
1058 myBuilder.UpdateEdge
1059 (E,Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
1060 Handle(Poly_Triangulation)::DownCast(myTriangulations(t)),
1061 Locations().Location(l));
1067 aMsg <<"Unexpected Curve Representation ="<< val << endl;
1068 Standard_Failure::Raise(aMsg);
1082 myBuilder.MakeWire(TopoDS::Wire(S));
1093 TopoDS_Face& F = TopoDS::Face(S);
1094 myBuilder.MakeFace(F);
1095 BinTools::GetBool(IS, bval); //NaturalRestriction flag
1096 BinTools::GetReal(IS, tol);
1097 BinTools::GetInteger(IS, s); //surface indx
1098 BinTools::GetInteger(IS, l); //location indx
1099 if (!mySurfaces.Surface(s).IsNull()) {
1100 myBuilder.UpdateFace(TopoDS::Face(S),
1101 mySurfaces.Surface(s),
1102 Locations().Location(l),tol);
1103 myBuilder.NaturalRestriction(TopoDS::Face(S),bval );
1106 Standard_Byte aByte = (Standard_Byte)IS.get();
1107 // cas triangulation
1109 BinTools::GetInteger(IS, s);
1110 myBuilder.UpdateFace(TopoDS::Face(S),
1111 Handle(Poly_Triangulation)::DownCast(myTriangulations(s)));
1122 myBuilder.MakeShell(TopoDS::Shell(S));
1131 myBuilder.MakeSolid(TopoDS::Solid(S));
1139 case TopAbs_COMPSOLID :
1140 myBuilder.MakeCompSolid(TopoDS::CompSolid(S));
1148 case TopAbs_COMPOUND :
1149 myBuilder.MakeCompound(TopoDS::Compound(S));
1153 aMsg << "Unexpected topology type = "<< T <<endl;
1154 Standard_Failure::Raise(aMsg);
1158 catch(Standard_Failure) {
1159 aMsg << "EXCEPTION in BinTools_ShapeSet::ReadGeometry(S,OS)" << endl;
1160 Handle(Standard_Failure) anExc = Standard_Failure::Caught();
1161 aMsg << anExc << endl;
1162 Standard_Failure::Raise(aMsg);
1168 //=======================================================================
1169 //function : AddShapes
1171 //=======================================================================
1173 void BinTools_ShapeSet::AddShapes(TopoDS_Shape& S1,
1174 const TopoDS_Shape& S2)
1176 myBuilder.Add(S1,S2);
1180 //=======================================================================
1181 //function : WritePolygonOnTriangulation
1183 //=======================================================================
1185 void BinTools_ShapeSet::WritePolygonOnTriangulation(Standard_OStream& OS) const
1187 Standard_Integer i, j, nbpOntri = myNodes.Extent();
1189 OS << "PolygonOnTriangulations " << nbpOntri << endl;
1190 Handle(Poly_PolygonOnTriangulation) Poly;
1191 Handle(TColStd_HArray1OfReal) Param;
1194 for (i=1; i<=nbpOntri; i++) {
1195 Poly = Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(i));
1196 const TColStd_Array1OfInteger& Nodes = Poly->Nodes();
1197 BinTools::PutInteger(OS, Nodes.Length());
1198 for (j=1; j <= Nodes.Length(); j++)
1199 BinTools::PutInteger(OS, Nodes.Value(j));
1201 // writing parameters:
1202 Param = Poly->Parameters();
1204 // write the deflection
1205 BinTools::PutReal(OS, Poly->Deflection());
1206 if (!Param.IsNull()) {
1207 BinTools::PutBool(OS, Standard_True);
1208 for (j=1; j <= Param->Length(); j++)
1209 BinTools::PutReal(OS, Param->Value(j));
1212 BinTools::PutBool(OS, Standard_False);
1215 catch(Standard_Failure) {
1216 Standard_SStream aMsg;
1217 aMsg << "EXCEPTION in BinTools_ShapeSet::WritePolygonOnTriangulation(..)" << endl;
1218 Handle(Standard_Failure) anExc = Standard_Failure::Caught();
1219 aMsg << anExc << endl;
1220 Standard_Failure::Raise(aMsg);
1224 //=======================================================================
1225 //function : ReadPolygonOnTriangulation
1227 //=======================================================================
1229 void BinTools_ShapeSet::ReadPolygonOnTriangulation(Standard_IStream& IS)
1233 Standard_SStream aMsg;
1234 if (IS.fail() || (strstr(buffer,"PolygonOnTriangulations") == NULL)) {
1235 aMsg << "BinTools_ShapeSet::ReadPolygonOnTriangulation: Not a PolygonOnTriangulation section" <<endl;
1236 Standard_Failure::Raise(aMsg);
1238 Standard_Integer i, j, val, nbpol = 0, nbnodes =0;
1239 Standard_Boolean hasparameters;
1241 Handle(TColStd_HArray1OfReal) Param;
1242 Handle(Poly_PolygonOnTriangulation) Poly;
1244 IS.get();//remove LF
1246 // cout << "ReadPolygonOnTriangulation: NbPoles = "<< nbpol<< endl;
1250 for (i=1; i<=nbpol; i++) {
1252 // streampos pos = IS.tellg();
1253 // cout << "ReadPolygonOnTriangulation: Pos = "<< pos << endl;
1255 BinTools::GetInteger(IS, nbnodes);
1258 // cout << "ReadPolygonOnTriangulation: PoleIndx = "<< i << " NbOfNodes = "<< nbnodes <<endl;
1261 TColStd_Array1OfInteger Nodes(1, nbnodes);
1262 for (j = 1; j <= nbnodes; j++) {
1263 BinTools::GetInteger(IS, val);
1267 BinTools::GetReal(IS, def);
1268 BinTools::GetBool(IS, hasparameters);
1269 if (hasparameters) {
1270 TColStd_Array1OfReal Param1(1, nbnodes);
1271 for (j = 1; j <= nbnodes; j++) {
1272 BinTools::GetReal(IS, par);
1275 Poly = new Poly_PolygonOnTriangulation(Nodes, Param1);
1277 else Poly = new Poly_PolygonOnTriangulation(Nodes);
1278 Poly->Deflection(def);
1282 catch(Standard_Failure) {
1283 aMsg << "EXCEPTION in BinTools_ShapeSet::ReadPolygonOnTriangulation(..)" << endl;
1284 Handle(Standard_Failure) anExc = Standard_Failure::Caught();
1285 aMsg << anExc << endl;
1286 Standard_Failure::Raise(aMsg);
1292 //=======================================================================
1293 //function : WritePolygon3D
1295 //=======================================================================
1297 void BinTools_ShapeSet::WritePolygon3D(Standard_OStream& OS)const
1299 Standard_Integer i, j, nbpol = myPolygons3D.Extent();
1300 OS << "Polygon3D " << nbpol << endl;
1301 Handle(Poly_Polygon3D) P;
1304 for (i = 1; i <= nbpol; i++) {
1305 P = Handle(Poly_Polygon3D)::DownCast(myPolygons3D(i));
1306 BinTools::PutInteger(OS, P->NbNodes());
1307 BinTools::PutBool(OS, P->HasParameters()? 1:0);
1309 // write the deflection
1310 BinTools::PutReal(OS, P->Deflection());
1313 Standard_Integer i1, nbNodes = P->NbNodes();
1314 const TColgp_Array1OfPnt& Nodes = P->Nodes();
1315 for (j = 1; j <= nbNodes; j++) {
1316 BinTools::PutReal(OS, Nodes(j).X());
1317 BinTools::PutReal(OS, Nodes(j).Y());
1318 BinTools::PutReal(OS, Nodes(j).Z());
1320 if (P->HasParameters()) {
1321 const TColStd_Array1OfReal& Param = P->Parameters();
1322 for ( i1 = 1; i1 <= nbNodes; i1++ ) {
1323 BinTools::PutReal(OS, Param(i1));
1328 catch(Standard_Failure) {
1329 Standard_SStream aMsg;
1330 aMsg << "EXCEPTION in BinTools_ShapeSet::WritePolygon3D(..)" << endl;
1331 Handle(Standard_Failure) anExc = Standard_Failure::Caught();
1332 aMsg << anExc << endl;
1333 Standard_Failure::Raise(aMsg);
1336 //=======================================================================
1337 //function : ReadPolygon3D
1339 //=======================================================================
1341 void BinTools_ShapeSet::ReadPolygon3D(Standard_IStream& IS)
1344 Standard_Integer i, j, p, nbpol=0, nbnodes =0;
1345 Standard_Boolean hasparameters = Standard_False;
1346 Standard_Real d, x, y, z;
1348 Standard_SStream aMsg;
1350 if (IS.fail() || strstr(buffer,"Polygon3D") == NULL) {
1351 aMsg << "BinTools_ShapeSet::ReadPolygon3D: Not a Polygon3D section" <<endl;
1353 cout <<"Buffer: " << buffer << endl;
1355 Standard_Failure::Raise(aMsg);
1357 Handle(Poly_Polygon3D) P;
1359 IS.get();//remove LF
1363 for (i=1; i<=nbpol; i++) {
1364 BinTools::GetInteger(IS, nbnodes);
1365 BinTools::GetBool(IS, hasparameters);
1366 TColgp_Array1OfPnt Nodes(1, nbnodes);
1367 BinTools::GetReal(IS, d);
1368 for (j = 1; j <= nbnodes; j++) {
1369 BinTools::GetReal(IS, x);
1370 BinTools::GetReal(IS, y);
1371 BinTools::GetReal(IS, z);
1372 Nodes(j).SetCoord(x,y,z);
1374 if (hasparameters) {
1375 TColStd_Array1OfReal Param(1,nbnodes);
1376 for (p = 1; p <= nbnodes; p++)
1377 BinTools::GetReal(IS, Param(p));
1379 P = new Poly_Polygon3D(Nodes, Param);
1381 else P = new Poly_Polygon3D(Nodes);
1383 myPolygons3D.Add(P);
1386 catch(Standard_Failure) {
1387 aMsg << "EXCEPTION in BinTools_ShapeSet::ReadPolygon3D(..)" << endl;
1388 Handle(Standard_Failure) anExc = Standard_Failure::Caught();
1389 aMsg << anExc << endl;
1390 Standard_Failure::Raise(aMsg);
1395 //=======================================================================
1396 //function : WriteTriangulation
1398 //=======================================================================
1400 void BinTools_ShapeSet::WriteTriangulation(Standard_OStream& OS) const
1402 Standard_Integer i, j, nbNodes, nbtri = myTriangulations.Extent();
1403 Standard_Integer nbTriangles = 0, n1, n2, n3;
1404 OS << "Triangulations " << nbtri << endl;
1405 Handle(Poly_Triangulation) T;
1408 for (i = 1; i <= nbtri; i++) {
1409 T = Handle(Poly_Triangulation)::DownCast(myTriangulations(i));
1410 BinTools::PutInteger(OS, T->NbNodes());
1411 BinTools::PutInteger(OS, T->NbTriangles());
1412 BinTools::PutBool(OS, T->HasUVNodes()? 1:0);
1413 // write the deflection
1414 BinTools::PutReal(OS, T->Deflection());
1416 // write the 3d nodes
1417 nbNodes = T->NbNodes();
1418 const TColgp_Array1OfPnt& Nodes = T->Nodes();
1419 for (j = 1; j <= nbNodes; j++) {
1420 BinTools::PutReal(OS, Nodes(j).X());
1421 BinTools::PutReal(OS, Nodes(j).Y());
1422 BinTools::PutReal(OS, Nodes(j).Z());
1425 if (T->HasUVNodes()) {
1426 const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes();
1427 for (j = 1; j <= nbNodes; j++) {
1428 BinTools::PutReal(OS, UVNodes(j).X());
1429 BinTools::PutReal(OS, UVNodes(j).Y());
1432 nbTriangles = T->NbTriangles();
1433 const Poly_Array1OfTriangle& Triangles = T->Triangles();
1434 for (j = 1; j <= nbTriangles; j++) {
1435 Triangles(j).Get(n1, n2, n3);
1436 BinTools::PutInteger(OS, n1);
1437 BinTools::PutInteger(OS, n2);
1438 BinTools::PutInteger(OS, n3);
1442 catch(Standard_Failure) {
1443 Standard_SStream aMsg;
1444 aMsg << "EXCEPTION in BinTools_ShapeSet::WriteTriangulation(..)" << endl;
1445 Handle(Standard_Failure) anExc = Standard_Failure::Caught();
1446 aMsg << anExc << endl;
1447 Standard_Failure::Raise(aMsg);
1451 //=======================================================================
1452 //function : ReadTriangulation
1454 //=======================================================================
1456 void BinTools_ShapeSet::ReadTriangulation(Standard_IStream& IS)
1459 Standard_Integer i, j, nbtri =0;
1460 Standard_Real d, x, y, z;
1461 Standard_Integer nbNodes =0, nbTriangles=0;
1462 Standard_Boolean hasUV = Standard_False;
1464 Handle(Poly_Triangulation) T;
1467 Standard_SStream aMsg;
1468 if (IS.fail() || (strstr(buffer,"Triangulations") == NULL)) {
1469 aMsg << "BinTools_ShapeSet::Triangulation: Not a Triangulation section" <<endl;
1470 Standard_Failure::Raise(aMsg);
1473 IS.get();// remove LF
1477 for (i=1; i<=nbtri; i++) {
1478 BinTools::GetInteger(IS, nbNodes);
1479 BinTools::GetInteger(IS, nbTriangles);
1480 TColgp_Array1OfPnt Nodes(1, nbNodes);
1481 BinTools::GetBool(IS, hasUV);
1482 TColgp_Array1OfPnt2d UVNodes(1, nbNodes);
1483 BinTools::GetReal(IS, d); //deflection
1484 for (j = 1; j <= nbNodes; j++) {
1485 BinTools::GetReal(IS, x);
1486 BinTools::GetReal(IS, y);
1487 BinTools::GetReal(IS, z);
1488 Nodes(j).SetCoord(x,y,z);
1492 for (j = 1; j <= nbNodes; j++) {
1493 BinTools::GetReal(IS, x);
1494 BinTools::GetReal(IS, y);
1495 UVNodes(j).SetCoord(x,y);
1499 // read the triangles
1500 Standard_Integer n1,n2,n3;
1501 Poly_Array1OfTriangle Triangles(1, nbTriangles);
1502 for (j = 1; j <= nbTriangles; j++) {
1503 BinTools::GetInteger(IS, n1);
1504 BinTools::GetInteger(IS, n2);
1505 BinTools::GetInteger(IS, n3);
1506 Triangles(j).Set(n1,n2,n3);
1509 if (hasUV) T = new Poly_Triangulation(Nodes,UVNodes,Triangles);
1510 else T = new Poly_Triangulation(Nodes,Triangles);
1512 myTriangulations.Add(T);
1515 catch(Standard_Failure) {
1516 aMsg << "EXCEPTION in BinTools_ShapeSet::ReadTriangulation(..)" << endl;
1517 Handle(Standard_Failure) anExc = Standard_Failure::Caught();
1518 aMsg << anExc << endl;
1519 Standard_Failure::Raise(aMsg);
1523 //=======================================================================
1524 //function : NbShapes
1526 //=======================================================================
1528 Standard_Integer BinTools_ShapeSet::NbShapes() const
1530 return myShapes.Extent();