Salome HOME
Integration of PAL/SALOME V2.1.0c from OCC
[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 using namespace std;
32
33 //=============================================================================
34 /*!
35  *  
36  */
37 //=============================================================================
38
39 SMESHDS_Group::SMESHDS_Group (const int                 theID,
40                               const SMESHDS_Mesh*       theMesh,
41                               const SMDSAbs_ElementType theType)
42      : SMDS_MeshGroup(theMesh,theType),
43        myID(theID), myStoreName(""),
44        myCurIndex(0), myCurID(0)
45 {
46 }
47
48 //=============================================================================
49 /*!
50  *  
51  */
52 //=============================================================================
53
54 bool SMESHDS_Group::Contains (const int theID) const
55 {
56   const SMDS_MeshElement* aElem = findInMesh (theID);
57   if (aElem)
58     return SMDS_MeshGroup::Contains(aElem);
59   return false;
60 }
61
62 //=============================================================================
63 /*!
64  *  
65  */
66 //=============================================================================
67
68 bool SMESHDS_Group::Add (const int theID)
69 {
70   const SMDS_MeshElement* aElem = findInMesh (theID);
71   if (!aElem || SMDS_MeshGroup::Contains(aElem))
72     return false;
73   SMDS_MeshGroup::Add (aElem);
74   return true;
75 }
76
77 //=============================================================================
78 /*!
79  *  
80  */
81 //=============================================================================
82
83 bool SMESHDS_Group::Remove (const int theID)
84 {
85   const SMDS_MeshElement* aElem = findInMesh (theID);
86   if (!aElem || !SMDS_MeshGroup::Contains(aElem))
87     return false;
88   SMDS_MeshGroup::Remove (aElem);
89   return true;
90 }
91
92 //=============================================================================
93 /*!
94  *  
95  */
96 //=============================================================================
97
98 int SMESHDS_Group::GetID (const int theIndex)
99 {
100   if (theIndex < 1 || theIndex > Extent())
101     return -1;
102   if (myCurIndex < 1 || myCurIndex > theIndex) {
103     InitIterator();
104     myCurIndex = 0;
105     myCurID = -1;
106   }
107   while (myCurIndex < theIndex && More()) {
108     myCurIndex++;
109     myCurID = Next()->GetID();
110   }
111   return myCurID;
112 }
113
114 //=============================================================================
115 /*!
116  *  
117  */
118 //=============================================================================
119
120 const SMDS_MeshElement* SMESHDS_Group::findInMesh (const int theID) const
121 {
122   SMDSAbs_ElementType aType = GetType();
123   const SMDS_MeshElement* aElem = NULL;
124   if (aType == SMDSAbs_Node) {
125     aElem = GetMesh()->FindNode(theID);
126   }
127   else if (aType != SMDSAbs_All) {
128     aElem = GetMesh()->FindElement(theID);
129     if (aElem && aType != aElem->GetType())
130       aElem = NULL;
131   }
132   return aElem;
133 }