0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / ShapePersistent / ShapePersistent_TopoDS.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_TopoDS_HeaderFile
16#define _ShapePersistent_TopoDS_HeaderFile
17
ec964372 18#include <ShapePersistent_TriangleMode.hxx>
19
ff205346 20#include <StdPersistent_TopoDS.hxx>
21#include <StdPersistent_HArray1.hxx>
22#include <StdLPersistent_HArray1.hxx>
23#include <StdObject_Shape.hxx>
ec964372 24#include <StdObjMgt_TransientPersistentMap.hxx>
ff205346 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
33class ShapePersistent_TopoDS : public StdPersistent_TopoDS
34{
35public:
45d8465e 36 class HShape : public StdObjMgt_Persistent, public StdObject_Shape
ff205346 37 {
38 public:
39 //! Read persistent data from a file.
40 Standard_EXPORT virtual void Read (StdObjMgt_ReadData& theReadData);
ec964372 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
0f57ab75 46 virtual Standard_CString PName() const { return "PTopoDS_HShape"; }
ff205346 47
ff205346 48 private:
45d8465e 49 Handle(StdObjMgt_Persistent) myEntry;
ff205346 50 };
51
52protected:
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
81private:
82 template <class Target>
83 class pTSimple : public pTBase
ec964372 84 {
85 virtual Handle(TopoDS_TShape) createTShape() const;
86 public:
87 inline Standard_CString PName() const;
88 };
ff205346 89
90 template <class Persistent, class ShapesArray>
91 class pTObject : public Persistent
92 {
93 virtual void addShapes (TopoDS_Shape& theParent) const
ec964372 94 { pTBase::addShapesT<ShapesArray> (theParent); }
ff205346 95 };
96
97 template <class Persistent, class ShapesArray>
ec964372 98 struct tObjectT : public Delayed <DelayedBase<TShape, TopoDS_TShape, pTBase>,
99 pTObject<Persistent, ShapesArray> >
100 { typedef pTObject<Persistent, ShapesArray> pTObjectT; };
ff205346 101
102protected:
103 template <class Persistent>
ec964372 104 struct tObject : public tObjectT<Persistent, StdLPersistent_HArray1::Persistent> { };
ff205346 105
106 template <class Persistent>
ec964372 107 struct tObject1 : public tObjectT<Persistent, StdPersistent_HArray1::Shape1> { };
ff205346 108
109public:
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;
ec964372 121
122public:
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);
ff205346 127};
128
ec964372 129template<>
130inline Standard_CString ShapePersistent_TopoDS::pTSimple<TopoDS_TWire>::PName() const
131 { return "PTopoDS_TWire"; }
132
133template<>
134inline Standard_CString ShapePersistent_TopoDS::pTSimple<TopoDS_TShell>::PName() const
135 { return "PTopoDS_TShell"; }
136
137template<>
138inline Standard_CString ShapePersistent_TopoDS::pTSimple<TopoDS_TSolid>::PName() const
139 { return "PTopoDS_TSolid"; }
140
141template<>
142inline Standard_CString ShapePersistent_TopoDS::pTSimple<TopoDS_TCompSolid>::PName() const
143 { return "PTopoDS_TCompSolid"; }
144
145template<>
146inline Standard_CString ShapePersistent_TopoDS::pTSimple<TopoDS_TCompound>::PName() const
147 { return "PTopoDS_TCompound"; }
148
ff205346 149#endif