Modify GetTypes() to return an empty array if there are no elements

This commit is contained in:
eap 2011-06-22 12:47:01 +00:00
parent 4d58862b1b
commit 5df2a8d168
3 changed files with 29 additions and 19 deletions

View File

@ -572,8 +572,12 @@ SMESH::long_array* SMESH_GroupBase_i::GetIDs()
SMESH::array_of_ElementType* SMESH_GroupBase_i::GetTypes() SMESH::array_of_ElementType* SMESH_GroupBase_i::GetTypes()
{ {
SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType; SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
types->length( 1 ); if ( SMESHDS_GroupBase* ds = GetGroupDS() )
types[0] = GetType(); if ( !ds->IsEmpty() )
{
types->length( 1 );
types[0] = GetType();
}
return types._retn(); return types._retn();
} }

View File

@ -428,8 +428,10 @@ struct _IDSource : public POA_SMESH::SMESH_IDSource
SMESH::array_of_ElementType* GetTypes() SMESH::array_of_ElementType* GetTypes()
{ {
SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType; SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
types->length( 1 ); if ( _ids.length() > 0 ) {
types[0] = _type; types->length( 1 );
types[0] = _type;
}
return types._retn(); return types._retn();
} }
}; };

View File

@ -557,23 +557,27 @@ SMESH::array_of_ElementType* SMESH_subMesh_i::GetTypes()
SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType; SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
::SMESH_subMesh* aSubMesh = _mesh_i->_mapSubMesh[_localId]; ::SMESH_subMesh* aSubMesh = _mesh_i->_mapSubMesh[_localId];
TopoDS_Shape shape = aSubMesh->GetSubShape(); if ( SMESHDS_SubMesh* smDS = aSubMesh->GetSubMeshDS() )
while ( !shape.IsNull() && shape.ShapeType() == TopAbs_COMPOUND )
{ {
TopoDS_Iterator it( shape ); SMDS_ElemIteratorPtr eIt = smDS->GetElements();
shape = it.More() ? it.Value() : TopoDS_Shape(); if ( eIt->more() )
}
if ( !shape.IsNull() )
{
types->length( 1 );
switch ( ::SMESH_Gen::GetShapeDim( shape ))
{ {
case 0: types[0] = SMESH::ELEM0D; break; types->length( 1 );
case 1: types[0] = SMESH::EDGE; break; types[0] = SMESH::ElementType( eIt->next()->GetType());
case 2: types[0] = SMESH::FACE; break; }
case 3: types[0] = SMESH::VOLUME; break; else if ( smDS->GetNodes()->more() )
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(); return types._retn();