Salome HOME
0021014: EDF 1583 SMESH: Improvement of the Python Dumpfor the creation of groups
[modules/smesh.git] / src / SMESH_I / SMESH_Filter_i.cxx
index d2a7ae648d7b2510cbef06115cb41d1a3276743c..948222dafb7cb45df871fb775837cf5045df8b1e 100644 (file)
@@ -1,23 +1,23 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
@@ -34,6 +34,7 @@
 #include "SMDS_MeshNode.hxx"
 #include "SMDS_MeshElement.hxx"
 #include "SMDS_ElemIterator.hxx"
+#include "SMDS_VolumeTool.hxx"
 
 #include "SMESHDS_Mesh.hxx"
 
@@ -572,7 +573,7 @@ Functor_i::Functor_i():
 
 Functor_i::~Functor_i()
 {
-  //TPythonDump()<<this<<".Destroy()";
+  //TPythonDump()<<this<<".UnRegister()";
 }
 
 void Functor_i::SetMesh( SMESH_Mesh_ptr theMesh )
@@ -600,7 +601,8 @@ SMESH::Histogram* NumericalFunctor_i::GetHistogram(CORBA::Short nbIntervals)
 {
   std::vector<int> nbEvents;
   std::vector<double> funValues;
-  myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues);
+  std::vector<int> elements;
+  myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues,elements);
 
   nbIntervals = CORBA::Short( std::min( nbEvents.size(), funValues.size() - 1));
   SMESH::Histogram_var histogram = new SMESH::Histogram;
@@ -937,6 +939,66 @@ FunctorType BadOrientedVolume_i::GetFunctorType()
   return SMESH::FT_BadOrientedVolume;
 }
 
