Salome HOME
Color Number (Color Group) parameter is returned for compatibility
[modules/smesh.git] / src / SMESHDS / SMESHDS_GroupOnGeom.cxx
1 //  SMESH SMESHDS : idl implementation based on 'SMESH' unit's classes
2 //
3 //  Copyright (C) 2004  CEA
4 // 
5 //  This library is free software; you can redistribute it and/or 
6 //  modify it under the terms of the GNU Lesser General Public 
7 //  License as published by the Free Software Foundation; either 
8 //  version 2.1 of the License. 
9 // 
10 //  This library is distributed in the hope that it will be useful, 
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
13 //  Lesser General Public License for more details. 
14 // 
15 //  You should have received a copy of the GNU Lesser General Public 
16 //  License along with this library; if not, write to the Free Software 
17 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
18 // 
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21 //
22 //
23 //  File   : SMESHDS_GroupOnGeom.cxx
24 //  Module : SMESH
25 //  $Header$
26
27 #include "SMESHDS_GroupOnGeom.hxx"
28 #include "SMESHDS_Mesh.hxx"
29 #include "utilities.h"
30
31 using namespace std;
32
33 //=============================================================================
34 /*!
35  *  
36  */
37 //=============================================================================
38
39 SMESHDS_GroupOnGeom::SMESHDS_GroupOnGeom (const int                 theID,
40                                           const SMESHDS_Mesh*       theMesh,
41                                           const SMDSAbs_ElementType theType,
42                                           const TopoDS_Shape&       theShape)
43      : SMESHDS_GroupBase(theID,theMesh,theType), myShape(theShape)
44 {
45   SMESHDS_Mesh* aMesh = const_cast<SMESHDS_Mesh*>(theMesh);
46   mySubMesh = aMesh->MeshElements( aMesh->AddCompoundSubmesh( theShape ));
47 }
48
49 // =====================
50 // class MyGroupIterator
51 // =====================
52
53 class MyIterator: public SMDS_ElemIterator
54 {
55   SMDSAbs_ElementType     myType;
56   SMDS_ElemIteratorPtr    myElemIt;
57   SMDS_NodeIteratorPtr    myNodeIt;
58   const SMDS_MeshElement* myElem;
59  public:
60   MyIterator(SMDSAbs_ElementType type, const SMESHDS_SubMesh* subMesh)
61     : myType(type), myElem(0)
62   {
63     if ( subMesh ) 
64       if ( myType == SMDSAbs_Node )
65         myNodeIt = subMesh->GetNodes();
66       else {
67         myElemIt = subMesh->GetElements();
68         next();
69       }
70   }
71   bool more()
72   {
73     if ( myType == SMDSAbs_Node && myNodeIt )
74       return myNodeIt->more();
75     return ( myElem != 0 );
76   }
77   const SMDS_MeshElement* next()
78   {
79     if ( myType == SMDSAbs_Node && myNodeIt )
80       return myNodeIt->next();
81     const SMDS_MeshElement* res = myElem;
82     myElem = 0;
83     while ( myElemIt && myElemIt->more() ) {
84       myElem = myElemIt->next();
85       if ( myElem && myElem->GetType() == myType )
86         break;
87       else
88         myElem = 0;
89     }
90     return res;
91   }
92 };
93
94 //=======================================================================
95 //function : GetElements
96 //purpose  : 
97 //=======================================================================
98
99 SMDS_ElemIteratorPtr SMESHDS_GroupOnGeom::GetElements()
100 {
101   return SMDS_ElemIteratorPtr( new MyIterator ( GetType(), mySubMesh ));
102 }
103
104 //=======================================================================
105 //function : Contains
106 //purpose  : 
107 //=======================================================================
108
109 bool SMESHDS_GroupOnGeom::Contains (const int theID)
110 {
111   return mySubMesh->Contains( findInMesh( theID ));
112 }