Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/smesh.git] / src / SMESHDS / SMESHDS_Document.cxx
1 //  Copyright (C) 2007-2008  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 //  SMESH SMESHDS : management of mesh data and SMESH document
23 //  File   : SMESHDS_Document.cxx
24 //  Author : Yves FRICAUD, OCC
25 //  Module : SMESH
26 //  $Header: 
27 //
28 #include "SMESHDS_Document.hxx"
29 #include "utilities.h"
30
31 using namespace std;
32
33 //=======================================================================
34 //function : Create
35 //purpose  : 
36 //=======================================================================
37 SMESHDS_Document::SMESHDS_Document(int UserID):myUserID(UserID)
38 {
39 }
40
41 //=======================================================================
42 //function : Destructor
43 //purpose  : 
44 //=======================================================================
45
46 SMESHDS_Document::~SMESHDS_Document()
47 {
48   InitMeshesIterator();
49   while ( MoreMesh() )
50     delete NextMesh();
51 }
52
53 //=======================================================================
54 //function : NewMesh
55 //purpose  : 
56 //=======================================================================
57 int SMESHDS_Document::NewMesh(bool theIsEmbeddedMode)
58 {
59   static int aNewMeshID = 0;
60   aNewMeshID++;
61   SMESHDS_Mesh *aNewMesh = new SMESHDS_Mesh(aNewMeshID,theIsEmbeddedMode);
62   myMeshes[aNewMeshID] = aNewMesh;
63   return aNewMeshID;
64 }
65
66 //=======================================================================
67 //function : GetMesh
68 //purpose  : 
69 //=======================================================================
70 SMESHDS_Mesh *SMESHDS_Document::GetMesh(int MeshID)
71 {
72         map<int,SMESHDS_Mesh*>::iterator it=myMeshes.find(MeshID);
73         if (it==myMeshes.end())
74         {
75                 MESSAGE("SMESHDS_Document::GetMesh : ID not found");
76                 return NULL;
77         }
78         else return (*it).second;
79 }
80
81 //=======================================================================
82 //function : RemoveMesh
83 //purpose  : 
84 //=======================================================================
85 void SMESHDS_Document::RemoveMesh(int MeshID)
86 {
87         map<int,SMESHDS_Mesh*>::iterator it=myMeshes.find(MeshID);
88         if (it==myMeshes.end())
89                 MESSAGE("SMESHDS_Document::RemoveMesh : ID not found"); 
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 }