+/*
+  Class       : BareBorderVolume_i
+  Description : Verify whether a mesh volume has a free facet without a face on it
+*/
+BareBorderVolume_i::BareBorderVolume_i()
+{
+  Controls::PredicatePtr control( new Controls::BareBorderVolume() );
+  myFunctorPtr = myPredicatePtr = control;
+};
+
+FunctorType BareBorderVolume_i::GetFunctorType()
+{
+  return SMESH::FT_BareBorderVolume;
+}
+
+/*
+  Class       : BareBorderFace_i
+  Description : Verify whether a mesh face has a free border without an edge on it
+*/
+BareBorderFace_i::BareBorderFace_i()
+{
+  Controls::PredicatePtr control( new Controls::BareBorderFace() );
+  myFunctorPtr = myPredicatePtr = control;
+};
+
+FunctorType BareBorderFace_i::GetFunctorType()
+{
+  return SMESH::FT_BareBorderFace;
+}
+
+/*
+  Class       : OverConstrainedVolume_i
+  Description : Verify whether a mesh volume has only one facet shared with other volumes
+*/
+OverConstrainedVolume_i::OverConstrainedVolume_i()
+{
+  Controls::PredicatePtr control( new Controls::OverConstrainedVolume() );
+  myFunctorPtr = myPredicatePtr = control;
+};
+
+FunctorType OverConstrainedVolume_i::GetFunctorType()
+{
+  return SMESH::FT_OverConstrainedVolume;
+}
+
+/*
+  Class       : OverConstrainedFace_i
+  Description : Verify whether a mesh face has only one border shared with other faces
+*/
+OverConstrainedFace_i::OverConstrainedFace_i()
+{
+  Controls::PredicatePtr control( new Controls::OverConstrainedFace() );
+  myFunctorPtr = myPredicatePtr = control;
+};
+
+FunctorType OverConstrainedFace_i::GetFunctorType()
+{
+  return SMESH::FT_OverConstrainedFace;
+}
+
 /*
   Class       : BelongToGeom_i
   Description : Predicate for selection on geometrical support
@@ -1557,7 +1619,7 @@ Comparator_i::Comparator_i():
 Comparator_i::~Comparator_i()
 {
   if ( myNumericalFunctor )
-    myNumericalFunctor->Destroy();
+    myNumericalFunctor->UnRegister();
 }
 
 void Comparator_i::SetMargin( CORBA::Double theValue )
@@ -1574,7 +1636,7 @@ CORBA::Double Comparator_i::GetMargin()
 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
 {
   if ( myNumericalFunctor )
-    myNumericalFunctor->Destroy();
+    myNumericalFunctor->UnRegister();
 
   myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
 
@@ -1669,13 +1731,13 @@ LogicalNOT_i::LogicalNOT_i()
 LogicalNOT_i::~LogicalNOT_i()
 {
   if ( myPredicate )
-    myPredicate->Destroy();
+    myPredicate->UnRegister();
 }
 
 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
 {
   if ( myPredicate )
-    myPredicate->Destroy();
+    myPredicate->UnRegister();
 
   myPredicate = SMESH::GetPredicate(thePredicate);
 
@@ -1709,10 +1771,10 @@ LogicalBinary_i::LogicalBinary_i()
 LogicalBinary_i::~LogicalBinary_i()
 {
   if ( myPredicate1 )
-    myPredicate1->Destroy();
+    myPredicate1->UnRegister();
 
   if ( myPredicate2 )
-    myPredicate2->Destroy();
+    myPredicate2->UnRegister();
 }
 
 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
@@ -1727,7 +1789,7 @@ void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
 {
   if ( myPredicate1 )
-    myPredicate1->Destroy();
+    myPredicate1->UnRegister();
 
   myPredicate1 = SMESH::GetPredicate(thePredicate);
 
@@ -1741,7 +1803,7 @@ void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
 {
   if ( myPredicate2 )
-    myPredicate2->Destroy();
+    myPredicate2->UnRegister();
 
   myPredicate2 = SMESH::GetPredicate(thePredicate);
 
@@ -1814,7 +1876,7 @@ FilterManager_i::FilterManager_i()
 
 FilterManager_i::~FilterManager_i()
 {
-  //TPythonDump()<<this<<".Destroy()";
+  //TPythonDump()<<this<<".UnRegister()";
 }
 
 
@@ -2036,6 +2098,38 @@ BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
   return anObj._retn();
 }
 
+BareBorderVolume_ptr FilterManager_i::CreateBareBorderVolume()
+{
+  SMESH::BareBorderVolume_i* aServant = new SMESH::BareBorderVolume_i();
+  SMESH::BareBorderVolume_var anObj = aServant->_this();
+  TPythonDump()<<aServant<<" = "<<this<<".CreateBareBorderVolume()";
+  return anObj._retn();
+}
+
+BareBorderFace_ptr FilterManager_i::CreateBareBorderFace()
+{
+  SMESH::BareBorderFace_i* aServant = new SMESH::BareBorderFace_i();
+  SMESH::BareBorderFace_var anObj = aServant->_this();
+  TPythonDump()<<aServant<<" = "<<this<<".CreateBareBorderFace()";
+  return anObj._retn();
+}
+
+OverConstrainedVolume_ptr FilterManager_i::CreateOverConstrainedVolume()
+{
+  SMESH::OverConstrainedVolume_i* aServant = new SMESH::OverConstrainedVolume_i();
+  SMESH::OverConstrainedVolume_var anObj = aServant->_this();
+  TPythonDump()<<aServant<<" = "<<this<<".CreateOverConstrainedVolume()";
+  return anObj._retn();
+}
+
+OverConstrainedFace_ptr FilterManager_i::CreateOverConstrainedFace()
+{
+  SMESH::OverConstrainedFace_i* aServant = new SMESH::OverConstrainedFace_i();
+  SMESH::OverConstrainedFace_var anObj = aServant->_this();
+  TPythonDump()<<aServant<<" = "<<this<<".CreateOverConstrainedFace()";
+  return anObj._retn();
+}
+
 LessThan_ptr FilterManager_i::CreateLessThan()
 {
   SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
@@ -2173,12 +2267,12 @@ Filter_i::Filter_i()
 Filter_i::~Filter_i()
 {
   if ( myPredicate )
-    myPredicate->Destroy();
+    myPredicate->UnRegister();
 
   if(!CORBA::is_nil(myMesh))
-    myMesh->Destroy();
+    myMesh->UnRegister();
 
-  //TPythonDump()<<this<<".Destroy()";
+  //TPythonDump()<<this<<".UnRegister()";
 }
 
 //=======================================================================
@@ -2188,7 +2282,7 @@ Filter_i::~Filter_i()
 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
 {
   if ( myPredicate )
-    myPredicate->Destroy();
+    myPredicate->UnRegister();
 
   myPredicate = SMESH::GetPredicate(thePredicate);
 
@@ -2198,6 +2292,9 @@ void Filter_i::SetPredicate( Predicate_ptr thePredicate )
     myPredicate->Register();
     TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
   }
+  std::list<TPredicateChangeWaiter*>::iterator i = myWaiters.begin();
+  for ( ; i != myWaiters.end(); ++i )
+    (*i)->PredicateChanged();
 }
 
 //=======================================================================
@@ -2221,7 +2318,7 @@ SetMesh( SMESH_Mesh_ptr theMesh )
     theMesh->Register();
 
   if(!CORBA::is_nil(myMesh))
-    myMesh->Destroy();
+    myMesh->UnRegister();
 
   myMesh = SMESH_Mesh::_duplicate( theMesh );
   TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
@@ -2306,26 +2403,25 @@ SMESH::long_array* ::Filter_i::GetMeshInfo()
     SMDS_ElemIteratorPtr it;
     switch( GetElementType() )
     {
-  case SMDSAbs_Node:
-    collectMeshInfo<const SMDS_MeshNode*>(aMesh->nodesIterator(),myPredicate,aRes);
-    break;
-  case SMDSAbs_Edge:
-    collectMeshInfo<const SMDS_MeshElement*>(aMesh->edgesIterator(),myPredicate,aRes);
-    break;
-  case SMDSAbs_Face:
-    collectMeshInfo<const SMDS_MeshElement*>(aMesh->facesIterator(),myPredicate,aRes);
-    break;
-  case SMDSAbs_Volume:
-    collectMeshInfo<const SMDS_MeshElement*>(aMesh->volumesIterator(),myPredicate,aRes);
-    break;
-  case SMDSAbs_All:
-  default:
-    collectMeshInfo<const SMDS_MeshElement*>(aMesh->elementsIterator(),myPredicate,aRes);
-    break;
+    case SMDSAbs_Node:
+      collectMeshInfo<const SMDS_MeshNode*>(aMesh->nodesIterator(),myPredicate,aRes);
+      break;
+    case SMDSAbs_Edge:
+      collectMeshInfo<const SMDS_MeshElement*>(aMesh->edgesIterator(),myPredicate,aRes);
+      break;
+    case SMDSAbs_Face:
+      collectMeshInfo<const SMDS_MeshElement*>(aMesh->facesIterator(),myPredicate,aRes);
+      break;
+    case SMDSAbs_Volume:
+      collectMeshInfo<const SMDS_MeshElement*>(aMesh->volumesIterator(),myPredicate,aRes);
+      break;
+    case SMDSAbs_All:
+    default:
+      collectMeshInfo<const SMDS_MeshElement*>(aMesh->elementsIterator(),myPredicate,aRes);
+      break;
     }
   }
 
-
   return aRes._retn();  
 }
 
@@ -2339,8 +2435,20 @@ SMESH::long_array* ::Filter_i::GetMeshInfo()
 SMESH::array_of_ElementType* Filter_i::GetTypes()
 {
   SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
-  types->length( 1 );
-  types[0] = GetElementType();
+
+  // check if any element passes through the filter
+  if ( !CORBA::is_nil(myMesh) && myPredicate )
+  {
+    const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
+    SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() ));
+    bool satisfies = false;
+    while ( !satisfies && it->more() )
+      satisfies = myPredicate->IsSatisfy( it->next()->GetID() );
+    if ( satisfies ) {
+      types->length( 1 );
+      types[0] = GetElementType();
+    }
+  }
   return types._retn();
 }
 
@@ -2354,6 +2462,29 @@ SMESH::SMESH_Mesh_ptr Filter_i::GetMesh()
   return SMESH_Mesh::_duplicate( myMesh );
 }
 
+//================================================================================
+/*!
+ * \brief Stores an object to be notified on change of predicate
+ */
+//================================================================================
+
+void Filter_i::AddWaiter( TPredicateChangeWaiter* waiter )
+{
+  if ( waiter )
+    myWaiters.push_back( waiter );
+}
+
+//================================================================================
+/*!
+ * \brief Removes an object to be notified on change of predicate
+ */
+//================================================================================
+
+void Filter_i::RemoveWaiter( TPredicateChangeWaiter* waiter )
+{
+  myWaiters.remove( waiter );
+}
+
 //=======================================================================
 // name    : getCriteria
 // Purpose : Retrieve criterions from predicate
