Salome HOME
Update copyright notes (for 2010)
[modules/smesh.git] / src / SMESH_I / SMESH_Filter_i.cxx
index 40742a667a47a06723cd0b38c872cde6f903f473..969ffb61387adfbe9d2b6a7ae0149770f5bf8651 100644 (file)
@@ -1,4 +1,4 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//  Copyright (C) 2007-2010  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
@@ -19,6 +19,7 @@
 //
 //  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_Filter_i.cxx
 //  Author : Alexey Petrov, OCC
@@ -32,6 +33,7 @@
 #include "SMDS_Mesh.hxx"
 #include "SMDS_MeshNode.hxx"
 #include "SMDS_MeshElement.hxx"
+#include "SMDS_ElemIterator.hxx"
 
 #include "SMESHDS_Mesh.hxx"
 
@@ -2098,7 +2100,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 +2152,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
@@ -2381,13 +2437,13 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria
       pd << "aCriterion = SMESH.Filter.Criterion(" << aCriterion << "," << aCompare
          << "," << aThreshold << ",'" << aThresholdStr;
       if (aThresholdID && strlen(aThresholdID))
-       //pd << "',salome.ObjectToID(" << aThresholdID
+        //pd << "',salome.ObjectToID(" << aThresholdID
         pd << "','" << aThresholdID
-          << "'," << aUnary << "," << aBinary << "," << aTolerance
-          << "," << aTypeOfElem << "," << aPrecision << ")";
+           << "'," << aUnary << "," << aBinary << "," << aTolerance
+           << "," << aTypeOfElem << "," << aPrecision << ")";
       else
-       pd << "',''," << aUnary << "," << aBinary << "," << aTolerance
-          << "," << aTypeOfElem << "," << aPrecision << ")";
+        pd << "',''," << aUnary << "," << aBinary << "," << aTolerance
+           << "," << aTypeOfElem << "," << aPrecision << ")";
     }
 
     SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
@@ -2479,7 +2535,7 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria
         {
           SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
           tmpPred->SetElementType( aTypeOfElem );
-         tmpPred->SetShape( aThresholdID, aThresholdStr );
+          tmpPred->SetShape( aThresholdID, aThresholdStr );
           tmpPred->SetTolerance( aTolerance );
           aPredicate = tmpPred;
         }