1 // Copyright (C) 2007-2022 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 Quantity_Color SMESHDS_GroupBase::myDefaultColor = Quantity_Color( 0.0, 0.0, 0.0, Quantity_TOC_RGB );
37 //=============================================================================
41 //=============================================================================
43 SMESHDS_GroupBase::SMESHDS_GroupBase (const int theID,
44 const SMESHDS_Mesh* theMesh,
45 const SMDSAbs_ElementType theType):
46 myID(theID), myMesh(theMesh), myType(theType), myStoreName(""),
47 myCurIndex(0), myCurID(-1)
49 myColor = myDefaultColor;
52 //=============================================================================
56 //=============================================================================
58 smIdType SMESHDS_GroupBase::GetID (const int theIndex)
60 if (myCurIndex < 1 || myCurIndex > theIndex) {
61 myIterator = GetElements();
65 while (myCurIndex < theIndex && myIterator->more()) {
67 myCurID = myIterator->next()->GetID();
69 return myCurIndex == theIndex ? myCurID : -1;
72 //=============================================================================
76 //=============================================================================
78 const SMDS_MeshElement* SMESHDS_GroupBase::findInMesh (const smIdType theID) const
80 SMDSAbs_ElementType aType = GetType();
81 const SMDS_MeshElement* aElem = NULL;
82 if (aType == SMDSAbs_Node) {
83 aElem = GetMesh()->FindNode(theID);
85 else if (aType != SMDSAbs_All) {
86 aElem = GetMesh()->FindElement(theID);
87 if (aElem && aType != aElem->GetType())
93 //=============================================================================
95 * Internal method: resets cached iterator, should be called by ancestors
96 * when they are modified (ex: Add() or Remove() )
98 //=============================================================================
99 void SMESHDS_GroupBase::resetIterator()
105 //=======================================================================
108 //=======================================================================
110 smIdType SMESHDS_GroupBase::Extent() const
112 SMDS_ElemIteratorPtr it = GetElements();
115 for ( ; it->more(); it->next() )
120 //=======================================================================
123 //=======================================================================
125 bool SMESHDS_GroupBase::IsEmpty()
127 if ( myMesh->GetMeshInfo().NbElements( myType ) == 0 )
128 // avoid long iteration over sub-meshes of a complex sub-mesh of a group on geometry
130 SMDS_ElemIteratorPtr it = GetElements();
131 return ( !it || !it->more() );
134 //=======================================================================
135 //function : Contains
137 //=======================================================================
139 bool SMESHDS_GroupBase::Contains (const smIdType theID)
141 if ( SMDS_ElemIteratorPtr it = GetElements() ) {
143 if ( it->next()->GetID() == theID )
149 //=======================================================================
150 //function : Contains
152 //=======================================================================
154 bool SMESHDS_GroupBase::Contains (const SMDS_MeshElement* elem)
157 return Contains( elem->GetID() );
161 //=======================================================================
164 //=======================================================================
166 void SMESHDS_GroupBase::SetType(SMDSAbs_ElementType theType)
171 //=======================================================================
174 //=======================================================================
176 void SMESHDS_GroupBase::SetColorGroup(int theColorGroup)
178 int aRed = ( theColorGroup/1000000 );
179 int aGreen = ( theColorGroup -aRed*1000000)/1000;
180 int aBlue = ( theColorGroup - aRed*1000000 - aGreen*1000 );
181 double aR = aRed/255.0;
182 double aG = aGreen/255.0;
183 double aB = aBlue/255.0;
184 if ( aR < 0. || aR > 1. || // PAL19395
185 aG < 0. || aG > 1. ||
188 // cout << "SMESHDS_GroupBase::SetColorGroup("<<theColorGroup<<"), invalid color ignored"<<endl;
191 Quantity_Color aColor( aR, aG, aB, Quantity_TOC_RGB );
195 //=======================================================================
198 //=======================================================================
200 int SMESHDS_GroupBase::GetColorGroup() const
202 Quantity_Color aColor = GetColor();
203 double aRed = aColor.Red();
204 double aGreen = aColor.Green();
205 double aBlue = aColor.Blue();
206 int aR = int( aRed *255 );
207 int aG = int( aGreen*255 );
208 int aB = int( aBlue *255 );
209 int aRet = (int)(aR*1000000 + aG*1000 + aB);