]> SALOME platform Git repositories - plugins/gmshplugin.git/blob - src/GMSHPlugin/GMSHPlugin_Hypothesis_i.cxx
Salome HOME
548629b387d53a0af24af54a3544196c39108359
[plugins/gmshplugin.git] / src / GMSHPlugin / GMSHPlugin_Hypothesis_i.cxx
1 // Copyright (C) 2012-2013  ALNEOS
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.alneos.com/ or email : contact@alneos.fr
18 //
19 #include "GMSHPlugin_Hypothesis_i.hxx"
20 #include "SMESH_Gen.hxx"
21 #include "SMESH_PythonDump.hxx"
22 #include "GEOM_Object.hxx"
23
24 #include "Utils_CorbaException.hxx"
25 #include "utilities.h"
26
27 using namespace std;
28
29 template<>
30 bool GMSHPlugin_Hypothesis_i::isToSetParameter<double>(double curValue,
31                                                          double newValue,
32                                                          /*SettingMethod*/int meth)
33 {
34   return isToSetParameter(true, (fabs(curValue - newValue) < 1e-20), meth);
35 }
36
37 GMSHPlugin_Hypothesis_i::
38 GMSHPlugin_Hypothesis_i (PortableServer::POA_ptr thePOA,
39                            int                     theStudyId,
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                                               theStudyId,
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 void GMSHPlugin_Hypothesis_i::SetMinSize (CORBA::Double theValue)
71 {
72   if ( isToSetParameter( GetMinSize(), theValue, METH_SetMinSize ))
73   {
74     this->GetImpl()->SetMinSize(theValue);
75     SMESH::TPythonDump() << _this() << ".SetMinSize( " << SMESH::TVar(theValue) << " )";
76   }
77 }
78
79 CORBA::Double GMSHPlugin_Hypothesis_i::GetMinSize()
80 {
81   return this->GetImpl()->GetMinSize();
82 }
83
84 void GMSHPlugin_Hypothesis_i::SetSecondOrder (CORBA::Boolean theValue)
85 {
86   if ( isToSetParameter( GetSecondOrder(), theValue, METH_SetSecondOrder ))
87   {
88     this->GetImpl()->SetSecondOrder(theValue);
89     SMESH::TPythonDump() << _this() << ".SetSecondOrder( " << theValue << " )";
90   }
91 }
92
93 CORBA::Boolean GMSHPlugin_Hypothesis_i::GetSecondOrder()
94 {
95   return this->GetImpl()->GetSecondOrder();
96 }
97
98 void GMSHPlugin_Hypothesis_i::Set2DAlgo (CORBA::Long theValue)
99 {
100   if ( isToSetParameter( Get2DAlgo(), theValue, METH_Set2DAlgo ))
101   {
102     this->GetImpl()->Set2DAlgo((::GMSHPlugin_Hypothesis::Algo2D)theValue);
103     SMESH::TPythonDump() << _this() << ".Set2DAlgo( " << theValue << " )";
104   }
105 }
106
107 CORBA::Long GMSHPlugin_Hypothesis_i::Get2DAlgo()
108 {
109   return this->GetImpl()->Get2DAlgo();
110 }
111
112 void GMSHPlugin_Hypothesis_i::Set3DAlgo (CORBA::Long theValue)
113 {
114   if ( isToSetParameter( Get3DAlgo(), theValue, METH_Set3DAlgo ))
115   {
116     this->GetImpl()->Set3DAlgo((::GMSHPlugin_Hypothesis::Algo3D)theValue);
117     SMESH::TPythonDump() << _this() << ".Set3DAlgo( " << theValue << " )";
118   }
119 }
120
121 CORBA::Long GMSHPlugin_Hypothesis_i::Get3DAlgo()
122 {
123   return this->GetImpl()->Get3DAlgo();
124 }
125
126 void GMSHPlugin_Hypothesis_i::SetRecomb2DAlgo (CORBA::Long theValue)
127 {
128   if ( isToSetParameter( GetRecomb2DAlgo(), theValue, METH_SetRecomb2DAlgo ))
129   {
130     this->GetImpl()->SetRecomb2DAlgo((::GMSHPlugin_Hypothesis::Recomb2DAlgo)theValue);
131     SMESH::TPythonDump() << _this() << ".SetRecomb2DAlgo( " << theValue << " )";
132   }
133 }
134
135 CORBA::Long GMSHPlugin_Hypothesis_i::GetRecomb2DAlgo()
136 {
137   return this->GetImpl()->GetRecomb2DAlgo();
138 }
139
140 void GMSHPlugin_Hypothesis_i::SetRecombineAll (CORBA::Boolean theValue)
141 {
142   if ( isToSetParameter( GetRecombineAll(), theValue, METH_SetRecombineAll ))
143   {
144     this->GetImpl()->SetRecombineAll(theValue);
145     SMESH::TPythonDump() << _this() << ".SetRecombineAll( " << theValue << " )";
146   }
147 }
148
149 CORBA::Boolean GMSHPlugin_Hypothesis_i::GetRecombineAll()
150 {
151   return this->GetImpl()->GetRecombineAll();
152 }
153
154 void GMSHPlugin_Hypothesis_i::SetSubdivAlgo (CORBA::Long theValue)
155 {
156   if ( isToSetParameter( GetSubdivAlgo(), theValue, METH_SetSubdivAlgo ))
157   {
158     this->GetImpl()->SetSubdivAlgo((::GMSHPlugin_Hypothesis::SubdivAlgo)theValue);
159     SMESH::TPythonDump() << _this() << ".SetSubdivAlgo( " << theValue << " )";
160   }
161 }
162
163 CORBA::Long GMSHPlugin_Hypothesis_i::GetSubdivAlgo()
164 {
165   return this->GetImpl()->GetSubdivAlgo();
166 }
167
168 void GMSHPlugin_Hypothesis_i::SetRemeshAlgo (CORBA::Long theValue)
169 {
170   if ( isToSetParameter( GetRemeshAlgo(), theValue, METH_SetRemeshAlgo ))
171   {
172     this->GetImpl()->SetRemeshAlgo((::GMSHPlugin_Hypothesis::RemeshAlgo)theValue);
173     SMESH::TPythonDump() << _this() << ".SetRemeshAlgo( " << theValue << " )";
174   }
175 }
176
177 CORBA::Long GMSHPlugin_Hypothesis_i::GetRemeshAlgo()
178 {
179   return this->GetImpl()->GetRemeshAlgo();
180 }
181
182 void GMSHPlugin_Hypothesis_i::SetRemeshPara (CORBA::Long theValue)
183 {
184   if ( isToSetParameter( GetRemeshPara(), theValue, METH_SetRemeshPara ))
185   {
186     this->GetImpl()->SetRemeshPara((::GMSHPlugin_Hypothesis::RemeshPara)theValue);
187     SMESH::TPythonDump() << _this() << ".SetRemeshAlgo( " << theValue << " )";
188   }
189 }
190
191 CORBA::Long GMSHPlugin_Hypothesis_i::GetRemeshPara()
192 {
193   return this->GetImpl()->GetRemeshPara();
194 }
195
196 void GMSHPlugin_Hypothesis_i::SetSmouthSteps (CORBA::Double theValue)
197 {
198   if ( isToSetParameter( GetSmouthSteps(), theValue, METH_SetSmouthSteps ))
199   {
200     this->GetImpl()->SetSmouthSteps(theValue);
201     SMESH::TPythonDump() << _this() << ".SetSmouthSteps( " << theValue << " )";
202   }
203 }
204
205 CORBA::Double GMSHPlugin_Hypothesis_i::GetSmouthSteps()
206 {
207   return this->GetImpl()->GetSmouthSteps();
208 }
209
210 void GMSHPlugin_Hypothesis_i::SetSizeFactor (CORBA::Double theValue)
211 {
212   if ( isToSetParameter( GetSizeFactor(), theValue, METH_SetSizeFactor ))
213   {
214     this->GetImpl()->SetSizeFactor(theValue);
215     SMESH::TPythonDump() << _this() << ".SetSizeFactor( " << theValue << " )";
216   }
217 }
218
219 CORBA::Double GMSHPlugin_Hypothesis_i::GetSizeFactor()
220 {
221   return this->GetImpl()->GetSizeFactor();
222 }
223
224 void GMSHPlugin_Hypothesis_i::SetUseIncomplElem (CORBA::Boolean theValue)
225 {
226   if ( isToSetParameter( GetUseIncomplElem(), theValue, METH_SetUseIncomplElem ))
227   {
228     this->GetImpl()->SetUseIncomplElem(theValue);
229     SMESH::TPythonDump() << _this() << ".SetUseIncomplElem( " << theValue << " )";
230   }
231 }
232
233 CORBA::Boolean GMSHPlugin_Hypothesis_i::GetUseIncomplElem()
234 {
235   return this->GetImpl()->GetUseIncomplElem();
236 }
237
238 void GMSHPlugin_Hypothesis_i::SetIs2d (CORBA::Boolean theValue)
239 {
240   this->GetImpl()->SetIs2d(theValue);
241   SMESH::TPythonDump() << _this() << ".SetIs2d( " << theValue << " )";
242 }
243
244 void GMSHPlugin_Hypothesis_i::SetCompoundOnShape(GEOM::GEOM_Object_ptr GeomObj)
245 {
246   string entry;
247   entry = GeomObj->GetStudyEntry();
248   SetCompoundOnEntry(entry.c_str());
249 }
250
251 void GMSHPlugin_Hypothesis_i::SetCompoundOnEntry(const char*   entry)
252 {
253   //if ( isToSetParameter( GetCompoundOnEntry(entry), METH_SetCompoundOnEntry ))
254   {
255     this->GetImpl()->SetCompoundOnEntry(entry);
256     SMESH::TPythonDump()
257       << _this() << ".SetCompoundOnShape(" << entry << ")";
258   }
259 }
260
261 GMSHPlugin::string_array* GMSHPlugin_Hypothesis_i::GetCompoundOnEntries()
262 {
263   GMSHPlugin::string_array_var result = new GMSHPlugin::string_array();
264   const ::GMSHPlugin_Hypothesis::TCompound compounds =
265     this->GetImpl()->GetCompoundOnEntries();
266   result->length(compounds.size());
267   ::GMSHPlugin_Hypothesis::TCompound::const_iterator it = compounds.begin();
268   for (int i=0 ; it != compounds.end() ; i++, it++)
269   {
270     string entry = *it;
271     result[i] = CORBA::string_dup(entry.c_str());
272   }
273   return result._retn();
274 }
275
276 void GMSHPlugin_Hypothesis_i::UnsetCompoundOnShape(GEOM::GEOM_Object_ptr GeomObj)
277 {
278   string entry;
279   entry = GeomObj->GetStudyEntry();
280   UnsetCompoundOnEntry(entry.c_str());
281 }
282
283 void GMSHPlugin_Hypothesis_i::UnsetCompoundOnEntry(const char* entry)
284 {
285   this->GetImpl()->UnsetCompoundOnEntry(entry);
286   SMESH::TPythonDump() << _this() << ".UnsetCompoundOnShape(" << entry << ")";
287 }
288
289 ::GMSHPlugin_Hypothesis* GMSHPlugin_Hypothesis_i::GetImpl()
290 {
291   return (::GMSHPlugin_Hypothesis*)myBaseImpl;
292 }
293
294 //================================================================================
295 /*!
296  * \brief Verify whether hypothesis supports given entity type 
297   * \param type - dimension (see SMESH::Dimension enumeration)
298   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
299  * 
300  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
301  */
302 //================================================================================  
303 CORBA::Boolean GMSHPlugin_Hypothesis_i::IsDimSupported( SMESH::Dimension type )
304 {
305   return type == SMESH::DIM_3D;
306 }
307
308 //================================================================================
309 /*!
310  * \brief method intended to remove explicit treatment of Netagen hypotheses from SMESH_NoteBook
311  */
312 //================================================================================
313
314 int GMSHPlugin_Hypothesis_i::getParamIndex(const TCollection_AsciiString& method,
315                                              int nbVars) const
316 {
317   if ( method == "SetMaxSize"        ) return 0;
318   if ( method == "SetGrowthRate"     ) return 1;
319   if ( method == "SetNbSegPerEdge"   ) return 2;
320   if ( method == "SetNbSegPerRadius" ) return 3;
321   if ( method == "SetMinSize" )        return nbVars-1;
322
323   return SMESH_Hypothesis_i::getParamIndex( method, nbVars ); // return default value
324 }
325
326 //================================================================================
327 /*!
328  * \brief Method used to convert variable parameters stored in an old study
329  * into myMethod2VarParams. It should return a method name for an index of
330  * variable parameters. Index is countered from zero
331  */
332 //================================================================================
333
334 std::string GMSHPlugin_Hypothesis_i::getMethodOfParameter(const int paramIndex,
335                                                             int nbVars) const
336 {
337   switch ( paramIndex ) {
338   case 0: return "SetMaxSize";
339   case 1: return nbVars == 2 ? "SetMinSize" : "SetGrowthRate";
340   case 2: return "SetNbSegPerEdge";
341   case 3: return "SetNbSegPerRadius";
342   case 4: return "SetMinSize";
343   }
344   return "";
345 }