+namespace {
+
+ //=======================================================================
+ /*!
+ * \brief Iterator on ancestors of the given type
+ */
+ //=======================================================================
+
+ struct TAncestorsIterator : public SMDS_Iterator<const TopoDS_Shape*>
+ {
+ TopTools_ListIteratorOfListOfShape _ancIter;
+ TopAbs_ShapeEnum _type;
+ TopTools_MapOfShape _encountered;
+ TAncestorsIterator( const TopTools_ListOfShape& ancestors, TopAbs_ShapeEnum type)
+ : _ancIter( ancestors ), _type( type )
+ {
+ if ( _ancIter.More() ) {
+ if ( _ancIter.Value().ShapeType() != _type ) next();
+ else _encountered.Add( _ancIter.Value() );
+ }
+ }
+ virtual bool more()
+ {
+ return _ancIter.More();
+ }
+ virtual const TopoDS_Shape* next()
+ {
+ const TopoDS_Shape* s = _ancIter.More() ? & _ancIter.Value() : 0;
+ if ( _ancIter.More() )
+ for ( _ancIter.Next(); _ancIter.More(); _ancIter.Next())
+ if ( _ancIter.Value().ShapeType() == _type && _encountered.Add( _ancIter.Value() ))
+ break;
+ return s;
+ }
+ };
+
+} // namespace
+
+//=======================================================================
+/*!
+ * \brief Return iterator on ancestors of the given type
+ */
+//=======================================================================
+
+PShapeIteratorPtr SMESH_MesherHelper::GetAncestors(const TopoDS_Shape& shape,
+ const SMESH_Mesh& mesh,
+ TopAbs_ShapeEnum ancestorType)
+{
+ return PShapeIteratorPtr( new TAncestorsIterator( mesh.GetAncestors(shape), ancestorType));
+}
+