0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / ShapePersistent / ShapePersistent_Geom.hxx
CommitLineData
ff205346 1// Copyright (c) 2015 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
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.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14
15#ifndef _ShapePersistent_Geom_HeaderFile
16#define _ShapePersistent_Geom_HeaderFile
17
ec964372 18#include <Standard_NotImplemented.hxx>
19#include <Standard_NullObject.hxx>
20
ff205346 21#include <StdObjMgt_SharedObject.hxx>
ec964372 22#include <StdObjMgt_TransientPersistentMap.hxx>
45d8465e 23
45d8465e 24#include <StdObject_gp_Curves.hxx>
25#include <StdObject_gp_Surfaces.hxx>
26#include <StdObject_gp_Trsfs.hxx>
ff205346 27
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>
ff205346 34#include <Geom_Surface.hxx>
35
ec964372 36class ShapePersistent_Geom : public StdObjMgt_SharedObject
ff205346 37{
38public:
39 class Geometry : public StdObjMgt_Persistent
40 {
41 public:
42 //! Read persistent data from a file.
43 Standard_EXPORT virtual void Read (StdObjMgt_ReadData& theReadData);
ec964372 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
0f57ab75 49 virtual Standard_CString PName() const { return "PGeom_Geometry"; }
ff205346 50 };
51
52protected:
53 template <class Transient>
ec964372 54 struct geometryBase : public DelayedBase<Geometry, Transient>
55 {
56 //! Write persistent data to a file.
0f57ab75 57 virtual void Write (StdObjMgt_WriteData&) const
ec964372 58 {
59 Standard_NotImplemented::Raise("ShapePersistent_Geom::geometryBase::Write - not implemented");
60 }
61 //! Gets persistent child objects
0f57ab75 62 virtual void PChildren (StdObjMgt_Persistent::SequenceOfPersistent&) const { }
ec964372 63 //! Returns persistent type name
0f57ab75 64 virtual Standard_CString PName() const
ec964372 65 {
66 Standard_NotImplemented::Raise("ShapePersistent_Geom::geometryBase::PName - not implemented");
67 return "";
68 }
69 };
ff205346 70
71 template <class Base, class PData>
72 class subBase : public Base
73 {
74 public:
75 //! Read persistent data from a file.
0f57ab75 76 virtual void Read (StdObjMgt_ReadData& theReadData)
ff205346 77 { PData().Read (theReadData); }
ec964372 78 //! Write persistent data to a file.
0f57ab75 79 virtual void Write (StdObjMgt_WriteData& theWriteData) const
ec964372 80 { PData().Write(theWriteData); }
81 //! Gets persistent child objects
0f57ab75 82 virtual void PChildren (StdObjMgt_Persistent::SequenceOfPersistent&) const
ec964372 83 {
84 Standard_NotImplemented::Raise("ShapePersistent_Geom::subBase::PChildren - not implemented");
85 }
86 //! Returns persistent type name
0f57ab75 87 virtual Standard_CString PName() const
ec964372 88 {
89 Standard_NotImplemented::Raise("ShapePersistent_Geom::subBase::PName - not implemented");
90 return "";
91 }
ff205346 92 };
93
94 template <class Base, class GpData>
45d8465e 95 struct subBase_gp : public Base
96 {
97 public:
98 //! Read persistent data from a file.
0f57ab75 99 virtual void Read (StdObjMgt_ReadData&) { }
ec964372 100 //! Write persistent data to a file.
0f57ab75 101 virtual void Write (StdObjMgt_WriteData&) const { }
ec964372 102 //! Gets persistent child objects
0f57ab75 103 virtual void PChildren (StdObjMgt_Persistent::SequenceOfPersistent&) const { }
ec964372 104 //! Returns persistent type name
0f57ab75 105 virtual Standard_CString PName() const
45d8465e 106 {
ec964372 107 Standard_NotImplemented::Raise("ShapePersistent_Geom::subBase_gp::PName - not implemented");
108 return "";
45d8465e 109 }
110 };
ff205346 111
112 template <class Base>
ec964372 113 struct subBase_empty : Base
114 {
115 //! Returns persistent type name
0f57ab75 116 virtual Standard_CString PName() const
ec964372 117 {
118 Standard_NotImplemented::Raise("ShapePersistent_Geom::subBase_empty::PName - not implemented");
119 return "";
120 }
121 };
ff205346 122
123 template <class Base, class Target, class Data = void>
124 class instance : public Base
125 {
126 public:
127 //! Read persistent data from a file.
0f57ab75 128 virtual void Read (StdObjMgt_ReadData& theReadData)
ff205346 129 {
45d8465e 130 Data aData;
ff205346 131 theReadData >> aData;
ec964372 132 this->myTransient = new Target(aData);
133 }
134 //! Gets persistent child objects
0f57ab75 135 virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent&) const { }
ec964372 136 //! Write persistent data to a file.
0f57ab75 137 virtual void Write(StdObjMgt_WriteData&) const
ec964372 138 {
139 Standard_NotImplemented::Raise("ShapePersistent_Geom::instance::Write - not implemented");
140 }
141 //! Returns persistent type name
0f57ab75 142 virtual Standard_CString PName() const
ec964372 143 {
144 Standard_NotImplemented::Raise("ShapePersistent_Geom::instance::PName - not implemented");
145 return "";
ff205346 146 }
147 };
148
149private:
150 typedef geometryBase<Geom_Geometry> basic;
151
152public:
153 typedef subBase_empty<basic> Point;
154 typedef instance<Point, Geom_CartesianPoint, gp_Pnt> CartesianPoint;
155
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;
159
160 typedef subBase_gp<basic, gp_Ax1> AxisPlacement;
161 typedef instance<AxisPlacement, Geom_Axis1Placement, gp_Ax1> Axis1Placement;
162 typedef instance<AxisPlacement, Geom_Axis2Placement> Axis2Placement;
163
164 typedef instance <SharedBase<Geom_Transformation>,
165 Geom_Transformation,
166 gp_Trsf> Transformation;
167
168 typedef geometryBase<Geom_Curve> Curve;
169 typedef geometryBase<Geom_Surface> Surface;
ec964372 170
171public:
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);
ff205346 178};
179
ec964372 180//=======================================================================
181// Point
182//=======================================================================
183
184template<>
185inline Standard_CString ShapePersistent_Geom::subBase_empty<ShapePersistent_Geom::basic>
186 ::PName() const { return "PGeom_Point"; }
187
188//=======================================================================
189// CartesianPoint
190//=======================================================================
191
192template<>
193inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::Point,
194 Geom_CartesianPoint,
195 gp_Pnt>
196 ::PName() const { return "PGeom_CartesianPoint"; }
197
198template<>
199inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::Point,
200 Geom_CartesianPoint,
201 gp_Pnt>
202 ::Write(StdObjMgt_WriteData& theWriteData) const
203{
204 Handle(Geom_CartesianPoint) aMyGeom =
205 Handle(Geom_CartesianPoint)::DownCast(myTransient);
206 theWriteData << aMyGeom->Pnt();
207}
208
209//=======================================================================
210// Vector
211//=======================================================================
212
213template<>
214inline Standard_CString ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::basic,
215 gp_Vec>
216 ::PName() const { return "PGeom_Vector"; }
217
218//=======================================================================
219// Direction
220//=======================================================================
221
222template<>
223inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::Direction,
224 Geom_Direction,
225 gp_Dir>
226 ::PName() const { return "PGeom_Direction"; }
227
228template<>
229inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::Direction,
230 Geom_Direction,
231 gp_Dir>
232 ::Write(StdObjMgt_WriteData& theWriteData) const
233{
234 Handle(Geom_Direction) aMyGeom =
235 Handle(Geom_Direction)::DownCast(myTransient);
236 theWriteData << aMyGeom->Dir();
237}
238
239//=======================================================================
240// VectorWithMagnitude
241//=======================================================================
242
243template<>
244inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::VectorWithMagnitude,
245 Geom_VectorWithMagnitude,
246 gp_Vec>
247 ::PName() const { return "PGeom_VectorWithMagnitude"; }
248
249template<>
250inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::VectorWithMagnitude,
251 Geom_VectorWithMagnitude,
252 gp_Vec>
253 ::Write(StdObjMgt_WriteData& theWriteData) const
254{
255 Handle(Geom_VectorWithMagnitude) aMyGeom =
256 Handle(Geom_VectorWithMagnitude)::DownCast(myTransient);
257 theWriteData << aMyGeom->Vec();
258}
259
260//=======================================================================
261// AxisPlacement
262//=======================================================================
263
264template<>
265inline Standard_CString ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::basic,
266 gp_Ax1>
267 ::PName() const { return "PGeom_AxisPlacement"; }
268
269//=======================================================================
270// Axis1Placement
271//=======================================================================
272
273template<>
274inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::Axis1Placement,
275 Geom_Axis1Placement,
276 gp_Ax1>
277 ::PName() const { return "PGeom_Axis1Placement"; }
278
279template<>
280inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::Axis1Placement,
281 Geom_Axis1Placement,
282 gp_Ax1>
283 ::Write(StdObjMgt_WriteData& theWriteData) const
284{
285 Handle(Geom_Axis1Placement) aMyGeom =
286 Handle(Geom_Axis1Placement)::DownCast(myTransient);
287 write(theWriteData, aMyGeom->Ax1());
288}
289
290//=======================================================================
291// Axis2Placement
292//=======================================================================
293
294template<>
295inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::AxisPlacement,
296 Geom_Axis2Placement>
297 ::PName() const { return "PGeom_Axis2Placement"; }
298
299template<>
300inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::AxisPlacement,
301 Geom_Axis2Placement>
302 ::Read (StdObjMgt_ReadData& theReadData)
303{
304 gp_Ax1 anAxis;
305 gp_Dir anXDirection;
306
307 theReadData >> anAxis >> anXDirection;
308
309 myTransient = new Geom_Axis2Placement(anAxis.Location(),
310 anAxis.Direction(),
311 anXDirection);
312}
313
314template<>
315inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::AxisPlacement,
316 Geom_Axis2Placement>
317 ::Write (StdObjMgt_WriteData& theWriteData) const
318{
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;
324}
325
326//=======================================================================
327// Transformation
328//=======================================================================
329
330template<>
331inline Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::Transformation,
332 Geom_Transformation,
333 gp_Trsf>
334 ::PName() const { return "PGeom_Transformation"; }
335
336template<>
337inline void ShapePersistent_Geom::instance<ShapePersistent_Geom::Transformation,
338 Geom_Transformation,
339 gp_Trsf>
340 ::Write (StdObjMgt_WriteData& theWriteData) const
341{
342 theWriteData << myTransient->Trsf();
343}
344
345//=======================================================================
346// Geometry
347//=======================================================================
348
349template<>
350inline Standard_CString ShapePersistent_Geom::geometryBase<Geom_Geometry>
351 ::PName() const { return "PGeom_Geometry"; }
352
353//=======================================================================
354// Curve
355//=======================================================================
356
357template<>
358inline Standard_CString ShapePersistent_Geom::geometryBase<Geom_Curve>
359 ::PName() const { return "PGeom_Curve"; }
360
361//=======================================================================
362// Surface
363//=======================================================================
364
ff205346 365template<>
ec964372 366inline Standard_CString ShapePersistent_Geom::geometryBase<Geom_Surface>
367 ::PName() const { return "PGeom_Surface"; }
ff205346 368
369#endif