1 // Copyright (C) 2012-2015 ALNEOS
2 // Copyright (C) 2016 EDF R&D
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.
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.
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
18 // See http://www.alneos.com/ or email : contact@alneos.fr
20 #include "GMSHPlugin_Hypothesis_i.hxx"
21 #include "SMESH_Gen.hxx"
22 #include "SMESH_PythonDump.hxx"
23 #include "GEOM_Object.hxx"
25 #include "Utils_CorbaException.hxx"
26 #include "utilities.h"
31 bool GMSHPlugin_Hypothesis_i::isToSetParameter<double>(double curValue,
33 /*SettingMethod*/int meth)
35 return isToSetParameter(true, (fabs(curValue - newValue) < 1e-20), meth);
38 GMSHPlugin_Hypothesis_i::
39 GMSHPlugin_Hypothesis_i (PortableServer::POA_ptr thePOA,
41 ::SMESH_Gen* theGenImpl)
42 : SALOME::GenericObj_i( thePOA ),
43 SMESH_Hypothesis_i( thePOA ),
46 MESSAGE( "GMSHPlugin_Hypothesis_i::GMSHPlugin_Hypothesis_i" );
47 myBaseImpl = new ::GMSHPlugin_Hypothesis (theGenImpl->GetANewId(),
52 GMSHPlugin_Hypothesis_i::~GMSHPlugin_Hypothesis_i()
54 MESSAGE( "GMSHPlugin_Hypothesis_i::~GMSHPlugin_Hypothesis_i" );
57 void GMSHPlugin_Hypothesis_i::SetMaxSize (CORBA::Double theValue)
59 if ( isToSetParameter( GetMaxSize(), theValue, METH_SetMaxSize ))
61 this->GetImpl()->SetMaxSize(theValue);
62 SMESH::TPythonDump() << _this() << ".SetMaxSize( " << SMESH::TVar(theValue) << " )";
66 CORBA::Double GMSHPlugin_Hypothesis_i::GetMaxSize()
68 return this->GetImpl()->GetMaxSize();
71 void GMSHPlugin_Hypothesis_i::SetMinSize (CORBA::Double theValue)
73 if ( isToSetParameter( GetMinSize(), theValue, METH_SetMinSize ))
75 this->GetImpl()->SetMinSize(theValue);
76 SMESH::TPythonDump() << _this() << ".SetMinSize( " << SMESH::TVar(theValue) << " )";
80 CORBA::Double GMSHPlugin_Hypothesis_i::GetMinSize()
82 return this->GetImpl()->GetMinSize();
85 void GMSHPlugin_Hypothesis_i::SetSecondOrder (CORBA::Boolean theValue)
87 if ( isToSetParameter( GetSecondOrder(), theValue, METH_SetSecondOrder ))
89 this->GetImpl()->SetSecondOrder(theValue);
90 SMESH::TPythonDump() << _this() << ".SetSecondOrder( " << theValue << " )";
94 CORBA::Boolean GMSHPlugin_Hypothesis_i::GetSecondOrder()
96 return this->GetImpl()->GetSecondOrder();
99 void GMSHPlugin_Hypothesis_i::Set2DAlgo (CORBA::Long theValue)
101 if ( isToSetParameter( Get2DAlgo(), theValue, METH_Set2DAlgo ))
103 this->GetImpl()->Set2DAlgo((::GMSHPlugin_Hypothesis::Algo2D)theValue);
104 SMESH::TPythonDump() << _this() << ".Set2DAlgo( " << theValue << " )";
108 CORBA::Long GMSHPlugin_Hypothesis_i::Get2DAlgo()
110 return this->GetImpl()->Get2DAlgo();
113 void GMSHPlugin_Hypothesis_i::Set3DAlgo (CORBA::Long theValue)
115 if ( isToSetParameter( Get3DAlgo(), theValue, METH_Set3DAlgo ))
117 this->GetImpl()->Set3DAlgo((::GMSHPlugin_Hypothesis::Algo3D)theValue);
118 SMESH::TPythonDump() << _this() << ".Set3DAlgo( " << theValue << " )";
122 CORBA::Long GMSHPlugin_Hypothesis_i::Get3DAlgo()
124 return this->GetImpl()->Get3DAlgo();
127 void GMSHPlugin_Hypothesis_i::SetRecomb2DAlgo (CORBA::Long theValue)
129 if ( isToSetParameter( GetRecomb2DAlgo(), theValue, METH_SetRecomb2DAlgo ))
131 this->GetImpl()->SetRecomb2DAlgo((::GMSHPlugin_Hypothesis::Recomb2DAlgo)theValue);
132 SMESH::TPythonDump() << _this() << ".SetRecomb2DAlgo( " << theValue << " )";
136 CORBA::Long GMSHPlugin_Hypothesis_i::GetRecomb2DAlgo()
138 return this->GetImpl()->GetRecomb2DAlgo();
141 void GMSHPlugin_Hypothesis_i::SetRecombineAll (CORBA::Boolean theValue)
143 if ( isToSetParameter( GetRecombineAll(), theValue, METH_SetRecombineAll ))
145 this->GetImpl()->SetRecombineAll(theValue);
146 SMESH::TPythonDump() << _this() << ".SetRecombineAll( " << theValue << " )";
150 CORBA::Boolean GMSHPlugin_Hypothesis_i::GetRecombineAll()
152 return this->GetImpl()->GetRecombineAll();
155 void GMSHPlugin_Hypothesis_i::SetSubdivAlgo (CORBA::Long theValue)
157 if ( isToSetParameter( GetSubdivAlgo(), theValue, METH_SetSubdivAlgo ))
159 this->GetImpl()->SetSubdivAlgo((::GMSHPlugin_Hypothesis::SubdivAlgo)theValue);
160 SMESH::TPythonDump() << _this() << ".SetSubdivAlgo( " << theValue << " )";
164 CORBA::Long GMSHPlugin_Hypothesis_i::GetSubdivAlgo()
166 return this->GetImpl()->GetSubdivAlgo();
169 void GMSHPlugin_Hypothesis_i::SetRemeshAlgo (CORBA::Long theValue)
171 if ( isToSetParameter( GetRemeshAlgo(), theValue, METH_SetRemeshAlgo ))
173 this->GetImpl()->SetRemeshAlgo((::GMSHPlugin_Hypothesis::RemeshAlgo)theValue);
174 SMESH::TPythonDump() << _this() << ".SetRemeshAlgo( " << theValue << " )";
178 CORBA::Long GMSHPlugin_Hypothesis_i::GetRemeshAlgo()
180 return this->GetImpl()->GetRemeshAlgo();
183 void GMSHPlugin_Hypothesis_i::SetRemeshPara (CORBA::Long theValue)
185 if ( isToSetParameter( GetRemeshPara(), theValue, METH_SetRemeshPara ))
187 this->GetImpl()->SetRemeshPara((::GMSHPlugin_Hypothesis::RemeshPara)theValue);
188 SMESH::TPythonDump() << _this() << ".SetRemeshAlgo( " << theValue << " )";
192 CORBA::Long GMSHPlugin_Hypothesis_i::GetRemeshPara()
194 return this->GetImpl()->GetRemeshPara();
197 void GMSHPlugin_Hypothesis_i::SetSmouthSteps (CORBA::Double theValue)
199 if ( isToSetParameter( GetSmouthSteps(), theValue, METH_SetSmouthSteps ))
201 this->GetImpl()->SetSmouthSteps(theValue);
202 SMESH::TPythonDump() << _this() << ".SetSmouthSteps( " << theValue << " )";
206 CORBA::Double GMSHPlugin_Hypothesis_i::GetSmouthSteps()
208 return this->GetImpl()->GetSmouthSteps();
211 void GMSHPlugin_Hypothesis_i::SetSizeFactor (CORBA::Double theValue)
213 if ( isToSetParameter( GetSizeFactor(), theValue, METH_SetSizeFactor ))
215 this->GetImpl()->SetSizeFactor(theValue);
216 SMESH::TPythonDump() << _this() << ".SetSizeFactor( " << theValue << " )";
220 CORBA::Double GMSHPlugin_Hypothesis_i::GetSizeFactor()
222 return this->GetImpl()->GetSizeFactor();
225 void GMSHPlugin_Hypothesis_i::SetUseIncomplElem (CORBA::Boolean theValue)
227 if ( isToSetParameter( GetUseIncomplElem(), theValue, METH_SetUseIncomplElem ))
229 this->GetImpl()->SetUseIncomplElem(theValue);
230 SMESH::TPythonDump() << _this() << ".SetUseIncomplElem( " << theValue << " )";
234 CORBA::Boolean GMSHPlugin_Hypothesis_i::GetUseIncomplElem()
236 return this->GetImpl()->GetUseIncomplElem();
239 void GMSHPlugin_Hypothesis_i::SetIs2d (CORBA::Boolean theValue)
241 this->GetImpl()->SetIs2d(theValue);
242 SMESH::TPythonDump() << _this() << ".SetIs2d( " << theValue << " )";
245 void GMSHPlugin_Hypothesis_i::SetCompoundOnShape(GEOM::GEOM_Object_ptr GeomObj)
248 entry = GeomObj->GetStudyEntry();
249 SetCompoundOnEntry(entry.c_str());
252 void GMSHPlugin_Hypothesis_i::SetCompoundOnEntry(const char* entry)
254 //if ( isToSetParameter( GetCompoundOnEntry(entry), METH_SetCompoundOnEntry ))
256 this->GetImpl()->SetCompoundOnEntry(entry);
258 << _this() << ".SetCompoundOnShape(" << entry << ")";
262 GMSHPlugin::string_array* GMSHPlugin_Hypothesis_i::GetCompoundOnEntries()
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++)
272 result[i] = CORBA::string_dup(entry.c_str());
274 return result._retn();
277 void GMSHPlugin_Hypothesis_i::UnsetCompoundOnShape(GEOM::GEOM_Object_ptr GeomObj)
280 entry = GeomObj->GetStudyEntry();
281 UnsetCompoundOnEntry(entry.c_str());
284 void GMSHPlugin_Hypothesis_i::UnsetCompoundOnEntry(const char* entry)
286 this->GetImpl()->UnsetCompoundOnEntry(entry);
287 SMESH::TPythonDump() << _this() << ".UnsetCompoundOnShape(" << entry << ")";
290 ::GMSHPlugin_Hypothesis* GMSHPlugin_Hypothesis_i::GetImpl()
292 return (::GMSHPlugin_Hypothesis*)myBaseImpl;
295 //================================================================================
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
301 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
303 //================================================================================
304 CORBA::Boolean GMSHPlugin_Hypothesis_i::IsDimSupported( SMESH::Dimension type )
306 return type == SMESH::DIM_3D;
309 //================================================================================
311 * \brief method intended to remove explicit treatment of Netagen hypotheses from SMESH_NoteBook
313 //================================================================================
315 int GMSHPlugin_Hypothesis_i::getParamIndex(const TCollection_AsciiString& method,
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;
324 return SMESH_Hypothesis_i::getParamIndex( method, nbVars ); // return default value
327 //================================================================================
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
333 //================================================================================
335 std::string GMSHPlugin_Hypothesis_i::getMethodOfParameter(const int paramIndex,
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";