Salome HOME
Merging with the MAN_SALOME2 branch
[modules/med.git] / src / MEDMEM / MEDMEM_MedMeshDriver.hxx
1 #ifndef MED_MESH_DRIVER_HXX
2 #define MED_MESH_DRIVER_HXX
3
4 #include <string>
5 #include <vector>
6 #include "MEDMEM_define.hxx"
7 #include "MEDMEM_GenDriver.hxx"
8
9 #include "MEDMEM_STRING.hxx"
10 #include "MEDMEM_Exception.hxx"
11 #include "utilities.h"
12
13 /*!
14
15   Driver Med for MESH.
16
17   Generic part : implement open and close methods.
18
19 */
20
21 namespace MEDMEM {
22 class MESH;
23 class FAMILY;
24 class GROUP;
25 class CONNECTIVITY;
26 class MED_MESH_DRIVER : public GENDRIVER
27 {
28 protected:
29   
30   MESH *   _ptrMesh;
31   MED_FR::med_idt        _medIdt;
32   string         _meshName;    // const ?
33   int            _meshNum;     // INUTILE ?
34   
35 public :
36
37   // all MED cell type
38   static const MED_FR::med_geometrie_element all_cell_type[MED_NBR_GEOMETRIE_MAILLE];
39   
40   static const char * const all_cell_type_tab [MED_NBR_GEOMETRIE_MAILLE];
41
42   /*!
43     Constructor.
44   */
45   MED_MESH_DRIVER() ;
46   /*!
47     Constructor.
48   */
49   MED_MESH_DRIVER(const string & fileName,  
50                   MESH * ptrMesh, 
51                   med_mode_acces accessMode) ;
52   /*!
53     Copy constructor.
54   */
55   MED_MESH_DRIVER(const MED_MESH_DRIVER & driver) ;
56
57   /*!
58     Destructor.
59   */
60   virtual ~MED_MESH_DRIVER() ;
61
62   void open() throw (MEDEXCEPTION);
63   void close() throw (MEDEXCEPTION);
64
65   virtual void write( void ) const = 0 ;
66   virtual void read ( void ) = 0 ;
67
68   /*!
69     Set the name of the MESH asked in file.
70
71     It could be different than the name of the MESH object.
72   */
73   void   setMeshName(const string & meshName) ;
74   /*!
75     Get the name of the MESH asked in file.
76   */
77   string getMeshName() const ;
78
79 private:
80   virtual GENDRIVER * copy ( void ) const = 0 ;
81
82 };
83
84 /*!
85
86   Driver Med for MESH : Read only.
87
88   Implement read method.
89
90 */
91
92 class MED_MESH_RDONLY_DRIVER : public virtual MED_MESH_DRIVER
93 {
94  
95 public :
96   
97   /*!
98     Constructor.
99   */
100   MED_MESH_RDONLY_DRIVER() ;
101   /*!
102     Constructor.
103   */
104   MED_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh) ;
105   /*!
106     Copy constructor.
107   */
108   MED_MESH_RDONLY_DRIVER(const MED_MESH_RDONLY_DRIVER & driver) ;
109
110   /*!
111     Destructor.
112   */
113   virtual ~MED_MESH_RDONLY_DRIVER() ;
114   
115   // CREER UNE METHODE POUR LIRE LA LISTE DES MAILLAGES .....
116
117   /*!
118     Return a MEDEXCEPTION : it is the read-only driver.
119   */
120   void write( void ) const throw (MEDEXCEPTION);
121   /*!
122     Read MESH in the specified file.
123   */
124   void read ( void ) throw (MEDEXCEPTION);
125
126 private:
127   int getCOORDINATE();
128   int getCONNECTIVITY();
129   int getFAMILY();
130   int getNodalConnectivity(CONNECTIVITY * Connectivity) ;
131   int getDescendingConnectivity(CONNECTIVITY * Connectivity) ;
132   int getNodesFamiliesNumber(int * MEDArrayNodeFamily) ;
133   int getCellsFamiliesNumber(int** Arrays, CONNECTIVITY* Connectivity) ;
134   void updateFamily() ;
135   void buildAllGroups(vector<GROUP*> & Groups, vector<FAMILY*> & Families) ;
136   void getGRID ();
137
138   GENDRIVER * copy ( void ) const ;
139
140 };
141
142 /*!
143
144   Driver Med for MESH : Write only.
145
146   Implement write method.
147
148 */
149
150 class MED_MESH_WRONLY_DRIVER : public virtual MED_MESH_DRIVER {
151   
152 public :
153   
154   /*!
155     Constructor.
156   */
157   MED_MESH_WRONLY_DRIVER() ;
158   /*!
159     Constructor.
160   */
161   MED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh) ;
162   /*!
163     Copy constructor.
164   */
165   MED_MESH_WRONLY_DRIVER(const MED_MESH_WRONLY_DRIVER & driver) ;
166
167   /*!
168     Destructor.
169   */
170   virtual ~MED_MESH_WRONLY_DRIVER() ;
171
172   /*!
173     Write MESH in the specified file.
174   */
175   void write( void ) const throw (MEDEXCEPTION);
176   /*!
177     Return a MEDEXCEPTION : it is the write-only driver.
178   */
179   void read ( void ) throw (MEDEXCEPTION);
180
181 private:
182   int writeCoordinates    ()                           const;
183   int writeConnectivities (medEntityMesh entity)       const;
184   int writeFamilyNumbers  ()                           const;
185   int writeFamilies       (vector<FAMILY*> & families) const;
186   int writeGRID() const;
187
188   GENDRIVER * copy ( void ) const ;
189 };
190
191
192 /*!
193
194   Driver Med for MESH : Read write.
195   - Use read method from MED_MESH_RDONLY_DRIVER
196   - Use write method from MED_MESH_WRONLY_DRIVER
197
198 */
199
200 class MED_MESH_RDWR_DRIVER : public MED_MESH_RDONLY_DRIVER, public MED_MESH_WRONLY_DRIVER {
201
202 public :
203
204   /*!
205     Constructor.
206   */
207   MED_MESH_RDWR_DRIVER() ;
208   /*!
209     Constructor.
210   */
211   MED_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh) ;
212   /*!
213     Copy constructor.
214   */
215   MED_MESH_RDWR_DRIVER(const MED_MESH_RDWR_DRIVER & driver) ;
216
217   /*!
218     Destructor.
219   */
220   ~MED_MESH_RDWR_DRIVER() ;
221
222   /*!
223     Write MESH in the specified file.
224   */
225   void write(void) const throw (MEDEXCEPTION);
226   /*!
227     Read MESH in the specified file.
228   */
229   void read (void) throw (MEDEXCEPTION);
230
231 private:
232   GENDRIVER * copy(void) const ;
233
234 };
235 };
236
237 #endif /* MED_MESH_DRIVER_HXX */