Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:56

0001 // Copyright (c) 2015 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 
0015 #ifndef _ShapePersistent_Geom_HeaderFile
0016 #define _ShapePersistent_Geom_HeaderFile
0017 
0018 #include <Standard_NotImplemented.hxx>
0019 #include <Standard_NullObject.hxx>
0020 
0021 #include <StdObjMgt_SharedObject.hxx>
0022 #include <StdObjMgt_TransientPersistentMap.hxx>
0023 
0024 #include <StdObject_gp_Curves.hxx>
0025 #include <StdObject_gp_Surfaces.hxx>
0026 #include <StdObject_gp_Trsfs.hxx>
0027 
0028 #include <Geom_CartesianPoint.hxx>
0029 #include <Geom_Direction.hxx>
0030 #include <Geom_VectorWithMagnitude.hxx>
0031 #include <Geom_Axis1Placement.hxx>
0032 #include <Geom_Axis2Placement.hxx>
0033 #include <Geom_Transformation.hxx>
0034 #include <Geom_Surface.hxx>
0035 
0036 class ShapePersistent_Geom : public StdObjMgt_SharedObject
0037 {
0038 public:
0039   class Geometry : public StdObjMgt_Persistent
0040   {
0041   public:
0042     //! Read persistent data from a file.
0043     Standard_EXPORT virtual void Read (StdObjMgt_ReadData& theReadData);
0044     //! Write persistent data to a file.
0045     Standard_EXPORT virtual void Write (StdObjMgt_WriteData& theWriteData) const;
0046     //! Gets persistent objects
0047     Standard_EXPORT virtual void PChildren(SequenceOfPersistent& theChildren) const;
0048     //! Returns persistent type name
0049     virtual Standard_CString PName() const { return "PGeom_Geometry"; }
0050   };
0051 
0052 protected:
0053   template <class Transient>
0054   struct geometryBase : public DelayedBase<Geometry, Transient> 
0055   {
0056     //! Write persistent data to a file.
0057     virtual void Write (StdObjMgt_WriteData&) const
0058     {
0059       Standard_NotImplemented::Raise("ShapePersistent_Geom::geometryBase::Write - not implemented");
0060     }
0061     //! Gets persistent child objects
0062     virtual void PChildren (StdObjMgt_Persistent::SequenceOfPersistent&) const { }
0063     //! Returns persistent type name
0064     virtual Standard_CString PName() const
0065     { 
0066       Standard_NotImplemented::Raise("ShapePersistent_Geom::geometryBase::PName - not implemented");
0067       return ""; 
0068     }
0069   };
0070 
0071   template <class Base, class PData>
0072   class subBase : public Base
0073   {
0074   public:
0075     //! Read persistent data from a file.
0076     virtual void Read (StdObjMgt_ReadData& theReadData)
0077       { PData().Read (theReadData); }
0078     //! Write persistent data to a file.
0079     virtual void Write (StdObjMgt_WriteData& theWriteData) const
0080       { PData().Write(theWriteData); }
0081     //! Gets persistent child objects
0082     virtual void PChildren (StdObjMgt_Persistent::SequenceOfPersistent&) const
0083     {
0084       Standard_NotImplemented::Raise("ShapePersistent_Geom::subBase::PChildren - not implemented");
0085     }
0086     //! Returns persistent type name
0087     virtual Standard_CString PName() const
0088     { 
0089       Standard_NotImplemented::Raise("ShapePersistent_Geom::subBase::PName - not implemented");
0090       return ""; 
0091     }
0092   };
0093 
0094   template <class Base, class GpData>
0095   struct subBase_gp : public Base
0096   {
0097   public:
0098     //! Read persistent data from a file.
0099     virtual void Read (StdObjMgt_ReadData&) { }
0100     //! Write persistent data to a file.
0101     virtual void Write (StdObjMgt_WriteData&) const { }
0102     //! Gets persistent child objects
0103     virtual void PChildren (StdObjMgt_Persistent::SequenceOfPersistent&) const { }
0104     //! Returns persistent type name
0105     virtual Standard_CString PName() const
0106     {
0107       Standard_NotImplemented::Raise("ShapePersistent_Geom::subBase_gp::PName - not implemented");
0108       return "";
0109     }
0110   };
0111 
0112   template <class Base>
0113   struct subBase_empty : Base  
0114   { 
0115     //! Returns persistent type name
0116     virtual Standard_CString PName() const
0117     {
0118       Standard_NotImplemented::Raise("ShapePersistent_Geom::subBase_empty::PName - not implemented");
0119       return "";
0120     }
0121   };
0122 
0123   template <class Base, class Target, class Data = void>
0124   class instance : public Base
0125   {
0126   public:
0127     //! Read persistent data from a file.
0128     virtual void Read (StdObjMgt_ReadData& theReadData)
0129     {
0130       Data aData;
0131       theReadData >> aData;
0132       this->myTransient = new Target(aData);
0133     }
0134     //! Gets persistent child objects
0135     virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent&) const { }
0136     //! Write persistent data to a file.
0137     virtual void Write(StdObjMgt_WriteData&) const
0138     {
0139       Standard_NotImplemented::Raise("ShapePersistent_Geom::instance::Write - not implemented");
0140     }
0141     //! Returns persistent type name
0142     virtual Standard_CString PName() const
0143     {
0144       Standard_NotImplemented::Raise("ShapePersistent_Geom::instance::PName - not implemented");
0145       return "";
0146     }
0147   };
0148 
0149 private:
0150   typedef geometryBase<Geom_Geometry> basic;
0151 
0152 public:
0153   typedef subBase_empty<basic>                                 Point;
0154   typedef instance<Point, Geom_CartesianPoint, gp_Pnt>         CartesianPoint;
0155 
0156   typedef subBase_gp<basic, gp_Vec>                            Vector;
0157   typedef instance<Vector, Geom_Direction          , gp_Dir>   Direction;
0158   typedef instance<Vector, Geom_VectorWithMagnitude, gp_Vec>   VectorWithMagnitude;
0159 
0160   typedef subBase_gp<basic, gp_Ax1>                            AxisPlacement;
0161   typedef instance<AxisPlacement, Geom_Axis1Placement, gp_Ax1> Axis1Placement;
0162   typedef instance<AxisPlacement, Geom_Axis2Placement>         Axis2Placement;
0163 
0164   typedef instance <SharedBase<Geom_Transformation>,
0165                     Geom_Transformation,
0166                     gp_Trsf>                                   Transformation;
0167 
0168   typedef geometryBase<Geom_Curve>                             Curve;
0169   typedef geometryBase<Geom_Surface>                           Surface;
0170 
0171 public:
0172   //! Create a persistent object for a curve
0173   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom_Curve)& theCurve,
0174                                                   StdObjMgt_TransientPersistentMap& theMap);
0175   //! Create a persistent object for a curve
0176   Standard_EXPORT static Handle(Surface) Translate (const Handle(Geom_Surface)& theSurf,
0177                                                     StdObjMgt_TransientPersistentMap& theMap);
0178 };
0179 
0180 //=======================================================================
0181 // Point 
0182 //=======================================================================
0183 
0184 template<>
0185 inline Standard_CString ShapePersistent_Geom::subBase_empty<ShapePersistent_Geom::basic>
0186   ::PName() const { return "PGeom_Point"; }
0187 
0188 //=======================================================================
0189 // CartesianPoint
0190 //=======================================================================
0191 
0192 template<>
0193 inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::Point,
0194                                                        Geom_CartesianPoint,
0195                                gp_Pnt>
0196   ::PName() const { return "PGeom_CartesianPoint"; }
0197 
0198 template<>
0199 inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::Point,
0200                        Geom_CartesianPoint,
0201                        gp_Pnt>
0202   ::Write(StdObjMgt_WriteData& theWriteData) const
0203 {
0204   Handle(Geom_CartesianPoint) aMyGeom =
0205     Handle(Geom_CartesianPoint)::DownCast(myTransient);
0206   theWriteData << aMyGeom->Pnt();
0207 }
0208 
0209 //=======================================================================
0210 // Vector
0211 //=======================================================================
0212 
0213 template<>
0214 inline Standard_CString ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::basic,
0215                              gp_Vec>
0216   ::PName() const { return "PGeom_Vector"; }
0217 
0218 //=======================================================================
0219 // Direction
0220 //=======================================================================
0221 
0222 template<>
0223 inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::Direction,
0224                                Geom_Direction,
0225                                gp_Dir>
0226   ::PName() const { return "PGeom_Direction"; }
0227 
0228 template<>
0229 inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::Direction,
0230                        Geom_Direction,
0231                        gp_Dir>
0232   ::Write(StdObjMgt_WriteData& theWriteData) const
0233 {
0234   Handle(Geom_Direction) aMyGeom =
0235     Handle(Geom_Direction)::DownCast(myTransient);
0236   theWriteData << aMyGeom->Dir();
0237 }
0238 
0239 //=======================================================================
0240 // VectorWithMagnitude
0241 //=======================================================================
0242 
0243 template<>
0244 inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::VectorWithMagnitude,
0245                                Geom_VectorWithMagnitude,
0246                                gp_Vec>
0247   ::PName() const { return "PGeom_VectorWithMagnitude"; }
0248 
0249 template<>
0250 inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::VectorWithMagnitude,
0251                        Geom_VectorWithMagnitude,
0252                        gp_Vec>
0253   ::Write(StdObjMgt_WriteData& theWriteData) const
0254 {
0255   Handle(Geom_VectorWithMagnitude) aMyGeom =
0256     Handle(Geom_VectorWithMagnitude)::DownCast(myTransient);
0257   theWriteData << aMyGeom->Vec();
0258 }
0259 
0260 //=======================================================================
0261 // AxisPlacement 
0262 //=======================================================================
0263 
0264 template<>
0265 inline Standard_CString ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::basic,
0266                              gp_Ax1>
0267   ::PName() const { return "PGeom_AxisPlacement"; }
0268 
0269 //=======================================================================
0270 // Axis1Placement
0271 //=======================================================================
0272 
0273 template<>
0274 inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::Axis1Placement,
0275                                Geom_Axis1Placement,
0276                                gp_Ax1>
0277   ::PName() const { return "PGeom_Axis1Placement"; }
0278 
0279 template<>
0280 inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::Axis1Placement,
0281                        Geom_Axis1Placement,
0282                        gp_Ax1>
0283   ::Write(StdObjMgt_WriteData& theWriteData) const
0284 {
0285   Handle(Geom_Axis1Placement) aMyGeom =
0286     Handle(Geom_Axis1Placement)::DownCast(myTransient);
0287   write(theWriteData, aMyGeom->Ax1());
0288 }
0289 
0290 //=======================================================================
0291 // Axis2Placement 
0292 //=======================================================================
0293 
0294 template<>
0295 inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::AxisPlacement,
0296                                Geom_Axis2Placement>
0297   ::PName() const { return "PGeom_Axis2Placement"; }
0298 
0299 template<>
0300 inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::AxisPlacement,
0301                        Geom_Axis2Placement>
0302   ::Read (StdObjMgt_ReadData& theReadData)
0303 {
0304   gp_Ax1 anAxis;
0305   gp_Dir anXDirection;
0306 
0307   theReadData >> anAxis >> anXDirection;
0308 
0309   myTransient = new Geom_Axis2Placement(anAxis.Location(),
0310     anAxis.Direction(),
0311     anXDirection);
0312 }
0313 
0314 template<>
0315 inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::AxisPlacement,
0316                        Geom_Axis2Placement>
0317   ::Write (StdObjMgt_WriteData& theWriteData) const
0318 {
0319   Handle(Geom_Axis2Placement) aMyGeom =
0320     Handle(Geom_Axis2Placement)::DownCast(myTransient);
0321   const gp_Ax1& anAxis = aMyGeom->Axis();
0322   const gp_Dir& anXDirection = aMyGeom->Direction();
0323   write(theWriteData, anAxis) << anXDirection;
0324 }
0325 
0326 //=======================================================================
0327 // Transformation
0328 //=======================================================================
0329 
0330 template<>
0331 inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::Transformation,
0332                                Geom_Transformation,
0333                                gp_Trsf>
0334   ::PName() const { return "PGeom_Transformation"; }
0335 
0336 template<>
0337 inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::Transformation,
0338                        Geom_Transformation,
0339                        gp_Trsf>
0340   ::Write (StdObjMgt_WriteData& theWriteData) const
0341 {
0342   theWriteData << myTransient->Trsf();
0343 }
0344 
0345 //=======================================================================
0346 // Geometry
0347 //=======================================================================
0348 
0349 template<>
0350 inline Standard_CString ShapePersistent_Geom::geometryBase<Geom_Geometry>
0351   ::PName() const { return "PGeom_Geometry"; }
0352 
0353 //=======================================================================
0354 // Curve
0355 //=======================================================================
0356 
0357 template<>
0358 inline Standard_CString ShapePersistent_Geom::geometryBase<Geom_Curve>
0359   ::PName() const { return "PGeom_Curve"; }
0360 
0361 //=======================================================================
0362 // Surface
0363 //=======================================================================
0364 
0365 template<>
0366 inline Standard_CString ShapePersistent_Geom::geometryBase<Geom_Surface>
0367   ::PName() const { return "PGeom_Surface"; }
0368 
0369 #endif