From 5df2a8d16815659a94f7f11d4c41e851a9686c87 Mon Sep 17 00:00:00 2001 From: eap Date: Wed, 22 Jun 2011 12:47:01 +0000 Subject: [PATCH] Modify GetTypes() to return an empty array if there are no elements --- src/SMESH_I/SMESH_Group_i.cxx | 8 +++++-- src/SMESH_I/SMESH_MeshEditor_i.cxx | 6 ++++-- src/SMESH_I/SMESH_subMesh_i.cxx | 34 +++++++++++++++++------------- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/SMESH_I/SMESH_Group_i.cxx b/src/SMESH_I/SMESH_Group_i.cxx index 6312b7389..6d359d840 100644 --- a/src/SMESH_I/SMESH_Group_i.cxx +++ b/src/SMESH_I/SMESH_Group_i.cxx @@ -572,8 +572,12 @@ SMESH::long_array* SMESH_GroupBase_i::GetIDs() 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(); + if ( SMESHDS_GroupBase* ds = GetGroupDS() ) + if ( !ds->IsEmpty() ) + { + types->length( 1 ); + types[0] = GetType(); + } return types._retn(); } diff --git a/src/SMESH_I/SMESH_MeshEditor_i.cxx b/src/SMESH_I/SMESH_MeshEditor_i.cxx index 27a63c744..897dd78a4 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.cxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.cxx @@ -428,8 +428,10 @@ struct _IDSource : public POA_SMESH::SMESH_IDSource SMESH::array_of_ElementType* GetTypes() { SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType; - types->length( 1 ); - types[0] = _type; + if ( _ids.length() > 0 ) { + types->length( 1 ); + types[0] = _type; + } return types._retn(); } }; diff --git a/src/SMESH_I/SMESH_subMesh_i.cxx b/src/SMESH_I/SMESH_subMesh_i.cxx index 9ccc8bc8c..475254f7c 100644 --- a/src/SMESH_I/SMESH_subMesh_i.cxx +++ b/src/SMESH_I/SMESH_subMesh_i.cxx @@ -557,23 +557,27 @@ SMESH::array_of_ElementType* SMESH_subMesh_i::GetTypes() SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType; ::SMESH_subMesh* aSubMesh = _mesh_i->_mapSubMesh[_localId]; - TopoDS_Shape shape = aSubMesh->GetSubShape(); - while ( !shape.IsNull() && shape.ShapeType() == TopAbs_COMPOUND ) + if ( SMESHDS_SubMesh* smDS = aSubMesh->GetSubMeshDS() ) { - TopoDS_Iterator it( shape ); - shape = it.More() ? it.Value() : TopoDS_Shape(); - } - if ( !shape.IsNull() ) - { - types->length( 1 ); - switch ( ::SMESH_Gen::GetShapeDim( shape )) + SMDS_ElemIteratorPtr eIt = smDS->GetElements(); + if ( eIt->more() ) + { + types->length( 1 ); + types[0] = SMESH::ElementType( eIt->next()->GetType()); + } + else if ( smDS->GetNodes()->more() ) { - case 0: types[0] = SMESH::ELEM0D; break; - case 1: types[0] = SMESH::EDGE; break; - case 2: types[0] = SMESH::FACE; break; - case 3: types[0] = SMESH::VOLUME; break; - default: - types->length(0); + TopoDS_Shape shape = aSubMesh->GetSubShape(); + while ( !shape.IsNull() && shape.ShapeType() == TopAbs_COMPOUND ) + { + TopoDS_Iterator it( shape ); + shape = it.More() ? it.Value() : TopoDS_Shape(); + } + if ( !shape.IsNull() && shape.ShapeType() == TopAbs_VERTEX ) + { + types->length( 1 ); + types[0] = SMESH::NODE; + } } } return types._retn(); -- 2.39.2