1 // Copyright (C) 2012-2013 ALNEOS
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.
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.
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
17 // See http://www.alneos.com/ or email : contact@alneos.fr
19 #include "GMSHPlugin_Hypothesis_i.hxx"
20 #include "SMESH_Gen.hxx"
21 #include "SMESH_PythonDump.hxx"
22 #include "GEOM_Object.hxx"
24 #include "Utils_CorbaException.hxx"
25 #include "utilities.h"
30 bool GMSHPlugin_Hypothesis_i::isToSetParameter<double>(double curValue,
32 /*SettingMethod*/int meth)
34 return isToSetParameter(true, (fabs(curValue - newValue) < 1e-20), meth);
37 GMSHPlugin_Hypothesis_i::
38 GMSHPlugin_Hypothesis_i (PortableServer::POA_ptr thePOA,
40 ::SMESH_Gen* theGenImpl)
41 : SALOME::GenericObj_i( thePOA ),
42 SMESH_Hypothesis_i( thePOA ),
45 MESSAGE( "GMSHPlugin_Hypothesis_i::GMSHPlugin_Hypothesis_i" );
46 myBaseImpl = new ::GMSHPlugin_Hypothesis (theGenImpl->GetANewId(),
51 GMSHPlugin_Hypothesis_i::~GMSHPlugin_Hypothesis_i()
53 MESSAGE( "GMSHPlugin_Hypothesis_i::~GMSHPlugin_Hypothesis_i" );
56 void GMSHPlugin_Hypothesis_i::SetMaxSize (CORBA::Double theValue)
58 if ( isToSetParameter( GetMaxSize(), theValue, METH_SetMaxSize ))
60 this->GetImpl()->SetMaxSize(theValue);
61 SMESH::TPythonDump() << _this() << ".SetMaxSize( " << SMESH::TVar(theValue) << " )";
65 CORBA::Double GMSHPlugin_Hypothesis_i::GetMaxSize()
67 return this->GetImpl()->GetMaxSize();
70 void GMSHPlugin_Hypothesis_i::SetMinSize (CORBA::Double theValue)
72 if ( isToSetParameter( GetMinSize(), theValue, METH_SetMinSize ))
74 this->GetImpl()->SetMinSize(theValue);
75 SMESH::TPythonDump() << _this() << ".SetMinSize( " << SMESH::TVar(theValue) << " )";
79 CORBA::Double GMSHPlugin_Hypothesis_i::GetMinSize()
81 return this->GetImpl()->GetMinSize();
84 void GMSHPlugin_Hypothesis_i::SetSecondOrder (CORBA::Boolean theValue)
86 if ( isToSetParameter( GetSecondOrder(), theValue, METH_SetSecondOrder ))
88 this->GetImpl()->SetSecondOrder(theValue);
89 SMESH::TPythonDump() << _this() << ".SetSecondOrder( " << theValue << " )";
93 CORBA::Boolean GMSHPlugin_Hypothesis_i::GetSecondOrder()
95 return this->GetImpl()->GetSecondOrder();
98 void GMSHPlugin_Hypothesis_i::Set2DAlgo (CORBA::Long theValue)
100 if ( isToSetParameter( Get2DAlgo(), theValue, METH_Set2DAlgo ))
102 this->GetImpl()->Set2DAlgo((::GMSHPlugin_Hypothesis::Algo2D)theValue);
103 SMESH::TPythonDump() << _this() << ".Set2DAlgo( " << theValue << " )";
107 CORBA::Long GMSHPlugin_Hypothesis_i::Get2DAlgo()
109 return this->GetImpl()->Get2DAlgo();
112 void GMSHPlugin_Hypothesis_i::Set3DAlgo (CORBA::Long theValue)
114 if ( isToSetParameter( Get3DAlgo(), theValue, METH_Set3DAlgo ))
116 this->GetImpl()->Set3DAlgo((::GMSHPlugin_Hypothesis::Algo3D)theValue);
117 SMESH::TPythonDump() << _this() << ".Set3DAlgo( " << theValue << " )";
121 CORBA::Long GMSHPlugin_Hypothesis_i::Get3DAlgo()
123 return this->GetImpl()->Get3DAlgo();
126 void GMSHPlugin_Hypothesis_i::SetRecomb2DAlgo (CORBA::Long theValue)
128 if ( isToSetParameter( GetRecomb2DAlgo(), theValue, METH_SetRecomb2DAlgo ))
130 this->GetImpl()->SetRecomb2DAlgo((::GMSHPlugin_Hypothesis::Recomb2DAlgo)theValue);
131 SMESH::TPythonDump() << _this() << ".SetRecomb2DAlgo( " << theValue << " )";
135 CORBA::Long GMSHPlugin_Hypothesis_i::GetRecomb2DAlgo()
137 return this->GetImpl()->GetRecomb2DAlgo();
140 void GMSHPlugin_Hypothesis_i::SetRecombineAll (CORBA::Boolean theValue)
142 if ( isToSetParameter( GetRecombineAll(), theValue, METH_SetRecombineAll ))
144 this->GetImpl()->SetRecombineAll(theValue);
145 SMESH::TPythonDump() << _this() << ".SetRecombineAll( " << theValue << " )";
149 CORBA::Boolean GMSHPlugin_Hypothesis_i::GetRecombineAll()
151 return this->GetImpl()->GetRecombineAll();
154 void GMSHPlugin_Hypothesis_i::SetSubdivAlgo (CORBA::Long theValue)
156 if ( isToSetParameter( GetSubdivAlgo(), theValue, METH_SetSubdivAlgo ))
158 this->GetImpl()->SetSubdivAlgo((::GMSHPlugin_Hypothesis::SubdivAlgo)theValue);
159 SMESH::TPythonDump() << _this() << ".SetSubdivAlgo( " << theValue << " )";
163 CORBA::Long GMSHPlugin_Hypothesis_i::GetSubdivAlgo()
165 return this->GetImpl()->GetSubdivAlgo();
168 void GMSHPlugin_Hypothesis_i::SetRemeshAlgo (CORBA::Long theValue)
170 if ( isToSetParameter( GetRemeshAlgo(), theValue, METH_SetRemeshAlgo ))
172 this->GetImpl()->SetRemeshAlgo((::GMSHPlugin_Hypothesis::RemeshAlgo)theValue);
173 SMESH::TPythonDump() << _this() << ".SetRemeshAlgo( " << theValue << " )";
177 CORBA::Long GMSHPlugin_Hypothesis_i::GetRemeshAlgo()
179 return this->GetImpl()->GetRemeshAlgo();
182 void GMSHPlugin_Hypothesis_i::SetRemeshPara (CORBA::Long theValue)
184 if ( isToSetParameter( GetRemeshPara(), theValue, METH_SetRemeshPara ))
186 this->GetImpl()->SetRemeshPara((::GMSHPlugin_Hypothesis::RemeshPara)theValue);
187 SMESH::TPythonDump() << _this() << ".SetRemeshAlgo( " << theValue << " )";
191 CORBA::Long GMSHPlugin_Hypothesis_i::GetRemeshPara()
193 return this->GetImpl()->GetRemeshPara();
196 void GMSHPlugin_Hypothesis_i::SetSmouthSteps (CORBA::Double theValue)
198 if ( isToSetParameter( GetSmouthSteps(), theValue, METH_SetSmouthSteps ))
200 this->GetImpl()->SetSmouthSteps(theValue);
201 SMESH::TPythonDump() << _this() << ".SetSmouthSteps( " << theValue << " )";
205 CORBA::Double GMSHPlugin_Hypothesis_i::GetSmouthSteps()
207 return this->GetImpl()->GetSmouthSteps();
210 void GMSHPlugin_Hypothesis_i::SetSizeFactor (CORBA::Double theValue)
212 if ( isToSetParameter( GetSizeFactor(), theValue, METH_SetSizeFactor ))
214 this->GetImpl()->SetSizeFactor(theValue);
215 SMESH::TPythonDump() << _this() << ".SetSizeFactor( " << theValue << " )";
219 CORBA::Double GMSHPlugin_Hypothesis_i::GetSizeFactor()
221 return this->GetImpl()->GetSizeFactor();
224 void GMSHPlugin_Hypothesis_i::SetUseIncomplElem (CORBA::Boolean theValue)
226 if ( isToSetParameter( GetUseIncomplElem(), theValue, METH_SetUseIncomplElem ))
228 this->GetImpl()->SetUseIncomplElem(theValue);
229 SMESH::TPythonDump() << _this() << ".SetUseIncomplElem( " << theValue << " )";
233 CORBA::Boolean GMSHPlugin_Hypothesis_i::GetUseIncomplElem()
235 return this->GetImpl()->GetUseIncomplElem();
238 void GMSHPlugin_Hypothesis_i::SetIs2d (CORBA::Boolean theValue)
240 this->GetImpl()->SetIs2d(theValue);
241 SMESH::TPythonDump() << _this() << ".SetIs2d( " << theValue << " )";
244 void GMSHPlugin_Hypothesis_i::SetCompoundOnShape(GEOM::GEOM_Object_ptr GeomObj)
247 entry = GeomObj->GetStudyEntry();
248 SetCompoundOnEntry(entry.c_str());
251 void GMSHPlugin_Hypothesis_i::SetCompoundOnEntry(const char* entry)
253 //if ( isToSetParameter( GetCompoundOnEntry(entry), METH_SetCompoundOnEntry ))
255 this->GetImpl()->SetCompoundOnEntry(entry);
257 << _this() << ".SetCompoundOnShape(" << entry << ")";
261 GMSHPlugin::string_array* GMSHPlugin_Hypothesis_i::GetCompoundOnEntries()
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++)
271 result[i] = CORBA::string_dup(entry.c_str());
273 return result._retn();
276 void GMSHPlugin_Hypothesis_i::UnsetCompoundOnShape(GEOM::GEOM_Object_ptr GeomObj)
279 entry = GeomObj->GetStudyEntry();
280 UnsetCompoundOnEntry(entry.c_str());
283 void GMSHPlugin_Hypothesis_i::UnsetCompoundOnEntry(const char* entry)
285 this->GetImpl()->UnsetCompoundOnEntry(entry);
286 SMESH::TPythonDump() << _this() << ".UnsetCompoundOnShape(" << entry << ")";
289 ::GMSHPlugin_Hypothesis* GMSHPlugin_Hypothesis_i::GetImpl()
291 return (::GMSHPlugin_Hypothesis*)myBaseImpl;
294 //================================================================================
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
300 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
302 //================================================================================
303 CORBA::Boolean GMSHPlugin_Hypothesis_i::IsDimSupported( SMESH::Dimension type )
305 return type == SMESH::DIM_3D;
308 //================================================================================
310 * \brief method intended to remove explicit treatment of Netagen hypotheses from SMESH_NoteBook
312 //================================================================================
314 int GMSHPlugin_Hypothesis_i::getParamIndex(const TCollection_AsciiString& method,
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;
323 return SMESH_Hypothesis_i::getParamIndex( method, nbVars ); // return default value
326 //================================================================================
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
332 //================================================================================
334 std::string GMSHPlugin_Hypothesis_i::getMethodOfParameter(const int paramIndex,
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";