2 // File: SMDS_MeshGroup.cxx
3 // Created: Mon Jun 3 12:15:55 2002
4 // Author: Jean-Michel BOULCOURT
5 // <jmb@localhost.localdomain>
8 #include "SMDS_MeshGroup.ixx"
9 #include "SMDS_ListIteratorOfListOfMeshGroup.hxx"
11 //=======================================================================
12 //function : SMDS_MeshGroup
14 //=======================================================================
16 SMDS_MeshGroup::SMDS_MeshGroup(const Handle(SMDS_Mesh)& aMesh)
17 :myMesh(aMesh),myType(SMDSAbs_All)
21 //=======================================================================
22 //function : SMDS_MeshGroup
24 //=======================================================================
26 SMDS_MeshGroup::SMDS_MeshGroup(const Handle(SMDS_MeshGroup)& parent)
27 :myMesh(parent->myMesh),myType(SMDSAbs_All),myParent(parent)
31 //=======================================================================
32 //function : AddSubGroup
34 //=======================================================================
36 Handle(SMDS_MeshGroup) SMDS_MeshGroup::AddSubGroup()
38 Handle(SMDS_MeshGroup) subgroup = new SMDS_MeshGroup(this);
39 if (!subgroup.IsNull()) {
40 myChildren.Append(subgroup);
45 //=======================================================================
46 //function : RemoveSubGroup
48 //=======================================================================
50 Standard_Boolean SMDS_MeshGroup::RemoveSubGroup(const Handle(SMDS_MeshGroup)& aGroup)
52 Standard_Boolean found = Standard_False;
54 SMDS_ListIteratorOfListOfMeshGroup itgroup(myChildren);
55 for (;itgroup.More() && !found; itgroup.Next()) {
56 Handle(SMDS_MeshGroup) subgroup;
57 subgroup = itgroup.Value();
58 if (subgroup == aGroup) {
59 found = Standard_True;
60 myChildren.Remove(itgroup);
67 //=======================================================================
68 //function : RemoveFromParent
70 //=======================================================================
72 Standard_Boolean SMDS_MeshGroup::RemoveFromParent()
74 if (myParent.IsNull())
75 return Standard_False;
77 return (myParent->RemoveSubGroup(this));
81 //=======================================================================
84 //=======================================================================
86 void SMDS_MeshGroup::Clear()
92 //=======================================================================
95 //=======================================================================
97 Standard_Boolean SMDS_MeshGroup::IsEmpty() const
99 return myElements.IsEmpty();
102 //=======================================================================
105 //=======================================================================
107 Standard_Integer SMDS_MeshGroup::Extent() const
109 return myElements.Extent();
112 //=======================================================================
115 //=======================================================================
117 void SMDS_MeshGroup::Add(const Handle(SMDS_MeshElement)& ME)
119 // the type of the group is determined by the first element added
120 if (myElements.IsEmpty()) {
121 myType = ME->GetType();
124 if (ME->GetType() != myType) {
125 Standard_TypeMismatch::Raise("SMDS_MeshGroup::Add");
132 //=======================================================================
135 //=======================================================================
137 void SMDS_MeshGroup::Remove(const Handle(SMDS_MeshElement)& ME)
139 myElements.Remove(ME);
140 if (myElements.IsEmpty())
141 myType = SMDSAbs_All;
144 //=======================================================================
147 //=======================================================================
149 SMDSAbs_ElementType SMDS_MeshGroup::Type() const
154 //=======================================================================
155 //function : Contains
157 //=======================================================================
159 Standard_Boolean SMDS_MeshGroup::Contains(const Handle(SMDS_MeshElement)& ME) const
161 return myElements.Contains(ME);