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