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 00023 // SMESH SMESHDS : idl implementation based on 'SMESH' unit's classes 00024 // File : SMESHDS_Group.cxx 00025 // Module : SMESH 00026 // $Header: /home/server/cvs/SMESH/SMESH_SRC/src/SMESHDS/SMESHDS_Group.cxx,v 1.10.20.2.6.1 2011-06-02 05:57:26 vsr Exp $ 00027 // 00028 #include "SMESHDS_Group.hxx" 00029 #include "SMESHDS_Mesh.hxx" 00030 00031 using namespace std; 00032 00033 //============================================================================= 00037 //============================================================================= 00038 00039 SMESHDS_Group::SMESHDS_Group (const int theID, 00040 const SMESHDS_Mesh* theMesh, 00041 const SMDSAbs_ElementType theType) 00042 : SMESHDS_GroupBase(theID,theMesh,theType), 00043 myGroup(theMesh,theType) 00044 { 00045 } 00046 00047 //======================================================================= 00048 //function : Extent 00049 //purpose : 00050 //======================================================================= 00051 00052 int SMESHDS_Group::Extent() 00053 { 00054 return myGroup.Extent(); 00055 } 00056 00057 //======================================================================= 00058 //function : IsEmpty 00059 //purpose : 00060 //======================================================================= 00061 00062 bool SMESHDS_Group::IsEmpty() 00063 { 00064 return myGroup.IsEmpty(); 00065 } 00066 00067 //============================================================================= 00071 //============================================================================= 00072 00073 bool SMESHDS_Group::Contains (const int theID) 00074 { 00075 const SMDS_MeshElement* aElem = findInMesh (theID); 00076 if (aElem) 00077 return myGroup.Contains(aElem); 00078 return false; 00079 } 00080 00081 //======================================================================= 00082 //function : Contains 00083 //purpose : 00084 //======================================================================= 00085 00086 bool SMESHDS_Group::Contains (const SMDS_MeshElement* elem) 00087 { 00088 if (elem) 00089 return myGroup.Contains(elem); 00090 return false; 00091 } 00092 00093 //============================================================================= 00097 //============================================================================= 00098 00099 bool SMESHDS_Group::Add (const int theID) 00100 { 00101 const SMDS_MeshElement* aElem = findInMesh (theID); 00102 if (!aElem || myGroup.Contains(aElem)) 00103 return false; 00104 00105 if (myGroup.IsEmpty()) 00106 SetType( aElem->GetType() ); 00107 00108 myGroup.Add (aElem); 00109 resetIterator(); 00110 return true; 00111 } 00112 00113 //============================================================================= 00117 //============================================================================= 00118 00119 bool SMESHDS_Group::Remove (const int theID) 00120 { 00121 const SMDS_MeshElement* aElem = findInMesh (theID); 00122 if (!aElem || !myGroup.Contains(aElem)) 00123 return false; 00124 myGroup.Remove (aElem); 00125 resetIterator(); 00126 return true; 00127 } 00128 00129 00130 //====================================================================== 00131 //function : Clear 00132 //purpose : 00133 //======================================================================= 00134 00135 void SMESHDS_Group::Clear() 00136 { 00137 myGroup.Clear(); 00138 resetIterator(); 00139 } 00140 00141 // ===================== 00142 // class MyGroupIterator 00143 // ===================== 00144 00145 class MyGroupIterator: public SMDS_ElemIterator 00146 { 00147 const SMDS_MeshGroup& myGroup; 00148 public: 00149 MyGroupIterator(const SMDS_MeshGroup& group): myGroup(group) { myGroup.InitIterator(); } 00150 bool more() { return myGroup.More(); } 00151 const SMDS_MeshElement* next() { return myGroup.Next(); } 00152 }; 00153 00154 //======================================================================= 00155 //function : GetElements 00156 //purpose : 00157 //======================================================================= 00158 00159 SMDS_ElemIteratorPtr SMESHDS_Group::GetElements() const 00160 { 00161 return SMDS_ElemIteratorPtr( new MyGroupIterator ( myGroup )); 00162 } 00163 00164 //======================================================================= 00165 //function : SetType 00166 //purpose : 00167 //======================================================================= 00168 00169 void SMESHDS_Group::SetType(SMDSAbs_ElementType theType) 00170 { 00171 if ( myGroup.IsEmpty() || GetType() == SMDSAbs_All ) { 00172 SMESHDS_GroupBase::SetType( theType ); 00173 myGroup.SetType ( theType ); 00174 } 00175 else 00176 SMESHDS_GroupBase::SetType( myGroup.GetType() ); 00177 } 00178