@@ -2476,6 +2607,62 @@ static inline bool getCriteria( Predicate_i*                thePred,
       theCriteria[ i ].Type          = FT_BadOrientedVolume;
       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
 
+      return true;
+    }
+  case FT_BareBorderVolume:
+    {
+      BareBorderVolume_i* aPred = dynamic_cast<BareBorderVolume_i*>( thePred );
+
+      CORBA::ULong i = theCriteria->length();
+      theCriteria->length( i + 1 );
+
+      theCriteria[ i ] = createCriterion();
+
+      theCriteria[ i ].Type          = FT_BareBorderVolume;
+      theCriteria[ i ].TypeOfElement = aPred->GetElementType();
+
+      return true;
+    }
+  case FT_BareBorderFace:
+    {
+      BareBorderFace_i* aPred = dynamic_cast<BareBorderFace_i*>( thePred );
+
+      CORBA::ULong i = theCriteria->length();
+      theCriteria->length( i + 1 );
+
+      theCriteria[ i ] = createCriterion();
+
+      theCriteria[ i ].Type          = FT_BareBorderFace;
+      theCriteria[ i ].TypeOfElement = aPred->GetElementType();
+
+      return true;
+    }
+  case FT_OverConstrainedVolume:
+    {
+      OverConstrainedVolume_i* aPred = dynamic_cast<OverConstrainedVolume_i*>( thePred );
+
+      CORBA::ULong i = theCriteria->length();
+      theCriteria->length( i + 1 );
+
+      theCriteria[ i ] = createCriterion();
+
+      theCriteria[ i ].Type          = FT_OverConstrainedVolume;
+      theCriteria[ i ].TypeOfElement = aPred->GetElementType();
+
+      return true;
+    }
+  case FT_OverConstrainedFace:
+    {
+      OverConstrainedFace_i* aPred = dynamic_cast<OverConstrainedFace_i*>( thePred );
+
+      CORBA::ULong i = theCriteria->length();
+      theCriteria->length( i + 1 );
+
+      theCriteria[ i ] = createCriterion();
+
+      theCriteria[ i ].Type          = FT_OverConstrainedFace;
+      theCriteria[ i ].TypeOfElement = aPred->GetElementType();
+
       return true;
     }
   case FT_LessThan:
