1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include <GeomAPI_ShapeExplorer.h>
23 #include <Standard_NoMoreObject.hxx>
24 #include <TopExp_Explorer.hxx>
26 #define MY_EXPLORER implPtr<TopExp_Explorer>()
28 //=================================================================================================
29 GeomAPI_ShapeExplorer::GeomAPI_ShapeExplorer()
30 : GeomAPI_Interface(new TopExp_Explorer())
34 // returns a type of shape to expolode, but if toFind==SHAPE, it will return the type
35 // of the first sub-element of compoud if theSHape is compound
36 static TopAbs_ShapeEnum ShapeType(const std::shared_ptr<GeomAPI_Shape>& theShape,
37 const GeomAPI_Shape::ShapeType toFind)
39 if (toFind == GeomAPI_Shape::SHAPE) {
40 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
41 if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPOUND) {
42 TopoDS_Iterator anIter(aShape);
44 return anIter.Value().ShapeType();
48 return (TopAbs_ShapeEnum)toFind;
51 //=================================================================================================
52 GeomAPI_ShapeExplorer::GeomAPI_ShapeExplorer(const std::shared_ptr<GeomAPI_Shape>& theShape,
53 const GeomAPI_Shape::ShapeType toFind,
54 const GeomAPI_Shape::ShapeType toAvoid)
55 : GeomAPI_Interface(new TopExp_Explorer(theShape->impl<TopoDS_Shape>(),
56 ShapeType(theShape, toFind),
57 (TopAbs_ShapeEnum)toAvoid))
61 //=================================================================================================
62 void GeomAPI_ShapeExplorer::init(const std::shared_ptr<GeomAPI_Shape>& theShape,
63 const GeomAPI_Shape::ShapeType toFind,
64 const GeomAPI_Shape::ShapeType toAvoid)
66 MY_EXPLORER->Init(theShape->impl<TopoDS_Shape>(),
67 ShapeType(theShape, toFind),
68 (TopAbs_ShapeEnum)toAvoid);
71 //=================================================================================================
72 bool GeomAPI_ShapeExplorer::more() const
74 return MY_EXPLORER->More() == Standard_True;
77 //=================================================================================================
78 void GeomAPI_ShapeExplorer::next()
82 } catch (Standard_NoMoreObject) {
86 //=================================================================================================
87 std::shared_ptr<GeomAPI_Shape> GeomAPI_ShapeExplorer::current()
90 const TopoDS_Shape& aShape = MY_EXPLORER->Current();
91 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape());
92 aGeomShape->setImpl(new TopoDS_Shape(aShape));
94 } catch (Standard_NoMoreObject) {
95 return std::shared_ptr<GeomAPI_Shape>();
99 //=================================================================================================
100 void GeomAPI_ShapeExplorer::reinit()
102 MY_EXPLORER->ReInit();
105 //=================================================================================================
106 int GeomAPI_ShapeExplorer::depth() const
108 return MY_EXPLORER->Depth();
111 //=================================================================================================
112 void GeomAPI_ShapeExplorer::clear()
114 MY_EXPLORER->Clear();