// Created on: 2004-05-20 // Created by: Sergey ZARITCHNY // Copyright (c) 2004-2014 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // // This library is free software; you can redistribute it and/or modify it under // the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. // // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define PLANE 1 #define CYLINDER 2 #define CONE 3 #define SPHERE 4 #define TORUS 5 #define LINEAREXTRUSION 6 #define REVOLUTION 7 #define BEZIER 8 #define BSPLINE 9 #define RECTANGULAR 10 #define OFFSET 11 //================================================================================================= BinTools_SurfaceSet::BinTools_SurfaceSet() {} //================================================================================================= void BinTools_SurfaceSet::Clear() { myMap.Clear(); } //================================================================================================= Standard_Integer BinTools_SurfaceSet::Add(const Handle(Geom_Surface)& S) { return myMap.Add(S); } //================================================================================================= Handle(Geom_Surface) BinTools_SurfaceSet::Surface(const Standard_Integer I) const { return Handle(Geom_Surface)::DownCast(myMap(I)); } //================================================================================================= Standard_Integer BinTools_SurfaceSet::Index(const Handle(Geom_Surface)& S) const { return myMap.FindIndex(S); } //======================================================================= // function : operator <<(Geom_Plane) // purpose : //======================================================================= static BinTools_OStream& operator<<(BinTools_OStream& OS, const Handle(Geom_Plane)& S) { OS << (Standard_Byte)PLANE; gp_Pln P = S->Pln(); OS << P.Location(); // Pnt OS << P.Axis().Direction(); OS << P.XAxis().Direction(); OS << P.YAxis().Direction(); return OS; } //======================================================================= // function : operator <<(Geom_CylindricalSurface) // purpose : //======================================================================= static BinTools_OStream& operator<<(BinTools_OStream& OS, const Handle(Geom_CylindricalSurface)& S) { OS << (Standard_Byte)CYLINDER; gp_Cylinder P = S->Cylinder(); OS << P.Location(); // Pnt OS << P.Axis().Direction(); OS << P.XAxis().Direction(); OS << P.YAxis().Direction(); OS << P.Radius(); return OS; } //======================================================================= // function : operator <<(Geom_ConicalSurface) // purpose : //======================================================================= static BinTools_OStream& operator<<(BinTools_OStream& OS, const Handle(Geom_ConicalSurface)& S) { OS << (Standard_Byte)CONE; gp_Cone P = S->Cone(); OS << P.Location(); // Pnt OS << P.Axis().Direction(); OS << P.XAxis().Direction(); OS << P.YAxis().Direction(); OS << P.RefRadius(); OS << P.SemiAngle(); return OS; } //======================================================================= // function : operator <<(Geom_SphericalSurface) // purpose : //======================================================================= static BinTools_OStream& operator<<(BinTools_OStream& OS, const Handle(Geom_SphericalSurface)& S) { OS << (Standard_Byte)SPHERE; gp_Sphere P = S->Sphere(); OS << P.Location(); // Pnt OS << P.Position().Axis().Direction(); OS << P.XAxis().Direction(); OS << P.YAxis().Direction(); OS << P.Radius(); return OS; } //======================================================================= // function : operator <<(Geom_ToroidalSurface) // purpose : //======================================================================= static BinTools_OStream& operator<<(BinTools_OStream& OS, const Handle(Geom_ToroidalSurface)& S) { OS << (Standard_Byte)TORUS; gp_Torus P = S->Torus(); OS << P.Location(); // Pnt OS << P.Axis().Direction(); OS << P.XAxis().Direction(); OS << P.YAxis().Direction(); OS << P.MajorRadius(); OS << P.MinorRadius(); return OS; } //======================================================================= // function : operator <<(Geom_SurfaceOfLinearExtrusion) // purpose : //======================================================================= static BinTools_OStream& operator<<(BinTools_OStream& OS, const Handle(Geom_SurfaceOfLinearExtrusion)& S) { OS << (Standard_Byte)LINEAREXTRUSION; OS << S->Direction(); BinTools_CurveSet::WriteCurve(S->BasisCurve(), OS); return OS; } //======================================================================= // function : operator <<(Geom_SurfaceOfRevolution) // purpose : //======================================================================= static BinTools_OStream& operator<<(BinTools_OStream& OS, const Handle(Geom_SurfaceOfRevolution)& S) { OS << (Standard_Byte)REVOLUTION; OS << S->Location(); OS << S->Direction(); BinTools_CurveSet::WriteCurve(S->BasisCurve(), OS); return OS; } //======================================================================= // function : operator <<(Geom_BezierSurface) // purpose : //======================================================================= static BinTools_OStream& operator<<(BinTools_OStream& OS, const Handle(Geom_BezierSurface)& S) { OS << (Standard_Byte)BEZIER; Standard_Boolean urational = S->IsURational() ? 1 : 0; Standard_Boolean vrational = S->IsVRational() ? 1 : 0; OS << urational; // rational OS << vrational; // poles and weights Standard_Integer i, j, udegree, vdegree; udegree = S->UDegree(); vdegree = S->VDegree(); OS << (Standard_ExtCharacter)udegree; OS << (Standard_ExtCharacter)vdegree; for (i = 1; i <= udegree + 1; i++) { for (j = 1; j <= vdegree + 1; j++) { OS << S->Pole(i, j); // Pnt if (urational || vrational) { OS << S->Weight(i, j); // Real } } } return OS; } //======================================================================= // function : operator <<(Geom_BSplineSurface) // purpose : //======================================================================= static BinTools_OStream& operator<<(BinTools_OStream& OS, const Handle(Geom_BSplineSurface)& S) { OS << (Standard_Byte)BSPLINE; Standard_Boolean urational = S->IsURational() ? 1 : 0; Standard_Boolean vrational = S->IsVRational() ? 1 : 0; Standard_Boolean uperiodic = S->IsUPeriodic() ? 1 : 0; Standard_Boolean vperiodic = S->IsVPeriodic() ? 1 : 0; OS << urational; OS << vrational; OS << uperiodic; OS << vperiodic; // poles and weights Standard_Integer i, j, udegree, vdegree, nbupoles, nbvpoles, nbuknots, nbvknots; udegree = S->UDegree(); vdegree = S->VDegree(); nbupoles = S->NbUPoles(); nbvpoles = S->NbVPoles(); nbuknots = S->NbUKnots(); nbvknots = S->NbVKnots(); OS << (Standard_ExtCharacter)udegree; OS << (Standard_ExtCharacter)vdegree; OS << nbupoles; OS << nbvpoles; OS << nbuknots; OS << nbvknots; for (i = 1; i <= nbupoles; i++) { for (j = 1; j <= nbvpoles; j++) { OS << S->Pole(i, j); // Pnt if (urational || vrational) OS << S->Weight(i, j); // Real } } for (i = 1; i <= nbuknots; i++) { OS << S->UKnot(i); OS << S->UMultiplicity(i); } for (i = 1; i <= nbvknots; i++) { OS << S->VKnot(i); OS << S->VMultiplicity(i); } return OS; } //======================================================================= // function : operator <<(Geom_RectangularTrimmedSurface) // purpose : //======================================================================= static BinTools_OStream& operator<<(BinTools_OStream& OS, const Handle(Geom_RectangularTrimmedSurface)& S) { OS << (Standard_Byte)RECTANGULAR; Standard_Real U1, U2, V1, V2; S->Bounds(U1, U2, V1, V2); OS << U1 << U2 << V1 << V2; BinTools_SurfaceSet::WriteSurface(S->BasisSurface(), OS); return OS; } //======================================================================= // function : operator <<(Geom_OffsetSurface) // purpose : //======================================================================= static BinTools_OStream& operator<<(BinTools_OStream& OS, const Handle(Geom_OffsetSurface)& S) { OS << (Standard_Byte)OFFSET; OS << S->Offset(); BinTools_SurfaceSet::WriteSurface(S->BasisSurface(), OS); return OS; } //================================================================================================= void BinTools_SurfaceSet::WriteSurface(const Handle(Geom_Surface)& S, BinTools_OStream& OS) { Handle(Standard_Type) TheType = S->DynamicType(); try { OCC_CATCH_SIGNALS if (TheType == STANDARD_TYPE(Geom_Plane)) { OS << Handle(Geom_Plane)::DownCast(S); } else if (TheType == STANDARD_TYPE(Geom_CylindricalSurface)) { OS << Handle(Geom_CylindricalSurface)::DownCast(S); } else if (TheType == STANDARD_TYPE(Geom_ConicalSurface)) { OS << Handle(Geom_ConicalSurface)::DownCast(S); } else if (TheType == STANDARD_TYPE(Geom_SphericalSurface)) { OS << Handle(Geom_SphericalSurface)::DownCast(S); } else if (TheType == STANDARD_TYPE(Geom_ToroidalSurface)) { OS << Handle(Geom_ToroidalSurface)::DownCast(S); } else if (TheType == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion)) { OS << Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(S); } else if (TheType == STANDARD_TYPE(Geom_SurfaceOfRevolution)) { OS << Handle(Geom_SurfaceOfRevolution)::DownCast(S); } else if (TheType == STANDARD_TYPE(Geom_BezierSurface)) { OS << Handle(Geom_BezierSurface)::DownCast(S); } else if (TheType == STANDARD_TYPE(Geom_BSplineSurface)) { OS << Handle(Geom_BSplineSurface)::DownCast(S); } else if (TheType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { OS << Handle(Geom_RectangularTrimmedSurface)::DownCast(S); } else if (TheType == STANDARD_TYPE(Geom_OffsetSurface)) { OS << Handle(Geom_OffsetSurface)::DownCast(S); } else { throw Standard_Failure("UNKNOWN SURFACE TYPE"); } } catch (Standard_Failure const& anException) { Standard_SStream aMsg; aMsg << "EXCEPTION in BinTools_SurfaceSet::WriteSurface(..)" << std::endl; aMsg << anException << std::endl; throw Standard_Failure(aMsg.str().c_str()); } } //================================================================================================= void BinTools_SurfaceSet::Write(Standard_OStream& OS, const Message_ProgressRange& theRange) const { Standard_Integer i, nbsurf = myMap.Extent(); Message_ProgressScope aPS(theRange, "Writing surfaces", nbsurf); OS << "Surfaces " << nbsurf << "\n"; BinTools_OStream aStream(OS); for (i = 1; i <= nbsurf && aPS.More(); i++, aPS.Next()) { WriteSurface(Handle(Geom_Surface)::DownCast(myMap(i)), aStream); } } //================================================================================================= static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt& P) { Standard_Real X = 0., Y = 0., Z = 0.; BinTools::GetReal(IS, X); BinTools::GetReal(IS, Y); BinTools::GetReal(IS, Z); P.SetCoord(X, Y, Z); return IS; } //================================================================================================= static Standard_IStream& operator>>(Standard_IStream& IS, gp_Dir& D) { Standard_Real X = 0., Y = 0., Z = 0.; BinTools::GetReal(IS, X); BinTools::GetReal(IS, Y); BinTools::GetReal(IS, Z); D.SetCoord(X, Y, Z); return IS; } //================================================================================================= static Standard_IStream& operator>>(Standard_IStream& IS, gp_Ax3& A3) { gp_Pnt P(0., 0., 0.); gp_Dir A(1., 0., 0.), AX(1., 0., 0.), AY(1., 0., 0.); IS >> P >> A >> AX >> AY; gp_Ax3 ax3(P, A, AX); if (AY.DotCross(A, AX) < 0) ax3.YReverse(); A3 = ax3; return IS; } //======================================================================= // function : operator>> // purpose : //======================================================================= static Standard_IStream& operator>>(Standard_IStream& IS, Handle(Geom_Plane)& S) { gp_Ax3 A; IS >> A; S = new Geom_Plane(A); return IS; } //======================================================================= // function : operator>> // purpose : //======================================================================= static Standard_IStream& operator>>(Standard_IStream& IS, Handle(Geom_CylindricalSurface)& S) { gp_Ax3 A; Standard_Real R = 0.; IS >> A; BinTools::GetReal(IS, R); S = new Geom_CylindricalSurface(A, R); return IS; } //======================================================================= // function : operator>> // purpose : //======================================================================= static Standard_IStream& operator>>(Standard_IStream& IS, Handle(Geom_ConicalSurface)& S) { gp_Ax3 A; Standard_Real R = 0., Ang = 0.; IS >> A; BinTools::GetReal(IS, R); BinTools::GetReal(IS, Ang); S = new Geom_ConicalSurface(A, Ang, R); return IS; } //======================================================================= // function : operator>> // purpose : //======================================================================= static Standard_IStream& operator>>(Standard_IStream& IS, Handle(Geom_SphericalSurface)& S) { gp_Ax3 A; Standard_Real R = 0.; IS >> A; BinTools::GetReal(IS, R); S = new Geom_SphericalSurface(A, R); return IS; } //======================================================================= // function : operator>> // purpose : //======================================================================= static Standard_IStream& operator>>(Standard_IStream& IS, Handle(Geom_ToroidalSurface)& S) { gp_Ax3 A; Standard_Real R1 = 0., R2 = 0.; IS >> A; BinTools::GetReal(IS, R1); BinTools::GetReal(IS, R2); S = new Geom_ToroidalSurface(A, R1, R2); return IS; } //======================================================================= // function : operator>> // purpose : //======================================================================= static Standard_IStream& operator>>(Standard_IStream& IS, Handle(Geom_SurfaceOfLinearExtrusion)& S) { gp_Dir D(1., 0., 0.); Handle(Geom_Curve) C; IS >> D; BinTools_CurveSet::ReadCurve(IS, C); S = new Geom_SurfaceOfLinearExtrusion(C, D); return IS; } //======================================================================= // function : operator>> // purpose : //======================================================================= static Standard_IStream& operator>>(Standard_IStream& IS, Handle(Geom_SurfaceOfRevolution)& S) { gp_Pnt P(0., 0., 0.); gp_Dir D(1., 0., 0.); Handle(Geom_Curve) C; IS >> P >> D; BinTools_CurveSet::ReadCurve(IS, C); S = new Geom_SurfaceOfRevolution(C, gp_Ax1(P, D)); return IS; } //======================================================================= // function : operator>> // purpose : //======================================================================= static Standard_IStream& operator>>(Standard_IStream& IS, Handle(Geom_BezierSurface)& S) { // std::cout << "BezierSurface:" <> buffer; if (IS.fail() || strcmp(buffer, "Surfaces")) { Standard_SStream aMsg; aMsg << "BinTools_SurfaceSet::Read: Not a surface table" << std::endl; #ifdef OCCT_DEBUG std::cout << "SurfaceSet buffer: " << buffer << std::endl; #endif throw Standard_Failure(aMsg.str().c_str()); return; } Handle(Geom_Surface) S; Standard_Integer i, nbsurf; IS >> nbsurf; Message_ProgressScope aPS(theRange, "Reading surfaces", nbsurf); IS.get(); // remove for (i = 1; i <= nbsurf && aPS.More(); i++, aPS.Next()) { BinTools_SurfaceSet::ReadSurface(IS, S); myMap.Add(S); } }