Salome HOME
PAL13617 NbSubMesh() method works wrong
[modules/smesh.git] / src / SMESH_I / SMESH_Mesh_i.cxx
index 87e95bbc7d31d82a8860907f6a286bc7446bb4a8..499c3b75163daf0c32fdbacf4b3cc5e2136f780a 100644 (file)
@@ -1,6 +1,6 @@
-//  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
 //  This library is free software; you can redistribute it and/or
 //  License along with this library; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+//  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
 //  File   : SMESH_Mesh_i.cxx
 //  Author : Paul RASCLE, EDF
 //  Module : SMESH
 //  $Header$
-
+//
 #include "SMESH_Mesh_i.hxx"
 
 #include "SMESH_Filter_i.hxx"
@@ -72,6 +71,7 @@
 #include <string>
 #include <iostream>
 #include <sstream>
+#include <sys/stat.h>
 
 #ifdef _DEBUG_
 static int MYDEBUG = 0;
@@ -175,7 +175,7 @@ CORBA::Boolean SMESH_Mesh_i::HasShapeToMesh()
 //=======================================================================
 
 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
-    throw (SALOME::SALOME_Exception)
+  throw (SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
   GEOM::GEOM_Object_var aShapeObj;
@@ -190,6 +190,24 @@ GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
   return aShapeObj._retn();
 }
 
+//================================================================================
+/*!
+ * \brief Remove all nodes and elements
+ */
+//================================================================================
+
+void SMESH_Mesh_i::Clear() throw (SALOME::SALOME_Exception)
+{
+  Unexpect aCatch(SALOME_SalomeException);
+  try {
+    _impl->Clear();
+  }
+  catch(SALOME_Exception & S_ex) {
+    THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
+  }
+  TPythonDump() <<  _this() << ".Clear()";
+}
+
 //=============================================================================
 /*!
  *
@@ -242,6 +260,24 @@ SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
 
   CreateGroupServants();
 
+  int major, minor, release;
+  if( !MED::getMEDVersion( theFileName, major, minor, release ) )
+    major = minor = release = -1;
+  myFileInfo           = new SALOME_MED::MedFileInfo();
+  myFileInfo->fileName = theFileName;
+  myFileInfo->fileSize = 0;
+#ifdef WIN32
+  struct _stati64 d;
+  if ( ::_stati64( theFileName, &d ) != -1 )
+#else
+  struct stat64 d;
+  if ( ::stat64( theFileName, &d ) != -1 )
+#endif
+    myFileInfo->fileSize = d.st_size;
+  myFileInfo->major    = major;
+  myFileInfo->minor    = minor;
+  myFileInfo->release  = release;
+
   return ConvertDriverMEDReadStatus(status);
 }
 
@@ -335,6 +371,7 @@ SMESH::Hypothesis_Status SMESH_Mesh_i::ConvertHypothesisStatus
   RETURNCASE( HYP_BAD_DIM       );
   RETURNCASE( HYP_BAD_SUBSHAPE  );
   RETURNCASE( HYP_BAD_GEOMETRY  );
+  RETURNCASE( HYP_NEED_SHAPE    );
   default:;
   }
   return SMESH::HYP_UNKNOWN_FATAL;
@@ -1437,7 +1474,7 @@ CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
   return _impl->HasDuplicatedGroupNamesMED();
 }
 
-static void PrepareForWriting (const char* file)
+void SMESH_Mesh_i::PrepareForWriting (const char* file)
 {
   TCollection_AsciiString aFullName ((char*)file);
   OSD_Path aPath (aFullName);
@@ -1756,7 +1793,7 @@ CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
-  return _impl->NbSubMesh();
+  return _mapSubMesh_i.size();
 }
 
 //=============================================================================
@@ -2008,7 +2045,8 @@ SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID
 CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
 {
   CORBA::LongLong pointeur = CORBA::LongLong(_impl);
-  cerr << "CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() " << pointeur << endl;
+  if ( MYDEBUG )
+    MESSAGE("CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() "<<pointeur);
   return pointeur;
 }
 
@@ -2479,3 +2517,20 @@ SMESH::ListOfGroups* SMESH_Mesh_i::GetGroups(const list<int>& groupIDs) const
   aList->length( nbGroups );
   return aList._retn();
 }
+
+//=============================================================================
+/*!
+ * \brief Return information about imported file
+ */
+//=============================================================================
+
+SALOME_MED::MedFileInfo* SMESH_Mesh_i::GetMEDFileInfo()
+{
+  SALOME_MED::MedFileInfo_var res( myFileInfo );
+  if ( !res.operator->() ) {
+    res = new SALOME_MED::MedFileInfo;
+    res->fileName = "";
+    res->fileSize = res->major = res->minor = res->release = -1;
+  }
+  return res._retn();
+}