Salome HOME
Merge from V5_1_4_BR 07/05/2010
[modules/smesh.git] / src / SMESHDS / SMESHDS_GroupOnGeom.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH SMESHDS : idl implementation based on 'SMESH' unit's classes
24 //  File   : SMESHDS_GroupOnGeom.cxx
25 //  Module : SMESH
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)
44 {
45   SetShape( theShape );
46 }
47
48 void SMESHDS_GroupOnGeom::SetShape( const TopoDS_Shape& theShape)
49 {
50   SMESHDS_Mesh* aMesh = const_cast<SMESHDS_Mesh*>( GetMesh() );
51   mySubMesh = aMesh->MeshElements( aMesh->AddCompoundSubmesh( theShape ));
52   myShape   = theShape;
53 }
54
55 // =====================
56 // class MyGroupIterator
57 // =====================
58
59 class MyIterator: public SMDS_ElemIterator
60 {
61   SMDSAbs_ElementType     myType;
62   SMDS_ElemIteratorPtr    myElemIt;
63   SMDS_NodeIteratorPtr    myNodeIt;
64   const SMDS_MeshElement* myElem;
65  public:
66   MyIterator(SMDSAbs_ElementType type, const SMESHDS_SubMesh* subMesh)
67     : myType(type), myElem(0)
68   {
69     if ( subMesh ) 
70       if ( myType == SMDSAbs_Node )
71         myNodeIt = subMesh->GetNodes();
72       else {
73         myElemIt = subMesh->GetElements();
74         next();
75       }
76   }
77   bool more()
78   {
79     if ( myType == SMDSAbs_Node && myNodeIt )
80       return myNodeIt->more();
81     return ( myElem != 0 );
82   }
83   const SMDS_MeshElement* next()
84   {
85     if ( myType == SMDSAbs_Node && myNodeIt )
86       return myNodeIt->next();
87     const SMDS_MeshElement* res = myElem;
88     myElem = 0;
89     while ( myElemIt && myElemIt->more() ) {
90       myElem = myElemIt->next();
91       if ( myElem && myElem->GetType() == myType )
92         break;
93       else
94         myElem = 0;
95     }
96     return res;
97   }
98 };
99
100 //=======================================================================
101 //function : GetElements
102 //purpose  : 
103 //=======================================================================
104
105 SMDS_ElemIteratorPtr SMESHDS_GroupOnGeom::GetElements()
106 {
107   return SMDS_ElemIteratorPtr( new MyIterator ( GetType(), mySubMesh ));
108 }
109
110 //=======================================================================
111 //function : Contains
112 //purpose  : 
113 //=======================================================================
114
115 bool SMESHDS_GroupOnGeom::Contains (const int theID)
116 {
117   return mySubMesh->Contains( findInMesh( theID ));
118 }
119
120 //=======================================================================
121 //function : Contains
122 //purpose  : 
123 //=======================================================================
124
125 bool SMESHDS_GroupOnGeom::Contains (const SMDS_MeshElement* elem)
126 {
127   return mySubMesh->Contains( elem );
128 }
129