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