1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #ifndef DRIVERFACTORY_HXX
23 #define DRIVERFACTORY_HXX
27 #include "MEDMEM_MedVersion.hxx"
28 #include "MEDMEM_GenDriver.hxx"
29 #include "MEDMEM_define.hxx"
31 #include "MEDMEM_FieldForward.hxx"
41 namespace DRIVERFACTORY {
44 definition of static variable across the Med Memory of a Med File version
45 for the writing of Med File set to V22
48 MEDMEM_EXPORT extern MED_EN::medFileVersion globalMedFileVersionForWriting;
50 MEDMEM_EXPORT MED_EN::medFileVersion getMedFileVersionForWriting();
52 MEDMEM_EXPORT void setMedFileVersionForWriting(MED_EN::medFileVersion version);
54 MEDMEM_EXPORT driverTypes deduceDriverTypeFromFileName(const std::string & fileName);
56 driverTypes deduceDriverTypeFromFileName(const std::string & fileName);
58 GENDRIVER * buildDriverForMesh(driverTypes driverType,
59 const std::string & fileName,
60 MESH *mesh,const string & driverName,
61 MED_EN::med_mode_acces access);
63 template<class T, class INTERLACING_TAG>
64 GENDRIVER * buildDriverForField(driverTypes driverType,
65 const std::string & fileName,
66 FIELD<T,INTERLACING_TAG> *fielde,
67 MED_EN::med_mode_acces access);
68 GENDRIVER * buildDriverForMed(driverTypes driverType,
69 const std::string & fileName,
71 MED_EN::med_mode_acces access);
72 GENDRIVER * buildMedDriverFromFile(const string & fileName,
74 MED_EN::med_mode_acces access);
75 GENDRIVER * buildMeshDriverFromFile(const string & fileName,
77 MED_EN::med_mode_acces access);
78 template<class T, class INTERLACING_TAG>
79 GENDRIVER * buildFieldDriverFromFile(const string & fileName,
80 FIELD<T,INTERLACING_TAG> * ptrField,
81 MED_EN::med_mode_acces access);
82 GENDRIVER * buildConcreteMedDriverForMesh(const std::string & fileName,
84 const string & driverName,
85 MED_EN::med_mode_acces access,
86 MED_EN::medFileVersion version);
87 template<class T, class INTERLACING_TAG>
88 GENDRIVER * buildConcreteMedDriverForField(const std::string & fileName,
89 FIELD<T,INTERLACING_TAG> *fielde,
90 MED_EN::med_mode_acces access,
91 MED_EN::medFileVersion version);
95 #include "MEDMEM_VtkFieldDriver.hxx"
96 #include "MEDMEM_MedFieldDriver.hxx"
97 #include "MEDMEM_MedFieldDriver21.hxx"
98 #include "MEDMEM_MedFieldDriver22.hxx"
99 #include "MEDMEM_AsciiFieldDriver.hxx"
100 #include "MEDMEM_EnsightFieldDriver.hxx"
103 template<class T, class INTERLACING_TAG>
104 GENDRIVER * DRIVERFACTORY::buildDriverForField(driverTypes driverType,
105 const std::string & fileName,
106 FIELD<T,INTERLACING_TAG> *field,
107 MED_EN::med_mode_acces access)
115 case MED_EN::RDONLY : {
116 ret = new MED_FIELD_RDONLY_DRIVER<T>(fileName,field);
119 case MED_EN::WRONLY : {
120 ret= new MED_FIELD_WRONLY_DRIVER<T>(fileName,field);
123 case MED_EN::RDWR : {
124 ret = new MED_FIELD_RDWR_DRIVER<T>(fileName,field);
128 throw MED_EXCEPTION ("access type has not been properly specified to the method");
133 case ENSIGHT_DRIVER : {
136 case MED_EN::RDONLY : {
137 ret = new ENSIGHT_FIELD_RDONLY_DRIVER(fileName,field);
140 case MED_EN::WRONLY : {
141 ret=new ENSIGHT_FIELD_WRONLY_DRIVER(fileName,field);
144 case MED_EN::RDWR : {
145 throw MED_EXCEPTION ("not yet implemented");
149 throw MED_EXCEPTION ("access type has not been properly specified to the method");
157 case MED_EN::RDONLY : {
158 throw MED_EXCEPTION ("access mode other than MED_ECRI and MED_REMP has been specified with the VTK_DRIVER type which is not allowed because VTK_DRIVER is only a write access driver");
161 case MED_EN::WRONLY : {
162 ret=new VTK_FIELD_DRIVER<T>(fileName,field);
165 case MED_EN::RDWR : {
166 ret=new VTK_FIELD_DRIVER<T>(fileName,field);
170 throw MED_EXCEPTION ("access type has not been properly specified to the method");
176 throw MED_EXCEPTION ("driverType other than MED_DRIVER and VTK_DRIVER has been specified to the method which is not allowed for the object FIELD");
180 case PORFLOW_DRIVER : {
181 throw MED_EXCEPTION ("driverType other than MED_DRIVER and VTK_DRIVER has been specified to the method which is not allowed for the object FIELD");
185 case ASCII_DRIVER : {
188 case MED_EN::WRONLY : {
189 ret=new ASCII_FIELD_DRIVER<T>(fileName,field);
193 throw MED_EXCEPTION ("driver ASCII_DRIVER on FIELD only in write mod");
199 throw MED_EXCEPTION ("driverType other than MED_DRIVER and VTK_DRIVER has been specified to the method which is not allowed for the object FIELD");
203 MED_EXCEPTION ("driverType other than MED_DRIVER and VTK_DRIVER has been specified to the method which is not allowed for the object FIELD");
208 template<class T, class INTERLACING_TAG>
209 GENDRIVER * DRIVERFACTORY::buildFieldDriverFromFile(const string & fileName,
210 FIELD<T,INTERLACING_TAG> * ptrField,
211 MED_EN::med_mode_acces access)
213 MED_EN::medFileVersion version;
217 version = getMedFileVersion(fileName);
219 catch (MEDEXCEPTION & )
221 version = DRIVERFACTORY::globalMedFileVersionForWriting;
224 MESSAGE_MED("buildFieldDriverFromFile version of the file " << version);
230 case MED_EN::RDONLY : {
231 if (version == MED_EN::V21)
232 driver = new MED_FIELD_RDONLY_DRIVER21<T>(fileName,ptrField);
233 else if (version == MED_EN::V22)
234 driver = new MED_FIELD_RDONLY_DRIVER22<T>(fileName,ptrField);
237 case MED_EN::WRONLY : {
238 if (version == MED_EN::V21)
239 driver = new MED_FIELD_WRONLY_DRIVER21<T>(fileName,ptrField);
240 else if (version == MED_EN::V22)
241 driver = new MED_FIELD_WRONLY_DRIVER22<T>(fileName,ptrField);
244 case MED_EN::RDWR : {
245 if (version == MED_EN::V21)
246 driver = new MED_FIELD_RDWR_DRIVER21<T>(fileName,ptrField);
247 else if (version == MED_EN::V22)
248 driver = new MED_FIELD_RDWR_DRIVER22<T>(fileName,ptrField);
252 throw MED_EXCEPTION ("access type has not been properly specified to the method");
256 template<class T, class INTERLACING_TAG>
257 GENDRIVER * DRIVERFACTORY::buildConcreteMedDriverForField(const std::string & fileName,
258 FIELD<T,INTERLACING_TAG> *ptrField,
259 MED_EN::med_mode_acces access,
260 MED_EN::medFileVersion version)
263 MESSAGE_MED("buildConcreteMedDriverForField version of the file " << version);
269 case MED_EN::RDONLY : {
270 if (version == MED_EN::V21)
271 driver = new MED_FIELD_RDONLY_DRIVER21<T>(fileName,ptrField);
272 else if (version == MED_EN::V22)
273 driver = new MED_FIELD_RDONLY_DRIVER22<T>(fileName,ptrField);
276 case MED_EN::WRONLY : {
277 if (version == MED_EN::V21)
278 driver = new MED_FIELD_WRONLY_DRIVER21<T>(fileName,ptrField);
279 else if (version == MED_EN::V22)
280 driver = new MED_FIELD_WRONLY_DRIVER22<T>(fileName,ptrField);
283 case MED_EN::RDWR : {
284 if (version == MED_EN::V21)
285 driver = new MED_FIELD_RDWR_DRIVER21<T>(fileName,ptrField);
286 else if (version == MED_EN::V22)
287 driver = new MED_FIELD_RDWR_DRIVER22<T>(fileName,ptrField);
291 throw MED_EXCEPTION ("access type has not been properly specified to the method");