Salome HOME
PR: synchro V6_main tag mergeto_V7_main_11Feb13
[modules/smesh.git] / src / SMESH_I / SMESH_PreMeshInfo.cxx
index 26eb2b9f5d2de25bea0e9da3fadfe4cc1e30fe49..caee49db7e8a5ecf05720d850ce56dad3b7f8c77 100644 (file)
 #include "SMESH_Mesh_i.hxx"
 #include "SMESH_subMesh_i.hxx"
 
+#include <MED_Factory.hxx>
+
 #include <HDFarray.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() )
         {
@@ -230,6 +205,17 @@ namespace
     return ids;
   }
 
+  //================================================================================
+  /*!
+   * \brief Return EEntiteMaillage by EGeometrieElement
+   */
+  //================================================================================
+
+  MED::EEntiteMaillage entityByGeom(const MED::EGeometrieElement geom )
+  {
+    return geom == MED::eBALL ? MED::eSTRUCT_ELEMENT : MED::eMAILLE;
+  }
+
   //================================================================================
   /*!
    * \brief Return a map< EGeometrieElement, SMDSAbs_EntityType >
@@ -263,6 +249,7 @@ namespace
       med2smeshTypes[ MED::ePOLYGONE ] = SMDSEntity_Polygon           ;
       med2smeshTypes[ MED::ePOLYEDRE ] = SMDSEntity_Polyhedra         ;
       med2smeshTypes[ MED::eNONE     ] = SMDSEntity_Node              ;
+      med2smeshTypes[ MED::eBALL     ] = SMDSEntity_Ball              ;
     }
     return med2smeshTypes;
   }
@@ -418,7 +405,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;
@@ -442,7 +429,7 @@ void SMESH_PreMeshInfo::LoadFromFile( SMESH_Mesh_i*      mesh,
   {
     meshPreInfo->FullLoadFromFile();
   }
-  PreMeshInfo_CATCH;
+  SMESH_CATCH( SMESH::doNothing );
 }
 
 //================================================================================
@@ -463,7 +450,6 @@ bool SMESH_PreMeshInfo::readPreInfoFromHDF()
   const bool infoAvailable = aFile->ExistInternalObject( hdfGroupName );
   if ( infoAvailable )
   {
-
     HDFgroup* infoHdfGroup = new HDFgroup( hdfGroupName, aFile );
     infoHdfGroup->OpenOnDisk();
 
@@ -530,7 +516,7 @@ bool SMESH_PreMeshInfo::readMeshInfo()
     Tmed2smeshElemTypeMap::const_iterator me2smeEnd = med2smeshElemTypeMap().end();
     for ( ; me2sme != me2smeEnd; ++me2sme )
     {
-      int nbElems = aMed->GetNbCells( medMeshInfo, MED::eMAILLE, me2sme->first );
+      int nbElems = aMed->GetNbCells( medMeshInfo, entityByGeom(me2sme->first), me2sme->first );
       if ( nbElems > 0 )
         setNb( me2sme->second, nbElems );
     }
@@ -600,7 +586,7 @@ void SMESH_PreMeshInfo::readGroupInfo()
   {
     famNums.resize( NbEntities( me2sme->second ));
     if ( famNums.empty() ) continue;
-    aMed->GetFamilies( medElemInfo, famNums.size(), MED::eMAILLE, me2sme->first );
+    aMed->GetFamilies( medElemInfo, famNums.size(), entityByGeom(me2sme->first), me2sme->first );
     // distribute elements of a type among groups
     map< int, vector< SMESH_PreMeshInfo* > >::iterator f2infos = famId2grInfo.begin();
     for ( size_t i = 0; i < famNums.size(); ++i )
@@ -786,7 +772,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 );
@@ -829,7 +815,7 @@ void SMESH_PreMeshInfo::SaveToFile( SMESH_Mesh_i* mesh,
     }
   }
 
-  PreMeshInfo_CATCH;
+  SMESH_CATCH( SMESH::doNothing );
 
   infoHdfGroup->CloseOnDisk();
 }
@@ -847,10 +833,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 );
 
@@ -871,7 +857,7 @@ void SMESH_PreMeshInfo::FullLoadFromFile() const
   // load sub-meshes
   readSubMeshes( &myReader );
 
-  PreMeshInfo_CATCH;
+  SMESH_CATCH( SMESH::doNothing );
 
   _mesh->changePreMeshInfo() = meshInfo;
 
@@ -908,6 +894,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
     {
@@ -1121,7 +1120,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();
@@ -1142,9 +1141,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;
     }
@@ -1153,12 +1152,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();
 
@@ -1169,7 +1168,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();
 }
 
 //================================================================================
@@ -1199,14 +1210,11 @@ SMESH::array_of_ElementType* SMESH_PreMeshInfo::GetTypes() const
 
   types->length( 4 );
   int nbTypes = 0;
-  if (NbEdges())
-    types[nbTypes++] = SMESH::EDGE;
-  if (NbFaces())
-    types[nbTypes++] = SMESH::FACE;
-  if (NbVolumes())
-    types[nbTypes++] = SMESH::VOLUME;
-  if (Nb0DElements())
-    types[nbTypes++] = SMESH::ELEM0D;
+  if (NbEdges())      types[nbTypes++] = SMESH::EDGE;
+  if (NbFaces())      types[nbTypes++] = SMESH::FACE;
+  if (NbVolumes())    types[nbTypes++] = SMESH::VOLUME;
+  if (Nb0DElements()) types[nbTypes++] = SMESH::ELEM0D;
+  if (NbBalls())      types[nbTypes++] = SMESH::BALL;
   types->length( nbTypes );
 
   return types._retn();
@@ -1254,10 +1262,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() )