1 // SMESH SMDS : implementaion of Salome mesh data structure
3 // Copyright (C) 2003 OPEN CASCADE
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.opencascade.org or email : webmaster@opencascade.org
23 // File : SMDS_MeshGroup.cxx
24 // Author : Jean-Michel BOULCOURT
28 #include "SMDS_MeshGroup.hxx"
29 #include "utilities.h"
30 //=======================================================================
31 //function : SMDS_MeshGroup
33 //=======================================================================
35 SMDS_MeshGroup::SMDS_MeshGroup(const SMDS_Mesh * theMesh,
36 const SMDSAbs_ElementType theType)
37 :myMesh(theMesh),myType(theType), myParent(NULL)
41 //=======================================================================
42 //function : SMDS_MeshGroup
44 //=======================================================================
46 SMDS_MeshGroup::SMDS_MeshGroup(SMDS_MeshGroup * theParent,
47 const SMDSAbs_ElementType theType)
48 :myMesh(theParent->myMesh),myType(theType), myParent(theParent)
52 //=======================================================================
53 //function : AddSubGroup
55 //=======================================================================
57 const SMDS_MeshGroup *SMDS_MeshGroup::AddSubGroup
58 (const SMDSAbs_ElementType theType)
60 const SMDS_MeshGroup * subgroup = new SMDS_MeshGroup(this,theType);
61 myChildren.insert(myChildren.end(),subgroup);
65 //=======================================================================
66 //function : RemoveSubGroup
68 //=======================================================================
70 bool SMDS_MeshGroup::RemoveSubGroup(const SMDS_MeshGroup * theGroup)
73 list<const SMDS_MeshGroup*>::iterator itgroup;
74 for(itgroup=myChildren.begin(); itgroup!=myChildren.end(); itgroup++)
76 const SMDS_MeshGroup* subgroup=*itgroup;
77 if (subgroup == theGroup)
80 myChildren.erase(itgroup);
87 //=======================================================================
88 //function : RemoveFromParent
90 //=======================================================================
92 bool SMDS_MeshGroup::RemoveFromParent()
95 if (myParent==NULL) return false;
98 return (myParent->RemoveSubGroup(this));
101 //=======================================================================
104 //=======================================================================
106 void SMDS_MeshGroup::Clear()
109 myType = SMDSAbs_All;
112 //=======================================================================
115 //=======================================================================
117 void SMDS_MeshGroup::Add(const SMDS_MeshElement * theElem)
119 // the type of the group is determined by the first element added
120 if (myElements.empty()) myType = theElem->GetType();
121 else if (theElem->GetType() != myType)
122 MESSAGE("SMDS_MeshGroup::Add : Type Mismatch");
124 myElements.insert(theElem);
127 //=======================================================================
130 //=======================================================================
132 void SMDS_MeshGroup::Remove(const SMDS_MeshElement * theElem)
134 myElements.erase(theElem);
135 if (myElements.empty()) myType = SMDSAbs_All;
138 //=======================================================================
139 //function : Contains
141 //=======================================================================
143 bool SMDS_MeshGroup::Contains(const SMDS_MeshElement * theElem) const
145 return myElements.find(theElem)!=myElements.end();
148 //=======================================================================
151 //=======================================================================
153 void SMDS_MeshGroup::SetType(const SMDSAbs_ElementType theType)