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 myBaseImpl = new ::NETGENPlugin_Hypothesis (theGenImpl->GetANewId(),
73 //=============================================================================
75 * NETGENPlugin_Hypothesis_i::~NETGENPlugin_Hypothesis_i
79 //=============================================================================
80 NETGENPlugin_Hypothesis_i::~NETGENPlugin_Hypothesis_i()
84 //=============================================================================
86 * NETGENPlugin_Hypothesis_i::SetMaxSize
90 //=============================================================================
91 void NETGENPlugin_Hypothesis_i::SetMaxSize (CORBA::Double theValue)
93 if ( isToSetParameter( GetMaxSize(), theValue, METH_SetMaxSize ))
95 this->GetImpl()->SetMaxSize(theValue);
96 SMESH::TPythonDump() << _this() << ".SetMaxSize( " << SMESH::TVar(theValue) << " )";
100 //=============================================================================
102 * NETGENPlugin_Hypothesis_i::GetMaxSize
106 //=============================================================================
107 CORBA::Double NETGENPlugin_Hypothesis_i::GetMaxSize()
109 return this->GetImpl()->GetMaxSize();
112 //=============================================================================
114 * NETGENPlugin_Hypothesis_i::SetMinSize
118 //=============================================================================
119 void NETGENPlugin_Hypothesis_i::SetMinSize (CORBA::Double theValue)
121 if ( isToSetParameter( GetMinSize(), theValue, METH_SetMinSize ))
123 this->GetImpl()->SetMinSize(theValue);
124 SMESH::TPythonDump() << _this() << ".SetMinSize( " << SMESH::TVar(theValue) << " )";
128 //=============================================================================
130 * NETGENPlugin_Hypothesis_i::GetMinSize
134 //=============================================================================
135 CORBA::Double NETGENPlugin_Hypothesis_i::GetMinSize()
137 return this->GetImpl()->GetMinSize();
140 //=============================================================================
142 * NETGENPlugin_Hypothesis_i::SetSecondOrder
144 * Set SecondOrder flag
146 //=============================================================================
147 void NETGENPlugin_Hypothesis_i::SetSecondOrder (CORBA::Boolean theValue)
149 if ( isToSetParameter( GetSecondOrder(), theValue, METH_SetSecondOrder ))
151 this->GetImpl()->SetSecondOrder(theValue);
152 SMESH::TPythonDump() << _this() << ".SetSecondOrder( " << theValue << " )";
156 //=============================================================================
158 * NETGENPlugin_Hypothesis_i::GetSecondOrder
160 * Get SecondOrder flag
162 //=============================================================================
163 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetSecondOrder()
165 return this->GetImpl()->GetSecondOrder();
168 //=============================================================================
170 * NETGENPlugin_Hypothesis_i::SetOptimize
174 //=============================================================================
175 void NETGENPlugin_Hypothesis_i::SetOptimize (CORBA::Boolean theValue)
177 if ( isToSetParameter( GetOptimize(), theValue, METH_SetOptimize ))
179 this->GetImpl()->SetOptimize(theValue);
180 SMESH::TPythonDump() << _this() << ".SetOptimize( " << theValue << " )";
184 //=============================================================================
186 * NETGENPlugin_Hypothesis_i::GetOptimize
190 //=============================================================================
191 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetOptimize()
193 return this->GetImpl()->GetOptimize();
196 //=============================================================================
198 * NETGENPlugin_Hypothesis_i::SetFineness
202 //=============================================================================
203 void NETGENPlugin_Hypothesis_i::SetFineness (CORBA::Long theValue)
205 if ( isToSetParameter( GetFineness(), theValue, METH_SetFineness ))
207 this->GetImpl()->SetFineness((::NETGENPlugin_Hypothesis::Fineness)theValue);
208 SMESH::TPythonDump() << _this() << ".SetFineness( " << theValue << " )";
212 //=============================================================================
214 * NETGENPlugin_Hypothesis_i::GetFineness
218 //=============================================================================
219 CORBA::Long NETGENPlugin_Hypothesis_i::GetFineness()
221 return this->GetImpl()->GetFineness();
224 //=============================================================================
226 * NETGENPlugin_Hypothesis_i::SetGrowthRate
230 //=============================================================================
231 void NETGENPlugin_Hypothesis_i::SetGrowthRate (CORBA::Double theValue)
233 if ( isToSetParameter( GetGrowthRate(), theValue, METH_SetGrowthRate ))
235 this->GetImpl()->SetGrowthRate(theValue);
236 SMESH::TPythonDump() << _this() << ".SetGrowthRate( " << SMESH::TVar(theValue) << " )";
240 //=============================================================================
242 * NETGENPlugin_Hypothesis_i::GetGrowthRate
246 //=============================================================================
247 CORBA::Double NETGENPlugin_Hypothesis_i::GetGrowthRate()
249 return this->GetImpl()->GetGrowthRate();
252 //=============================================================================
254 * NETGENPlugin_Hypothesis_i::SetNbSegPerEdge
258 //=============================================================================
259 void NETGENPlugin_Hypothesis_i::SetNbSegPerEdge (CORBA::Double theValue)
261 if ( isToSetParameter( GetNbSegPerEdge(), theValue, METH_SetNbSegPerEdge ))
263 this->GetImpl()->SetNbSegPerEdge(theValue);
264 SMESH::TPythonDump() << _this() << ".SetNbSegPerEdge( " << SMESH::TVar(theValue) << " )";
268 //=============================================================================
270 * NETGENPlugin_Hypothesis_i::GetNbSegPerEdge
274 //=============================================================================
275 CORBA::Double NETGENPlugin_Hypothesis_i::GetNbSegPerEdge()
277 return this->GetImpl()->GetNbSegPerEdge();
280 //=============================================================================
282 * NETGENPlugin_Hypothesis_i::SetNbSegPerRadius
286 //=============================================================================
287 void NETGENPlugin_Hypothesis_i::SetNbSegPerRadius (CORBA::Double theValue)
289 if ( isToSetParameter( GetNbSegPerRadius(), theValue, METH_SetNbSegPerRadius ))
291 this->GetImpl()->SetNbSegPerRadius(theValue);
292 SMESH::TPythonDump() << _this() << ".SetNbSegPerRadius( " << SMESH::TVar(theValue) << " )";
296 //=============================================================================
298 * NETGENPlugin_Hypothesis_i::GetNbSegPerRadius
302 //=============================================================================
303 CORBA::Double NETGENPlugin_Hypothesis_i::GetNbSegPerRadius()
305 return this->GetImpl()->GetNbSegPerRadius();
308 //=============================================================================
310 void NETGENPlugin_Hypothesis_i::SetChordalErrorEnabled(CORBA::Boolean theValue)
312 if ( isToSetParameter( GetChordalErrorEnabled(), theValue, METH_SetChordalErrorEnabled ))
314 this->GetImpl()->SetChordalErrorEnabled(theValue);
315 SMESH::TPythonDump() << _this() << ".SetChordalErrorEnabled( " << theValue << " )";
319 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetChordalErrorEnabled()
321 return GetImpl()->GetChordalErrorEnabled();
324 void NETGENPlugin_Hypothesis_i::SetChordalError(CORBA::Double theValue)
326 if ( isToSetParameter( GetChordalError(), theValue, METH_SetChordalError ))
328 this->GetImpl()->SetChordalError(theValue);
329 SMESH::TPythonDump() << _this() << ".SetChordalError( " << SMESH::TVar(theValue) << " )";
333 CORBA::Double NETGENPlugin_Hypothesis_i::GetChordalError()
335 return GetImpl()->GetChordalError();
338 //=============================================================================
340 void NETGENPlugin_Hypothesis_i::SetLocalSizeOnShape(GEOM::GEOM_Object_ptr GeomObj,
341 CORBA::Double localSize)
342 throw (SALOME::SALOME_Exception)
345 entry = GeomObj->GetStudyEntry();
347 THROW_SALOME_CORBA_EXCEPTION( "SetLocalSizeOnShape(), shape is not published in study!",
349 SetLocalSizeOnEntry(entry.c_str(), localSize);
352 //=============================================================================
354 void NETGENPlugin_Hypothesis_i::SetLocalSizeOnEntry(const char* entry,
355 CORBA::Double localSize)
357 if ( isToSetParameter( GetLocalSizeOnEntry(entry), localSize, METH_SetLocalSizeOnEntry ))
359 this->GetImpl()->SetLocalSizeOnEntry(entry, localSize);
361 << _this() << ".SetLocalSizeOnShape(" << entry << ", " << localSize << ")";
365 //=============================================================================
367 CORBA::Double NETGENPlugin_Hypothesis_i::GetLocalSizeOnEntry(const char* entry)
369 return this->GetImpl()->GetLocalSizeOnEntry(entry);
372 //=============================================================================
374 NETGENPlugin::string_array* NETGENPlugin_Hypothesis_i::GetLocalSizeEntries()
376 NETGENPlugin::string_array_var result = new NETGENPlugin::string_array();
377 const ::NETGENPlugin_Hypothesis::TLocalSize localSizes =
378 this->GetImpl()->GetLocalSizesAndEntries();
379 result->length(localSizes.size());
380 ::NETGENPlugin_Hypothesis::TLocalSize::const_iterator it = localSizes.begin();
381 for (int i=0 ; it != localSizes.end() ; i++, it++)
383 string entry = (*it).first;
384 result[i] = CORBA::string_dup(entry.c_str());
386 return result._retn();
389 //=============================================================================
391 void NETGENPlugin_Hypothesis_i::UnsetLocalSizeOnEntry(const char* entry)
393 this->GetImpl()->UnsetLocalSizeOnEntry(entry);
394 SMESH::TPythonDump() << _this() << ".UnsetLocalSizeOnEntry(\"" << entry << "\")";
397 //=============================================================================
399 void NETGENPlugin_Hypothesis_i::SetMeshSizeFile(const char* fileName)
401 if ( GetImpl()->GetMeshSizeFile() != fileName )
403 GetImpl()->SetMeshSizeFile( fileName );
404 SMESH::TPythonDump() << _this() << ".SetMeshSizeFile( '" << fileName << "' )";
408 //=============================================================================
410 char* NETGENPlugin_Hypothesis_i::GetMeshSizeFile()
412 return CORBA::string_dup( GetImpl()->GetMeshSizeFile().c_str() );
415 //=============================================================================
417 void NETGENPlugin_Hypothesis_i::SetQuadAllowed (CORBA::Boolean theValue)
419 if ( NETGENPlugin_Hypothesis_i::isToSetParameter( GetQuadAllowed(),
421 METH_SetQuadAllowed ))
423 this->GetImpl()->SetQuadAllowed(theValue);
424 SMESH::TPythonDump() << _this() << ".SetQuadAllowed( " << theValue << " )";
428 //=============================================================================
430 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetQuadAllowed()
432 return this->GetImpl()->GetQuadAllowed();
435 //=============================================================================
437 void NETGENPlugin_Hypothesis_i::SetUseSurfaceCurvature (CORBA::Boolean theValue)
439 if ( NETGENPlugin_Hypothesis_i::isToSetParameter( GetUseSurfaceCurvature(),
441 METH_SetSurfaceCurvature ))
443 this->GetImpl()->SetSurfaceCurvature(theValue);
444 SMESH::TPythonDump() << _this() << ".SetUseSurfaceCurvature( " << theValue << " )";
448 //=============================================================================
450 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetUseSurfaceCurvature()
452 return this->GetImpl()->GetSurfaceCurvature();
455 //=============================================================================
457 void NETGENPlugin_Hypothesis_i::SetFuseEdges (CORBA::Boolean theValue)
459 if ( NETGENPlugin_Hypothesis_i::isToSetParameter( GetFuseEdges(),
463 this->GetImpl()->SetFuseEdges(theValue);
464 SMESH::TPythonDump() << _this() << ".SetFuseEdges( " << theValue << " )";
468 //=============================================================================
470 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetFuseEdges()
472 return this->GetImpl()->GetFuseEdges();
475 //=============================================================================
477 * NETGENPlugin_Hypothesis_i::GetImpl
481 //=============================================================================
482 ::NETGENPlugin_Hypothesis* NETGENPlugin_Hypothesis_i::GetImpl()
484 return (::NETGENPlugin_Hypothesis*)myBaseImpl;
487 //================================================================================
489 * \brief Verify whether hypothesis supports given entity type
490 * \param type - dimension (see SMESH::Dimension enumeration)
491 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
493 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
495 //================================================================================
496 CORBA::Boolean NETGENPlugin_Hypothesis_i::IsDimSupported( SMESH::Dimension type )
498 return type == SMESH::DIM_3D;
501 //================================================================================
503 * \brief method intended to remove explicit treatment of Netgen hypotheses from SMESH_NoteBook
505 //================================================================================
507 int NETGENPlugin_Hypothesis_i::getParamIndex(const TCollection_AsciiString& method,
510 if ( method == "SetMaxSize" ) return 0;
511 if ( method == "SetGrowthRate" ) return 1;
512 if ( method == "SetNbSegPerEdge" ) return 2;
513 if ( method == "SetNbSegPerRadius" ) return 3;
514 if ( method == "SetMinSize" ) return nbVars-1;
516 return SMESH_Hypothesis_i::getParamIndex( method, nbVars ); // return default value
519 //================================================================================
521 * \brief Method used to convert variable parameters stored in an old study
522 * into myMethod2VarParams. It should return a method name for an index of
523 * variable parameters. Index is countered from zero
525 //================================================================================
527 std::string NETGENPlugin_Hypothesis_i::getMethodOfParameter(const int paramIndex,
530 switch ( paramIndex ) {
531 case 0: return "SetMaxSize";
532 case 1: return nbVars == 2 ? "SetMinSize" : "SetGrowthRate";
533 case 2: return "SetNbSegPerEdge";
534 case 3: return "SetNbSegPerRadius";
535 case 4: return "SetMinSize";