Salome HOME
#18963 Minimize compiler warnings
[modules/smesh.git] / src / SMESH_I / SMESH_PreMeshInfo.cxx
index 59a7e65c8318f73712850918bad3f1181882b1cc..7514ad21580bf1dd2b3a451346aa63836cea69a9 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  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
@@ -35,6 +35,7 @@
 #include "SMDS_VertexPosition.hxx"
 #include "SMESHDS_Group.hxx"
 #include "SMESHDS_GroupOnFilter.hxx"
+#include "SMESHDS_Mesh.hxx"
 #include "SMESH_Gen_i.hxx"
 #include "SMESH_Group_i.hxx"
 #include "SMESH_Mesh_i.hxx"
 
 #include CORBA_SERVER_HEADER(SALOME_Session)
 
+using namespace std;
 
 #define MYDEBUGOUT(msg) //std::cout << msg << std::endl;
 
 namespace
 {
-  enum {  GroupOnFilter_OutOfDate = -1 };
+  enum {  GroupOnFilter_OutOfDate = -777 };
 
-  // a map to count not yet loaded meshes 
-  static map< int, int > theStudyIDToMeshCounter;
+  // count not yet loaded meshes
+  static int theMeshCounter = 0;
 
   //================================================================================
   /*!
@@ -70,11 +72,9 @@ namespace
    */
   //================================================================================
 
-  void meshInfoLoaded( SMESH_Mesh_i* mesh )
+  void meshInfoLoaded( SMESH_Mesh_i* /*mesh*/ )
   {
-    map< int, int >::iterator id2counter =
-      theStudyIDToMeshCounter.insert( make_pair( (int) mesh->GetStudyId(), 0 )).first;
-    id2counter->second++;
+    theMeshCounter++;
   }
   //================================================================================
   /*!
@@ -82,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 )
     {
-      string tmpDir = SALOMEDS_Tool::GetDirFromPath( hdfFile );
+      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 );
     }
   }
 
@@ -109,38 +109,35 @@ namespace
 
   class SignalToGUI
   {
-    string              _messagePrefix;
+    std::string         _messagePrefix;
     SALOME::Session_var _session;
   public:
     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();
 
-          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()
     {
       if ( !_messagePrefix.empty() )
       {
-        string msgToGUI = _messagePrefix + "/stop";
+        std::string msgToGUI = _messagePrefix + "/stop";
         _session->emitMessageOneWay( msgToGUI.c_str());
         _messagePrefix.clear();
       }
@@ -173,7 +170,7 @@ namespace
     SMDS_PositionPtr vertexPosition()  const { return SMDS_PositionPtr( new SMDS_VertexPosition); }
     SMDS_PositionPtr defaultPosition() const { return SMDS_SpacePosition::originSpacePosition();  }
     typedef SMDS_PositionPtr (PositionCreator:: * FmakePos)() const;
-    vector<FmakePos> myFuncTable;
+    std::vector<FmakePos> myFuncTable;
   };
 
   //================================================================================
@@ -182,12 +179,12 @@ namespace
    */
   //================================================================================
 
-  vector<int> getSimpleSubMeshIds( SMESHDS_Mesh* meshDS, int shapeId )
+  std::vector<int> getSimpleSubMeshIds( SMESHDS_Mesh* meshDS, int shapeId )
   {
-    vector<int> ids;
+    std::vector<int> ids;
 
-    list<TopoDS_Shape> shapeQueue( 1, meshDS->IndexToShape( shapeId ));
-    list<TopoDS_Shape>::iterator shape = shapeQueue.begin();
+    std::list<TopoDS_Shape> shapeQueue( 1, meshDS->IndexToShape( shapeId ));
+    std::list<TopoDS_Shape>::iterator shape = shapeQueue.begin();
     for ( ; shape != shapeQueue.end(); ++shape )
     {
       if ( shape->IsNull() ) continue;
@@ -222,10 +219,10 @@ namespace
    */
   //================================================================================
 
-  typedef map< MED::EGeometrieElement, SMDSAbs_EntityType > Tmed2smeshElemTypeMap;
+  typedef std::map< MED::EGeometrieElement, SMDSAbs_EntityType > Tmed2smeshElemTypeMap;
   const Tmed2smeshElemTypeMap& med2smeshElemTypeMap()
   {
-    static map< MED::EGeometrieElement, SMDSAbs_EntityType> med2smeshTypes;
+    static Tmed2smeshElemTypeMap med2smeshTypes;
     if ( med2smeshTypes.empty() )
     {
       for  ( int iG = 0; iG < SMDSEntity_Last; ++iG )
@@ -233,7 +230,7 @@ namespace
         SMDSAbs_EntityType    smdsType = (SMDSAbs_EntityType) iG;
         MED::EGeometrieElement medType =
           (MED::EGeometrieElement) DriverMED::GetMedGeoType( smdsType );
-        med2smeshTypes.insert( make_pair( medType, smdsType ));
+        med2smeshTypes.insert( std::make_pair( medType, smdsType ));
       }
     }
     return med2smeshTypes;
@@ -254,10 +251,10 @@ namespace
     // change at insertion of new items in the middle.
     //const vector<MED::EGeometrieElement>& medTypes = mesh2medElemType();
 
-    vector<int> data;
+    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 ] );
@@ -285,10 +282,12 @@ namespace
  */
 //================================================================================
 
-void SMESH_PreMeshInfo::hdf2meshInfo( const std::string& name,
-                                      HDFgroup*          hdfGroup)
+void SMESH_PreMeshInfo::hdf2meshInfo( const std::string&              name,
+                                      HDFgroup*                       hdfGroup,
+                                      const TColStd_MapOfAsciiString& allHdfNames)
 {
-  if ( hdfGroup->ExistInternalObject( name.c_str()) )
+  //if ( hdfGroup->ExistInternalObject( name.c_str()) ) PAL23514
+  if ( allHdfNames.Contains( name.c_str() ))
   {
     HDFdataset* dataset = new HDFdataset( name.c_str(), hdfGroup );
     dataset->OpenOnDisk();
@@ -298,7 +297,7 @@ void SMESH_PreMeshInfo::hdf2meshInfo( const std::string& name,
     // // array->GetDim( datasetSize );
     // int size = dataset->GetSize();
 
-    vector<int> info( SMDSEntity_Last * 2, 0 );
+    std::vector<int> info( SMDSEntity_Last * 2, 0 );
     dataset->ReadFromDisk( &info[0] );
     dataset->CloseOnDisk();
 
@@ -417,7 +416,17 @@ bool SMESH_PreMeshInfo::readPreInfoFromHDF()
     HDFgroup* infoHdfGroup = new HDFgroup( hdfGroupName, aFile );
     infoHdfGroup->OpenOnDisk();
 
-    _mesh->changePreMeshInfo()->hdf2meshInfo( "Mesh", infoHdfGroup );
+    // PAL23514: get all names from the HDFgroup to avoid iteration on its contents
+    // within aGroup->ExistInternalObject( name )
+    TColStd_MapOfAsciiString mapOfNames;
+    {
+      std::vector< std::string > subNames;
+      infoHdfGroup->GetAllObjects( subNames );
+      for ( size_t iN = 0; iN < subNames.size(); ++iN )
+        mapOfNames.Add( subNames[ iN ].c_str() );
+    }
+
+    _mesh->changePreMeshInfo()->hdf2meshInfo( "Mesh", infoHdfGroup, mapOfNames );
 
     // read SMESH_PreMeshInfo of groups
     map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator i2group = _mesh->_mapGroups.begin();
@@ -429,8 +438,8 @@ bool SMESH_PreMeshInfo::readPreInfoFromHDF()
         group_i->changePreMeshInfo() = newInstance();
         if ( SMESHDS_GroupBase* group = group_i->GetGroupDS() )
         {
-          const string name = group->GetStoreName();
-          group_i->changePreMeshInfo()->hdf2meshInfo( name, infoHdfGroup );
+          const std::string name = group->GetStoreName();
+          group_i->changePreMeshInfo()->hdf2meshInfo( name, infoHdfGroup, mapOfNames );
         }
       }
     }
@@ -442,9 +451,12 @@ bool SMESH_PreMeshInfo::readPreInfoFromHDF()
       if ( SMESH_subMesh_i* sm = SMESH::DownCast<SMESH_subMesh_i*>( id2sm->second ))
       {
         sm->changePreMeshInfo() = newInstance();
-        sm->changePreMeshInfo()->hdf2meshInfo( SMESH_Comment( sm->GetId()), infoHdfGroup );
+        sm->changePreMeshInfo()->hdf2meshInfo( SMESH_Comment( sm->GetId()),
+                                               infoHdfGroup,
+                                               mapOfNames );
       }
     }
+    infoHdfGroup->CloseOnDisk();
   }
 
   aFile->CloseOnDisk();