@@ -2572,7 +2759,7 @@ CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
 {
   if ( myPredicate != 0 )
-    myPredicate->Destroy();
+    myPredicate->UnRegister();
 
   SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
   FilterManager_ptr aFilterMgr = aFilter->_this();
@@ -2598,17 +2785,20 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria
 
     {
       TPythonDump pd;
-      pd << "aCriterion = SMESH.Filter.Criterion(" << aCriterion << "," << aCompare
-         << "," << aThreshold << ",'" << aThresholdStr;
-      if (aThresholdID && strlen(aThresholdID))
-        //pd << "',salome.ObjectToID(" << aThresholdID
-        pd << "','" << aThresholdID
-           << "'," << aUnary << "," << aBinary << "," << aTolerance
-           << "," << aTypeOfElem << "," << aPrecision << ")";
-      else
-        pd << "',''," << aUnary << "," << aBinary << "," << aTolerance
-           << "," << aTypeOfElem << "," << aPrecision << ")";
+      pd << "aCriterion = SMESH.Filter.Criterion("
+         << aCriterion    << ", "
+         << aCompare      << ", "
+         << aThreshold    << ", '"
+         << aThresholdStr << "', '";
+      if (aThresholdID) pd << aThresholdID;
+      pd                  << "', "
+         << aUnary        << ", "
+         << aBinary       << ", "
+         << aTolerance    << ", "
+         << aTypeOfElem   << ", "
+         << aPrecision    << ")";
     }
+    TPythonDump pd;
 
     SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
     SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
@@ -2723,6 +2913,26 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria
           aPredicate = aFilterMgr->CreateBadOrientedVolume();
         }
         break;
