+//=============================================================================
+/*!
+ * KindOfBRep
+ * \return 0 if theShape contains only simple entities (wires, edges and vertices),
+ * 1 if theShape contains only complex entities (shells, solids and compsolids)
+ * 2 if theShape contains only indifferent entities (faces)
+ * -1 if theShape contains both simple and complex entities (and in this case it
+ * cannot be saved without any loss neither in BRepMode == 0 nor in BRepMode == 1)
+ */
+//=============================================================================
+int KindOfBRep (const TopoDS_Shape& theShape)
+{
+ int aKind = 2;
+
+ switch (theShape.ShapeType())
+ {
+ case TopAbs_COMPOUND:
+ {
+ bool isSimple = false;
+ bool isComplex = false;
+ TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
+ for (; anIt.More(); anIt.Next()) {
+ TopoDS_Shape aS = anIt.Value();
+ int aKindSub = KindOfBRep(aS);
+ if (aKindSub == 0)
+ isSimple = true;
+ else if (aKindSub == 1)
+ isComplex = true;
+ else if (aKindSub == -1) {
+ return -1; // heterogeneous
+ }
+ }
+ if (isSimple && isComplex)
+ aKind = -1; // heterogeneous
+ else if (isSimple)
+ aKind = 0;
+ else if (isComplex)
+ aKind = 1;
+ }
+ break;
+ case TopAbs_COMPSOLID:
+ case TopAbs_SOLID:
+ case TopAbs_SHELL:
+ aKind = 1;
+ break;
+ case TopAbs_WIRE:
+ case TopAbs_EDGE:
+ case TopAbs_VERTEX:
+ aKind = 0;
+ break;
+ default:
+ aKind = 2;
+ }
+
+ return aKind;
+}
+