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