1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/
20 #ifndef DRIVERFACTORY_HXX
21 #define DRIVERFACTORY_HXX
23 #include "MEDMEM_MedVersion.hxx"
24 #include "MEDMEM_GenDriver.hxx"
25 #include "MEDMEM_define.hxx"
32 template<class T> class FIELD;
36 namespace DRIVERFACTORY {
39 definition of static variable across the Med Memory of a Med File version
40 for the writing of Med File set to V22
43 extern MED_EN::medFileVersion globalMedFileVersionForWriting;
45 MED_EN::medFileVersion getMedFileVersionForWriting();
47 void setMedFileVersionForWriting(MED_EN::medFileVersion version);
49 GENDRIVER * buildDriverForMesh(driverTypes driverType,
50 const std::string & fileName,
51 MESH *mesh,const string & driverName,
52 MED_EN::med_mode_acces access);
54 GENDRIVER * buildDriverForField(driverTypes driverType,
55 const std::string & fileName,
57 MED_EN::med_mode_acces access);
58 GENDRIVER * buildDriverForMed(driverTypes driverType,
59 const std::string & fileName,
61 MED_EN::med_mode_acces access);
62 GENDRIVER * buildMedDriverFromFile(const string & fileName,
64 MED_EN::med_mode_acces access);
65 GENDRIVER * buildMeshDriverFromFile(const string & fileName,
67 MED_EN::med_mode_acces access);
69 GENDRIVER * buildFieldDriverFromFile(const string & fileName,
71 MED_EN::med_mode_acces access);
72 GENDRIVER * buildConcreteMedDriverForMesh(const std::string & fileName,
74 const string & driverName,
75 MED_EN::med_mode_acces access,
76 MED_EN::medFileVersion version);
78 GENDRIVER * buildConcreteMedDriverForField(const std::string & fileName,
80 MED_EN::med_mode_acces access,
81 MED_EN::medFileVersion version);
85 #include "MEDMEM_VtkFieldDriver.hxx"
86 #include "MEDMEM_MedFieldDriver.hxx"
87 #include "MEDMEM_MedFieldDriver21.hxx"
88 #include "MEDMEM_MedFieldDriver22.hxx"
89 #include "MEDMEM_AsciiFieldDriver.hxx"
93 GENDRIVER * DRIVERFACTORY::buildDriverForField(driverTypes driverType,
94 const std::string & fileName,
96 MED_EN::med_mode_acces access)
104 case MED_EN::MED_LECT : {
105 ret = new MED_FIELD_RDONLY_DRIVER<T>(fileName,field);
108 case MED_EN::MED_ECRI : {
109 ret= new MED_FIELD_WRONLY_DRIVER<T>(fileName,field);
112 case MED_EN::MED_REMP : {
113 ret = new MED_FIELD_RDWR_DRIVER<T>(fileName,field);
117 throw MED_EXCEPTION ("access type has not been properly specified to the method");
125 case MED_EN::MED_LECT : {
126 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");
129 case MED_EN::MED_ECRI : {
130 ret=new VTK_FIELD_DRIVER<T>(fileName,field);
133 case MED_EN::MED_REMP : {
134 ret=new VTK_FIELD_DRIVER<T>(fileName,field);
138 throw MED_EXCEPTION ("access type has not been properly specified to the method");
144 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");
148 case PORFLOW_DRIVER : {
149 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");
153 case ASCII_DRIVER : {
156 case MED_EN::MED_ECRI : {
157 ret=new ASCII_FIELD_DRIVER<T>(fileName,field);
161 throw MED_EXCEPTION ("driver ASCII_DRIVER on FIELD only in write mod");
167 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");
171 MED_EXCEPTION ("driverType other than MED_DRIVER and VTK_DRIVER has been specified to the method which is not allowed for the object FIELD");
177 GENDRIVER * DRIVERFACTORY::buildFieldDriverFromFile(const string & fileName,
179 MED_EN::med_mode_acces access)
181 MED_EN::medFileVersion version;
185 version = getMedFileVersion(fileName);
187 catch (MEDEXCEPTION & ex)
189 version = DRIVERFACTORY::globalMedFileVersionForWriting;
192 MESSAGE("buildFieldDriverFromFile version of the file " << version);
198 case MED_EN::MED_LECT : {
199 if (version == MED_EN::V21)
200 driver = new MED_FIELD_RDONLY_DRIVER21<T>(fileName,ptrField);
201 else if (version == MED_EN::V22)
202 driver = new MED_FIELD_RDONLY_DRIVER22<T>(fileName,ptrField);
205 case MED_EN::MED_ECRI : {
206 if (version == MED_EN::V21)
207 driver = new MED_FIELD_WRONLY_DRIVER21<T>(fileName,ptrField);
208 else if (version == MED_EN::V22)
209 driver = new MED_FIELD_WRONLY_DRIVER22<T>(fileName,ptrField);
212 case MED_EN::MED_REMP : {
213 if (version == MED_EN::V21)
214 driver = new MED_FIELD_RDWR_DRIVER21<T>(fileName,ptrField);
215 else if (version == MED_EN::V22)
216 driver = new MED_FIELD_RDWR_DRIVER22<T>(fileName,ptrField);
220 throw MED_EXCEPTION ("access type has not been properly specified to the method");
225 GENDRIVER * DRIVERFACTORY::buildConcreteMedDriverForField(const std::string & fileName,
227 MED_EN::med_mode_acces access,
228 MED_EN::medFileVersion version)
231 MESSAGE("buildConcreteMedDriverForField version of the file " << version);
237 case MED_EN::MED_LECT : {
238 if (version == MED_EN::V21)
239 driver = new MED_FIELD_RDONLY_DRIVER21<T>(fileName,ptrField);
240 else if (version == MED_EN::V22)
241 driver = new MED_FIELD_RDONLY_DRIVER22<T>(fileName,ptrField);
244 case MED_EN::MED_ECRI : {
245 if (version == MED_EN::V21)
246 driver = new MED_FIELD_WRONLY_DRIVER21<T>(fileName,ptrField);
247 else if (version == MED_EN::V22)
248 driver = new MED_FIELD_WRONLY_DRIVER22<T>(fileName,ptrField);
251 case MED_EN::MED_REMP : {
252 if (version == MED_EN::V21)
253 driver = new MED_FIELD_RDWR_DRIVER21<T>(fileName,ptrField);
254 else if (version == MED_EN::V22)
255 driver = new MED_FIELD_RDWR_DRIVER22<T>(fileName,ptrField);
259 throw MED_EXCEPTION ("access type has not been properly specified to the method");