Salome HOME
0020431: EDF 1020 SMESH : Radial Mesh of a cylinder
[modules/smesh.git] / src / SMDS / SMDS_MeshElement.cxx
index 701e6fe97ce20051f79820ed74110609341e86a1..a24cbff94b6512aeed6dc066cbb171e3f0c5707d 100644 (file)
@@ -1,23 +1,29 @@
+//  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+#ifdef _MSC_VER
+#pragma warning(disable:4786)
+#endif
 
 #include "SMDS_MeshElement.hxx"
 #include "SMDS_MeshNode.hxx"
@@ -26,6 +32,8 @@
 #include "SMDS_MeshVolume.hxx"
 #include "utilities.h"
 
+using namespace std;
+
 SMDS_MeshElement::SMDS_MeshElement(int ID):myID(ID)
 {
 }
@@ -45,7 +53,7 @@ ostream & operator <<(ostream & OS, const SMDS_MeshElement * ME)
 /// Create an iterator which iterate on nodes owned by the element.
 /// This method call elementsIterator().
 ///////////////////////////////////////////////////////////////////////////////
-SMDS_Iterator<const SMDS_MeshElement *> * SMDS_MeshElement::nodesIterator() const
+SMDS_ElemIteratorPtr SMDS_MeshElement::nodesIterator() const
 {
        return elementsIterator(SMDSAbs_Node);
 }
@@ -54,7 +62,7 @@ SMDS_Iterator<const SMDS_MeshElement *> * SMDS_MeshElement::nodesIterator() cons
 /// Create an iterator which iterate on edges linked with or owned by the element.
 /// This method call elementsIterator().
 ///////////////////////////////////////////////////////////////////////////////
-SMDS_Iterator<const SMDS_MeshElement *> * SMDS_MeshElement::edgesIterator() const
+SMDS_ElemIteratorPtr SMDS_MeshElement::edgesIterator() const
 {
        return elementsIterator(SMDSAbs_Edge);
 }
@@ -63,7 +71,7 @@ SMDS_Iterator<const SMDS_MeshElement *> * SMDS_MeshElement::edgesIterator() cons
 /// Create an iterator which iterate on faces linked with or owned by the element.
 /// This method call elementsIterator().
 ///////////////////////////////////////////////////////////////////////////////
-SMDS_Iterator<const SMDS_MeshElement *> * SMDS_MeshElement::facesIterator() const
+SMDS_ElemIteratorPtr SMDS_MeshElement::facesIterator() const
 {
        return elementsIterator(SMDSAbs_Face);
 }
@@ -74,13 +82,12 @@ SMDS_Iterator<const SMDS_MeshElement *> * SMDS_MeshElement::facesIterator() cons
 int SMDS_MeshElement::NbNodes() const
 {
        int nbnodes=0;
-       SMDS_Iterator<const SMDS_MeshElement *> * it=nodesIterator();
+       SMDS_ElemIteratorPtr it=nodesIterator();
        while(it->more())
        {
                it->next();
                nbnodes++;
        }
-       delete it;
        return nbnodes;
 }
 
@@ -90,13 +97,12 @@ int SMDS_MeshElement::NbNodes() const
 int SMDS_MeshElement::NbEdges() const
 {
        int nbedges=0;
-       SMDS_Iterator<const SMDS_MeshElement *> * it=edgesIterator();
+       SMDS_ElemIteratorPtr it=edgesIterator();
        while(it->more())
        {
                it->next();
                nbedges++;
        }
-       delete it;
        return nbedges;
 }
 
@@ -106,55 +112,52 @@ int SMDS_MeshElement::NbEdges() const
 int SMDS_MeshElement::NbFaces() const
 {
        int nbfaces=0;
-       SMDS_Iterator<const SMDS_MeshElement *> * it=facesIterator();
+       SMDS_ElemIteratorPtr it=facesIterator();
        while(it->more())
        {
                it->next();
                nbfaces++;
        }
-       delete it;
        return nbfaces;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-///Create and iterator which iterate on elements linked with the current element.
-///The iterator must be free by the caller (call delete myIterator).
+///Create an iterator which iterate on elements linked with the current element.
 ///@param type The of elements on which you want to iterate
-///@return An iterator, that you must free when you no longer need it
+///@return A smart pointer to iterator, you are not to take care of freeing memory
 ///////////////////////////////////////////////////////////////////////////////
-SMDS_Iterator<const SMDS_MeshElement *> * SMDS_MeshElement::
+class SMDS_MeshElement_MyIterator:public SMDS_ElemIterator
+{
+  const SMDS_MeshElement * myElement;
+  bool myMore;
+ public:
+  SMDS_MeshElement_MyIterator(const SMDS_MeshElement * element):
+    myElement(element),myMore(true) {}
+
+  bool more()
+  {
+    return myMore;
+  }
+
+  const SMDS_MeshElement* next()
+  {
+    myMore=false;
+    return myElement;  
+  }    
+};
+SMDS_ElemIteratorPtr SMDS_MeshElement::
        elementsIterator(SMDSAbs_ElementType type) const
 {
        /** @todo Check that iterator in the child classes return elements
        in the same order for each different implementation (i.e: SMDS_VolumeOfNodes
        and SMDS_VolumeOfFaces */
-       class MyIterator:public SMDS_Iterator<const SMDS_MeshElement*>
-       {
-               const SMDS_MeshElement * myElement;
-               bool myMore;
-         public:
-               MyIterator(const SMDS_MeshElement * element):
-                       myElement(element),myMore(true)
-               {
-               }
-
-               bool more()
-               {
-                       return myMore;
-               }
-
-               const SMDS_MeshElement* next()
-               {
-                       myMore=false;
-                       return myElement;       
-               }       
-       };
        
-       if(type==GetType()) return new MyIterator(this);
+       if(type==GetType())
+          return SMDS_ElemIteratorPtr(new SMDS_MeshElement_MyIterator(this));
        else 
        {
-               MESSAGE("Iterator not implemented");            
-               return NULL;
+          MESSAGE("Iterator not implemented");
+          return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL);
        }
 }
 
@@ -189,4 +192,49 @@ bool operator<(const SMDS_MeshElement& e1, const SMDS_MeshElement& e2)
 
        default : MESSAGE("Internal Error");
        }
+        return false;
+}
+
+bool SMDS_MeshElement::IsValidIndex(const int ind) const
+{
+  return ( ind>-1 && ind<NbNodes() );
+}
+
+const SMDS_MeshNode* SMDS_MeshElement::GetNode(const int ind) const
+{
+  if ( ind >= 0 ) {
+    SMDS_ElemIteratorPtr it = nodesIterator();
+    for ( int i = 0; i < ind; ++i )
+      it->next();
+    if ( it->more() )
+      return static_cast<const SMDS_MeshNode*> (it->next());
+  }
+  return 0;
+}
+
+bool SMDS_MeshElement::IsQuadratic() const
+{
+  return false;
+}
+
+bool SMDS_MeshElement::IsMediumNode(const SMDS_MeshNode* node) const
+{
+  return false;
+}
+
+//================================================================================
+  /*!
+   * \brief Check if a node belongs to the element
+    * \param node - the node to check
+    * \retval int - node index within the element, -1 if not found
+   */
+//================================================================================
+
+int SMDS_MeshElement::GetNodeIndex( const SMDS_MeshNode* node ) const
+{
+  SMDS_ElemIteratorPtr nIt = nodesIterator();
+  for ( int i = 0; nIt->more(); ++i )
+    if ( nIt->next() == node )
+      return i;
+  return -1;
 }