Salome HOME
Dump Python extension
[modules/smesh.git] / src / SMESHDS / SMESHDS_GroupBase.cxx
index c3fc31d7017c8df8c942e5fd963687665910caba..f21b6df54bca97f4fccbec4b3b63164b4e572823 100644 (file)
@@ -16,7 +16,7 @@
 //  License along with this library; if not, write to the Free Software 
 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
 // 
-//  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org 
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //
 //
@@ -41,8 +41,9 @@ SMESHDS_GroupBase::SMESHDS_GroupBase (const int                 theID,
                                       const SMESHDS_Mesh*       theMesh,
                                       const SMDSAbs_ElementType theType):
        myID(theID), myMesh(theMesh), myType(theType), myStoreName(""),
-       myCurIndex(0), myCurID(0)
+       myCurIndex(0), myCurID(-1)
 {
+  myColor = Quantity_Color( 0.0, 0.0, 0.0, Quantity_TOC_RGB );
 }
 
 //=============================================================================
@@ -86,6 +87,18 @@ const SMDS_MeshElement* SMESHDS_GroupBase::findInMesh (const int theID) const
   return aElem;
 }
 
+//=============================================================================
+/*!
+ *  Internal method: resets cached iterator, should be called by ancestors
+ *  when they are modified (ex: Add() or Remove() )
+ */
+//=============================================================================
+void SMESHDS_GroupBase::resetIterator()
+{
+  myCurIndex = 0;
+  myCurID = -1;
+}
+
 //=======================================================================
 //function : Extent
 //purpose  : 
@@ -119,12 +132,24 @@ bool SMESHDS_GroupBase::IsEmpty()
 
 bool SMESHDS_GroupBase::Contains (const int theID)
 {
-  SMDS_ElemIteratorPtr it = GetElements();
-  bool contains = false;
-  if ( it )
-    while ( !contains && it->more() )
-      contains = ( it->next()->GetID() == theID );
-  return contains;
+  if ( SMDS_ElemIteratorPtr it = GetElements() ) {
+    while ( it->more() )
+      if ( it->next()->GetID() == theID )
+        return true;
+  }
+  return false;
+}
+
+//=======================================================================
+//function : Contains
+//purpose  : 
+//=======================================================================
+
+bool SMESHDS_GroupBase::Contains (const SMDS_MeshElement* elem)
+{
+  if ( elem )
+    return Contains( elem->GetID() );
+  return false;
 }
 
 //=======================================================================
@@ -136,3 +161,47 @@ void SMESHDS_GroupBase::SetType(SMDSAbs_ElementType theType)
 {
   myType = theType;
 }
+
+//=======================================================================
+//function : SetType
+//purpose  : 
+//=======================================================================
+
+void SMESHDS_GroupBase::SetColorGroup(int theColorGroup)
+{
+  int aRed = ( theColorGroup/1000000 );
+  int aGreen = ( theColorGroup -aRed*1000000)/1000;
+  int aBlue = ( theColorGroup - aRed*1000000 - aGreen*1000 );
+  double aR = aRed/255.0;
+  double aG = aGreen/255.0;
+  double aB = aBlue/255.0;
+  if ( aR < 0. || aR > 1. || // PAL19395
+       aG < 0. || aG > 1. ||
+       aB < 0. || aB > 1. )
+// #ifdef _DEBUG_
+//     cout << "SMESHDS_GroupBase::SetColorGroup("<<theColorGroup<<"), invalid color ignored"<<endl;
+// #endif
+    return;
+  Quantity_Color aColor( aR, aG, aB, Quantity_TOC_RGB );
+  SetColor( aColor );
+}
+  
+//=======================================================================
+//function : SetType
+//purpose  : 
+//=======================================================================
+
+int SMESHDS_GroupBase::GetColorGroup() const
+{
+  Quantity_Color aColor = GetColor();
+  double aRed = aColor.Red();
+  double aGreen = aColor.Green();
+  double aBlue = aColor.Blue();
+  int aR = int( aRed  *255 );
+  int aG = int( aGreen*255 );
+  int aB = int( aBlue *255 );
+  int aRet = (int)(aR*1000000 + aG*1000 + aB);
+
+  return aRet;
+}
+