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_WriteData.hxx>
22 #include <StdObjMgt_SharedObject.hxx>
23 #include <StdObjMgt_TransientPersistentMap.hxx>
25 #include <StdObject_gp_Vectors.hxx>
26 #include <StdObject_gp_Axes.hxx>
27 #include <StdObject_gp_Curves.hxx>
28 #include <StdObject_gp_Surfaces.hxx>
29 #include <StdObject_gp_Trsfs.hxx>
31 #include <Geom_CartesianPoint.hxx>
32 #include <Geom_Direction.hxx>
33 #include <Geom_VectorWithMagnitude.hxx>
34 #include <Geom_Axis1Placement.hxx>
35 #include <Geom_Axis2Placement.hxx>
36 #include <Geom_Transformation.hxx>
37 #include <Geom_Curve.hxx>
38 #include <Geom_Surface.hxx>
40 class ShapePersistent_Geom : public StdObjMgt_SharedObject
43 class Geometry : public StdObjMgt_Persistent
46 //! Read persistent data from a file.
47 Standard_EXPORT virtual void Read (StdObjMgt_ReadData& theReadData);
48 //! Write persistent data to a file.
49 Standard_EXPORT virtual void Write (StdObjMgt_WriteData& theWriteData) const;
50 //! Gets persistent objects
51 Standard_EXPORT virtual void PChildren(SequenceOfPersistent& theChildren) const;
52 //! Returns persistent type name
53 virtual Standard_CString PName() const { return "PGeom_Geometry"; }
57 template <class Transient>
58 struct geometryBase : public DelayedBase<Geometry, Transient>
60 //! Write persistent data to a file.
61 virtual void Write (StdObjMgt_WriteData&) const
63 Standard_NotImplemented::Raise("ShapePersistent_Geom::geometryBase::Write - not implemented");
65 //! Gets persistent child objects
66 virtual void PChildren (StdObjMgt_Persistent::SequenceOfPersistent&) const { }
67 //! Returns persistent type name
68 virtual Standard_CString PName() const
70 Standard_NotImplemented::Raise("ShapePersistent_Geom::geometryBase::PName - not implemented");
75 template <class Base, class PData>
76 class subBase : public Base
79 //! Read persistent data from a file.
80 virtual void Read (StdObjMgt_ReadData& theReadData)
81 { PData().Read (theReadData); }
82 //! Write persistent data to a file.
83 virtual void Write (StdObjMgt_WriteData& theWriteData) const
84 { PData().Write(theWriteData); }
85 //! Gets persistent child objects
86 virtual void PChildren (StdObjMgt_Persistent::SequenceOfPersistent&) const
88 Standard_NotImplemented::Raise("ShapePersistent_Geom::subBase::PChildren - not implemented");
90 //! Returns persistent type name
91 virtual Standard_CString PName() const
93 Standard_NotImplemented::Raise("ShapePersistent_Geom::subBase::PName - not implemented");
98 template <class Base, class GpData>
99 struct subBase_gp : public Base
102 //! Read persistent data from a file.
103 virtual void Read (StdObjMgt_ReadData&) { }
104 //! Write persistent data to a file.
105 virtual void Write (StdObjMgt_WriteData&) const { }
106 //! Gets persistent child objects
107 virtual void PChildren (StdObjMgt_Persistent::SequenceOfPersistent&) const { }
108 //! Returns persistent type name
109 virtual Standard_CString PName() const
111 Standard_NotImplemented::Raise("ShapePersistent_Geom::subBase_gp::PName - not implemented");
116 template <class Base>
117 struct subBase_empty : Base
119 //! Returns persistent type name
120 virtual Standard_CString PName() const
122 Standard_NotImplemented::Raise("ShapePersistent_Geom::subBase_empty::PName - not implemented");
127 template <class Base, class Target, class Data = void>
128 class instance : public Base
131 //! Read persistent data from a file.
132 virtual void Read (StdObjMgt_ReadData& theReadData)
135 theReadData >> aData;
136 this->myTransient = new Target(aData);
138 //! Gets persistent child objects
139 virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent&) const { }
140 //! Write persistent data to a file.
141 virtual void Write(StdObjMgt_WriteData&) const
143 Standard_NotImplemented::Raise("ShapePersistent_Geom::instance::Write - not implemented");
145 //! Returns persistent type name
146 virtual Standard_CString PName() const
148 Standard_NotImplemented::Raise("ShapePersistent_Geom::instance::PName - not implemented");
154 typedef geometryBase<Geom_Geometry> basic;
157 typedef subBase_empty<basic> Point;
158 typedef instance<Point, Geom_CartesianPoint, gp_Pnt> CartesianPoint;
160 typedef subBase_gp<basic, gp_Vec> Vector;
161 typedef instance<Vector, Geom_Direction , gp_Dir> Direction;
162 typedef instance<Vector, Geom_VectorWithMagnitude, gp_Vec> VectorWithMagnitude;
164 typedef subBase_gp<basic, gp_Ax1> AxisPlacement;
165 typedef instance<AxisPlacement, Geom_Axis1Placement, gp_Ax1> Axis1Placement;
166 typedef instance<AxisPlacement, Geom_Axis2Placement> Axis2Placement;
168 typedef instance <SharedBase<Geom_Transformation>,
170 gp_Trsf> Transformation;
172 typedef geometryBase<Geom_Curve> Curve;
173 typedef geometryBase<Geom_Surface> Surface;
176 //! Create a persistent object for a curve
177 Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom_Curve)& theCurve,
178 StdObjMgt_TransientPersistentMap& theMap);
179 //! Create a persistent object for a curve
180 Standard_EXPORT static Handle(Surface) Translate (const Handle(Geom_Surface)& theSurf,
181 StdObjMgt_TransientPersistentMap& theMap);
184 //=======================================================================
186 //=======================================================================
189 inline Standard_CString ShapePersistent_Geom::subBase_empty<ShapePersistent_Geom::basic>
190 ::PName() const { return "PGeom_Point"; }
192 //=======================================================================
194 //=======================================================================
197 inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::Point,
200 ::PName() const { return "PGeom_CartesianPoint"; }
203 inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::Point,
206 ::Write(StdObjMgt_WriteData& theWriteData) const
208 Handle(Geom_CartesianPoint) aMyGeom =
209 Handle(Geom_CartesianPoint)::DownCast(myTransient);
210 theWriteData << aMyGeom->Pnt();
213 //=======================================================================
215 //=======================================================================
218 inline Standard_CString ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::basic,
220 ::PName() const { return "PGeom_Vector"; }
222 //=======================================================================
224 //=======================================================================
227 inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::Direction,
230 ::PName() const { return "PGeom_Direction"; }
233 inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::Direction,
236 ::Write(StdObjMgt_WriteData& theWriteData) const
238 Handle(Geom_Direction) aMyGeom =
239 Handle(Geom_Direction)::DownCast(myTransient);
240 theWriteData << aMyGeom->Dir();
243 //=======================================================================
244 // VectorWithMagnitude
245 //=======================================================================
248 inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::VectorWithMagnitude,
249 Geom_VectorWithMagnitude,
251 ::PName() const { return "PGeom_VectorWithMagnitude"; }
254 inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::VectorWithMagnitude,
255 Geom_VectorWithMagnitude,
257 ::Write(StdObjMgt_WriteData& theWriteData) const
259 Handle(Geom_VectorWithMagnitude) aMyGeom =
260 Handle(Geom_VectorWithMagnitude)::DownCast(myTransient);
261 theWriteData << aMyGeom->Vec();
264 //=======================================================================
266 //=======================================================================
269 inline Standard_CString ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::basic,
271 ::PName() const { return "PGeom_AxisPlacement"; }
273 //=======================================================================
275 //=======================================================================
278 inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::Axis1Placement,
281 ::PName() const { return "PGeom_Axis1Placement"; }
284 inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::Axis1Placement,
287 ::Write(StdObjMgt_WriteData& theWriteData) const
289 Handle(Geom_Axis1Placement) aMyGeom =
290 Handle(Geom_Axis1Placement)::DownCast(myTransient);
291 write(theWriteData, aMyGeom->Ax1());
294 //=======================================================================
296 //=======================================================================
299 inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::AxisPlacement,
301 ::PName() const { return "PGeom_Axis2Placement"; }
304 inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::AxisPlacement,
306 ::Read (StdObjMgt_ReadData& theReadData)
311 theReadData >> anAxis >> anXDirection;
313 myTransient = new Geom_Axis2Placement(anAxis.Location(),
319 inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::AxisPlacement,
321 ::Write (StdObjMgt_WriteData& theWriteData) const
323 Handle(Geom_Axis2Placement) aMyGeom =
324 Handle(Geom_Axis2Placement)::DownCast(myTransient);
325 const gp_Ax1& anAxis = aMyGeom->Axis();
326 const gp_Dir& anXDirection = aMyGeom->Direction();
327 write(theWriteData, anAxis) << anXDirection;
330 //=======================================================================
332 //=======================================================================
335 inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::Transformation,
338 ::PName() const { return "PGeom_Transformation"; }
341 inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::Transformation,
344 ::Write (StdObjMgt_WriteData& theWriteData) const
346 theWriteData << myTransient->Trsf();
349 //=======================================================================
351 //=======================================================================
354 inline Standard_CString ShapePersistent_Geom::geometryBase<Geom_Geometry>
355 ::PName() const { return "PGeom_Geometry"; }
357 //=======================================================================
359 //=======================================================================
362 inline Standard_CString ShapePersistent_Geom::geometryBase<Geom_Curve>
363 ::PName() const { return "PGeom_Curve"; }
365 //=======================================================================
367 //=======================================================================
370 inline Standard_CString ShapePersistent_Geom::geometryBase<Geom_Surface>
371 ::PName() const { return "PGeom_Surface"; }