Salome HOME
3d3f986c06ccea7b1ff0b3e113ddc5e19e222899
[modules/med.git] / src / MEDMEM / MEDMEM_MedFieldDriver.hxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef MED_FIELD_DRIVER_HXX
24 #define MED_FIELD_DRIVER_HXX
25
26 #include "MEDMEM_GenDriver.hxx"
27
28 namespace MEDMEM {
29 template <class T> class MED_FIELD_RDWR_DRIVER;
30 template <class T> class MED_FIELD_RDONLY_DRIVER;
31 template <class T> class MED_FIELD_WRONLY_DRIVER;
32
33 /*!
34
35   Driver Med for FIELD.
36
37   Generic part : implement open and close methods.
38
39 */
40
41 template <class T> class MED_FIELD_DRIVER : public GENDRIVER
42 {
43 protected:
44   // Developement plus propre :
45   // - Il faudrait soit utiliser le type FIELD_ et ajouter à cette classe
46   //   les accesseurs de FIELD<> utilisées dans les drivers
47   // - Ou bien avoir des drivers à deux paramètres template (le top)
48   // - Remarquez l'affreux cast dans le second constructeur :
49   //      _ptrField( (FIELD<T> *) ptrField )
50   //   Cela cast toujours le ptrField en FullInterlace
51   //   Cela ne pose cependant pas de pb de fonctionement aux drivers
52   FIELD<T> *       _ptrField;
53   std::string      _fieldName;
54   int              _fieldNum;
55   med_2_3::med_idt _medIdt;
56
57 public :
58
59   MED_FIELD_DRIVER();
60
61   template <class INTERLACING_TAG>
62   MED_FIELD_DRIVER(const std::string &         fileName,
63                    FIELD<T, INTERLACING_TAG> * ptrField,
64                    MED_EN::med_mode_acces      accessMode);
65
66   MED_FIELD_DRIVER(const MED_FIELD_DRIVER & fieldDriver);
67
68   virtual ~MED_FIELD_DRIVER();
69
70   virtual void open() throw (MEDEXCEPTION);
71   virtual void close();
72   virtual void write( void ) const = 0 ;
73   virtual void read ( void ) = 0 ;
74   /*!
75     Set the name of the FIELD asked in file.
76
77     It could be different than the name of the FIELD object.
78   */
79   virtual void   setFieldName(const std::string & fieldName) { _fieldName = fieldName; }
80   /*!
81     Get the name of the FIELD asked in file.
82   */
83   virtual std::string getFieldName() const { return _fieldName; }
84
85 protected:
86   virtual GENDRIVER * copy ( void ) const = 0 ;
87
88   bool createFieldSupportPart1(med_2_3::med_idt        id,
89                                const std::string &     fieldName,
90                                med_2_3::med_int        ndt,
91                                med_2_3::med_int        od,
92                                SUPPORT &               support,
93                                std::string &           meshName,
94                                std::vector<int> &      numberOfElementsOfTypeC,
95                                std::vector<int> &      numberOfGaussPoint,
96                                std::vector<std::string>& gaussModelName,
97                                std::vector<std::string>& profilName,
98                                int &                   totalNumberOfElWg,
99                                MED_EN::medEntityMesh & fieldMedFileEntity,
100                                MED_EN::medEntityMesh   preferEntity=MED_EN::MED_ALL_ENTITIES
101                                ) const throw (MEDEXCEPTION);
102
103   void getMeshGeometricTypeFromFile(med_2_3::med_idt      id,
104                                     std::string &              meshName,
105                                     MED_EN::medEntityMesh entite,
106                                     std::vector<MED_EN::medGeometryElement> & geoType,
107                                     std::vector<int> &         nbOfElOfType,
108                                     std::vector<int> &         nbOfElOfTypeC
109                                     ) const throw(MEDEXCEPTION);
110
111   void getMeshGeometricTypeFromMESH( const GMESH * meshPtr,
112                                      MED_EN::medEntityMesh  entity,
113                                      std::vector<MED_EN::medGeometryElement> & geoType,
114                                      std::vector<int> &nbOfElOfType,
115                                      std::vector<int> &nbOfElOfTypeC
116                                      ) const throw(MEDEXCEPTION);
117
118   int getMeshDimensionFromFile(med_2_3::med_idt id, const string & meshName) const;
119         
120   MED_EN::medEntityMesh getMEDMEMEntityFromMEDType(MED_EN::medGeometryElement type,
121                                                    int                        mesh_dim) const;
122
123 };
124
125 /*!
126
127   Driver Med for FIELD : Read only.
128
129   Implement read method.
130
131 */
132
133 template <class T> class MED_FIELD_RDONLY_DRIVER : public virtual MED_FIELD_DRIVER<T>
134 {
135 public :
136
137   MED_FIELD_RDONLY_DRIVER();
138
139   template <class INTERLACING_TAG>
140   MED_FIELD_RDONLY_DRIVER(const string &              fileName,
141                           FIELD<T, INTERLACING_TAG> * ptrField);
142
143   MED_FIELD_RDONLY_DRIVER(const MED_FIELD_RDONLY_DRIVER & fieldDriver);
144
145   virtual ~MED_FIELD_RDONLY_DRIVER() {};
146
147   void write( void ) const throw (MEDEXCEPTION) ;
148   void read ( void ) throw (MEDEXCEPTION) ;
149
150 private:
151   GENDRIVER * copy( void ) const ;
152
153 };
154
155 /*!
156
157   Driver Med for FIELD : Write only.
158
159   Implement write method.
160
161 */
162
163 template <class T> class MED_FIELD_WRONLY_DRIVER : public virtual MED_FIELD_DRIVER<T>
164 {
165 public :
166
167   MED_FIELD_WRONLY_DRIVER();
168
169   template <class INTERLACING_TAG>
170   MED_FIELD_WRONLY_DRIVER(const string &              fileName,
171                           FIELD<T, INTERLACING_TAG> * ptrField);
172
173   MED_FIELD_WRONLY_DRIVER(const MED_FIELD_WRONLY_DRIVER & fieldDriver);
174
175   virtual ~MED_FIELD_WRONLY_DRIVER();
176
177   /*!
178     Write FIELD in the specified file.
179   */
180   void write( void ) const throw (MEDEXCEPTION) ;
181   /*!
182     Return a MEDEXCEPTION : it is the write-only driver.
183   */
184   void read ( void ) throw (MEDEXCEPTION) ;
185
186 private:
187   GENDRIVER * copy( void ) const ;
188
189 };
190
191
192 /*!
193
194   Driver Med for FIELD : Read write.
195   - Use read method from MED_FIELD_RDONLY_DRIVER
196   - Use write method from MED_FIELD_WDONLY_DRIVER
197
198 */
199
200 template <class T> class MED_FIELD_RDWR_DRIVER : public MED_FIELD_RDONLY_DRIVER<T>, public MED_FIELD_WRONLY_DRIVER<T>
201 {
202 public :
203
204   MED_FIELD_RDWR_DRIVER();
205
206   template <class INTERLACING_TAG>
207   MED_FIELD_RDWR_DRIVER(const string &              fileName,
208                         FIELD<T, INTERLACING_TAG> * ptrField);
209
210   MED_FIELD_RDWR_DRIVER(const MED_FIELD_RDWR_DRIVER & fieldDriver);
211
212   /*!
213     Destructor.
214   */
215   ~MED_FIELD_RDWR_DRIVER();
216
217   /*!
218     Write FIELD in the specified file.
219   */
220   void write(void) const throw (MEDEXCEPTION) ;
221   /*!
222     Read FIELD in the specified file.
223   */
224   void read (void) throw (MEDEXCEPTION) ;
225
226 private:
227   GENDRIVER * copy( void ) const ;
228
229 };
230
231 } //End namespace MEDMEM
232
233 // implementation
234 #include "MEDMEM_MedFieldDriver.txx"
235
236 #endif /* MED_FIELD_DRIVER_HXX */