bool ret = false;
SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
(SUIT_Session::session()->activeApplication()->activeStudy());
- if ( appStudy && !CORBA::is_nil( obj ) && obj->GetShapeType() == GEOM::COMPOUND ) {
- GEOM::GEOM_IMeasureOperations_var anOper = GeometryGUI::GetGeomGen()->GetIMeasureOperations( appStudy->id() );
- QString whatIs = anOper->WhatIs( obj );
- QStringList data = whatIs.split( "\n", QString::SkipEmptyParts );
- int nbVertices = 0, nbCompounds = 0, nbOther = 0;
- foreach ( QString s, data ) {
- QString type = s.section( ":", 0, 0 ).trimmed().toLower();
- int cnt = s.section( ":", 1, 1 ).trimmed().toInt();
- if ( type == "vertex" ) nbVertices += cnt;
- else if ( type == "compound" ) nbCompounds += cnt;
- else if ( type != "shape" ) nbOther += cnt;
- }
- ret = nbVertices > 0 && nbCompounds == 1 && nbOther == 0;
- anOper->Destroy();
- }
+ if ( appStudy && !CORBA::is_nil( obj ) )
+ ret = obj->GetShapeType() == GEOM::COMPOUND && obj->GetMaxShapeType() == GEOM::VERTEX;
return ret;
}
}
}
-static bool isCompoundOfVertices( const TopoDS_Shape& theShape )
+static int getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
{
- bool ret = false;
- if ( !theShape.IsNull() ) {
- int iType, nbTypes [TopAbs_SHAPE];
- for (iType = 0; iType < TopAbs_SHAPE; ++iType)
- nbTypes[iType] = 0;
- nbTypes[theShape.ShapeType()]++;
-
- TopTools_MapOfShape aMapOfShape;
- aMapOfShape.Add(theShape);
- TopTools_ListOfShape aListOfShape;
- aListOfShape.Append(theShape);
-
- TopTools_ListIteratorOfListOfShape itL (aListOfShape);
- for (; itL.More(); itL.Next()) {
- TopoDS_Iterator it (itL.Value());
- for (; it.More(); it.Next()) {
- TopoDS_Shape s = it.Value();
- if (aMapOfShape.Add(s)) {
- aListOfShape.Append(s);
- nbTypes[s.ShapeType()]++;
- }
- }
+ if ( shape.IsNull() )
+ return TopAbs_SHAPE;
+
+ int ret = shape.ShapeType();
+
+ if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
+ TopoDS_Iterator it(shape, Standard_True, Standard_False);
+ for (; it.More(); it.Next()) {
+ TopoDS_Shape sub_shape = it.Value();
+ if ( sub_shape.IsNull() ) continue;
+ int stype = getMinMaxShapeType( sub_shape, ismin );
+ if ( stype == TopAbs_SHAPE ) continue;
+ if ( ismin && stype > ret )
+ ret = stype;
+ else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
+ ret = stype;
}
- ret = nbTypes[TopAbs_VERTEX] > 0 && nbTypes[TopAbs_COMPOUND] == 1;
}
+
return ret;
}
+static bool isCompoundOfVertices( const TopoDS_Shape& theShape )
+{
+ return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
+}
+
//================================================================
// Function : getFilter
// Purpose : Get filter corresponding to the type of object