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