Salome HOME
SALOME PAL V1_4_1
[modules/smesh.git] / src / SMESHDS / SMESHDS_Group.cxx
1 //  SMESH SMESHDS : idl implementation based on 'SMESH' unit's classes
2 //
3 //  Copyright (C) 2004  CEA
4 // 
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. 
9 // 
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. 
14 // 
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 
18 // 
19 //  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org 
20 //
21 //
22 //
23 //  File   : SMESHDS_Group.cxx
24 //  Author : Michael Sazonov, OCC
25 //  Module : SMESH
26 //  $Header$
27
28 #include <SMESHDS_Group.hxx>
29 #include <SMESHDS_Mesh.hxx>
30
31 //=============================================================================
32 /*!
33  *  
34  */
35 //=============================================================================
36
37 SMESHDS_Group::SMESHDS_Group (const SMESHDS_Mesh*       theMesh,
38                               const SMDSAbs_ElementType theType)
39      : SMDS_MeshGroup(theMesh,theType), myStoreName(""),
40        myCurIndex(0), myCurID(0)
41 {
42 }
43
44 //=============================================================================
45 /*!
46  *  
47  */
48 //=============================================================================
49
50 bool SMESHDS_Group::Contains (const int theID) const
51 {
52   const SMDS_MeshElement* aElem = findInMesh (theID);
53   if (aElem)
54     return SMDS_MeshGroup::Contains(aElem);
55   return false;
56 }
57
58 //=============================================================================
59 /*!
60  *  
61  */
62 //=============================================================================
63
64 bool SMESHDS_Group::Add (const int theID)
65 {
66   const SMDS_MeshElement* aElem = findInMesh (theID);
67   if (!aElem || SMDS_MeshGroup::Contains(aElem))
68     return false;
69   SMDS_MeshGroup::Add (aElem);
70   return true;
71 }
72
73 //=============================================================================
74 /*!
75  *  
76  */
77 //=============================================================================
78
79 bool SMESHDS_Group::Remove (const int theID)
80 {
81   const SMDS_MeshElement* aElem = findInMesh (theID);
82   if (!aElem || !SMDS_MeshGroup::Contains(aElem))
83     return false;
84   SMDS_MeshGroup::Remove (aElem);
85   return true;
86 }
87
88 //=============================================================================
89 /*!
90  *  
91  */
92 //=============================================================================
93
94 int SMESHDS_Group::GetID (const int theIndex)
95 {
96   if (theIndex < 1 || theIndex > Extent())
97     return -1;
98   if (myCurIndex < 1 || myCurIndex > theIndex) {
99     InitIterator();
100     myCurIndex = 0;
101     myCurID = -1;
102   }
103   while (myCurIndex < theIndex && More()) {
104     myCurIndex++;
105     myCurID = Next()->GetID();
106   }
107   return myCurID;
108 }
109
110 //=============================================================================
111 /*!
112  *  
113  */
114 //=============================================================================
115
116 const SMDS_MeshElement* SMESHDS_Group::findInMesh (const int theID) const
117 {
118   SMDSAbs_ElementType aType = GetType();
119   const SMDS_MeshElement* aElem = NULL;
120   if (aType == SMDSAbs_Node) {
121     aElem = GetMesh()->FindNode(theID);
122   }
123   else if (aType != SMDSAbs_All) {
124     aElem = GetMesh()->FindElement(theID);
125     if (aElem && aType != aElem->GetType())
126       aElem = NULL;
127   }
128   return aElem;
129 }