1 // SMESH SMESHDS : idl implementation based on 'SMESH' unit's classes
3 // Copyright (C) 2004 CEA
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SMESHDS_Group.cxx
27 #include "SMESHDS_GroupBase.hxx"
28 #include "SMESHDS_Mesh.hxx"
30 #include "utilities.h"
34 //=============================================================================
38 //=============================================================================
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)
46 myColor = Quantity_Color( 0.0, 0.0, 0.0, Quantity_TOC_RGB );
49 //=============================================================================
53 //=============================================================================
55 int SMESHDS_GroupBase::GetID (const int theIndex)
57 if (myCurIndex < 1 || myCurIndex > theIndex) {
58 myIterator = GetElements();
62 while (myCurIndex < theIndex && myIterator->more()) {
64 myCurID = myIterator->next()->GetID();
66 return myCurIndex == theIndex ? myCurID : -1;
69 //=============================================================================
73 //=============================================================================
75 const SMDS_MeshElement* SMESHDS_GroupBase::findInMesh (const int theID) const
77 SMDSAbs_ElementType aType = GetType();
78 const SMDS_MeshElement* aElem = NULL;
79 if (aType == SMDSAbs_Node) {
80 aElem = GetMesh()->FindNode(theID);
82 else if (aType != SMDSAbs_All) {
83 aElem = GetMesh()->FindElement(theID);
84 if (aElem && aType != aElem->GetType())
90 //=============================================================================
92 * Internal method: resets cached iterator, should be called by ancestors
93 * when they are modified (ex: Add() or Remove() )
95 //=============================================================================
96 void SMESHDS_GroupBase::resetIterator()
102 //=======================================================================
105 //=======================================================================
107 int SMESHDS_GroupBase::Extent()
109 SMDS_ElemIteratorPtr it = GetElements();
112 for ( ; it->more(); it->next() )
117 //=======================================================================
120 //=======================================================================
122 bool SMESHDS_GroupBase::IsEmpty()
124 SMDS_ElemIteratorPtr it = GetElements();
125 return ( !it || !it->more() );
128 //=======================================================================
129 //function : Contains
131 //=======================================================================
133 bool SMESHDS_GroupBase::Contains (const int theID)
135 if ( SMDS_ElemIteratorPtr it = GetElements() ) {
137 if ( it->next()->GetID() == theID )
143 //=======================================================================
144 //function : Contains
146 //=======================================================================
148 bool SMESHDS_GroupBase::Contains (const SMDS_MeshElement* elem)
151 return Contains( elem->GetID() );
155 //=======================================================================
158 //=======================================================================
160 void SMESHDS_GroupBase::SetType(SMDSAbs_ElementType theType)
165 //=======================================================================
168 //=======================================================================
170 void SMESHDS_GroupBase::SetColorGroup(int theColorGroup)
172 int aRed = ( theColorGroup/1000000 );
173 int aGreen = ( theColorGroup -aRed*1000000)/1000;
174 int aBlue = ( theColorGroup - aRed*1000000 - aGreen*1000 );
175 double aR = aRed/255.0;
176 double aG = aGreen/255.0;
177 double aB = aBlue/255.0;
178 Quantity_Color aColor( aR, aG, aB, Quantity_TOC_RGB );
182 //=======================================================================
185 //=======================================================================
187 int SMESHDS_GroupBase::GetColorGroup() const
189 Quantity_Color aColor = GetColor();
190 double aRed = aColor.Red();
191 double aGreen = aColor.Green();
192 double aBlue = aColor.Blue();
196 int aRet = (int)(aR*1000000 + aG*1000 + aB);