Salome HOME
Merge from V5_1_main branch 24/11/2010
[modules/smesh.git] / src / SMESH_I / SMESH_Group_i.cxx
index c69024ed215ce4f5d93118049be515259ff5fa35..592d172bacbdd4b61c8da769af0630132ab76541 100644 (file)
@@ -36,6 +36,8 @@
 #include "SMESH_Filter_i.hxx"
 #include "SMESH_PythonDump.hxx"
 
+#include CORBA_SERVER_HEADER(SMESH_Filter)
+
 #include "utilities.h"
 
 using namespace SMESH;
@@ -347,6 +349,37 @@ RemoveByPredicate( SMESH::Predicate_ptr thePredicate )
   return 0;
 }
 
+CORBA::Long SMESH_Group_i::AddFrom( SMESH::SMESH_IDSource_ptr theSource )
+{
+  long nbAdd = 0;
+  SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
+  if (aGroupDS) {
+    SMESH::long_array_var anIds;
+    SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow(theSource);
+    SMESH::SMESH_Mesh_var mesh       = SMESH::SMESH_Mesh::_narrow(theSource);
+    SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow(theSource);
+    SMESH::Filter_var filter         = SMESH::Filter::_narrow(theSource);
+    if ( !group->_is_nil())
+      anIds = group->GetType()==GetType() ? theSource->GetIDs() :  new SMESH::long_array();
+    else if ( !mesh->_is_nil() )
+      anIds = mesh->GetElementsByType( GetType() );
+    else if ( !submesh->_is_nil())
+      anIds = submesh->GetElementsByType( GetType() );
+    else if ( !filter->_is_nil() )
+      anIds = filter->GetElementType()==GetType() ? theSource->GetIDs() : new SMESH::long_array();
+    else 
+      anIds = theSource->GetIDs();
+    for ( int i = 0, total = anIds->length(); i < total; i++ ) {
+      if ( aGroupDS->Add((int)anIds[i]) ) nbAdd++;
+    }
+  }
+
+  // Update Python script
+  TPythonDump() << "nbAdd = " << _this() << ".AddFrom( " << theSource << " )";
+
+  return nbAdd;
+}
+
 //=============================================================================
 /*!
  *  
@@ -396,17 +429,6 @@ SMESH::SMESH_Mesh_ptr SMESH_GroupBase_i::GetMesh()
   return aMesh._retn();
 }
 
-//=============================================================================
-/*!
- *  
- */
-//=============================================================================
-SMESH::long_array* SMESH_GroupBase_i::GetIDs()
-{
-  SMESH::long_array_var aResult = GetListOfID();
-  return aResult._retn();
-}
-
 //=======================================================================
 //function : GetShape
 //purpose  : 
@@ -513,3 +535,28 @@ SMESH::long_array* SMESH_GroupBase_i::GetMeshInfo()
     SMESH_Mesh_i::CollectMeshInfo( aGrpDS->GetElements(), aRes);
   return aRes._retn();
 }
+
+//=======================================================================
+//function : GetIDs
+//purpose  : Returns ids of members
+//=======================================================================
+
+SMESH::long_array* SMESH_GroupBase_i::GetIDs()
+{
+  SMESH::long_array_var aResult = GetListOfID();
+  return aResult._retn();
+}
+
+//=======================================================================
+//function : GetTypes
+//purpose  : Returns types of elements it contains
+//=======================================================================
+
+SMESH::array_of_ElementType* SMESH_GroupBase_i::GetTypes()
+{
+  SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
+  types->length( 1 );
+  types[0] = GetType();
+  return types._retn();
+}
+