Salome HOME
Add support for tetra, pyramid and prism
[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 void SMESHDS_SubMesh::RemoveElement(const SMDS_MeshElement * ME)
46 {
47         myElements.erase(ME);
48 }
49
50 //=======================================================================
51 //function : AddNode
52 //purpose  : 
53 //=======================================================================
54 void SMESHDS_SubMesh::AddNode(const SMDS_MeshNode * N)
55 {
56         myNodes.insert(N);
57 }
58
59 //=======================================================================
60 //function : RemoveNode
61 //purpose  : 
62 //=======================================================================
63 void SMESHDS_SubMesh::RemoveNode(const SMDS_MeshNode * N)
64 {
65         myNodes.erase(N);
66 }
67
68 //=======================================================================
69 //function : NbElements
70 //purpose  : 
71 //=======================================================================
72 int SMESHDS_SubMesh::NbElements() const
73 {
74         return myElements.size();
75 }
76
77 //=======================================================================
78 //function : NbNodes
79 //purpose  : 
80 //=======================================================================
81 int SMESHDS_SubMesh::NbNodes() const
82 {
83         return myNodes.size();
84 }
85
86 template<typename T> class MySetIterator:public SMDS_Iterator<const T*>
87 {
88         const set<const T*>& mySet;
89         set<const T*>::const_iterator myIt;
90
91   public:
92         MySetIterator(const set<const T*>& s):mySet(s), myIt(s.begin())
93         {
94         }
95
96         bool more()
97         {
98                 return myIt!=mySet.end();
99         }
100         const T* next()
101         {
102                 const T* t=*myIt;
103                 myIt++;
104                 return t;                       
105         }
106 };
107 ///////////////////////////////////////////////////////////////////////////////
108 ///Return an iterator on the elements of submesh
109 ///The created iterator must be free by the caller
110 ///////////////////////////////////////////////////////////////////////////////
111 SMDS_Iterator<const SMDS_MeshElement*> * SMESHDS_SubMesh::GetElements() const
112 {
113         return new MySetIterator<SMDS_MeshElement>(myElements);
114 }
115
116 ///////////////////////////////////////////////////////////////////////////////
117 ///Return an iterator on the nodes of submesh
118 ///The created iterator must be free by the caller
119 ///////////////////////////////////////////////////////////////////////////////
120 SMDS_Iterator<const SMDS_MeshNode*> * SMESHDS_SubMesh::GetNodes() const
121 {
122         return new MySetIterator<SMDS_MeshNode>(myNodes);
123 }
124