Salome HOME
Fix Python dump of ExportPartToMED()
[modules/smesh.git] / src / SMESH_I / SMESH_Mesh_i.cxx
index 5110e337b95d197036ca1b839bcb45e9755dbf33..8dc1b25b585e3bb0def9dcdef7cef4d507dc6adc 100644 (file)
@@ -299,6 +299,9 @@ void SMESH_Mesh_i::Clear() throw (SALOME::SALOME_Exception)
   }
 
   TPythonDump() <<  SMESH::SMESH_Mesh_var(_this()) << ".Clear()";
+
+  SMESH::SMESH_Mesh_var mesh = _this();
+  _gen_i->UpdateIcons( mesh );
 }
 
 //================================================================================
@@ -442,9 +445,29 @@ SMESH::DriverMED_ReadStatus SMESH_Mesh_i::ImportCGNSFile( const char*  theFileNa
 
   CreateGroupServants();
 
+  _medFileInfo           = new SMESH::MedFileInfo();
+  _medFileInfo->fileName = theFileName;
+  _medFileInfo->major    = 0;
+  _medFileInfo->minor    = 0;
+  _medFileInfo->release  = 0;
+  _medFileInfo->fileSize = SMESH_File( theFileName ).size();
+
   return ConvertDriverMEDReadStatus(status);
 }
 
+//================================================================================
+/*!
+ * \brief Return string representation of a MED file version comprising nbDigits
+ */
+//================================================================================
+
+char* SMESH_Mesh_i::GetVersionString(CORBA::Long minor, CORBA::Short nbDigits)
+{
+  string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(minor,
+                                                          nbDigits);
+  return CORBA::string_dup( ver.c_str() );
+}
+
 //=============================================================================
 /*!
  *  ImportUNVFile
@@ -463,6 +486,13 @@ int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
 
   CreateGroupServants();
 
+  _medFileInfo           = new SMESH::MedFileInfo();
+  _medFileInfo->fileName = theFileName;
+  _medFileInfo->major    = 0;
+  _medFileInfo->minor    = 0;
+  _medFileInfo->release  = 0;
+  _medFileInfo->fileSize = SMESH_File( theFileName ).size();
+
   SMESH_CATCH( SMESH::throwCorbaException );
 
   return 1;
@@ -487,6 +517,12 @@ int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
     SALOMEDS::SObject_wrap meshSO = _gen_i->ObjectToSObject( _this() );
     _gen_i->SetName( meshSO, name.c_str() );
   }
+  _medFileInfo           = new SMESH::MedFileInfo();
+  _medFileInfo->fileName = theFileName;
+  _medFileInfo->major    = 0;
+  _medFileInfo->minor    = 0;
+  _medFileInfo->release  = 0;
+  _medFileInfo->fileSize = SMESH_File( theFileName ).size();
 
   SMESH_CATCH( SMESH::throwCorbaException );
 
@@ -525,6 +561,13 @@ SMESH::ComputeError* SMESH_Mesh_i::ImportGMFFile( const char* theFileName,
 
   error = _impl->GMFToMesh( theFileName, theMakeRequiredGroups );
 
+  _medFileInfo           = new SMESH::MedFileInfo();
+  _medFileInfo->fileName = theFileName;
+  _medFileInfo->major    = 0;
+  _medFileInfo->minor    = 0;
+  _medFileInfo->release  = 0;
+  _medFileInfo->fileSize = SMESH_File( theFileName ).size();
+
   SMESH_CATCH( exceptionToComputeError );
 #undef SMESH_CAUGHT
 #define SMESH_CAUGHT
@@ -594,6 +637,7 @@ SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr       aSubShape,
   if ( !SMESH_Hypothesis::IsStatusFatal(status) )
   {
     _gen_i->AddHypothesisToShape( mesh, aSubShape, anHyp );
+    _gen_i->UpdateIcons( mesh );
   }
   if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
 
@@ -679,6 +723,7 @@ SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aS
   if ( !SMESH_Hypothesis::IsStatusFatal(status) )
   {
     _gen_i->RemoveHypothesisFromShape( mesh, aSubShape, anHyp );
+    _gen_i->UpdateIcons( mesh );
   }
   // Update Python script
   if(_impl->HasShapeToMesh())
@@ -2705,6 +2750,9 @@ void SMESH_Mesh_i::onHypothesisModified()
 {
   if ( _preMeshInfo )
     _preMeshInfo->ForgetOrLoad();
+
+  SMESH::SMESH_Mesh_var mesh = _this();
+  _gen_i->UpdateIcons( mesh );
 }
 
 //=============================================================================
@@ -2979,22 +3027,26 @@ string SMESH_Mesh_i::prepareMeshNameAndGroups(const char*    file,
 
 void SMESH_Mesh_i::ExportMED(const char*        file,
                              CORBA::Boolean     auto_groups,
+                             CORBA::Long        minor,
                              CORBA::Boolean     overwrite,
                              CORBA::Boolean     autoDimension)
   throw(SALOME::SALOME_Exception)
 {
-  //MESSAGE("SMESH::MED_VERSION:"<< theVersion);
+  //MESSAGE("MED minor version: "<< minor);
   SMESH_TRY;
   if ( _preMeshInfo )
     _preMeshInfo->FullLoadFromFile();
 
   string aMeshName = prepareMeshNameAndGroups(file, overwrite);
-  _impl->ExportMED( file, aMeshName.c_str(), auto_groups, 0, autoDimension );
+  _impl->ExportMED( file, aMeshName.c_str(), auto_groups, minor, 0, autoDimension );
 
   TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportMED( r'"
-                << file << "', " << auto_groups << ", "
-                << overwrite << ", "
-                << autoDimension << " )";
+                << file << "', "
+                << "auto_groups=" <<auto_groups << ", "
+                << "minor=" << minor <<  ", "
+                << "overwrite=" << overwrite << ", "
+                << "meshPart=None, "
+                << "autoDimension=" << autoDimension << " )";
 
   SMESH_CATCH( SMESH::throwCorbaException );
 }
@@ -3104,12 +3156,14 @@ void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
 void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
                                    const char*               file,
                                    CORBA::Boolean            auto_groups,
+                                   CORBA::Long               minor,
                                    CORBA::Boolean            overwrite,
                                    CORBA::Boolean            autoDimension,
                                    const GEOM::ListOfFields& fields,
                                    const char*               geomAssocFields)
   throw (SALOME::SALOME_Exception)
 {
+  //MESSAGE("MED minor version: "<< minor);
   SMESH_TRY;
   if ( _preMeshInfo )
     _preMeshInfo->FullLoadFromFile();
@@ -3156,7 +3210,7 @@ void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
        SMESH::DownCast< SMESH_Mesh_i* >( meshPart ))
   {
     aMeshName = prepareMeshNameAndGroups(file, overwrite);
-    _impl->ExportMED( file, aMeshName.c_str(), auto_groups,
+    _impl->ExportMED( file, aMeshName.c_str(), auto_groups, minor,
                       0, autoDimension, /*addODOnVertices=*/have0dField);
     meshDS = _impl->GetMeshDS();
   }
