+namespace /* Iterators used in SMESH_Mesh_i::GetElements(SMESH::SMESH_IDSource_var obj,
+ * SMESH::ElementType type) */
+{
+ using namespace SMESH::Controls;
+ //-----------------------------------------------------------------------------
+ struct PredicateIterator : public SMDS_ElemIterator
+ {
+ SMDS_ElemIteratorPtr _elemIter;
+ PredicatePtr _predicate;
+ const SMDS_MeshElement* _elem;
+
+ PredicateIterator( SMDS_ElemIteratorPtr iterator,
+ PredicatePtr predicate):
+ _elemIter(iterator), _predicate(predicate)
+ {
+ next();
+ }
+ virtual bool more()
+ {
+ return _elem;
+ }
+ virtual const SMDS_MeshElement* next()
+ {
+ const SMDS_MeshElement* res = _elem;
+ _elem = 0;
+ while ( _elemIter->more() && !_elem )
+ {
+ _elem = _elemIter->next();
+ if ( _elem && ( !_predicate->IsSatisfy( _elem->GetID() )))
+ _elem = 0;
+ }
+ return res;
+ }
+ };
+
+ //-----------------------------------------------------------------------------
+ struct IDSourceIterator : public SMDS_ElemIterator
+ {
+ const CORBA::Long* _idPtr;
+ const CORBA::Long* _idEndPtr;
+ SMESH::long_array_var _idArray;
+ const SMDS_Mesh* _mesh;
+ const SMDSAbs_ElementType _type;
+ const SMDS_MeshElement* _elem;
+
+ IDSourceIterator( const SMDS_Mesh* mesh,
+ const CORBA::Long* ids,
+ const int nbIds,
+ SMDSAbs_ElementType type):
+ _idPtr( ids ), _idEndPtr( ids + nbIds ), _mesh( mesh ), _type( type ), _elem( 0 )
+ {
+ if ( _idPtr && nbIds && _mesh )
+ next();
+ }
+ IDSourceIterator( const SMDS_Mesh* mesh,
+ SMESH::long_array* idArray,
+ SMDSAbs_ElementType type):
+ _idPtr( 0 ), _idEndPtr( 0 ), _idArray( idArray), _mesh( mesh ), _type( type ), _elem( 0 )
+ {
+ if ( idArray && _mesh )
+ {
+ _idPtr = &_idArray[0];
+ _idEndPtr = _idPtr + _idArray->length();
+ next();
+ }
+ }
+ virtual bool more()
+ {
+ return _elem;
+ }
+ virtual const SMDS_MeshElement* next()
+ {
+ const SMDS_MeshElement* res = _elem;
+ _elem = 0;
+ while ( _idPtr < _idEndPtr && !_elem )
+ {
+ if ( _type == SMDSAbs_Node )
+ {
+ _elem = _mesh->FindNode( *_idPtr++ );
+ }
+ else if ((_elem = _mesh->FindElement( *_idPtr++ )) &&
+ _elem->GetType() != _type )
+ {
+ _elem = 0;
+ }
+ }
+ return res;
+ }
+ };
+ //-----------------------------------------------------------------------------
+
+ struct NodeOfElemIterator : public SMDS_ElemIterator
+ {
+ TColStd_MapOfInteger _checkedNodeIDs;
+ SMDS_ElemIteratorPtr _elemIter;
+ SMDS_ElemIteratorPtr _nodeIter;
+ const SMDS_MeshElement* _node;
+
+ NodeOfElemIterator( SMDS_ElemIteratorPtr iter ): _elemIter( iter ), _node( 0 )
+ {
+ if ( _elemIter && _elemIter->more() )
+ {
+ _nodeIter = _elemIter->next()->nodesIterator();
+ next();
+ }
+ }
+ virtual bool more()
+ {
+ return _node;
+ }
+ virtual const SMDS_MeshElement* next()
+ {
+ const SMDS_MeshElement* res = _node;
+ _node = 0;
+ while (( _elemIter->more() || _nodeIter->more() ) && !_node )
+ {
+ if ( _nodeIter->more() )
+ {
+ _node = _nodeIter->next();
+ if ( !_checkedNodeIDs.Add( _node->GetID() ))
+ _node = 0;
+ }
+ else
+ {
+ _nodeIter = _elemIter->next()->nodesIterator();
+ }
+ }
+ return res;
+ }
+ };
+}
+
+//=============================================================================
+/*
+ * Return iterator on elements of given type in given object