1 // Copyright (C) 2007-2012 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
23 #include "MEDMEM_DriverFactory.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"
33 #include "MEDMEM_Exception.hxx"
35 #include "MEDMEM_MedVersion.hxx"
36 #include "MEDMEM_MedMeshDriver.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 bool DRIVERFACTORY::globalVtkBinaryFormatForWriting = false;
54 bool DRIVERFACTORY::getVtkBinaryFormatForWriting()
56 return globalVtkBinaryFormatForWriting;
59 void DRIVERFACTORY::setVtkBinaryFormatForWriting(bool isBinary)
61 globalVtkBinaryFormatForWriting = isBinary;
64 driverTypes DRIVERFACTORY::deduceDriverTypeFromFileName(const std::string & fileName)
66 string extension(fileName);
67 string::size_type 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;
80 return ENSIGHT_DRIVER;
84 GENDRIVER *DRIVERFACTORY::buildDriverForMesh(driverTypes driverType,
85 const std::string & fileName,
87 const string & driverName,
88 med_mode_acces access)
97 ret = new MED_MESH_RDONLY_DRIVER(fileName, mesh);
98 ret->setMeshName(driverName);
102 ret = new MED_MESH_WRONLY_DRIVER(fileName, mesh, access);
103 ret->setMeshName(driverName);
107 ret = new MED_MESH_RDWR_DRIVER(fileName, mesh);
108 ret->setMeshName(driverName);
112 throw MED_EXCEPTION ("access type has not been properly specified to the method");
118 if ( mesh->getIsAGrid() )
119 throw MED_EXCEPTION("GIBI file can contain unstructured mesh only, not a GRID");
123 ret=new GIBI_MESH_RDONLY_DRIVER(fileName,(MESH*)mesh);
127 ret=new GIBI_MESH_RDWR_DRIVER(fileName,(MESH*)mesh);
131 ret=new GIBI_MESH_WRONLY_DRIVER(fileName,(MESH*)mesh);
135 throw MED_EXCEPTION ("access type has not been properly specified to the method");
140 case PORFLOW_DRIVER : {
141 if ( mesh->getIsAGrid() )
142 throw MED_EXCEPTION("PORFLOW file can contain unstructured mesh only, not a GRID");
146 ret=new PORFLOW_MESH_RDONLY_DRIVER(fileName,(MESH*)mesh);
151 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");
154 throw MED_EXCEPTION ("access type has not been properly specified to the method");
159 case ENSIGHT_DRIVER : {
160 if ( mesh->getIsAGrid() )
161 throw MED_EXCEPTION("EnSight driver reads unstructured mesh, not a GRID");
165 ret=new ENSIGHT_MESH_RDONLY_DRIVER(fileName,(MESH*)mesh);
169 ret=new ENSIGHT_MESH_WRONLY_DRIVER(fileName,(MESH*)mesh);
173 throw MED_EXCEPTION ("not yet implemented");
177 throw MED_EXCEPTION ("access type has not been properly specified to the method");
186 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");
190 ret=new VTK_MESH_DRIVER(fileName,mesh);
195 throw MED_EXCEPTION ("access type has not been properly specified to the method");
201 throw MED_EXCEPTION ("NO_DRIVER has been specified to the method 1 which is not allowed");
204 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");
208 GENDRIVER * DRIVERFACTORY::buildMeshDriverFromFile(const string & fileName,
210 MED_EN::med_mode_acces access)
212 medFileVersion version = MED_EN::V22;
216 version = getMedFileVersion(fileName);
218 catch (MEDEXCEPTION & ex)
222 MESSAGE_MED("buildMeshDriverFromFile version of the file " << version);
224 if (version == MED_EN::V21)
225 throw MED_EXCEPTION ("med-2.1 files are no more supported");
227 GENDRIVER * driver=0;
232 driver = new MED_MESH_RDONLY_DRIVER(fileName,ptrMesh);
236 driver = new MED_MESH_WRONLY_DRIVER(fileName,ptrMesh,access);
240 driver = new MED_MESH_RDWR_DRIVER(fileName,ptrMesh);
244 throw MED_EXCEPTION ("access type has not been properly specified to the method");
249 GENDRIVER * DRIVERFACTORY::buildConcreteMedDriverForMesh(const std::string & fileName,
251 const string & driverName,
252 MED_EN::med_mode_acces access,
253 MED_EN::medFileVersion version)
255 GENDRIVER * driver=0;
257 MESSAGE_MED("buildConcreteMedDriverForMesh version of the file " << version);
259 if (version == MED_EN::V21)
260 throw MED_EXCEPTION ("med-2.1 files are no more supported");
265 driver = new MED_MESH_RDONLY_DRIVER(fileName,ptrMesh);
266 driver->setMeshName(driverName);
270 driver = new MED_MESH_WRONLY_DRIVER(fileName,ptrMesh);
271 driver->setMeshName(driverName);
275 driver = new MED_MESH_RDWR_DRIVER(fileName,ptrMesh);
276 driver->setMeshName(driverName);
280 throw MED_EXCEPTION ("access type has not been properly specified to the method");