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