Salome HOME
untabify
[modules/smesh.git] / src / SMESH_I / SMESH_Filter_i.cxx
index 40742a667a47a06723cd0b38c872cde6f903f473..c75d81e8877cc7914074b69ddfb0e9a2746406d6 100644 (file)
@@ -32,6 +32,7 @@
 #include "SMDS_Mesh.hxx"
 #include "SMDS_MeshNode.hxx"
 #include "SMDS_MeshElement.hxx"
+#include "SMDS_ElemIterator.hxx"
 
 #include "SMESHDS_Mesh.hxx"
 
@@ -2098,7 +2099,7 @@ SetMesh( SMESH_Mesh_ptr theMesh )
   if(!CORBA::is_nil(myMesh))
     myMesh->Destroy();
 
-  myMesh = theMesh;
+  myMesh = SMESH_Mesh::_duplicate( theMesh );
   TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
 }
 
@@ -2150,6 +2151,60 @@ GetElementsId( SMESH_Mesh_ptr theMesh )
   return anArray._retn();
 }
 
+template<class TElement, class TIterator, class TPredicate>
+static void collectMeshInfo(const TIterator& theItr,
+                            TPredicate& thePred,
+                            SMESH::long_array& theRes)
+{         
+  if (!theItr)
+    return;
+  while (theItr->more()) {
+    const SMDS_MeshElement* anElem = theItr->next();
+    if ( thePred->IsSatisfy( anElem->GetID() ) )
+      theRes[ anElem->GetEntityType() ]++;
+  }
+}
+
+//=============================================================================
+/*!
+ * \brief Returns statistic of mesh elements
+ */
+//=============================================================================
+SMESH::long_array* ::Filter_i::GetMeshInfo()
+{
+  SMESH::long_array_var aRes = new SMESH::long_array();
+  aRes->length(SMESH::Entity_Last);
+  for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
+    aRes[i] = 0;
+
+  if(!CORBA::is_nil(myMesh) && myPredicate) {
+    const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
+    SMDS_ElemIteratorPtr it;
+    switch( GetElementType() )
+    {
+  case SMDSAbs_Node:
+    collectMeshInfo<const SMDS_MeshNode*>(aMesh->nodesIterator(),myPredicate,aRes);
+    break;
+  case SMDSAbs_Edge:
+    collectMeshInfo<const SMDS_MeshElement*>(aMesh->edgesIterator(),myPredicate,aRes);
+    break;
+  case SMDSAbs_Face:
+    collectMeshInfo<const SMDS_MeshElement*>(aMesh->facesIterator(),myPredicate,aRes);
+    break;
+  case SMDSAbs_Volume:
+    collectMeshInfo<const SMDS_MeshElement*>(aMesh->volumesIterator(),myPredicate,aRes);
+    break;
+  case SMDSAbs_All:
+  default:
+    collectMeshInfo<const SMDS_MeshElement*>(aMesh->elementsIterator(),myPredicate,aRes);
+    break;
+    }
+  }
+
+
+  return aRes._retn();  
+}
+
 //=======================================================================
 // name    : getCriteria
 // Purpose : Retrieve criterions from predicate