Back to index

salome-med  6.5.0
MEDMEM_DriverFactory.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "MEDMEM_DriverFactory.hxx"
00024 #include "MEDMEM_MedMeshDriver.hxx"
00025 #include "MEDMEM_Mesh.hxx"
00026 #include "MEDMEM_GibiMeshDriver.hxx"
00027 #include "MEDMEM_PorflowMeshDriver.hxx"
00028 #include "MEDMEM_VtkMeshDriver.hxx"
00029 #include "MEDMEM_VtkMedDriver.hxx"
00030 #include "MEDMEM_EnsightFieldDriver.hxx"
00031 #include "MEDMEM_EnsightMeshDriver.hxx"
00032 
00033 #include "MEDMEM_Exception.hxx"
00034 
00035 #include "MEDMEM_MedVersion.hxx"
00036 #include "MEDMEM_MedMeshDriver.hxx"
00037 
00038 using namespace MEDMEM;
00039 using namespace MED_EN;
00040 
00041 template<>
00042 void MEDMEM::fill<-1,0x3>(double *a, const double *b)
00043 {
00044 }
00045 
00046 template<>
00047 bool MEDMEM::compare<-1>(const double *a, const double *b)
00048 {
00049   return false;
00050 }
00051 
00052 bool DRIVERFACTORY::globalVtkBinaryFormatForWriting = false;
00053 
00054 bool DRIVERFACTORY::getVtkBinaryFormatForWriting()
00055 {
00056   return globalVtkBinaryFormatForWriting;
00057 }
00058 
00059 void DRIVERFACTORY::setVtkBinaryFormatForWriting(bool isBinary)
00060 {
00061   globalVtkBinaryFormatForWriting = isBinary;
00062 }
00063 
00064 driverTypes DRIVERFACTORY::deduceDriverTypeFromFileName(const std::string & fileName)
00065 {
00066   string extension(fileName);
00067   string::size_type pos=extension.rfind('.');
00068   if(pos==string::npos)
00069     return NO_DRIVER;
00070   extension.erase(0,pos+1);
00071   if(extension=="med")
00072     return MED_DRIVER;
00073   if(extension=="sauve" || extension=="sauv")
00074     return GIBI_DRIVER;
00075   if(extension=="cnc" || extension=="inp" || extension=="xyz")
00076     return PORFLOW_DRIVER;
00077   if(extension=="vtk")
00078     return VTK_DRIVER;
00079   if(extension=="case")
00080     return ENSIGHT_DRIVER;
00081   return NO_DRIVER;
00082 }
00083 
00084 GENDRIVER *DRIVERFACTORY::buildDriverForMesh(driverTypes driverType,
00085                                              const std::string & fileName,
00086                                              GMESH *mesh,
00087                                              const string & driverName,
00088                                              med_mode_acces access)
00089 {
00090   GENDRIVER *ret;
00091   switch(driverType)
00092     {
00093     case MED_DRIVER : {
00094       switch(access)
00095         {
00096         case RDONLY : {
00097           ret = new MED_MESH_RDONLY_DRIVER(fileName, mesh);
00098           ret->setMeshName(driverName);
00099           return ret;
00100         }
00101         case WRONLY : {
00102           ret = new MED_MESH_WRONLY_DRIVER(fileName, mesh, access);
00103           ret->setMeshName(driverName);
00104           return ret;
00105         }
00106         case RDWR : {
00107           ret = new MED_MESH_RDWR_DRIVER(fileName, mesh);
00108           ret->setMeshName(driverName);
00109           return ret;
00110         }
00111         default:
00112           throw MED_EXCEPTION ("access type has not been properly specified to the method");
00113         }
00114       break;
00115     }
00116 
00117     case GIBI_DRIVER : {
00118       if ( mesh->getIsAGrid() )
00119         throw MED_EXCEPTION("GIBI file can contain unstructured mesh only, not a GRID");
00120       switch(access)
00121         {
00122         case RDONLY : {
00123           ret=new GIBI_MESH_RDONLY_DRIVER(fileName,(MESH*)mesh);
00124           return ret;
00125         }
00126         case RDWR :
00127           ret=new GIBI_MESH_RDWR_DRIVER(fileName,(MESH*)mesh);
00128           return ret;
00129           
00130         case WRONLY :{
00131           ret=new GIBI_MESH_WRONLY_DRIVER(fileName,(MESH*)mesh);
00132           return ret;
00133         }
00134         default:
00135           throw MED_EXCEPTION ("access type has not been properly specified to the method");
00136         }
00137       break;
00138     }
00139 
00140     case PORFLOW_DRIVER : {
00141       if ( mesh->getIsAGrid() )
00142         throw MED_EXCEPTION("PORFLOW file can contain unstructured mesh only, not a GRID");
00143       switch(access)
00144         {
00145         case RDONLY : {
00146           ret=new PORFLOW_MESH_RDONLY_DRIVER(fileName,(MESH*)mesh);
00147           return ret;
00148         }
00149         case RDWR :
00150         case WRONLY : {
00151           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");
00152         }
00153         default:
00154           throw MED_EXCEPTION ("access type has not been properly specified to the method");
00155         }
00156       break;
00157     }
00158 
00159     case ENSIGHT_DRIVER : {
00160       if ( mesh->getIsAGrid() )
00161         throw MED_EXCEPTION("EnSight driver reads unstructured mesh, not a GRID");
00162       switch(access)
00163         {
00164         case RDONLY : {
00165           ret=new ENSIGHT_MESH_RDONLY_DRIVER(fileName,(MESH*)mesh);
00166           return ret;
00167         }
00168         case WRONLY : {
00169           ret=new ENSIGHT_MESH_WRONLY_DRIVER(fileName,(MESH*)mesh);
00170           return ret;
00171         }
00172         case RDWR : {
00173           throw MED_EXCEPTION ("not yet implemented");
00174           return ret;
00175         }
00176         default:
00177           throw MED_EXCEPTION ("access type has not been properly specified to the method");
00178         }
00179       break;
00180     }
00181 
00182     case VTK_DRIVER : {
00183       switch(access)
00184         {
00185         case RDONLY : {
00186           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");
00187         }
00188         case RDWR :
00189         case WRONLY : {
00190           ret=new VTK_MESH_DRIVER(fileName,mesh);
00191           return ret;
00192         }
00193 
00194         default:
00195           throw MED_EXCEPTION ("access type has not been properly specified to the method");
00196         }
00197       break;
00198     }
00199 
00200     case NO_DRIVER : {
00201       throw MED_EXCEPTION ("NO_DRIVER has been specified to the method 1 which is not allowed");
00202     }
00203     default:
00204       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");
00205     }
00206 }
00207 
00208 GENDRIVER * DRIVERFACTORY::buildMeshDriverFromFile(const string &         fileName,
00209                                                    GMESH *                ptrMesh,
00210                                                    MED_EN::med_mode_acces access)
00211 {
00212   medFileVersion version = MED_EN::V22;
00213 
00214   try
00215     {
00216       version = getMedFileVersion(fileName);
00217     }
00218   catch (MEDEXCEPTION & ex)
00219     {
00220     }
00221 
00222   MESSAGE_MED("buildMeshDriverFromFile version of the file " << version);
00223 
00224   if (version == MED_EN::V21)
00225     throw MED_EXCEPTION ("med-2.1 files are no more supported");
00226 
00227   GENDRIVER * driver=0;
00228 
00229   switch(access)
00230     {
00231     case RDONLY : {
00232       driver = new MED_MESH_RDONLY_DRIVER(fileName,ptrMesh);
00233       return driver;
00234     }
00235     case WRONLY : {
00236       driver = new MED_MESH_WRONLY_DRIVER(fileName,ptrMesh,access);
00237       return driver;
00238     }
00239     case RDWR : {
00240       driver = new MED_MESH_RDWR_DRIVER(fileName,ptrMesh);
00241       return driver;
00242     }
00243     default:
00244       throw MED_EXCEPTION ("access type has not been properly specified to the method");
00245     }
00246   return driver;
00247 }
00248 
00249 GENDRIVER * DRIVERFACTORY::buildConcreteMedDriverForMesh(const std::string &    fileName,
00250                                                          GMESH *                ptrMesh,
00251                                                          const string &         driverName,
00252                                                          MED_EN::med_mode_acces access,
00253                                                          MED_EN::medFileVersion version)
00254 {
00255   GENDRIVER * driver=0;
00256 
00257   MESSAGE_MED("buildConcreteMedDriverForMesh version of the file " << version);
00258 
00259   if (version == MED_EN::V21)
00260     throw MED_EXCEPTION ("med-2.1 files are no more supported");
00261 
00262   switch(access)
00263     {
00264     case RDONLY : {
00265       driver = new MED_MESH_RDONLY_DRIVER(fileName,ptrMesh);
00266       driver->setMeshName(driverName);
00267       return driver;
00268     }
00269     case WRONLY : {
00270       driver = new MED_MESH_WRONLY_DRIVER(fileName,ptrMesh);
00271       driver->setMeshName(driverName);
00272       return driver;
00273     }
00274     case RDWR : {
00275       driver = new MED_MESH_RDWR_DRIVER(fileName,ptrMesh);
00276       driver->setMeshName(driverName);
00277       return driver;
00278     }
00279     default:
00280       throw MED_EXCEPTION ("access type has not been properly specified to the method");
00281     }
00282   return driver;
00283 }