1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // NETGENPlugin : C++ implementation
24 // File : NETGENPlugin_Hypothesis_i.cxx
25 // Author : Michael Sazonov (OCN)
28 //=============================================================================
30 #include "NETGENPlugin_Hypothesis_i.hxx"
31 #include "SMESH_Gen.hxx"
32 #include "SMESH_PythonDump.hxx"
34 #include "Utils_CorbaException.hxx"
35 #include "utilities.h"
39 //=============================================================================
41 * Specialization of isToSetParameter<T> for double
43 //=============================================================================
46 bool NETGENPlugin_Hypothesis_i::isToSetParameter<double>(double curValue,
48 /*SettingMethod*/int meth)
50 return isToSetParameter(true, (fabs(curValue - newValue) < 1e-20), meth);
53 //=============================================================================
55 * NETGENPlugin_Hypothesis_i::NETGENPlugin_Hypothesis_i
59 //=============================================================================
60 NETGENPlugin_Hypothesis_i::
61 NETGENPlugin_Hypothesis_i (PortableServer::POA_ptr thePOA,
63 ::SMESH_Gen* theGenImpl)
64 : SALOME::GenericObj_i( thePOA ),
65 SMESH_Hypothesis_i( thePOA ),
68 MESSAGE( "NETGENPlugin_Hypothesis_i::NETGENPlugin_Hypothesis_i" );
69 myBaseImpl = new ::NETGENPlugin_Hypothesis (theGenImpl->GetANewId(),
74 //=============================================================================
76 * NETGENPlugin_Hypothesis_i::~NETGENPlugin_Hypothesis_i
80 //=============================================================================
81 NETGENPlugin_Hypothesis_i::~NETGENPlugin_Hypothesis_i()
83 MESSAGE( "NETGENPlugin_Hypothesis_i::~NETGENPlugin_Hypothesis_i" );
86 //=============================================================================
88 * NETGENPlugin_Hypothesis_i::SetMaxSize
92 //=============================================================================
93 void NETGENPlugin_Hypothesis_i::SetMaxSize (CORBA::Double theValue)
95 if ( isToSetParameter( GetMaxSize(), theValue, METH_SetMaxSize ))
97 this->GetImpl()->SetMaxSize(theValue);
98 SMESH::TPythonDump() << _this() << ".SetMaxSize( " << SMESH::TVar(theValue) << " )";
102 //=============================================================================
104 * NETGENPlugin_Hypothesis_i::GetMaxSize
108 //=============================================================================
109 CORBA::Double NETGENPlugin_Hypothesis_i::GetMaxSize()
111 return this->GetImpl()->GetMaxSize();
114 //=============================================================================
116 * NETGENPlugin_Hypothesis_i::SetMinSize
120 //=============================================================================
121 void NETGENPlugin_Hypothesis_i::SetMinSize (CORBA::Double theValue)
123 if ( isToSetParameter( GetMinSize(), theValue, METH_SetMinSize ))
125 this->GetImpl()->SetMinSize(theValue);
126 SMESH::TPythonDump() << _this() << ".SetMinSize( " << SMESH::TVar(theValue) << " )";
130 //=============================================================================
132 * NETGENPlugin_Hypothesis_i::GetMinSize
136 //=============================================================================
137 CORBA::Double NETGENPlugin_Hypothesis_i::GetMinSize()
139 return this->GetImpl()->GetMinSize();
142 //=============================================================================
144 * NETGENPlugin_Hypothesis_i::SetSecondOrder
146 * Set SecondOrder flag
148 //=============================================================================
149 void NETGENPlugin_Hypothesis_i::SetSecondOrder (CORBA::Boolean theValue)
151 if ( isToSetParameter( GetSecondOrder(), theValue, METH_SetSecondOrder ))
153 this->GetImpl()->SetSecondOrder(theValue);
154 SMESH::TPythonDump() << _this() << ".SetSecondOrder( " << theValue << " )";
158 //=============================================================================
160 * NETGENPlugin_Hypothesis_i::GetSecondOrder
162 * Get SecondOrder flag
164 //=============================================================================
165 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetSecondOrder()
167 return this->GetImpl()->GetSecondOrder();
170 //=============================================================================
172 * NETGENPlugin_Hypothesis_i::SetOptimize
176 //=============================================================================
177 void NETGENPlugin_Hypothesis_i::SetOptimize (CORBA::Boolean theValue)
179 if ( isToSetParameter( GetOptimize(), theValue, METH_SetOptimize ))
181 this->GetImpl()->SetOptimize(theValue);
182 SMESH::TPythonDump() << _this() << ".SetOptimize( " << theValue << " )";
186 //=============================================================================
188 * NETGENPlugin_Hypothesis_i::GetOptimize
192 //=============================================================================
193 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetOptimize()
195 return this->GetImpl()->GetOptimize();
198 //=============================================================================
200 * NETGENPlugin_Hypothesis_i::SetFineness
204 //=============================================================================
205 void NETGENPlugin_Hypothesis_i::SetFineness (CORBA::Long theValue)
207 if ( isToSetParameter( GetFineness(), theValue, METH_SetFineness ))
209 this->GetImpl()->SetFineness((::NETGENPlugin_Hypothesis::Fineness)theValue);
210 SMESH::TPythonDump() << _this() << ".SetFineness( " << theValue << " )";
214 //=============================================================================
216 * NETGENPlugin_Hypothesis_i::GetFineness
220 //=============================================================================
221 CORBA::Long NETGENPlugin_Hypothesis_i::GetFineness()
223 return this->GetImpl()->GetFineness();
226 //=============================================================================
228 * NETGENPlugin_Hypothesis_i::SetGrowthRate
232 //=============================================================================
233 void NETGENPlugin_Hypothesis_i::SetGrowthRate (CORBA::Double theValue)
235 if ( isToSetParameter( GetGrowthRate(), theValue, METH_SetGrowthRate ))
237 this->GetImpl()->SetGrowthRate(theValue);
238 SMESH::TPythonDump() << _this() << ".SetGrowthRate( " << SMESH::TVar(theValue) << " )";
242 //=============================================================================
244 * NETGENPlugin_Hypothesis_i::GetGrowthRate
248 //=============================================================================
249 CORBA::Double NETGENPlugin_Hypothesis_i::GetGrowthRate()
251 return this->GetImpl()->GetGrowthRate();
254 //=============================================================================
256 * NETGENPlugin_Hypothesis_i::SetNbSegPerEdge
260 //=============================================================================
261 void NETGENPlugin_Hypothesis_i::SetNbSegPerEdge (CORBA::Double theValue)
263 if ( isToSetParameter( GetNbSegPerEdge(), theValue, METH_SetNbSegPerEdge ))
265 this->GetImpl()->SetNbSegPerEdge(theValue);
266 SMESH::TPythonDump() << _this() << ".SetNbSegPerEdge( " << SMESH::TVar(theValue) << " )";
270 //=============================================================================
272 * NETGENPlugin_Hypothesis_i::GetNbSegPerEdge
276 //=============================================================================
277 CORBA::Double NETGENPlugin_Hypothesis_i::GetNbSegPerEdge()
279 return this->GetImpl()->GetNbSegPerEdge();
282 //=============================================================================
284 * NETGENPlugin_Hypothesis_i::SetNbSegPerRadius
288 //=============================================================================
289 void NETGENPlugin_Hypothesis_i::SetNbSegPerRadius (CORBA::Double theValue)
291 if ( isToSetParameter( GetNbSegPerRadius(), theValue, METH_SetNbSegPerRadius ))
293 this->GetImpl()->SetNbSegPerRadius(theValue);
294 SMESH::TPythonDump() << _this() << ".SetNbSegPerRadius( " << SMESH::TVar(theValue) << " )";
298 //=============================================================================
300 * NETGENPlugin_Hypothesis_i::GetNbSegPerRadius
304 //=============================================================================
305 CORBA::Double NETGENPlugin_Hypothesis_i::GetNbSegPerRadius()
307 return this->GetImpl()->GetNbSegPerRadius();
310 //=============================================================================
312 void NETGENPlugin_Hypothesis_i::SetLocalSizeOnShape(GEOM::GEOM_Object_ptr GeomObj,
313 CORBA::Double localSize)
314 throw (SALOME::SALOME_Exception)
317 entry = GeomObj->GetStudyEntry();
319 THROW_SALOME_CORBA_EXCEPTION( "SetLocalSizeOnShape(), shape is not published in study!",
321 SetLocalSizeOnEntry(entry.c_str(), localSize);
324 //=============================================================================
326 void NETGENPlugin_Hypothesis_i::SetLocalSizeOnEntry(const char* entry,
327 CORBA::Double localSize)
329 if ( isToSetParameter( GetLocalSizeOnEntry(entry), localSize, METH_SetLocalSizeOnEntry ))
331 this->GetImpl()->SetLocalSizeOnEntry(entry, localSize);
333 << _this() << ".SetLocalSizeOnShape(" << entry << ", " << localSize << ")";
337 //=============================================================================
339 CORBA::Double NETGENPlugin_Hypothesis_i::GetLocalSizeOnEntry(const char* entry)
341 return this->GetImpl()->GetLocalSizeOnEntry(entry);
344 //=============================================================================
346 NETGENPlugin::string_array* NETGENPlugin_Hypothesis_i::GetLocalSizeEntries()
348 NETGENPlugin::string_array_var result = new NETGENPlugin::string_array();
349 const ::NETGENPlugin_Hypothesis::TLocalSize localSizes =
350 this->GetImpl()->GetLocalSizesAndEntries();
351 result->length(localSizes.size());
352 ::NETGENPlugin_Hypothesis::TLocalSize::const_iterator it = localSizes.begin();
353 for (int i=0 ; it != localSizes.end() ; i++, it++)
355 string entry = (*it).first;
356 result[i] = CORBA::string_dup(entry.c_str());
358 return result._retn();
361 //=============================================================================
363 void NETGENPlugin_Hypothesis_i::UnsetLocalSizeOnEntry(const char* entry)
365 this->GetImpl()->UnsetLocalSizeOnEntry(entry);
366 SMESH::TPythonDump() << _this() << ".UnsetLocalSizeOnEntry(\"" << entry << "\")";
369 //=============================================================================
371 void NETGENPlugin_Hypothesis_i::SetQuadAllowed (CORBA::Boolean theValue)
373 if ( NETGENPlugin_Hypothesis_i::isToSetParameter( GetQuadAllowed(),
375 METH_SetQuadAllowed ))
377 this->GetImpl()->SetQuadAllowed(theValue);
378 SMESH::TPythonDump() << _this() << ".SetQuadAllowed( " << theValue << " )";
382 //=============================================================================
384 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetQuadAllowed()
386 return this->GetImpl()->GetQuadAllowed();
389 //=============================================================================
391 void NETGENPlugin_Hypothesis_i::SetUseSurfaceCurvature (CORBA::Boolean theValue)
393 if ( NETGENPlugin_Hypothesis_i::isToSetParameter( GetUseSurfaceCurvature(),
395 METH_SetSurfaceCurvature ))
397 this->GetImpl()->SetSurfaceCurvature(theValue);
398 SMESH::TPythonDump() << _this() << ".SetUseSurfaceCurvature( " << theValue << " )";
402 //=============================================================================
404 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetUseSurfaceCurvature()
406 return this->GetImpl()->GetSurfaceCurvature();
409 //=============================================================================
411 void NETGENPlugin_Hypothesis_i::SetFuseEdges (CORBA::Boolean theValue)
413 if ( NETGENPlugin_Hypothesis_i::isToSetParameter( GetFuseEdges(),
417 this->GetImpl()->SetFuseEdges(theValue);
418 SMESH::TPythonDump() << _this() << ".SetFuseEdges( " << theValue << " )";
422 //=============================================================================
424 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetFuseEdges()
426 return this->GetImpl()->GetFuseEdges();
429 //=============================================================================
431 * NETGENPlugin_Hypothesis_i::GetImpl
435 //=============================================================================
436 ::NETGENPlugin_Hypothesis* NETGENPlugin_Hypothesis_i::GetImpl()
438 return (::NETGENPlugin_Hypothesis*)myBaseImpl;
441 //================================================================================
443 * \brief Verify whether hypothesis supports given entity type
444 * \param type - dimension (see SMESH::Dimension enumeration)
445 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
447 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
449 //================================================================================
450 CORBA::Boolean NETGENPlugin_Hypothesis_i::IsDimSupported( SMESH::Dimension type )
452 return type == SMESH::DIM_3D;
455 //================================================================================
457 * \brief method intended to remove explicit treatment of Netgen hypotheses from SMESH_NoteBook
459 //================================================================================
461 int NETGENPlugin_Hypothesis_i::getParamIndex(const TCollection_AsciiString& method,
464 if ( method == "SetMaxSize" ) return 0;
465 if ( method == "SetGrowthRate" ) return 1;
466 if ( method == "SetNbSegPerEdge" ) return 2;
467 if ( method == "SetNbSegPerRadius" ) return 3;
468 if ( method == "SetMinSize" ) return nbVars-1;
470 return SMESH_Hypothesis_i::getParamIndex( method, nbVars ); // return default value
473 //================================================================================
475 * \brief Method used to convert variable parameters stored in an old study
476 * into myMethod2VarParams. It should return a method name for an index of
477 * variable parameters. Index is countered from zero
479 //================================================================================
481 std::string NETGENPlugin_Hypothesis_i::getMethodOfParameter(const int paramIndex,
484 switch ( paramIndex ) {
485 case 0: return "SetMaxSize";
486 case 1: return nbVars == 2 ? "SetMinSize" : "SetGrowthRate";
487 case 2: return "SetNbSegPerEdge";
488 case 3: return "SetNbSegPerRadius";
489 case 4: return "SetMinSize";