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 #include "MEDMEM_DriverFactory.hxx"
23 #include "MEDMEM_MedMedDriver.hxx"
24 #include "MEDMEM_MedMeshDriver.hxx"
25 #include "MEDMEM_Mesh.hxx"
26 #include "MEDMEM_GibiMeshDriver.hxx"
27 #include "MEDMEM_PorflowMeshDriver.hxx"
28 #include "MEDMEM_VtkMeshDriver.hxx"
29 #include "MEDMEM_VtkMedDriver.hxx"
30 #include "MEDMEM_EnsightFieldDriver.hxx"
31 #include "MEDMEM_EnsightMeshDriver.hxx"
32 #include "MEDMEM_EnsightMedDriver.hxx"
34 #include "MEDMEM_Exception.hxx"
36 #include "MEDMEM_MedVersion.hxx"
37 #include "MEDMEM_Compatibility21_22.hxx"
38 #include "MEDMEM_MedMedDriver21.hxx"
39 #include "MEDMEM_MedMedDriver22.hxx"
40 #include "MEDMEM_MedMeshDriver21.hxx"
41 #include "MEDMEM_MedMeshDriver22.hxx"
43 using namespace MEDMEM;
44 using namespace MED_EN;
47 void MEDMEM::fill<-1,0x3>(double *a, const double *b)
52 bool MEDMEM::compare<-1>(const double *a, const double *b)
57 MED_EN::medFileVersion DRIVERFACTORY::globalMedFileVersionForWriting = MED_EN::V22;
59 medFileVersion DRIVERFACTORY::getMedFileVersionForWriting()
61 return DRIVERFACTORY::globalMedFileVersionForWriting;
64 void DRIVERFACTORY::setMedFileVersionForWriting(medFileVersion version)
66 DRIVERFACTORY::globalMedFileVersionForWriting = version;
69 driverTypes DRIVERFACTORY::deduceDriverTypeFromFileName(const std::string & fileName)
71 string extension(fileName);
72 string::size_type pos=extension.rfind('.');
75 extension.erase(0,pos+1);
78 if(extension=="sauve" || extension=="sauv")
80 if(extension=="cnc" || extension=="inp" || extension=="xyz")
81 return PORFLOW_DRIVER;
85 return ENSIGHT_DRIVER;
89 GENDRIVER *DRIVERFACTORY::buildDriverForMesh(driverTypes driverType,
90 const std::string & fileName,
92 const string & driverName,
93 med_mode_acces access)
102 ret = new MED_MESH_RDONLY_DRIVER(fileName, mesh);
103 ret->setMeshName(driverName);
107 ret = new MED_MESH_WRONLY_DRIVER(fileName, mesh, access);
108 ret->setMeshName(driverName);
112 ret = new MED_MESH_RDWR_DRIVER(fileName, mesh);
113 ret->setMeshName(driverName);
117 throw MED_EXCEPTION ("access type has not been properly specified to the method");
126 ret=new GIBI_MESH_RDONLY_DRIVER(fileName,mesh);
131 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");
134 throw MED_EXCEPTION ("access type has not been properly specified to the method");
139 case PORFLOW_DRIVER : {
143 ret=new PORFLOW_MESH_RDONLY_DRIVER(fileName,mesh);
148 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");
151 throw MED_EXCEPTION ("access type has not been properly specified to the method");
156 case ENSIGHT_DRIVER : {
160 ret=new ENSIGHT_MESH_RDONLY_DRIVER(fileName,mesh);
164 ret=new ENSIGHT_MESH_WRONLY_DRIVER(fileName,mesh);
168 throw MED_EXCEPTION ("not yet implemented");
172 throw MED_EXCEPTION ("access type has not been properly specified to the method");
181 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");
185 ret=new VTK_MESH_DRIVER(fileName,mesh);
190 throw MED_EXCEPTION ("access type has not been properly specified to the method");
196 throw MED_EXCEPTION ("NO_DRIVER has been specified to the method 1 which is not allowed");
199 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");
203 GENDRIVER *DRIVERFACTORY::buildDriverForMed(driverTypes driverType,
204 const std::string & fileName,
205 MED *med, med_mode_acces access)
215 ret=new MED_MED_RDONLY_DRIVER(fileName,med);
219 ret=new MED_MED_WRONLY_DRIVER(fileName,med);
223 ret=new MED_MED_RDWR_DRIVER(fileName,med);
227 throw MED_EXCEPTION ("access type has not been properly specified to the method");
236 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");
239 ret=new VTK_MED_DRIVER(fileName,med);
243 ret=new VTK_MED_DRIVER(fileName,med);
247 throw MED_EXCEPTION ("access type has not been properly specified to the method");
252 case ENSIGHT_DRIVER : {
256 ret=new ENSIGHT_MED_RDONLY_DRIVER(fileName,med);
260 ret=new ENSIGHT_MED_WRONLY_DRIVER(fileName,med);
264 throw MED_EXCEPTION ("not yet implemented");
268 throw MED_EXCEPTION ("access type has not been properly specified to the method");
274 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");
278 case PORFLOW_DRIVER : {
279 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");
284 throw MED_EXCEPTION ("NO_DRIVER has been specified to the method 2 which is not allowed");
288 throw MED_EXCEPTION ("NO_DRIVER has been specified to the method 3 which is not allowed");
293 GENDRIVER * DRIVERFACTORY::buildMedDriverFromFile(const string & fileName,
295 MED_EN::med_mode_acces access)
297 medFileVersion version;
301 version = getMedFileVersion(fileName);
303 catch (MEDEXCEPTION & ex)
305 version = DRIVERFACTORY::globalMedFileVersionForWriting;
308 MESSAGE_MED("buildMedDriverFromFile version of the file " << version);
316 driver = new MED_MED_RDONLY_DRIVER21(fileName,ptrMed);
317 else if (version == V22)
318 driver = new MED_MED_RDONLY_DRIVER22(fileName,ptrMed);
323 driver = new MED_MED_WRONLY_DRIVER21(fileName,ptrMed);
324 else if (version == V22)
325 driver = new MED_MED_WRONLY_DRIVER22(fileName,ptrMed);
330 driver = new MED_MED_RDWR_DRIVER21(fileName,ptrMed);
331 else if (version == V22)
332 driver = new MED_MED_RDWR_DRIVER22(fileName,ptrMed);
336 throw MED_EXCEPTION ("access type has not been properly specified to the method");
340 GENDRIVER * DRIVERFACTORY::buildMeshDriverFromFile(const string & fileName,
342 MED_EN::med_mode_acces access)
344 medFileVersion version;
348 version = getMedFileVersion(fileName);
350 catch (MEDEXCEPTION & ex)
352 version = DRIVERFACTORY::globalMedFileVersionForWriting;
355 MESSAGE_MED("buildMeshDriverFromFile version of the file " << version);
363 driver = new MED_MESH_RDONLY_DRIVER21(fileName,ptrMesh);
364 else if (version == V22)
365 driver = new MED_MESH_RDONLY_DRIVER22(fileName,ptrMesh);
370 driver = new MED_MESH_WRONLY_DRIVER21(fileName,ptrMesh);
371 else if (version == V22)
372 driver = new MED_MESH_WRONLY_DRIVER22(fileName,ptrMesh,access);
377 driver = new MED_MESH_RDWR_DRIVER21(fileName,ptrMesh);
378 else if (version == V22)
379 driver = new MED_MESH_RDWR_DRIVER22(fileName,ptrMesh);
383 throw MED_EXCEPTION ("access type has not been properly specified to the method");
387 GENDRIVER * DRIVERFACTORY::buildConcreteMedDriverForMesh(const std::string & fileName,
388 MESH *ptrMesh,const string & driverName,
389 MED_EN::med_mode_acces access,
390 MED_EN::medFileVersion version)
394 MESSAGE_MED("buildConcreteMedDriverForMesh version of the file " << version);
400 driver = new MED_MESH_RDONLY_DRIVER21(fileName,ptrMesh);
401 else if (version == V22)
402 driver = new MED_MESH_RDONLY_DRIVER22(fileName,ptrMesh);
403 driver->setMeshName(driverName);
408 driver = new MED_MESH_WRONLY_DRIVER21(fileName,ptrMesh);
409 else if (version == V22)
410 driver = new MED_MESH_WRONLY_DRIVER22(fileName,ptrMesh);
411 driver->setMeshName(driverName);
416 driver = new MED_MESH_RDWR_DRIVER21(fileName,ptrMesh);
417 else if (version == V22)
418 driver = new MED_MESH_RDWR_DRIVER22(fileName,ptrMesh);
419 driver->setMeshName(driverName);
423 throw MED_EXCEPTION ("access type has not been properly specified to the method");