@@ -463,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);
@@ -499,7 +508,7 @@ void SMESH_PreMeshInfo::readGroupInfo()
   if ( _mesh->_mapGroups.empty() ) return;
 
   // make SMESH_PreMeshInfo of groups
-  map< string, SMESH_PreMeshInfo* > name2GroupInfo;
+  map< std::string, SMESH_PreMeshInfo* > name2GroupInfo;
   map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator i2group = _mesh->_mapGroups.begin();
   for ( ; i2group != _mesh->_mapGroups.end(); ++i2group )
   {
@@ -510,8 +519,8 @@ void SMESH_PreMeshInfo::readGroupInfo()
       group_i->changePreMeshInfo() = info;
       if ( SMESHDS_Group* group = dynamic_cast< SMESHDS_Group* >( group_i->GetGroupDS() ))
       {
-        string name = group->GetStoreName();
-        name2GroupInfo.insert( make_pair( name, info ));
+        std::string name = group->GetStoreName();
+        name2GroupInfo.insert( std::make_pair( name, info ));
         info->_isInfoOk = true;
       }
     }
@@ -519,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
@@ -534,8 +543,8 @@ void SMESH_PreMeshInfo::readGroupInfo()
     vector< SMESH_PreMeshInfo* >& grInfoVec = famId2grInfo[ medFamInfo->GetId() ];
     for ( int iG = 0; iG < nbGroups; ++iG )
     {
-      const string grName = medFamInfo->GetGroupName( iG );
-      map< string, SMESH_PreMeshInfo* >::iterator n2i = name2GroupInfo.find( grName );
+      const std::string grName = medFamInfo->GetGroupName( iG );
+      map< std::string, SMESH_PreMeshInfo* >::iterator n2i = name2GroupInfo.find( grName );
       if ( n2i != name2GroupInfo.end() )
         grInfoVec.push_back( n2i->second );
     }
