Salome HOME
Merge from BR_V5_DEV 16Feb09
[plugins/netgenplugin.git] / src / NETGENPlugin / NETGENPlugin_Hypothesis.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 //  NETGENPlugin : C++ implementation
23 // File      : NETGENPlugin_Hypothesis.cxx
24 // Author    : Michael Sazonov (OCN)
25 // Date      : 28/03/2006
26 // Project   : SALOME
27 //
28 #include <NETGENPlugin_Hypothesis.hxx>
29 #include <utilities.h>
30
31 using namespace std;
32
33 //=============================================================================
34 /*!
35  *  
36  */
37 //=============================================================================
38 NETGENPlugin_Hypothesis::NETGENPlugin_Hypothesis (int hypId, int studyId,
39                                                   SMESH_Gen * gen)
40   : SMESH_Hypothesis(hypId, studyId, gen),
41     _maxSize       (GetDefaultMaxSize()),
42     _growthRate    (GetDefaultGrowthRate()),
43     _nbSegPerEdge  (GetDefaultNbSegPerEdge()),
44     _nbSegPerRadius(GetDefaultNbSegPerRadius()),
45     _fineness      (GetDefaultFineness()),
46     _secondOrder   (GetDefaultSecondOrder()),
47     _optimize      (GetDefaultOptimize())
48 {
49   _name = "NETGEN_Parameters";
50   _param_algo_dim = 3;
51 }
52
53 //=============================================================================
54 /*!
55  *  
56  */
57 //=============================================================================
58 void NETGENPlugin_Hypothesis::SetMaxSize(double theSize)
59 {
60   if (theSize != _maxSize)
61   {
62     _maxSize = theSize;
63     NotifySubMeshesHypothesisModification();
64   }
65 }
66
67 //=============================================================================
68 /*!
69  *  
70  */
71 //=============================================================================
72 void NETGENPlugin_Hypothesis::SetSecondOrder(bool theVal)
73 {
74   if (theVal != _secondOrder)
75   {
76     _secondOrder = theVal;
77     NotifySubMeshesHypothesisModification();
78   }
79 }
80
81 //=============================================================================
82 /*!
83  *  
84  */
85 //=============================================================================
86 void NETGENPlugin_Hypothesis::SetOptimize(bool theVal)
87 {
88   if (theVal != _optimize)
89   {
90     _optimize = theVal;
91     NotifySubMeshesHypothesisModification();
92   }
93 }
94
95 //=============================================================================
96 /*!
97  *  
98  */
99 //=============================================================================
100 void NETGENPlugin_Hypothesis::SetFineness(Fineness theFineness)
101 {
102   if (theFineness != _fineness)
103   {
104     _fineness = theFineness;
105     // the predefined values are taken from NETGEN 4.5 sources
106     switch (_fineness)
107     {
108     case VeryCoarse:
109       _growthRate = 0.7;
110       _nbSegPerEdge = 0.3;
111       _nbSegPerRadius = 1;
112       break;
113     case Coarse:
114       _growthRate = 0.5;
115       _nbSegPerEdge = 0.5;
116       _nbSegPerRadius = 1.5;
117       break;
118     case Fine:
119       _growthRate = 0.2;
120       _nbSegPerEdge = 2;
121       _nbSegPerRadius = 3;
122       break;
123     case VeryFine:
124       _growthRate = 0.1;
125       _nbSegPerEdge = 3;
126       _nbSegPerRadius = 5;
127       break;
128     case UserDefined:
129       break;
130     case Moderate:
131     default:
132       _growthRate = 0.3;
133       _nbSegPerEdge = 1;
134       _nbSegPerRadius = 2;
135       break;
136     }
137     NotifySubMeshesHypothesisModification();
138   }
139 }
140
141 //=============================================================================
142 /*!
143  *  
144  */
145 //=============================================================================
146 void NETGENPlugin_Hypothesis::SetGrowthRate(double theRate)
147 {
148   if (theRate != _growthRate)
149   {
150     _growthRate = theRate;
151     _fineness = UserDefined;
152     NotifySubMeshesHypothesisModification();
153   }
154 }
155
156 //=============================================================================
157 /*!
158  *  
159  */
160 //=============================================================================
161 void NETGENPlugin_Hypothesis::SetNbSegPerEdge(double theVal)
162 {
163   if (theVal != _nbSegPerEdge)
164   {
165     _nbSegPerEdge = theVal;
166     _fineness = UserDefined;
167     NotifySubMeshesHypothesisModification();
168   }
169 }
170
171 //=============================================================================
172 /*!
173  *  
174  */
175 //=============================================================================
176 void NETGENPlugin_Hypothesis::SetNbSegPerRadius(double theVal)
177 {
178   if (theVal != _nbSegPerRadius)
179   {
180     _nbSegPerRadius = theVal;
181     _fineness = UserDefined;
182     NotifySubMeshesHypothesisModification();
183   }
184 }
185
186 //=============================================================================
187 /*!
188  *  
189  */
190 //=============================================================================
191 ostream & NETGENPlugin_Hypothesis::SaveTo(ostream & save)
192 {
193   save << _maxSize << " " << _fineness;
194
195   if (_fineness == UserDefined)
196     save << " " << _growthRate << " " << _nbSegPerEdge << " " << _nbSegPerRadius;
197
198   save << " " << (int)_secondOrder << " " << (int)_optimize;
199
200   return save;
201 }
202
203 //=============================================================================
204 /*!
205  *  
206  */
207 //=============================================================================
208 istream & NETGENPlugin_Hypothesis::LoadFrom(istream & load)
209 {
210   bool isOK = true;
211   int is;
212   double val;
213
214   isOK = (load >> val);
215   if (isOK)
216     _maxSize = val;
217   else
218     load.clear(ios::badbit | load.rdstate());
219
220   isOK = (load >> is);
221   if (isOK)
222     SetFineness((Fineness) is);
223   else
224     load.clear(ios::badbit | load.rdstate());
225
226   if (_fineness == UserDefined)
227   {
228     isOK = (load >> val);
229     if (isOK)
230       _growthRate = val;
231     else
232       load.clear(ios::badbit | load.rdstate());
233
234     isOK = (load >> val);
235     if (isOK)
236       _nbSegPerEdge = val;
237     else
238       load.clear(ios::badbit | load.rdstate());
239
240     isOK = (load >> val);
241     if (isOK)
242       _nbSegPerRadius = val;
243     else
244       load.clear(ios::badbit | load.rdstate());
245   }
246
247   isOK = (load >> is);
248   if (isOK)
249     _secondOrder = (bool) is;
250   else
251     load.clear(ios::badbit | load.rdstate());
252
253   isOK = (load >> is);
254   if (isOK)
255     _optimize = (bool) is;
256   else
257     load.clear(ios::badbit | load.rdstate());
258   return load;
259 }
260
261 //=============================================================================
262 /*!
263  *  
264  */
265 //=============================================================================
266 ostream & operator <<(ostream & save, NETGENPlugin_Hypothesis & hyp)
267 {
268   return hyp.SaveTo( save );
269 }
270
271 //=============================================================================
272 /*!
273  *  
274  */
275 //=============================================================================
276 istream & operator >>(istream & load, NETGENPlugin_Hypothesis & hyp)
277 {
278   return hyp.LoadFrom( load );
279 }
280
281
282 //================================================================================
283 /*!
284  * \brief Does nothing
285  * \param theMesh - the built mesh
286  * \param theShape - the geometry of interest
287  * \retval bool - always false
288  */
289 //================================================================================
290 bool NETGENPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh*   theMesh,
291                                                   const TopoDS_Shape& theShape)
292 {
293   return false;
294 }
295
296 //================================================================================
297 /*!
298  * \brief Initialize my parameter values by default parameters.
299  *  \retval bool - true if parameter values have been successfully defined
300  */
301 //================================================================================
302
303 bool NETGENPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&  dflts,
304                                                       const SMESH_Mesh* /*theMesh*/)
305 {
306   _nbSegPerEdge = dflts._nbSegments;
307   _maxSize      = dflts._elemLength;
308   return _nbSegPerEdge && _maxSize > 0;
309 }
310
311 //=============================================================================
312 /*!
313  *  
314  */
315 //=============================================================================
316 double NETGENPlugin_Hypothesis::GetDefaultMaxSize()
317 {
318   return 1000;
319 }
320
321 //=============================================================================
322 /*!
323  *  
324  */
325 //=============================================================================
326 NETGENPlugin_Hypothesis::Fineness NETGENPlugin_Hypothesis::GetDefaultFineness()
327 {
328   return Moderate;
329 }
330
331 //=============================================================================
332 /*!
333  *  
334  */
335 //=============================================================================
336 double NETGENPlugin_Hypothesis::GetDefaultGrowthRate()
337 {
338   return 0.3;
339 }
340
341 //=============================================================================
342 /*!
343  *  
344  */
345 //=============================================================================
346 double NETGENPlugin_Hypothesis::GetDefaultNbSegPerEdge()
347 {
348   return 1;
349 }
350
351 //=============================================================================
352 /*!
353  *  
354  */
355 //=============================================================================
356 double NETGENPlugin_Hypothesis::GetDefaultNbSegPerRadius()
357 {
358   return 2;
359 }
360
361 //=============================================================================
362 /*!
363  *  
364  */
365 //=============================================================================
366 bool NETGENPlugin_Hypothesis::GetDefaultSecondOrder()
367 {
368   return false;
369 }
370
371 //=============================================================================
372 /*!
373  *  
374  */
375 //=============================================================================
376 bool NETGENPlugin_Hypothesis::GetDefaultOptimize()
377 {
378   return true;
379 }