Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/smesh.git] / src / SMDS / SMDS_MeshNode.cxx
index 1d968dcbbf710571ec9f267f81970322d5182e39..d7c291b520ef059bf962734466b24a9fa36608af 100644 (file)
@@ -1,24 +1,26 @@
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 //  SMESH SMDS : implementaion of Salome mesh data structure
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-
 #ifdef _MSC_VER
 #pragma warning(disable:4786)
 #endif
@@ -88,16 +90,28 @@ const SMDS_PositionPtr& SMDS_MeshNode::GetPosition() const
        return myPosition;
 }
 
+//=======================================================================
+/*!
+ * \brief Iterator on list of elements
+ */
+//=======================================================================
+
 class SMDS_MeshNode_MyInvIterator:public SMDS_ElemIterator
 {
   NCollection_List<const SMDS_MeshElement*>::Iterator myIterator;
+  SMDSAbs_ElementType                                 myType;
  public:
-  SMDS_MeshNode_MyInvIterator(const NCollection_List<const SMDS_MeshElement*>& s):
-    myIterator(s)
+  SMDS_MeshNode_MyInvIterator(const NCollection_List<const SMDS_MeshElement*>& s,
+                              SMDSAbs_ElementType type):
+    myIterator(s), myType(type)
   {}
 
   bool more()
   {
+    if ( myType != SMDSAbs_All ) {
+      while ( myIterator.More() && myIterator.Value()->GetType() != myType)
+        myIterator.Next();
+    }
     return myIterator.More() != Standard_False;
   }
 
@@ -110,9 +124,9 @@ class SMDS_MeshNode_MyInvIterator:public SMDS_ElemIterator
 };
 
 SMDS_ElemIteratorPtr SMDS_MeshNode::
-       GetInverseElementIterator() const
+       GetInverseElementIterator(SMDSAbs_ElementType type) const
 {
-  return SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyInvIterator(myInverseElements));
+  return SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyInvIterator(myInverseElements,type));
 }
 
 // Same as GetInverseElementIterator but the create iterator only return
@@ -228,6 +242,24 @@ bool SMDS_MeshNode::emptyInverseElements()
   return myInverseElements.IsEmpty() != Standard_False;
 }
 
+//================================================================================
+/*!
+ * \brief Count inverse elements of given type
+ */
+//================================================================================
+
+int SMDS_MeshNode::NbInverseElements(SMDSAbs_ElementType type) const
+{
+  if ( type == SMDSAbs_All )
+    return myInverseElements.Extent();
+  int nb = 0;
+  NCollection_List<const SMDS_MeshElement*>::Iterator it( myInverseElements );
+  for ( ; it.More(); it.Next() )
+    if ( it.Value()->GetType() == type )
+      nb++;
+  return nb;
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 /// To be used with STL set
 ///////////////////////////////////////////////////////////////////////////////