Salome HOME
da7b0da13f2200da883385a8651e4e73dd9c543b
[modules/smesh.git] / src / SMESHDS / SMESHDS_GroupBase.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.com
20 //
21 //
22 //
23 //  File   : SMESHDS_Group.cxx
24 //  Module : SMESH
25 //  $Header$
26
27 #include "SMESHDS_GroupBase.hxx"
28 #include "SMESHDS_Mesh.hxx"
29
30 #include "utilities.h"
31
32 using namespace std;
33
34 //=============================================================================
35 /*!
36  *  
37  */
38 //=============================================================================
39
40 SMESHDS_GroupBase::SMESHDS_GroupBase (const int                 theID,
41                                       const SMESHDS_Mesh*       theMesh,
42                                       const SMDSAbs_ElementType theType):
43        myID(theID), myMesh(theMesh), myType(theType), myStoreName(""),
44        myCurIndex(0), myCurID(-1)
45 {
46   myColor.R = 0.f;
47   myColor.G = 0.f;
48   myColor.B = 0.f;
49 }
50
51 //=============================================================================
52 /*!
53  *  
54  */
55 //=============================================================================
56
57 int SMESHDS_GroupBase::GetID (const int theIndex)
58 {
59   if (myCurIndex < 1 || myCurIndex > theIndex) {
60     myIterator = GetElements();
61     myCurIndex = 0;
62     myCurID = -1;
63   }
64   while (myCurIndex < theIndex && myIterator->more()) {
65     myCurIndex++;
66     myCurID = myIterator->next()->GetID();
67   }
68   return myCurIndex == theIndex ? myCurID : -1;
69 }
70
71 //=============================================================================
72 /*!
73  *  
74  */
75 //=============================================================================
76
77 const SMDS_MeshElement* SMESHDS_GroupBase::findInMesh (const int theID) const
78 {
79   SMDSAbs_ElementType aType = GetType();
80   const SMDS_MeshElement* aElem = NULL;
81   if (aType == SMDSAbs_Node) {
82     aElem = GetMesh()->FindNode(theID);
83   }
84   else if (aType != SMDSAbs_All) {
85     aElem = GetMesh()->FindElement(theID);
86     if (aElem && aType != aElem->GetType())
87       aElem = NULL;
88   }
89   return aElem;
90 }
91
92 //=============================================================================
93 /*!
94  *  Internal method: resets cached iterator, should be called by ancestors
95  *  when they are modified (ex: Add() or Remove() )
96  */
97 //=============================================================================
98 void SMESHDS_GroupBase::resetIterator()
99 {
100   myCurIndex = 0;
101   myCurID = -1;
102 }
103
104 //=======================================================================
105 //function : Extent
106 //purpose  : 
107 //=======================================================================
108
109 int SMESHDS_GroupBase::Extent()
110 {
111   SMDS_ElemIteratorPtr it = GetElements();
112   int nb = 0;
113   if ( it )
114     for ( ; it->more(); it->next() ) 
115       nb++;
116   return nb;
117 }
118
119 //=======================================================================
120 //function : IsEmpty
121 //purpose  : 
122 //=======================================================================
123
124 bool SMESHDS_GroupBase::IsEmpty()
125 {
126   SMDS_ElemIteratorPtr it = GetElements();
127   return ( !it || !it->more() );
128 }
129
130 //=======================================================================
131 //function : Contains
132 //purpose  : 
133 //=======================================================================
134
135 bool SMESHDS_GroupBase::Contains (const int theID)
136 {
137   SMDS_ElemIteratorPtr it = GetElements();
138   bool contains = false;
139   if ( it )
140     while ( !contains && it->more() )
141       contains = ( it->next()->GetID() == theID );
142   return contains;
143 }
144
145 //=======================================================================
146 //function : SetType
147 //purpose  : 
148 //=======================================================================
149
150 void SMESHDS_GroupBase::SetType(SMDSAbs_ElementType theType)
151 {
152   myType = theType;
153 }