Salome HOME
yfr : Merge with v1.2
[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.ixx"
31 #include "SMDS_MapIteratorOfExtendedMap.hxx"
32
33 //=======================================================================
34 //function : SMESHDS_SubMesh
35 //purpose  : 
36 //=======================================================================
37 SMESHDS_SubMesh::SMESHDS_SubMesh(const Handle(SMDS_Mesh)& M) : myMesh(M)
38 {
39   myListOfEltIDIsUpdate  = Standard_False;
40   myListOfNodeIDIsUpdate = Standard_False;
41 }
42
43 //=======================================================================
44 //function : AddElement
45 //purpose  : 
46 //=======================================================================
47 void SMESHDS_SubMesh::AddElement (const Handle(SMDS_MeshElement)& ME) 
48 {
49   myElements.Add(ME);
50   myListOfEltIDIsUpdate = Standard_False;
51 }
52
53 //=======================================================================
54 //function : RemoveElement
55 //purpose  : 
56 //=======================================================================
57 void SMESHDS_SubMesh::RemoveElement(const Handle(SMDS_MeshElement)& ME) 
58 {
59   myElements.Remove(ME);
60   myListOfEltIDIsUpdate = Standard_False;
61 }
62 //=======================================================================
63 //function : AddNode
64 //purpose  : 
65 //=======================================================================
66 void SMESHDS_SubMesh::AddNode (const Handle(SMDS_MeshNode)& N) 
67 {
68   myNodes.Add(N);
69   myListOfNodeIDIsUpdate = Standard_False;
70 }
71
72 //=======================================================================
73 //function : RemoveNode
74 //purpose  : 
75 //=======================================================================
76 void SMESHDS_SubMesh::RemoveNode (const Handle(SMDS_MeshNode)& N) 
77 {
78   myNodes.Remove(N);
79   myListOfNodeIDIsUpdate = Standard_False;
80 }
81
82 //=======================================================================
83 //function : NbElements
84 //purpose  : 
85 //=======================================================================
86 Standard_Integer SMESHDS_SubMesh::NbElements() 
87 {
88   return myElements.Extent();
89 }
90
91 //=======================================================================
92 //function : GetElements
93 //purpose  : 
94 //=======================================================================
95 const SMDS_MapOfMeshElement& SMESHDS_SubMesh::GetElements() 
96 {
97   return myElements;
98 }
99 //=======================================================================
100 //function : NbNodes
101 //purpose  : 
102 //=======================================================================
103 Standard_Integer SMESHDS_SubMesh::NbNodes() 
104 {
105   return myNodes.Extent();
106 }
107
108 //=======================================================================
109 //function : GetNodes
110 //purpose  : 
111 //=======================================================================
112 const SMDS_MapOfMeshElement& SMESHDS_SubMesh::GetNodes() 
113 {
114   return myNodes;
115 }
116
117 //=======================================================================
118 //function : GetIDElements
119 //purpose  : 
120 //=======================================================================
121 const TColStd_ListOfInteger& SMESHDS_SubMesh::GetIDElements()
122 {
123   if (!myListOfEltIDIsUpdate) {
124     myListOfEltID.Clear();
125     for (SMDS_MapIteratorOfExtendedMap it(myElements); it.More(); it.Next()) {
126       myListOfEltID.Append(it.Key()->GetID());
127     }
128     myListOfEltIDIsUpdate = Standard_True;
129   }
130   return myListOfEltID;
131 }
132
133 //=======================================================================
134 //function : GetIDNodes
135 //purpose  : 
136 //=======================================================================
137 const TColStd_ListOfInteger& SMESHDS_SubMesh::GetIDNodes()
138 {
139   if (!myListOfNodeIDIsUpdate) {
140     myListOfNodeID.Clear();
141     for (SMDS_MapIteratorOfExtendedMap it(myNodes); it.More(); it.Next()) {
142       myListOfNodeID.Append(it.Key()->GetID());
143     }
144     myListOfNodeIDIsUpdate = Standard_True;
145   }
146   return myListOfNodeID;
147 }