Back to index

salome-smesh  6.5.0
SMESHDS_GroupBase.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SMESH SMESHDS : idl implementation based on 'SMESH' unit's classes
00024 //  File   : SMESHDS_Group.cxx
00025 //  Module : SMESH
00026 //  $Header: /home/server/cvs/SMESH/SMESH_SRC/src/SMESHDS/SMESHDS_GroupBase.cxx,v 1.8.20.3.8.1 2012-04-13 09:31:09 vsr Exp $
00027 //
00028 #include "SMESHDS_GroupBase.hxx"
00029 #include "SMESHDS_Mesh.hxx"
00030 
00031 #include "utilities.h"
00032 
00033 using namespace std;
00034 
00035 //=============================================================================
00039 //=============================================================================
00040 
00041 SMESHDS_GroupBase::SMESHDS_GroupBase (const int                 theID,
00042                                       const SMESHDS_Mesh*       theMesh,
00043                                       const SMDSAbs_ElementType theType):
00044        myID(theID), myMesh(theMesh), myType(theType), myStoreName(""),
00045        myCurIndex(0), myCurID(-1)
00046 {
00047   myColor = Quantity_Color( 0.0, 0.0, 0.0, Quantity_TOC_RGB );
00048 }
00049 
00050 //=============================================================================
00054 //=============================================================================
00055 
00056 int SMESHDS_GroupBase::GetID (const int theIndex)
00057 {
00058   if (myCurIndex < 1 || myCurIndex > theIndex) {
00059     myIterator = GetElements();
00060     myCurIndex = 0;
00061     myCurID = -1;
00062   }
00063   while (myCurIndex < theIndex && myIterator->more()) {
00064     myCurIndex++;
00065     myCurID = myIterator->next()->GetID();
00066   }
00067   return myCurIndex == theIndex ? myCurID : -1;
00068 }
00069 
00070 //=============================================================================
00074 //=============================================================================
00075 
00076 const SMDS_MeshElement* SMESHDS_GroupBase::findInMesh (const int theID) const
00077 {
00078   SMDSAbs_ElementType aType = GetType();
00079   const SMDS_MeshElement* aElem = NULL;
00080   if (aType == SMDSAbs_Node) {
00081     aElem = GetMesh()->FindNode(theID);
00082   }
00083   else if (aType != SMDSAbs_All) {
00084     aElem = GetMesh()->FindElement(theID);
00085     if (aElem && aType != aElem->GetType())
00086       aElem = NULL;
00087   }
00088   return aElem;
00089 }
00090 
00091 //=============================================================================
00096 //=============================================================================
00097 void SMESHDS_GroupBase::resetIterator()
00098 {
00099   myCurIndex = 0;
00100   myCurID = -1;
00101 }
00102 
00103 //=======================================================================
00104 //function : Extent
00105 //purpose  : 
00106 //=======================================================================
00107 
00108 int SMESHDS_GroupBase::Extent() const
00109 {
00110   SMDS_ElemIteratorPtr it = GetElements();
00111   int nb = 0;
00112   if ( it )
00113     for ( ; it->more(); it->next() ) 
00114       nb++;
00115   return nb;
00116 }
00117 
00118 //=======================================================================
00119 //function : IsEmpty
00120 //purpose  : 
00121 //=======================================================================
00122 
00123 bool SMESHDS_GroupBase::IsEmpty()
00124 {
00125   SMDS_ElemIteratorPtr it = GetElements();
00126   return ( !it || !it->more() );
00127 }
00128 
00129 //=======================================================================
00130 //function : Contains
00131 //purpose  : 
00132 //=======================================================================
00133 
00134 bool SMESHDS_GroupBase::Contains (const int theID)
00135 {
00136   if ( SMDS_ElemIteratorPtr it = GetElements() ) {
00137     while ( it->more() )
00138       if ( it->next()->GetID() == theID )
00139         return true;
00140   }
00141   return false;
00142 }
00143 
00144 //=======================================================================
00145 //function : Contains
00146 //purpose  : 
00147 //=======================================================================
00148 
00149 bool SMESHDS_GroupBase::Contains (const SMDS_MeshElement* elem)
00150 {
00151   if ( elem )
00152     return Contains( elem->GetID() );
00153   return false;
00154 }
00155 
00156 //=======================================================================
00157 //function : SetType
00158 //purpose  : 
00159 //=======================================================================
00160 
00161 void SMESHDS_GroupBase::SetType(SMDSAbs_ElementType theType)
00162 {
00163   myType = theType;
00164 }
00165 
00166 //=======================================================================
00167 //function : SetType
00168 //purpose  : 
00169 //=======================================================================
00170 
00171 void SMESHDS_GroupBase::SetColorGroup(int theColorGroup)
00172 {
00173   int aRed = ( theColorGroup/1000000 );
00174   int aGreen = ( theColorGroup -aRed*1000000)/1000;
00175   int aBlue = ( theColorGroup - aRed*1000000 - aGreen*1000 );
00176   double aR = aRed/255.0;
00177   double aG = aGreen/255.0;
00178   double aB = aBlue/255.0;
00179   if ( aR < 0. || aR > 1. || // PAL19395
00180        aG < 0. || aG > 1. ||
00181        aB < 0. || aB > 1. )
00182 // #ifdef _DEBUG_
00183 //     cout << "SMESHDS_GroupBase::SetColorGroup("<<theColorGroup<<"), invalid color ignored"<<endl;
00184 // #endif
00185     return;
00186   Quantity_Color aColor( aR, aG, aB, Quantity_TOC_RGB );
00187   SetColor( aColor );
00188 }
00189   
00190 //=======================================================================
00191 //function : SetType
00192 //purpose  : 
00193 //=======================================================================
00194 
00195 int SMESHDS_GroupBase::GetColorGroup() const
00196 {
00197   Quantity_Color aColor = GetColor();
00198   double aRed = aColor.Red();
00199   double aGreen = aColor.Green();
00200   double aBlue = aColor.Blue();
00201   int aR = int( aRed  *255 );
00202   int aG = int( aGreen*255 );
00203   int aB = int( aBlue *255 );
00204   int aRet = (int)(aR*1000000 + aG*1000 + aB);
00205 
00206   return aRet;
00207 }
00208