Back to home page

EIC code displayed by LXR

 
 

    


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