0030675: Visualization - remove redundant proxy classes in hierarchy of PrsMgr_Presen...
[occt.git] / src / ShapePersistent / ShapePersistent_TopoDS.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_TopoDS_HeaderFile
16 #define _ShapePersistent_TopoDS_HeaderFile
17
18 #include <ShapePersistent_TriangleMode.hxx>
19
20 #include <StdPersistent_TopoDS.hxx>
21 #include <StdPersistent_HArray1.hxx>
22 #include <StdLPersistent_HArray1.hxx>
23 #include <StdObject_Shape.hxx>
24 #include <StdObjMgt_TransientPersistentMap.hxx>
25
26 #include <TopoDS_TWire.hxx>
27 #include <TopoDS_TShell.hxx>
28 #include <TopoDS_TSolid.hxx>
29 #include <TopoDS_TCompSolid.hxx>
30 #include <TopoDS_TCompound.hxx>
31
32
33 class ShapePersistent_TopoDS : public StdPersistent_TopoDS
34 {
35 public:
36   class HShape : public StdObjMgt_Persistent, public StdObject_Shape
37   {
38   public:
39     //! Read persistent data from a file.
40     Standard_EXPORT virtual void Read (StdObjMgt_ReadData& theReadData);
41     //! Write persistent data to a file
42     Standard_EXPORT virtual void Write (StdObjMgt_WriteData& theWriteData) const;
43     //! Gets persistent child objects
44     Standard_EXPORT virtual void PChildren(SequenceOfPersistent& theChildren) const;
45     //! Returns persistent type name
46     virtual Standard_CString PName() const { return "PTopoDS_HShape"; }
47
48   private:
49     Handle(StdObjMgt_Persistent) myEntry;
50   };
51
52 protected:
53   class pTBase : public pTShape
54   {
55   public:
56     inline Handle(TopoDS_TShape) Import() const
57     {
58       Handle(TopoDS_TShape) aTShape = createTShape();
59
60       TopoDS_Shape aWrapperShape;
61       aWrapperShape.TShape (aTShape);
62       addShapes (aWrapperShape);
63
64       setFlags (aTShape);
65
66       return aTShape;
67     }
68
69   private:
70     virtual Handle(TopoDS_TShape) createTShape() const = 0;
71
72     virtual void addShapes (TopoDS_Shape& theParent) const = 0;
73
74     void setFlags (const Handle(TopoDS_TShape)& theTShape) const;
75
76   protected:
77     template <class ShapesArray>
78     void addShapesT (TopoDS_Shape& theParent) const;
79   };
80
81 private:
82   template <class Target>
83   class pTSimple : public pTBase
84   { 
85     virtual Handle(TopoDS_TShape) createTShape() const; 
86   public:
87     inline Standard_CString PName() const;
88   };
89
90   template <class Persistent, class ShapesArray>
91   class pTObject : public Persistent
92   {
93     virtual void addShapes (TopoDS_Shape& theParent) const
94       { pTBase::addShapesT<ShapesArray> (theParent); }
95   };
96
97   template <class Persistent, class ShapesArray>
98   struct tObjectT : public Delayed <DelayedBase<TShape, TopoDS_TShape, pTBase>,
99                                     pTObject<Persistent, ShapesArray> > 
100     { typedef pTObject<Persistent, ShapesArray> pTObjectT; };
101
102 protected:
103   template <class Persistent>
104   struct tObject : public tObjectT<Persistent, StdLPersistent_HArray1::Persistent> { };
105
106   template <class Persistent>
107   struct tObject1 : public tObjectT<Persistent, StdPersistent_HArray1::Shape1> { };
108
109 public:
110   typedef tObject  <pTSimple<TopoDS_TWire>      > TWire;
111   typedef tObject  <pTSimple<TopoDS_TShell>     > TShell;
112   typedef tObject  <pTSimple<TopoDS_TSolid>     > TSolid;
113   typedef tObject  <pTSimple<TopoDS_TCompSolid> > TCompSolid;
114   typedef tObject  <pTSimple<TopoDS_TCompound>  > TCompound;
115
116   typedef tObject1 <pTSimple<TopoDS_TWire>      > TWire1;
117   typedef tObject1 <pTSimple<TopoDS_TShell>     > TShell1;
118   typedef tObject1 <pTSimple<TopoDS_TSolid>     > TSolid1;
119   typedef tObject1 <pTSimple<TopoDS_TCompSolid> > TCompSolid1;
120   typedef tObject1 <pTSimple<TopoDS_TCompound>  > TCompound1;
121
122 public:
123   //! Create a persistent object for a shape
124   Standard_EXPORT static Handle(HShape) Translate (const TopoDS_Shape& theShape,
125                                                    StdObjMgt_TransientPersistentMap& theMap,
126                                                    ShapePersistent_TriangleMode theTriangleMode);
127 };
128
129 template<>
130 inline Standard_CString ShapePersistent_TopoDS::pTSimple<TopoDS_TWire>::PName() const 
131   { return "PTopoDS_TWire"; }
132
133 template<>
134 inline Standard_CString ShapePersistent_TopoDS::pTSimple<TopoDS_TShell>::PName() const
135   { return "PTopoDS_TShell"; }
136
137 template<>
138 inline Standard_CString ShapePersistent_TopoDS::pTSimple<TopoDS_TSolid>::PName() const
139   { return "PTopoDS_TSolid"; }
140
141 template<>
142 inline Standard_CString ShapePersistent_TopoDS::pTSimple<TopoDS_TCompSolid>::PName() const
143   { return "PTopoDS_TCompSolid"; }
144
145 template<>
146 inline Standard_CString ShapePersistent_TopoDS::pTSimple<TopoDS_TCompound>::PName() const
147   { return "PTopoDS_TCompound"; }
148
149 #endif