class IdSortedIterator : public SMDS_Iterator<ELEM>
{
const SMDS_MeshElementIDFactory& myIDFact;
- int myID, myMaxID;
+ int myID, myMaxID, myNbFound, myTotalNb;
+ SMDSAbs_ElementType myType;
ELEM myElem;
public:
- IdSortedIterator(const SMDS_MeshElementIDFactory& fact)
- :myIDFact( fact ), myID(1), myMaxID( myIDFact.GetMaxID() ), myElem(0)
+ IdSortedIterator(const SMDS_MeshElementIDFactory& fact,
+ const SMDSAbs_ElementType type, // SMDSAbs_All NOT allowed!!!
+ const int totalNb)
+ :myIDFact( fact ),
+ myID(1), myMaxID( myIDFact.GetMaxID() ),myNbFound(0), myTotalNb( totalNb ),
+ myType( type ),
+ myElem(0)
{
next();
}
ELEM next()
{
ELEM current = myElem;
- for ( myElem = 0; myID <= myMaxID && !myElem; ++myID )
- myElem = (ELEM) myIDFact.MeshElement( myID );
+
+ for ( myElem = 0; !myElem && myNbFound < myTotalNb && myID <= myMaxID; ++myID )
+ if ((myElem = (ELEM) myIDFact.MeshElement( myID ))
+ && myElem->GetType() != myType )
+ myElem = 0;
+
+ myNbFound += bool(myElem);
+
return current;
}
};
< SetOfNodes, const SMDS_MeshNode*, SMDS_NodeIterator > TIterator;
typedef IdSortedIterator< const SMDS_MeshNode* > TSortedIterator;
return ( idInceasingOrder ?
- SMDS_NodeIteratorPtr( new TSortedIterator( *myNodeIDFactory )) :
+ SMDS_NodeIteratorPtr( new TSortedIterator( *myNodeIDFactory, SMDSAbs_Node, NbNodes())) :
SMDS_NodeIteratorPtr( new TIterator(myNodes)));
}
///Return an iterator on 0D elements of the current mesh.
///////////////////////////////////////////////////////////////////////////////
-SMDS_0DElementIteratorPtr SMDS_Mesh::elements0dIterator() const
+SMDS_0DElementIteratorPtr SMDS_Mesh::elements0dIterator(bool idInceasingOrder) const
{
typedef MYNCollection_Map_Iterator
< SetOf0DElements, const SMDS_Mesh0DElement*, SMDS_0DElementIterator > TIterator;
- return SMDS_0DElementIteratorPtr(new TIterator(my0DElements));
+ typedef IdSortedIterator< const SMDS_Mesh0DElement* > TSortedIterator;
+ return ( idInceasingOrder ?
+ SMDS_0DElementIteratorPtr( new TSortedIterator( *myElementIDFactory,
+ SMDSAbs_0DElement,
+ Nb0DElements() )) :
+ SMDS_0DElementIteratorPtr( new TIterator(my0DElements)));
}
///////////////////////////////////////////////////////////////////////////////
///Return an iterator on edges of the current mesh.
///////////////////////////////////////////////////////////////////////////////
-SMDS_EdgeIteratorPtr SMDS_Mesh::edgesIterator() const
+SMDS_EdgeIteratorPtr SMDS_Mesh::edgesIterator(bool idInceasingOrder) const
{
typedef MYNCollection_Map_Iterator
< SetOfEdges, const SMDS_MeshEdge*, SMDS_EdgeIterator > TIterator;
- return SMDS_EdgeIteratorPtr(new TIterator(myEdges));
+ typedef IdSortedIterator< const SMDS_MeshEdge* > TSortedIterator;
+ return ( idInceasingOrder ?
+ SMDS_EdgeIteratorPtr( new TSortedIterator( *myElementIDFactory,
+ SMDSAbs_Edge,
+ NbEdges() )) :
+ SMDS_EdgeIteratorPtr(new TIterator(myEdges)));
}
///////////////////////////////////////////////////////////////////////////////
///Return an iterator on faces of the current mesh.
///////////////////////////////////////////////////////////////////////////////
-SMDS_FaceIteratorPtr SMDS_Mesh::facesIterator() const
+SMDS_FaceIteratorPtr SMDS_Mesh::facesIterator(bool idInceasingOrder) const
{
typedef MYNCollection_Map_Iterator
< SetOfFaces, const SMDS_MeshFace*, SMDS_FaceIterator > TIterator;
- return SMDS_FaceIteratorPtr(new TIterator(myFaces));
+ typedef IdSortedIterator< const SMDS_MeshFace* > TSortedIterator;
+ return ( idInceasingOrder ?
+ SMDS_FaceIteratorPtr( new TSortedIterator( *myElementIDFactory,
+ SMDSAbs_Face,
+ NbFaces() )) :
+ SMDS_FaceIteratorPtr(new TIterator(myFaces)));
}
///////////////////////////////////////////////////////////////////////////////
///Return an iterator on volumes of the current mesh.
///////////////////////////////////////////////////////////////////////////////
-SMDS_VolumeIteratorPtr SMDS_Mesh::volumesIterator() const
+SMDS_VolumeIteratorPtr SMDS_Mesh::volumesIterator(bool idInceasingOrder) const
{
typedef MYNCollection_Map_Iterator
< SetOfVolumes, const SMDS_MeshVolume*, SMDS_VolumeIterator > TIterator;
- return SMDS_VolumeIteratorPtr(new TIterator(myVolumes));
+ typedef IdSortedIterator< const SMDS_MeshVolume* > TSortedIterator;
+ return ( idInceasingOrder ?
+ SMDS_VolumeIteratorPtr( new TSortedIterator( *myElementIDFactory,
+ SMDSAbs_Volume,
+ NbVolumes() )) :
+ SMDS_VolumeIteratorPtr(new TIterator(myVolumes)));
}
///////////////////////////////////////////////////////////////////////////////