Salome HOME
Merge from V5_1_main 14/05/2010
[modules/smesh.git] / src / SMESHDS / SMESHDS_Document.cxx
1 //  Copyright (C) 2007-2010  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                 MESSAGE("SMESHDS_Document::RemoveMesh : ID not found"); 
91         myMeshes.erase(it);
92 }
93
94 //=======================================================================
95 //function : AddHypothesis
96 //purpose  : 
97 //=======================================================================
98 void SMESHDS_Document::AddHypothesis(SMESHDS_Hypothesis * H)
99 {
100         myHypothesis[H->GetID()]=H;
101 }
102
103 //=======================================================================
104 //function : GetHypothesis
105 //purpose  : 
106 //=======================================================================
107 SMESHDS_Hypothesis * SMESHDS_Document::GetHypothesis(int HypID)
108 {
109         map<int,SMESHDS_Hypothesis*>::iterator it=myHypothesis.find(HypID);
110         if (it==myHypothesis.end())
111         {
112                 MESSAGE("SMESHDS_Document::GetHypothesis : ID not found");
113                 return NULL;
114         }
115         else return (*it).second;
116 }
117
118 //=======================================================================
119 //function : RemoveHypothesis
120 //purpose  : 
121 //=======================================================================
122 void SMESHDS_Document::RemoveHypothesis(int HypID)
123 {
124         map<int,SMESHDS_Hypothesis*>::iterator it=myHypothesis.find(HypID);
125         if (it==myHypothesis.end())
126                 MESSAGE("SMESHDS_Document::RemoveHypothesis : ID not found");   
127         myHypothesis.erase(it);
128 }
129
130 //=======================================================================
131 //function : NbMeshes
132 //purpose  : 
133 //=======================================================================
134 int SMESHDS_Document::NbMeshes()
135 {
136         return myMeshes.size();
137 }
138
139 //=======================================================================
140 //function : NbHypothesis
141 //purpose  : 
142 //=======================================================================
143 int SMESHDS_Document::NbHypothesis()
144 {
145         return myHypothesis.size();
146 }
147
148 //=======================================================================
149 //function : InitMeshesIterator
150 //purpose  : 
151 //=======================================================================
152 void SMESHDS_Document::InitMeshesIterator()
153 {
154         myMeshesIt=myMeshes.begin();
155 }
156
157 //=======================================================================
158 //function : NextMesh
159 //purpose  : 
160 //=======================================================================
161 SMESHDS_Mesh * SMESHDS_Document::NextMesh()
162 {
163         SMESHDS_Mesh * toReturn=(*myMeshesIt).second;
164         myMeshesIt++;
165         return toReturn;
166 }
167
168 //=======================================================================
169 //function : MoreMesh
170 //purpose  : 
171 //=======================================================================
172 bool SMESHDS_Document::MoreMesh()
173 {
174         return myMeshesIt!=myMeshes.end();
175 }
176
177 //=======================================================================
178 //function : InitHypothesisIterator
179 //purpose  : 
180 //=======================================================================
181 void SMESHDS_Document::InitHypothesisIterator()
182 {
183         myHypothesisIt=myHypothesis.begin();
184 }
185
186 //=======================================================================
187 //function : NextMesh
188 //purpose  : 
189 //=======================================================================
190 SMESHDS_Hypothesis * SMESHDS_Document::NextHypothesis()
191 {
192         SMESHDS_Hypothesis * toReturn=(*myHypothesisIt).second;
193         myHypothesisIt++;
194         return toReturn;
195 }
196
197 //=======================================================================
198 //function : MoreMesh
199 //purpose  : 
200 //=======================================================================
201 bool SMESHDS_Document::MoreHypothesis()
202 {
203         return myHypothesisIt!=myHypothesis.end();
204 }