X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_subMesh_i.cxx;h=50d689eb3e131c42f4d20d83d1d59d96ed2bd65e;hb=0cf919dde01c300a8f74d697198fba6538560c22;hp=8c6563ffd1cddda956e8058c88dc48584661d150;hpb=c3bf92bd87b770fd81631a3853f7f5bb1ac6a4e8;p=modules%2Fsmesh.git diff --git a/src/SMESH_I/SMESH_subMesh_i.cxx b/src/SMESH_I/SMESH_subMesh_i.cxx index 8c6563ffd..50d689eb3 100644 --- a/src/SMESH_I/SMESH_subMesh_i.cxx +++ b/src/SMESH_I/SMESH_subMesh_i.cxx @@ -26,7 +26,6 @@ // Module : SMESH // $Header$ -using namespace std; using namespace std; #include "SMESH_subMesh_i.hxx" #include "SMESH_Gen_i.hxx" @@ -95,11 +94,24 @@ CORBA::Long SMESH_subMesh_i::GetNumberOfElements() if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() ) return 0; - SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS(); - if ( aSubMeshDS == NULL ) - return 0; - - return aSubMeshDS->NbElements(); + ::SMESH_subMesh* aSubMesh = _mesh_i->_mapSubMesh[_localId]; + SMESHDS_SubMesh* aSubMeshDS = aSubMesh->GetSubMeshDS(); + + int nbElems = aSubMeshDS ? aSubMeshDS->NbElements() : 0; + + // volumes are bound to shell + if ( nbElems == 0 && aSubMesh->GetSubShape().ShapeType() <= TopAbs_SOLID ) + { + SMESHDS_Mesh* aMeshDS = aSubMesh->GetFather()->GetMeshDS(); + TopExp_Explorer exp( aSubMesh->GetSubShape(), TopAbs_SHELL ); + for ( ; exp.More(); exp.Next() ) + { + aSubMeshDS = aMeshDS->MeshElements( exp.Current() ); + if ( aSubMeshDS ) + nbElems += aSubMeshDS->NbElements(); + } + } + return nbElems; } //============================================================================= @@ -108,7 +120,7 @@ CORBA::Long SMESH_subMesh_i::GetNumberOfElements() */ //============================================================================= -CORBA::Long SMESH_subMesh_i::GetNumberOfNodes() +CORBA::Long SMESH_subMesh_i::GetNumberOfNodes(CORBA::Boolean all) throw (SALOME::SALOME_Exception) { Unexpect aCatch(SALOME_SalomeException); @@ -116,10 +128,46 @@ CORBA::Long SMESH_subMesh_i::GetNumberOfNodes() if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() ) return 0; - SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS(); + ::SMESH_subMesh* aSubMesh = _mesh_i->_mapSubMesh[_localId]; + SMESHDS_SubMesh* aSubMeshDS = aSubMesh->GetSubMeshDS(); + + set nodeIds; + + // node are bound to shell instead of solid + if ( all && aSubMesh->GetSubShape().ShapeType() <= TopAbs_SOLID ) + { + SMESHDS_Mesh* aMeshDS = aSubMesh->GetFather()->GetMeshDS(); + TopExp_Explorer exp( aSubMesh->GetSubShape(), TopAbs_SHELL ); + for ( ; exp.More(); exp.Next() ) + { + aSubMeshDS = aMeshDS->MeshElements( exp.Current() ); + if ( aSubMeshDS ) { + 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() ); + } + } + } + return nodeIds.size(); + } + if ( aSubMeshDS == NULL ) return 0; + if ( all ) { // all nodes of submesh elements + 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() ); + } + return nodeIds.size(); + } + return aSubMeshDS->NbNodes(); } @@ -139,15 +187,41 @@ SMESH::long_array* SMESH_subMesh_i::GetElementsId() 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(); + ::SMESH_subMesh* aSubMesh = _mesh_i->_mapSubMesh[_localId]; + SMESHDS_SubMesh* aSubMeshDS = aSubMesh->GetSubMeshDS(); + + int nbElems = aSubMeshDS ? aSubMeshDS->NbElements() : 0; + list smList; + if ( nbElems ) + smList.push_back( aSubMeshDS ); + + // volumes are bound to shell + if ( nbElems == 0 && aSubMesh->GetSubShape().ShapeType() <= TopAbs_SOLID ) + { + SMESHDS_Mesh* aMeshDS = aSubMesh->GetFather()->GetMeshDS(); + TopExp_Explorer exp( aSubMesh->GetSubShape(), TopAbs_SHELL ); + for ( ; exp.More(); exp.Next() ) + { + aSubMeshDS = aMeshDS->MeshElements( exp.Current() ); + if ( aSubMeshDS ) { + smList.push_back( aSubMeshDS ); + nbElems += aSubMeshDS->NbElements(); + } + } + } + if ( nbElems ) + { + aResult->length( nbElems ); + list::iterator sm = smList.begin(); + for ( int i = 0; sm != smList.end(); sm++ ) + { + aSubMeshDS = *sm; + SMDS_ElemIteratorPtr anIt = aSubMeshDS->GetElements(); + for ( int n = aSubMeshDS->NbElements(); i < n && anIt->more(); i++ ) + aResult[i] = anIt->next()->GetID(); + } + } return aResult._retn(); } @@ -168,32 +242,82 @@ SMESH::long_array* SMESH_subMesh_i::GetElementsByType( SMESH::ElementType theEle 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(); + ::SMESH_subMesh* aSubMesh = _mesh_i->_mapSubMesh[_localId]; + SMESHDS_SubMesh* aSubMeshDS = aSubMesh->GetSubMeshDS(); + + // PAL5440, return all nodes belonging to elements of submesh + set nodeIds; + int nbElems = aSubMeshDS ? aSubMeshDS->NbElements() : 0; + + // volumes may be bound to shell instead of solid + list< SMESHDS_SubMesh* > smList; + if ( nbElems == 0 && aSubMesh->GetSubShape().ShapeType() <= TopAbs_SOLID ) + { + SMESHDS_Mesh* aMeshDS = aSubMesh->GetFather()->GetMeshDS(); + TopExp_Explorer exp( aSubMesh->GetSubShape(), TopAbs_SHELL ); + for ( ; exp.More(); exp.Next() ) + { + aSubMeshDS = aMeshDS->MeshElements( exp.Current() ); + if ( !aSubMeshDS ) continue; + if ( theElemType == SMESH::NODE ) + { + 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() ); + } + } + else + { + smList.push_back( aSubMeshDS ); + nbElems += aSubMeshDS->NbElements(); + } + } + aSubMeshDS = 0; + } + else + { + if ( nbElems ) + smList.push_back( aSubMeshDS ); + } + + if ( theElemType == SMESH::NODE && aSubMeshDS ) + { + 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() ); + } + } - int i = 0; - if ( theElemType == SMESH::ALL ) - aResult->length( aSubMeshDS->NbElements() + aSubMeshDS->NbNodes() ); - else if ( theElemType == SMESH::NODE ) - aResult->length( aSubMeshDS->NbNodes() ); + if ( theElemType == SMESH::NODE ) + aResult->length( nodeIds.size() ); else - aResult->length( aSubMeshDS->NbElements() ); + aResult->length( nbElems ); - int n = aResult->length(); + int i = 0, n = aResult->length(); - if ( theElemType == SMESH::ALL || theElemType == SMESH::NODE ) { - SMDS_NodeIteratorPtr anIt = aSubMeshDS->GetNodes(); - while ( i < n && anIt->more() ) - aResult[i++] = anIt->next()->GetID(); + if ( theElemType == SMESH::NODE && !nodeIds.empty() ) { + set::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(); + if ( theElemType != SMESH::NODE ) { + list::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(); + } } } @@ -213,20 +337,7 @@ SMESH::long_array* SMESH_subMesh_i::GetNodesId() { Unexpect aCatch(SALOME_SalomeException); MESSAGE("SMESH_subMesh_i::GetNodesId"); - 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->NbNodes() ); - SMDS_NodeIteratorPtr anIt = aSubMeshDS->GetNodes(); - for ( int i = 0, n = aSubMeshDS->NbNodes(); i < n && anIt->more(); i++ ) - aResult[i] = anIt->next()->GetID(); - + SMESH::long_array_var aResult = GetElementsByType( SMESH::NODE ); return aResult._retn(); } @@ -256,6 +367,29 @@ CORBA::Long SMESH_subMesh_i::GetId() return _localId; } +//======================================================================= +//function : GetSubShape +//purpose : +//======================================================================= + +GEOM::GEOM_Object_ptr SMESH_subMesh_i::GetSubShape() + throw (SALOME::SALOME_Exception) +{ + Unexpect aCatch(SALOME_SalomeException); + GEOM::GEOM_Object_var aShapeObj; + try { + if ( _mesh_i->_mapSubMesh.find( _localId ) != _mesh_i->_mapSubMesh.end()) { + TopoDS_Shape S = _mesh_i->_mapSubMesh[ _localId ]->GetSubShape(); + if ( !S.IsNull() ) + aShapeObj = _gen_i->ShapeToGeomObject( S ); + } + } + catch(SALOME_Exception & S_ex) { + THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM); + } + return aShapeObj._retn(); +} + //============================================================================= /*! * @@ -274,4 +408,17 @@ SALOME_MED::FAMILY_ptr SMESH_subMesh_i::GetFamily() if ( families[i]->getIdentifier() == ( _localId ) ) return families[i]; } + + return SALOME_MED::FAMILY::_nil(); +} + +//============================================================================= +/*! + * + */ +//============================================================================= +SMESH::long_array* SMESH_subMesh_i::GetIDs() +{ + SMESH::long_array_var aResult = GetElementsId(); + return aResult._retn(); }