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