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,
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(),
50 GMSHPlugin_Hypothesis_i::~GMSHPlugin_Hypothesis_i()
52 MESSAGE( "GMSHPlugin_Hypothesis_i::~GMSHPlugin_Hypothesis_i" );
55 void GMSHPlugin_Hypothesis_i::SetMaxSize (CORBA::Double theValue)
57 if ( isToSetParameter( GetMaxSize(), theValue, METH_SetMaxSize ))
59 this->GetImpl()->SetMaxSize(theValue);
60 SMESH::TPythonDump() << _this() << ".SetMaxSize( " << SMESH::TVar(theValue) << " )";
64 CORBA::Double GMSHPlugin_Hypothesis_i::GetMaxSize()
66 return this->GetImpl()->GetMaxSize();
69 void GMSHPlugin_Hypothesis_i::SetMinSize (CORBA::Double theValue)
71 if ( isToSetParameter( GetMinSize(), theValue, METH_SetMinSize ))
73 this->GetImpl()->SetMinSize(theValue);
74 SMESH::TPythonDump() << _this() << ".SetMinSize( " << SMESH::TVar(theValue) << " )";
78 CORBA::Double GMSHPlugin_Hypothesis_i::GetMinSize()
80 return this->GetImpl()->GetMinSize();
83 void GMSHPlugin_Hypothesis_i::SetSecondOrder (CORBA::Boolean theValue)
85 if ( isToSetParameter( GetSecondOrder(), theValue, METH_SetSecondOrder ))
87 this->GetImpl()->SetSecondOrder(theValue);
88 SMESH::TPythonDump() << _this() << ".SetSecondOrder( " << theValue << " )";
92 CORBA::Boolean GMSHPlugin_Hypothesis_i::GetSecondOrder()
94 return this->GetImpl()->GetSecondOrder();
97 void GMSHPlugin_Hypothesis_i::Set2DAlgo (CORBA::Long theValue)
99 if ( isToSetParameter( Get2DAlgo(), theValue, METH_Set2DAlgo ))
101 this->GetImpl()->Set2DAlgo((::GMSHPlugin_Hypothesis::Algo2D)theValue);
102 SMESH::TPythonDump() << _this() << ".Set2DAlgo( " << theValue << " )";
106 CORBA::Long GMSHPlugin_Hypothesis_i::Get2DAlgo()
108 return this->GetImpl()->Get2DAlgo();
111 void GMSHPlugin_Hypothesis_i::Set3DAlgo (CORBA::Long theValue)
113 if ( isToSetParameter( Get3DAlgo(), theValue, METH_Set3DAlgo ))
115 this->GetImpl()->Set3DAlgo((::GMSHPlugin_Hypothesis::Algo3D)theValue);
116 SMESH::TPythonDump() << _this() << ".Set3DAlgo( " << theValue << " )";
120 CORBA::Long GMSHPlugin_Hypothesis_i::Get3DAlgo()
122 return this->GetImpl()->Get3DAlgo();
125 void GMSHPlugin_Hypothesis_i::SetRecomb2DAlgo (CORBA::Long theValue)
127 if ( isToSetParameter( GetRecomb2DAlgo(), theValue, METH_SetRecomb2DAlgo ))
129 this->GetImpl()->SetRecomb2DAlgo((::GMSHPlugin_Hypothesis::Recomb2DAlgo)theValue);
130 SMESH::TPythonDump() << _this() << ".SetRecomb2DAlgo( " << theValue << " )";
134 CORBA::Long GMSHPlugin_Hypothesis_i::GetRecomb2DAlgo()
136 return this->GetImpl()->GetRecomb2DAlgo();
139 void GMSHPlugin_Hypothesis_i::SetRecombineAll (CORBA::Boolean theValue)
141 if ( isToSetParameter( GetRecombineAll(), theValue, METH_SetRecombineAll ))
143 this->GetImpl()->SetRecombineAll(theValue);
144 SMESH::TPythonDump() << _this() << ".SetRecombineAll( " << theValue << " )";
148 CORBA::Boolean GMSHPlugin_Hypothesis_i::GetRecombineAll()
150 return this->GetImpl()->GetRecombineAll();
153 void GMSHPlugin_Hypothesis_i::SetSubdivAlgo (CORBA::Long theValue)
155 if ( isToSetParameter( GetSubdivAlgo(), theValue, METH_SetSubdivAlgo ))
157 this->GetImpl()->SetSubdivAlgo((::GMSHPlugin_Hypothesis::SubdivAlgo)theValue);
158 SMESH::TPythonDump() << _this() << ".SetSubdivAlgo( " << theValue << " )";
162 CORBA::Long GMSHPlugin_Hypothesis_i::GetSubdivAlgo()
164 return this->GetImpl()->GetSubdivAlgo();
167 void GMSHPlugin_Hypothesis_i::SetRemeshAlgo (CORBA::Long theValue)
169 if ( isToSetParameter( GetRemeshAlgo(), theValue, METH_SetRemeshAlgo ))
171 this->GetImpl()->SetRemeshAlgo((::GMSHPlugin_Hypothesis::RemeshAlgo)theValue);
172 SMESH::TPythonDump() << _this() << ".SetRemeshAlgo( " << theValue << " )";
176 CORBA::Long GMSHPlugin_Hypothesis_i::GetRemeshAlgo()
178 return this->GetImpl()->GetRemeshAlgo();
181 void GMSHPlugin_Hypothesis_i::SetRemeshPara (CORBA::Long theValue)
183 if ( isToSetParameter( GetRemeshPara(), theValue, METH_SetRemeshPara ))
185 this->GetImpl()->SetRemeshPara((::GMSHPlugin_Hypothesis::RemeshPara)theValue);
186 SMESH::TPythonDump() << _this() << ".SetRemeshAlgo( " << theValue << " )";
190 CORBA::Long GMSHPlugin_Hypothesis_i::GetRemeshPara()
192 return this->GetImpl()->GetRemeshPara();
195 void GMSHPlugin_Hypothesis_i::SetSmouthSteps (CORBA::Double theValue)
197 if ( isToSetParameter( GetSmouthSteps(), theValue, METH_SetSmouthSteps ))
199 this->GetImpl()->SetSmouthSteps(theValue);
200 SMESH::TPythonDump() << _this() << ".SetSmouthSteps( " << theValue << " )";
204 CORBA::Double GMSHPlugin_Hypothesis_i::GetSmouthSteps()
206 return this->GetImpl()->GetSmouthSteps();
209 void GMSHPlugin_Hypothesis_i::SetSizeFactor (CORBA::Double theValue)
211 if ( isToSetParameter( GetSizeFactor(), theValue, METH_SetSizeFactor ))
213 this->GetImpl()->SetSizeFactor(theValue);
214 SMESH::TPythonDump() << _this() << ".SetSizeFactor( " << theValue << " )";
218 CORBA::Double GMSHPlugin_Hypothesis_i::GetSizeFactor()
220 return this->GetImpl()->GetSizeFactor();
223 void GMSHPlugin_Hypothesis_i::SetUseIncomplElem (CORBA::Boolean theValue)
225 if ( isToSetParameter( GetUseIncomplElem(), theValue, METH_SetUseIncomplElem ))
227 this->GetImpl()->SetUseIncomplElem(theValue);
228 SMESH::TPythonDump() << _this() << ".SetUseIncomplElem( " << theValue << " )";
232 CORBA::Boolean GMSHPlugin_Hypothesis_i::GetUseIncomplElem()
234 return this->GetImpl()->GetUseIncomplElem();
237 void GMSHPlugin_Hypothesis_i::SetIs2d (CORBA::Boolean theValue)
239 this->GetImpl()->SetIs2d(theValue);
240 SMESH::TPythonDump() << _this() << ".SetIs2d( " << theValue << " )";
243 void GMSHPlugin_Hypothesis_i::SetCompoundOnShape(GEOM::GEOM_Object_ptr GeomObj)
246 entry = GeomObj->GetStudyEntry();
247 SetCompoundOnEntry(entry.c_str());
250 void GMSHPlugin_Hypothesis_i::SetCompoundOnEntry(const char* entry)
252 //if ( isToSetParameter( GetCompoundOnEntry(entry), METH_SetCompoundOnEntry ))
254 this->GetImpl()->SetCompoundOnEntry(entry);
256 << _this() << ".SetCompoundOnShape(" << entry << ")";
260 GMSHPlugin::string_array* GMSHPlugin_Hypothesis_i::GetCompoundOnEntries()
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++)
270 result[i] = CORBA::string_dup(entry.c_str());
272 return result._retn();
275 void GMSHPlugin_Hypothesis_i::UnsetCompoundOnShape(GEOM::GEOM_Object_ptr GeomObj)
278 entry = GeomObj->GetStudyEntry();
279 UnsetCompoundOnEntry(entry.c_str());
282 void GMSHPlugin_Hypothesis_i::UnsetCompoundOnEntry(const char* entry)
284 this->GetImpl()->UnsetCompoundOnEntry(entry);
285 SMESH::TPythonDump() << _this() << ".UnsetCompoundOnShape(" << entry << ")";
288 ::GMSHPlugin_Hypothesis* GMSHPlugin_Hypothesis_i::GetImpl()
290 return (::GMSHPlugin_Hypothesis*)myBaseImpl;
293 //================================================================================
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
299 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
301 //================================================================================
302 CORBA::Boolean GMSHPlugin_Hypothesis_i::IsDimSupported( SMESH::Dimension type )
304 return type == SMESH::DIM_3D;
307 //================================================================================
309 * \brief method intended to remove explicit treatment of Netagen hypotheses from SMESH_NoteBook
311 //================================================================================
313 int GMSHPlugin_Hypothesis_i::getParamIndex(const TCollection_AsciiString& method,
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;
322 return SMESH_Hypothesis_i::getParamIndex( method, nbVars ); // return default value
325 //================================================================================
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
331 //================================================================================
333 std::string GMSHPlugin_Hypothesis_i::getMethodOfParameter(const int paramIndex,
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";
346 //================================================================================
348 * \brief Return geometry this hypothesis depends on. Return false if there is no geometry parameter
350 //================================================================================
353 GMSHPlugin_Hypothesis_i::getObjectsDependOn( std::vector< std::string > & entryArray,
354 std::vector< int > & subIDArray ) const
356 typedef ::GMSHPlugin_Hypothesis THyp;
357 const THyp* impl = static_cast<const THyp*>( myBaseImpl );
359 const THyp::TCompound& compounds = impl->GetCompoundOnEntries();
360 entryArray.assign( compounds.cbegin(), compounds.cend() );
365 //================================================================================
367 * \brief Set new geometry instead of that returned by getObjectsDependOn()
369 //================================================================================
372 GMSHPlugin_Hypothesis_i::setObjectsDependOn( std::vector< std::string > & entryArray,
373 std::vector< int > & subIDArray )
375 typedef ::GMSHPlugin_Hypothesis THyp;
376 THyp* impl = static_cast< THyp* >( myBaseImpl );
380 THyp::TCompound& compoundsNew = const_cast< THyp::TCompound& > ( impl->GetCompoundOnEntries() );
381 THyp::TCompound compounds;
382 compounds.swap( compoundsNew );
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 ]);