1 // Copyright (c) 2015 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #ifndef _ShapePersistent_Geom_HeaderFile
16 #define _ShapePersistent_Geom_HeaderFile
18 #include <Standard_NotImplemented.hxx>
19 #include <Standard_NullObject.hxx>
21 #include <StdObjMgt_SharedObject.hxx>
22 #include <StdObjMgt_TransientPersistentMap.hxx>
24 #include <StdObject_gp_Curves.hxx>
25 #include <StdObject_gp_Surfaces.hxx>
26 #include <StdObject_gp_Trsfs.hxx>
28 #include <Geom_CartesianPoint.hxx>
29 #include <Geom_Direction.hxx>
30 #include <Geom_VectorWithMagnitude.hxx>
31 #include <Geom_Axis1Placement.hxx>
32 #include <Geom_Axis2Placement.hxx>
33 #include <Geom_Transformation.hxx>
34 #include <Geom_Surface.hxx>
36 class ShapePersistent_Geom : public StdObjMgt_SharedObject
39 class Geometry : public StdObjMgt_Persistent
42 //! Read persistent data from a file.
43 Standard_EXPORT virtual void Read (StdObjMgt_ReadData& theReadData);
44 //! Write persistent data to a file.
45 Standard_EXPORT virtual void Write (StdObjMgt_WriteData& theWriteData) const;
46 //! Gets persistent objects
47 Standard_EXPORT virtual void PChildren(SequenceOfPersistent& theChildren) const;
48 //! Returns persistent type name
49 virtual Standard_CString PName() const { return "PGeom_Geometry"; }
53 template <class Transient>
54 struct geometryBase : public DelayedBase<Geometry, Transient>
56 //! Write persistent data to a file.
57 virtual void Write (StdObjMgt_WriteData&) const
59 Standard_NotImplemented::Raise("ShapePersistent_Geom::geometryBase::Write - not implemented");
61 //! Gets persistent child objects
62 virtual void PChildren (StdObjMgt_Persistent::SequenceOfPersistent&) const { }
63 //! Returns persistent type name
64 virtual Standard_CString PName() const
66 Standard_NotImplemented::Raise("ShapePersistent_Geom::geometryBase::PName - not implemented");
71 template <class Base, class PData>
72 class subBase : public Base
75 //! Read persistent data from a file.
76 virtual void Read (StdObjMgt_ReadData& theReadData)
77 { PData().Read (theReadData); }
78 //! Write persistent data to a file.
79 virtual void Write (StdObjMgt_WriteData& theWriteData) const
80 { PData().Write(theWriteData); }
81 //! Gets persistent child objects
82 virtual void PChildren (StdObjMgt_Persistent::SequenceOfPersistent&) const
84 Standard_NotImplemented::Raise("ShapePersistent_Geom::subBase::PChildren - not implemented");
86 //! Returns persistent type name
87 virtual Standard_CString PName() const
89 Standard_NotImplemented::Raise("ShapePersistent_Geom::subBase::PName - not implemented");
94 template <class Base, class GpData>
95 struct subBase_gp : public Base
98 //! Read persistent data from a file.
99 virtual void Read (StdObjMgt_ReadData&) { }
100 //! Write persistent data to a file.
101 virtual void Write (StdObjMgt_WriteData&) const { }
102 //! Gets persistent child objects
103 virtual void PChildren (StdObjMgt_Persistent::SequenceOfPersistent&) const { }
104 //! Returns persistent type name
105 virtual Standard_CString PName() const
107 Standard_NotImplemented::Raise("ShapePersistent_Geom::subBase_gp::PName - not implemented");
112 template <class Base>
113 struct subBase_empty : Base
115 //! Returns persistent type name
116 virtual Standard_CString PName() const
118 Standard_NotImplemented::Raise("ShapePersistent_Geom::subBase_empty::PName - not implemented");
123 template <class Base, class Target, class Data = void>
124 class instance : public Base
127 //! Read persistent data from a file.
128 virtual void Read (StdObjMgt_ReadData& theReadData)
131 theReadData >> aData;
132 this->myTransient = new Target(aData);
134 //! Gets persistent child objects
135 virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent&) const { }
136 //! Write persistent data to a file.
137 virtual void Write(StdObjMgt_WriteData&) const
139 Standard_NotImplemented::Raise("ShapePersistent_Geom::instance::Write - not implemented");
141 //! Returns persistent type name
142 virtual Standard_CString PName() const
144 Standard_NotImplemented::Raise("ShapePersistent_Geom::instance::PName - not implemented");
150 typedef geometryBase<Geom_Geometry> basic;
153 typedef subBase_empty<basic> Point;
154 typedef instance<Point, Geom_CartesianPoint, gp_Pnt> CartesianPoint;
156 typedef subBase_gp<basic, gp_Vec> Vector;
157 typedef instance<Vector, Geom_Direction , gp_Dir> Direction;
158 typedef instance<Vector, Geom_VectorWithMagnitude, gp_Vec> VectorWithMagnitude;
160 typedef subBase_gp<basic, gp_Ax1> AxisPlacement;
161 typedef instance<AxisPlacement, Geom_Axis1Placement, gp_Ax1> Axis1Placement;
162 typedef instance<AxisPlacement, Geom_Axis2Placement> Axis2Placement;
164 typedef instance <SharedBase<Geom_Transformation>,
166 gp_Trsf> Transformation;
168 typedef geometryBase<Geom_Curve> Curve;
169 typedef geometryBase<Geom_Surface> Surface;
172 //! Create a persistent object for a curve
173 Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom_Curve)& theCurve,
174 StdObjMgt_TransientPersistentMap& theMap);
175 //! Create a persistent object for a curve
176 Standard_EXPORT static Handle(Surface) Translate (const Handle(Geom_Surface)& theSurf,
177 StdObjMgt_TransientPersistentMap& theMap);
180 //=======================================================================
182 //=======================================================================
185 inline Standard_CString ShapePersistent_Geom::subBase_empty<ShapePersistent_Geom::basic>
186 ::PName() const { return "PGeom_Point"; }
188 //=======================================================================
190 //=======================================================================
193 inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::Point,
196 ::PName() const { return "PGeom_CartesianPoint"; }
199 inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::Point,
202 ::Write(StdObjMgt_WriteData& theWriteData) const
204 Handle(Geom_CartesianPoint) aMyGeom =
205 Handle(Geom_CartesianPoint)::DownCast(myTransient);
206 theWriteData << aMyGeom->Pnt();
209 //=======================================================================
211 //=======================================================================
214 inline Standard_CString ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::basic,
216 ::PName() const { return "PGeom_Vector"; }
218 //=======================================================================
220 //=======================================================================
223 inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::Direction,
226 ::PName() const { return "PGeom_Direction"; }
229 inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::Direction,
232 ::Write(StdObjMgt_WriteData& theWriteData) const
234 Handle(Geom_Direction) aMyGeom =
235 Handle(Geom_Direction)::DownCast(myTransient);
236 theWriteData << aMyGeom->Dir();
239 //=======================================================================
240 // VectorWithMagnitude
241 //=======================================================================
244 inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::VectorWithMagnitude,
245 Geom_VectorWithMagnitude,
247 ::PName() const { return "PGeom_VectorWithMagnitude"; }
250 inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::VectorWithMagnitude,
251 Geom_VectorWithMagnitude,
253 ::Write(StdObjMgt_WriteData& theWriteData) const
255 Handle(Geom_VectorWithMagnitude) aMyGeom =
256 Handle(Geom_VectorWithMagnitude)::DownCast(myTransient);
257 theWriteData << aMyGeom->Vec();
260 //=======================================================================
262 //=======================================================================
265 inline Standard_CString ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::basic,
267 ::PName() const { return "PGeom_AxisPlacement"; }
269 //=======================================================================
271 //=======================================================================
274 inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::Axis1Placement,
277 ::PName() const { return "PGeom_Axis1Placement"; }
280 inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::Axis1Placement,
283 ::Write(StdObjMgt_WriteData& theWriteData) const
285 Handle(Geom_Axis1Placement) aMyGeom =
286 Handle(Geom_Axis1Placement)::DownCast(myTransient);
287 write(theWriteData, aMyGeom->Ax1());
290 //=======================================================================
292 //=======================================================================
295 inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::AxisPlacement,
297 ::PName() const { return "PGeom_Axis2Placement"; }
300 inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::AxisPlacement,
302 ::Read (StdObjMgt_ReadData& theReadData)
307 theReadData >> anAxis >> anXDirection;
309 myTransient = new Geom_Axis2Placement(anAxis.Location(),
315 inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::AxisPlacement,
317 ::Write (StdObjMgt_WriteData& theWriteData) const
319 Handle(Geom_Axis2Placement) aMyGeom =
320 Handle(Geom_Axis2Placement)::DownCast(myTransient);
321 const gp_Ax1& anAxis = aMyGeom->Axis();
322 const gp_Dir& anXDirection = aMyGeom->Direction();
323 write(theWriteData, anAxis) << anXDirection;
326 //=======================================================================
328 //=======================================================================
331 inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::Transformation,
334 ::PName() const { return "PGeom_Transformation"; }
337 inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::Transformation,
340 ::Write (StdObjMgt_WriteData& theWriteData) const
342 theWriteData << myTransient->Trsf();
345 //=======================================================================
347 //=======================================================================
350 inline Standard_CString ShapePersistent_Geom::geometryBase<Geom_Geometry>
351 ::PName() const { return "PGeom_Geometry"; }
353 //=======================================================================
355 //=======================================================================
358 inline Standard_CString ShapePersistent_Geom::geometryBase<Geom_Curve>
359 ::PName() const { return "PGeom_Curve"; }
361 //=======================================================================
363 //=======================================================================
366 inline Standard_CString ShapePersistent_Geom::geometryBase<Geom_Surface>
367 ::PName() const { return "PGeom_Surface"; }