1 // Copyright (C) 2007-2013 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.
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"
33 #include "GEOM_Object.hxx"
35 #include "Utils_CorbaException.hxx"
36 #include "utilities.h"
40 //=============================================================================
42 * Specialization of isToSetParameter<T> for double
44 //=============================================================================
47 bool NETGENPlugin_Hypothesis_i::isToSetParameter<double>(double curValue,
49 /*SettingMethod*/int meth)
51 return isToSetParameter(true, (fabs(curValue - newValue) < 1e-20), meth);
54 //=============================================================================
56 * NETGENPlugin_Hypothesis_i::NETGENPlugin_Hypothesis_i
60 //=============================================================================
61 NETGENPlugin_Hypothesis_i::
62 NETGENPlugin_Hypothesis_i (PortableServer::POA_ptr thePOA,
64 ::SMESH_Gen* theGenImpl)
65 : SALOME::GenericObj_i( thePOA ),
66 SMESH_Hypothesis_i( thePOA ),
69 MESSAGE( "NETGENPlugin_Hypothesis_i::NETGENPlugin_Hypothesis_i" );
70 myBaseImpl = new ::NETGENPlugin_Hypothesis (theGenImpl->GetANewId(),
75 //=============================================================================
77 * NETGENPlugin_Hypothesis_i::~NETGENPlugin_Hypothesis_i
81 //=============================================================================
82 NETGENPlugin_Hypothesis_i::~NETGENPlugin_Hypothesis_i()
84 MESSAGE( "NETGENPlugin_Hypothesis_i::~NETGENPlugin_Hypothesis_i" );
87 //=============================================================================
89 * NETGENPlugin_Hypothesis_i::SetMaxSize
93 //=============================================================================
94 void NETGENPlugin_Hypothesis_i::SetMaxSize (CORBA::Double theValue)
96 if ( isToSetParameter( GetMaxSize(), theValue, METH_SetMaxSize ))
98 this->GetImpl()->SetMaxSize(theValue);
99 SMESH::TPythonDump() << _this() << ".SetMaxSize( " << SMESH::TVar(theValue) << " )";
103 //=============================================================================
105 * NETGENPlugin_Hypothesis_i::GetMaxSize
109 //=============================================================================
110 CORBA::Double NETGENPlugin_Hypothesis_i::GetMaxSize()
112 return this->GetImpl()->GetMaxSize();
115 //=============================================================================
117 * NETGENPlugin_Hypothesis_i::SetMinSize
121 //=============================================================================
122 void NETGENPlugin_Hypothesis_i::SetMinSize (CORBA::Double theValue)
124 if ( isToSetParameter( GetMinSize(), theValue, METH_SetMinSize ))
126 this->GetImpl()->SetMinSize(theValue);
127 SMESH::TPythonDump() << _this() << ".SetMinSize( " << SMESH::TVar(theValue) << " )";
131 //=============================================================================
133 * NETGENPlugin_Hypothesis_i::GetMinSize
137 //=============================================================================
138 CORBA::Double NETGENPlugin_Hypothesis_i::GetMinSize()
140 return this->GetImpl()->GetMinSize();
143 //=============================================================================
145 * NETGENPlugin_Hypothesis_i::SetSecondOrder
147 * Set SecondOrder flag
149 //=============================================================================
150 void NETGENPlugin_Hypothesis_i::SetSecondOrder (CORBA::Boolean theValue)
152 if ( isToSetParameter( GetSecondOrder(), theValue, METH_SetSecondOrder ))
154 this->GetImpl()->SetSecondOrder(theValue);
155 SMESH::TPythonDump() << _this() << ".SetSecondOrder( " << theValue << " )";
159 //=============================================================================
161 * NETGENPlugin_Hypothesis_i::GetSecondOrder
163 * Get SecondOrder flag
165 //=============================================================================
166 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetSecondOrder()
168 return this->GetImpl()->GetSecondOrder();
171 //=============================================================================
173 * NETGENPlugin_Hypothesis_i::SetOptimize
177 //=============================================================================
178 void NETGENPlugin_Hypothesis_i::SetOptimize (CORBA::Boolean theValue)
180 if ( isToSetParameter( GetOptimize(), theValue, METH_SetOptimize ))
182 this->GetImpl()->SetOptimize(theValue);
183 SMESH::TPythonDump() << _this() << ".SetOptimize( " << theValue << " )";
187 //=============================================================================
189 * NETGENPlugin_Hypothesis_i::GetOptimize
193 //=============================================================================
194 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetOptimize()
196 return this->GetImpl()->GetOptimize();
199 //=============================================================================
201 * NETGENPlugin_Hypothesis_i::SetFineness
205 //=============================================================================
206 void NETGENPlugin_Hypothesis_i::SetFineness (CORBA::Long theValue)
208 if ( isToSetParameter( GetFineness(), theValue, METH_SetFineness ))
210 this->GetImpl()->SetFineness((::NETGENPlugin_Hypothesis::Fineness)theValue);
211 SMESH::TPythonDump() << _this() << ".SetFineness( " << theValue << " )";
215 //=============================================================================
217 * NETGENPlugin_Hypothesis_i::GetFineness
221 //=============================================================================
222 CORBA::Long NETGENPlugin_Hypothesis_i::GetFineness()
224 return this->GetImpl()->GetFineness();
227 //=============================================================================
229 * NETGENPlugin_Hypothesis_i::SetGrowthRate
233 //=============================================================================
234 void NETGENPlugin_Hypothesis_i::SetGrowthRate (CORBA::Double theValue)
236 if ( isToSetParameter( GetGrowthRate(), theValue, METH_SetGrowthRate ))
238 this->GetImpl()->SetGrowthRate(theValue);
239 SMESH::TPythonDump() << _this() << ".SetGrowthRate( " << SMESH::TVar(theValue) << " )";
243 //=============================================================================
245 * NETGENPlugin_Hypothesis_i::GetGrowthRate
249 //=============================================================================
250 CORBA::Double NETGENPlugin_Hypothesis_i::GetGrowthRate()
252 return this->GetImpl()->GetGrowthRate();
255 //=============================================================================
257 * NETGENPlugin_Hypothesis_i::SetNbSegPerEdge
261 //=============================================================================
262 void NETGENPlugin_Hypothesis_i::SetNbSegPerEdge (CORBA::Double theValue)
264 if ( isToSetParameter( GetNbSegPerEdge(), theValue, METH_SetNbSegPerEdge ))
266 this->GetImpl()->SetNbSegPerEdge(theValue);
267 SMESH::TPythonDump() << _this() << ".SetNbSegPerEdge( " << SMESH::TVar(theValue) << " )";
271 //=============================================================================
273 * NETGENPlugin_Hypothesis_i::GetNbSegPerEdge
277 //=============================================================================
278 CORBA::Double NETGENPlugin_Hypothesis_i::GetNbSegPerEdge()
280 return this->GetImpl()->GetNbSegPerEdge();
283 //=============================================================================
285 * NETGENPlugin_Hypothesis_i::SetNbSegPerRadius
289 //=============================================================================
290 void NETGENPlugin_Hypothesis_i::SetNbSegPerRadius (CORBA::Double theValue)
292 if ( isToSetParameter( GetNbSegPerRadius(), theValue, METH_SetNbSegPerRadius ))
294 this->GetImpl()->SetNbSegPerRadius(theValue);
295 SMESH::TPythonDump() << _this() << ".SetNbSegPerRadius( " << SMESH::TVar(theValue) << " )";
299 //=============================================================================
301 * NETGENPlugin_Hypothesis_i::GetNbSegPerRadius
305 //=============================================================================
306 CORBA::Double NETGENPlugin_Hypothesis_i::GetNbSegPerRadius()
308 return this->GetImpl()->GetNbSegPerRadius();
311 //=============================================================================
313 void NETGENPlugin_Hypothesis_i::SetLocalSizeOnShape(GEOM::GEOM_Object_ptr GeomObj,
314 CORBA::Double localSize)
317 entry = GeomObj->GetStudyEntry();
318 SetLocalSizeOnEntry(entry.c_str(), localSize);
321 //=============================================================================
323 void NETGENPlugin_Hypothesis_i::SetLocalSizeOnEntry(const char* entry,
324 CORBA::Double localSize)
326 if ( isToSetParameter( GetLocalSizeOnEntry(entry), localSize, METH_SetLocalSizeOnEntry ))
328 this->GetImpl()->SetLocalSizeOnEntry(entry, localSize);
330 << _this() << ".SetLocalSizeOnShape(" << entry << ", " << localSize << ")";
334 //=============================================================================
336 CORBA::Double NETGENPlugin_Hypothesis_i::GetLocalSizeOnEntry(const char* entry)
338 return this->GetImpl()->GetLocalSizeOnEntry(entry);
341 //=============================================================================
343 NETGENPlugin::string_array* NETGENPlugin_Hypothesis_i::GetLocalSizeEntries()
345 NETGENPlugin::string_array_var result = new NETGENPlugin::string_array();
346 const ::NETGENPlugin_Hypothesis::TLocalSize localSizes =
347 this->GetImpl()->GetLocalSizesAndEntries();
348 result->length(localSizes.size());
349 ::NETGENPlugin_Hypothesis::TLocalSize::const_iterator it = localSizes.begin();
350 for (int i=0 ; it != localSizes.end() ; i++, it++)
352 string entry = (*it).first;
353 result[i] = CORBA::string_dup(entry.c_str());
355 return result._retn();
358 //=============================================================================
360 void NETGENPlugin_Hypothesis_i::UnsetLocalSizeOnEntry(const char* entry)
362 this->GetImpl()->UnsetLocalSizeOnEntry(entry);
363 SMESH::TPythonDump() << _this() << ".UnsetLocalSizeOnEntry(" << entry << ")";
366 //=============================================================================
368 void NETGENPlugin_Hypothesis_i::SetQuadAllowed (CORBA::Boolean theValue)
370 if ( NETGENPlugin_Hypothesis_i::isToSetParameter( GetQuadAllowed(),
372 METH_SetQuadAllowed ))
374 this->GetImpl()->SetQuadAllowed(theValue);
375 SMESH::TPythonDump() << _this() << ".SetQuadAllowed( " << theValue << " )";
379 //=============================================================================
381 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetQuadAllowed()
383 return this->GetImpl()->GetQuadAllowed();
386 //=============================================================================
388 * NETGENPlugin_Hypothesis_i::GetImpl
392 //=============================================================================
393 ::NETGENPlugin_Hypothesis* NETGENPlugin_Hypothesis_i::GetImpl()
395 return (::NETGENPlugin_Hypothesis*)myBaseImpl;
398 //================================================================================
400 * \brief Verify whether hypothesis supports given entity type
401 * \param type - dimension (see SMESH::Dimension enumeration)
402 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
404 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
406 //================================================================================
407 CORBA::Boolean NETGENPlugin_Hypothesis_i::IsDimSupported( SMESH::Dimension type )
409 return type == SMESH::DIM_3D;
412 //================================================================================
414 * \brief method intended to remove explicit treatment of Netgen hypotheses from SMESH_NoteBook
416 //================================================================================
418 int NETGENPlugin_Hypothesis_i::getParamIndex(const TCollection_AsciiString& method,
421 if ( method == "SetMaxSize" ) return 0;
422 if ( method == "SetGrowthRate" ) return 1;
423 if ( method == "SetNbSegPerEdge" ) return 2;
424 if ( method == "SetNbSegPerRadius" ) return 3;
425 if ( method == "SetMinSize" ) return nbVars-1;
427 return SMESH_Hypothesis_i::getParamIndex( method, nbVars ); // return default value
430 //================================================================================
432 * \brief Method used to convert variable parameters stored in an old study
433 * into myMethod2VarParams. It should return a method name for an index of
434 * variable parameters. Index is countered from zero
436 //================================================================================
438 std::string NETGENPlugin_Hypothesis_i::getMethodOfParameter(const int paramIndex,
441 switch ( paramIndex ) {
442 case 0: return "SetMaxSize";
443 case 1: return nbVars == 2 ? "SetMinSize" : "SetGrowthRate";
444 case 2: return "SetNbSegPerEdge";
445 case 3: return "SetNbSegPerRadius";
446 case 4: return "SetMinSize";