1 // Copyright (C) 2007-2021 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,
62 ::SMESH_Gen* theGenImpl)
63 : SALOME::GenericObj_i( thePOA ),
64 SMESH_Hypothesis_i( thePOA ),
67 myBaseImpl = new ::NETGENPlugin_Hypothesis (theGenImpl->GetANewId(),
71 //=============================================================================
73 * NETGENPlugin_Hypothesis_i::~NETGENPlugin_Hypothesis_i
77 //=============================================================================
78 NETGENPlugin_Hypothesis_i::~NETGENPlugin_Hypothesis_i()
82 //=============================================================================
84 * NETGENPlugin_Hypothesis_i::SetMaxSize
88 //=============================================================================
89 void NETGENPlugin_Hypothesis_i::SetMaxSize (CORBA::Double theValue)
91 if ( isToSetParameter( GetMaxSize(), theValue, METH_SetMaxSize ))
93 this->GetImpl()->SetMaxSize(theValue);
94 SMESH::TPythonDump() << _this() << ".SetMaxSize( " << SMESH::TVar(theValue) << " )";
98 //=============================================================================
100 * NETGENPlugin_Hypothesis_i::GetMaxSize
104 //=============================================================================
105 CORBA::Double NETGENPlugin_Hypothesis_i::GetMaxSize()
107 return this->GetImpl()->GetMaxSize();
110 //=============================================================================
112 * NETGENPlugin_Hypothesis_i::SetMinSize
116 //=============================================================================
117 void NETGENPlugin_Hypothesis_i::SetMinSize (CORBA::Double theValue)
119 if ( isToSetParameter( GetMinSize(), theValue, METH_SetMinSize ))
121 this->GetImpl()->SetMinSize(theValue);
122 SMESH::TPythonDump() << _this() << ".SetMinSize( " << SMESH::TVar(theValue) << " )";
126 //=============================================================================
128 * NETGENPlugin_Hypothesis_i::GetMinSize
132 //=============================================================================
133 CORBA::Double NETGENPlugin_Hypothesis_i::GetMinSize()
135 return this->GetImpl()->GetMinSize();
138 //=============================================================================
140 * NETGENPlugin_Hypothesis_i::SetSecondOrder
142 * Set SecondOrder flag
144 //=============================================================================
145 void NETGENPlugin_Hypothesis_i::SetSecondOrder (CORBA::Boolean theValue)
147 if ( isToSetParameter( GetSecondOrder(), theValue, METH_SetSecondOrder ))
149 this->GetImpl()->SetSecondOrder(theValue);
150 SMESH::TPythonDump() << _this() << ".SetSecondOrder( " << theValue << " )";
154 //=============================================================================
156 * NETGENPlugin_Hypothesis_i::GetSecondOrder
158 * Get SecondOrder flag
160 //=============================================================================
161 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetSecondOrder()
163 return this->GetImpl()->GetSecondOrder();
166 //=============================================================================
168 * NETGENPlugin_Hypothesis_i::SetOptimize
172 //=============================================================================
173 void NETGENPlugin_Hypothesis_i::SetOptimize (CORBA::Boolean theValue)
175 if ( isToSetParameter( GetOptimize(), theValue, METH_SetOptimize ))
177 this->GetImpl()->SetOptimize(theValue);
178 SMESH::TPythonDump() << _this() << ".SetOptimize( " << theValue << " )";
182 //=============================================================================
184 * NETGENPlugin_Hypothesis_i::GetOptimize
188 //=============================================================================
189 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetOptimize()
191 return this->GetImpl()->GetOptimize();
194 //=============================================================================
196 * NETGENPlugin_Hypothesis_i::SetFineness
200 //=============================================================================
201 void NETGENPlugin_Hypothesis_i::SetFineness (CORBA::Long theValue)
203 if ( isToSetParameter( GetFineness(), theValue, METH_SetFineness ))
205 this->GetImpl()->SetFineness((::NETGENPlugin_Hypothesis::Fineness)theValue);
206 SMESH::TPythonDump() << _this() << ".SetFineness( " << theValue << " )";
210 //=============================================================================
212 * NETGENPlugin_Hypothesis_i::GetFineness
216 //=============================================================================
217 CORBA::Long NETGENPlugin_Hypothesis_i::GetFineness()
219 return this->GetImpl()->GetFineness();
222 //=============================================================================
224 * NETGENPlugin_Hypothesis_i::SetGrowthRate
228 //=============================================================================
229 void NETGENPlugin_Hypothesis_i::SetGrowthRate (CORBA::Double theValue)
231 if ( isToSetParameter( GetGrowthRate(), theValue, METH_SetGrowthRate ))
233 this->GetImpl()->SetGrowthRate(theValue);
234 SMESH::TPythonDump() << _this() << ".SetGrowthRate( " << SMESH::TVar(theValue) << " )";
238 //=============================================================================
240 * NETGENPlugin_Hypothesis_i::GetGrowthRate
244 //=============================================================================
245 CORBA::Double NETGENPlugin_Hypothesis_i::GetGrowthRate()
247 return this->GetImpl()->GetGrowthRate();
250 //=============================================================================
252 * NETGENPlugin_Hypothesis_i::SetNbSegPerEdge
256 //=============================================================================
257 void NETGENPlugin_Hypothesis_i::SetNbSegPerEdge (CORBA::Double theValue)
259 if ( isToSetParameter( GetNbSegPerEdge(), theValue, METH_SetNbSegPerEdge ))
261 this->GetImpl()->SetNbSegPerEdge(theValue);
262 SMESH::TPythonDump() << _this() << ".SetNbSegPerEdge( " << SMESH::TVar(theValue) << " )";
266 //=============================================================================
268 * NETGENPlugin_Hypothesis_i::GetNbSegPerEdge
272 //=============================================================================
273 CORBA::Double NETGENPlugin_Hypothesis_i::GetNbSegPerEdge()
275 return this->GetImpl()->GetNbSegPerEdge();
278 //=============================================================================
280 * NETGENPlugin_Hypothesis_i::SetNbSegPerRadius
284 //=============================================================================
285 void NETGENPlugin_Hypothesis_i::SetNbSegPerRadius (CORBA::Double theValue)
287 if ( isToSetParameter( GetNbSegPerRadius(), theValue, METH_SetNbSegPerRadius ))
289 this->GetImpl()->SetNbSegPerRadius(theValue);
290 SMESH::TPythonDump() << _this() << ".SetNbSegPerRadius( " << SMESH::TVar(theValue) << " )";
294 //=============================================================================
296 * NETGENPlugin_Hypothesis_i::GetNbSegPerRadius
300 //=============================================================================
301 CORBA::Double NETGENPlugin_Hypothesis_i::GetNbSegPerRadius()
303 return this->GetImpl()->GetNbSegPerRadius();
306 //=============================================================================
308 void NETGENPlugin_Hypothesis_i::SetChordalErrorEnabled(CORBA::Boolean theValue)
310 if ( isToSetParameter( GetChordalErrorEnabled(), theValue, METH_SetChordalErrorEnabled ))
312 this->GetImpl()->SetChordalErrorEnabled(theValue);
313 SMESH::TPythonDump() << _this() << ".SetChordalErrorEnabled( " << theValue << " )";
317 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetChordalErrorEnabled()
319 return GetImpl()->GetChordalErrorEnabled();
322 void NETGENPlugin_Hypothesis_i::SetChordalError(CORBA::Double theValue)
324 if ( isToSetParameter( GetChordalError(), theValue, METH_SetChordalError ))
326 this->GetImpl()->SetChordalError(theValue);
327 SMESH::TPythonDump() << _this() << ".SetChordalError( " << SMESH::TVar(theValue) << " )";
331 CORBA::Double NETGENPlugin_Hypothesis_i::GetChordalError()
333 return GetImpl()->GetChordalError();
336 //=============================================================================
338 void NETGENPlugin_Hypothesis_i::SetLocalSizeOnShape(GEOM::GEOM_Object_ptr GeomObj,
339 CORBA::Double localSize)
342 entry = GeomObj->GetStudyEntry();
344 THROW_SALOME_CORBA_EXCEPTION( "SetLocalSizeOnShape(), shape is not published in study!",
346 SetLocalSizeOnEntry(entry.c_str(), localSize);
349 //=============================================================================
351 void NETGENPlugin_Hypothesis_i::SetLocalSizeOnEntry(const char* entry,
352 CORBA::Double localSize)
354 if ( isToSetParameter( GetLocalSizeOnEntry(entry), localSize, METH_SetLocalSizeOnEntry ))
356 this->GetImpl()->SetLocalSizeOnEntry(entry, localSize);
358 << _this() << ".SetLocalSizeOnShape(" << entry << ", " << localSize << ")";
362 //=============================================================================
364 CORBA::Double NETGENPlugin_Hypothesis_i::GetLocalSizeOnEntry(const char* entry)
366 return this->GetImpl()->GetLocalSizeOnEntry(entry);
369 //=============================================================================
371 NETGENPlugin::string_array* NETGENPlugin_Hypothesis_i::GetLocalSizeEntries()
373 NETGENPlugin::string_array_var result = new NETGENPlugin::string_array();
374 const ::NETGENPlugin_Hypothesis::TLocalSize localSizes =
375 this->GetImpl()->GetLocalSizesAndEntries();
376 result->length(localSizes.size());
377 ::NETGENPlugin_Hypothesis::TLocalSize::const_iterator it = localSizes.begin();
378 for (int i=0 ; it != localSizes.end() ; i++, it++)
380 string entry = (*it).first;
381 result[i] = CORBA::string_dup(entry.c_str());
383 return result._retn();
386 //=============================================================================
388 void NETGENPlugin_Hypothesis_i::UnsetLocalSizeOnEntry(const char* entry)
390 this->GetImpl()->UnsetLocalSizeOnEntry(entry);
391 SMESH::TPythonDump() << _this() << ".UnsetLocalSizeOnEntry(\"" << entry << "\")";
394 //=============================================================================
396 void NETGENPlugin_Hypothesis_i::SetMeshSizeFile(const char* fileName)
398 if ( GetImpl()->GetMeshSizeFile() != fileName )
400 GetImpl()->SetMeshSizeFile( fileName );
401 SMESH::TPythonDump() << _this() << ".SetMeshSizeFile( '" << fileName << "' )";
405 //=============================================================================
407 char* NETGENPlugin_Hypothesis_i::GetMeshSizeFile()
409 return CORBA::string_dup( GetImpl()->GetMeshSizeFile().c_str() );
412 //=============================================================================
414 void NETGENPlugin_Hypothesis_i::SetQuadAllowed (CORBA::Boolean theValue)
416 if ( NETGENPlugin_Hypothesis_i::isToSetParameter( GetQuadAllowed(),
418 METH_SetQuadAllowed ))
420 this->GetImpl()->SetQuadAllowed(theValue);
421 SMESH::TPythonDump() << _this() << ".SetQuadAllowed( " << theValue << " )";
425 //=============================================================================
427 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetQuadAllowed()
429 return this->GetImpl()->GetQuadAllowed();
432 //=============================================================================
434 void NETGENPlugin_Hypothesis_i::SetUseSurfaceCurvature (CORBA::Boolean theValue)
436 if ( NETGENPlugin_Hypothesis_i::isToSetParameter( GetUseSurfaceCurvature(),
438 METH_SetSurfaceCurvature ))
440 this->GetImpl()->SetSurfaceCurvature(theValue);
441 SMESH::TPythonDump() << _this() << ".SetUseSurfaceCurvature( " << theValue << " )";
445 //=============================================================================
447 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetUseSurfaceCurvature()
449 return this->GetImpl()->GetSurfaceCurvature();
452 //=============================================================================
454 void NETGENPlugin_Hypothesis_i::SetFuseEdges (CORBA::Boolean theValue)
456 if ( NETGENPlugin_Hypothesis_i::isToSetParameter( GetFuseEdges(),
460 this->GetImpl()->SetFuseEdges(theValue);
461 SMESH::TPythonDump() << _this() << ".SetFuseEdges( " << theValue << " )";
465 //=============================================================================
467 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetFuseEdges()
469 return this->GetImpl()->GetFuseEdges();
472 //=======================================================================
473 //function : SetNbSurfOptSteps
475 //=======================================================================
477 void NETGENPlugin_Hypothesis_i::SetNbSurfOptSteps(CORBA::Short nb )
479 if ( GetNbSurfOptSteps() != nb )
481 this->GetImpl()->SetNbSurfOptSteps( nb );
482 SMESH::TPythonDump() << _this() << ".SetNbSurfOptSteps( " << SMESH::TVar(nb) << " )";
486 //=======================================================================
487 //function : GetNbSurfOptSteps
489 //=======================================================================
491 CORBA::Short NETGENPlugin_Hypothesis_i::GetNbSurfOptSteps()
493 return GetImpl()->GetNbSurfOptSteps();
496 //=======================================================================
497 //function : SetNbVolOptSteps
499 //=======================================================================
501 void NETGENPlugin_Hypothesis_i::SetNbVolOptSteps(CORBA::Short nb )
503 if ( GetNbVolOptSteps() != nb )
505 this->GetImpl()->SetNbVolOptSteps( nb );
506 SMESH::TPythonDump() << _this() << ".SetNbVolOptSteps( " << SMESH::TVar(nb) << " )";
511 //=======================================================================
512 //function : GetNbVolOptSteps
514 //=======================================================================
516 CORBA::Short NETGENPlugin_Hypothesis_i::GetNbVolOptSteps()
518 return GetImpl()->GetNbVolOptSteps();
521 //=======================================================================
522 //function : SetElemSizeWeight
524 //=======================================================================
526 void NETGENPlugin_Hypothesis_i::SetElemSizeWeight(CORBA::Double size )
528 if ( GetElemSizeWeight() != size )
530 this->GetImpl()->SetElemSizeWeight( size );
531 SMESH::TPythonDump() << _this() << ".SetElemSizeWeight( " << SMESH::TVar(size) << " )";
535 //=======================================================================
536 //function : GetElemSizeWeight
538 //=======================================================================
540 CORBA::Double NETGENPlugin_Hypothesis_i::GetElemSizeWeight()
542 return GetImpl()->GetElemSizeWeight();
545 //=======================================================================
546 //function : SetWorstElemMeasure
548 //=======================================================================
550 void NETGENPlugin_Hypothesis_i::SetWorstElemMeasure(CORBA::Short val )
552 if ( GetWorstElemMeasure() != val )
554 this->GetImpl()->SetWorstElemMeasure( val );
555 SMESH::TPythonDump() << _this() << ".SetWorstElemMeasure( " << SMESH::TVar(val) << " )";
559 //=======================================================================
560 //function : GetWorstElemMeasure
562 //=======================================================================
564 CORBA::Short NETGENPlugin_Hypothesis_i::GetWorstElemMeasure()
566 return GetImpl()->GetWorstElemMeasure();
569 //=======================================================================
570 //function : SetUseDelauney
572 //=======================================================================
574 void NETGENPlugin_Hypothesis_i::SetUseDelauney(CORBA::Boolean toUse)
576 if ( GetUseDelauney() != toUse )
578 this->GetImpl()->SetUseDelauney( toUse );
579 SMESH::TPythonDump() << _this() << ".SetUseDelauney( " << toUse << " )";
583 //=======================================================================
584 //function : GetUseDelauney
586 //=======================================================================
588 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetUseDelauney()
590 return GetImpl()->GetUseDelauney();
593 //=======================================================================
594 //function : SetCheckOverlapping
596 //=======================================================================
598 void NETGENPlugin_Hypothesis_i::SetCheckOverlapping(CORBA::Boolean toCheck )
600 if ( GetCheckOverlapping() != toCheck )
602 this->GetImpl()->SetCheckOverlapping( toCheck );
603 SMESH::TPythonDump() << _this() << ".SetCheckOverlapping( " << toCheck << " )";
607 //=======================================================================
608 //function : GetCheckOverlapping
610 //=======================================================================
612 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetCheckOverlapping()
614 return GetImpl()->GetCheckOverlapping();
617 //=======================================================================
618 //function : SetCheckChartBoundary
620 //=======================================================================
622 void NETGENPlugin_Hypothesis_i::SetCheckChartBoundary(CORBA::Boolean toCheck )
624 if ( GetCheckChartBoundary() != toCheck )
626 this->GetImpl()->SetCheckChartBoundary( toCheck );
627 SMESH::TPythonDump() << _this() << ".SetCheckChartBoundary( " << toCheck << " )";
631 //=======================================================================
632 //function : GetCheckChartBoundary
633 //purpose : Get implementation
634 //=======================================================================
636 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetCheckChartBoundary()
638 return GetImpl()->GetCheckChartBoundary();
641 //=============================================================================
643 * NETGENPlugin_Hypothesis_i::GetImpl
647 //=============================================================================
648 ::NETGENPlugin_Hypothesis* NETGENPlugin_Hypothesis_i::GetImpl()
650 return (::NETGENPlugin_Hypothesis*)myBaseImpl;
653 //================================================================================
655 * \brief Verify whether hypothesis supports given entity type
656 * \param type - dimension (see SMESH::Dimension enumeration)
657 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
659 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
661 //================================================================================
662 CORBA::Boolean NETGENPlugin_Hypothesis_i::IsDimSupported( SMESH::Dimension type )
664 return type == SMESH::DIM_3D;
667 //================================================================================
669 * \brief method intended to remove explicit treatment of Netgen hypotheses from SMESH_NoteBook
671 //================================================================================
673 int NETGENPlugin_Hypothesis_i::getParamIndex(const TCollection_AsciiString& method,
676 if ( method == "SetMaxSize" ) return 0;
677 if ( method == "SetGrowthRate" ) return 1;
678 if ( method == "SetNbSegPerEdge" ) return 2;
679 if ( method == "SetNbSegPerRadius" ) return 3;
680 if ( method == "SetMinSize" ) return nbVars-1;
682 return SMESH_Hypothesis_i::getParamIndex( method, nbVars ); // return default value
685 //================================================================================
687 * \brief Method used to convert variable parameters stored in an old study
688 * into myMethod2VarParams. It should return a method name for an index of
689 * variable parameters. Index is countered from zero
691 //================================================================================
693 std::string NETGENPlugin_Hypothesis_i::getMethodOfParameter(const int paramIndex,
696 switch ( paramIndex ) {
697 case 0: return "SetMaxSize";
698 case 1: return nbVars == 2 ? "SetMinSize" : "SetGrowthRate";
699 case 2: return "SetNbSegPerEdge";
700 case 3: return "SetNbSegPerRadius";
701 case 4: return "SetMinSize";
706 //================================================================================
708 * \brief Return geometry this hypothesis depends on. Return false if there is no geometry parameter
710 //================================================================================
713 NETGENPlugin_Hypothesis_i::getObjectsDependOn( std::vector< std::string > & entryArray,
714 std::vector< int > & /*subIDArray*/ ) const
716 typedef ::NETGENPlugin_Hypothesis THyp;
718 const THyp* h = static_cast< ::NETGENPlugin_Hypothesis* >( myBaseImpl );
719 const THyp::TLocalSize& ls = h->GetLocalSizesAndEntries();
721 THyp::TLocalSize::const_iterator entry2size = ls.cbegin();
722 for ( ; entry2size != ls.cend(); ++entry2size )
723 entryArray.push_back( entry2size->first );
728 //================================================================================
730 * \brief Set new geometry instead of that returned by getObjectsDependOn()
732 //================================================================================
735 NETGENPlugin_Hypothesis_i::setObjectsDependOn( std::vector< std::string > & entryArray,
736 std::vector< int > & /*subIDArray*/ )
738 typedef ::NETGENPlugin_Hypothesis THyp;
740 const THyp* h = static_cast< ::NETGENPlugin_Hypothesis* >( myBaseImpl );
742 THyp::TLocalSize& lsNew = const_cast< THyp::TLocalSize& >( h->GetLocalSizesAndEntries() );
746 THyp::TLocalSize::const_iterator entry2size = ls.cbegin();
747 for ( int i = 0; entry2size != ls.cend(); ++entry2size, ++i )
748 if ( !entryArray[ i ].empty() )
749 lsNew[ entryArray[ i ]] = entry2size->second;