Version: 6.3.1

src/SMDS/SMDS_MeshGroup.cxx

Go to the documentation of this file.
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 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)
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 }
00118 
00119 //=======================================================================
00120 //function : Add
00121 //purpose  : 
00122 //=======================================================================
00123 
00124 void SMDS_MeshGroup::Add(const SMDS_MeshElement * theElem)
00125 {
00126         // the type of the group is determined by the first element added
00127         if (myElements.empty()) myType = theElem->GetType();
00128         else if (theElem->GetType() != myType) {
00129           MESSAGE("SMDS_MeshGroup::Add : Type Mismatch "<<theElem->GetType()<<"!="<<myType);
00130           return;
00131         }
00132         
00133         myElements.insert(theElem);
00134 }
00135 
00136 //=======================================================================
00137 //function : Remove
00138 //purpose  : 
00139 //=======================================================================
00140 
00141 bool SMDS_MeshGroup::Remove(const SMDS_MeshElement * theElem)
00142 {
00143   std::set<const SMDS_MeshElement *>::iterator found
00144     = myElements.find(theElem);
00145   if ( found != myElements.end() ) {
00146     myElements.erase(found);
00147     if (myElements.empty()) myType = SMDSAbs_All;
00148     return true;
00149   }
00150   return false;
00151 }
00152 
00153 //=======================================================================
00154 //function : Contains
00155 //purpose  : 
00156 //=======================================================================
00157 
00158 bool SMDS_MeshGroup::Contains(const SMDS_MeshElement * theElem) const
00159 {
00160         return myElements.find(theElem)!=myElements.end();
00161 }
00162 
00163 //=======================================================================
00164 //function : SetType
00165 //purpose  : 
00166 //=======================================================================
00167 
00168 void SMDS_MeshGroup::SetType(const SMDSAbs_ElementType theType)
00169 {
00170   if (IsEmpty())
00171     myType = theType;
00172 }
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS