Salome HOME
Merge from V6_main 01/04/2013
[modules/smesh.git] / src / SMESHDS / SMESHDS_Document.cxx
1 // Copyright (C) 2007-2013  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 SMESHDS_Mesh * SMESHDS_Document::NewMesh(bool theIsEmbeddedMode, int MeshID)
59 {
60   std::map<int,SMESHDS_Mesh*>::iterator i_m =
61     myMeshes.insert( make_pair( MeshID, (SMESHDS_Mesh*)0 )).first;
62   if ( i_m->second )
63     throw SALOME_Exception("SMESHDS_Document::NewMesh(): ID of existing mesh given");
64   SMESHDS_Mesh *aNewMesh = new SMESHDS_Mesh(MeshID,theIsEmbeddedMode);
65   i_m->second = aNewMesh;
66   return aNewMesh;
67 }
68
69 //=======================================================================
70 //function : GetMesh
71 //purpose  : 
72 //=======================================================================
73 SMESHDS_Mesh *SMESHDS_Document::GetMesh(int MeshID)
74 {
75         map<int,SMESHDS_Mesh*>::iterator it=myMeshes.find(MeshID);
76         if (it==myMeshes.end())
77         {
78                 MESSAGE("SMESHDS_Document::GetMesh : ID not found");
79                 return NULL;
80         }
81         else return (*it).second;
82 }
83
84 //=======================================================================
85 //function : RemoveMesh
86 //purpose  : 
87 //=======================================================================
88 void SMESHDS_Document::RemoveMesh(int MeshID)
89 {
90   map<int,SMESHDS_Mesh*>::iterator it=myMeshes.find(MeshID);
91   if (it!=myMeshes.end())
92     myMeshes.erase(it);
93 }
94
95 //=======================================================================
96 //function : AddHypothesis
97 //purpose  : 
98 //=======================================================================
99 void SMESHDS_Document::AddHypothesis(SMESHDS_Hypothesis * H)
100 {
101   myHypothesis[H->GetID()]=H;
102 }
103
104 //=======================================================================
105 //function : GetHypothesis
106 //purpose  : 
107 //=======================================================================
108 SMESHDS_Hypothesis * SMESHDS_Document::GetHypothesis(int HypID)
109 {
110         map<int,SMESHDS_Hypothesis*>::iterator it=myHypothesis.find(HypID);
111         if (it==myHypothesis.end())
112         {
113                 MESSAGE("SMESHDS_Document::GetHypothesis : ID not found");
114                 return NULL;
115         }
116         else return (*it).second;
117 }
118
119 //=======================================================================
120 //function : RemoveHypothesis
121 //purpose  : 
122 //=======================================================================
123 void SMESHDS_Document::RemoveHypothesis(int HypID)
124 {
125         map<int,SMESHDS_Hypothesis*>::iterator it=myHypothesis.find(HypID);
126         if (it==myHypothesis.end())
127                 MESSAGE("SMESHDS_Document::RemoveHypothesis : ID not found");   
128         myHypothesis.erase(it);
129 }
130
131 //=======================================================================
132 //function : NbMeshes
133 //purpose  : 
134 //=======================================================================
135 int SMESHDS_Document::NbMeshes()
136 {
137         return myMeshes.size();
138 }
139
140 //=======================================================================
141 //function : NbHypothesis
142 //purpose  : 
143 //=======================================================================
144 int SMESHDS_Document::NbHypothesis()
145 {
146         return myHypothesis.size();
147 }
148
149 //=======================================================================
150 //function : InitMeshesIterator
151 //purpose  : 
152 //=======================================================================
153 void SMESHDS_Document::InitMeshesIterator()
154 {
155         myMeshesIt=myMeshes.begin();
156 }
157
158 //=======================================================================
159 //function : NextMesh
160 //purpose  : 
161 //=======================================================================
162 SMESHDS_Mesh * SMESHDS_Document::NextMesh()
163 {
164         SMESHDS_Mesh * toReturn=(*myMeshesIt).second;
165         myMeshesIt++;
166         return toReturn;
167 }
168
169 //=======================================================================
170 //function : MoreMesh
171 //purpose  : 
172 //=======================================================================
173 bool SMESHDS_Document::MoreMesh()
174 {
175         return myMeshesIt!=myMeshes.end();
176 }
177
178 //=======================================================================
179 //function : InitHypothesisIterator
180 //purpose  : 
181 //=======================================================================
182 void SMESHDS_Document::InitHypothesisIterator()
183 {
184         myHypothesisIt=myHypothesis.begin();
185 }
186
187 //=======================================================================
188 //function : NextMesh
189 //purpose  : 
190 //=======================================================================
191 SMESHDS_Hypothesis * SMESHDS_Document::NextHypothesis()
192 {
193         SMESHDS_Hypothesis * toReturn=(*myHypothesisIt).second;
194         myHypothesisIt++;
195         return toReturn;
196 }
197
198 //=======================================================================
199 //function : MoreMesh
200 //purpose  : 
201 //=======================================================================
202 bool SMESHDS_Document::MoreHypothesis()
203 {
204         return myHypothesisIt!=myHypothesis.end();
205 }