]> SALOME platform Git repositories - plugins/gmshplugin.git/blob - src/GMSHPlugin/GMSHPlugin_Hypothesis_i.cxx
Salome HOME
453074b533d5301ba8aa8ac85bac7f69f55b7e57
[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                            int                     theStudyId,
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                                               theStudyId,
49                                               theGenImpl);
50 }
51
52 GMSHPlugin_Hypothesis_i::~GMSHPlugin_Hypothesis_i()
53 {
54   MESSAGE( "GMSHPlugin_Hypothesis_i::~GMSHPlugin_Hypothesis_i" );
55 }
56
57 void GMSHPlugin_Hypothesis_i::SetMaxSize (CORBA::Double theValue)
58 {
59   if ( isToSetParameter( GetMaxSize(), theValue, METH_SetMaxSize ))
60   {
61     this->GetImpl()->SetMaxSize(theValue);
62     SMESH::TPythonDump() << _this() << ".SetMaxSize( " << SMESH::TVar(theValue) << " )";
63   }
64 }
65
66 CORBA::Double GMSHPlugin_Hypothesis_i::GetMaxSize()
67 {
68   return this->GetImpl()->GetMaxSize();
69 }
70
71 void GMSHPlugin_Hypothesis_i::SetMinSize (CORBA::Double theValue)
72 {
73   if ( isToSetParameter( GetMinSize(), theValue, METH_SetMinSize ))
74   {
75     this->GetImpl()->SetMinSize(theValue);
76     SMESH::TPythonDump() << _this() << ".SetMinSize( " << SMESH::TVar(theValue) << " )";
77   }
78 }
79
80 CORBA::Double GMSHPlugin_Hypothesis_i::GetMinSize()
81 {
82   return this->GetImpl()->GetMinSize();
83 }
84
85 void GMSHPlugin_Hypothesis_i::SetSecondOrder (CORBA::Boolean theValue)
86 {
87   if ( isToSetParameter( GetSecondOrder(), theValue, METH_SetSecondOrder ))
88   {
89     this->GetImpl()->SetSecondOrder(theValue);
90     SMESH::TPythonDump() << _this() << ".SetSecondOrder( " << theValue << " )";
91   }
92 }
93
94 CORBA::Boolean GMSHPlugin_Hypothesis_i::GetSecondOrder()
95 {
96   return this->GetImpl()->GetSecondOrder();
97 }
98
99 void GMSHPlugin_Hypothesis_i::Set2DAlgo (CORBA::Long theValue)
100 {
101   if ( isToSetParameter( Get2DAlgo(), theValue, METH_Set2DAlgo ))
102   {
103     this->GetImpl()->Set2DAlgo((::GMSHPlugin_Hypothesis::Algo2D)theValue);
104     SMESH::TPythonDump() << _this() << ".Set2DAlgo( " << theValue << " )";
105   }
106 }
107
108 CORBA::Long GMSHPlugin_Hypothesis_i::Get2DAlgo()
109 {
110   return this->GetImpl()->Get2DAlgo();
111 }
112
113 void GMSHPlugin_Hypothesis_i::Set3DAlgo (CORBA::Long theValue)
114 {
115   if ( isToSetParameter( Get3DAlgo(), theValue, METH_Set3DAlgo ))
116   {
117     this->GetImpl()->Set3DAlgo((::GMSHPlugin_Hypothesis::Algo3D)theValue);
118     SMESH::TPythonDump() << _this() << ".Set3DAlgo( " << theValue << " )";
119   }
120 }
121
122 CORBA::Long GMSHPlugin_Hypothesis_i::Get3DAlgo()
123 {
124   return this->GetImpl()->Get3DAlgo();
125 }
126
127 void GMSHPlugin_Hypothesis_i::SetRecomb2DAlgo (CORBA::Long theValue)
128 {
129   if ( isToSetParameter( GetRecomb2DAlgo(), theValue, METH_SetRecomb2DAlgo ))
130   {
131     this->GetImpl()->SetRecomb2DAlgo((::GMSHPlugin_Hypothesis::Recomb2DAlgo)theValue);
132     SMESH::TPythonDump() << _this() << ".SetRecomb2DAlgo( " << theValue << " )";
133   }
134 }
135
136 CORBA::Long GMSHPlugin_Hypothesis_i::GetRecomb2DAlgo()
137 {
138   return this->GetImpl()->GetRecomb2DAlgo();
139 }
140
141 void GMSHPlugin_Hypothesis_i::SetRecombineAll (CORBA::Boolean theValue)
142 {
143   if ( isToSetParameter( GetRecombineAll(), theValue, METH_SetRecombineAll ))
144   {
145     this->GetImpl()->SetRecombineAll(theValue);
146     SMESH::TPythonDump() << _this() << ".SetRecombineAll( " << theValue << " )";
147   }
148 }
149
150 CORBA::Boolean GMSHPlugin_Hypothesis_i::GetRecombineAll()
151 {
152   return this->GetImpl()->GetRecombineAll();
153 }
154
155 void GMSHPlugin_Hypothesis_i::SetSubdivAlgo (CORBA::Long theValue)
156 {
157   if ( isToSetParameter( GetSubdivAlgo(), theValue, METH_SetSubdivAlgo ))
158   {
159     this->GetImpl()->SetSubdivAlgo((::GMSHPlugin_Hypothesis::SubdivAlgo)theValue);
160     SMESH::TPythonDump() << _this() << ".SetSubdivAlgo( " << theValue << " )";
161   }
162 }
163
164 CORBA::Long GMSHPlugin_Hypothesis_i::GetSubdivAlgo()
165 {
166   return this->GetImpl()->GetSubdivAlgo();
167 }
168
169 void GMSHPlugin_Hypothesis_i::SetRemeshAlgo (CORBA::Long theValue)
170 {
171   if ( isToSetParameter( GetRemeshAlgo(), theValue, METH_SetRemeshAlgo ))
172   {
173     this->GetImpl()->SetRemeshAlgo((::GMSHPlugin_Hypothesis::RemeshAlgo)theValue);
174     SMESH::TPythonDump() << _this() << ".SetRemeshAlgo( " << theValue << " )";
175   }
176 }
177
178 CORBA::Long GMSHPlugin_Hypothesis_i::GetRemeshAlgo()
179 {
180   return this->GetImpl()->GetRemeshAlgo();
181 }
182
183 void GMSHPlugin_Hypothesis_i::SetRemeshPara (CORBA::Long theValue)
184 {
185   if ( isToSetParameter( GetRemeshPara(), theValue, METH_SetRemeshPara ))
186   {
187     this->GetImpl()->SetRemeshPara((::GMSHPlugin_Hypothesis::RemeshPara)theValue);
188     SMESH::TPythonDump() << _this() << ".SetRemeshAlgo( " << theValue << " )";
189   }
190 }
191
192 CORBA::Long GMSHPlugin_Hypothesis_i::GetRemeshPara()
193 {
194   return this->GetImpl()->GetRemeshPara();
195 }
196
197 void GMSHPlugin_Hypothesis_i::SetSmouthSteps (CORBA::Double theValue)
198 {
199   if ( isToSetParameter( GetSmouthSteps(), theValue, METH_SetSmouthSteps ))
200   {
201     this->GetImpl()->SetSmouthSteps(theValue);
202     SMESH::TPythonDump() << _this() << ".SetSmouthSteps( " << theValue << " )";
203   }
204 }
205
206 CORBA::Double GMSHPlugin_Hypothesis_i::GetSmouthSteps()
207 {
208   return this->GetImpl()->GetSmouthSteps();
209 }
210
211 void GMSHPlugin_Hypothesis_i::SetSizeFactor (CORBA::Double theValue)
212 {
213   if ( isToSetParameter( GetSizeFactor(), theValue, METH_SetSizeFactor ))
214   {
215     this->GetImpl()->SetSizeFactor(theValue);
216     SMESH::TPythonDump() << _this() << ".SetSizeFactor( " << theValue << " )";
217   }
218 }
219
220 CORBA::Double GMSHPlugin_Hypothesis_i::GetSizeFactor()
221 {
222   return this->GetImpl()->GetSizeFactor();
223 }
224
225 void GMSHPlugin_Hypothesis_i::SetUseIncomplElem (CORBA::Boolean theValue)
226 {
227   if ( isToSetParameter( GetUseIncomplElem(), theValue, METH_SetUseIncomplElem ))
228   {
229     this->GetImpl()->SetUseIncomplElem(theValue);
230     SMESH::TPythonDump() << _this() << ".SetUseIncomplElem( " << theValue << " )";
231   }
232 }
233
234 CORBA::Boolean GMSHPlugin_Hypothesis_i::GetUseIncomplElem()
235 {
236   return this->GetImpl()->GetUseIncomplElem();
237 }
238
239 void GMSHPlugin_Hypothesis_i::SetIs2d (CORBA::Boolean theValue)
240 {
241   this->GetImpl()->SetIs2d(theValue);
242   SMESH::TPythonDump() << _this() << ".SetIs2d( " << theValue << " )";
243 }
244
245 void GMSHPlugin_Hypothesis_i::SetCompoundOnShape(GEOM::GEOM_Object_ptr GeomObj)
246 {
247   string entry;
248   entry = GeomObj->GetStudyEntry();
249   SetCompoundOnEntry(entry.c_str());
250 }
251
252 void GMSHPlugin_Hypothesis_i::SetCompoundOnEntry(const char*   entry)
253 {
254   //if ( isToSetParameter( GetCompoundOnEntry(entry), METH_SetCompoundOnEntry ))
255   {
256     this->GetImpl()->SetCompoundOnEntry(entry);
257     SMESH::TPythonDump()
258       << _this() << ".SetCompoundOnShape(" << entry << ")";
259   }
260 }
261
262 GMSHPlugin::string_array* GMSHPlugin_Hypothesis_i::GetCompoundOnEntries()
263 {
264   GMSHPlugin::string_array_var result = new GMSHPlugin::string_array();
265   const ::GMSHPlugin_Hypothesis::TCompound compounds =
266     this->GetImpl()->GetCompoundOnEntries();
267   result->length(compounds.size());
268   ::GMSHPlugin_Hypothesis::TCompound::const_iterator it = compounds.begin();
269   for (int i=0 ; it != compounds.end() ; i++, it++)
270   {
271     string entry = *it;
272     result[i] = CORBA::string_dup(entry.c_str());
273   }
274   return result._retn();
275 }
276
277 void GMSHPlugin_Hypothesis_i::UnsetCompoundOnShape(GEOM::GEOM_Object_ptr GeomObj)
278 {
279   string entry;
280   entry = GeomObj->GetStudyEntry();
281   UnsetCompoundOnEntry(entry.c_str());
282 }
283
284 void GMSHPlugin_Hypothesis_i::UnsetCompoundOnEntry(const char* entry)
285 {
286   this->GetImpl()->UnsetCompoundOnEntry(entry);
287   SMESH::TPythonDump() << _this() << ".UnsetCompoundOnShape(" << entry << ")";
288 }
289
290 ::GMSHPlugin_Hypothesis* GMSHPlugin_Hypothesis_i::GetImpl()
291 {
292   return (::GMSHPlugin_Hypothesis*)myBaseImpl;
293 }
294
295 //================================================================================
296 /*!
297  * \brief Verify whether hypothesis supports given entity type 
298   * \param type - dimension (see SMESH::Dimension enumeration)
299   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
300  * 
301  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
302  */
303 //================================================================================  
304 CORBA::Boolean GMSHPlugin_Hypothesis_i::IsDimSupported( SMESH::Dimension type )
305 {
306   return type == SMESH::DIM_3D;
307 }
308
309 //================================================================================
310 /*!
311  * \brief method intended to remove explicit treatment of Netagen hypotheses from SMESH_NoteBook
312  */
313 //================================================================================
314
315 int GMSHPlugin_Hypothesis_i::getParamIndex(const TCollection_AsciiString& method,
316                                              int nbVars) const
317 {
318   if ( method == "SetMaxSize"        ) return 0;
319   if ( method == "SetGrowthRate"     ) return 1;
320   if ( method == "SetNbSegPerEdge"   ) return 2;
321   if ( method == "SetNbSegPerRadius" ) return 3;
322   if ( method == "SetMinSize" )        return nbVars-1;
323
324   return SMESH_Hypothesis_i::getParamIndex( method, nbVars ); // return default value
325 }
326
327 //================================================================================
328 /*!
329  * \brief Method used to convert variable parameters stored in an old study
330  * into myMethod2VarParams. It should return a method name for an index of
331  * variable parameters. Index is countered from zero
332  */
333 //================================================================================
334
335 std::string GMSHPlugin_Hypothesis_i::getMethodOfParameter(const int paramIndex,
336                                                             int nbVars) const
337 {
338   switch ( paramIndex ) {
339   case 0: return "SetMaxSize";
340   case 1: return nbVars == 2 ? "SetMinSize" : "SetGrowthRate";
341   case 2: return "SetNbSegPerEdge";
342   case 3: return "SetNbSegPerRadius";
343   case 4: return "SetMinSize";
344   }
345   return "";
346 }