Salome HOME
52447: Re-compute fails after hypothesis modification
[modules/smesh.git] / src / SMESH_I / SMESH_PreMeshInfo.cxx
index e56adfadf43b4e3f9971d8dadf19f8720a7946de..59a7e65c8318f73712850918bad3f1181882b1cc 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  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
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -26,7 +26,9 @@
 
 #include "SMESH_PreMeshInfo.hxx"
 
+#include "DriverMED.hxx"
 #include "DriverMED_R_SMESHDS_Mesh.h"
+#include "MED_Factory.hxx"
 #include "SMDS_EdgePosition.hxx"
 #include "SMDS_FacePosition.hxx"
 #include "SMDS_SpacePosition.hxx"
 #include <HDFdataset.hxx>
 #include <HDFfile.hxx>
 #include <HDFgroup.hxx>
-#include <MED_Factory.hxx>
 #include <SALOMEDS_Tool.hxx>
+#include <SALOMEDS_wrap.hxx>
 
-#include <Standard_ErrorHandler.hxx>
-#include <Standard_Failure.hxx>
 #include <TopoDS_Iterator.hxx>
 #include <TopoDS_Shape.hxx>
 
+#include "SMESH_TryCatch.hxx"
+
 #include CORBA_SERVER_HEADER(SALOME_Session)
 
-#define MYDEBUGOUT(msg) //std::cout << msg << std::endl;
 
-//================================================================================
-#define PreMeshInfo_TRY \
-  try { OCC_CATCH_SIGNALS
-//================================================================================
-#define PreMeshInfo_CATCH }                                             \
-  catch (Standard_Failure& ex) {                                        \
-    onExceptionCaught(SMESH_Comment("OCC Exception caught: \t")<<ex.GetMessageString()); \
-  }                                                                     \
-  catch ( const std::exception& ex) {                                   \
-    onExceptionCaught(SMESH_Comment("Exception caught: \t")<<ex.what()); \
-  }                                                                     \
-  catch (...) {                                                         \
-    onExceptionCaught("Unknown Exception caught");                      \
-  }
-//================================================================================
+#define MYDEBUGOUT(msg) //std::cout << msg << std::endl;
 
 namespace
 {
@@ -114,18 +101,6 @@ namespace
     }
   }
 