+      case SMESH::FT_BareBorderVolume:
+        {
+          aPredicate = aFilterMgr->CreateBareBorderVolume();
+        }
+        break;
+      case SMESH::FT_BareBorderFace:
+        {
+          aPredicate = aFilterMgr->CreateBareBorderFace();
+        }
+        break;
+      case SMESH::FT_OverConstrainedVolume:
+        {
+          aPredicate = aFilterMgr->CreateOverConstrainedVolume();
+        }
+        break;
+      case SMESH::FT_OverConstrainedFace:
+        {
+          aPredicate = aFilterMgr->CreateOverConstrainedFace();
+        }
+        break;
       case SMESH::FT_LinearOrQuadratic:
         {
           SMESH::LinearOrQuadratic_ptr tmpPred = aFilterMgr->CreateLinearOrQuadratic();
@@ -2798,10 +3008,10 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria
     // logical op
     aPredicates.push_back( aPredicate );
     aBinaries.push_back( aBinary );
-    TPythonDump()<<"aCriteria.append(aCriterion)";
+    pd <<"aCriteria.append(aCriterion)";
 
   } // end of for
-  TPythonDump()<<this<<".SetCriteria(aCriteria)";
+  TPythonDump pd; pd<<this<<".SetCriteria(aCriteria)";
 
   // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
 
@@ -2963,7 +3173,11 @@ static inline LDOMString toString( CORBA::Long theType )
     case FT_BelongToCylinder: return "Belong to Cylinder";
     case FT_BelongToGenSurface: return "Belong to Generic Surface";
     case FT_LyingOnGeom     : return "Lying on Geom";
-    case FT_BadOrientedVolume: return "Bad Oriented Volume";
+    case FT_BadOrientedVolume:return "Bad Oriented Volume";
+    case FT_BareBorderVolume: return "Volumes with bare border";
+    case FT_BareBorderFace  : return "Faces with bare border";
+    case FT_OverConstrainedVolume: return "Over-constrained Volumes";
+    case FT_OverConstrainedFace  : return "Over-constrained Faces";
     case FT_RangeOfIds      : return "Range of IDs";
     case FT_FreeBorders     : return "Free borders";
     case FT_FreeEdges       : return "Free edges";
@@ -3017,6 +3231,10 @@ static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
   //  else if ( theStr.equals( "Length2D"                     ) ) return FT_Length2D;
   else if ( theStr.equals( "Range of IDs"                 ) ) return FT_RangeOfIds;
   else if ( theStr.equals( "Bad Oriented Volume"          ) ) return FT_BadOrientedVolume;
+  else if ( theStr.equals( "Volumes with bare border"     ) ) return FT_BareBorderVolume;
+  else if ( theStr.equals( "Faces with bare border"       ) ) return FT_BareBorderFace;
+  else if ( theStr.equals( "Over-constrained Volumes"     ) ) return FT_OverConstrainedVolume;
+  else if ( theStr.equals( "Over-constrained Faces"       ) ) return FT_OverConstrainedFace;
   else if ( theStr.equals( "Less than"                    ) ) return FT_LessThan;
   else if ( theStr.equals( "More than"                    ) ) return FT_MoreThan;
   else if ( theStr.equals( "Equal to"                     ) ) return FT_EqualTo;
