+ SMESH::long_array_var aResult = new SMESH::long_array();
+
+ if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
+ return aResult._retn();
+
+ SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS();
+ if ( aSubMeshDS == NULL )
+ return aResult._retn();
+
+ aResult->length( aSubMeshDS->NbElements() );
+ SMDS_ElemIteratorPtr anIt = aSubMeshDS->GetElements();
+ for ( int i = 0, n = aSubMeshDS->NbElements(); i < n && anIt->more(); i++ )
+ aResult[i] = anIt->next()->GetID();
+
+ return aResult._retn();
+}
+
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+SMESH::long_array* SMESH_subMesh_i::GetElementsByType( SMESH::ElementType theElemType )
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ MESSAGE("SMESH_subMesh_i::GetElementsByType");
+ SMESH::long_array_var aResult = new SMESH::long_array();
+
+ if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
+ return aResult._retn();
+
+ SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS();
+ if ( aSubMeshDS == NULL )
+ return aResult._retn();
+
+ // No sense in returning ids of elements along with ids of nodes:
+ // when theElemType == SMESH::ALL, return node ids only if
+ // there are no elements
+ bool retNodes = (theElemType == SMESH::NODE ||
+ (theElemType == SMESH::ALL && aSubMeshDS->NbElements() == 0));
+
+ // PAL5440, return all nodes belonging to elements of submesh
+ set<int> nodeIds;
+ if ( retNodes ) {
+ SMDS_ElemIteratorPtr eIt = aSubMeshDS->GetElements();
+ while ( eIt->more() ) {
+ const SMDS_MeshElement* anElem = eIt->next();
+ SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
+ while ( nIt->more() )
+ nodeIds.insert( nIt->next()->GetID() );
+ }
+ }
+
+ if ( theElemType == SMESH::ALL )
+ aResult->length( aSubMeshDS->NbElements() + nodeIds.size());
+ else if ( theElemType == SMESH::NODE )
+ aResult->length( nodeIds.size() );
+ else
+ aResult->length( aSubMeshDS->NbElements() );
+
+ int i = 0, n = aResult->length();
+
+ if ( retNodes && !nodeIds.empty() ) {
+ set<int>::iterator idIt = nodeIds.begin();
+ for ( ; i < n && idIt != nodeIds.end() ; i++, idIt++ )
+ aResult[i] = *idIt;
+ }
+
+ if ( theElemType == SMESH::ALL || theElemType != SMESH::NODE ) {
+ SMDS_ElemIteratorPtr anIt = aSubMeshDS->GetElements();
+ while ( i < n && anIt->more() ) {
+ const SMDS_MeshElement* anElem = anIt->next();
+ if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
+ aResult[i++] = anElem->GetID();
+ }
+ }
+
+ aResult->length( i );
+
+ return aResult._retn();