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 driverTypes DRIVERFACTORY::deduceDriverTypeFromFileName(const std::string & fileName)
66 string extension(fileName);
67 unsigned int pos=extension.rfind('.');
70 extension.erase(0,pos+1);
73 if(extension=="sauve" || extension=="sauv")
75 if(extension=="cnc" || extension=="inp" || extension=="xyz")
76 return PORFLOW_DRIVER;
82 GENDRIVER *DRIVERFACTORY::buildDriverForMesh(driverTypes driverType,
83 const std::string & fileName,
85 const string & driverName,
86 med_mode_acces access)
95 ret = new MED_MESH_RDONLY_DRIVER(fileName, mesh);
96 ret->setMeshName(driverName);
100 ret = new MED_MESH_WRONLY_DRIVER(fileName, mesh);
101 ret->setMeshName(driverName);
105 ret = new MED_MESH_RDWR_DRIVER(fileName, mesh);
106 ret->setMeshName(driverName);
110 throw MED_EXCEPTION ("access type has not been properly specified to the method");
119 ret=new GIBI_MESH_RDONLY_DRIVER(fileName,mesh);
123 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");
126 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");
129 throw MED_EXCEPTION ("access type has not been properly specified to the method");
134 case PORFLOW_DRIVER : {
138 ret=new PORFLOW_MESH_RDONLY_DRIVER(fileName,mesh);
142 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");
145 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");
148 throw MED_EXCEPTION ("access type has not been properly specified to the method");
157 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");
160 ret=new VTK_MESH_DRIVER(fileName,mesh);
164 ret=new VTK_MESH_DRIVER(fileName,mesh);
168 throw MED_EXCEPTION ("access type has not been properly specified to the method");
174 throw MED_EXCEPTION ("NO_DRIVER has been specified to the method which is not allowed");
177 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");
181 GENDRIVER *DRIVERFACTORY::buildDriverForMed(driverTypes driverType,
182 const std::string & fileName,
183 MED *med, med_mode_acces access)
193 ret=new MED_MED_RDONLY_DRIVER(fileName,med);
197 ret=new MED_MED_WRONLY_DRIVER(fileName,med);
201 ret=new MED_MED_RDWR_DRIVER(fileName,med);
205 throw MED_EXCEPTION ("access type has not been properly specified to the method");
214 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");
217 ret=new VTK_MED_DRIVER(fileName,med);
221 ret=new VTK_MED_DRIVER(fileName,med);
225 throw MED_EXCEPTION ("access type has not been properly specified to the method");
231 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");
235 case PORFLOW_DRIVER : {
236 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");
241 throw MED_EXCEPTION ("NO_DRIVER has been specified to the method which is not allowed");
245 throw MED_EXCEPTION ("NO_DRIVER has been specified to the method which is not allowed");
250 GENDRIVER * DRIVERFACTORY::buildMedDriverFromFile(const string & fileName,
252 MED_EN::med_mode_acces access)
254 medFileVersion version;
258 version = getMedFileVersion(fileName);
260 catch (MEDEXCEPTION & ex)
262 version = DRIVERFACTORY::globalMedFileVersionForWriting;
265 MESSAGE("buildMedDriverFromFile version of the file " << version);
273 driver = new MED_MED_RDONLY_DRIVER21(fileName,ptrMed);
274 else if (version == V22)
275 driver = new MED_MED_RDONLY_DRIVER22(fileName,ptrMed);
280 driver = new MED_MED_WRONLY_DRIVER21(fileName,ptrMed);
281 else if (version == V22)
282 driver = new MED_MED_WRONLY_DRIVER22(fileName,ptrMed);
287 driver = new MED_MED_RDWR_DRIVER21(fileName,ptrMed);
288 else if (version == V22)
289 driver = new MED_MED_RDWR_DRIVER22(fileName,ptrMed);
293 throw MED_EXCEPTION ("access type has not been properly specified to the method");
297 GENDRIVER * DRIVERFACTORY::buildMeshDriverFromFile(const string & fileName,
299 MED_EN::med_mode_acces access)
301 medFileVersion version;
305 version = getMedFileVersion(fileName);
307 catch (MEDEXCEPTION & ex)
309 version = DRIVERFACTORY::globalMedFileVersionForWriting;
312 MESSAGE("buildMeshDriverFromFile version of the file " << version);
320 driver = new MED_MESH_RDONLY_DRIVER21(fileName,ptrMesh);
321 else if (version == V22)
322 driver = new MED_MESH_RDONLY_DRIVER22(fileName,ptrMesh);
327 driver = new MED_MESH_WRONLY_DRIVER21(fileName,ptrMesh);
328 else if (version == V22)
329 driver = new MED_MESH_WRONLY_DRIVER22(fileName,ptrMesh);
334 driver = new MED_MESH_RDWR_DRIVER21(fileName,ptrMesh);
335 else if (version == V22)
336 driver = new MED_MESH_RDWR_DRIVER22(fileName,ptrMesh);
340 throw MED_EXCEPTION ("access type has not been properly specified to the method");
344 GENDRIVER * DRIVERFACTORY::buildConcreteMedDriverForMesh(const std::string & fileName,
345 MESH *ptrMesh,const string & driverName,
346 MED_EN::med_mode_acces access,
347 MED_EN::medFileVersion version)
351 MESSAGE("buildConcreteMedDriverForMesh version of the file " << version);
357 driver = new MED_MESH_RDONLY_DRIVER21(fileName,ptrMesh);
358 else if (version == V22)
359 driver = new MED_MESH_RDONLY_DRIVER22(fileName,ptrMesh);
360 driver->setMeshName(driverName);
365 driver = new MED_MESH_WRONLY_DRIVER21(fileName,ptrMesh);
366 else if (version == V22)
367 driver = new MED_MESH_WRONLY_DRIVER22(fileName,ptrMesh);
368 driver->setMeshName(driverName);
373 driver = new MED_MESH_RDWR_DRIVER21(fileName,ptrMesh);
374 else if (version == V22)
375 driver = new MED_MESH_RDWR_DRIVER22(fileName,ptrMesh);
376 driver->setMeshName(driverName);
380 throw MED_EXCEPTION ("access type has not been properly specified to the method");