+ Unexpect aCatch(SALOME_SalomeException);
+
+ SMESH::long_array_var aResult = new SMESH::long_array();
+
+ if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
+ return aResult._retn();
+
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ ::SMESH_subMesh* aSubMesh = _mesh_i->_mapSubMesh[_localId];
+ SMESHDS_SubMesh* aSubMeshDS = aSubMesh->GetSubMeshDS();
+
+ int nbElems = aSubMeshDS ? aSubMeshDS->NbElements() : 0;
+ TListOfSubMeshes smList;
+ if ( nbElems )
+ smList.push_back( aSubMeshDS );
+
+ // volumes are bound to shell
+ if ( nbElems == 0 && getSubMeshes( aSubMesh, smList ))
+ {
+ TListOfSubMeshes::iterator sm = smList.begin();
+ for ( ; sm != smList.end(); ++sm )
+ nbElems += (*sm)->NbElements();
+ }
+
+ aResult->length( nbElems );
+ if ( nbElems )
+ {
+ TListOfSubMeshes::iterator sm = smList.begin();
+ for ( int i = 0; sm != smList.end(); sm++ )
+ {
+ SMDS_ElemIteratorPtr anIt = (*sm)->GetElements();
+ for ( ; i < nbElems && 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);
+
+ SMESH::long_array_var aResult = new SMESH::long_array();
+
+ if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
+ return aResult._retn();
+
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ ::SMESH_subMesh* aSubMesh = _mesh_i->_mapSubMesh[_localId];
+ SMESHDS_SubMesh* aSubMeshDS = aSubMesh->GetSubMeshDS();
+
+ // PAL5440, return all nodes belonging to elements of submesh
+ set<int> nodeIds;
+ int nbElems = aSubMeshDS ? aSubMeshDS->NbElements() : 0;
+
+ // volumes may be bound to shell instead of solid
+ TListOfSubMeshes smList;
+ if ( nbElems == 0 && getSubMeshes( aSubMesh, smList ))
+ {
+ TListOfSubMeshes::iterator sm = smList.begin();
+ for ( ; sm != smList.end(); ++sm )
+ {
+ if ( theElemType == SMESH::NODE )
+ {
+ SMDS_ElemIteratorPtr eIt = (*sm)->GetElements();
+ if ( eIt->more() ) {
+ while ( eIt->more() ) {
+ const SMDS_MeshElement* anElem = eIt->next();
+ SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
+ while ( nIt->more() )
+ nodeIds.insert( nIt->next()->GetID() );
+ }
+ } else {
+ SMDS_NodeIteratorPtr nIt = (*sm)->GetNodes();
+ while ( nIt->more() )
+ nodeIds.insert( nIt->next()->GetID() );
+ }
+ }
+ else
+ {
+ nbElems += (*sm)->NbElements();
+ }
+ }
+ aSubMeshDS = 0;
+ }
+ else
+ {
+ if ( nbElems )
+ smList.push_back( aSubMeshDS );
+ }
+
+ if ( theElemType == SMESH::NODE && aSubMeshDS )
+ {
+ SMDS_ElemIteratorPtr eIt = aSubMeshDS->GetElements();
+ if ( eIt->more() ) {
+ while ( eIt->more() ) {
+ const SMDS_MeshElement* anElem = eIt->next();
+ SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
+ while ( nIt->more() )
+ nodeIds.insert( nIt->next()->GetID() );
+ }
+ } else {
+ SMDS_NodeIteratorPtr nIt = aSubMeshDS->GetNodes();
+ while ( nIt->more() )
+ nodeIds.insert( nIt->next()->GetID() );
+ }
+ }
+
+ if ( theElemType == SMESH::NODE )
+ aResult->length( nodeIds.size() );
+ else
+ aResult->length( nbElems );
+
+ int i = 0, n = aResult->length();
+
+ if ( theElemType == SMESH::NODE && !nodeIds.empty() ) {
+ set<int>::iterator idIt = nodeIds.begin();
+ for ( ; i < n && idIt != nodeIds.end() ; i++, idIt++ )
+ aResult[i] = *idIt;
+ }
+
+ if ( theElemType != SMESH::NODE ) {
+ TListOfSubMeshes::iterator sm = smList.begin();
+ for ( i = 0; sm != smList.end(); sm++ )
+ {
+ aSubMeshDS = *sm;
+ 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();