+static void PrepareForWriting (const char* file)
+{
+ TCollection_AsciiString aFullName ((char*)file);
+ OSD_Path aPath (aFullName);
+ OSD_File aFile (aPath);
+ if (aFile.Exists()) {
+ // existing filesystem node
+ if (aFile.KindOfFile() == OSD_FILE) {
+ if (aFile.IsWriteable()) {
+ aFile.Reset();
+ aFile.Remove();
+ if (aFile.Failed()) {
+ TCollection_AsciiString msg ("File ");
+ msg += aFullName + " cannot be replaced.";
+ THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
+ }
+ } else {
+ TCollection_AsciiString msg ("File ");
+ msg += aFullName + " cannot be overwritten.";
+ THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
+ }
+ } else {
+ TCollection_AsciiString msg ("Location ");
+ msg += aFullName + " is not a file.";
+ THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
+ }
+ } else {
+ // nonexisting file
+ TCollection_AsciiString aDirName = aPath.TrekValue(aPath.TrekLength());
+ aPath.UpTrek();
+ aPath.SetName(aDirName);
+ aPath.SetExtension("");
+ OSD_Directory aDir (aPath);
+ TCollection_AsciiString aFullDirName;
+ aPath.SystemName(aFullDirName);
+ if (aDir.Exists()) {
+ aFile.Reset();
+ aFile.Build(OSD_WriteOnly, OSD_Protection());
+ if (aFile.Failed()) {
+ TCollection_AsciiString msg ("You cannot write to directory ");
+ msg += aFullDirName + ".";
+ THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
+ } else {
+ aFile.Close();
+ aFile.Remove();
+ }
+ } else {
+ TCollection_AsciiString msg ("Directory ");
+ msg += aFullDirName + " does not exist.";
+ THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
+ }
+ }
+}
+
+void SMESH_Mesh_i::ExportToMED (const char* file,
+ CORBA::Boolean auto_groups,