1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAPI_ShapeExplorer.cpp
4 // Created: 5 June 2015
5 // Author: Dmitry Bobylev
7 #include <GeomAPI_ShapeExplorer.h>
9 #include <Standard_NoMoreObject.hxx>
10 #include <TopExp_Explorer.hxx>
12 #define MY_EXPLORER implPtr<TopExp_Explorer>()
14 //=================================================================================================
15 GeomAPI_ShapeExplorer::GeomAPI_ShapeExplorer()
16 : GeomAPI_Interface(new TopExp_Explorer())
20 // returns a type of shape to expolode, but if toFind==SHAPE, it will return the type
21 // of the first sub-element of compoud if theSHape is compound
22 static TopAbs_ShapeEnum ShapeType(const std::shared_ptr<GeomAPI_Shape>& theShape,
23 const GeomAPI_Shape::ShapeType toFind)
25 if (toFind == GeomAPI_Shape::SHAPE) {
26 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
27 if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPOUND) {
28 TopoDS_Iterator anIter(aShape);
30 return anIter.Value().ShapeType();
34 return (TopAbs_ShapeEnum)toFind;
37 //=================================================================================================
38 GeomAPI_ShapeExplorer::GeomAPI_ShapeExplorer(const std::shared_ptr<GeomAPI_Shape>& theShape,
39 const GeomAPI_Shape::ShapeType toFind,
40 const GeomAPI_Shape::ShapeType toAvoid)
41 : GeomAPI_Interface(new TopExp_Explorer(theShape->impl<TopoDS_Shape>(),
42 ShapeType(theShape, toFind),
43 (TopAbs_ShapeEnum)toAvoid))
47 //=================================================================================================
48 void GeomAPI_ShapeExplorer::init(const std::shared_ptr<GeomAPI_Shape>& theShape,
49 const GeomAPI_Shape::ShapeType toFind,
50 const GeomAPI_Shape::ShapeType toAvoid)
52 MY_EXPLORER->Init(theShape->impl<TopoDS_Shape>(),
53 ShapeType(theShape, toFind),
54 (TopAbs_ShapeEnum)toAvoid);
57 //=================================================================================================
58 bool GeomAPI_ShapeExplorer::more() const
60 return MY_EXPLORER->More() == Standard_True;
63 //=================================================================================================
64 void GeomAPI_ShapeExplorer::next()
68 } catch (Standard_NoMoreObject) {
72 //=================================================================================================
73 std::shared_ptr<GeomAPI_Shape> GeomAPI_ShapeExplorer::current()
76 const TopoDS_Shape& aShape = MY_EXPLORER->Current();
77 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape());
78 aGeomShape->setImpl(new TopoDS_Shape(aShape));
80 } catch (Standard_NoMoreObject) {
81 return std::shared_ptr<GeomAPI_Shape>();
85 //=================================================================================================
86 void GeomAPI_ShapeExplorer::reinit()
88 MY_EXPLORER->ReInit();
91 //=================================================================================================
92 int GeomAPI_ShapeExplorer::depth() const
94 return MY_EXPLORER->Depth();
97 //=================================================================================================
98 void GeomAPI_ShapeExplorer::clear()
100 MY_EXPLORER->Clear();