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 #include "MEDMEM_DriverFactory.hxx"
21 #include "MEDMEM_MedMedDriver.hxx"
22 #include "MEDMEM_MedMeshDriver.hxx"
23 #include "MEDMEM_Mesh.hxx"
24 #include "MEDMEM_GibiMeshDriver.hxx"
25 #include "MEDMEM_PorflowMeshDriver.hxx"
26 #include "MEDMEM_VtkMeshDriver.hxx"
27 #include "MEDMEM_VtkMedDriver.hxx"
29 #include "MEDMEM_Exception.hxx"
31 #include "MEDMEM_MedVersion.hxx"
32 #include "MEDMEM_Compatibility21_22.hxx"
33 #include "MEDMEM_MedMedDriver21.hxx"
34 #include "MEDMEM_MedMedDriver22.hxx"
35 #include "MEDMEM_MedMeshDriver21.hxx"
36 #include "MEDMEM_MedMeshDriver22.hxx"
38 using namespace MEDMEM;
39 using namespace MED_EN;
42 void MEDMEM::fill<-1,0x3>(double *a, const double *b)
47 bool MEDMEM::compare<-1>(const double *a, const double *b)
52 MED_EN::medFileVersion DRIVERFACTORY::globalMedFileVersionForWriting = MED_EN::V22;
54 medFileVersion DRIVERFACTORY::getMedFileVersionForWriting()
56 return DRIVERFACTORY::globalMedFileVersionForWriting;
59 void DRIVERFACTORY::setMedFileVersionForWriting(medFileVersion version)
61 DRIVERFACTORY::globalMedFileVersionForWriting = version;
64 GENDRIVER *DRIVERFACTORY::buildDriverForMesh(driverTypes driverType,
65 const std::string & fileName,
67 const string & driverName,
68 med_mode_acces access)
77 ret = new MED_MESH_RDONLY_DRIVER(fileName, mesh);
78 ret->setMeshName(driverName);
82 ret = new MED_MESH_WRONLY_DRIVER(fileName, mesh);
83 ret->setMeshName(driverName);
87 ret = new MED_MESH_RDWR_DRIVER(fileName, mesh);
88 ret->setMeshName(driverName);
92 throw MED_EXCEPTION ("access type has not been properly specified to the method");
101 ret=new GIBI_MESH_RDONLY_DRIVER(fileName,mesh);
105 throw MED_EXCEPTION ("access mode other than MED_LECT has been specified with the GIBI_DRIVER type which is not allowed because GIBI_DRIVER is only a read access driver");
108 throw MED_EXCEPTION ("access mode other than MED_LECT has been specified with the GIBI_DRIVER type which is not allowed because GIBI_DRIVER is only a read access driver");
111 throw MED_EXCEPTION ("access type has not been properly specified to the method");
116 case PORFLOW_DRIVER : {
120 ret=new PORFLOW_MESH_RDONLY_DRIVER(fileName,mesh);
124 throw MED_EXCEPTION ("access mode other than MED_LECT has been specified with the PORFLOW_DRIVER type which is not allowed because PORFLOW_DRIVER is only a read access driver");
127 throw MED_EXCEPTION ("access mode other than MED_LECT has been specified with the PORFLOW_DRIVER type which is not allowed because PORFLOW_DRIVER is only a read access driver");
130 throw MED_EXCEPTION ("access type has not been properly specified to the method");
139 throw MED_EXCEPTION ("access mode other than MED_ECRI or MED_REMPT has been specified with the VTK_DRIVER type which is not allowed because VTK_DRIVER is only a write access driver");
142 ret=new VTK_MESH_DRIVER(fileName,mesh);
146 ret=new VTK_MESH_DRIVER(fileName,mesh);
150 throw MED_EXCEPTION ("access type has not been properly specified to the method");
156 throw MED_EXCEPTION ("NO_DRIVER has been specified to the method which is not allowed");
159 throw MED_EXCEPTION ("other driver than MED_DRIVER GIBI_DRIVER PORFLOW_DRIVER and VT_DRIVER has been specified to the method which is not allowed");
163 GENDRIVER *DRIVERFACTORY::buildDriverForMed(driverTypes driverType,
164 const std::string & fileName,
165 MED *med, med_mode_acces access)
175 ret=new MED_MED_RDONLY_DRIVER(fileName,med);
179 ret=new MED_MED_WRONLY_DRIVER(fileName,med);
183 ret=new MED_MED_RDONLY_DRIVER(fileName,med);
187 throw MED_EXCEPTION ("access type has not been properly specified to the method");
196 throw MED_EXCEPTION ("access mode other than MED_ECRI or MED_REMPT has been specified with the VTK_DRIVER type which is not allowed because VTK_DRIVER is only a write access driver");
199 ret=new VTK_MED_DRIVER(fileName,med);
203 ret=new VTK_MED_DRIVER(fileName,med);
207 throw MED_EXCEPTION ("access type has not been properly specified to the method");
213 throw MED_EXCEPTION ("GIBI_DRIVER has been specified to the method which is not allowed because there is no GIBI driver for the MED object");
217 case PORFLOW_DRIVER : {
218 throw MED_EXCEPTION ("PORFLOW_DRIVER has been specified to the method which is not allowed because there is no PORFLOW driver for the MED object");
223 throw MED_EXCEPTION ("NO_DRIVER has been specified to the method which is not allowed");
227 throw MED_EXCEPTION ("NO_DRIVER has been specified to the method which is not allowed");
232 GENDRIVER * DRIVERFACTORY::buildMedDriverFromFile(const string & fileName,
234 MED_EN::med_mode_acces access)
236 medFileVersion version;
240 version = getMedFileVersion(fileName);
242 catch (MEDEXCEPTION & ex)
244 version = DRIVERFACTORY::globalMedFileVersionForWriting;
247 MESSAGE("buildMedDriverFromFile version of the file " << version);
255 driver = new MED_MED_RDONLY_DRIVER21(fileName,ptrMed);
256 else if (version == V22)
257 driver = new MED_MED_RDONLY_DRIVER22(fileName,ptrMed);
262 driver = new MED_MED_WRONLY_DRIVER21(fileName,ptrMed);
263 else if (version == V22)
264 driver = new MED_MED_WRONLY_DRIVER22(fileName,ptrMed);
269 driver = new MED_MED_RDWR_DRIVER21(fileName,ptrMed);
270 else if (version == V22)
271 driver = new MED_MED_RDWR_DRIVER22(fileName,ptrMed);
275 throw MED_EXCEPTION ("access type has not been properly specified to the method");
279 GENDRIVER * DRIVERFACTORY::buildMeshDriverFromFile(const string & fileName,
281 MED_EN::med_mode_acces access)
283 medFileVersion version;
287 version = getMedFileVersion(fileName);
289 catch (MEDEXCEPTION & ex)
291 version = DRIVERFACTORY::globalMedFileVersionForWriting;
294 MESSAGE("buildMeshDriverFromFile version of the file " << version);
302 driver = new MED_MESH_RDONLY_DRIVER21(fileName,ptrMesh);
303 else if (version == V22)
304 driver = new MED_MESH_RDONLY_DRIVER22(fileName,ptrMesh);
309 driver = new MED_MESH_WRONLY_DRIVER21(fileName,ptrMesh);
310 else if (version == V22)
311 driver = new MED_MESH_WRONLY_DRIVER22(fileName,ptrMesh);
316 driver = new MED_MESH_RDWR_DRIVER21(fileName,ptrMesh);
317 else if (version == V22)
318 driver = new MED_MESH_RDWR_DRIVER22(fileName,ptrMesh);
322 throw MED_EXCEPTION ("access type has not been properly specified to the method");
326 GENDRIVER * DRIVERFACTORY::buildConcreteMedDriverForMesh(const std::string & fileName,
327 MESH *ptrMesh,const string & driverName,
328 MED_EN::med_mode_acces access,
329 MED_EN::medFileVersion version)
333 MESSAGE("buildConcreteMedDriverForMesh version of the file " << version);
339 driver = new MED_MESH_RDONLY_DRIVER21(fileName,ptrMesh);
340 else if (version == V22)
341 driver = new MED_MESH_RDONLY_DRIVER22(fileName,ptrMesh);
342 driver->setMeshName(driverName);
347 driver = new MED_MESH_WRONLY_DRIVER21(fileName,ptrMesh);
348 else if (version == V22)
349 driver = new MED_MESH_WRONLY_DRIVER22(fileName,ptrMesh);
350 driver->setMeshName(driverName);
355 driver = new MED_MESH_RDWR_DRIVER21(fileName,ptrMesh);
356 else if (version == V22)
357 driver = new MED_MESH_RDWR_DRIVER22(fileName,ptrMesh);
358 driver->setMeshName(driverName);
362 throw MED_EXCEPTION ("access type has not been properly specified to the method");