Salome HOME
Fix for "54515: [FORUM] MED export issue" issue.
[modules/smesh.git] / src / MEDWrapper / MED_Factory.cxx
1 // Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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, or (at your option) any later version.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "MED_Factory.hxx"
24 #include "MED_Utilities.hxx"
25 #include "MED_Wrapper.hxx"
26
27 #include <Basics_Utils.hxx>
28
29 #include <stdio.h>
30 #include <errno.h>
31 #include <sstream>
32 #include <fstream>
33
34 #include <med.h>
35 extern "C"
36 {
37 #ifndef WIN32
38   #include <unistd.h>
39 #endif
40 }
41 #include <utilities.h>
42
43 #ifdef WIN32
44 #include <windows.h>
45 #endif
46
47 // -------------------------------------------------------------------------------------------------------------------
48 // --- MED file compatibility: write using a lower major version implies append on an empty file of the target version
49
50 #define MED_MAJOR_EXPECTED 4
51 #define MED_MINOR_EXPECTED 0
52 #if MED_MAJOR_NUM != MED_MAJOR_EXPECTED
53   #error "MED major version does not correspond to the expected version, fix the minor and major compatibility values in CheckCompatibility method (MED_VERSIONS_APPEND_COMPATIBLE) and set the correct expected version"
54 #endif
55 #if MED_MINOR_NUM != MED_MINOR_EXPECTED
56   #error "MED minor version does not correspond to the expected version, fix the minor and major compatibility values in CheckCompatibility method (MED_VERSIONS_APPEND_COMPATIBLE) and set the correct expected version"
57 #endif
58 #define MED_VERSIONS_APPEND_COMPATIBLE {40, 32, 33} // --- 10*major + minor (the 3rd digit, release, is not used here,
59                                                     //                       med uses always the latest available)
60                                                     // --- The first in the list should be the default: current version
61 // --- empty med file content for the different MED versions with a different major.
62 //     ==> correct accordingly CreateEmptyMEDFile method below!
63 #define EMPTY_FILE_32 {0x89,0x48,0x44,0x46,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0x0,0x0,0x8,0x8,0x0,0x4,0x0,0x10,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xe8,0x7,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x60,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x88,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xa8,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x1,0x0,0x1,0x0,0x0,0x0,0x18,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x11,0x0,0x10,0x0,0x0,0x0,0x0,0x0,0x88,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xa8,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x54,0x52,0x45,0x45,0x0,0x0,0x1,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xe0,0x5,0x0,0x0,0x0,0x0,0x0,0x0,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0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,0x0,0x0,0x0}
65 /* --- bytes hexa representation of MED file built in Python
66 f= open('vide_321.med', 'rb')
67 data=f.read()
68 ba=bytearray(data)
69 a=""
70 for i in ba:
71   a+=hex(i)
72   a+=','
73 print a
74 */
75
76 //! internal use: fileName and version must be checked before call
77 bool CreateEmptyMEDFile(const std::string& fileName, int version)
78 {
79   MESSAGE("create an empty med file of the right version, for append " << version);
80   static const unsigned char empty_32[] = EMPTY_FILE_32;
81   static const unsigned char empty_33[] = EMPTY_FILE_33;
82 #ifdef WIN32
83 #ifdef UNICODE
84   std::wstring aFilename = Kernel_Utils::utf8_decode_s(fileName);
85 #else
86   std::wstring aFilename = fileName;
87 #endif
88   std::ofstream ofs(aFilename, std::ios::binary);
89 #else
90   std::ofstream ofs(fileName);
91 #endif
92   if (version == 32)
93     ofs.write(reinterpret_cast<const char *>(empty_32),sizeof(empty_32));
94   else if (version == 33)
95     ofs.write(reinterpret_cast<const char *>(empty_33),sizeof(empty_33));
96   ofs.flush();
97   ofs.close();
98   return true;
99 }
100 // -------------------------------------------------------------------------------------------------------------------
101
102 namespace MED
103 {
104   bool exists(const std::string& fileName)
105   {
106 #ifdef WIN32
107 #ifdef UNICODE
108     int size_needed = MultiByteToWideChar(CP_UTF8, 0, fileName.c_str(), strlen(fileName.c_str()), NULL, 0);
109     wchar_t* path = new wchar_t[size_needed + 1];
110     MultiByteToWideChar(CP_UTF8, 0, fileName.c_str(), strlen(fileName.c_str()), path, size_needed);
111     path[size_needed] = '\0';
112 #else
113     cosnt char* path = xmlPath.c_str();
114 #endif
115     bool res = (GetFileAttributes(path) != INVALID_FILE_ATTRIBUTES);
116 #ifdef UNICODE
117     delete path;
118 #endif
119     return res;
120 #else
121     return (access(fileName.c_str(), F_OK) == 0);
122 #endif
123   }
124
125   /*!
126    *  Return the list of med versions compatibles for write/append,
127    *  encoded in 10*major+minor (for instance, code for med 3.2.1 is 32)
128    */
129   std::vector<int> GetMEDVersionsAppendCompatible()
130   {
131     int mvok[] = MED_VERSIONS_APPEND_COMPATIBLE;
132     std::vector<int> MEDVersionsOK(mvok, mvok + sizeof(mvok)/sizeof(int));
133     return MEDVersionsOK;
134   }
135
136   /*!
137    *  \brief: Check read or write(append) Compatibility of a med file
138    *  \param [in] : fileName - the file to read or to append to
139    *  \param [in] : isforAppend - when true, check if the med file version is OK to append a mesh,
140    *                              when false, check if the med file is readable.
141    */
142   bool CheckCompatibility(const std::string& fileName, bool isForAppend)
143   {
144     bool ok = false;
145     int medVersionsOK[] = MED_VERSIONS_APPEND_COMPATIBLE;
146     // check that file is accessible
147     if ( exists(fileName) ) {
148       // check HDF5 && MED compatibility
149       med_bool hdfok, medok;
150       med_err r0 = MEDfileCompatibility(fileName.c_str(), &hdfok, &medok);
151       MESSAGE(r0 << " " << hdfok << " " << medok);
152       if ( r0==0 && hdfok && medok ) {
153         med_idt aFid = MEDfileOpen(fileName.c_str(), MED_ACC_RDONLY);
154         if (aFid >= 0) {
155           med_int major, minor, release;
156           med_err ret = MEDfileNumVersionRd(aFid, &major, &minor, &release);
157           MESSAGE(ret << " " << major << "." << minor << "." << release);
158           if (ret >= 0) {
159             bool isReadOnly = !isForAppend;
160             if (isReadOnly)
161               ok = true;
162             else {
163               int medVersion = 10*major + minor;
164               for (size_t ii=0; ii < sizeof(medVersionsOK)/sizeof(int); ii++)
165                 if (medVersionsOK[ii] == medVersion) {
166                   ok =true;
167                   break;
168                 }
169             }
170           }
171         }
172         MEDfileClose(aFid);
173       }
174     }
175     return ok;
176   }
177
178   bool GetMEDVersion(const std::string& fileName, int& major, int& minor, int& release)
179   {
180     bool ok = false;
181     major = minor = release = 0;
182     med_idt aFid = MEDfileOpen(fileName.c_str(), MED_ACC_RDONLY);
183     if (aFid >= 0) {
184       med_int _major, _minor, _release;
185       med_err ret = MEDfileNumVersionRd(aFid, &_major, &_minor, &_release);
186       if (ret == 0) {
187         major = _major;
188         minor = _minor;
189         release = _release;
190         ok = true;
191       }
192       MEDfileClose(aFid);
193     }
194     return ok;
195   }
196
197   std::string GetMEDVersion(const std::string& fileName)
198   {
199     std::string version;
200     int major, minor, release;
201     if (GetMEDVersion(fileName, major, minor, release)) {
202       std::ostringstream os;
203       os << major << "." << minor << "." << release;
204       version = os.str();
205     }
206     return version;
207   }
208
209   PWrapper CrWrapperR(const std::string& fileName)
210   {
211     if (!CheckCompatibility(fileName)) {
212       EXCEPTION(std::runtime_error, "Cannot open file '"<<fileName<<"'.");
213     }
214     return new MED::TWrapper(fileName);
215   }
216
217   PWrapper CrWrapperW(const std::string& fileName, int theVersion)
218   {
219     bool isCreated = false;
220     if (!CheckCompatibility(fileName, true))
221     {
222       remove(fileName.c_str());
223       isCreated = true;
224     }
225     int minor = -1;
226     if (isCreated)
227     {
228       med_int wantedMajor = MED_MAJOR_NUM;
229       med_int wantedMinor = MED_MINOR_NUM;
230       if (theVersion > 0)
231       {
232         wantedMajor = theVersion/10;
233         wantedMinor = theVersion%10;
234       }
235       if (wantedMajor == MED_MAJOR_NUM) // the med file will be actually created
236       {
237         if (wantedMinor < MED_MINOR_NUM)
238           minor = wantedMinor;
239       }
240       else                              // an empty existing med file of the right version will be used for append
241       {
242         int medVersionsOK[] = MED_VERSIONS_APPEND_COMPATIBLE;
243         bool isVersionOK = false;
244         for (size_t ii=0; ii < sizeof(medVersionsOK)/sizeof(int); ii++)
245           if (medVersionsOK[ii] == theVersion)
246           {
247             isVersionOK =true;
248             break;
249           }
250         if (isVersionOK)              // copy an empty existing med file of the right version, for append
251           CreateEmptyMEDFile(fileName, theVersion);
252       }
253     }
254     return new MED::TWrapper(fileName, minor);
255   }
256 }