Salome HOME
#18963 Minimize compiler warnings
[modules/smesh.git] / src / SMESH_I / SMESH_PreMeshInfo.cxx
index 38c13009cc5bfc1dffbce082c3a746fedc897753..7514ad21580bf1dd2b3a451346aa63836cea69a9 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -61,10 +61,10 @@ using namespace std;
 
 namespace
 {
-  enum {  GroupOnFilter_OutOfDate = -1 };
+  enum {  GroupOnFilter_OutOfDate = -777 };
 
-  // a map to count not yet loaded meshes 
-  static std::map< int, int > theStudyIDToMeshCounter;
+  // count not yet loaded meshes
+  static int theMeshCounter = 0;
 
   //================================================================================
   /*!
@@ -72,11 +72,9 @@ namespace
    */
   //================================================================================
 
-  void meshInfoLoaded( SMESH_Mesh_i* mesh )
+  void meshInfoLoaded( SMESH_Mesh_i* /*mesh*/ )
   {
-    std::map< int, int >::iterator id2counter =
-      theStudyIDToMeshCounter.insert( std::make_pair( (int) mesh->GetStudyId(), 0 )).first;
-    id2counter->second++;
+    theMeshCounter++;
   }
   //================================================================================
   /*!
@@ -84,22 +82,22 @@ namespace
    */
   //================================================================================
 
-  void filesNoMoreNeeded(SMESH_Mesh_i* mesh,
+  void filesNoMoreNeeded(SMESH_Mesh_i* /*mesh*/,
                          std::string   medFile,
                          std::string   hdfFile)
   {
-    if ( --theStudyIDToMeshCounter[ (int) mesh->GetStudyId() ] == 0 )
+    if ( --theMeshCounter == 0 )
     {
       std::string tmpDir = SALOMEDS_Tool::GetDirFromPath( hdfFile );
 
-      SALOMEDS::ListOfFileNames_var aFiles = new SALOMEDS::ListOfFileNames;
-      aFiles->length(2);
+      SALOMEDS_Tool::ListOfFiles aFiles;
+      aFiles.reserve(2);
       medFile = SALOMEDS_Tool::GetNameFromPath( medFile ) + ".med";
       hdfFile = SALOMEDS_Tool::GetNameFromPath( hdfFile ) + ".hdf";
-      aFiles[0] = medFile.c_str();
-      aFiles[1] = hdfFile.c_str();
+      aFiles.push_back(medFile.c_str());
+      aFiles.push_back(hdfFile.c_str());
 
-      SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.c_str(), aFiles.in(), true );
+      SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.c_str(), aFiles, true );
     }
   }
 
@@ -117,25 +115,22 @@ namespace
     SignalToGUI( SMESH_Mesh_i* mesh )
     {
       SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
-      SALOMEDS::Study_var study = gen->GetCurrentStudy();
-      if ( !study->_is_nil() && study->StudyId() == mesh->GetStudyId() )
+
+      SALOMEDS::SObject_wrap meshSO = gen->ObjectToSObject( mesh->_this() );
+      CORBA::Object_var        obj = gen->GetNS()->Resolve( "/Kernel/Session" );
+      _session = SALOME::Session::_narrow( obj );
+      if ( !meshSO->_is_nil() && !_session->_is_nil() )
       {
-        SALOMEDS::SObject_wrap meshSO = gen->ObjectToSObject(study, mesh->_this() );
-        CORBA::Object_var        obj = gen->GetNS()->Resolve( "/Kernel/Session" );
-        _session = SALOME::Session::_narrow( obj );
-        if ( !meshSO->_is_nil() && !_session->_is_nil() )
-        {
-          CORBA::String_var meshEntry = meshSO->GetID();
-          _messagePrefix = "SMESH/mesh_loading/";
-          _messagePrefix += meshEntry.in();
+        CORBA::String_var meshEntry = meshSO->GetID();
+        _messagePrefix = "SMESH/mesh_loading/";
+        _messagePrefix += meshEntry.in();
 
-          std::string msgToGUI = _messagePrefix + "/";
-          msgToGUI += SMESH_Comment( mesh->NbNodes() );
-          msgToGUI += "/";
-          msgToGUI += SMESH_Comment( mesh->NbElements() );
+        std::string msgToGUI = _messagePrefix + "/";
+        msgToGUI += SMESH_Comment( mesh->NbNodes() );
+        msgToGUI += "/";
+        msgToGUI += SMESH_Comment( mesh->NbElements() );
 
-          _session->emitMessageOneWay( msgToGUI.c_str());
-        }
+        _session->emitMessageOneWay( msgToGUI.c_str());
       }
     }
     void sendStop()
