Salome HOME
Regression of SALOME_TESTS/Grids/smesh/viscous_layers_01/B2
[plugins/netgenplugin.git] / src / NETGENPlugin / NETGENPlugin_Hypothesis_i.cxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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 //  NETGENPlugin : C++ implementation
24 // File      : NETGENPlugin_Hypothesis_i.cxx
25 // Author    : Michael Sazonov (OCN)
26 // Date      : 03/04/2006
27 // Project   : SALOME
28 //=============================================================================
29 //
30 #include "NETGENPlugin_Hypothesis_i.hxx"
31 #include "SMESH_Gen.hxx"
32 #include "SMESH_PythonDump.hxx"
33
34 #include "Utils_CorbaException.hxx"
35 #include "utilities.h"
36
37 using namespace std;
38
39 //=============================================================================
40 /*!
41  *  Specialization of isToSetParameter<T> for double
42  */
43 //=============================================================================
44
45 template<>
46 bool NETGENPlugin_Hypothesis_i::isToSetParameter<double>(double curValue,
47                                                          double newValue,
48                                                          /*SettingMethod*/int meth)
49 {
50   return isToSetParameter(true, (fabs(curValue - newValue) < 1e-20), meth);
51 }
52
53 //=============================================================================
54 /*!
55  *  NETGENPlugin_Hypothesis_i::NETGENPlugin_Hypothesis_i
56  *
57  *  Constructor
58  */
59 //=============================================================================
60 NETGENPlugin_Hypothesis_i::
61 NETGENPlugin_Hypothesis_i (PortableServer::POA_ptr thePOA,
62                            int                     theStudyId,
63                            ::SMESH_Gen*            theGenImpl)
64   : SALOME::GenericObj_i( thePOA ), 
65     SMESH_Hypothesis_i( thePOA ),
66     mySetMethodFlags(0)
67 {
68   myBaseImpl = new ::NETGENPlugin_Hypothesis (theGenImpl->GetANewId(),
69                                               theStudyId,
70                                               theGenImpl);
71 }
72
73 //=============================================================================
74 /*!
75  *  NETGENPlugin_Hypothesis_i::~NETGENPlugin_Hypothesis_i
76  *
77  *  Destructor
78  */
79 //=============================================================================
80 NETGENPlugin_Hypothesis_i::~NETGENPlugin_Hypothesis_i()
81 {
82 }
83
84 //=============================================================================
85 /*!
86  *  NETGENPlugin_Hypothesis_i::SetMaxSize
87  *
88  *  Set MaxSize
89  */
90 //=============================================================================
91 void NETGENPlugin_Hypothesis_i::SetMaxSize (CORBA::Double theValue)
92 {
93   if ( isToSetParameter( GetMaxSize(), theValue, METH_SetMaxSize ))
94   {
95     this->GetImpl()->SetMaxSize(theValue);
96     SMESH::TPythonDump() << _this() << ".SetMaxSize( " << SMESH::TVar(theValue) << " )";
97   }
98 }
99
100 //=============================================================================
101 /*!
102  *  NETGENPlugin_Hypothesis_i::GetMaxSize
103  *
104  *  Get MaxSize
105  */
106 //=============================================================================
107 CORBA::Double NETGENPlugin_Hypothesis_i::GetMaxSize()
108 {
109   return this->GetImpl()->GetMaxSize();
110 }
111
112 //=============================================================================
113 /*!
114  *  NETGENPlugin_Hypothesis_i::SetMinSize
115  *
116  *  Set MinSize
117  */
118 //=============================================================================
119 void NETGENPlugin_Hypothesis_i::SetMinSize (CORBA::Double theValue)
120 {
121   if ( isToSetParameter( GetMinSize(), theValue, METH_SetMinSize ))
122   {
123     this->GetImpl()->SetMinSize(theValue);
124     SMESH::TPythonDump() << _this() << ".SetMinSize( " << SMESH::TVar(theValue) << " )";
125   }
126 }
127
128 //=============================================================================
129 /*!
130  *  NETGENPlugin_Hypothesis_i::GetMinSize
131  *
132  *  Get MinSize
133  */
134 //=============================================================================
135 CORBA::Double NETGENPlugin_Hypothesis_i::GetMinSize()
136 {
137   return this->GetImpl()->GetMinSize();
138 }
139
140 //=============================================================================
141 /*!
142  *  NETGENPlugin_Hypothesis_i::SetSecondOrder
143  *
144  *  Set SecondOrder flag
145  */
146 //=============================================================================
147 void NETGENPlugin_Hypothesis_i::SetSecondOrder (CORBA::Boolean theValue)
148 {
149   if ( isToSetParameter( GetSecondOrder(), theValue, METH_SetSecondOrder ))
150   {
151     this->GetImpl()->SetSecondOrder(theValue);
152     SMESH::TPythonDump() << _this() << ".SetSecondOrder( " << theValue << " )";
153   }
154 }
155
156 //=============================================================================
157 /*!
158  *  NETGENPlugin_Hypothesis_i::GetSecondOrder
159  *
160  *  Get SecondOrder flag
161  */
162 //=============================================================================
163 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetSecondOrder()
164 {
165   return this->GetImpl()->GetSecondOrder();
166 }
167
168 //=============================================================================
169 /*!
170  *  NETGENPlugin_Hypothesis_i::SetOptimize
171  *
172  *  Set Optimize flag
173  */
174 //=============================================================================
175 void NETGENPlugin_Hypothesis_i::SetOptimize (CORBA::Boolean theValue)
176 {
177   if ( isToSetParameter( GetOptimize(), theValue, METH_SetOptimize ))
178   {
179     this->GetImpl()->SetOptimize(theValue);
180     SMESH::TPythonDump() << _this() << ".SetOptimize( " << theValue << " )";
181   }
182 }
183
184 //=============================================================================
185 /*!
186  *  NETGENPlugin_Hypothesis_i::GetOptimize
187  *
188  *  Get Optimize flag
189  */
190 //=============================================================================
191 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetOptimize()
192 {
193   return this->GetImpl()->GetOptimize();
194 }
195
196 //=============================================================================
197 /*!
198  *  NETGENPlugin_Hypothesis_i::SetFineness
199  *
200  *  Set Fineness
201  */
202 //=============================================================================
203 void NETGENPlugin_Hypothesis_i::SetFineness (CORBA::Long theValue)
204 {
205   if ( isToSetParameter( GetFineness(), theValue, METH_SetFineness ))
206   {
207     this->GetImpl()->SetFineness((::NETGENPlugin_Hypothesis::Fineness)theValue);
208     SMESH::TPythonDump() << _this() << ".SetFineness( " << theValue << " )";
209   }
210 }
211
212 //=============================================================================
213 /*!
214  *  NETGENPlugin_Hypothesis_i::GetFineness
215  *
216  *  Get Fineness
217  */
218 //=============================================================================
219 CORBA::Long NETGENPlugin_Hypothesis_i::GetFineness()
220 {
221   return this->GetImpl()->GetFineness();
222 }
223
224 //=============================================================================
225 /*!
226  *  NETGENPlugin_Hypothesis_i::SetGrowthRate
227  *
228  *  Set GrowthRate
229  */
230 //=============================================================================
231 void NETGENPlugin_Hypothesis_i::SetGrowthRate (CORBA::Double theValue)
232 {
233   if ( isToSetParameter( GetGrowthRate(), theValue, METH_SetGrowthRate ))
234   {
235     this->GetImpl()->SetGrowthRate(theValue);
236     SMESH::TPythonDump() << _this() << ".SetGrowthRate( " << SMESH::TVar(theValue) << " )";
237   }
238 }
239
240 //=============================================================================
241 /*!
242  *  NETGENPlugin_Hypothesis_i::GetGrowthRate
243  *
244  *  Get GrowthRate
245  */
246 //=============================================================================
247 CORBA::Double NETGENPlugin_Hypothesis_i::GetGrowthRate()
248 {
249   return this->GetImpl()->GetGrowthRate();
250 }
251
252 //=============================================================================
253 /*!
254  *  NETGENPlugin_Hypothesis_i::SetNbSegPerEdge
255  *
256  *  Set NbSegPerEdge
257  */
258 //=============================================================================
259 void NETGENPlugin_Hypothesis_i::SetNbSegPerEdge (CORBA::Double theValue)
260 {
261   if ( isToSetParameter( GetNbSegPerEdge(), theValue, METH_SetNbSegPerEdge ))
262   {
263     this->GetImpl()->SetNbSegPerEdge(theValue);
264     SMESH::TPythonDump() << _this() << ".SetNbSegPerEdge( " << SMESH::TVar(theValue) << " )";
265   }
266 }
267
268 //=============================================================================
269 /*!
270  *  NETGENPlugin_Hypothesis_i::GetNbSegPerEdge
271  *
272  *  Get NbSegPerEdge
273  */
274 //=============================================================================
275 CORBA::Double NETGENPlugin_Hypothesis_i::GetNbSegPerEdge()
276 {
277   return this->GetImpl()->GetNbSegPerEdge();
278 }
279
280 //=============================================================================
281 /*!
282  *  NETGENPlugin_Hypothesis_i::SetNbSegPerRadius
283  *
284  *  Set NbSegPerRadius
285  */
286 //=============================================================================
287 void NETGENPlugin_Hypothesis_i::SetNbSegPerRadius (CORBA::Double theValue)
288 {
289   if ( isToSetParameter( GetNbSegPerRadius(), theValue, METH_SetNbSegPerRadius ))
290   {
291     this->GetImpl()->SetNbSegPerRadius(theValue);
292     SMESH::TPythonDump() << _this() << ".SetNbSegPerRadius( " << SMESH::TVar(theValue) << " )";
293   }
294 }
295
296 //=============================================================================
297 /*!
298  *  NETGENPlugin_Hypothesis_i::GetNbSegPerRadius
299  *
300  *  Get NbSegPerRadius
301  */
302 //=============================================================================
303 CORBA::Double NETGENPlugin_Hypothesis_i::GetNbSegPerRadius()
304 {
305   return this->GetImpl()->GetNbSegPerRadius();
306 }
307
308 //=============================================================================
309
310 void NETGENPlugin_Hypothesis_i::SetLocalSizeOnShape(GEOM::GEOM_Object_ptr GeomObj,
311                                                     CORBA::Double         localSize)
312   throw (SALOME::SALOME_Exception)
313 {
314   string entry;
315   entry = GeomObj->GetStudyEntry();
316   if ( entry.empty() )
317     THROW_SALOME_CORBA_EXCEPTION( "SetLocalSizeOnShape(), shape is not published in study!",
318                                   SALOME::BAD_PARAM );
319   SetLocalSizeOnEntry(entry.c_str(), localSize);
320 }
321
322 //=============================================================================
323
324 void NETGENPlugin_Hypothesis_i::SetLocalSizeOnEntry(const char*   entry,
325                                                     CORBA::Double localSize)
326 {
327   if ( isToSetParameter( GetLocalSizeOnEntry(entry), localSize, METH_SetLocalSizeOnEntry ))
328   {
329     this->GetImpl()->SetLocalSizeOnEntry(entry, localSize);
330     SMESH::TPythonDump()
331       << _this() << ".SetLocalSizeOnShape(" << entry << ", " << localSize << ")";
332   }
333 }
334
335 //=============================================================================
336
337 CORBA::Double NETGENPlugin_Hypothesis_i::GetLocalSizeOnEntry(const char* entry)
338 {
339   return this->GetImpl()->GetLocalSizeOnEntry(entry);
340 }
341
342 //=============================================================================
343
344 NETGENPlugin::string_array* NETGENPlugin_Hypothesis_i::GetLocalSizeEntries()
345 {
346   NETGENPlugin::string_array_var result = new NETGENPlugin::string_array();
347   const ::NETGENPlugin_Hypothesis::TLocalSize localSizes =
348     this->GetImpl()->GetLocalSizesAndEntries();
349   result->length(localSizes.size());
350   ::NETGENPlugin_Hypothesis::TLocalSize::const_iterator it = localSizes.begin();
351   for (int i=0 ; it != localSizes.end() ; i++, it++)
352     {
353       string entry = (*it).first;
354       result[i] = CORBA::string_dup(entry.c_str());
355     }
356   return result._retn();
357 }
358
359 //=============================================================================
360
361 void NETGENPlugin_Hypothesis_i::UnsetLocalSizeOnEntry(const char* entry)
362 {
363   this->GetImpl()->UnsetLocalSizeOnEntry(entry);
364   SMESH::TPythonDump() << _this() << ".UnsetLocalSizeOnEntry(\"" << entry << "\")";
365 }
366
367 //=============================================================================
368
369 void NETGENPlugin_Hypothesis_i::SetQuadAllowed (CORBA::Boolean theValue)
370 {
371   if ( NETGENPlugin_Hypothesis_i::isToSetParameter( GetQuadAllowed(),
372                                                     theValue,
373                                                     METH_SetQuadAllowed ))
374   {
375     this->GetImpl()->SetQuadAllowed(theValue);
376     SMESH::TPythonDump() << _this() << ".SetQuadAllowed( " << theValue << " )";
377   }
378 }
379
380 //=============================================================================
381
382 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetQuadAllowed()
383 {
384   return this->GetImpl()->GetQuadAllowed();
385 }
386
387 //=============================================================================
388
389 void NETGENPlugin_Hypothesis_i::SetUseSurfaceCurvature (CORBA::Boolean theValue)
390 {
391   if ( NETGENPlugin_Hypothesis_i::isToSetParameter( GetUseSurfaceCurvature(),
392                                                     theValue,
393                                                     METH_SetSurfaceCurvature ))
394   {
395     this->GetImpl()->SetSurfaceCurvature(theValue);
396     SMESH::TPythonDump() << _this() << ".SetUseSurfaceCurvature( " << theValue << " )";
397   }
398 }
399
400 //=============================================================================
401
402 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetUseSurfaceCurvature()
403 {
404   return this->GetImpl()->GetSurfaceCurvature();
405 }
406
407 //=============================================================================
408
409 void NETGENPlugin_Hypothesis_i::SetFuseEdges (CORBA::Boolean theValue)
410 {
411   if ( NETGENPlugin_Hypothesis_i::isToSetParameter( GetFuseEdges(),
412                                                     theValue,
413                                                     METH_SetFuseEdges ))
414   {
415     this->GetImpl()->SetFuseEdges(theValue);
416     SMESH::TPythonDump() << _this() << ".SetFuseEdges( " << theValue << " )";
417   }
418 }
419
420 //=============================================================================
421
422 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetFuseEdges()
423 {
424   return this->GetImpl()->GetFuseEdges();
425 }
426
427 //=============================================================================
428 /*!
429  *  NETGENPlugin_Hypothesis_i::GetImpl
430  *
431  *  Get implementation
432  */
433 //=============================================================================
434 ::NETGENPlugin_Hypothesis* NETGENPlugin_Hypothesis_i::GetImpl()
435 {
436   return (::NETGENPlugin_Hypothesis*)myBaseImpl;
437 }
438
439 //================================================================================
440 /*!
441  * \brief Verify whether hypothesis supports given entity type 
442   * \param type - dimension (see SMESH::Dimension enumeration)
443   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
444  * 
445  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
446  */
447 //================================================================================  
448 CORBA::Boolean NETGENPlugin_Hypothesis_i::IsDimSupported( SMESH::Dimension type )
449 {
450   return type == SMESH::DIM_3D;
451 }
452
453 //================================================================================
454 /*!
455  * \brief method intended to remove explicit treatment of Netgen hypotheses from SMESH_NoteBook
456  */
457 //================================================================================
458
459 int NETGENPlugin_Hypothesis_i::getParamIndex(const TCollection_AsciiString& method,
460                                              int nbVars) const
461 {
462   if ( method == "SetMaxSize"        ) return 0;
463   if ( method == "SetGrowthRate"     ) return 1;
464   if ( method == "SetNbSegPerEdge"   ) return 2;
465   if ( method == "SetNbSegPerRadius" ) return 3;
466   if ( method == "SetMinSize" )        return nbVars-1;
467
468   return SMESH_Hypothesis_i::getParamIndex( method, nbVars ); // return default value
469 }
470
471 //================================================================================
472 /*!
473  * \brief Method used to convert variable parameters stored in an old study
474  * into myMethod2VarParams. It should return a method name for an index of
475  * variable parameters. Index is countered from zero
476  */
477 //================================================================================
478
479 std::string NETGENPlugin_Hypothesis_i::getMethodOfParameter(const int paramIndex,
480                                                             int nbVars) const
481 {
482   switch ( paramIndex ) {
483   case 0: return "SetMaxSize";
484   case 1: return nbVars == 2 ? "SetMinSize" : "SetGrowthRate";
485   case 2: return "SetNbSegPerEdge";
486   case 3: return "SetNbSegPerRadius";
487   case 4: return "SetMinSize";
488   }
489   return "";
490 }