]> SALOME platform Git repositories - modules/smesh.git/commitdiff
Salome HOME
Implement iteration in id increasing order
authoreap <eap@opencascade.com>
Thu, 19 Aug 2010 09:17:39 +0000 (09:17 +0000)
committereap <eap@opencascade.com>
Thu, 19 Aug 2010 09:17:39 +0000 (09:17 +0000)
-  SMDS_NodeIteratorPtr nodesIterator(bool idInceasingOrder=false) const;
-  SMDS_0DElementIteratorPtr elements0dIterator() const;
-  SMDS_EdgeIteratorPtr edgesIterator() const;
-  SMDS_FaceIteratorPtr facesIterator() const;
-  SMDS_VolumeIteratorPtr volumesIterator() const;
+  SMDS_NodeIteratorPtr nodesIterator          (bool idInceasingOrder=false) const;
+  SMDS_0DElementIteratorPtr elements0dIterator(bool idInceasingOrder=false) const;
+  SMDS_EdgeIteratorPtr edgesIterator          (bool idInceasingOrder=false) const;
+  SMDS_FaceIteratorPtr facesIterator          (bool idInceasingOrder=false) const;
+  SMDS_VolumeIteratorPtr volumesIterator      (bool idInceasingOrder=false) const;

src/SMDS/SMDS_Mesh.cxx
src/SMDS/SMDS_Mesh.hxx

index 408ad1f0e3f566ac0d3dbce21f7597438f062390..d3d41b135bc4faa4a3eec9041dd6659a41b48278 100644 (file)
@@ -2191,12 +2191,18 @@ namespace {
   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();
     }
@@ -2207,8 +2213,14 @@ namespace {
     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;
     }
   };
@@ -2224,7 +2236,7 @@ SMDS_NodeIteratorPtr SMDS_Mesh::nodesIterator(bool idInceasingOrder) const
     < 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)));
 }
 
@@ -2232,44 +2244,64 @@ SMDS_NodeIteratorPtr SMDS_Mesh::nodesIterator(bool idInceasingOrder) const
 ///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)));
 }
 
 ///////////////////////////////////////////////////////////////////////////////
index 36f7e37c1f1d5c7791d19467bee2e30f89ab2526..e9397b6a202318e2a59cf599af92acf87090614e 100644 (file)
@@ -48,11 +48,11 @@ public:
 
   SMDS_Mesh();
 
-  SMDS_NodeIteratorPtr nodesIterator(bool idInceasingOrder=false) const;
-  SMDS_0DElementIteratorPtr elements0dIterator() const;
-  SMDS_EdgeIteratorPtr edgesIterator() const;
-  SMDS_FaceIteratorPtr facesIterator() const;
-  SMDS_VolumeIteratorPtr volumesIterator() const;
+  SMDS_NodeIteratorPtr nodesIterator          (bool idInceasingOrder=false) const;
+  SMDS_0DElementIteratorPtr elements0dIterator(bool idInceasingOrder=false) const;
+  SMDS_EdgeIteratorPtr edgesIterator          (bool idInceasingOrder=false) const;
+  SMDS_FaceIteratorPtr facesIterator          (bool idInceasingOrder=false) const;
+  SMDS_VolumeIteratorPtr volumesIterator      (bool idInceasingOrder=false) const;
   SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type=SMDSAbs_All) const;
 
   SMDSAbs_ElementType GetElementType( const int id, const bool iselem ) const;