@@ -259,7 +254,7 @@ namespace
     std::vector<int> data;
 
     for ( size_t i = 0; i < meshInfo->length(); ++i )
-      if ( meshInfo[i] > 0 )
+      if ( meshInfo[i] > 0 || meshInfo[i] == GroupOnFilter_OutOfDate )
       {
         data.push_back( DriverMED::GetMedGeoType( SMDSAbs_EntityType( i ))); //medTypes[ i ] );
         data.push_back( meshInfo[ i ] );
@@ -461,6 +456,7 @@ bool SMESH_PreMeshInfo::readPreInfoFromHDF()
                                                mapOfNames );
       }
     }
+    infoHdfGroup->CloseOnDisk();
   }
 
   aFile->CloseOnDisk();
@@ -479,14 +475,11 @@ bool SMESH_PreMeshInfo::readMeshInfo()
 {
   _isInfoOk = true;
 
-  MED::PWrapper aMed = MED::CrWrapper(_medFileName,true);
-  // if ( aMed->GetVersion() != MED::eV2_2 )
-  //   return false;
-
+  MED::PWrapper aMed = MED::CrWrapperR(_medFileName);
   MED::PMeshInfo medMeshInfo = aMed->CrMeshInfo(3,3,SMESH_Comment( _meshID ));
 
   // read nb nodes
-  int nbNodes = std::max( 0, aMed->GetNbNodes( medMeshInfo ));
+  int nbNodes = Max( 0, aMed->GetNbNodes( medMeshInfo ));
   if ( nbNodes > 0 )
   {
     setNb( SMDSEntity_Node, nbNodes);
@@ -535,7 +528,7 @@ void SMESH_PreMeshInfo::readGroupInfo()
 
   map< int, vector< SMESH_PreMeshInfo* > > famId2grInfo;
 
-  MED::PWrapper aMed = MED::CrWrapper(_medFileName,false);
+  MED::PWrapper aMed = MED::CrWrapperR(_medFileName);
   MED::PMeshInfo medMeshInfo = aMed->CrMeshInfo(3,3,SMESH_Comment( _meshID ));
 
   // read families to fill in famId2grInfo
@@ -848,8 +841,9 @@ void SMESH_PreMeshInfo::FullLoadFromFile() const
   meshDS->Modified();
 
   // load dependent meshes referring/referred via hypotheses
-  mesh.GetSubMesh( mesh.GetShapeToMesh() )->
-    ComputeStateEngine (SMESH_subMesh::SUBMESH_LOADED);
+  SMESH_subMesh* mainSub = mesh.GetSubMesh( mesh.GetShapeToMesh() );
+  mainSub->ComputeStateEngine (SMESH_subMesh::SUBMESH_RESTORED); // #16648 
+  mainSub->ComputeStateEngine (SMESH_subMesh::SUBMESH_LOADED);
 
   MYDEBUGOUT( "END FullLoadFromFile()" );
 }
@@ -1237,10 +1231,9 @@ bool SMESH_PreMeshInfo::IsMeshInfoCorrect() const
 
 void SMESH_PreMeshInfo::RemoveStudyFiles_TMP_METHOD(SALOMEDS::SComponent_ptr smeshComp)
 {
-  SALOMEDS::Study_var study = smeshComp->GetStudy();
-  if ( theStudyIDToMeshCounter[ (int) study->StudyId() ] > 0 )
+  if ( theMeshCounter > 0 )
   {
-    SALOMEDS::ChildIterator_wrap itBig = study->NewChildIterator( smeshComp );
+    SALOMEDS::ChildIterator_wrap itBig = SMESH_Gen_i::getStudyServant()->NewChildIterator( smeshComp );
     for ( ; itBig->More(); itBig->Next() ) {
       SALOMEDS::SObject_wrap gotBranch = itBig->Value();
       CORBA::Object_var       anObject = SMESH_Gen_i::SObjectToObject( gotBranch );