@@ -560,14 +569,14 @@ void SMESH_PreMeshInfo::readGroupInfo()
         f2infos = famId2grInfo.find( famNums[i] );
         if ( f2infos == famId2grInfo.end() )
           f2infos = famId2grInfo.insert
-            ( make_pair( famNums[i], vector< SMESH_PreMeshInfo*>())).first;
+            ( std::make_pair( famNums[i], vector< SMESH_PreMeshInfo*>())).first;
       }
       vector< SMESH_PreMeshInfo* >& infoVec = f2infos->second ;
       for ( size_t j = 0; j < infoVec.size(); ++j )
         infoVec[j]->_elemCounter++;
     }
     // pass _elemCounter to a real elem type
-    map< string, SMESH_PreMeshInfo* >::iterator n2i = name2GroupInfo.begin();
+    map< std::string, SMESH_PreMeshInfo* >::iterator n2i = name2GroupInfo.begin();
     for ( ; n2i != name2GroupInfo.end(); ++n2i )
     {
       SMESH_PreMeshInfo* info = n2i->second;
@@ -618,7 +627,7 @@ void SMESH_PreMeshInfo::readSubMeshInfo()
 
       for ( int isNode = 0; isNode < 2; ++isNode )
       {
-        string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
+        std::string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
         if ( aGroup->ExistInternalObject( (char*) aDSName.c_str() ))
         {
           // read sub-mesh id of all nodes or elems
@@ -832,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()" );
 }
@@ -893,13 +903,13 @@ void SMESH_PreMeshInfo::readSubMeshes(DriverMED_R_SMESHDS_Mesh* reader) const
       SMDS_ElemIteratorPtr eIt = meshDS->elementsIterator();
       for ( int isNode = 0; isNode < 2; ++isNode )
       {
-        string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
+        std::string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
         if ( aGroup->ExistInternalObject( (char*) aDSName.c_str() ))
         {
           HDFdataset* aDataset = new HDFdataset( (char*) aDSName.c_str(), aGroup );
           aDataset->OpenOnDisk();
           // read submesh IDs for all elements sorted by ID
-          int nbElems = aDataset->GetSize();
+          size_t nbElems = aDataset->GetSize();
           int* smIDs = new int [ nbElems ];
           aDataset->ReadFromDisk( smIDs );
           aDataset->CloseOnDisk();
@@ -919,9 +929,9 @@ void SMESH_PreMeshInfo::readSubMeshes(DriverMED_R_SMESHDS_Mesh* reader) const
 #endif
             nbElems = elemSet.size();
           }
-          // add elements to submeshes
+          // add elements to sub-meshes
           TIDSortedElemSet::iterator iE = elemSet.begin();
-          for ( int i = 0; i < nbElems; ++i, ++iE )
+          for ( size_t i = 0; i < nbElems; ++i, ++iE )
           {
             int smID = smIDs[ i ];
             if ( smID == 0 ) continue;
@@ -942,7 +952,7 @@ void SMESH_PreMeshInfo::readSubMeshes(DriverMED_R_SMESHDS_Mesh* reader) const
             if ( isNode ) {
               SMDS_PositionPtr pos = aPositionCreator.MakePosition( smType[ smID ]);
               SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( static_cast<const SMDS_MeshNode*>( elem ));
-              node->SetPosition( pos );
+              node->SetPosition( pos, sm->GetID() );
               sm->AddNode( node );
             } else {
               sm->AddElement( elem );
@@ -1043,8 +1053,7 @@ void SMESH_PreMeshInfo::readSubMeshes(DriverMED_R_SMESHDS_Mesh* reader) const
             // -- Most probably a bad study was saved when there were
             // not fixed bugs in SMDS_MeshInfo
             if ( aPos->GetTypeOfPosition() == SMDS_TOP_FACE ) {
-              SMDS_FacePosition* fPos = const_cast<SMDS_FacePosition*>
-                ( static_cast<const SMDS_FacePosition*>( aPos ));
+              SMDS_FacePositionPtr fPos = aPos;
               fPos->SetUParameter( aUPos[ iNode ]);
               fPos->SetVParameter( aVPos[ iNode ]);
             }
@@ -1052,9 +1061,8 @@ void SMESH_PreMeshInfo::readSubMeshes(DriverMED_R_SMESHDS_Mesh* reader) const
           else {
             // ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE );-- issue 20182
             if ( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE ) {
-              SMDS_EdgePosition* fPos = const_cast<SMDS_EdgePosition*>
-                ( static_cast<const SMDS_EdgePosition*>( aPos ));
-              fPos->SetUParameter( aUPos[ iNode ]);
+              SMDS_EdgePositionPtr ePos = aPos;
+              ePos->SetUParameter( aUPos[ iNode ]);
             }
           }
         }
@@ -1223,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 );