@@ -3243,7 +3461,7 @@ FilterLibrary_i::FilterLibrary_i()
 FilterLibrary_i::~FilterLibrary_i()
 {
   delete myFileName;
-  //TPythonDump()<<this<<".Destroy()";
+  //TPythonDump()<<this<<".UnRegister()";
 }
 
 //=======================================================================
@@ -3435,7 +3653,7 @@ CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
   {
     aFilterItem.ReplaceElement( aNewItem );
     if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
-      TPythonDump()<<this<<".Replace('"<<theFilterName<<"',"<<theNewName<<"',"<<aFilter<<")";
+      TPythonDump()<<this<<".Replace('"<<theFilterName<<"','"<<theNewName<<"',"<<aFilter<<")";
     return true;
   }
 }
@@ -3540,3 +3758,61 @@ string_array* FilterLibrary_i::GetAllNames()
 
   return aResArray._retn();
 }
+
+//================================================================================
+/*!
+ * \brief Return an array of strings corresponding to items of enum FunctorType
+ */
+//================================================================================
+
+static const char** getFunctNames()
+{
+  static const char* functName[ SMESH::FT_Undefined + 1 ] = {
+    // If this line doesn't compile, this means that enum FunctorType has changed and
+    // it's necessary to update this array accordingly (refer to SMESH_Filter.idl)
+    // The order is IMPORTANT !!!
+    "FT_AspectRatio", "FT_AspectRatio3D", "FT_Warping", "FT_MinimumAngle",
+    "FT_Taper", "FT_Skew", "FT_Area", "FT_Volume3D", "FT_MaxElementLength2D",
+    "FT_MaxElementLength3D", "FT_FreeBorders", "FT_FreeEdges", "FT_FreeNodes",
+    "FT_FreeFaces", "FT_MultiConnection", "FT_MultiConnection2D", "FT_Length",
+    "FT_Length2D", "FT_BelongToGeom", "FT_BelongToPlane", "FT_BelongToCylinder",
+    "FT_BelongToGenSurface", "FT_LyingOnGeom", "FT_RangeOfIds", "FT_BadOrientedVolume",
+    "FT_BareBorderVolume", "FT_BareBorderFace", "FT_OverConstrainedVolume",
+    "FT_OverConstrainedFace", "FT_LinearOrQuadratic", "FT_GroupColor", "FT_ElemGeomType",
+    "FT_CoplanarFaces", "FT_LessThan", "FT_MoreThan", "FT_EqualTo", "FT_LogicalNOT",
+    "FT_LogicalAND", "FT_LogicalOR", "FT_Undefined" };
+  return functName;
+}
+
+//================================================================================
+/*!
+ * \brief Return a string corresponding to an item of enum FunctorType
+ */
+//================================================================================
+
+const char* SMESH::FunctorTypeToString(SMESH::FunctorType ft)
+{
+  if ( ft < 0 || ft > SMESH::FT_Undefined )
+    return "FT_Undefined";
+  return getFunctNames()[ ft ];
+}
+
+//================================================================================
+/*!
+ * \brief Converts a string to FunctorType. This is reverse of FunctorTypeToString()
+ */
+//================================================================================
+
+SMESH::FunctorType SMESH::StringToFunctorType(const char* str)
+{
+  std::string name( str + 3 ); // skip "FT_"
+  const char** functNames = getFunctNames();
+  int ft = SMESH::FT_Undefined;
+  for ( ; ft >= 0; --ft )
+    if ( name == ( functNames[ft] + 3 ))
+      break;
+
+  //ASSERT( strcmp( str, FunctorTypeToString( SMESH::FunctorType( ft ))) == 0 );
+
+  return SMESH::FunctorType( ft );
+}