0030675: Visualization - remove redundant proxy classes in hierarchy of PrsMgr_Presen...
[occt.git] / src / ShapePersistent / ShapePersistent_BRep.hxx
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_BRep_HeaderFile
16 #define _ShapePersistent_BRep_HeaderFile
17
18 #include <ShapePersistent_TopoDS.hxx>
19 #include <ShapePersistent_Geom.hxx>
20 #include <ShapePersistent_Geom2d.hxx>
21 #include <ShapePersistent_Poly.hxx>
22 #include <StdObjMgt_TransientPersistentMap.hxx>
23 #include <StdObject_Location.hxx>
24 #include <StdObject_gp_Vectors.hxx>
25
26 #include <BRep_ListOfPointRepresentation.hxx>
27 #include <BRep_ListOfCurveRepresentation.hxx>
28
29 #include <gp_Pnt.hxx>
30 #include <gp_Pnt2d.hxx>
31
32 class BRep_PointRepresentation;
33 class BRep_CurveRepresentation;
34 class TopoDS_Vertex;
35 class TopoDS_Edge;
36 class TopoDS_Face;
37
38 class ShapePersistent_BRep : public ShapePersistent_TopoDS
39 {
40 public:
41   class PointRepresentation : public StdObjMgt_Persistent
42   {
43     friend class ShapePersistent_BRep;
44
45   public:
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 child objects
51     virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const;
52     //! Returns persistent type name
53     virtual Standard_CString PName() const { return "PBRep_PointRepresentation"; }
54     //! Import transient object from the persistent data.
55     Standard_EXPORT void Import (BRep_ListOfPointRepresentation& thePoints) const;
56
57   protected:
58     virtual Handle(BRep_PointRepresentation) import() const;
59
60   protected:
61     StdObject_Location myLocation;
62     Standard_Real      myParameter;
63
64   private:
65     Handle(PointRepresentation) myNext;
66   };
67
68   class PointOnCurve : public PointRepresentation
69   {
70     friend class ShapePersistent_BRep;
71
72   public:
73     virtual void Read (StdObjMgt_ReadData& theReadData);
74     virtual void Write (StdObjMgt_WriteData& theWriteData) const;
75     virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const;
76     virtual Standard_CString PName() const { return "PBRep_PointOnCurve"; }
77     virtual Handle(BRep_PointRepresentation) import() const;
78
79   private:
80     Handle(ShapePersistent_Geom::Curve) myCurve;
81   };
82
83   class PointsOnSurface : public PointRepresentation
84   {
85     friend class ShapePersistent_BRep;
86
87   public:
88     virtual void Read (StdObjMgt_ReadData& theReadData);
89     virtual void Write (StdObjMgt_WriteData& theWriteData) const;
90     virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const;
91     virtual Standard_CString PName() const { return "PBRep_PointsOnSurface"; }
92
93   protected:
94     Handle(ShapePersistent_Geom::Surface) mySurface;
95   };
96
97   class PointOnCurveOnSurface : public PointsOnSurface
98   {
99     friend class ShapePersistent_BRep;
100
101   public:
102     virtual void Read (StdObjMgt_ReadData& theReadData);
103     virtual void Write (StdObjMgt_WriteData& theWriteData) const;
104     virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const;
105     virtual Standard_CString PName() const { return "PBRep_PointOnCurveOnSurface"; }
106     virtual Handle(BRep_PointRepresentation) import() const;
107
108   private:
109     Handle(ShapePersistent_Geom2d::Curve) myPCurve;
110   };
111
112   class PointOnSurface : public PointsOnSurface
113   {
114     friend class ShapePersistent_BRep;
115
116   public:
117     virtual void Read (StdObjMgt_ReadData& theReadData);
118     virtual void Write (StdObjMgt_WriteData& theWriteData) const;
119     virtual Standard_CString PName() const { return "PBRep_PointOnSurface"; }
120     virtual Handle(BRep_PointRepresentation) import() const;
121
122   private:
123     Standard_Real myParameter2;
124   };
125
126   class CurveRepresentation : public StdObjMgt_Persistent
127   {
128     friend class ShapePersistent_BRep;
129
130   public:
131     //! Read persistent data from a file.
132     Standard_EXPORT virtual void Read (StdObjMgt_ReadData& theReadData);
133     //! Write persistent data from a file.
134     Standard_EXPORT virtual void Write (StdObjMgt_WriteData& theWriteData) const;
135     //! Gets persistent child objects
136     virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const;
137     //! Returns persistent type name
138     virtual Standard_CString PName() const { return "PBRep_CurveRepresentation"; }
139     //! Import transient object from the persistent data.
140     Standard_EXPORT void Import (BRep_ListOfCurveRepresentation& theCurves) const;
141
142   protected:
143     virtual Handle(BRep_CurveRepresentation) import() const;
144
145   protected:
146     StdObject_Location myLocation;
147
148   private:
149     Handle(CurveRepresentation) myNext;
150   };
151
152   class GCurve : public CurveRepresentation
153   {
154     friend class ShapePersistent_BRep;
155
156   public:
157     virtual void Read (StdObjMgt_ReadData& theReadData);
158     virtual void Write (StdObjMgt_WriteData& theWriteData) const;
159     virtual Standard_CString PName() const { return "PBRep_GCurve"; }
160
161   protected:
162     Standard_Real myFirst;
163     Standard_Real myLast;
164   };
165
166   class Curve3D : public GCurve
167   {
168     friend class ShapePersistent_BRep;
169
170   public:
171     virtual void Read (StdObjMgt_ReadData& theReadData);
172     virtual void Write (StdObjMgt_WriteData& theWriteData) const;
173     virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const;
174     virtual Standard_CString PName() const { return "PBRep_Curve3D"; }
175     virtual Handle(BRep_CurveRepresentation) import() const;
176
177   private:
178     Handle(ShapePersistent_Geom::Curve) myCurve3D;
179   };
180
181   class CurveOnSurface : public GCurve
182   {
183     friend class ShapePersistent_BRep;
184
185   public:
186     virtual void Read (StdObjMgt_ReadData& theReadData);
187     virtual void Write (StdObjMgt_WriteData& theWriteData) const;
188     virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const;
189     virtual Standard_CString PName() const { return "PBRep_CurveOnSurface"; }
190     virtual Handle(BRep_CurveRepresentation) import() const;
191
192   protected:
193     Handle(ShapePersistent_Geom2d::Curve) myPCurve;
194     Handle(ShapePersistent_Geom::Surface) mySurface;
195     gp_Pnt2d                              myUV1;
196     gp_Pnt2d                              myUV2;
197   };
198
199   class CurveOnClosedSurface : public CurveOnSurface
200   {
201     friend class ShapePersistent_BRep;
202
203   public:
204     virtual void Read (StdObjMgt_ReadData& theReadData);
205     virtual void Write (StdObjMgt_WriteData& theWriteData) const;
206     virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const;
207     virtual Standard_CString PName() const { return "PBRep_CurveOnClosedSurface"; }
208     virtual Handle(BRep_CurveRepresentation) import() const;
209
210   private:
211     Handle(ShapePersistent_Geom2d::Curve) myPCurve2;
212     Standard_Integer                      myContinuity;
213     gp_Pnt2d                              myUV21;
214     gp_Pnt2d                              myUV22;
215   };
216
217   class Polygon3D : public CurveRepresentation
218   {
219     friend class ShapePersistent_BRep;
220
221   public:
222     virtual void Read (StdObjMgt_ReadData& theReadData);
223     virtual void Write (StdObjMgt_WriteData& theWriteData) const;
224     virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const;
225     virtual Standard_CString PName() const { return "PBRep_Polygon3D"; }
226     virtual Handle(BRep_CurveRepresentation) import() const;
227
228   private:
229     Handle(ShapePersistent_Poly::Polygon3D) myPolygon3D;
230   };
231
232   class PolygonOnTriangulation : public CurveRepresentation
233   {
234     friend class ShapePersistent_BRep;
235
236   public:
237     virtual void Read (StdObjMgt_ReadData& theReadData);
238     virtual void Write (StdObjMgt_WriteData& theWriteData) const;
239     virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const;
240     virtual Standard_CString PName() const { return "PBRep_PolygonOnTriangulation"; }
241     virtual Handle(BRep_CurveRepresentation) import() const;
242
243   protected:
244     Handle(ShapePersistent_Poly::PolygonOnTriangulation) myPolygon;
245     Handle(ShapePersistent_Poly::Triangulation)          myTriangulation;
246   };
247
248   class PolygonOnClosedTriangulation : public PolygonOnTriangulation
249   {
250     friend class ShapePersistent_BRep;
251
252   public:
253     virtual void Read (StdObjMgt_ReadData& theReadData);
254     virtual void Write (StdObjMgt_WriteData& theWriteData) const;
255     virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const;
256     virtual Standard_CString PName() const { return "PBRep_PolygonOnClosedTriangulation"; }
257     virtual Handle(BRep_CurveRepresentation) import() const;
258
259   private:
260     Handle(ShapePersistent_Poly::PolygonOnTriangulation) myPolygon2;
261   };
262
263   class PolygonOnSurface : public CurveRepresentation
264   {
265     friend class ShapePersistent_BRep;
266
267   public:
268     virtual void Read (StdObjMgt_ReadData& theReadData);
269     virtual void Write (StdObjMgt_WriteData& theWriteData) const;
270     virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const;
271     virtual Standard_CString PName() const { return "PBRep_PolygonOnSurface"; }
272     virtual Handle(BRep_CurveRepresentation) import() const;
273
274   protected:
275     Handle(ShapePersistent_Poly::Polygon2D) myPolygon2D;
276     Handle(ShapePersistent_Geom::Surface)   mySurface;
277   };
278
279   class PolygonOnClosedSurface : public PolygonOnSurface
280   {
281     friend class ShapePersistent_BRep;
282
283   public:
284     virtual void Read (StdObjMgt_ReadData& theReadData);
285     virtual void Write (StdObjMgt_WriteData& theWriteData) const;
286     virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const;
287     virtual Standard_CString PName() const { return "PBRep_PolygonOnClosedSurface"; }
288     virtual Handle(BRep_CurveRepresentation) import() const;
289
290   private:
291     Handle(ShapePersistent_Poly::Polygon2D) myPolygon2;
292   };
293
294   class CurveOn2Surfaces : public CurveRepresentation
295   {
296     friend class ShapePersistent_BRep;
297
298   public:
299     virtual void Read (StdObjMgt_ReadData& theReadData);
300     virtual void Write (StdObjMgt_WriteData& theWriteData) const;
301     virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const;
302     virtual Standard_CString PName() const { return "PBRep_CurveOn2Surfaces"; }
303     virtual Handle(BRep_CurveRepresentation) import() const;
304
305   private:
306     Handle(ShapePersistent_Geom::Surface) mySurface;
307     Handle(ShapePersistent_Geom::Surface) mySurface2;
308     StdObject_Location                    myLocation2;
309     Standard_Integer                      myContinuity;
310   };
311
312 private:
313   class pTVertex : public pTBase
314   {
315     friend class ShapePersistent_BRep;
316
317   public:
318     inline void Read (StdObjMgt_ReadData& theReadData)
319     {
320       pTBase::Read (theReadData);
321       theReadData >> myTolerance >> myPnt >> myPoints;
322     }
323     inline void Write (StdObjMgt_WriteData& theWriteData) const
324     {
325       pTBase::Write (theWriteData);
326       theWriteData << myTolerance << myPnt << myPoints;
327     }
328     inline void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const 
329     { 
330       pTBase::PChildren(theChildren);
331       theChildren.Append(myPoints);
332     }
333     inline Standard_CString PName() const 
334       { return "PBRep_TVertex"; }
335
336   private:
337     virtual Handle(TopoDS_TShape) createTShape() const;
338
339   private:
340     Standard_Real               myTolerance;
341     gp_Pnt                      myPnt;
342     Handle(PointRepresentation) myPoints;
343   };
344
345   class pTEdge : public pTBase
346   {
347     friend class ShapePersistent_BRep;
348
349   public:
350     inline void Read (StdObjMgt_ReadData& theReadData)
351     {
352       pTBase::Read (theReadData);
353       theReadData >> myTolerance >> myFlags >> myCurves;
354     }
355     inline void Write (StdObjMgt_WriteData& theWriteData) const
356     {
357       pTBase::Write (theWriteData);
358       theWriteData << myTolerance << myFlags << myCurves;
359     }
360     inline void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const 
361     { 
362       pTBase::PChildren(theChildren);
363       theChildren.Append(myCurves);
364     }
365     inline Standard_CString PName() const 
366       { return "PBRep_TEdge"; }
367
368   private:
369     virtual Handle(TopoDS_TShape) createTShape() const;
370
371   private:
372     Standard_Real               myTolerance;
373     Standard_Integer            myFlags;
374     Handle(CurveRepresentation) myCurves;
375   };
376
377   class pTFace : public pTBase
378   {
379     friend class ShapePersistent_BRep;
380
381   public:
382     inline void Read (StdObjMgt_ReadData& theReadData)
383     {
384       pTBase::Read (theReadData);
385       theReadData >> mySurface >> myTriangulation >> myLocation;
386       theReadData >> myTolerance >> myNaturalRestriction;
387     }
388     inline void Write (StdObjMgt_WriteData& theWriteData) const
389     {
390       pTBase::Write (theWriteData);
391       theWriteData << mySurface << myTriangulation << myLocation;
392       theWriteData << myTolerance << myNaturalRestriction;
393     }
394     inline void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const 
395     {
396       pTBase::PChildren(theChildren);
397       theChildren.Append(mySurface);
398       theChildren.Append(myTriangulation);
399       myLocation.PChildren(theChildren);
400     }
401     inline Standard_CString PName() const
402       { return "PBRep_TFace"; }
403
404   private:
405     virtual Handle(TopoDS_TShape) createTShape() const;
406
407   private:
408     Handle(ShapePersistent_Geom::Surface)       mySurface;
409     Handle(ShapePersistent_Poly::Triangulation) myTriangulation;
410     StdObject_Location                          myLocation;
411     Standard_Real                               myTolerance;
412     Standard_Boolean                            myNaturalRestriction;
413   };
414
415 public:
416   typedef tObject  <pTVertex> TVertex;
417   typedef tObject  <pTEdge>   TEdge;
418   typedef tObject  <pTFace>   TFace;
419
420   typedef tObject1 <pTVertex> TVertex1;
421   typedef tObject1 <pTEdge>   TEdge1;
422   typedef tObject1 <pTFace>   TFace1;
423
424 public:
425   //! Create a persistent object for a vertex
426   Standard_EXPORT static Handle(TVertex::pTObjectT) Translate (const TopoDS_Vertex& theVertex,
427                                                                StdObjMgt_TransientPersistentMap& theMap);
428   //! Create a persistent object for an edge
429   Standard_EXPORT static Handle(TEdge::pTObjectT) Translate (const TopoDS_Edge& theEdge,
430                                                              StdObjMgt_TransientPersistentMap& theMap,
431                                                              ShapePersistent_TriangleMode theTriangleMode);
432   //! Create a persistent object for a face
433   Standard_EXPORT static Handle(TFace::pTObjectT) Translate (const TopoDS_Face& theFace,
434                                                              StdObjMgt_TransientPersistentMap& theMap,
435                                                              ShapePersistent_TriangleMode theTriangleMode);
436   //! Create a persistent object for a point on a 3D curve
437   Standard_EXPORT static Handle(PointOnCurve) Translate(Standard_Real theParam, 
438                                                         const Handle(Geom_Curve)& theCurve, 
439                                                         const TopLoc_Location& theLoc, 
440                                                         StdObjMgt_TransientPersistentMap& theMap);
441   //! Create a persistent object for a point on a 3D curve on a surface
442   Standard_EXPORT static Handle(PointOnCurveOnSurface) Translate (Standard_Real theParam, 
443                                                                   const Handle(Geom2d_Curve)& theCurve, 
444                                                                   const Handle(Geom_Surface)& theSurf, 
445                                                                   const TopLoc_Location& theLoc,
446                                                                   StdObjMgt_TransientPersistentMap& theMap);
447   //! Create a persistent object for a point on a surface
448   Standard_EXPORT static Handle(PointOnSurface) Translate (Standard_Real theParam, 
449                                                            Standard_Real theParam2, 
450                                                            const Handle(Geom_Surface)& theSurf, 
451                                                            const TopLoc_Location& theLoc,
452                                                            StdObjMgt_TransientPersistentMap& theMap);
453   //! Create a persistent object for a curve on a surface
454   Standard_EXPORT static Handle(CurveOnSurface) Translate (const Handle(Geom2d_Curve)& theCurve, 
455                                                            const Standard_Real theFirstParam,
456                                                            const Standard_Real theLastParam, 
457                                                            const Handle(Geom_Surface)& theSurf, 
458                                                            const TopLoc_Location& theLoc,
459                                                            StdObjMgt_TransientPersistentMap& theMap);
460   //! Create a persistent object for a curve on a closed surface
461   Standard_EXPORT static Handle(CurveOnClosedSurface) Translate (const Handle(Geom2d_Curve)& theCurve, 
462                                                                  const Handle(Geom2d_Curve)& theCurve2,
463                                                                  const Standard_Real theFirstParam,
464                                                                  const Standard_Real theLastParam, 
465                                                                  const Handle(Geom_Surface)& theSurf,
466                                                                  const TopLoc_Location& theLoc, 
467                                                                  const GeomAbs_Shape theContinuity,
468                                                                  StdObjMgt_TransientPersistentMap& theMap);
469   //! Create a persistent object for a curve on two surfaces
470   Standard_EXPORT static Handle(CurveOn2Surfaces) Translate (const Handle(Geom_Surface)& theSurf, 
471                                                              const Handle(Geom_Surface)& theSurf2,
472                                                              const TopLoc_Location& theLoc, 
473                                                              const TopLoc_Location& theLoc2,
474                                                              const GeomAbs_Shape theContinuity,
475                                                              StdObjMgt_TransientPersistentMap& theMap);
476   //! Create a persistent object for a 3D curve
477   Standard_EXPORT static Handle(Curve3D) Translate (const Handle(Geom_Curve)& theCurve,
478                                                     const Standard_Real theFirstParam, 
479                                                     const Standard_Real theLastParam,
480                                                     const TopLoc_Location& theLoc,
481                                                     StdObjMgt_TransientPersistentMap& theMap);
482   //! Create a persistent object for a 3D polygon
483   Standard_EXPORT static Handle(Polygon3D) Translate (const Handle(Poly_Polygon3D)& thePoly,
484                                                       const TopLoc_Location& theLoc,
485                                                       StdObjMgt_TransientPersistentMap& theMap);
486   //! Create a persistent object for a polygon on a closed surface
487   Standard_EXPORT static Handle(PolygonOnClosedSurface) Translate (const Handle(Poly_Polygon2D)& thePoly, 
488                                                                    const Handle(Poly_Polygon2D)& thePoly2,
489                                                                    const Handle(Geom_Surface)& theSurf, 
490                                                                    const TopLoc_Location& theLoc,
491                                                                    StdObjMgt_TransientPersistentMap& theMap);
492   //! Create a persistent object for a polygon on a surface
493   Standard_EXPORT static Handle(PolygonOnSurface) Translate (const Handle(Poly_Polygon2D)& thePoly, 
494                                                              const Handle(Geom_Surface)& theSurf,
495                                                              const TopLoc_Location& theLoc, 
496                                                              StdObjMgt_TransientPersistentMap& theMap);
497   //! Create a persistent object for a polygon on a surface
498   Standard_EXPORT static Handle(PolygonOnClosedTriangulation) Translate (const Handle(Poly_PolygonOnTriangulation)& thePolyOnTriang,
499                                                                          const Handle(Poly_PolygonOnTriangulation)& thePolyOnTriang2,
500                                                                          const Handle(Poly_Triangulation)& thePolyTriang,
501                                                                          const TopLoc_Location& theLoc,
502                                                                          StdObjMgt_TransientPersistentMap& theMap);
503   //! Create a persistent object for a polygon on a surface
504   Standard_EXPORT static Handle(PolygonOnTriangulation) Translate (const Handle(Poly_PolygonOnTriangulation)& thePolyOnTriang,
505                                                                    const Handle(Poly_Triangulation)& thePolyTriang,
506                                                                    const TopLoc_Location& theLoc,
507                                                                    StdObjMgt_TransientPersistentMap& theMap);
508 };
509
510 #endif