1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHDS : idl implementation based on 'SMESH' unit's classes
24 // File : SMESHDS_Group.cxx
28 #include "SMESHDS_GroupBase.hxx"
29 #include "SMESHDS_Mesh.hxx"
31 #include "utilities.h"
35 //=============================================================================
39 //=============================================================================
41 SMESHDS_GroupBase::SMESHDS_GroupBase (const int theID,
42 const SMESHDS_Mesh* theMesh,
43 const SMDSAbs_ElementType theType):
44 myID(theID), myMesh(theMesh), myType(theType), myStoreName(""),
45 myCurIndex(0), myCurID(-1)
47 myColor = Quantity_Color( 0.0, 0.0, 0.0, Quantity_TOC_RGB );
50 //=============================================================================
54 //=============================================================================
56 int SMESHDS_GroupBase::GetID (const int theIndex)
58 if (myCurIndex < 1 || myCurIndex > theIndex) {
59 myIterator = GetElements();
63 while (myCurIndex < theIndex && myIterator->more()) {
65 myCurID = myIterator->next()->GetID();
67 return myCurIndex == theIndex ? myCurID : -1;
70 //=============================================================================
74 //=============================================================================
76 const SMDS_MeshElement* SMESHDS_GroupBase::findInMesh (const int theID) const
78 SMDSAbs_ElementType aType = GetType();
79 const SMDS_MeshElement* aElem = NULL;
80 if (aType == SMDSAbs_Node) {
81 aElem = GetMesh()->FindNode(theID);
83 else if (aType != SMDSAbs_All) {
84 aElem = GetMesh()->FindElement(theID);
85 if (aElem && aType != aElem->GetType())
91 //=============================================================================
93 * Internal method: resets cached iterator, should be called by ancestors
94 * when they are modified (ex: Add() or Remove() )
96 //=============================================================================
97 void SMESHDS_GroupBase::resetIterator()
103 //=======================================================================
106 //=======================================================================
108 int SMESHDS_GroupBase::Extent() const
110 SMDS_ElemIteratorPtr it = GetElements();
113 for ( ; it->more(); it->next() )
118 //=======================================================================
121 //=======================================================================
123 bool SMESHDS_GroupBase::IsEmpty()
125 SMDS_ElemIteratorPtr it = GetElements();
126 return ( !it || !it->more() );
129 //=======================================================================
130 //function : Contains
132 //=======================================================================
134 bool SMESHDS_GroupBase::Contains (const int theID)
136 if ( SMDS_ElemIteratorPtr it = GetElements() ) {
138 if ( it->next()->GetID() == theID )
144 //=======================================================================
145 //function : Contains
147 //=======================================================================
149 bool SMESHDS_GroupBase::Contains (const SMDS_MeshElement* elem)
152 return Contains( elem->GetID() );
156 //=======================================================================
159 //=======================================================================
161 void SMESHDS_GroupBase::SetType(SMDSAbs_ElementType theType)
166 //=======================================================================
169 //=======================================================================
171 void SMESHDS_GroupBase::SetColorGroup(int theColorGroup)
173 int aRed = ( theColorGroup/1000000 );
174 int aGreen = ( theColorGroup -aRed*1000000)/1000;
175 int aBlue = ( theColorGroup - aRed*1000000 - aGreen*1000 );
176 double aR = aRed/255.0;
177 double aG = aGreen/255.0;
178 double aB = aBlue/255.0;
179 if ( aR < 0. || aR > 1. || // PAL19395
180 aG < 0. || aG > 1. ||
183 // cout << "SMESHDS_GroupBase::SetColorGroup("<<theColorGroup<<"), invalid color ignored"<<endl;
186 Quantity_Color aColor( aR, aG, aB, Quantity_TOC_RGB );
190 //=======================================================================
193 //=======================================================================
195 int SMESHDS_GroupBase::GetColorGroup() const
197 Quantity_Color aColor = GetColor();
198 double aRed = aColor.Red();
199 double aGreen = aColor.Green();
200 double aBlue = aColor.Blue();
201 int aR = int( aRed *255 );
202 int aG = int( aGreen*255 );
203 int aB = int( aBlue *255 );
204 int aRet = (int)(aR*1000000 + aG*1000 + aB);