Back to index

salome-smesh  6.5.0
SMDS_MeshGroup.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  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 SMDS : implementaion of Salome mesh data structure
00024 //  File   : SMDS_MeshGroup.cxx
00025 //  Author : Jean-Michel BOULCOURT
00026 //  Module : SMESH
00027 //
00028 #ifdef _MSC_VER
00029 #pragma warning(disable:4786)
00030 #endif
00031 
00032 #include "SMDS_MeshGroup.hxx"
00033 #include "utilities.h"
00034 
00035 using namespace std;
00036 
00037 //=======================================================================
00038 //function : SMDS_MeshGroup
00039 //purpose  : 
00040 //=======================================================================
00041 
00042 SMDS_MeshGroup::SMDS_MeshGroup(const SMDS_Mesh * theMesh,
00043                                const SMDSAbs_ElementType theType)
00044   :myMesh(theMesh),myType(theType), myParent(NULL), myTic(0)
00045 {
00046 }
00047 
00048 //=======================================================================
00049 //function : SMDS_MeshGroup
00050 //purpose  : 
00051 //=======================================================================
00052 
00053 SMDS_MeshGroup::SMDS_MeshGroup(SMDS_MeshGroup * theParent,
00054                                const SMDSAbs_ElementType theType)
00055         :myMesh(theParent->myMesh),myType(theType), myParent(theParent)
00056 {
00057 }
00058 
00059 //=======================================================================
00060 //function : AddSubGroup
00061 //purpose  : 
00062 //=======================================================================
00063 
00064 const SMDS_MeshGroup *SMDS_MeshGroup::AddSubGroup
00065                 (const SMDSAbs_ElementType theType)
00066 {
00067         const SMDS_MeshGroup * subgroup = new SMDS_MeshGroup(this,theType);
00068         myChildren.insert(myChildren.end(),subgroup);
00069         return subgroup;
00070 }
00071 
00072 //=======================================================================
00073 //function : RemoveSubGroup
00074 //purpose  : 
00075 //=======================================================================
00076 
00077 bool SMDS_MeshGroup::RemoveSubGroup(const SMDS_MeshGroup * theGroup)
00078 {
00079         bool found = false;     
00080         list<const SMDS_MeshGroup*>::iterator itgroup;
00081         for(itgroup=myChildren.begin(); itgroup!=myChildren.end(); itgroup++)
00082         {
00083                 const SMDS_MeshGroup* subgroup=*itgroup;
00084                 if (subgroup == theGroup)
00085                 {
00086                         found = true;
00087                         myChildren.erase(itgroup);
00088                 }
00089         }
00090 
00091         return found;
00092 }
00093 
00094 //=======================================================================
00095 //function : RemoveFromParent
00096 //purpose  : 
00097 //=======================================================================
00098 
00099 bool SMDS_MeshGroup::RemoveFromParent()
00100 {
00101         
00102         if (myParent==NULL) return false;
00103         else
00104         {
00105                 return (myParent->RemoveSubGroup(this));
00106         }
00107 }
00108 //=======================================================================
00109 //function : Clear
00110 //purpose  : 
00111 //=======================================================================
00112 
00113 void SMDS_MeshGroup::Clear()
00114 {
00115   myElements.clear();
00116   myType = SMDSAbs_All;
00117   ++myTic;
00118 }
00119 
00120 //=======================================================================
00121 //function : Add
00122 //purpose  : 
00123 //=======================================================================
00124 
00125 void SMDS_MeshGroup::Add(const SMDS_MeshElement * theElem)
00126 {
00127   // the type of the group is determined by the first element added
00128   if (myElements.empty()) myType = theElem->GetType();
00129   else if (theElem->GetType() != myType) {
00130     MESSAGE("SMDS_MeshGroup::Add : Type Mismatch "<<theElem->GetType()<<"!="<<myType);
00131     return;
00132   }
00133         
00134   myElements.insert(myElements.end(), theElem);
00135   ++myTic;
00136 }
00137 
00138 //=======================================================================
00139 //function : Remove
00140 //purpose  : 
00141 //=======================================================================
00142 
00143 bool SMDS_MeshGroup::Remove(const SMDS_MeshElement * theElem)
00144 {
00145   set<const SMDS_MeshElement *>::iterator found = myElements.find(theElem);
00146   if ( found != myElements.end() ) {
00147     myElements.erase(found);
00148     if (myElements.empty()) myType = SMDSAbs_All;
00149     ++myTic;
00150     return true;
00151   }
00152   return false;
00153 }
00154 
00155 //=======================================================================
00156 //function : Contains
00157 //purpose  : 
00158 //=======================================================================
00159 
00160 bool SMDS_MeshGroup::Contains(const SMDS_MeshElement * theElem) const
00161 {
00162         return myElements.find(theElem)!=myElements.end();
00163 }
00164 
00165 //=======================================================================
00166 //function : SetType
00167 //purpose  : 
00168 //=======================================================================
00169 
00170 void SMDS_MeshGroup::SetType(const SMDSAbs_ElementType theType)
00171 {
00172   if (IsEmpty())
00173     myType = theType;
00174 }