Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/smesh.git] / src / SMESHDS / SMESHDS_SubMesh.cxx
1 //  SMESH SMESHDS : management of mesh data and SMESH document
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESH_SubMesh.cxx
25 //  Author : Yves FRICAUD, OCC
26 //  Module : SMESH
27 //  $Header: 
28
29 using namespace std;
30 #include "SMESHDS_SubMesh.hxx"
31
32 //=======================================================================
33 //function : AddElement
34 //purpose  : 
35 //=======================================================================
36 void SMESHDS_SubMesh::AddElement(const SMDS_MeshElement * ME)
37 {
38         myElements.insert(ME);
39 }
40
41 //=======================================================================
42 //function : RemoveElement
43 //purpose  : 
44 //=======================================================================
45 bool SMESHDS_SubMesh::RemoveElement(const SMDS_MeshElement * ME)
46 {
47   if ( NbElements() )
48     return myElements.erase(ME);
49   
50   return false;
51 }
52
53 //=======================================================================
54 //function : AddNode
55 //purpose  : 
56 //=======================================================================
57 void SMESHDS_SubMesh::AddNode(const SMDS_MeshNode * N)
58 {
59         myNodes.insert(N);
60 }
61
62 //=======================================================================
63 //function : RemoveNode
64 //purpose  : 
65 //=======================================================================
66 bool SMESHDS_SubMesh::RemoveNode(const SMDS_MeshNode * N)
67 {
68   if ( NbNodes() )
69     return myNodes.erase(N);
70
71   return false;
72 }
73
74 //=======================================================================
75 //function : NbElements
76 //purpose  : 
77 //=======================================================================
78 int SMESHDS_SubMesh::NbElements() const
79 {
80         return myElements.size();
81 }
82
83 //=======================================================================
84 //function : NbNodes
85 //purpose  : 
86 //=======================================================================
87 int SMESHDS_SubMesh::NbNodes() const
88 {
89         return myNodes.size();
90 }
91
92 template<typename T> class MySetIterator:public SMDS_Iterator<const T*>
93 {
94   typedef const set<const T*> TSet;
95   typename TSet::const_iterator myIt;
96   TSet& mySet;
97
98   public:
99         MySetIterator(const set<const T*>& s):mySet(s), myIt(s.begin())
100         {
101         }
102
103         bool more()
104         {
105                 return myIt!=mySet.end();
106         }
107         const T* next()
108         {
109                 const T* t=*myIt;
110                 myIt++;
111                 return t;                       
112         }
113 };
114 ///////////////////////////////////////////////////////////////////////////////
115 ///Return an iterator on the elements of submesh
116 ///The created iterator must be free by the caller
117 ///////////////////////////////////////////////////////////////////////////////
118 SMDS_ElemIteratorPtr SMESHDS_SubMesh::GetElements() const
119 {
120   return SMDS_ElemIteratorPtr(new MySetIterator<SMDS_MeshElement>(myElements));
121 }
122
123 ///////////////////////////////////////////////////////////////////////////////
124 ///Return an iterator on the nodes of submesh
125 ///The created iterator must be free by the caller
126 ///////////////////////////////////////////////////////////////////////////////
127 SMDS_NodeIteratorPtr SMESHDS_SubMesh::GetNodes() const
128 {
129   return SMDS_NodeIteratorPtr(new MySetIterator<SMDS_MeshNode>(myNodes));
130 }
131