Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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
00105
00106
00107
00108 int SMESHDS_GroupBase::Extent()
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
00120
00121
00122
00123 bool SMESHDS_GroupBase::IsEmpty()
00124 {
00125 SMDS_ElemIteratorPtr it = GetElements();
00126 return ( !it || !it->more() );
00127 }
00128
00129
00130
00131
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
00146
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
00158
00159
00160
00161 void SMESHDS_GroupBase::SetType(SMDSAbs_ElementType theType)
00162 {
00163 myType = theType;
00164 }
00165
00166
00167
00168
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. ||
00180 aG < 0. || aG > 1. ||
00181 aB < 0. || aB > 1. )
00182
00183
00184
00185 return;
00186 Quantity_Color aColor( aR, aG, aB, Quantity_TOC_RGB );
00187 SetColor( aColor );
00188 }
00189
00190
00191
00192
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