00001 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE 00002 // 00003 // This library is free software; you can redistribute it and/or 00004 // modify it under the terms of the GNU Lesser General Public 00005 // License as published by the Free Software Foundation; either 00006 // version 2.1 of the License. 00007 // 00008 // This library is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 // Lesser General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU Lesser General Public 00014 // License along with this library; if not, write to the Free Software 00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00016 // 00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com 00018 // 00019 00020 // SMESH SMDS : implementaion of Salome mesh data structure 00021 // File : SMDS_Mesh0DElement.cxx 00022 // Author : Jean-Michel BOULCOURT 00023 // Module : SMESH 00024 // 00025 #ifdef _MSC_VER 00026 #pragma warning(disable:4786) 00027 #endif 00028 00029 #include "SMDS_Mesh0DElement.hxx" 00030 #include "SMDS_IteratorOfElements.hxx" 00031 #include "SMDS_MeshNode.hxx" 00032 #include "utilities.h" 00033 00034 using namespace std; 00035 00036 //======================================================================= 00037 //function : SMDS_Mesh0DElement 00038 //purpose : 00039 //======================================================================= 00040 SMDS_Mesh0DElement::SMDS_Mesh0DElement (const SMDS_MeshNode * node) 00041 { 00042 MESSAGE("SMDS_Mesh0DElement " << GetID()); 00043 myNode = node; 00044 } 00045 00046 //======================================================================= 00047 //function : Print 00048 //purpose : 00049 //======================================================================= 00050 void SMDS_Mesh0DElement::Print (ostream & OS) const 00051 { 00052 OS << "0D Element <" << GetID() << "> : (" << myNode << ") " << endl; 00053 } 00054 00055 //======================================================================= 00056 //function : NbNodes 00057 //purpose : 00058 //======================================================================= 00059 int SMDS_Mesh0DElement::NbNodes() const 00060 { 00061 return 1; 00062 } 00063 00064 //======================================================================= 00065 //function : NbEdges 00066 //purpose : 00067 //======================================================================= 00068 int SMDS_Mesh0DElement::NbEdges() const 00069 { 00070 return 0; 00071 } 00072 00073 //======================================================================= 00074 //function : GetType 00075 //purpose : 00076 //======================================================================= 00077 SMDSAbs_ElementType SMDS_Mesh0DElement::GetType() const 00078 { 00079 return SMDSAbs_0DElement; 00080 } 00081 00082 vtkIdType SMDS_Mesh0DElement::GetVtkType() const 00083 { 00084 return VTK_VERTEX; 00085 } 00086 00087 //======================================================================= 00088 //function : elementsIterator 00089 //purpose : 00090 //======================================================================= 00091 class SMDS_Mesh0DElement_MyNodeIterator: public SMDS_ElemIterator 00092 { 00093 const SMDS_MeshNode * myNode; 00094 int myIndex; 00095 public: 00096 SMDS_Mesh0DElement_MyNodeIterator(const SMDS_MeshNode * node): 00097 myNode(node),myIndex(0) {} 00098 00099 bool more() 00100 { 00101 return myIndex < 1; 00102 } 00103 00104 const SMDS_MeshElement* next() 00105 { 00106 myIndex++; 00107 if (myIndex == 1) 00108 return myNode; 00109 return NULL; 00110 } 00111 }; 00112 00113 SMDS_ElemIteratorPtr SMDS_Mesh0DElement::elementsIterator (SMDSAbs_ElementType type) const 00114 { 00115 switch(type) 00116 { 00117 case SMDSAbs_0DElement: 00118 return SMDS_MeshElement::elementsIterator(SMDSAbs_0DElement); 00119 case SMDSAbs_Node: 00120 return SMDS_ElemIteratorPtr(new SMDS_Mesh0DElement_MyNodeIterator(myNode)); 00121 default: 00122 return SMDS_ElemIteratorPtr 00123 (new SMDS_IteratorOfElements 00124 (this,type, SMDS_ElemIteratorPtr(new SMDS_Mesh0DElement_MyNodeIterator(myNode)))); 00125 } 00126 } 00127 00128 //======================================================================= 00129 //function : operator< 00130 //purpose : 00131 //======================================================================= 00132 bool operator< (const SMDS_Mesh0DElement & e1, const SMDS_Mesh0DElement & e2) 00133 { 00134 int id1 = e1.myNode->getVtkId(); 00135 int id2 = e2.myNode->getVtkId(); 00136 00137 return (id1 < id2); 00138 } 00139 00145 const SMDS_MeshNode* SMDS_Mesh0DElement::GetNode(const int ind) const 00146 { 00147 if (ind == 0) 00148 return myNode; 00149 return NULL; 00150 } 00151 00152 //======================================================================= 00153 //function : ChangeNode 00154 //purpose : 00155 //======================================================================= 00156 bool SMDS_Mesh0DElement::ChangeNode (const SMDS_MeshNode * node) 00157 { 00158 myNode = node; 00159 return true; 00160 }