Salome HOME
Merge from V6_5_BR 05/06/2012
[modules/smesh.git] / src / SMESHDS / SMESHDS_Document.cxx
1 // Copyright (C) 2007-2012  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 : management of mesh data and SMESH document
24 //  File   : SMESHDS_Document.cxx
25 //  Author : Yves FRICAUD, OCC
26 //  Module : SMESH
27 //  $Header: 
28 //
29 #include "SMESHDS_Document.hxx"
30 #include "utilities.h"
31
32 using namespace std;
33
34 //=======================================================================
35 //function : Create
36 //purpose  : 
37 //=======================================================================
38 SMESHDS_Document::SMESHDS_Document(int UserID):myUserID(UserID)
39 {
40 }
41
42 //=======================================================================
43 //function : Destructor
44 //purpose  : 
45 //=======================================================================
46
47 SMESHDS_Document::~SMESHDS_Document()
48 {
49   InitMeshesIterator();
50   while ( MoreMesh() )
51     delete NextMesh();
52 }
53
54 //=======================================================================
55 //function : NewMesh
56 //purpose  : 
57 //=======================================================================
58 int SMESHDS_Document::NewMesh(bool theIsEmbeddedMode)
59 {
60   static int aNewMeshID = 0;
61   aNewMeshID++;
62   SMESHDS_Mesh *aNewMesh = new SMESHDS_Mesh(aNewMeshID,theIsEmbeddedMode);
63   myMeshes[aNewMeshID] = aNewMesh;
64   return aNewMeshID;
65 }
66
67 //=======================================================================
68 //function : GetMesh
69 //purpose  : 
70 //=======================================================================
71 SMESHDS_Mesh *SMESHDS_Document::GetMesh(int MeshID)
72 {
73         map<int,SMESHDS_Mesh*>::iterator it=myMeshes.find(MeshID);
74         if (it==myMeshes.end())
75         {
76                 MESSAGE("SMESHDS_Document::GetMesh : ID not found");
77                 return NULL;
78         }
79         else return (*it).second;
80 }
81
82 //=======================================================================
83 //function : RemoveMesh
84 //purpose  : 
85 //=======================================================================
86 void SMESHDS_Document::RemoveMesh(int MeshID)
87 {
88   map<int,SMESHDS_Mesh*>::iterator it=myMeshes.find(MeshID);
89   if (it!=myMeshes.end())
90     myMeshes.erase(it);
91 }
92
93 //=======================================================================
94 //function : AddHypothesis
95 //purpose  : 
96 //=======================================================================
97 void SMESHDS_Document::AddHypothesis(SMESHDS_Hypothesis * H)
98 {
99   myHypothesis[H->GetID()]=H;
100 }
101
102 //=======================================================================
103 //function : GetHypothesis
104 //purpose  : 
105 //=======================================================================
106 SMESHDS_Hypothesis * SMESHDS_Document::GetHypothesis(int HypID)
107 {
108         map<int,SMESHDS_Hypothesis*>::iterator it=myHypothesis.find(HypID);
109         if (it==myHypothesis.end())
110         {
111                 MESSAGE("SMESHDS_Document::GetHypothesis : ID not found");
112                 return NULL;
113         }
114         else return (*it).second;
115 }
116
117 //=======================================================================
118 //function : RemoveHypothesis
119 //purpose  : 
120 //=======================================================================
121 void SMESHDS_Document::RemoveHypothesis(int HypID)
122 {
123         map<int,SMESHDS_Hypothesis*>::iterator it=myHypothesis.find(HypID);
124         if (it==myHypothesis.end())
125                 MESSAGE("SMESHDS_Document::RemoveHypothesis : ID not found");   
126         myHypothesis.erase(it);
127 }
128
129 //=======================================================================
130 //function : NbMeshes
131 //purpose  : 
132 //=======================================================================
133 int SMESHDS_Document::NbMeshes()
134 {
135         return myMeshes.size();
136 }
137
138 //=======================================================================
139 //function : NbHypothesis
140 //purpose  : 
141 //=======================================================================
142 int SMESHDS_Document::NbHypothesis()
143 {
144         return myHypothesis.size();
145 }
146
147 //=======================================================================
148 //function : InitMeshesIterator
149 //purpose  : 
150 //=======================================================================
151 void SMESHDS_Document::InitMeshesIterator()
152 {
153         myMeshesIt=myMeshes.begin();
154 }
155
156 //=======================================================================
157 //function : NextMesh
158 //purpose  : 
159 //=======================================================================
160 SMESHDS_Mesh * SMESHDS_Document::NextMesh()
161 {
162         SMESHDS_Mesh * toReturn=(*myMeshesIt).second;
163         myMeshesIt++;
164         return toReturn;
165 }
166
167 //=======================================================================
168 //function : MoreMesh
169 //purpose  : 
170 //=======================================================================
171 bool SMESHDS_Document::MoreMesh()
172 {
173         return myMeshesIt!=myMeshes.end();
174 }
175
176 //=======================================================================
177 //function : InitHypothesisIterator
178 //purpose  : 
179 //=======================================================================
180 void SMESHDS_Document::InitHypothesisIterator()
181 {
182         myHypothesisIt=myHypothesis.begin();
183 }
184
185 //=======================================================================
186 //function : NextMesh
187 //purpose  : 
188 //=======================================================================
189 SMESHDS_Hypothesis * SMESHDS_Document::NextHypothesis()
190 {
191         SMESHDS_Hypothesis * toReturn=(*myHypothesisIt).second;
192         myHypothesisIt++;
193         return toReturn;
194 }
195
196 //=======================================================================
197 //function : MoreMesh
198 //purpose  : 
199 //=======================================================================
200 bool SMESHDS_Document::MoreHypothesis()
201 {
202         return myHypothesisIt!=myHypothesis.end();
203 }