1 // Copyright (C) 2012-2015 ALNEOS
2 // Copyright (C) 2016-2023 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, or (at your option) any later version.
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
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include "GMSHPlugin_Hypothesis_i.hxx"
22 #include "SMESH_Gen.hxx"
23 #include "SMESH_PythonDump.hxx"
24 #include "GEOM_Object.hxx"
26 #include "Utils_CorbaException.hxx"
27 #include "utilities.h"
32 bool GMSHPlugin_Hypothesis_i::isToSetParameter<double>(double curValue,
34 /*SettingMethod*/int meth)
36 return isToSetParameter(true, (fabs(curValue - newValue) < 1e-20), meth);
39 GMSHPlugin_Hypothesis_i::
40 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(),
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();
71 void GMSHPlugin_Hypothesis_i::SetMeshCurvatureSize (CORBA::Double theMeshCurvatureSize)
73 if ( isToSetParameter( GetMeshCurvatureSize(), theMeshCurvatureSize, METH_SetMeshCurvatureSize ))
75 this->GetImpl()->SetMeshCurvatureSize(theMeshCurvatureSize);
76 SMESH::TPythonDump() << _this() << ".SetMeshCurvatureSize( " << SMESH::TVar(theMeshCurvatureSize) << " )";
80 CORBA::Double GMSHPlugin_Hypothesis_i::GetMeshCurvatureSize()
82 return this->GetImpl()->GetMeshCurvatureSize();
86 void GMSHPlugin_Hypothesis_i::SetMinSize (CORBA::Double theValue)
88 if ( isToSetParameter( GetMinSize(), theValue, METH_SetMinSize ))
90 this->GetImpl()->SetMinSize(theValue);
91 SMESH::TPythonDump() << _this() << ".SetMinSize( " << SMESH::TVar(theValue) << " )";
95 CORBA::Double GMSHPlugin_Hypothesis_i::GetMinSize()
97 return this->GetImpl()->GetMinSize();
100 void GMSHPlugin_Hypothesis_i::SetSecondOrder (CORBA::Boolean theValue)
102 if ( isToSetParameter( GetSecondOrder(), theValue, METH_SetSecondOrder ))
104 this->GetImpl()->SetSecondOrder(theValue);
105 SMESH::TPythonDump() << _this() << ".SetSecondOrder( " << theValue << " )";
109 CORBA::Boolean GMSHPlugin_Hypothesis_i::GetSecondOrder()
111 return this->GetImpl()->GetSecondOrder();
114 void GMSHPlugin_Hypothesis_i::Set2DAlgo (CORBA::Long theValue)
116 if ( isToSetParameter( Get2DAlgo(), theValue, METH_Set2DAlgo ))
118 this->GetImpl()->Set2DAlgo((::GMSHPlugin_Hypothesis::Algo2D)theValue);
119 SMESH::TPythonDump() << _this() << ".Set2DAlgo( " << theValue << " )";
123 CORBA::Long GMSHPlugin_Hypothesis_i::Get2DAlgo()
125 return this->GetImpl()->Get2DAlgo();
128 void GMSHPlugin_Hypothesis_i::Set3DAlgo (CORBA::Long theValue)
130 if ( isToSetParameter( Get3DAlgo(), theValue, METH_Set3DAlgo ))
132 this->GetImpl()->Set3DAlgo((::GMSHPlugin_Hypothesis::Algo3D)theValue);
133 SMESH::TPythonDump() << _this() << ".Set3DAlgo( " << theValue << " )";
137 CORBA::Long GMSHPlugin_Hypothesis_i::Get3DAlgo()
139 return this->GetImpl()->Get3DAlgo();
142 void GMSHPlugin_Hypothesis_i::SetRecomb2DAlgo (CORBA::Long theValue)
144 if ( isToSetParameter( GetRecomb2DAlgo(), theValue, METH_SetRecomb2DAlgo ))
146 this->GetImpl()->SetRecomb2DAlgo((::GMSHPlugin_Hypothesis::Recomb2DAlgo)theValue);
147 SMESH::TPythonDump() << _this() << ".SetRecomb2DAlgo( " << theValue << " )";
151 CORBA::Long GMSHPlugin_Hypothesis_i::GetRecomb2DAlgo()
153 return this->GetImpl()->GetRecomb2DAlgo();
156 void GMSHPlugin_Hypothesis_i::SetRecombineAll (CORBA::Boolean theValue)
158 if ( isToSetParameter( GetRecombineAll(), theValue, METH_SetRecombineAll ))
160 this->GetImpl()->SetRecombineAll(theValue);
161 SMESH::TPythonDump() << _this() << ".SetRecombineAll( " << theValue << " )";
165 CORBA::Boolean GMSHPlugin_Hypothesis_i::GetRecombineAll()
167 return this->GetImpl()->GetRecombineAll();
170 void GMSHPlugin_Hypothesis_i::SetSubdivAlgo (CORBA::Long theValue)
172 if ( isToSetParameter( GetSubdivAlgo(), theValue, METH_SetSubdivAlgo ))
174 this->GetImpl()->SetSubdivAlgo((::GMSHPlugin_Hypothesis::SubdivAlgo)theValue);
175 SMESH::TPythonDump() << _this() << ".SetSubdivAlgo( " << theValue << " )";
179 CORBA::Long GMSHPlugin_Hypothesis_i::GetSubdivAlgo()
181 return this->GetImpl()->GetSubdivAlgo();
184 void GMSHPlugin_Hypothesis_i::SetRemeshAlgo (CORBA::Long theValue)
186 if ( isToSetParameter( GetRemeshAlgo(), theValue, METH_SetRemeshAlgo ))
188 this->GetImpl()->SetRemeshAlgo((::GMSHPlugin_Hypothesis::RemeshAlgo)theValue);
189 SMESH::TPythonDump() << _this() << ".SetRemeshAlgo( " << theValue << " )";
193 CORBA::Long GMSHPlugin_Hypothesis_i::GetRemeshAlgo()
195 return this->GetImpl()->GetRemeshAlgo();
198 void GMSHPlugin_Hypothesis_i::SetRemeshPara (CORBA::Long theValue)
200 if ( isToSetParameter( GetRemeshPara(), theValue, METH_SetRemeshPara ))
202 this->GetImpl()->SetRemeshPara((::GMSHPlugin_Hypothesis::RemeshPara)theValue);
203 SMESH::TPythonDump() << _this() << ".SetRemeshAlgo( " << theValue << " )";
207 CORBA::Long GMSHPlugin_Hypothesis_i::GetRemeshPara()
209 return this->GetImpl()->GetRemeshPara();
212 void GMSHPlugin_Hypothesis_i::SetSmouthSteps (CORBA::Double theValue)
214 if ( isToSetParameter( GetSmouthSteps(), theValue, METH_SetSmouthSteps ))
216 this->GetImpl()->SetSmouthSteps(theValue);
217 SMESH::TPythonDump() << _this() << ".SetSmouthSteps( " << theValue << " )";
221 CORBA::Double GMSHPlugin_Hypothesis_i::GetSmouthSteps()
223 return this->GetImpl()->GetSmouthSteps();
226 void GMSHPlugin_Hypothesis_i::SetSizeFactor (CORBA::Double theValue)
228 if ( isToSetParameter( GetSizeFactor(), theValue, METH_SetSizeFactor ))
230 this->GetImpl()->SetSizeFactor(theValue);
231 SMESH::TPythonDump() << _this() << ".SetSizeFactor( " << theValue << " )";
235 CORBA::Double GMSHPlugin_Hypothesis_i::GetSizeFactor()
237 return this->GetImpl()->GetSizeFactor();
240 void GMSHPlugin_Hypothesis_i::SetUseIncomplElem (CORBA::Boolean theValue)
242 if ( isToSetParameter( GetUseIncomplElem(), theValue, METH_SetUseIncomplElem ))
244 this->GetImpl()->SetUseIncomplElem(theValue);
245 SMESH::TPythonDump() << _this() << ".SetUseIncomplElem( " << theValue << " )";
249 CORBA::Boolean GMSHPlugin_Hypothesis_i::GetUseIncomplElem()
251 return this->GetImpl()->GetUseIncomplElem();
254 void GMSHPlugin_Hypothesis_i::SetIs2d (CORBA::Boolean theValue)
256 this->GetImpl()->SetIs2d(theValue);
257 SMESH::TPythonDump() << _this() << ".SetIs2d( " << theValue << " )";
260 void GMSHPlugin_Hypothesis_i::SetCompoundOnShape(GEOM::GEOM_Object_ptr GeomObj)
263 entry = GeomObj->GetStudyEntry();
264 SetCompoundOnEntry(entry.c_str());
267 void GMSHPlugin_Hypothesis_i::SetCompoundOnEntry(const char* entry)
269 //if ( isToSetParameter( GetCompoundOnEntry(entry), METH_SetCompoundOnEntry ))
271 this->GetImpl()->SetCompoundOnEntry(entry);
273 << _this() << ".SetCompoundOnShape(" << entry << ")";
277 GMSHPlugin::string_array* GMSHPlugin_Hypothesis_i::GetCompoundOnEntries()
279 GMSHPlugin::string_array_var result = new GMSHPlugin::string_array();
280 const ::GMSHPlugin_Hypothesis::TCompound compounds =
281 this->GetImpl()->GetCompoundOnEntries();
282 result->length(compounds.size());
283 ::GMSHPlugin_Hypothesis::TCompound::const_iterator it = compounds.begin();
284 for (int i=0 ; it != compounds.end() ; i++, it++)
287 result[i] = CORBA::string_dup(entry.c_str());
289 return result._retn();
292 void GMSHPlugin_Hypothesis_i::UnsetCompoundOnShape(GEOM::GEOM_Object_ptr GeomObj)
295 entry = GeomObj->GetStudyEntry();
296 UnsetCompoundOnEntry(entry.c_str());
299 void GMSHPlugin_Hypothesis_i::UnsetCompoundOnEntry(const char* entry)
301 this->GetImpl()->UnsetCompoundOnEntry(entry);
302 SMESH::TPythonDump() << _this() << ".UnsetCompoundOnShape(" << entry << ")";
305 ::GMSHPlugin_Hypothesis* GMSHPlugin_Hypothesis_i::GetImpl()
307 return (::GMSHPlugin_Hypothesis*)myBaseImpl;
310 //================================================================================
312 * \brief Verify whether hypothesis supports given entity type
313 * \param type - dimension (see SMESH::Dimension enumeration)
314 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
316 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
318 //================================================================================
319 CORBA::Boolean GMSHPlugin_Hypothesis_i::IsDimSupported( SMESH::Dimension type )
321 return type == SMESH::DIM_3D;
324 //================================================================================
326 * \brief method intended to remove explicit treatment of Netagen hypotheses from SMESH_NoteBook
328 //================================================================================
330 int GMSHPlugin_Hypothesis_i::getParamIndex(const TCollection_AsciiString& method,
333 if ( method == "SetMaxSize" ) return 0;
334 if ( method == "SetGrowthRate" ) return 1;
335 if ( method == "SetNbSegPerEdge" ) return 2;
336 if ( method == "SetNbSegPerRadius" ) return 3;
337 if ( method == "SetMinSize" ) return nbVars-1;
338 if ( method == "SetMeshCurvatureSize" ) return 5;
340 return SMESH_Hypothesis_i::getParamIndex( method, nbVars ); // return default value
343 //================================================================================
345 * \brief Method used to convert variable parameters stored in an old study
346 * into myMethod2VarParams. It should return a method name for an index of
347 * variable parameters. Index is countered from zero
349 //================================================================================
351 std::string GMSHPlugin_Hypothesis_i::getMethodOfParameter(const int paramIndex,
354 switch ( paramIndex ) {
355 case 0: return "SetMaxSize";
356 case 1: return nbVars == 2 ? "SetMinSize" : "SetGrowthRate";
357 case 2: return "SetNbSegPerEdge";
358 case 3: return "SetNbSegPerRadius";
359 case 4: return "SetMinSize";
360 case 5: return "SetMeshCurvatureSize";
365 //================================================================================
367 * \brief Return geometry this hypothesis depends on. Return false if there is no geometry parameter
369 //================================================================================
372 GMSHPlugin_Hypothesis_i::getObjectsDependOn( std::vector< std::string > & entryArray,
373 std::vector< int > & /*subIDArray*/ ) const
375 typedef ::GMSHPlugin_Hypothesis THyp;
376 const THyp* impl = static_cast<const THyp*>( myBaseImpl );
378 const THyp::TCompound& compounds = impl->GetCompoundOnEntries();
379 entryArray.assign( compounds.cbegin(), compounds.cend() );
384 //================================================================================
386 * \brief Set new geometry instead of that returned by getObjectsDependOn()
388 //================================================================================
391 GMSHPlugin_Hypothesis_i::setObjectsDependOn( std::vector< std::string > & entryArray,
392 std::vector< int > & /*subIDArray*/ )
394 typedef ::GMSHPlugin_Hypothesis THyp;
395 THyp* impl = static_cast< THyp* >( myBaseImpl );
399 THyp::TCompound& compoundsNew = const_cast< THyp::TCompound& > ( impl->GetCompoundOnEntries() );
400 THyp::TCompound compounds;
401 compounds.swap( compoundsNew );
403 THyp::TCompound::const_iterator entry = compounds.cbegin();
404 for ( ; entry != compounds.cend(); ++entry, ++iEnt )
405 if ( !entryArray[ iEnt ].empty() )
406 compoundsNew.insert( entryArray[ iEnt ]);