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