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 * aMesh)
36 :myMesh(aMesh),myType(SMDSAbs_All), myParent(NULL)
40 //=======================================================================
41 //function : SMDS_MeshGroup
43 //=======================================================================
45 SMDS_MeshGroup::SMDS_MeshGroup(SMDS_MeshGroup * parent)
46 :myMesh(parent->myMesh),myType(SMDSAbs_All), myParent(parent)
50 //=======================================================================
51 //function : AddSubGroup
53 //=======================================================================
55 const SMDS_MeshGroup *SMDS_MeshGroup::AddSubGroup()
57 const SMDS_MeshGroup * subgroup = new SMDS_MeshGroup(this);
58 myChildren.insert(myChildren.end(),subgroup);
62 //=======================================================================
63 //function : RemoveSubGroup
65 //=======================================================================
67 bool SMDS_MeshGroup::RemoveSubGroup(const SMDS_MeshGroup * aGroup)
70 list<const SMDS_MeshGroup*>::iterator itgroup;
71 for(itgroup=myChildren.begin(); itgroup!=myChildren.end(); itgroup++)
73 const SMDS_MeshGroup* subgroup=*itgroup;
74 if (subgroup == aGroup)
77 myChildren.erase(itgroup);
84 //=======================================================================
85 //function : RemoveFromParent
87 //=======================================================================
89 bool SMDS_MeshGroup::RemoveFromParent()
92 if (myParent==NULL) return false;
95 return (myParent->RemoveSubGroup(this));
98 //=======================================================================
101 //=======================================================================
103 void SMDS_MeshGroup::Clear()
106 myType = SMDSAbs_All;
109 //=======================================================================
112 //=======================================================================
114 bool SMDS_MeshGroup::IsEmpty() const
116 return myElements.empty();
119 //=======================================================================
122 //=======================================================================
124 int SMDS_MeshGroup::Extent() const
126 return myElements.size();
129 //=======================================================================
132 //=======================================================================
134 void SMDS_MeshGroup::Add(const SMDS_MeshElement * ME)
136 // the type of the group is determined by the first element added
137 if (myElements.empty()) myType = ME->GetType();
138 else if (ME->GetType() != myType)
139 MESSAGE("SMDS_MeshGroup::Add : Type Mismatch");
141 myElements.insert(ME);
144 //=======================================================================
147 //=======================================================================
149 void SMDS_MeshGroup::Remove(const SMDS_MeshElement * ME)
151 myElements.erase(ME);
152 if (myElements.empty()) myType = SMDSAbs_All;
155 //=======================================================================
158 //=======================================================================
160 SMDSAbs_ElementType SMDS_MeshGroup::Type() const
165 //=======================================================================
166 //function : Contains
168 //=======================================================================
170 bool SMDS_MeshGroup::Contains(const SMDS_MeshElement * ME) const
172 return myElements.find(ME)!=myElements.end();