+
+/*!
+ * template class used for iteration on submesh elements. Interface of iterator remains
+ * unchanged after redesign of SMDS to avoid modification everywhere in SMESH.
+ * instances are stored in shared_ptr for automatic destruction.
+ * Container is copied for iteration, because original can be modified
+ * by addition of elements, for instance, and then reallocated (vector)
+ */
+template <class ELEM, typename TSET> class MySetIterator : public SMDS_Iterator<ELEM>
+{
+protected:
+ typename TSET::const_iterator _it, _end;
+ TSET _table;
+// int _ind;
+public:
+ MySetIterator(const TSET& table)
+// : _it(table.begin()), _end(table.end())
+ {
+// MESSAGE("table.size()="<< table.size());
+ _table = table;
+ _it = _table.begin();
+ _end = _table.end();
+// for (int i=0; i< _table.size(); i++)
+// if (_table[i]) { MESSAGE("_table["<< i << "]="<< _table[i]);}
+// else
+// { MESSAGE("_table["<< i << "]=NULL"); }
+// _ind = 0;
+ }
+
+ virtual bool more()
+ {
+ while((_it != _end) && (*_it == 0))
+ {
+ _it++;
+// _ind++;
+ }
+// MESSAGE("more _ind=" << _ind);
+ return (_it != _end);
+ }
+
+ virtual ELEM next()
+ {
+ ELEM e=*_it;
+// if (e) { MESSAGE("next _ind=" << _ind << " *_it=" << *_it);}
+// else { MESSAGE("next _ind=" << _ind << " *_it=NULL");}
+// _ind++;
+ _it++;
+ return e;
+ }
+};
+
+// =====================
+// class MyIterator
+// =====================
+
+template<typename VALUE> class MyIterator : public SMDS_Iterator<VALUE>
+{
+ public:
+ MyIterator (const set<const SMESHDS_SubMesh*>& theSubMeshes)
+ : mySubIt( theSubMeshes.begin() ), mySubEnd( theSubMeshes.end() ), myMore(false)
+ {}
+ bool more()
+ {
+ while (( !myElemIt.get() || !myElemIt->more() ) && mySubIt != mySubEnd)
+ {
+ myElemIt = getElements(*mySubIt);
+ mySubIt++;
+ }
+ myMore = myElemIt.get() && myElemIt->more();
+ return myMore;
+ }
+ VALUE next()
+ {
+ VALUE elem = 0;
+ if ( myMore )
+ elem = myElemIt->next();
+ return elem;
+ }
+ protected:
+ virtual boost::shared_ptr< SMDS_Iterator<VALUE> >
+ getElements(const SMESHDS_SubMesh*) const = 0;
+
+ private:
+ bool myMore;
+ set<const SMESHDS_SubMesh*>::const_iterator mySubIt, mySubEnd;
+ boost::shared_ptr< SMDS_Iterator<VALUE> > myElemIt;
+};
+
+// =====================
+// class MyElemIterator
+// =====================
+
+class MyElemIterator: public MyIterator<const SMDS_MeshElement*>
+{
+ public:
+ MyElemIterator (const set<const SMESHDS_SubMesh*>& theSubMeshes)
+ :MyIterator<const SMDS_MeshElement*>( theSubMeshes ) {}
+ SMDS_ElemIteratorPtr getElements(const SMESHDS_SubMesh* theSubMesh) const
+ { return theSubMesh->GetElements(); }
+};
+
+// =====================
+// class MyNodeIterator
+// =====================
+
+class MyNodeIterator: public MyIterator<const SMDS_MeshNode*>
+{
+ public:
+ MyNodeIterator (const set<const SMESHDS_SubMesh*>& theSubMeshes)
+ :MyIterator<const SMDS_MeshNode*>( theSubMeshes ) {}
+ SMDS_NodeIteratorPtr getElements(const SMESHDS_SubMesh* theSubMesh) const
+ { return theSubMesh->GetNodes(); }
+};
+