]> SALOME platform Git repositories - plugins/netgenplugin.git/blob - src/NETGENPlugin/NETGENPlugin_Hypothesis.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[plugins/netgenplugin.git] / src / NETGENPlugin / NETGENPlugin_Hypothesis.cxx
1 //  NETGENPlugin : C++ implementation
2 //
3 //  Copyright (C) 2006  OPEN CASCADE, CEA/DEN, EDF R&D
4 // 
5 //  This library is free software; you can redistribute it and/or 
6 //  modify it under the terms of the GNU Lesser General Public 
7 //  License as published by the Free Software Foundation; either 
8 //  version 2.1 of the License. 
9 // 
10 //  This library is distributed in the hope that it will be useful, 
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
13 //  Lesser General Public License for more details. 
14 // 
15 //  You should have received a copy of the GNU Lesser General Public 
16 //  License along with this library; if not, write to the Free Software 
17 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
18 // 
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21 //
22 // File      : NETGENPlugin_Hypothesis.cxx
23 // Author    : Michael Sazonov (OCN)
24 // Date      : 28/03/2006
25 // Project   : SALOME
26 // $Header$
27 //=============================================================================
28
29 #include <NETGENPlugin_Hypothesis.hxx>
30 #include <utilities.h>
31
32 using namespace std;
33
34 //=============================================================================
35 /*!
36  *  
37  */
38 //=============================================================================
39 NETGENPlugin_Hypothesis::NETGENPlugin_Hypothesis (int hypId, int studyId,
40                                                   SMESH_Gen * gen)
41   : SMESH_Hypothesis(hypId, studyId, gen),
42     _maxSize       (GetDefaultMaxSize()),
43     _growthRate    (GetDefaultGrowthRate()),
44     _nbSegPerEdge  (GetDefaultNbSegPerEdge()),
45     _nbSegPerRadius(GetDefaultNbSegPerRadius()),
46     _fineness      (GetDefaultFineness()),
47     _secondOrder   (GetDefaultSecondOrder()),
48     _optimize      (GetDefaultOptimize())
49 {
50   _name = "NETGEN_Parameters";
51   _param_algo_dim = 3;
52 }
53
54 //=============================================================================
55 /*!
56  *  
57  */
58 //=============================================================================
59 void NETGENPlugin_Hypothesis::SetMaxSize(double theSize)
60 {
61   if (theSize != _maxSize)
62   {
63     _maxSize = theSize;
64     NotifySubMeshesHypothesisModification();
65   }
66 }
67
68 //=============================================================================
69 /*!
70  *  
71  */
72 //=============================================================================
73 void NETGENPlugin_Hypothesis::SetSecondOrder(bool theVal)
74 {
75   if (theVal != _secondOrder)
76   {
77     _secondOrder = theVal;
78     NotifySubMeshesHypothesisModification();
79   }
80 }
81
82 //=============================================================================
83 /*!
84  *  
85  */
86 //=============================================================================
87 void NETGENPlugin_Hypothesis::SetOptimize(bool theVal)
88 {
89   if (theVal != _optimize)
90   {
91     _optimize = theVal;
92     NotifySubMeshesHypothesisModification();
93   }
94 }
95
96 //=============================================================================
97 /*!
98  *  
99  */
100 //=============================================================================
101 void NETGENPlugin_Hypothesis::SetFineness(Fineness theFineness)
102 {
103   if (theFineness != _fineness)
104   {
105     _fineness = theFineness;
106     // the predefined values are taken from NETGEN 4.5 sources
107     switch (_fineness)
108     {
109     case VeryCoarse:
110       _growthRate = 0.7;
111       _nbSegPerEdge = 0.3;
112       _nbSegPerRadius = 1;
113       break;
114     case Coarse:
115       _growthRate = 0.5;
116       _nbSegPerEdge = 0.5;
117       _nbSegPerRadius = 1.5;
118       break;
119     case Fine:
120       _growthRate = 0.2;
121       _nbSegPerEdge = 2;
122       _nbSegPerRadius = 3;
123       break;
124     case VeryFine:
125       _growthRate = 0.1;
126       _nbSegPerEdge = 3;
127       _nbSegPerRadius = 5;
128       break;
129     case UserDefined:
130       break;
131     case Moderate:
132     default:
133       _growthRate = 0.3;
134       _nbSegPerEdge = 1;
135       _nbSegPerRadius = 2;
136       break;
137     }
138     NotifySubMeshesHypothesisModification();
139   }
140 }
141
142 //=============================================================================
143 /*!
144  *  
145  */
146 //=============================================================================
147 void NETGENPlugin_Hypothesis::SetGrowthRate(double theRate)
148 {
149   if (theRate != _growthRate)
150   {
151     _growthRate = theRate;
152     _fineness = UserDefined;
153     NotifySubMeshesHypothesisModification();
154   }
155 }
156
157 //=============================================================================
158 /*!
159  *  
160  */
161 //=============================================================================
162 void NETGENPlugin_Hypothesis::SetNbSegPerEdge(double theVal)
163 {
164   if (theVal != _nbSegPerEdge)
165   {
166     _nbSegPerEdge = theVal;
167     _fineness = UserDefined;
168     NotifySubMeshesHypothesisModification();
169   }
170 }
171
172 //=============================================================================
173 /*!
174  *  
175  */
176 //=============================================================================
177 void NETGENPlugin_Hypothesis::SetNbSegPerRadius(double theVal)
178 {
179   if (theVal != _nbSegPerRadius)
180   {
181     _nbSegPerRadius = theVal;
182     _fineness = UserDefined;
183     NotifySubMeshesHypothesisModification();
184   }
185 }
186
187 //=============================================================================
188 /*!
189  *  
190  */
191 //=============================================================================
192 ostream & NETGENPlugin_Hypothesis::SaveTo(ostream & save)
193 {
194   save << _maxSize << " " << _fineness;
195
196   if (_fineness == UserDefined)
197     save << " " << _growthRate << " " << _nbSegPerEdge << " " << _nbSegPerRadius;
198
199   save << " " << (int)_secondOrder << " " << (int)_optimize;
200
201   return save;
202 }
203
204 //=============================================================================
205 /*!
206  *  
207  */
208 //=============================================================================
209 istream & NETGENPlugin_Hypothesis::LoadFrom(istream & load)
210 {
211   bool isOK = true;
212   int is;
213   double val;
214
215   isOK = (load >> val);
216   if (isOK)
217     _maxSize = val;
218   else
219     load.clear(ios::badbit | load.rdstate());
220
221   isOK = (load >> is);
222   if (isOK)
223     SetFineness((Fineness) is);
224   else
225     load.clear(ios::badbit | load.rdstate());
226
227   if (_fineness == UserDefined)
228   {
229     isOK = (load >> val);
230     if (isOK)
231       _growthRate = val;
232     else
233       load.clear(ios::badbit | load.rdstate());
234
235     isOK = (load >> val);
236     if (isOK)
237       _nbSegPerEdge = val;
238     else
239       load.clear(ios::badbit | load.rdstate());
240
241     isOK = (load >> val);
242     if (isOK)
243       _nbSegPerRadius = val;
244     else
245       load.clear(ios::badbit | load.rdstate());
246   }
247
248   isOK = (load >> is);
249   if (isOK)
250     _secondOrder = (bool) is;
251   else
252     load.clear(ios::badbit | load.rdstate());
253
254   isOK = (load >> is);
255   if (isOK)
256     _optimize = (bool) is;
257   else
258     load.clear(ios::badbit | load.rdstate());
259   return load;
260 }
261
262 //=============================================================================
263 /*!
264  *  
265  */
266 //=============================================================================
267 ostream & operator <<(ostream & save, NETGENPlugin_Hypothesis & hyp)
268 {
269   return hyp.SaveTo( save );
270 }
271
272 //=============================================================================
273 /*!
274  *  
275  */
276 //=============================================================================
277 istream & operator >>(istream & load, NETGENPlugin_Hypothesis & hyp)
278 {
279   return hyp.LoadFrom( load );
280 }
281
282
283 //================================================================================
284 /*!
285  * \brief Does nothing
286  * \param theMesh - the built mesh
287  * \param theShape - the geometry of interest
288  * \retval bool - always false
289  */
290 //================================================================================
291 bool NETGENPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh*   theMesh,
292                                                       const TopoDS_Shape& theShape)
293 {
294   return false;
295 }
296
297 //=============================================================================
298 /*!
299  *  
300  */
301 //=============================================================================
302 double NETGENPlugin_Hypothesis::GetDefaultMaxSize()
303 {
304   return 1000;
305 }
306
307 //=============================================================================
308 /*!
309  *  
310  */
311 //=============================================================================
312 NETGENPlugin_Hypothesis::Fineness NETGENPlugin_Hypothesis::GetDefaultFineness()
313 {
314   return Moderate;
315 }
316
317 //=============================================================================
318 /*!
319  *  
320  */
321 //=============================================================================
322 double NETGENPlugin_Hypothesis::GetDefaultGrowthRate()
323 {
324   return 0.3;
325 }
326
327 //=============================================================================
328 /*!
329  *  
330  */
331 //=============================================================================
332 double NETGENPlugin_Hypothesis::GetDefaultNbSegPerEdge()
333 {
334   return 1;
335 }
336
337 //=============================================================================
338 /*!
339  *  
340  */
341 //=============================================================================
342 double NETGENPlugin_Hypothesis::GetDefaultNbSegPerRadius()
343 {
344   return 2;
345 }
346
347 //=============================================================================
348 /*!
349  *  
350  */
351 //=============================================================================
352 bool NETGENPlugin_Hypothesis::GetDefaultSecondOrder()
353 {
354   return false;
355 }
356
357 //=============================================================================
358 /*!
359  *  
360  */
361 //=============================================================================
362 bool NETGENPlugin_Hypothesis::GetDefaultOptimize()
363 {
364   return true;
365 }