Salome HOME
Merge branch 'Dev_2.1.0' of salome:modules/shaper into Dev_2.1.0
[modules/shaper.git] / src / GeomAPI / GeomAPI_ShapeExplorer.cpp
index 3732d5afe2cbf8bbe34dd0b6c61721a5cde72b6c..bf6ca1727251314d944796c4da0a6b2bdf31c9b3 100644 (file)
@@ -9,7 +9,7 @@
 #include <Standard_NoMoreObject.hxx>
 #include <TopExp_Explorer.hxx>
 
-#define MY_EXPLORER static_cast<TopExp_Explorer*>(myImpl)
+#define MY_EXPLORER implPtr<TopExp_Explorer>()
 
 //=================================================================================================
 GeomAPI_ShapeExplorer::GeomAPI_ShapeExplorer()
@@ -17,12 +17,29 @@ GeomAPI_ShapeExplorer::GeomAPI_ShapeExplorer()
 {
 }
 
+// returns a type of shape to expolode, but if toFind==SHAPE, it will return the type
+// of the first sub-element of compoud if theSHape is compound
+static TopAbs_ShapeEnum ShapeType(const std::shared_ptr<GeomAPI_Shape>& theShape,
+                                  const GeomAPI_Shape::ShapeType toFind)
+{
+  if (toFind == GeomAPI_Shape::SHAPE) {
+    TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+    if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPOUND) {
+      TopoDS_Iterator anIter(aShape);
+      if (anIter.More()) {
+        return anIter.Value().ShapeType();
+      }
+    }
+  }
+  return (TopAbs_ShapeEnum)toFind;
+}
+
 //=================================================================================================
 GeomAPI_ShapeExplorer::GeomAPI_ShapeExplorer(const std::shared_ptr<GeomAPI_Shape>& theShape,
                                              const GeomAPI_Shape::ShapeType toFind,
                                              const GeomAPI_Shape::ShapeType toAvoid)
 : GeomAPI_Interface(new TopExp_Explorer(theShape->impl<TopoDS_Shape>(),
-                                       (TopAbs_ShapeEnum)toFind,
+                                       ShapeType(theShape, toFind),
                                        (TopAbs_ShapeEnum)toAvoid))
 {
 }
@@ -33,7 +50,7 @@ void GeomAPI_ShapeExplorer::init(const std::shared_ptr<GeomAPI_Shape>& theShape,
                                  const GeomAPI_Shape::ShapeType toAvoid)
 {
   MY_EXPLORER->Init(theShape->impl<TopoDS_Shape>(),
-                   (TopAbs_ShapeEnum)toFind,
+                   ShapeType(theShape, toFind),
                    (TopAbs_ShapeEnum)toAvoid);
 }