3 // Copyright (C) 2003 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
29 #include "MED_Factory.hxx"
30 #include "MED_Utilities.hxx"
31 #include "MED_V2_2_Wrapper.hxx"
32 #include "MED_V2_1_Wrapper.hxx"
43 static int MYDEBUG = 0;
45 static int MYDEBUG = 0;
51 EVersion GetVersionId(const std::string& theFileName,
52 bool theDoPreCheckInSeparateProcess)
54 INITMSG(MYDEBUG,"GetVersionId - theFileName = '"<<theFileName<<"'"<<std::endl);
55 EVersion aVersion = eVUnknown;
58 if(theDoPreCheckInSeparateProcess){
59 // First check, is it possible to deal with the file
60 std::ostringstream aStr;
61 // File name is in quotes for the case of space(s) inside it (PAL13009)
62 aStr<<"bash -c \""<<getenv("MED_ROOT_DIR")<<"/bin/salome/mprint_version \'"<<theFileName<<"\'\"";
64 aStr<<" 2>&1 > /dev/null";
66 std::string aCommand = aStr.str();
67 int aStatus = system(aCommand.c_str());
69 BEGMSG(MYDEBUG,"aCommand = '"<<aCommand<<"'; aStatus = "<<aStatus<<std::endl);
75 // Next, try to open the file trough the MED API
76 char* aFileName = const_cast<char*>(theFileName.c_str());
77 med_idt aFid = MEDouvrir(aFileName,MED_LECTURE);
79 MSG(MYDEBUG,"GetVersionId - theFileName = '"<<theFileName<<"'; aFid = "<<aFid<<std::endl);
81 med_int aMajor, aMinor, aRelease;
82 med_err aRet = MEDversionLire(aFid,&aMajor,&aMinor,&aRelease);
83 INITMSG(MYDEBUG,"GetVersionId - theFileName = '"<<theFileName<<"'; aRet = "<<aRet<<std::endl);
85 if(aMajor >= 2 && aMinor >= 2)
93 BEGMSG(MYDEBUG,"GetVersionId - theFileName = '"<<theFileName<<"'; aVersion = "<<aVersion<<std::endl);
97 PWrapper CrWrapper(const std::string& theFileName,
98 bool theDoPreCheckInSeparateProcess)
101 EVersion aVersion = GetVersionId(theFileName,theDoPreCheckInSeparateProcess);
104 aWrapper.reset(new MED::V2_2::TVWrapper(theFileName));
107 aWrapper.reset(new MED::V2_1::TVWrapper(theFileName));
110 EXCEPTION(std::runtime_error,"MED::CrWrapper - theFileName = '"<<theFileName<<"'");
115 PWrapper CrWrapper(const std::string& theFileName, EVersion theId)
117 EVersion aVersion = GetVersionId(theFileName);
119 if(aVersion != theId)
120 remove(theFileName.c_str());
125 aWrapper.reset(new MED::V2_2::TVWrapper(theFileName));
128 aWrapper.reset(new MED::V2_1::TVWrapper(theFileName));