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 :myFormatNb(3), myWithTriangles(isWithTriangles)
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_Size 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 = 0,s,s2,l,l2,t, pt, pt2 = 0;
763 Standard_Real tol,X,Y,Z,first,last,p1 = 0.,p2;
764 Standard_Real PfX,PfY,PlX,PlY;
766 Standard_Boolean closed, bval;
767 Standard_SStream aMsg;
768 GeomAbs_Shape reg = GeomAbs_C0;
780 // Standard_Integer aPos = IS.tellg();
781 // cout << "\nPOS = " << aPos << endl;
782 TopoDS_Vertex& V = TopoDS::Vertex(S);
784 // Read the point geometry
785 BinTools::GetReal(IS, tol);
786 BinTools::GetReal(IS, X);
787 BinTools::GetReal(IS, Y);
788 BinTools::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();
794 Standard_Boolean aNewF = (myFormatNb > 2) ? Standard_True : Standard_False;
796 gp_Pnt aPnt = gp_Pnt(X,Y,Z);
800 val = (Standard_Integer)IS.get();//case {0|1|2|3}
801 if (val > 0 && val <= 3)
802 BinTools::GetReal(IS, p1);
804 streampos aPos = IS.tellg();
805 BinTools::GetReal(IS, p1);
806 val = (Standard_Integer)IS.get();//case {0|1|2|3}
808 cout << "\nVal = " << val <<endl;
810 if(val != 1 && val !=2 && val !=3){
812 val = (Standard_Integer)IS.get();
813 if (val > 0 && val <= 3)
814 BinTools::GetReal(IS, p1);
817 Handle(BRep_PointRepresentation) PR;
824 BinTools::GetInteger(IS, c);
825 if (myCurves.Curve(c).IsNull())
827 Handle(BRep_PointOnCurve) POC =
828 new BRep_PointOnCurve(p1,
837 BinTools::GetInteger(IS, pc);
838 BinTools::GetInteger(IS, s);
839 if (myCurves2d.Curve2d(pc).IsNull() ||
840 mySurfaces.Surface(s).IsNull())
843 Handle(BRep_PointOnCurveOnSurface) POC =
844 new BRep_PointOnCurveOnSurface(p1,
845 myCurves2d.Curve2d(pc),
846 mySurfaces.Surface(s),
854 BinTools::GetReal(IS, p2);
855 BinTools::GetInteger(IS, s);
856 if (mySurfaces.Surface(s).IsNull())
859 Handle(BRep_PointOnSurface) POC =
860 new BRep_PointOnSurface(p1,p2,
861 mySurfaces.Surface(s),
869 aMsg << "BinTools_SurfaceSet::ReadGeometry: UnExpected BRep_PointRepresentation = "<< val <<endl;
870 Standard_Failure::Raise(aMsg);
875 BinTools::GetInteger(IS, l);//Locations index
878 PR->Location(Locations().Location(l));
896 TopoDS_Edge& E = TopoDS::Edge(S);
898 myBuilder.MakeEdge(E);
900 // Read the curve geometry
901 BinTools::GetReal(IS, tol);
902 BinTools::GetBool(IS, bval);
903 myBuilder.SameParameter(E, bval);
905 BinTools::GetBool(IS, bval);
906 myBuilder.SameRange(E,bval);
908 BinTools::GetBool(IS, bval);
909 myBuilder.Degenerated(E,bval);
912 val = (Standard_Integer)IS.get();//{0|1|2|3|4|5|6|7}
913 // -0- no representation
916 // -3- Curve on closed surf
919 // -6- Polygon on triangulation
920 // -7- Polygon on closed triangulation
926 case 1 : // -1- Curve 3D
927 BinTools::GetInteger(IS, c);
928 BinTools::GetInteger(IS, l);
929 if (!myCurves.Curve(c).IsNull()) {
930 myBuilder.UpdateEdge(E,myCurves.Curve(c),
931 Locations().Location(l),tol);
933 BinTools::GetReal(IS, first);
934 BinTools::GetReal(IS, last);
935 if (!myCurves.Curve(c).IsNull()) {
936 Standard_Boolean Only3d = Standard_True;
937 myBuilder.Range(E,first,last,Only3d);
942 case 2 : // -2- Curve on surf
943 case 3 : // -3- Curve on closed surf
945 BinTools::GetInteger(IS, pc);
947 BinTools::GetInteger(IS, pc2);
948 reg = (GeomAbs_Shape)IS.get();
952 BinTools::GetInteger(IS, s);
953 BinTools::GetInteger(IS, l);
956 BinTools::GetReal(IS, first);
957 BinTools::GetReal(IS, last);
959 // read UV Points // for XML Persistence higher performance
962 BinTools::GetReal(IS, PfX);
963 BinTools::GetReal(IS, PfY);
964 BinTools::GetReal(IS, PlX);
965 BinTools::GetReal(IS, PlY);
966 aPf = gp_Pnt2d(PfX,PfY);
967 aPl = gp_Pnt2d(PlX,PlY);
970 if (myCurves2d.Curve2d(pc).IsNull() ||
971 (closed && myCurves2d.Curve2d(pc2).IsNull()) ||
972 mySurfaces.Surface(s).IsNull())
977 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
978 myCurves2d.Curve2d(pc2),
979 mySurfaces.Surface(s),
980 Locations().Location(l),tol,
983 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
984 myCurves2d.Curve2d(pc2),
985 mySurfaces.Surface(s),
986 Locations().Location(l),tol);
988 myBuilder.Continuity(E,
989 mySurfaces.Surface(s),
990 mySurfaces.Surface(s),
991 Locations().Location(l),
992 Locations().Location(l),
998 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
999 mySurfaces.Surface(s),
1000 Locations().Location(l),tol,
1003 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1004 mySurfaces.Surface(s),
1005 Locations().Location(l),tol);
1008 mySurfaces.Surface(s),
1009 Locations().Location(l),
1013 case 4 : // -4- Regularity
1014 reg = (GeomAbs_Shape)IS.get();
1015 BinTools::GetInteger(IS, s);
1016 BinTools::GetInteger(IS, l);
1017 BinTools::GetInteger(IS, s2);
1018 BinTools::GetInteger(IS, l2);
1019 if (mySurfaces.Surface(s).IsNull() ||
1020 mySurfaces.Surface(s2).IsNull())
1022 myBuilder.Continuity(E,
1023 mySurfaces.Surface(s),
1024 mySurfaces.Surface(s2),
1025 Locations().Location(l),
1026 Locations().Location(l2),
1030 case 5 : // -5- Polygon3D
1031 BinTools::GetInteger(IS, c);
1032 BinTools::GetInteger(IS, l);
1033 //??? Bug? myBuilder.UpdateEdge(E,Handle(Poly_Polygon3D)::DownCast(myPolygons3D(c)));
1034 myBuilder.UpdateEdge(E,Handle(Poly_Polygon3D)::DownCast(myPolygons3D(c)), Locations().Location(l));
1037 case 6 : // -6- Polygon on triangulation
1038 case 7 : // -7- Polygon on closed triangulation
1039 closed = (val == 7);
1040 BinTools::GetInteger(IS, pt);
1042 BinTools::GetInteger(IS, pt2);
1044 BinTools::GetInteger(IS, t);
1045 BinTools::GetInteger(IS, l);
1047 myBuilder.UpdateEdge
1048 (E, Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
1049 Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt2)),
1050 Handle(Poly_Triangulation)::DownCast(myTriangulations(t)),
1051 Locations().Location(l));
1054 myBuilder.UpdateEdge
1055 (E,Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
1056 Handle(Poly_Triangulation)::DownCast(myTriangulations(t)),
1057 Locations().Location(l));
1063 aMsg <<"Unexpected Curve Representation ="<< val << endl;
1064 Standard_Failure::Raise(aMsg);
1078 myBuilder.MakeWire(TopoDS::Wire(S));
1089 TopoDS_Face& F = TopoDS::Face(S);
1090 myBuilder.MakeFace(F);
1091 BinTools::GetBool(IS, bval); //NaturalRestriction flag
1092 BinTools::GetReal(IS, tol);
1093 BinTools::GetInteger(IS, s); //surface indx
1094 BinTools::GetInteger(IS, l); //location indx
1095 if (!mySurfaces.Surface(s).IsNull()) {
1096 myBuilder.UpdateFace(TopoDS::Face(S),
1097 mySurfaces.Surface(s),
1098 Locations().Location(l),tol);
1099 myBuilder.NaturalRestriction(TopoDS::Face(S),bval );
1102 Standard_Byte aByte = (Standard_Byte)IS.get();
1103 // cas triangulation
1105 BinTools::GetInteger(IS, s);
1106 myBuilder.UpdateFace(TopoDS::Face(S),
1107 Handle(Poly_Triangulation)::DownCast(myTriangulations(s)));
1118 myBuilder.MakeShell(TopoDS::Shell(S));
1127 myBuilder.MakeSolid(TopoDS::Solid(S));
1135 case TopAbs_COMPSOLID :
1136 myBuilder.MakeCompSolid(TopoDS::CompSolid(S));
1144 case TopAbs_COMPOUND :
1145 myBuilder.MakeCompound(TopoDS::Compound(S));
1149 aMsg << "Unexpected topology type = "<< T <<endl;
1150 Standard_Failure::Raise(aMsg);
1154 catch(Standard_Failure) {
1155 aMsg << "EXCEPTION in BinTools_ShapeSet::ReadGeometry(S,OS)" << endl;
1156 Handle(Standard_Failure) anExc = Standard_Failure::Caught();
1157 aMsg << anExc << endl;
1158 Standard_Failure::Raise(aMsg);
1164 //=======================================================================
1165 //function : AddShapes
1167 //=======================================================================
1169 void BinTools_ShapeSet::AddShapes(TopoDS_Shape& S1,
1170 const TopoDS_Shape& S2)
1172 myBuilder.Add(S1,S2);
1176 //=======================================================================
1177 //function : WritePolygonOnTriangulation
1179 //=======================================================================
1181 void BinTools_ShapeSet::WritePolygonOnTriangulation(Standard_OStream& OS) const
1183 Standard_Integer i, j, nbpOntri = myNodes.Extent();
1185 OS << "PolygonOnTriangulations " << nbpOntri << endl;
1186 Handle(Poly_PolygonOnTriangulation) Poly;
1187 Handle(TColStd_HArray1OfReal) Param;
1190 for (i=1; i<=nbpOntri; i++) {
1191 Poly = Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(i));
1192 const TColStd_Array1OfInteger& Nodes = Poly->Nodes();
1193 BinTools::PutInteger(OS, Nodes.Length());
1194 for (j=1; j <= Nodes.Length(); j++)
1195 BinTools::PutInteger(OS, Nodes.Value(j));
1197 // writing parameters:
1198 Param = Poly->Parameters();
1200 // write the deflection
1201 BinTools::PutReal(OS, Poly->Deflection());
1202 if (!Param.IsNull()) {
1203 BinTools::PutBool(OS, Standard_True);
1204 for (j=1; j <= Param->Length(); j++)
1205 BinTools::PutReal(OS, Param->Value(j));
1208 BinTools::PutBool(OS, Standard_False);
1211 catch(Standard_Failure) {
1212 Standard_SStream aMsg;
1213 aMsg << "EXCEPTION in BinTools_ShapeSet::WritePolygonOnTriangulation(..)" << endl;
1214 Handle(Standard_Failure) anExc = Standard_Failure::Caught();
1215 aMsg << anExc << endl;
1216 Standard_Failure::Raise(aMsg);
1220 //=======================================================================
1221 //function : ReadPolygonOnTriangulation
1223 //=======================================================================
1225 void BinTools_ShapeSet::ReadPolygonOnTriangulation(Standard_IStream& IS)
1229 Standard_SStream aMsg;
1230 if (IS.fail() || (strstr(buffer,"PolygonOnTriangulations") == NULL)) {
1231 aMsg << "BinTools_ShapeSet::ReadPolygonOnTriangulation: Not a PolygonOnTriangulation section" <<endl;
1232 Standard_Failure::Raise(aMsg);
1234 Standard_Integer i, j, val, nbpol = 0, nbnodes =0;
1235 Standard_Boolean hasparameters;
1237 Handle(TColStd_HArray1OfReal) Param;
1238 Handle(Poly_PolygonOnTriangulation) Poly;
1240 IS.get();//remove LF
1242 // cout << "ReadPolygonOnTriangulation: NbPoles = "<< nbpol<< endl;
1246 for (i=1; i<=nbpol; i++) {
1248 // streampos pos = IS.tellg();
1249 // cout << "ReadPolygonOnTriangulation: Pos = "<< pos << endl;
1251 BinTools::GetInteger(IS, nbnodes);
1254 // cout << "ReadPolygonOnTriangulation: PoleIndx = "<< i << " NbOfNodes = "<< nbnodes <<endl;
1257 TColStd_Array1OfInteger Nodes(1, nbnodes);
1258 for (j = 1; j <= nbnodes; j++) {
1259 BinTools::GetInteger(IS, val);
1263 BinTools::GetReal(IS, def);
1264 BinTools::GetBool(IS, hasparameters);
1265 if (hasparameters) {
1266 TColStd_Array1OfReal Param1(1, nbnodes);
1267 for (j = 1; j <= nbnodes; j++) {
1268 BinTools::GetReal(IS, par);
1271 Poly = new Poly_PolygonOnTriangulation(Nodes, Param1);
1273 else Poly = new Poly_PolygonOnTriangulation(Nodes);
1274 Poly->Deflection(def);
1278 catch(Standard_Failure) {
1279 aMsg << "EXCEPTION in BinTools_ShapeSet::ReadPolygonOnTriangulation(..)" << endl;
1280 Handle(Standard_Failure) anExc = Standard_Failure::Caught();
1281 aMsg << anExc << endl;
1282 Standard_Failure::Raise(aMsg);
1288 //=======================================================================
1289 //function : WritePolygon3D
1291 //=======================================================================
1293 void BinTools_ShapeSet::WritePolygon3D(Standard_OStream& OS)const
1295 Standard_Integer i, j, nbpol = myPolygons3D.Extent();
1296 OS << "Polygon3D " << nbpol << endl;
1297 Handle(Poly_Polygon3D) P;
1300 for (i = 1; i <= nbpol; i++) {
1301 P = Handle(Poly_Polygon3D)::DownCast(myPolygons3D(i));
1302 BinTools::PutInteger(OS, P->NbNodes());
1303 BinTools::PutBool(OS, P->HasParameters()? 1:0);
1305 // write the deflection
1306 BinTools::PutReal(OS, P->Deflection());
1309 Standard_Integer i1, nbNodes = P->NbNodes();
1310 const TColgp_Array1OfPnt& Nodes = P->Nodes();
1311 for (j = 1; j <= nbNodes; j++) {
1312 BinTools::PutReal(OS, Nodes(j).X());
1313 BinTools::PutReal(OS, Nodes(j).Y());
1314 BinTools::PutReal(OS, Nodes(j).Z());
1316 if (P->HasParameters()) {
1317 const TColStd_Array1OfReal& Param = P->Parameters();
1318 for ( i1 = 1; i1 <= nbNodes; i1++ ) {
1319 BinTools::PutReal(OS, Param(i1));
1324 catch(Standard_Failure) {
1325 Standard_SStream aMsg;
1326 aMsg << "EXCEPTION in BinTools_ShapeSet::WritePolygon3D(..)" << endl;
1327 Handle(Standard_Failure) anExc = Standard_Failure::Caught();
1328 aMsg << anExc << endl;
1329 Standard_Failure::Raise(aMsg);
1332 //=======================================================================
1333 //function : ReadPolygon3D
1335 //=======================================================================
1337 void BinTools_ShapeSet::ReadPolygon3D(Standard_IStream& IS)
1340 Standard_Integer i, j, p, nbpol=0, nbnodes =0;
1341 Standard_Boolean hasparameters = Standard_False;
1342 Standard_Real d, x, y, z;
1344 Standard_SStream aMsg;
1346 if (IS.fail() || strstr(buffer,"Polygon3D") == NULL) {
1347 aMsg << "BinTools_ShapeSet::ReadPolygon3D: Not a Polygon3D section" <<endl;
1349 cout <<"Buffer: " << buffer << endl;
1351 Standard_Failure::Raise(aMsg);
1353 Handle(Poly_Polygon3D) P;
1355 IS.get();//remove LF
1359 for (i=1; i<=nbpol; i++) {
1360 BinTools::GetInteger(IS, nbnodes);
1361 BinTools::GetBool(IS, hasparameters);
1362 TColgp_Array1OfPnt Nodes(1, nbnodes);
1363 BinTools::GetReal(IS, d);
1364 for (j = 1; j <= nbnodes; j++) {
1365 BinTools::GetReal(IS, x);
1366 BinTools::GetReal(IS, y);
1367 BinTools::GetReal(IS, z);
1368 Nodes(j).SetCoord(x,y,z);
1370 if (hasparameters) {
1371 TColStd_Array1OfReal Param(1,nbnodes);
1372 for (p = 1; p <= nbnodes; p++)
1373 BinTools::GetReal(IS, Param(p));
1375 P = new Poly_Polygon3D(Nodes, Param);
1377 else P = new Poly_Polygon3D(Nodes);
1379 myPolygons3D.Add(P);
1382 catch(Standard_Failure) {
1383 aMsg << "EXCEPTION in BinTools_ShapeSet::ReadPolygon3D(..)" << endl;
1384 Handle(Standard_Failure) anExc = Standard_Failure::Caught();
1385 aMsg << anExc << endl;
1386 Standard_Failure::Raise(aMsg);
1391 //=======================================================================
1392 //function : WriteTriangulation
1394 //=======================================================================
1396 void BinTools_ShapeSet::WriteTriangulation(Standard_OStream& OS) const
1398 Standard_Integer i, j, nbNodes, nbtri = myTriangulations.Extent();
1399 Standard_Integer nbTriangles = 0, n1, n2, n3;
1400 OS << "Triangulations " << nbtri << endl;
1401 Handle(Poly_Triangulation) T;
1404 for (i = 1; i <= nbtri; i++) {
1405 T = Handle(Poly_Triangulation)::DownCast(myTriangulations(i));
1406 BinTools::PutInteger(OS, T->NbNodes());
1407 BinTools::PutInteger(OS, T->NbTriangles());
1408 BinTools::PutBool(OS, T->HasUVNodes()? 1:0);
1409 // write the deflection
1410 BinTools::PutReal(OS, T->Deflection());
1412 // write the 3d nodes
1413 nbNodes = T->NbNodes();
1414 const TColgp_Array1OfPnt& Nodes = T->Nodes();
1415 for (j = 1; j <= nbNodes; j++) {
1416 BinTools::PutReal(OS, Nodes(j).X());
1417 BinTools::PutReal(OS, Nodes(j).Y());
1418 BinTools::PutReal(OS, Nodes(j).Z());
1421 if (T->HasUVNodes()) {
1422 const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes();
1423 for (j = 1; j <= nbNodes; j++) {
1424 BinTools::PutReal(OS, UVNodes(j).X());
1425 BinTools::PutReal(OS, UVNodes(j).Y());
1428 nbTriangles = T->NbTriangles();
1429 const Poly_Array1OfTriangle& Triangles = T->Triangles();
1430 for (j = 1; j <= nbTriangles; j++) {
1431 Triangles(j).Get(n1, n2, n3);
1432 BinTools::PutInteger(OS, n1);
1433 BinTools::PutInteger(OS, n2);
1434 BinTools::PutInteger(OS, n3);
1438 catch(Standard_Failure) {
1439 Standard_SStream aMsg;
1440 aMsg << "EXCEPTION in BinTools_ShapeSet::WriteTriangulation(..)" << endl;
1441 Handle(Standard_Failure) anExc = Standard_Failure::Caught();
1442 aMsg << anExc << endl;
1443 Standard_Failure::Raise(aMsg);
1447 //=======================================================================
1448 //function : ReadTriangulation
1450 //=======================================================================
1452 void BinTools_ShapeSet::ReadTriangulation(Standard_IStream& IS)
1455 Standard_Integer i, j, nbtri =0;
1456 Standard_Real d, x, y, z;
1457 Standard_Integer nbNodes =0, nbTriangles=0;
1458 Standard_Boolean hasUV = Standard_False;
1460 Handle(Poly_Triangulation) T;
1463 Standard_SStream aMsg;
1464 if (IS.fail() || (strstr(buffer,"Triangulations") == NULL)) {
1465 aMsg << "BinTools_ShapeSet::Triangulation: Not a Triangulation section" <<endl;
1466 Standard_Failure::Raise(aMsg);
1469 IS.get();// remove LF
1473 for (i=1; i<=nbtri; i++) {
1474 BinTools::GetInteger(IS, nbNodes);
1475 BinTools::GetInteger(IS, nbTriangles);
1476 TColgp_Array1OfPnt Nodes(1, nbNodes);
1477 BinTools::GetBool(IS, hasUV);
1478 TColgp_Array1OfPnt2d UVNodes(1, nbNodes);
1479 BinTools::GetReal(IS, d); //deflection
1480 for (j = 1; j <= nbNodes; j++) {
1481 BinTools::GetReal(IS, x);
1482 BinTools::GetReal(IS, y);
1483 BinTools::GetReal(IS, z);
1484 Nodes(j).SetCoord(x,y,z);
1488 for (j = 1; j <= nbNodes; j++) {
1489 BinTools::GetReal(IS, x);
1490 BinTools::GetReal(IS, y);
1491 UVNodes(j).SetCoord(x,y);
1495 // read the triangles
1496 Standard_Integer n1,n2,n3;
1497 Poly_Array1OfTriangle Triangles(1, nbTriangles);
1498 for (j = 1; j <= nbTriangles; j++) {
1499 BinTools::GetInteger(IS, n1);
1500 BinTools::GetInteger(IS, n2);
1501 BinTools::GetInteger(IS, n3);
1502 Triangles(j).Set(n1,n2,n3);
1505 if (hasUV) T = new Poly_Triangulation(Nodes,UVNodes,Triangles);
1506 else T = new Poly_Triangulation(Nodes,Triangles);
1508 myTriangulations.Add(T);
1511 catch(Standard_Failure) {
1512 aMsg << "EXCEPTION in BinTools_ShapeSet::ReadTriangulation(..)" << endl;
1513 Handle(Standard_Failure) anExc = Standard_Failure::Caught();
1514 aMsg << anExc << endl;
1515 Standard_Failure::Raise(aMsg);
1519 //=======================================================================
1520 //function : NbShapes
1522 //=======================================================================
1524 Standard_Integer BinTools_ShapeSet::NbShapes() const
1526 return myShapes.Extent();