Salome HOME
da19dad6f351971f9db9552edcd8e55080dd57e4
[plugins/gmshplugin.git] / src / GMSHPlugin / GMSHPlugin_Hypothesis_i.cxx
1 // Copyright (C) 2012-2015  ALNEOS
2 // Copyright (C) 2016-2023  EDF R&D
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 //
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.alneos.com/ or email : contact@alneos.fr
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21 #include "GMSHPlugin_Hypothesis_i.hxx"
22 #include "SMESH_Gen.hxx"
23 #include "SMESH_PythonDump.hxx"
24 #include "GEOM_Object.hxx"
25
26 #include "Utils_CorbaException.hxx"
27 #include "utilities.h"
28
29 using namespace std;
30
31 template<>
32 bool GMSHPlugin_Hypothesis_i::isToSetParameter<double>(double curValue,
33                                                          double newValue,
34                                                          /*SettingMethod*/int meth)
35 {
36   return isToSetParameter(true, (fabs(curValue - newValue) < 1e-20), meth);
37 }
38
39 GMSHPlugin_Hypothesis_i::
40 GMSHPlugin_Hypothesis_i (PortableServer::POA_ptr thePOA,
41                            ::SMESH_Gen*            theGenImpl)
42   : SALOME::GenericObj_i( thePOA ), 
43     SMESH_Hypothesis_i( thePOA ),
44     mySetMethodFlags(0)
45 {
46   MESSAGE( "GMSHPlugin_Hypothesis_i::GMSHPlugin_Hypothesis_i" );
47   myBaseImpl = new ::GMSHPlugin_Hypothesis (theGenImpl->GetANewId(),
48                                               theGenImpl);
49 }
50
51 GMSHPlugin_Hypothesis_i::~GMSHPlugin_Hypothesis_i()
52 {
53   MESSAGE( "GMSHPlugin_Hypothesis_i::~GMSHPlugin_Hypothesis_i" );
54 }
55
56 void GMSHPlugin_Hypothesis_i::SetMaxSize (CORBA::Double theValue)
57 {
58   if ( isToSetParameter( GetMaxSize(), theValue, METH_SetMaxSize ))
59   {
60     this->GetImpl()->SetMaxSize(theValue);
61     SMESH::TPythonDump() << _this() << ".SetMaxSize( " << SMESH::TVar(theValue) << " )";
62   }
63 }
64
65 CORBA::Double GMSHPlugin_Hypothesis_i::GetMaxSize()
66 {
67   return this->GetImpl()->GetMaxSize();
68 }
69
70
71 void GMSHPlugin_Hypothesis_i::SetMeshCurvatureSize (CORBA::Double theMeshCurvatureSize)
72 {
73   if ( isToSetParameter( GetMeshCurvatureSize(), theMeshCurvatureSize, METH_SetMeshCurvatureSize ))
74   {
75     this->GetImpl()->SetMeshCurvatureSize(theMeshCurvatureSize);
76     SMESH::TPythonDump() << _this() << ".SetMeshCurvatureSize( " << SMESH::TVar(theMeshCurvatureSize) << " )";
77   }
78 }
79
80 CORBA::Double GMSHPlugin_Hypothesis_i::GetMeshCurvatureSize()
81 {
82   return this->GetImpl()->GetMeshCurvatureSize();
83 }
84
85
86 void GMSHPlugin_Hypothesis_i::SetMinSize (CORBA::Double theValue)
87 {
88   if ( isToSetParameter( GetMinSize(), theValue, METH_SetMinSize ))
89   {
90     this->GetImpl()->SetMinSize(theValue);
91     SMESH::TPythonDump() << _this() << ".SetMinSize( " << SMESH::TVar(theValue) << " )";
92   }
93 }
94
95 CORBA::Double GMSHPlugin_Hypothesis_i::GetMinSize()
96 {
97   return this->GetImpl()->GetMinSize();
98 }
99
100 void GMSHPlugin_Hypothesis_i::SetSecondOrder (CORBA::Boolean theValue)
101 {
102   if ( isToSetParameter( GetSecondOrder(), theValue, METH_SetSecondOrder ))
103   {
104     this->GetImpl()->SetSecondOrder(theValue);
105     SMESH::TPythonDump() << _this() << ".SetSecondOrder( " << theValue << " )";
106   }
107 }
108
109 CORBA::Boolean GMSHPlugin_Hypothesis_i::GetSecondOrder()
110 {
111   return this->GetImpl()->GetSecondOrder();
112 }
113
114 void GMSHPlugin_Hypothesis_i::Set2DAlgo (CORBA::Long theValue)
115 {
116   if ( isToSetParameter( Get2DAlgo(), theValue, METH_Set2DAlgo ))
117   {
118     this->GetImpl()->Set2DAlgo((::GMSHPlugin_Hypothesis::Algo2D)theValue);
119     SMESH::TPythonDump() << _this() << ".Set2DAlgo( " << theValue << " )";
120   }
121 }
122
123 CORBA::Long GMSHPlugin_Hypothesis_i::Get2DAlgo()
124 {
125   return this->GetImpl()->Get2DAlgo();
126 }
127
128 void GMSHPlugin_Hypothesis_i::Set3DAlgo (CORBA::Long theValue)
129 {
130   if ( isToSetParameter( Get3DAlgo(), theValue, METH_Set3DAlgo ))
131   {
132     this->GetImpl()->Set3DAlgo((::GMSHPlugin_Hypothesis::Algo3D)theValue);
133     SMESH::TPythonDump() << _this() << ".Set3DAlgo( " << theValue << " )";
134   }
135 }
136
137 CORBA::Long GMSHPlugin_Hypothesis_i::Get3DAlgo()
138 {
139   return this->GetImpl()->Get3DAlgo();
140 }
141
142 void GMSHPlugin_Hypothesis_i::SetRecomb2DAlgo (CORBA::Long theValue)
143 {
144   if ( isToSetParameter( GetRecomb2DAlgo(), theValue, METH_SetRecomb2DAlgo ))
145   {
146     this->GetImpl()->SetRecomb2DAlgo((::GMSHPlugin_Hypothesis::Recomb2DAlgo)theValue);
147     SMESH::TPythonDump() << _this() << ".SetRecomb2DAlgo( " << theValue << " )";
148   }
149 }
150
151 CORBA::Long GMSHPlugin_Hypothesis_i::GetRecomb2DAlgo()
152 {
153   return this->GetImpl()->GetRecomb2DAlgo();
154 }
155
156 void GMSHPlugin_Hypothesis_i::SetRecombineAll (CORBA::Boolean theValue)
157 {
158   if ( isToSetParameter( GetRecombineAll(), theValue, METH_SetRecombineAll ))
159   {
160     this->GetImpl()->SetRecombineAll(theValue);
161     SMESH::TPythonDump() << _this() << ".SetRecombineAll( " << theValue << " )";
162   }
163 }
164
165 CORBA::Boolean GMSHPlugin_Hypothesis_i::GetRecombineAll()
166 {
167   return this->GetImpl()->GetRecombineAll();
168 }
169
170 void GMSHPlugin_Hypothesis_i::SetSubdivAlgo (CORBA::Long theValue)
171 {
172   if ( isToSetParameter( GetSubdivAlgo(), theValue, METH_SetSubdivAlgo ))
173   {
174     this->GetImpl()->SetSubdivAlgo((::GMSHPlugin_Hypothesis::SubdivAlgo)theValue);
175     SMESH::TPythonDump() << _this() << ".SetSubdivAlgo( " << theValue << " )";
176   }
177 }
178
179 CORBA::Long GMSHPlugin_Hypothesis_i::GetSubdivAlgo()
180 {
181   return this->GetImpl()->GetSubdivAlgo();
182 }
183
184 void GMSHPlugin_Hypothesis_i::SetRemeshAlgo (CORBA::Long theValue)
185 {
186   if ( isToSetParameter( GetRemeshAlgo(), theValue, METH_SetRemeshAlgo ))
187   {
188     this->GetImpl()->SetRemeshAlgo((::GMSHPlugin_Hypothesis::RemeshAlgo)theValue);
189     SMESH::TPythonDump() << _this() << ".SetRemeshAlgo( " << theValue << " )";
190   }
191 }
192
193 CORBA::Long GMSHPlugin_Hypothesis_i::GetRemeshAlgo()
194 {
195   return this->GetImpl()->GetRemeshAlgo();
196 }
197
198 void GMSHPlugin_Hypothesis_i::SetRemeshPara (CORBA::Long theValue)
199 {
200   if ( isToSetParameter( GetRemeshPara(), theValue, METH_SetRemeshPara ))
201   {
202     this->GetImpl()->SetRemeshPara((::GMSHPlugin_Hypothesis::RemeshPara)theValue);
203     SMESH::TPythonDump() << _this() << ".SetRemeshAlgo( " << theValue << " )";
204   }
205 }
206
207 CORBA::Long GMSHPlugin_Hypothesis_i::GetRemeshPara()
208 {
209   return this->GetImpl()->GetRemeshPara();
210 }
211
212 void GMSHPlugin_Hypothesis_i::SetSmouthSteps (CORBA::Double theValue)
213 {
214   if ( isToSetParameter( GetSmouthSteps(), theValue, METH_SetSmouthSteps ))
215   {
216     this->GetImpl()->SetSmouthSteps(theValue);
217     SMESH::TPythonDump() << _this() << ".SetSmouthSteps( " << theValue << " )";
218   }
219 }
220
221 CORBA::Double GMSHPlugin_Hypothesis_i::GetSmouthSteps()
222 {
223   return this->GetImpl()->GetSmouthSteps();
224 }
225
226 void GMSHPlugin_Hypothesis_i::SetSizeFactor (CORBA::Double theValue)
227 {
228   if ( isToSetParameter( GetSizeFactor(), theValue, METH_SetSizeFactor ))
229   {
230     this->GetImpl()->SetSizeFactor(theValue);
231     SMESH::TPythonDump() << _this() << ".SetSizeFactor( " << theValue << " )";
232   }
233 }
234
235 CORBA::Double GMSHPlugin_Hypothesis_i::GetSizeFactor()
236 {
237   return this->GetImpl()->GetSizeFactor();
238 }
239
240 void GMSHPlugin_Hypothesis_i::SetUseIncomplElem (CORBA::Boolean theValue)
241 {
242   if ( isToSetParameter( GetUseIncomplElem(), theValue, METH_SetUseIncomplElem ))
243   {
244     this->GetImpl()->SetUseIncomplElem(theValue);
245     SMESH::TPythonDump() << _this() << ".SetUseIncomplElem( " << theValue << " )";
246   }
247 }
248
249 CORBA::Boolean GMSHPlugin_Hypothesis_i::GetUseIncomplElem()
250 {
251   return this->GetImpl()->GetUseIncomplElem();
252 }
253
254 void GMSHPlugin_Hypothesis_i::SetIs2d (CORBA::Boolean theValue)
255 {
256   this->GetImpl()->SetIs2d(theValue);
257   SMESH::TPythonDump() << _this() << ".SetIs2d( " << theValue << " )";
258 }
259
260 void GMSHPlugin_Hypothesis_i::SetCompoundOnShape(GEOM::GEOM_Object_ptr GeomObj)
261 {
262   string entry;
263   entry = GeomObj->GetStudyEntry();
264   SetCompoundOnEntry(entry.c_str());
265 }
266
267 void GMSHPlugin_Hypothesis_i::SetCompoundOnEntry(const char*   entry)
268 {
269   //if ( isToSetParameter( GetCompoundOnEntry(entry), METH_SetCompoundOnEntry ))
270   {
271     this->GetImpl()->SetCompoundOnEntry(entry);
272     SMESH::TPythonDump()
273       << _this() << ".SetCompoundOnShape(" << entry << ")";
274   }
275 }
276
277 GMSHPlugin::string_array* GMSHPlugin_Hypothesis_i::GetCompoundOnEntries()
278 {
279   GMSHPlugin::string_array_var result = new GMSHPlugin::string_array();
280   const ::GMSHPlugin_Hypothesis::TCompound compounds =
281     this->GetImpl()->GetCompoundOnEntries();
282   result->length(compounds.size());
283   ::GMSHPlugin_Hypothesis::TCompound::const_iterator it = compounds.begin();
284   for (int i=0 ; it != compounds.end() ; i++, it++)
285   {
286     string entry = *it;
287     result[i] = CORBA::string_dup(entry.c_str());
288   }
289   return result._retn();
290 }
291
292 void GMSHPlugin_Hypothesis_i::UnsetCompoundOnShape(GEOM::GEOM_Object_ptr GeomObj)
293 {
294   string entry;
295   entry = GeomObj->GetStudyEntry();
296   UnsetCompoundOnEntry(entry.c_str());
297 }
298
299 void GMSHPlugin_Hypothesis_i::UnsetCompoundOnEntry(const char* entry)
300 {
301   this->GetImpl()->UnsetCompoundOnEntry(entry);
302   SMESH::TPythonDump() << _this() << ".UnsetCompoundOnShape(" << entry << ")";
303 }
304
305 ::GMSHPlugin_Hypothesis* GMSHPlugin_Hypothesis_i::GetImpl()
306 {
307   return (::GMSHPlugin_Hypothesis*)myBaseImpl;
308 }
309
310 //================================================================================
311 /*!
312  * \brief Verify whether hypothesis supports given entity type 
313   * \param type - dimension (see SMESH::Dimension enumeration)
314   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
315  * 
316  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
317  */
318 //================================================================================  
319 CORBA::Boolean GMSHPlugin_Hypothesis_i::IsDimSupported( SMESH::Dimension type )
320 {
321   return type == SMESH::DIM_3D;
322 }
323
324 //================================================================================
325 /*!
326  * \brief method intended to remove explicit treatment of Netagen hypotheses from SMESH_NoteBook
327  */
328 //================================================================================
329
330 int GMSHPlugin_Hypothesis_i::getParamIndex(const TCollection_AsciiString& method,
331                                              int nbVars) const
332 {
333   if ( method == "SetMaxSize"        ) return 0;
334   if ( method == "SetGrowthRate"     ) return 1;
335   if ( method == "SetNbSegPerEdge"   ) return 2;
336   if ( method == "SetNbSegPerRadius" ) return 3;
337   if ( method == "SetMinSize" )        return nbVars-1;
338   if ( method == "SetMeshCurvatureSize" )        return 5;
339
340   return SMESH_Hypothesis_i::getParamIndex( method, nbVars ); // return default value
341 }
342
343 //================================================================================
344 /*!
345  * \brief Method used to convert variable parameters stored in an old study
346  * into myMethod2VarParams. It should return a method name for an index of
347  * variable parameters. Index is countered from zero
348  */
349 //================================================================================
350
351 std::string GMSHPlugin_Hypothesis_i::getMethodOfParameter(const int paramIndex,
352                                                             int nbVars) const
353 {
354   switch ( paramIndex ) {
355   case 0: return "SetMaxSize";
356   case 1: return nbVars == 2 ? "SetMinSize" : "SetGrowthRate";
357   case 2: return "SetNbSegPerEdge";
358   case 3: return "SetNbSegPerRadius";
359   case 4: return "SetMinSize";
360   case 5: return "SetMeshCurvatureSize";
361   }
362   return "";
363 }
364
365 //================================================================================
366 /*!
367  * \brief Return geometry this hypothesis depends on. Return false if there is no geometry parameter
368  */
369 //================================================================================
370
371 bool
372 GMSHPlugin_Hypothesis_i::getObjectsDependOn( std::vector< std::string > & entryArray,
373                                              std::vector< int >         & /*subIDArray*/ ) const
374 {
375   typedef ::GMSHPlugin_Hypothesis THyp;
376   const THyp* impl = static_cast<const THyp*>( myBaseImpl );
377
378   const THyp::TCompound& compounds = impl->GetCompoundOnEntries();
379   entryArray.assign( compounds.cbegin(), compounds.cend() );
380
381   return true;
382 }
383
384 //================================================================================
385 /*!
386  * \brief Set new geometry instead of that returned by getObjectsDependOn()
387  */
388 //================================================================================
389
390 bool
391 GMSHPlugin_Hypothesis_i::setObjectsDependOn( std::vector< std::string > & entryArray,
392                                              std::vector< int >         & /*subIDArray*/ )
393 {
394   typedef ::GMSHPlugin_Hypothesis THyp;
395   THyp* impl = static_cast< THyp* >( myBaseImpl );
396
397   size_t iEnt = 0;
398
399   THyp::TCompound& compoundsNew = const_cast< THyp::TCompound& > ( impl->GetCompoundOnEntries() );
400   THyp::TCompound compounds;
401   compounds.swap( compoundsNew );
402
403   THyp::TCompound::const_iterator entry = compounds.cbegin();
404   for ( ; entry != compounds.cend(); ++entry, ++iEnt )
405     if ( !entryArray[ iEnt ].empty() )
406       compoundsNew.insert( entryArray[ iEnt ]);
407
408   return true;
409 }