Salome HOME
0020210: EDF SMESH 976: Update of a smesh group after modification of the associated...
[modules/smesh.git] / src / SMESHDS / SMESHDS_GroupOnGeom.cxx
1 //  Copyright (C) 2007-2008  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 //  SMESH SMESHDS : idl implementation based on 'SMESH' unit's classes
23 //  File   : SMESHDS_GroupOnGeom.cxx
24 //  Module : SMESH
25 //
26 #include "SMESHDS_GroupOnGeom.hxx"
27 #include "SMESHDS_Mesh.hxx"
28 #include "utilities.h"
29
30 using namespace std;
31
32 //=============================================================================
33 /*!
34  *  
35  */
36 //=============================================================================
37
38 SMESHDS_GroupOnGeom::SMESHDS_GroupOnGeom (const int                 theID,
39                                           const SMESHDS_Mesh*       theMesh,
40                                           const SMDSAbs_ElementType theType,
41                                           const TopoDS_Shape&       theShape)
42      : SMESHDS_GroupBase(theID,theMesh,theType)
43 {
44   SetShape( theShape );
45 }
46
47 void SMESHDS_GroupOnGeom::SetShape( const TopoDS_Shape& theShape)
48 {
49   SMESHDS_Mesh* aMesh = const_cast<SMESHDS_Mesh*>( GetMesh() );
50   mySubMesh = aMesh->MeshElements( aMesh->AddCompoundSubmesh( theShape ));
51   myShape   = theShape;
52 }
53
54 // =====================
55 // class MyGroupIterator
56 // =====================
57
58 class MyIterator: public SMDS_ElemIterator
59 {
60   SMDSAbs_ElementType     myType;
61   SMDS_ElemIteratorPtr    myElemIt;
62   SMDS_NodeIteratorPtr    myNodeIt;
63   const SMDS_MeshElement* myElem;
64  public:
65   MyIterator(SMDSAbs_ElementType type, const SMESHDS_SubMesh* subMesh)
66     : myType(type), myElem(0)
67   {
68     if ( subMesh ) 
69       if ( myType == SMDSAbs_Node )
70         myNodeIt = subMesh->GetNodes();
71       else {
72         myElemIt = subMesh->GetElements();
73         next();
74       }
75   }
76   bool more()
77   {
78     if ( myType == SMDSAbs_Node && myNodeIt )
79       return myNodeIt->more();
80     return ( myElem != 0 );
81   }
82   const SMDS_MeshElement* next()
83   {
84     if ( myType == SMDSAbs_Node && myNodeIt )
85       return myNodeIt->next();
86     const SMDS_MeshElement* res = myElem;
87     myElem = 0;
88     while ( myElemIt && myElemIt->more() ) {
89       myElem = myElemIt->next();
90       if ( myElem && myElem->GetType() == myType )
91         break;
92       else
93         myElem = 0;
94     }
95     return res;
96   }
97 };
98
99 //=======================================================================
100 //function : GetElements
101 //purpose  : 
102 //=======================================================================
103
104 SMDS_ElemIteratorPtr SMESHDS_GroupOnGeom::GetElements()
105 {
106   return SMDS_ElemIteratorPtr( new MyIterator ( GetType(), mySubMesh ));
107 }
108
109 //=======================================================================
110 //function : Contains
111 //purpose  : 
112 //=======================================================================
113
114 bool SMESHDS_GroupOnGeom::Contains (const int theID)
115 {
116   return mySubMesh->Contains( findInMesh( theID ));
117 }
118
119 //=======================================================================
120 //function : Contains
121 //purpose  : 
122 //=======================================================================
123
124 bool SMESHDS_GroupOnGeom::Contains (const SMDS_MeshElement* elem)
125 {
126   return mySubMesh->Contains( elem );
127 }
128