1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include <GeomAPI_ShapeExplorer.h>
22 #include <Standard_NoMoreObject.hxx>
23 #include <TopExp_Explorer.hxx>
25 #define MY_EXPLORER implPtr<TopExp_Explorer>()
27 //=================================================================================================
28 GeomAPI_ShapeExplorer::GeomAPI_ShapeExplorer()
29 : GeomAPI_Interface(new TopExp_Explorer())
33 // returns a type of shape to expolode, but if toFind==SHAPE, it will return the type
34 // of the first sub-element of compoud if theSHape is compound
35 static TopAbs_ShapeEnum ShapeType(const std::shared_ptr<GeomAPI_Shape>& theShape,
36 const GeomAPI_Shape::ShapeType toFind)
38 if (toFind == GeomAPI_Shape::SHAPE) {
39 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
40 if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPOUND) {
41 TopoDS_Iterator anIter(aShape);
43 return anIter.Value().ShapeType();
47 return (TopAbs_ShapeEnum)toFind;
50 //=================================================================================================
51 GeomAPI_ShapeExplorer::GeomAPI_ShapeExplorer(const std::shared_ptr<GeomAPI_Shape>& theShape,
52 const GeomAPI_Shape::ShapeType toFind,
53 const GeomAPI_Shape::ShapeType toAvoid)
54 : GeomAPI_Interface(new TopExp_Explorer(theShape->impl<TopoDS_Shape>(),
55 ShapeType(theShape, toFind),
56 (TopAbs_ShapeEnum)toAvoid))
60 //=================================================================================================
61 void GeomAPI_ShapeExplorer::init(const std::shared_ptr<GeomAPI_Shape>& theShape,
62 const GeomAPI_Shape::ShapeType toFind,
63 const GeomAPI_Shape::ShapeType toAvoid)
65 MY_EXPLORER->Init(theShape->impl<TopoDS_Shape>(),
66 ShapeType(theShape, toFind),
67 (TopAbs_ShapeEnum)toAvoid);
70 //=================================================================================================
71 bool GeomAPI_ShapeExplorer::more() const
73 return MY_EXPLORER->More() == Standard_True;
76 //=================================================================================================
77 void GeomAPI_ShapeExplorer::next()
81 } catch (Standard_NoMoreObject) {
85 //=================================================================================================
86 std::shared_ptr<GeomAPI_Shape> GeomAPI_ShapeExplorer::current()
89 const TopoDS_Shape& aShape = MY_EXPLORER->Current();
90 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape());
91 aGeomShape->setImpl(new TopoDS_Shape(aShape));
93 } catch (Standard_NoMoreObject) {
94 return std::shared_ptr<GeomAPI_Shape>();
98 //=================================================================================================
99 void GeomAPI_ShapeExplorer::reinit()
101 MY_EXPLORER->ReInit();
104 //=================================================================================================
105 int GeomAPI_ShapeExplorer::depth() const
107 return MY_EXPLORER->Depth();
110 //=================================================================================================
111 void GeomAPI_ShapeExplorer::clear()
113 MY_EXPLORER->Clear();