-  //================================================================================
-  /*!
-   * \brief Method useful only to set a breakpoint to debug in case of exception
-   */
-  //================================================================================
-
-  void onExceptionCaught(const string& msg)
-  {
-    INFOS( msg );
-    MYDEBUGOUT( msg );
-  }
-
   //=============================================================================
   /*!
    * \brief Class sending signals on start and finish of loading
@@ -143,8 +118,8 @@ namespace
       SALOMEDS::Study_var study = gen->GetCurrentStudy();
       if ( !study->_is_nil() && study->StudyId() == mesh->GetStudyId() )
       {
-        SALOMEDS::SObject_var meshSO = gen->ObjectToSObject(study, mesh->_this() );
-        CORBA::Object_var obj = gen->GetNS()->Resolve( "/Kernel/Session" );
+        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() )
         {
@@ -253,53 +228,17 @@ namespace
     static map< MED::EGeometrieElement, SMDSAbs_EntityType> med2smeshTypes;
     if ( med2smeshTypes.empty() )
     {
-      med2smeshTypes[ MED::ePOINT1   ] = SMDSEntity_0D                ;
-      med2smeshTypes[ MED::eSEG2     ] = SMDSEntity_Edge              ;
-      med2smeshTypes[ MED::eSEG3     ] = SMDSEntity_Quad_Edge         ;
-      med2smeshTypes[ MED::eTRIA3    ] = SMDSEntity_Triangle          ;
-      med2smeshTypes[ MED::eTRIA6    ] = SMDSEntity_Quad_Triangle     ;
-      med2smeshTypes[ MED::eQUAD4    ] = SMDSEntity_Quadrangle        ;
-      med2smeshTypes[ MED::eQUAD8    ] = SMDSEntity_Quad_Quadrangle   ;
-      med2smeshTypes[ MED::eQUAD9    ] = SMDSEntity_BiQuad_Quadrangle ;
-      med2smeshTypes[ MED::eTETRA4   ] = SMDSEntity_Tetra             ;
-      med2smeshTypes[ MED::ePYRA5    ] = SMDSEntity_Pyramid           ;
-      med2smeshTypes[ MED::ePENTA6   ] = SMDSEntity_Penta             ;
-      med2smeshTypes[ MED::eHEXA8    ] = SMDSEntity_Hexa              ;
-      med2smeshTypes[ MED::eOCTA12   ] = SMDSEntity_Hexagonal_Prism   ;
-      med2smeshTypes[ MED::eTETRA10  ] = SMDSEntity_Quad_Tetra        ;
-      med2smeshTypes[ MED::ePYRA13   ] = SMDSEntity_Quad_Pyramid      ;
-      med2smeshTypes[ MED::ePENTA15  ] = SMDSEntity_Quad_Penta        ;
-      med2smeshTypes[ MED::eHEXA20   ] = SMDSEntity_Quad_Hexa         ;
-      med2smeshTypes[ MED::eHEXA27   ] = SMDSEntity_TriQuad_Hexa      ;
-      med2smeshTypes[ MED::ePOLYGONE ] = SMDSEntity_Polygon           ;
-      med2smeshTypes[ MED::ePOLYEDRE ] = SMDSEntity_Polyhedra         ;
-      med2smeshTypes[ MED::eNONE     ] = SMDSEntity_Node              ;
-      med2smeshTypes[ MED::eBALL     ] = SMDSEntity_Ball              ;
+      for  ( int iG = 0; iG < SMDSEntity_Last; ++iG )
+      {
+        SMDSAbs_EntityType    smdsType = (SMDSAbs_EntityType) iG;
+        MED::EGeometrieElement medType =
+          (MED::EGeometrieElement) DriverMED::GetMedGeoType( smdsType );
+        med2smeshTypes.insert( make_pair( medType, smdsType ));
+      }
     }
     return med2smeshTypes;
   }
 
-  //================================================================================
-  /*!
-   * \brief Return a vector<MED::EGeometrieElement> intended to retrieve
-   *        MED::EGeometrieElement by SMDSAbs_EntityType
-   */
-  //================================================================================
-
-  const vector<MED::EGeometrieElement>& mesh2medElemType()
-  {
-    static vector<MED::EGeometrieElement> mesh2medElemTypes;
-    if ( mesh2medElemTypes.empty() )
-    {
-      mesh2medElemTypes.resize( SMDSEntity_Last + 1 );
-      Tmed2smeshElemTypeMap::const_iterator me2sme    = med2smeshElemTypeMap().begin();
-      Tmed2smeshElemTypeMap::const_iterator me2smeEnd = med2smeshElemTypeMap().end();
-      for ( ; me2sme != me2smeEnd; ++me2sme )
-        mesh2medElemTypes[ me2sme->second ] = me2sme->first;
-    }
-    return mesh2medElemTypes;
-  }
-
   //================================================================================
   /*!
    * \brief Writes meshInfo into a HDF file
@@ -310,17 +249,17 @@ namespace
                      const std::string&    name,
                      HDFgroup*             hdfGroup)
   {
-    // we use med identification of element (MED::EGeometrieElement>) types
+    // we use med identification of element (MED::EGeometrieElement) types
     // but not enum SMDSAbs_EntityType because values of SMDSAbs_EntityType may
     // change at insertion of new items in the middle.
-    const vector<MED::EGeometrieElement>& medTypes = mesh2medElemType();
+    //const vector<MED::EGeometrieElement>& medTypes = mesh2medElemType();
 
     vector<int> data;
 
     for ( size_t i = 0; i < meshInfo->length(); ++i )
       if ( meshInfo[i] > 0 )
       {
-        data.push_back( medTypes[ i ] );
+        data.push_back( DriverMED::GetMedGeoType( SMDSAbs_EntityType( i ))); //medTypes[ i ] );
         data.push_back( meshInfo[ i ] );
       }
 
@@ -430,7 +369,7 @@ void SMESH_PreMeshInfo::LoadFromFile( SMESH_Mesh_i*      mesh,
                                       const std::string& hdfFile,
                                       const bool         toRemoveFiles)
 {
-  PreMeshInfo_TRY;
+  SMESH_TRY;
 
   SMESH_PreMeshInfo* meshPreInfo = new SMESH_PreMeshInfo( mesh,meshID,medFile,hdfFile );
   mesh->changePreMeshInfo() = meshPreInfo;
@@ -454,7 +393,7 @@ void SMESH_PreMeshInfo::LoadFromFile( SMESH_Mesh_i*      mesh,
   {
     meshPreInfo->FullLoadFromFile();
   }
-  PreMeshInfo_CATCH;
+  SMESH_CATCH( SMESH::doNothing );
 }
 
 //================================================================================
@@ -797,7 +736,7 @@ void SMESH_PreMeshInfo::SaveToFile( SMESH_Mesh_i* mesh,
   HDFgroup* infoHdfGroup = new HDFgroup( hdfGroupName, hdfFile );
   infoHdfGroup->CreateOnDisk();
 
-  PreMeshInfo_TRY;
+  SMESH_TRY;
 
   // info of mesh
   meshInfo2hdf( mesh->GetMeshInfo(), "Mesh", infoHdfGroup );
@@ -840,7 +779,7 @@ void SMESH_PreMeshInfo::SaveToFile( SMESH_Mesh_i* mesh,
     }
   }
 
-  PreMeshInfo_CATCH;
+  SMESH_CATCH( SMESH::doNothing );
 
   infoHdfGroup->CloseOnDisk();
 }
@@ -858,10 +797,10 @@ void SMESH_PreMeshInfo::FullLoadFromFile() const
   SMESH_PreMeshInfo* meshInfo = _mesh->changePreMeshInfo();
   _mesh->changePreMeshInfo() = NULL; // to allow GUI accessing to real info
 
-  ::SMESH_Mesh& mesh = _mesh->GetImpl();
+  ::SMESH_Mesh&   mesh = _mesh->GetImpl();
   SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
 
-  PreMeshInfo_TRY;
+  SMESH_TRY;
 
   MYDEBUGOUT( "BEG FullLoadFromFile() " << _meshID );
 
@@ -882,7 +821,7 @@ void SMESH_PreMeshInfo::FullLoadFromFile() const
   // load sub-meshes
   readSubMeshes( &myReader );
 
-  PreMeshInfo_CATCH;
+  SMESH_CATCH( SMESH::doNothing );
 
   _mesh->changePreMeshInfo() = meshInfo;
 
@@ -919,6 +858,19 @@ void SMESH_PreMeshInfo::readSubMeshes(DriverMED_R_SMESHDS_Mesh* reader) const
 
     SMESHDS_Mesh* meshDS = _mesh->GetImpl().GetMeshDS();
 
+    // issue 0020693. Restore _isModified flag
+    if ( aTopGroup->ExistInternalObject( "_isModified" ))
+    {
+      HDFdataset* aDataset = new HDFdataset( "_isModified", aTopGroup );
+      aDataset->OpenOnDisk();
+      hdf_size size = aDataset->GetSize();
+      int* isModified = new int[ size ];
+      aDataset->ReadFromDisk( isModified );
+      aDataset->CloseOnDisk();
+      _mesh->GetImpl().SetIsModified( bool(*isModified));
+      delete [] isModified;
+    }
+
     bool submeshesInFamilies = ( ! aTopGroup->ExistInternalObject( "Submeshes" ));
     if ( submeshesInFamilies ) // from MED
     {
@@ -1132,7 +1084,7 @@ void SMESH_PreMeshInfo::readSubMeshes(DriverMED_R_SMESHDS_Mesh* reader) const
 
 void SMESH_PreMeshInfo::ForgetAllData() const
 {
-  PreMeshInfo_TRY;
+  SMESH_TRY;
 
   if ( _mesh->changePreMeshInfo() != this )
     return _mesh->changePreMeshInfo()->ForgetAllData();
@@ -1153,9 +1105,9 @@ void SMESH_PreMeshInfo::ForgetAllData() const
   map<int, SMESH::SMESH_subMesh_ptr>::iterator id2sm = _mesh->_mapSubMeshIor.begin();
   for ( ; id2sm != _mesh->_mapSubMeshIor.end(); ++id2sm )
   {
-    if ( SMESH_subMesh_i* sm = SMESH::DownCast<SMESH_subMesh_i*>( id2sm->second ))
+    if ( SMESH_subMesh_i* sm_i = SMESH::DownCast<SMESH_subMesh_i*>( id2sm->second ))
     {
-      SMESH_PreMeshInfo* & info = sm->changePreMeshInfo();
+      SMESH_PreMeshInfo* & info = sm_i->changePreMeshInfo();
       delete info;
       info = NULL;
     }
@@ -1164,12 +1116,12 @@ void SMESH_PreMeshInfo::ForgetAllData() const
   _mesh->changePreMeshInfo() = NULL;
   delete this;
 
-  PreMeshInfo_CATCH;
+  SMESH_CATCH( SMESH::doNothing );
 
 
   // Finalize loading
 
-  // PreMeshInfo_TRY;
+  // SMESH_TRY;
 
   // ::SMESH_Mesh& mesh = _mesh->GetImpl();
 
@@ -1180,7 +1132,19 @@ void SMESH_PreMeshInfo::ForgetAllData() const
   // //     hyp->UpdateAsMeshesRestored();
 
 
-  // PreMeshInfo_CATCH;
+  // SMESH_CATCH( SMESH::doNothing );
+}
+
+//================================================================================
+/*!
+ * \brief remove all SMESH_PreMeshInfo fields from mesh and its child objects w/o data loading
+ */
+//================================================================================
+
+void SMESH_PreMeshInfo::ForgetAllData( SMESH_Mesh_i* mesh )
+{
+  if ( mesh && mesh->changePreMeshInfo() )
+    mesh->changePreMeshInfo()->ForgetAllData();
 }
 
 //================================================================================
@@ -1262,10 +1226,10 @@ void SMESH_PreMeshInfo::RemoveStudyFiles_TMP_METHOD(SALOMEDS::SComponent_ptr sme
   SALOMEDS::Study_var study = smeshComp->GetStudy();
   if ( theStudyIDToMeshCounter[ (int) study->StudyId() ] > 0 )
   {
-    SALOMEDS::ChildIterator_var itBig = study->NewChildIterator( smeshComp );
+    SALOMEDS::ChildIterator_wrap itBig = study->NewChildIterator( smeshComp );
     for ( ; itBig->More(); itBig->Next() ) {
-      SALOMEDS::SObject_var gotBranch = itBig->Value();
-      CORBA::Object_var anObject = SMESH_Gen_i::SObjectToObject( gotBranch );
+      SALOMEDS::SObject_wrap gotBranch = itBig->Value();
+      CORBA::Object_var       anObject = SMESH_Gen_i::SObjectToObject( gotBranch );
       if ( SMESH_Mesh_i* mesh = SMESH::DownCast<SMESH_Mesh_i*>( anObject ))
       {
         if ( mesh->changePreMeshInfo() )