Salome HOME
Fix mixed Python dump of a new and a closed study
[modules/smesh.git] / src / SMESH_I / SMESH_Gen_i.cxx
index 3a575aa0a20e5997b409d47dbbb376c5297631e1..e6ebe05e91a43b03b87159ff1fbf7cdd2afd3ffd 100644 (file)
@@ -2959,7 +2959,7 @@ char* SMESH_Gen_i::GetMEDVersion(const char* theFileName)
 /*!
  *  SMESH_Gen_i::CheckCompatibility
  *
- *  Check compatibility of file with MED format being used.
+ *  Check compatibility of file with MED format being used, read only.
  */
 //================================================================================
 CORBA::Boolean SMESH_Gen_i::CheckCompatibility(const char* theFileName)
@@ -2967,6 +2967,18 @@ CORBA::Boolean SMESH_Gen_i::CheckCompatibility(const char* theFileName)
   return MED::CheckCompatibility( theFileName );
 }
 
+//================================================================================
+/*!
+ *  SMESH_Gen_i::CheckWriteCompatibility
+ *
+ *  Check compatibility of file with MED format being used, for append on write.
+ */
+//================================================================================
+CORBA::Boolean SMESH_Gen_i::CheckWriteCompatibility(const char* theFileName)
+{
+  return MED::CheckCompatibility( theFileName, true );
+}
+
 //================================================================================
 /*!
  *  SMESH_Gen_i::GetMeshNames
@@ -2976,10 +2988,12 @@ CORBA::Boolean SMESH_Gen_i::CheckCompatibility(const char* theFileName)
 //================================================================================
 SMESH::string_array* SMESH_Gen_i::GetMeshNames(const char* theFileName)
 {
+  //MESSAGE("GetMeshNames " << theFileName);
   SMESH::string_array_var aResult = new SMESH::string_array();
   MED::PWrapper aMed = MED::CrWrapperR( theFileName );
   MED::TErr anErr;
   MED::TInt aNbMeshes = aMed->GetNbMeshes( &anErr );
+  //MESSAGE("---" << aNbMeshes);
   if( anErr >= 0 ) {
     aResult->length( aNbMeshes );
     for( MED::TInt i = 0; i < aNbMeshes; i++ ) {
@@ -3075,7 +3089,6 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
             myMesh->Load(); // load from study file if not yet done
             TPythonDump pd; // not to dump GetGroups()
             SMESH::ListOfGroups_var groups = myMesh->GetGroups();
-            pd << ""; // to avoid optimizing pd out
             for ( CORBA::ULong i = 0; i < groups->length(); ++i )
             {
               SMESH_GroupBase_i* grImpl = SMESH::DownCast<SMESH_GroupBase_i*>( groups[i]);
@@ -3329,6 +3342,17 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
               }
             }
 
+            // Store file info
+            std::string info = myImpl->FileInfoToString();
+            if ( !info.empty() )
+            {
+              aSize[ 0 ] = info.size();
+              aDataset = new HDFdataset( "file info", aTopGroup, HDF_STRING, aSize, 1 );
+              aDataset->CreateOnDisk();
+              aDataset->WriteOnDisk( (char*) info.data() );
+              aDataset->CloseOnDisk();
+            }
+
             // write applied hypotheses if exist
             SALOMEDS::SObject_wrap myHypBranch;
             found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch.inout() );
@@ -4002,7 +4026,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
                         const char*              theURL,
                         bool                     isMultiFile )
 {
-  if (!myStudyContext)
+  //if (!myStudyContext)
     UpdateStudy();
   SALOMEDS::Study_var aStudy = getStudyServant();
   /*  if( !theComponent->_is_nil() )
@@ -4353,6 +4377,18 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
             myNewMeshImpl->GetImpl().GetMeshDS()->SetPersistentId( *meshPersistentId );
             delete [] meshPersistentId;
           }
+
+          // Restore file info
+          if ( aTopGroup->ExistInternalObject( "file info" ))
+          {
+            aDataset = new HDFdataset( "file info", aTopGroup );
+            aDataset->OpenOnDisk();
+            size = aDataset->GetSize();
+            std::string info( size, ' ');
+            aDataset->ReadFromDisk( (char*) info.data() );
+            aDataset->CloseOnDisk();
+            myNewMeshImpl->FileInfoFromString( info );
+          }
         }
       }
     } // reading MESHes
@@ -4935,6 +4971,9 @@ void SMESH_Gen_i::Close( SALOMEDS::SComponent_ptr theComponent )
   // remove the tmp files meshes are loaded from
   SMESH_PreMeshInfo::RemoveStudyFiles_TMP_METHOD( theComponent );
 
+  // Clean trace of API methods calls
+  CleanPythonTrace();
+
   return;
 }