smesh/src/SMESHDS/SMESHDS_GroupBase.cxx

209 lines
6.1 KiB
C++
Raw Normal View History

2014-02-20 18:25:37 +06:00
// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
2009-02-17 10:27:49 +05:00
//
2012-08-09 16:03:55 +06:00
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
2004-12-01 15:48:31 +05:00
//
2012-08-09 16:03:55 +06:00
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
2014-02-20 18:25:37 +06:00
// version 2.1 of the License, or (at your option) any later version.
2004-12-01 15:48:31 +05:00
//
2012-08-09 16:03:55 +06:00
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
2004-12-01 15:48:31 +05:00
//
2012-08-09 16:03:55 +06:00
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2004-12-01 15:48:31 +05:00
//
2012-08-09 16:03:55 +06:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2009-02-17 10:27:49 +05:00
//
2012-08-09 16:03:55 +06:00
2009-02-17 10:27:49 +05:00
// SMESH SMESHDS : idl implementation based on 'SMESH' unit's classes
2004-12-01 15:48:31 +05:00
// File : SMESHDS_Group.cxx
// Module : SMESH
// $Header$
2009-02-17 10:27:49 +05:00
//
2004-12-01 15:48:31 +05:00
#include "SMESHDS_GroupBase.hxx"
#include "SMESHDS_Mesh.hxx"
#include "utilities.h"
using namespace std;
//=============================================================================
/*!
*
*/
//=============================================================================
SMESHDS_GroupBase::SMESHDS_GroupBase (const int theID,
const SMESHDS_Mesh* theMesh,
const SMDSAbs_ElementType theType):
myID(theID), myMesh(theMesh), myType(theType), myStoreName(""),
2005-02-07 18:51:15 +05:00
myCurIndex(0), myCurID(-1)
2004-12-01 15:48:31 +05:00
{
myColor = Quantity_Color( 0.0, 0.0, 0.0, Quantity_TOC_RGB );
2004-12-01 15:48:31 +05:00
}
//=============================================================================
/*!
*
*/
//=============================================================================
int SMESHDS_GroupBase::GetID (const int theIndex)
{
if (myCurIndex < 1 || myCurIndex > theIndex) {
myIterator = GetElements();
myCurIndex = 0;
myCurID = -1;
}
while (myCurIndex < theIndex && myIterator->more()) {
myCurIndex++;
myCurID = myIterator->next()->GetID();
}
return myCurIndex == theIndex ? myCurID : -1;
}
//=============================================================================
/*!
*
*/
//=============================================================================
const SMDS_MeshElement* SMESHDS_GroupBase::findInMesh (const int theID) const
{
SMDSAbs_ElementType aType = GetType();
const SMDS_MeshElement* aElem = NULL;
if (aType == SMDSAbs_Node) {
aElem = GetMesh()->FindNode(theID);
}
else if (aType != SMDSAbs_All) {
aElem = GetMesh()->FindElement(theID);
if (aElem && aType != aElem->GetType())
aElem = NULL;
}
return aElem;
}
2005-02-07 18:51:15 +05:00
//=============================================================================
/*!
* 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;
}
2004-12-01 15:48:31 +05:00
//=======================================================================
//function : Extent
//purpose :
//=======================================================================
2012-08-09 16:03:55 +06:00
int SMESHDS_GroupBase::Extent() const
2004-12-01 15:48:31 +05:00
{
SMDS_ElemIteratorPtr it = GetElements();
int nb = 0;
if ( it )
for ( ; it->more(); it->next() )
nb++;
return nb;
}
//=======================================================================
//function : IsEmpty
//purpose :
//=======================================================================
bool SMESHDS_GroupBase::IsEmpty()
{
SMDS_ElemIteratorPtr it = GetElements();
return ( !it || !it->more() );
}
//=======================================================================
//function : Contains
//purpose :
//=======================================================================
bool SMESHDS_GroupBase::Contains (const int theID)
{
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;
2004-12-01 15:48:31 +05:00
}
//=======================================================================
//function : SetType
//purpose :
//=======================================================================
void SMESHDS_GroupBase::SetType(SMDSAbs_ElementType theType)
{
myType = theType;
}
//=======================================================================
//function : SetType
//purpose :
//=======================================================================
void SMESHDS_GroupBase::SetColorGroup(int theColorGroup)
{
2009-02-17 10:27:49 +05:00
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;
2009-02-17 10:27:49 +05:00
Quantity_Color aColor( aR, aG, aB, Quantity_TOC_RGB );
SetColor( aColor );
}
//=======================================================================
//function : SetType
//purpose :
//=======================================================================
int SMESHDS_GroupBase::GetColorGroup() const
{
Quantity_Color aColor = GetColor();
2009-02-17 10:27:49 +05:00
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;
}