// Copyright (c) 2015 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. #ifndef _ShapePersistent_Geom_HeaderFile #define _ShapePersistent_Geom_HeaderFile #include #include #include #include #include #include #include #include #include #include #include #include #include #include class ShapePersistent_Geom : public StdObjMgt_SharedObject { public: class Geometry : public StdObjMgt_Persistent { public: //! Read persistent data from a file. Standard_EXPORT virtual void Read (StdObjMgt_ReadData& theReadData); //! Write persistent data to a file. Standard_EXPORT virtual void Write (StdObjMgt_WriteData& theWriteData) const; //! Gets persistent objects Standard_EXPORT virtual void PChildren(SequenceOfPersistent& theChildren) const; //! Returns persistent type name virtual Standard_CString PName() const { return "PGeom_Geometry"; } }; protected: template struct geometryBase : public DelayedBase { //! Write persistent data to a file. virtual void Write (StdObjMgt_WriteData&) const { Standard_NotImplemented::Raise("ShapePersistent_Geom::geometryBase::Write - not implemented"); } //! Gets persistent child objects virtual void PChildren (StdObjMgt_Persistent::SequenceOfPersistent&) const { } //! Returns persistent type name virtual Standard_CString PName() const { Standard_NotImplemented::Raise("ShapePersistent_Geom::geometryBase::PName - not implemented"); return ""; } }; template class subBase : public Base { public: //! Read persistent data from a file. virtual void Read (StdObjMgt_ReadData& theReadData) { PData().Read (theReadData); } //! Write persistent data to a file. virtual void Write (StdObjMgt_WriteData& theWriteData) const { PData().Write(theWriteData); } //! Gets persistent child objects virtual void PChildren (StdObjMgt_Persistent::SequenceOfPersistent&) const { Standard_NotImplemented::Raise("ShapePersistent_Geom::subBase::PChildren - not implemented"); } //! Returns persistent type name virtual Standard_CString PName() const { Standard_NotImplemented::Raise("ShapePersistent_Geom::subBase::PName - not implemented"); return ""; } }; template struct subBase_gp : public Base { public: //! Read persistent data from a file. virtual void Read (StdObjMgt_ReadData&) { } //! Write persistent data to a file. virtual void Write (StdObjMgt_WriteData&) const { } //! Gets persistent child objects virtual void PChildren (StdObjMgt_Persistent::SequenceOfPersistent&) const { } //! Returns persistent type name virtual Standard_CString PName() const { Standard_NotImplemented::Raise("ShapePersistent_Geom::subBase_gp::PName - not implemented"); return ""; } }; template struct subBase_empty : Base { //! Returns persistent type name virtual Standard_CString PName() const { Standard_NotImplemented::Raise("ShapePersistent_Geom::subBase_empty::PName - not implemented"); return ""; } }; template class instance : public Base { public: //! Read persistent data from a file. virtual void Read (StdObjMgt_ReadData& theReadData) { Data aData; theReadData >> aData; this->myTransient = new Target(aData); } //! Gets persistent child objects virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent&) const { } //! Write persistent data to a file. virtual void Write(StdObjMgt_WriteData&) const { Standard_NotImplemented::Raise("ShapePersistent_Geom::instance::Write - not implemented"); } //! Returns persistent type name virtual Standard_CString PName() const { Standard_NotImplemented::Raise("ShapePersistent_Geom::instance::PName - not implemented"); return ""; } }; private: typedef geometryBase basic; public: typedef subBase_empty Point; typedef instance CartesianPoint; typedef subBase_gp Vector; typedef instance Direction; typedef instance VectorWithMagnitude; typedef subBase_gp AxisPlacement; typedef instance Axis1Placement; typedef instance Axis2Placement; typedef instance , Geom_Transformation, gp_Trsf> Transformation; typedef geometryBase Curve; typedef geometryBase Surface; public: //! Create a persistent object for a curve Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom_Curve)& theCurve, StdObjMgt_TransientPersistentMap& theMap); //! Create a persistent object for a curve Standard_EXPORT static Handle(Surface) Translate (const Handle(Geom_Surface)& theSurf, StdObjMgt_TransientPersistentMap& theMap); }; //======================================================================= // Point //======================================================================= template<> inline Standard_CString ShapePersistent_Geom::subBase_empty ::PName() const { return "PGeom_Point"; } //======================================================================= // CartesianPoint //======================================================================= template<> inline Standard_CString ShapePersistent_Geom::instance ::PName() const { return "PGeom_CartesianPoint"; } template<> inline void ShapePersistent_Geom::instance ::Write(StdObjMgt_WriteData& theWriteData) const { Handle(Geom_CartesianPoint) aMyGeom = Handle(Geom_CartesianPoint)::DownCast(myTransient); theWriteData << aMyGeom->Pnt(); } //======================================================================= // Vector //======================================================================= template<> inline Standard_CString ShapePersistent_Geom::subBase_gp ::PName() const { return "PGeom_Vector"; } //======================================================================= // Direction //======================================================================= template<> inline Standard_CString ShapePersistent_Geom::instance ::PName() const { return "PGeom_Direction"; } template<> inline void ShapePersistent_Geom::instance ::Write(StdObjMgt_WriteData& theWriteData) const { Handle(Geom_Direction) aMyGeom = Handle(Geom_Direction)::DownCast(myTransient); theWriteData << aMyGeom->Dir(); } //======================================================================= // VectorWithMagnitude //======================================================================= template<> inline Standard_CString ShapePersistent_Geom::instance ::PName() const { return "PGeom_VectorWithMagnitude"; } template<> inline void ShapePersistent_Geom::instance ::Write(StdObjMgt_WriteData& theWriteData) const { Handle(Geom_VectorWithMagnitude) aMyGeom = Handle(Geom_VectorWithMagnitude)::DownCast(myTransient); theWriteData << aMyGeom->Vec(); } //======================================================================= // AxisPlacement //======================================================================= template<> inline Standard_CString ShapePersistent_Geom::subBase_gp ::PName() const { return "PGeom_AxisPlacement"; } //======================================================================= // Axis1Placement //======================================================================= template<> inline Standard_CString ShapePersistent_Geom::instance ::PName() const { return "PGeom_Axis1Placement"; } template<> inline void ShapePersistent_Geom::instance ::Write(StdObjMgt_WriteData& theWriteData) const { Handle(Geom_Axis1Placement) aMyGeom = Handle(Geom_Axis1Placement)::DownCast(myTransient); write(theWriteData, aMyGeom->Ax1()); } //======================================================================= // Axis2Placement //======================================================================= template<> inline Standard_CString ShapePersistent_Geom::instance ::PName() const { return "PGeom_Axis2Placement"; } template<> inline void ShapePersistent_Geom::instance ::Read (StdObjMgt_ReadData& theReadData) { gp_Ax1 anAxis; gp_Dir anXDirection; theReadData >> anAxis >> anXDirection; myTransient = new Geom_Axis2Placement(anAxis.Location(), anAxis.Direction(), anXDirection); } template<> inline void ShapePersistent_Geom::instance ::Write (StdObjMgt_WriteData& theWriteData) const { Handle(Geom_Axis2Placement) aMyGeom = Handle(Geom_Axis2Placement)::DownCast(myTransient); const gp_Ax1& anAxis = aMyGeom->Axis(); const gp_Dir& anXDirection = aMyGeom->Direction(); write(theWriteData, anAxis) << anXDirection; } //======================================================================= // Transformation //======================================================================= template<> inline Standard_CString ShapePersistent_Geom::instance ::PName() const { return "PGeom_Transformation"; } template<> inline void ShapePersistent_Geom::instance ::Write (StdObjMgt_WriteData& theWriteData) const { theWriteData << myTransient->Trsf(); } //======================================================================= // Geometry //======================================================================= template<> inline Standard_CString ShapePersistent_Geom::geometryBase ::PName() const { return "PGeom_Geometry"; } //======================================================================= // Curve //======================================================================= template<> inline Standard_CString ShapePersistent_Geom::geometryBase ::PName() const { return "PGeom_Curve"; } //======================================================================= // Surface //======================================================================= template<> inline Standard_CString ShapePersistent_Geom::geometryBase ::PName() const { return "PGeom_Surface"; } #endif