@@ -3174,7 +3228,7 @@ void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
     }
 
     SMESH_MeshPartDS* partDS = new SMESH_MeshPartDS( meshPart );
-    _impl->ExportMED( file, aMeshName.c_str(), auto_groups,
+    _impl->ExportMED( file, aMeshName.c_str(), auto_groups, minor,
                       partDS, autoDimension, /*addODOnVertices=*/have0dField);
     meshDS = tmpDSDeleter._obj = partDS;
   }
@@ -3200,10 +3254,14 @@ void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
     goList[i] = gbo;
   }
   TPythonDump() << _this() << ".ExportPartToMED( "
-                << meshPart << ", r'" << file << "', "
-                << auto_groups << ", " << overwrite << ", "
-                << autoDimension << ", " << goList
-                << ", '" << ( geomAssocFields ? geomAssocFields : "" ) << "'" << " )";
+                << meshPart << ", r'"
+                << file << "', "
+                << auto_groups << ", "
+                << minor << ", "
+                << overwrite << ", "
+                << autoDimension << ", "
+                << goList << ", '"
+                << ( geomAssocFields ? geomAssocFields : "" ) << "'" << " )";
 
   SMESH_CATCH( SMESH::throwCorbaException );
 }
@@ -4991,6 +5049,17 @@ void SMESH_Mesh_i::CreateGroupServants()
   }
 }
 
+//=============================================================================
+/*!
+ * \brief Return true if all sub-meshes are computed OK - to update an icon
+ */
+//=============================================================================
+
+bool SMESH_Mesh_i::IsComputedOK()
+{
+  return _impl->IsComputedOK();
+}
+
 //=============================================================================
 /*!
  * \brief Return groups cantained in _mapGroups by their IDs
@@ -5031,6 +5100,48 @@ SMESH::MedFileInfo* SMESH_Mesh_i::GetMEDFileInfo()
   return res._retn();
 }
 
+//=======================================================================
+//function : FileInfoToString
+//purpose  : Persistence of file info
+//=======================================================================
+
+std::string SMESH_Mesh_i::FileInfoToString()
+{
+  std::string s;
+  if ( &_medFileInfo.in() && _medFileInfo->fileName[0] )
+  {
+    s = SMESH_Comment( _medFileInfo->fileSize )
+      << " " << _medFileInfo->major
+      << " " << _medFileInfo->minor
+      << " " << _medFileInfo->release
+      << " " << _medFileInfo->fileName;
+  }
+  return s;
+}
+
+//=======================================================================
+//function : FileInfoFromString
+//purpose  : Persistence of file info
+//=======================================================================
+
+void SMESH_Mesh_i::FileInfoFromString(const std::string& info)
+{
+  std::string size, major, minor, release, fileName;
+  std::istringstream is(info);
+  is >> size >> major >> minor >> release;
+  fileName = info.data() + ( size.size()   + 1 +
+                             major.size()  + 1 +
+                             minor.size()  + 1 +
+                             release.size()+ 1 );
+
+  _medFileInfo           = new SMESH::MedFileInfo();
+  _medFileInfo->fileName = fileName.c_str();
+  _medFileInfo->fileSize = atoi( size.c_str() );
+  _medFileInfo->major    = atoi( major.c_str() );
+  _medFileInfo->minor    = atoi( minor.c_str() );
+  _medFileInfo->release  = atoi( release.c_str() );
+}
+
 //=============================================================================
 /*!
  * \brief Pass names of mesh groups from study to mesh DS
@@ -5968,6 +6079,9 @@ TListOfListOfInt SMESH_Mesh_i::findConcurrentSubMeshes()
   mesh.SetMeshOrder( subMeshOrder );
   res = true;
   
+  SMESH::SMESH_Mesh_var me = _this();
+  _gen_i->UpdateIcons( me );
+
   return res;
 }