Salome HOME
sources v1.2
[modules/med.git] / src / MEDMEM / MEDMEM_MedMeshDriver.hxx
1 //  MED MEDMEM : MED files in memory
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : MEDMEM_MedMeshDriver.hxx
25 //  Module : MED
26
27 #ifndef MED_MESH_DRIVER_HXX
28 #define MED_MESH_DRIVER_HXX
29
30 #include <string>
31 #include <vector>
32 #include "MEDMEM_define.hxx"
33 #include "MEDMEM_GenDriver.hxx"
34
35 #include "MEDMEM_STRING.hxx"
36 #include "MEDMEM_Exception.hxx"
37 #include "utilities.h"
38
39 class MESH;
40 class FAMILY;
41 class GROUP;
42 class CONNECTIVITY;
43
44 /*!
45
46   Driver Med for MESH.
47
48   Generic part : implement open and close methods.
49
50 */
51
52 class MED_MESH_DRIVER : public GENDRIVER
53 {
54 protected:
55   
56   MESH *   _ptrMesh;
57   MED_FR::med_idt        _medIdt;
58   string         _meshName;    // const ?
59   int            _meshNum;     // INUTILE ?
60   
61 public :
62
63   // all MED cell type
64   static const MED_FR::med_geometrie_element all_cell_type[MED_NBR_GEOMETRIE_MAILLE];
65   
66   static const char * const all_cell_type_tab [MED_NBR_GEOMETRIE_MAILLE];
67
68   /*!
69     Constructor.
70   */
71   MED_MESH_DRIVER() ;
72   /*!
73     Constructor.
74   */
75   MED_MESH_DRIVER(const string & fileName,  
76                   MESH * ptrMesh, 
77                   med_mode_acces accessMode) ;
78   /*!
79     Copy constructor.
80   */
81   MED_MESH_DRIVER(const MED_MESH_DRIVER & driver) ;
82
83   /*!
84     Destructor.
85   */
86   virtual ~MED_MESH_DRIVER() ;
87
88   void open() throw (MEDEXCEPTION);
89   void close() throw (MEDEXCEPTION);
90
91   virtual void write( void ) const = 0 ;
92   virtual void read ( void ) = 0 ;
93
94   /*!
95     Set the name of the MESH asked in file.
96
97     It could be different than the name of the MESH object.
98   */
99   void   setMeshName(const string & meshName) ;
100   /*!
101     Get the name of the MESH asked in file.
102   */
103   string getMeshName() const ;
104
105 private:
106   virtual GENDRIVER * copy ( void ) const = 0 ;
107
108 };
109
110 /*!
111
112   Driver Med for MESH : Read only.
113
114   Implement read method.
115
116 */
117
118 class MED_MESH_RDONLY_DRIVER : public virtual MED_MESH_DRIVER
119 {
120  
121 public :
122   
123   /*!
124     Constructor.
125   */
126   MED_MESH_RDONLY_DRIVER() ;
127   /*!
128     Constructor.
129   */
130   MED_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh) ;
131   /*!
132     Copy constructor.
133   */
134   MED_MESH_RDONLY_DRIVER(const MED_MESH_RDONLY_DRIVER & driver) ;
135
136   /*!
137     Destructor.
138   */
139   virtual ~MED_MESH_RDONLY_DRIVER() ;
140   
141   // CREER UNE METHODE POUR LIRE LA LISTE DES MAILLAGES .....
142
143   /*!
144     Return a MEDEXCEPTION : it is the read-only driver.
145   */
146   void write( void ) const throw (MEDEXCEPTION);
147   /*!
148     Read MESH in the specified file.
149   */
150   void read ( void ) throw (MEDEXCEPTION);
151
152 private:
153   int getCOORDINATE();
154   int getCONNECTIVITY();
155   int getFAMILY();
156   int getNodalConnectivity(CONNECTIVITY * Connectivity) ;
157   int getDescendingConnectivity(CONNECTIVITY * Connectivity) ;
158   int getNodesFamiliesNumber(int * MEDArrayNodeFamily) ;
159   int getCellsFamiliesNumber(int** Arrays, CONNECTIVITY* Connectivity) ;
160   void updateFamily() ;
161   void buildAllGroups(vector<GROUP*> & Groups, vector<FAMILY*> & Families) ;
162   void getGRID ();
163
164   GENDRIVER * copy ( void ) const ;
165
166 };
167
168 /*!
169
170   Driver Med for MESH : Write only.
171
172   Implement write method.
173
174 */
175
176 class MED_MESH_WRONLY_DRIVER : public virtual MED_MESH_DRIVER {
177   
178 public :
179   
180   /*!
181     Constructor.
182   */
183   MED_MESH_WRONLY_DRIVER() ;
184   /*!
185     Constructor.
186   */
187   MED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh) ;
188   /*!
189     Copy constructor.
190   */
191   MED_MESH_WRONLY_DRIVER(const MED_MESH_WRONLY_DRIVER & driver) ;
192
193   /*!
194     Destructor.
195   */
196   virtual ~MED_MESH_WRONLY_DRIVER() ;
197
198   /*!
199     Write MESH in the specified file.
200   */
201   void write( void ) const throw (MEDEXCEPTION);
202   /*!
203     Return a MEDEXCEPTION : it is the write-only driver.
204   */
205   void read ( void ) throw (MEDEXCEPTION);
206
207 private:
208   int writeCoordinates    ()                           const;
209   int writeConnectivities (medEntityMesh entity)       const;
210   int writeFamilyNumbers  ()                           const;
211   int writeFamilies       (vector<FAMILY*> & families) const;
212   int writeGRID() const;
213
214   GENDRIVER * copy ( void ) const ;
215 };
216
217
218 /*!
219
220   Driver Med for MESH : Read write.
221   - Use read method from MED_MESH_RDONLY_DRIVER
222   - Use write method from MED_MESH_WRONLY_DRIVER
223
224 */
225
226 class MED_MESH_RDWR_DRIVER : public MED_MESH_RDONLY_DRIVER, public MED_MESH_WRONLY_DRIVER {
227
228 public :
229
230   /*!
231     Constructor.
232   */
233   MED_MESH_RDWR_DRIVER() ;
234   /*!
235     Constructor.
236   */
237   MED_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh) ;
238   /*!
239     Copy constructor.
240   */
241   MED_MESH_RDWR_DRIVER(const MED_MESH_RDWR_DRIVER & driver) ;
242
243   /*!
244     Destructor.
245   */
246   ~MED_MESH_RDWR_DRIVER() ;
247
248   /*!
249     Write MESH in the specified file.
250   */
251   void write(void) const throw (MEDEXCEPTION);
252   /*!
253     Read MESH in the specified file.
254   */
255   void read (void) throw (MEDEXCEPTION);
256
257 private:
258   GENDRIVER * copy(void) const ;
259
260 };
261
262 #endif /* MED_MESH_DRIVER_HXX */