Salome HOME
Merge from V5_1_main branch 24/11/2010
[modules/smesh.git] / src / SMESH / SMESH_Hypothesis.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 SMESH : implementaion of SMESH idl descriptions
24 //  File   : SMESH_Hypothesis.cxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //
28 #include "SMESH_Hypothesis.hxx"
29 #include "SMESH_Gen.hxx"
30 #include "SMESH_subMesh.hxx"
31 #include "utilities.h"
32
33 using namespace std;
34
35 //=============================================================================
36 /*!
37  * 
38  */
39 //=============================================================================
40
41 SMESH_Hypothesis::SMESH_Hypothesis(int hypId,
42                                    int studyId,
43                                    SMESH_Gen* gen) : SMESHDS_Hypothesis(hypId)
44 {
45   //MESSAGE("SMESH_Hypothesis::SMESH_Hypothesis");
46   _gen = gen;
47   _studyId = studyId;
48   StudyContextStruct* myStudyContext = _gen->GetStudyContext(_studyId);
49   myStudyContext->mapHypothesis[_hypId] = this;
50   _type = PARAM_ALGO;
51   _shapeType = 0; // to be set by algo with TopAbs_Enum
52   _param_algo_dim = -1; // to be set by algo parameter
53   _parameters = string();
54 }
55
56 //=============================================================================
57 /*!
58  * 
59  */
60 //=============================================================================
61
62 SMESH_Hypothesis::~SMESH_Hypothesis()
63 {
64   MESSAGE("SMESH_Hypothesis::~SMESH_Hypothesis");
65 }
66
67 //=============================================================================
68 /*!
69  * 
70  */
71 //=============================================================================
72
73 int SMESH_Hypothesis::GetDim() const
74 {
75   int dim = 0;
76   switch (_type)
77     {
78     case ALGO_1D: dim = 1; break;
79     case ALGO_2D: dim = 2; break;
80     case ALGO_3D: dim = 3; break;
81     case PARAM_ALGO:
82       dim = ( _param_algo_dim < 0 ) ? -_param_algo_dim : _param_algo_dim; break;
83     }
84   return dim;
85 }
86
87 //=============================================================================
88 /*!
89  *  
90  */
91 //=============================================================================
92
93 int SMESH_Hypothesis::GetShapeType() const
94 {
95   return _shapeType;
96 }
97
98 //=============================================================================
99 /*!
100  * 
101  */
102 //=============================================================================
103
104 int SMESH_Hypothesis::GetStudyId() const
105 {
106   return _studyId;
107 }
108
109 //=============================================================================
110 /*!
111  * 
112  */
113 //=============================================================================
114
115 void SMESH_Hypothesis::NotifySubMeshesHypothesisModification()
116 {
117   MESSAGE("SMESH_Hypothesis::NotifySubMeshesHypothesisModification");
118
119   // for all meshes in study
120
121   StudyContextStruct* myStudyContext = _gen->GetStudyContext(_studyId);
122   map<int, SMESH_Mesh*>::iterator itm;
123   for (itm = myStudyContext->mapMesh.begin();
124        itm != myStudyContext->mapMesh.end();
125        itm++)
126     {
127       SMESH_Mesh* mesh = (*itm).second;
128       mesh->NotifySubMeshesHypothesisModification( this );
129     }
130 }
131
132 //=============================================================================
133 /*!
134  * 
135  */
136 //=============================================================================
137
138 const char* SMESH_Hypothesis::GetLibName() const
139 {
140   return _libName.c_str();
141 }
142
143 //=============================================================================
144 /*!
145  * 
146  */
147 //=============================================================================
148
149 void SMESH_Hypothesis::SetLibName(const char* theLibName)
150 {
151   _libName = string(theLibName);
152 }
153
154 //=======================================================================
155 //function : GetMeshByPersistentID
156 //purpose  : Find a mesh with given persistent ID
157 //=======================================================================
158
159 SMESH_Mesh* SMESH_Hypothesis::GetMeshByPersistentID(int id)
160 {
161   StudyContextStruct* myStudyContext = _gen->GetStudyContext(_studyId);
162   map<int, SMESH_Mesh*>::iterator itm = itm = myStudyContext->mapMesh.begin();
163   for ( ; itm != myStudyContext->mapMesh.end(); itm++)
164   {
165     SMESH_Mesh* mesh = (*itm).second;
166     if ( mesh->GetMeshDS()->GetPersistentId() == id )
167       return mesh;
168   }
169   return 0;
170 }
171
172 //=============================================================================
173 /*!
174  * 
175  */
176 //=============================================================================
177 void SMESH_Hypothesis::SetParameters(const char *theParameters)
178 {
179   string aNewParameters(theParameters);
180   if(aNewParameters.size()==0 && _parameters.size()==0)
181     aNewParameters = " ";
182   if(_parameters.size()>0)
183     _parameters +="|";
184   _parameters +=aNewParameters;
185   SetLastParameters(theParameters);
186 }
187
188 //=============================================================================
189 /*!
190  * 
191  */
192 //=============================================================================
193 void SMESH_Hypothesis::ClearParameters()
194 {
195   _parameters = string();
196 }
197
198 //=============================================================================
199 /*!
200  * 
201  */
202 //=============================================================================
203 char* SMESH_Hypothesis::GetParameters() const
204 {
205   return (char*)_parameters.c_str();
206 }
207
208 //=============================================================================
209 /*!
210  * 
211  */
212 //=============================================================================
213 char* SMESH_Hypothesis::GetLastParameters() const
214 {
215   return (char*)_lastParameters.c_str();
216 }
217
218 //=============================================================================
219 /*!
220  * 
221  */
222 //=============================================================================
223 void SMESH_Hypothesis::SetLastParameters(const char* theParameters)
224 {
225   _lastParameters = string(theParameters);
226 }