Salome HOME
0021014: EDF 1583 SMESH: Improvement of the Python Dump for the creation of groups
[modules/smesh.git] / src / SMESH_I / SMESH_Filter_i.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
24 //  File   : SMESH_Filter_i.cxx
25 //  Author : Alexey Petrov, OCC
26 //  Module : SMESH
27 //
28 #include "SMESH_Filter_i.hxx"
29
30 #include "SMESH_Gen_i.hxx"
31 #include "SMESH_PythonDump.hxx"
32
33 #include "SMDS_Mesh.hxx"
34 #include "SMDS_MeshNode.hxx"
35 #include "SMDS_MeshElement.hxx"
36 #include "SMDS_ElemIterator.hxx"
37 #include "SMDS_VolumeTool.hxx"
38
39 #include "SMESHDS_Mesh.hxx"
40
41 #include <BRep_Tool.hxx>
42 #include <Geom_CylindricalSurface.hxx>
43 #include <Geom_Plane.hxx>
44 #include <LDOMParser.hxx>
45 #include <LDOMString.hxx>
46 #include <LDOM_Document.hxx>
47 #include <LDOM_Element.hxx>
48 #include <LDOM_Node.hxx>
49 #include <LDOM_XmlWriter.hxx>
50 #include <Precision.hxx>
51 #include <TColStd_ListIteratorOfListOfInteger.hxx>
52 #include <TColStd_ListIteratorOfListOfReal.hxx>
53 #include <TColStd_ListOfInteger.hxx>
54 #include <TColStd_ListOfReal.hxx>
55 #include <TColStd_SequenceOfHAsciiString.hxx>
56 #include <TCollection_HAsciiString.hxx>
57 #include <TopExp.hxx>
58 #include <TopExp_Explorer.hxx>
59 #include <TopoDS.hxx>
60 #include <TopoDS_Face.hxx>
61 #include <TopoDS_Shape.hxx>
62 #include <TopTools_IndexedMapOfShape.hxx>
63
64 using namespace SMESH;
65 using namespace SMESH::Controls;
66
67
68 namespace SMESH
69 {
70   Predicate_i*
71   GetPredicate( Predicate_ptr thePredicate )
72   {
73     return DownCast<Predicate_i*>(thePredicate);
74   }
75 }
76
77
78 /*
79   Class       : BelongToGeom
80   Description : Predicate for verifying whether entity belongs to
81                 specified geometrical support
82 */
83
84 Controls::BelongToGeom::BelongToGeom()
85   : myMeshDS(NULL),
86     myType(SMDSAbs_All),
87     myIsSubshape(false),
88     myTolerance(Precision::Confusion())
89 {}
90
91 void Controls::BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
92 {
93   myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
94   init();
95 }
96
97 void Controls::BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
98 {
99   myShape = theShape;
100   init();
101 }
102
103 static bool IsSubShape (const TopTools_IndexedMapOfShape& theMap,
104                         const TopoDS_Shape& theShape)
105 {
106   if (theMap.Contains(theShape)) return true;
107
108   if (theShape.ShapeType() == TopAbs_COMPOUND ||
109       theShape.ShapeType() == TopAbs_COMPSOLID)
110   {
111     TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
112     for (; anIt.More(); anIt.Next())
113     {
114       if (!IsSubShape(theMap, anIt.Value())) {
115         return false;
116       }
117     }
118     return true;
119   }
120
121   return false;
122 }
123
124 void Controls::BelongToGeom::init()
125 {
126   if (!myMeshDS || myShape.IsNull()) return;
127
128   // is subshape of main shape?
129   TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
130   if (aMainShape.IsNull()) {
131     myIsSubshape = false;
132   }
133   else {
134     TopTools_IndexedMapOfShape aMap;
135     TopExp::MapShapes(aMainShape, aMap);
136     myIsSubshape = IsSubShape(aMap, myShape);
137   }
138
139   if (!myIsSubshape)
140   {
141     myElementsOnShapePtr.reset(new Controls::ElementsOnShape());
142     myElementsOnShapePtr->SetTolerance(myTolerance);
143     myElementsOnShapePtr->SetAllNodes(true); // belong, while false means "lays on"
144     myElementsOnShapePtr->SetMesh(myMeshDS);
145     myElementsOnShapePtr->SetShape(myShape, myType);
146   }
147 }
148
149 static bool IsContains( const SMESHDS_Mesh*     theMeshDS,
150                         const TopoDS_Shape&     theShape,
151                         const SMDS_MeshElement* theElem,
152                         TopAbs_ShapeEnum        theFindShapeEnum,
153                         TopAbs_ShapeEnum        theAvoidShapeEnum = TopAbs_SHAPE )
154 {
155   TopExp_Explorer anExp( theShape,theFindShapeEnum,theAvoidShapeEnum );
156
157   while( anExp.More() )
158   {
159     const TopoDS_Shape& aShape = anExp.Current();
160     if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
161       if( aSubMesh->Contains( theElem ) )
162         return true;
163     }
164     anExp.Next();
165   }
166   return false;
167 }
168
169 bool Controls::BelongToGeom::IsSatisfy (long theId)
170 {
171   if (myMeshDS == 0 || myShape.IsNull())
172     return false;
173
174   if (!myIsSubshape)
175   {
176     return myElementsOnShapePtr->IsSatisfy(theId);
177   }
178
179   // Case of submesh
180   if (myType == SMDSAbs_Node)
181   {
182     if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
183     {
184       const SMDS_PositionPtr& aPosition = aNode->GetPosition();
185       SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
186       switch( aTypeOfPosition )
187       {
188       case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
189       case SMDS_TOP_EDGE   : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
190       case SMDS_TOP_FACE   : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
191       case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
192       }
193     }
194   }
195   else
196   {
197     if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
198     {
199       if( myType == SMDSAbs_All )
200       {
201         return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
202                IsContains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
203                IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
204                IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
205       }
206       else if( myType == anElem->GetType() )
207       {
208         switch( myType )
209         {
210         case SMDSAbs_Edge  : return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE );
211         case SMDSAbs_Face  : return IsContains( myMeshDS,myShape,anElem,TopAbs_FACE );
212         case SMDSAbs_Volume: return IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
213                                     IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
214         }
215       }
216     }
217   }
218
219   return false;
220 }
221
222 void Controls::BelongToGeom::SetType (SMDSAbs_ElementType theType)
223 {
224   myType = theType;
225   init();
226 }
227
228 SMDSAbs_ElementType Controls::BelongToGeom::GetType() const
229 {
230   return myType;
231 }
232
233 TopoDS_Shape Controls::BelongToGeom::GetShape()
234 {
235   return myShape;
236 }
237
238 const SMESHDS_Mesh* Controls::BelongToGeom::GetMeshDS() const
239 {
240   return myMeshDS;
241 }
242
243 void Controls::BelongToGeom::SetTolerance (double theTolerance)
244 {
245   myTolerance = theTolerance;
246   if (!myIsSubshape)
247     init();
248 }
249
250 double Controls::BelongToGeom::GetTolerance()
251 {
252   return myTolerance;
253 }
254
255 /*
256   Class       : LyingOnGeom
257   Description : Predicate for verifying whether entiy lying or partially lying on
258                 specified geometrical support
259 */
260
261 Controls::LyingOnGeom::LyingOnGeom()
262   : myMeshDS(NULL),
263     myType(SMDSAbs_All),
264     myIsSubshape(false),
265     myTolerance(Precision::Confusion())
266 {}
267
268 void Controls::LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
269 {
270   myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
271   init();
272 }
273
274 void Controls::LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
275 {
276   myShape = theShape;
277   init();
278 }
279
280 void Controls::LyingOnGeom::init()
281 {
282   if (!myMeshDS || myShape.IsNull()) return;
283
284   // is subshape of main shape?
285   TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
286   if (aMainShape.IsNull()) {
287     myIsSubshape = false;
288   }
289   else {
290     TopTools_IndexedMapOfShape aMap;
291     TopExp::MapShapes(aMainShape, aMap);
292     myIsSubshape = IsSubShape(aMap, myShape);
293   }
294
295   if (!myIsSubshape)
296   {
297     myElementsOnShapePtr.reset(new Controls::ElementsOnShape());
298     myElementsOnShapePtr->SetTolerance(myTolerance);
299     myElementsOnShapePtr->SetAllNodes(false); // lays on, while true means "belong"
300     myElementsOnShapePtr->SetMesh(myMeshDS);
301     myElementsOnShapePtr->SetShape(myShape, myType);
302   }
303 }
304
305 bool Controls::LyingOnGeom::IsSatisfy( long theId )
306 {
307   if ( myMeshDS == 0 || myShape.IsNull() )
308     return false;
309
310   if (!myIsSubshape)
311   {
312     return myElementsOnShapePtr->IsSatisfy(theId);
313   }
314
315   // Case of submesh
316   if( myType == SMDSAbs_Node )
317   {
318     if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
319     {
320       const SMDS_PositionPtr& aPosition = aNode->GetPosition();
321       SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
322       switch( aTypeOfPosition )
323       {
324       case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
325       case SMDS_TOP_EDGE   : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
326       case SMDS_TOP_FACE   : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
327       case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
328       }
329     }
330   }
331   else
332   {
333     if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
334     {
335       if( myType == SMDSAbs_All )
336       {
337         return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
338                Contains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
339                Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
340                Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
341       }
342       else if( myType == anElem->GetType() )
343       {
344         switch( myType )
345         {
346         case SMDSAbs_Edge  : return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE );
347         case SMDSAbs_Face  : return Contains( myMeshDS,myShape,anElem,TopAbs_FACE );
348         case SMDSAbs_Volume: return Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
349                                     Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
350         }
351       }
352     }
353   }
354
355   return false;
356 }
357
358 void Controls::LyingOnGeom::SetType( SMDSAbs_ElementType theType )
359 {
360   myType = theType;
361   init();
362 }
363
364 SMDSAbs_ElementType Controls::LyingOnGeom::GetType() const
365 {
366   return myType;
367 }
368
369 TopoDS_Shape Controls::LyingOnGeom::GetShape()
370 {
371   return myShape;
372 }
373
374 const SMESHDS_Mesh* Controls::LyingOnGeom::GetMeshDS() const
375 {
376   return myMeshDS;
377 }
378
379 void Controls::LyingOnGeom::SetTolerance (double theTolerance)
380 {
381   myTolerance = theTolerance;
382   if (!myIsSubshape)
383     init();
384 }
385
386 double Controls::LyingOnGeom::GetTolerance()
387 {
388   return myTolerance;
389 }
390
391 bool Controls::LyingOnGeom::Contains( const SMESHDS_Mesh*     theMeshDS,
392                                       const TopoDS_Shape&     theShape,
393                                       const SMDS_MeshElement* theElem,
394                                       TopAbs_ShapeEnum        theFindShapeEnum,
395                                       TopAbs_ShapeEnum        theAvoidShapeEnum )
396 {
397   if (IsContains(theMeshDS, theShape, theElem, theFindShapeEnum, theAvoidShapeEnum))
398     return true;
399
400   TopTools_IndexedMapOfShape aSubShapes;
401   TopExp::MapShapes( theShape, aSubShapes );
402
403   for (int i = 1; i <= aSubShapes.Extent(); i++)
404   {
405     const TopoDS_Shape& aShape = aSubShapes.FindKey(i);
406
407     if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
408       if( aSubMesh->Contains( theElem ) )
409         return true;
410
411       SMDS_NodeIteratorPtr aNodeIt = aSubMesh->GetNodes();
412       while ( aNodeIt->more() )
413       {
414         const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(aNodeIt->next());
415         SMDS_ElemIteratorPtr anElemIt = aNode->GetInverseElementIterator();
416         while ( anElemIt->more() )
417         {
418           const SMDS_MeshElement* anElement = static_cast<const SMDS_MeshElement*>(anElemIt->next());
419           if (anElement == theElem)
420             return true;
421         }
422       }
423     }
424   }
425   return false;
426 }
427
428
429 /*
430                             AUXILIARY METHODS
431 */
432
433 inline
434 const SMDS_Mesh*
435 MeshPtr2SMDSMesh( SMESH_Mesh_ptr theMesh )
436 {
437   SMESH_Mesh_i* anImplPtr = DownCast<SMESH_Mesh_i*>(theMesh);
438   return anImplPtr ? anImplPtr->GetImpl().GetMeshDS() : 0;
439 }
440
441 inline
442 SMESH::long_array*
443 toArray( const TColStd_ListOfInteger& aList )
444 {
445   SMESH::long_array_var anArray = new SMESH::long_array;
446   anArray->length( aList.Extent() );
447   TColStd_ListIteratorOfListOfInteger anIter( aList );
448   int i = 0;
449   for( ; anIter.More(); anIter.Next() )
450     anArray[ i++ ] = anIter.Value();
451
452   return anArray._retn();
453 }
454
455 inline
456 SMESH::double_array*
457 toArray( const TColStd_ListOfReal& aList )
458 {
459   SMESH::double_array_var anArray = new SMESH::double_array;
460   anArray->length( aList.Extent() );
461   TColStd_ListIteratorOfListOfReal anIter( aList );
462   int i = 0;
463   for( ; anIter.More(); anIter.Next() )
464     anArray[ i++ ] = anIter.Value();
465
466   return anArray._retn();
467 }
468
469 static SMESH::Filter::Criterion createCriterion()
470 {
471   SMESH::Filter::Criterion aCriterion;
472
473   aCriterion.Type          = FT_Undefined;
474   aCriterion.Compare       = FT_Undefined;
475   aCriterion.Threshold     = 0;
476   aCriterion.UnaryOp       = FT_Undefined;
477   aCriterion.BinaryOp      = FT_Undefined;
478   aCriterion.ThresholdStr  = "";
479   aCriterion.ThresholdID   = "";
480   aCriterion.Tolerance     = Precision::Confusion();
481   aCriterion.TypeOfElement = SMESH::ALL;
482   aCriterion.Precision     = -1;
483
484   return aCriterion;
485 }
486
487 static TopoDS_Shape getShapeByName( const char* theName )
488 {
489   if ( theName != 0 )
490   {
491     SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
492     SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
493     if (!CORBA::is_nil(aStudy))
494     {
495       SALOMEDS::Study::ListOfSObject_var aList =
496         aStudy->FindObjectByName( theName, "GEOM" );
497       if ( aList->length() > 0 )
498       {
499         GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aList[ 0 ]->GetObject() );
500         if ( !aGeomObj->_is_nil() )
501         {
502           GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
503           TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
504           return aLocShape;
505         }
506       }
507     }
508   }
509   return TopoDS_Shape();
510 }
511
512 static TopoDS_Shape getShapeByID (const char* theID)
513 {
514   if (theID != 0 && theID != "") {
515     SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
516     SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
517     if (aStudy != 0) {
518       SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
519       SALOMEDS::GenericAttribute_var anAttr;
520       if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
521         SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
522         CORBA::String_var aVal = anIOR->Value();
523         CORBA::Object_var obj = aStudy->ConvertIORToObject(aVal);
524         GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(obj);
525       
526         if (!aGeomObj->_is_nil()) {
527           GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
528           TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
529           return aLocShape;
530         }
531       }
532     }
533   }
534   return TopoDS_Shape();
535 }
536
537 static char* getShapeNameByID (const char* theID)
538 {
539   char* aName = (char*)"";
540
541   if (theID != 0 && theID != "") {
542     SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
543     SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
544     if (aStudy != 0) {
545       //SALOMEDS::SObject_var aSObj = aStudy->FindObjectIOR( theID );
546       SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
547       SALOMEDS::GenericAttribute_var anAttr;
548       if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeName")) {
549         SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow(anAttr);
550         aName = aNameAttr->Value();
551       }
552     }
553   }
554
555   return aName;
556 }
557
558 /*
559                                 FUNCTORS
560 */
561
562 /*
563   Class       : Functor_i
564   Description : An abstact class for all functors
565 */
566 Functor_i::Functor_i():
567   SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
568 {
569   //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method  
570   //PortableServer::ObjectId_var anObjectId =
571   //  SMESH_Gen_i::GetPOA()->activate_object( this );
572 }
573
574 Functor_i::~Functor_i()
575 {
576   //TPythonDump()<<this<<".UnRegister()";
577 }
578
579 void Functor_i::SetMesh( SMESH_Mesh_ptr theMesh )
580 {
581   myFunctorPtr->SetMesh( MeshPtr2SMDSMesh( theMesh ) );
582   TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
583 }
584
585 ElementType Functor_i::GetElementType()
586 {
587   return ( ElementType )myFunctorPtr->GetType();
588 }
589
590
591 /*
592   Class       : NumericalFunctor_i
593   Description : Base class for numerical functors
594 */
595 CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
596 {
597   return myNumericalFunctorPtr->GetValue( theId );
598 }
599
600 SMESH::Histogram* NumericalFunctor_i::GetHistogram(CORBA::Short nbIntervals)
601 {
602   std::vector<int> nbEvents;
603   std::vector<double> funValues;
604   std::vector<int> elements;
605   myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues,elements);
606
607 #ifdef WIN32
608   nbIntervals = CORBA::Short( min( nbEvents.size(), funValues.size() - 1));
609 #else
610   nbIntervals = CORBA::Short( std::min( nbEvents.size(), funValues.size() - 1));
611 #endif
612   SMESH::Histogram_var histogram = new SMESH::Histogram;
613   if ( nbIntervals > 0 )
614   {
615     histogram->length( nbIntervals );
616     for ( int i = 0; i < nbIntervals; ++i )
617     {
618       HistogramRectangle& rect = histogram[i];
619       rect.nbEvents = nbEvents[i];
620       rect.min = funValues[i];
621       rect.max = funValues[i+1];
622     }
623   }
624   return histogram._retn();
625 }
626
627 void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision )
628 {
629   myNumericalFunctorPtr->SetPrecision( thePrecision );
630   TPythonDump()<<this<<".SetPrecision("<<thePrecision<<")";
631 }
632
633 CORBA::Long NumericalFunctor_i::GetPrecision()
634 {
635  return myNumericalFunctorPtr->GetPrecision();
636 }
637
638 Controls::NumericalFunctorPtr NumericalFunctor_i::GetNumericalFunctor()
639 {
640   return myNumericalFunctorPtr;
641 }
642
643
644 /*
645   Class       : SMESH_MinimumAngle
646   Description : Functor for calculation of minimum angle
647 */
648 MinimumAngle_i::MinimumAngle_i()
649 {
650   myNumericalFunctorPtr.reset( new Controls::MinimumAngle() );
651   myFunctorPtr = myNumericalFunctorPtr;
652 }
653
654 FunctorType MinimumAngle_i::GetFunctorType()
655 {
656   return SMESH::FT_MinimumAngle;
657 }
658
659
660 /*
661   Class       : AspectRatio
662   Description : Functor for calculating aspect ratio
663 */
664 AspectRatio_i::AspectRatio_i()
665 {
666   myNumericalFunctorPtr.reset( new Controls::AspectRatio() );
667   myFunctorPtr = myNumericalFunctorPtr;
668 }
669
670 FunctorType AspectRatio_i::GetFunctorType()
671 {
672   return SMESH::FT_AspectRatio;
673 }
674
675
676 /*
677   Class       : AspectRatio3D
678   Description : Functor for calculating aspect ratio 3D
679 */
680 AspectRatio3D_i::AspectRatio3D_i()
681 {
682   myNumericalFunctorPtr.reset( new Controls::AspectRatio3D() );
683   myFunctorPtr = myNumericalFunctorPtr;
684 }
685
686 FunctorType AspectRatio3D_i::GetFunctorType()
687 {
688   return SMESH::FT_AspectRatio3D;
689 }
690
691
692 /*
693   Class       : Warping_i
694   Description : Functor for calculating warping
695 */
696 Warping_i::Warping_i()
697 {
698   myNumericalFunctorPtr.reset( new Controls::Warping() );
699   myFunctorPtr = myNumericalFunctorPtr;
700 }
701
702 FunctorType Warping_i::GetFunctorType()
703 {
704   return SMESH::FT_Warping;
705 }
706
707
708 /*
709   Class       : Taper_i
710   Description : Functor for calculating taper
711 */
712 Taper_i::Taper_i()
713 {
714   myNumericalFunctorPtr.reset( new Controls::Taper() );
715   myFunctorPtr = myNumericalFunctorPtr;
716 }
717
718 FunctorType Taper_i::GetFunctorType()
719 {
720   return SMESH::FT_Taper;
721 }
722
723
724 /*
725   Class       : Skew_i
726   Description : Functor for calculating skew in degrees
727 */
728 Skew_i::Skew_i()
729 {
730   myNumericalFunctorPtr.reset( new Controls::Skew() );
731   myFunctorPtr = myNumericalFunctorPtr;
732 }
733
734 FunctorType Skew_i::GetFunctorType()
735 {
736   return SMESH::FT_Skew;
737 }
738
739 /*
740   Class       : Area_i
741   Description : Functor for calculating area
742 */
743 Area_i::Area_i()
744 {
745   myNumericalFunctorPtr.reset( new Controls::Area() );
746   myFunctorPtr = myNumericalFunctorPtr;
747 }
748
749 FunctorType Area_i::GetFunctorType()
750 {
751   return SMESH::FT_Area;
752 }
753
754 /*
755   Class       : Volume3D_i
756   Description : Functor for calculating volume of 3D element
757 */
758 Volume3D_i::Volume3D_i()
759 {
760   myNumericalFunctorPtr.reset( new Controls::Volume() );
761   myFunctorPtr = myNumericalFunctorPtr;
762 }
763
764 FunctorType Volume3D_i::GetFunctorType()
765 {
766   return SMESH::FT_Volume3D;
767 }
768
769 /*
770   Class       : MaxElementLength2D_i
771   Description : Functor for calculating maximum length of 2D element
772 */
773 MaxElementLength2D_i::MaxElementLength2D_i()
774 {
775   myNumericalFunctorPtr.reset( new Controls::MaxElementLength2D() );
776   myFunctorPtr = myNumericalFunctorPtr;
777 }
778
779 FunctorType MaxElementLength2D_i::GetFunctorType()
780 {
781   return SMESH::FT_MaxElementLength2D;
782 }
783
784 /*
785   Class       : MaxElementLength3D_i
786   Description : Functor for calculating maximum length of 3D element
787 */
788 MaxElementLength3D_i::MaxElementLength3D_i()
789 {
790   myNumericalFunctorPtr.reset( new Controls::MaxElementLength3D() );
791   myFunctorPtr = myNumericalFunctorPtr;
792 }
793
794 FunctorType MaxElementLength3D_i::GetFunctorType()
795 {
796   return SMESH::FT_MaxElementLength3D;
797 }
798
799 /*
800   Class       : Length_i
801   Description : Functor for calculating length off edge
802 */
803 Length_i::Length_i()
804 {
805   myNumericalFunctorPtr.reset( new Controls::Length() );
806   myFunctorPtr = myNumericalFunctorPtr;
807 }
808
809 FunctorType Length_i::GetFunctorType()
810 {
811   return SMESH::FT_Length;
812 }
813
814 /*
815   Class       : Length2D_i
816   Description : Functor for calculating length of edge
817 */
818 Length2D_i::Length2D_i()
819 {
820   myNumericalFunctorPtr.reset( new Controls::Length2D() );
821   myFunctorPtr = myNumericalFunctorPtr;
822 }
823
824 FunctorType Length2D_i::GetFunctorType()
825 {
826   return SMESH::FT_Length2D;
827 }
828
829 SMESH::Length2D::Values* Length2D_i::GetValues()
830 {
831   INFOS("Length2D_i::GetValues");
832   SMESH::Controls::Length2D::TValues aValues;
833   (dynamic_cast<SMESH::Controls::Length2D*>(myFunctorPtr.get()))->GetValues( aValues );
834
835   long i = 0, iEnd = aValues.size();
836
837   SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd);
838   aResult->length(iEnd);
839
840   SMESH::Controls::Length2D::TValues::const_iterator anIter;
841   for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
842   {
843     const SMESH::Controls::Length2D::Value&  aVal = *anIter;
844     SMESH::Length2D::Value &aValue = aResult[ i ];
845
846     aValue.myLength = aVal.myLength;
847     aValue.myPnt1 = aVal.myPntId[ 0 ];
848     aValue.myPnt2 = aVal.myPntId[ 1 ];
849   }
850
851   INFOS("Length2D_i::GetValuess~");
852   return aResult._retn();
853 }
854
855 /*
856   Class       : MultiConnection_i
857   Description : Functor for calculating number of faces conneted to the edge
858 */
859 MultiConnection_i::MultiConnection_i()
860 {
861   myNumericalFunctorPtr.reset( new Controls::MultiConnection() );
862   myFunctorPtr = myNumericalFunctorPtr;
863 }
864
865 FunctorType MultiConnection_i::GetFunctorType()
866 {
867   return SMESH::FT_MultiConnection;
868 }
869
870 /*
871   Class       : MultiConnection2D_i
872   Description : Functor for calculating number of faces conneted to the edge
873 */
874 MultiConnection2D_i::MultiConnection2D_i()
875 {
876   myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() );
877   myFunctorPtr = myNumericalFunctorPtr;
878 }
879
880 FunctorType MultiConnection2D_i::GetFunctorType()
881 {
882   return SMESH::FT_MultiConnection2D;
883 }
884
885 SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
886 {
887   INFOS("MultiConnection2D_i::GetValues");
888   SMESH::Controls::MultiConnection2D::MValues aValues;
889   (dynamic_cast<SMESH::Controls::MultiConnection2D*>(myFunctorPtr.get()))->GetValues( aValues );
890   
891   long i = 0, iEnd = aValues.size();
892
893   SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd);
894   aResult->length(iEnd);
895
896   SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter;
897   for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
898   {
899     const SMESH::Controls::MultiConnection2D::Value&  aVal = (*anIter).first;
900     SMESH::MultiConnection2D::Value &aValue = aResult[ i ];
901
902     aValue.myPnt1 = aVal.myPntId[ 0 ];
903     aValue.myPnt2 = aVal.myPntId[ 1 ];
904     aValue.myNbConnects = (*anIter).second;
905   }
906
907   INFOS("Multiconnection2D_i::GetValuess~");
908   return aResult._retn();
909 }
910
911 /*
912                             PREDICATES
913 */
914
915
916 /*
917   Class       : Predicate_i
918   Description : Base class for all predicates
919 */
920 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
921 {
922   return myPredicatePtr->IsSatisfy( theId );
923 }
924
925 Controls::PredicatePtr Predicate_i::GetPredicate()
926 {
927   return myPredicatePtr;
928 }
929
930 /*
931   Class       : BadOrientedVolume_i
932   Description : Verify whether a mesh volume is incorrectly oriented from
933                 the point of view of MED convention
934 */
935 BadOrientedVolume_i::BadOrientedVolume_i()
936 {
937   Controls::PredicatePtr control( new Controls::BadOrientedVolume() );
938   myFunctorPtr = myPredicatePtr = control;
939 };
940
941 FunctorType BadOrientedVolume_i::GetFunctorType()
942 {
943   return SMESH::FT_BadOrientedVolume;
944 }
945
946 /*
947   Class       : BareBorderVolume_i
948   Description : Verify whether a mesh volume has a free facet without a face on it
949 */
950 BareBorderVolume_i::BareBorderVolume_i()
951 {
952   Controls::PredicatePtr control( new Controls::BareBorderVolume() );
953   myFunctorPtr = myPredicatePtr = control;
954 };
955
956 FunctorType BareBorderVolume_i::GetFunctorType()
957 {
958   return SMESH::FT_BareBorderVolume;
959 }
960
961 /*
962   Class       : BareBorderFace_i
963   Description : Verify whether a mesh face has a free border without an edge on it
964 */
965 BareBorderFace_i::BareBorderFace_i()
966 {
967   Controls::PredicatePtr control( new Controls::BareBorderFace() );
968   myFunctorPtr = myPredicatePtr = control;
969 };
970
971 FunctorType BareBorderFace_i::GetFunctorType()
972 {
973   return SMESH::FT_BareBorderFace;
974 }
975
976 /*
977   Class       : OverConstrainedVolume_i
978   Description : Verify whether a mesh volume has only one facet shared with other volumes
979 */
980 OverConstrainedVolume_i::OverConstrainedVolume_i()
981 {
982   Controls::PredicatePtr control( new Controls::OverConstrainedVolume() );
983   myFunctorPtr = myPredicatePtr = control;
984 };
985
986 FunctorType OverConstrainedVolume_i::GetFunctorType()
987 {
988   return SMESH::FT_OverConstrainedVolume;
989 }
990
991 /*
992   Class       : OverConstrainedFace_i
993   Description : Verify whether a mesh face has only one border shared with other faces
994 */
995 OverConstrainedFace_i::OverConstrainedFace_i()
996 {
997   Controls::PredicatePtr control( new Controls::OverConstrainedFace() );
998   myFunctorPtr = myPredicatePtr = control;
999 };
1000
1001 FunctorType OverConstrainedFace_i::GetFunctorType()
1002 {
1003   return SMESH::FT_OverConstrainedFace;
1004 }
1005
1006 /*
1007   Class       : BelongToGeom_i
1008   Description : Predicate for selection on geometrical support
1009 */
1010 BelongToGeom_i::BelongToGeom_i()
1011 {
1012   myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
1013   myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
1014   myShapeName = 0;
1015   myShapeID   = 0;
1016 }
1017
1018 BelongToGeom_i::~BelongToGeom_i()
1019 {
1020   delete myShapeName;
1021   delete myShapeID;
1022 }
1023
1024 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
1025 {
1026   if ( theGeom->_is_nil() )
1027     return;
1028   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1029   GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1030   TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1031   myBelongToGeomPtr->SetGeom( aLocShape );
1032   TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
1033 }
1034
1035 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
1036 {
1037   myBelongToGeomPtr->SetGeom( theShape );
1038 }
1039
1040 void BelongToGeom_i::SetElementType(ElementType theType){
1041   myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
1042   TPythonDump()<<this<<".SetElementType("<<theType<<")";
1043 }
1044
1045 FunctorType BelongToGeom_i::GetFunctorType()
1046 {
1047   return SMESH::FT_BelongToGeom;
1048 }
1049
1050 void BelongToGeom_i::SetShapeName( const char* theName )
1051 {
1052   delete myShapeName;
1053   myShapeName = strdup( theName );
1054   myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1055   TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
1056 }
1057
1058 void BelongToGeom_i::SetShape( const char* theID, const char* theName )
1059 {
1060   delete myShapeName;
1061   myShapeName = strdup( theName );
1062   delete myShapeID;
1063   if ( theID )
1064     myShapeID = strdup( theID );
1065   else
1066     myShapeID = 0;
1067
1068   if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1069     myBelongToGeomPtr->SetGeom( getShapeByID(myShapeID) );
1070   else
1071     myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1072 }
1073
1074 char* BelongToGeom_i::GetShapeName()
1075 {
1076   return CORBA::string_dup( myShapeName );
1077 }
1078
1079 char* BelongToGeom_i::GetShapeID()
1080 {
1081   return CORBA::string_dup( myShapeID );
1082 }
1083
1084 void BelongToGeom_i::SetTolerance( CORBA::Double theToler )
1085 {
1086   myBelongToGeomPtr->SetTolerance( theToler );
1087   TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1088 }
1089
1090 CORBA::Double BelongToGeom_i::GetTolerance()
1091 {
1092   return myBelongToGeomPtr->GetTolerance();
1093 }
1094
1095 /*
1096   Class       : BelongToSurface_i
1097   Description : Predicate for selection on geometrical support
1098 */
1099 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
1100 {
1101   myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
1102   myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
1103   myShapeName = 0;
1104   myShapeID   = 0;
1105   mySurfaceType = theSurfaceType;
1106 }
1107
1108 BelongToSurface_i::~BelongToSurface_i()
1109 {
1110   delete myShapeName;
1111   delete myShapeID;
1112 }
1113
1114 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1115 {
1116   if ( theGeom->_is_nil() )
1117     return;
1118   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1119   GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1120   TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1121
1122   if ( aLocShape.ShapeType() == TopAbs_FACE )
1123   {
1124     Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
1125     if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
1126     {
1127       myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1128       return;
1129     }
1130   }
1131
1132   myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
1133 }
1134
1135 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
1136 {
1137   delete myShapeName;
1138   myShapeName = strdup( theName );
1139   myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
1140   TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
1141 }
1142
1143 void BelongToSurface_i::SetShape( const char* theID,  const char* theName, ElementType theType )
1144 {
1145   delete myShapeName;
1146   myShapeName = strdup( theName );
1147   delete myShapeID;
1148   if ( theID )
1149     myShapeID = strdup( theID );
1150   else
1151     myShapeID = 0;
1152   
1153   if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1154     myElementsOnSurfacePtr->SetSurface( getShapeByID(myShapeID), (SMDSAbs_ElementType)theType );
1155   else
1156     myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
1157 }
1158
1159 char* BelongToSurface_i::GetShapeName()
1160 {
1161   return CORBA::string_dup( myShapeName );
1162 }
1163
1164 char* BelongToSurface_i::GetShapeID()
1165 {
1166   return CORBA::string_dup( myShapeID );
1167 }
1168
1169 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
1170 {
1171   myElementsOnSurfacePtr->SetTolerance( theToler );
1172   TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1173 }
1174
1175 CORBA::Double BelongToSurface_i::GetTolerance()
1176 {
1177   return myElementsOnSurfacePtr->GetTolerance();
1178 }
1179
1180 void BelongToSurface_i::SetUseBoundaries( CORBA::Boolean theUseBndRestrictions )
1181 {
1182   myElementsOnSurfacePtr->SetUseBoundaries( theUseBndRestrictions );
1183   TPythonDump()<<this<<".SetUseBoundaries( " << theUseBndRestrictions << " )";
1184 }
1185
1186 CORBA::Boolean BelongToSurface_i::GetUseBoundaries()
1187 {
1188   return myElementsOnSurfacePtr->GetUseBoundaries();
1189 }
1190
1191
1192 /*
1193   Class       : BelongToPlane_i
1194   Description : Verify whether mesh element lie in pointed Geom planar object
1195 */
1196
1197 BelongToPlane_i::BelongToPlane_i()
1198 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
1199 {
1200 }
1201
1202 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1203 {
1204   BelongToSurface_i::SetSurface( theGeom, theType );
1205   TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
1206 }
1207
1208 FunctorType BelongToPlane_i::GetFunctorType()
1209 {
1210   return FT_BelongToPlane;
1211 }
1212
1213 /*
1214   Class       : BelongToCylinder_i
1215   Description : Verify whether mesh element lie in pointed Geom planar object
1216 */
1217
1218 BelongToCylinder_i::BelongToCylinder_i()
1219 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1220 {
1221 }
1222
1223 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1224 {
1225   BelongToSurface_i::SetSurface( theGeom, theType );
1226   TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
1227 }
1228
1229 FunctorType BelongToCylinder_i::GetFunctorType()
1230 {
1231   return FT_BelongToCylinder;
1232 }
1233
1234 /*
1235   Class       : BelongToGenSurface_i
1236   Description : Verify whether mesh element lie in pointed Geom planar object
1237 */
1238
1239 BelongToGenSurface_i::BelongToGenSurface_i()
1240 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1241 {
1242 }
1243
1244 void BelongToGenSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1245 {
1246   if ( theGeom->_is_nil() )
1247     return;
1248   TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
1249   if ( !aLocShape.IsNull() && aLocShape.ShapeType() != TopAbs_FACE )
1250     aLocShape.Nullify();
1251   
1252   BelongToSurface_i::myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1253   TPythonDump()<<this<<".SetGenSurface("<<theGeom<<","<<theType<<")";
1254 }
1255
1256 FunctorType BelongToGenSurface_i::GetFunctorType()
1257 {
1258   return FT_BelongToGenSurface;
1259 }
1260
1261 /*
1262   Class       : LyingOnGeom_i
1263   Description : Predicate for selection on geometrical support
1264 */
1265 LyingOnGeom_i::LyingOnGeom_i()
1266 {
1267   myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
1268   myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
1269   myShapeName = 0;
1270   myShapeID = 0;
1271 }
1272
1273 LyingOnGeom_i::~LyingOnGeom_i()
1274 {
1275   delete myShapeName;
1276   delete myShapeID;
1277 }
1278
1279 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
1280 {
1281   if ( theGeom->_is_nil() )
1282     return;
1283   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1284   GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1285   TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1286   myLyingOnGeomPtr->SetGeom( aLocShape );
1287   TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
1288 }
1289
1290 void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
1291 {
1292   myLyingOnGeomPtr->SetGeom( theShape );
1293 }
1294
1295 void LyingOnGeom_i::SetElementType(ElementType theType){
1296   myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
1297   TPythonDump()<<this<<".SetElementType("<<theType<<")";
1298 }
1299
1300 FunctorType LyingOnGeom_i::GetFunctorType()
1301 {
1302   return SMESH::FT_LyingOnGeom;
1303 }
1304
1305 void LyingOnGeom_i::SetShapeName( const char* theName )
1306 {
1307   delete myShapeName;
1308   myShapeName = strdup( theName );
1309   myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1310   TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
1311 }
1312
1313 void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
1314 {
1315   delete myShapeName;
1316   myShapeName = strdup( theName );
1317   delete myShapeID;
1318   if ( theID )
1319     myShapeID = strdup( theID );
1320   else
1321     myShapeID = 0;
1322   
1323   if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1324     myLyingOnGeomPtr->SetGeom( getShapeByID(myShapeID) );
1325   else
1326     myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1327 }
1328
1329 char* LyingOnGeom_i::GetShapeName()
1330 {
1331   return CORBA::string_dup( myShapeName );
1332 }
1333
1334 char* LyingOnGeom_i::GetShapeID()
1335 {
1336   return CORBA::string_dup( myShapeID );
1337 }
1338
1339 void LyingOnGeom_i::SetTolerance( CORBA::Double theToler )
1340 {
1341   myLyingOnGeomPtr->SetTolerance( theToler );
1342   TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1343 }
1344
1345 CORBA::Double LyingOnGeom_i::GetTolerance()
1346 {
1347   return myLyingOnGeomPtr->GetTolerance();
1348 }
1349
1350 /*
1351   Class       : FreeBorders_i
1352   Description : Predicate for free borders
1353 */
1354 FreeBorders_i::FreeBorders_i()
1355 {
1356   myPredicatePtr.reset(new Controls::FreeBorders());
1357   myFunctorPtr = myPredicatePtr;
1358 }
1359
1360 FunctorType FreeBorders_i::GetFunctorType()
1361 {
1362   return SMESH::FT_FreeBorders;
1363 }
1364
1365 /*
1366   Class       : FreeEdges_i
1367   Description : Predicate for free borders
1368 */
1369 FreeEdges_i::FreeEdges_i()
1370 : myFreeEdgesPtr( new Controls::FreeEdges() )
1371 {
1372   myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
1373 }
1374
1375 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
1376 {
1377   INFOS("FreeEdges_i::GetBorders");
1378   SMESH::Controls::FreeEdges::TBorders aBorders;
1379   myFreeEdgesPtr->GetBoreders( aBorders );
1380
1381   long i = 0, iEnd = aBorders.size();
1382
1383   SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders;
1384   aResult->length(iEnd);
1385
1386   SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
1387   for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
1388   {
1389     const SMESH::Controls::FreeEdges::Border&  aBord = *anIter;
1390     SMESH::FreeEdges::Border &aBorder = aResult[ i ];
1391
1392     aBorder.myElemId = aBord.myElemId;
1393     aBorder.myPnt1 = aBord.myPntId[ 0 ];
1394     aBorder.myPnt2 = aBord.myPntId[ 1 ];
1395   }
1396
1397   INFOS("FreeEdges_i::GetBorders~");
1398   return aResult._retn();
1399 }
1400
1401 FunctorType FreeEdges_i::GetFunctorType()
1402 {
1403   return SMESH::FT_FreeEdges;
1404 }
1405
1406 /*
1407   Class       : FreeFaces_i
1408   Description : Predicate for free faces
1409 */
1410 FreeFaces_i::FreeFaces_i()
1411 {
1412   myPredicatePtr.reset(new Controls::FreeFaces());
1413   myFunctorPtr = myPredicatePtr;
1414 }
1415
1416 FunctorType FreeFaces_i::GetFunctorType()
1417 {
1418   return SMESH::FT_FreeFaces;
1419 }
1420
1421 /*
1422   Class       : FreeNodes_i
1423   Description : Predicate for free nodes
1424 */
1425 FreeNodes_i::FreeNodes_i()
1426 {
1427   myPredicatePtr.reset(new Controls::FreeNodes());
1428   myFunctorPtr = myPredicatePtr;
1429 }
1430
1431 FunctorType FreeNodes_i::GetFunctorType()
1432 {
1433   return SMESH::FT_FreeNodes;
1434 }
1435
1436 /*
1437   Class       : RangeOfIds_i
1438   Description : Predicate for Range of Ids.
1439                 Range may be specified with two ways.
1440                 1. Using AddToRange method
1441                 2. With SetRangeStr method. Parameter of this method is a string
1442                    like as "1,2,3,50-60,63,67,70-"
1443 */
1444
1445 RangeOfIds_i::RangeOfIds_i()
1446 {
1447   myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
1448   myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
1449 }
1450
1451 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
1452 {
1453   CORBA::Long iEnd = theIds.length();
1454   for ( CORBA::Long i = 0; i < iEnd; i++ )
1455     myRangeOfIdsPtr->AddToRange( theIds[ i ] );
1456   TPythonDump()<<this<<".SetRange("<<theIds<<")";
1457 }
1458
1459 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
1460 {
1461   TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
1462   return myRangeOfIdsPtr->SetRangeStr(
1463     TCollection_AsciiString( (Standard_CString)theRange ) );
1464 }
1465
1466 char* RangeOfIds_i::GetRangeStr()
1467 {
1468   TCollection_AsciiString aStr;
1469   myRangeOfIdsPtr->GetRangeStr( aStr );
1470   return CORBA::string_dup( aStr.ToCString() );
1471 }
1472
1473 void RangeOfIds_i::SetElementType( ElementType theType )
1474 {
1475   myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
1476   TPythonDump()<<this<<".SetElementType("<<theType<<")";
1477 }
1478
1479 FunctorType RangeOfIds_i::GetFunctorType()
1480 {
1481   return SMESH::FT_RangeOfIds;
1482 }
1483
1484 /*
1485   Class       : LinearOrQuadratic_i
1486   Description : Predicate to verify whether a mesh element is linear
1487 */
1488 LinearOrQuadratic_i::LinearOrQuadratic_i()
1489 {
1490   myLinearOrQuadraticPtr.reset(new Controls::LinearOrQuadratic());
1491   myFunctorPtr = myPredicatePtr = myLinearOrQuadraticPtr;
1492 }
1493
1494 void LinearOrQuadratic_i::SetElementType(ElementType theType)
1495 {
1496   myLinearOrQuadraticPtr->SetType(SMDSAbs_ElementType(theType));
1497   TPythonDump()<<this<<".SetElementType("<<theType<<")";
1498 }
1499
1500 FunctorType LinearOrQuadratic_i::GetFunctorType()
1501 {
1502   return SMESH::FT_LinearOrQuadratic;
1503 }
1504
1505 /*
1506   Class       : GroupColor_i
1507   Description : Functor for check color of group to whic mesh element belongs to
1508 */
1509 GroupColor_i::GroupColor_i()
1510 {
1511   myGroupColorPtr.reset(new Controls::GroupColor());
1512   myFunctorPtr = myPredicatePtr = myGroupColorPtr;
1513 }
1514
1515 FunctorType GroupColor_i::GetFunctorType()
1516 {
1517   return SMESH::FT_GroupColor;
1518 }
1519
1520 void GroupColor_i::SetColorStr( const char* theColor )
1521 {
1522   myGroupColorPtr->SetColorStr(
1523     TCollection_AsciiString( (Standard_CString)theColor ) );
1524   TPythonDump()<<this<<".SetColorStr('"<<theColor<<"')";
1525 }
1526
1527 char* GroupColor_i::GetColorStr()
1528 {
1529   TCollection_AsciiString aStr;
1530   myGroupColorPtr->GetColorStr( aStr );
1531   return CORBA::string_dup( aStr.ToCString() );
1532 }
1533
1534 void GroupColor_i::SetElementType(ElementType theType)
1535 {
1536   myGroupColorPtr->SetType(SMDSAbs_ElementType(theType));
1537   TPythonDump()<<this<<".SetElementType("<<theType<<")";
1538 }
1539
1540 /*
1541   Class       : ElemGeomType_i
1542   Description : Predicate check is element has indicated geometry type
1543 */
1544 ElemGeomType_i::ElemGeomType_i()
1545 {
1546   myElemGeomTypePtr.reset(new Controls::ElemGeomType());
1547   myFunctorPtr = myPredicatePtr = myElemGeomTypePtr;
1548 }
1549
1550 void ElemGeomType_i::SetElementType(ElementType theType)
1551 {
1552   myElemGeomTypePtr->SetType(SMDSAbs_ElementType(theType));
1553   TPythonDump()<<this<<".SetElementType("<<theType<<")";
1554 }
1555
1556 void ElemGeomType_i::SetGeometryType(GeometryType theType)
1557 {
1558   myElemGeomTypePtr->SetGeomType(SMDSAbs_GeometryType(theType));
1559   TPythonDump()<<this<<".SetGeometryType("<<theType<<")";
1560 }
1561
1562 GeometryType ElemGeomType_i::GetGeometryType() const
1563 {
1564   return (GeometryType)myElemGeomTypePtr->GetGeomType();
1565 }
1566
1567 FunctorType ElemGeomType_i::GetFunctorType()
1568 {
1569   return SMESH::FT_ElemGeomType;
1570 }
1571
1572 /*
1573   Class       : CoplanarFaces_i
1574   Description : Returns true if a mesh face is a coplanar neighbour to a given one
1575 */
1576 CoplanarFaces_i::CoplanarFaces_i()
1577 {
1578   myCoplanarFacesPtr.reset(new Controls::CoplanarFaces());
1579   myFunctorPtr = myPredicatePtr = myCoplanarFacesPtr;
1580 }
1581
1582 void CoplanarFaces_i::SetFace ( CORBA::Long theFaceID )
1583 {
1584   myCoplanarFacesPtr->SetFace(theFaceID);
1585   TPythonDump()<<this<<".SetFace("<<theFaceID<<")";
1586 }
1587
1588 void CoplanarFaces_i::SetTolerance( CORBA::Double theToler )
1589 {
1590   myCoplanarFacesPtr->SetTolerance(theToler);
1591   TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1592 }
1593
1594 CORBA::Long CoplanarFaces_i::GetFace () const
1595 {
1596   return myCoplanarFacesPtr->GetFace();
1597 }
1598
1599 char* CoplanarFaces_i::GetFaceAsString () const
1600 {
1601   TCollection_AsciiString str(Standard_Integer(myCoplanarFacesPtr->GetFace()));
1602   return CORBA::string_dup( str.ToCString() );
1603 }
1604
1605 CORBA::Double CoplanarFaces_i::GetTolerance() const
1606 {
1607   return myCoplanarFacesPtr->GetTolerance();
1608 }
1609
1610 FunctorType CoplanarFaces_i::GetFunctorType()
1611 {
1612   return SMESH::FT_CoplanarFaces;
1613 }
1614
1615 /*
1616   Class       : Comparator_i
1617   Description : Base class for comparators
1618 */
1619 Comparator_i::Comparator_i():
1620   myNumericalFunctor( NULL )
1621 {}
1622
1623 Comparator_i::~Comparator_i()
1624 {
1625   if ( myNumericalFunctor )
1626     myNumericalFunctor->UnRegister();
1627 }
1628
1629 void Comparator_i::SetMargin( CORBA::Double theValue )
1630 {
1631   myComparatorPtr->SetMargin( theValue );
1632   TPythonDump()<<this<<".SetMargin("<<theValue<<")";
1633 }
1634
1635 CORBA::Double Comparator_i::GetMargin()
1636 {
1637   return myComparatorPtr->GetMargin();
1638 }
1639
1640 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
1641 {
1642   if ( myNumericalFunctor )
1643     myNumericalFunctor->UnRegister();
1644
1645   myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
1646
1647   if ( myNumericalFunctor )
1648   {
1649     myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
1650     myNumericalFunctor->Register();
1651     TPythonDump()<<this<<".SetNumFunctor("<<myNumericalFunctor<<")";
1652   }
1653 }
1654
1655 Controls::ComparatorPtr Comparator_i::GetComparator()
1656 {
1657   return myComparatorPtr;
1658 }
1659
1660 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
1661 {
1662   return myNumericalFunctor;
1663 }
1664
1665
1666 /*
1667   Class       : LessThan_i
1668   Description : Comparator "<"
1669 */
1670 LessThan_i::LessThan_i()
1671 {
1672   myComparatorPtr.reset( new Controls::LessThan() );
1673   myFunctorPtr = myPredicatePtr = myComparatorPtr;
1674 }
1675
1676 FunctorType LessThan_i::GetFunctorType()
1677 {
1678   return SMESH::FT_LessThan;
1679 }
1680
1681
1682 /*
1683   Class       : MoreThan_i
1684   Description : Comparator ">"
1685 */
1686 MoreThan_i::MoreThan_i()
1687 {
1688   myComparatorPtr.reset( new Controls::MoreThan() );
1689   myFunctorPtr = myPredicatePtr = myComparatorPtr;
1690 }
1691
1692 FunctorType MoreThan_i::GetFunctorType()
1693 {
1694   return SMESH::FT_MoreThan;
1695 }
1696
1697
1698 /*
1699   Class       : EqualTo_i
1700   Description : Comparator "="
1701 */
1702 EqualTo_i::EqualTo_i()
1703 : myEqualToPtr( new Controls::EqualTo() )
1704 {
1705   myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
1706 }
1707
1708 void EqualTo_i::SetTolerance( CORBA::Double theToler )
1709 {
1710   myEqualToPtr->SetTolerance( theToler );
1711   TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1712 }
1713
1714 CORBA::Double EqualTo_i::GetTolerance()
1715 {
1716   return myEqualToPtr->GetTolerance();
1717 }
1718
1719 FunctorType EqualTo_i::GetFunctorType()
1720 {
1721   return SMESH::FT_EqualTo;
1722 }
1723
1724 /*
1725   Class       : LogicalNOT_i
1726   Description : Logical NOT predicate
1727 */
1728 LogicalNOT_i::LogicalNOT_i()
1729 : myPredicate( NULL ),
1730   myLogicalNOTPtr( new Controls::LogicalNOT() )
1731 {
1732   myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
1733 }
1734
1735 LogicalNOT_i::~LogicalNOT_i()
1736 {
1737   if ( myPredicate )
1738     myPredicate->UnRegister();
1739 }
1740
1741 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
1742 {
1743   if ( myPredicate )
1744     myPredicate->UnRegister();
1745
1746   myPredicate = SMESH::GetPredicate(thePredicate);
1747
1748   if ( myPredicate ){
1749     myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
1750     myPredicate->Register();
1751     TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1752   }
1753 }
1754
1755 FunctorType LogicalNOT_i::GetFunctorType()
1756 {
1757   return SMESH::FT_LogicalNOT;
1758 }
1759
1760 Predicate_i* LogicalNOT_i::GetPredicate_i()
1761 {
1762   return myPredicate;
1763 }
1764
1765
1766 /*
1767   Class       : LogicalBinary_i
1768   Description : Base class for binary logical predicate
1769 */
1770 LogicalBinary_i::LogicalBinary_i()
1771 : myPredicate1( NULL ),
1772   myPredicate2( NULL )
1773 {}
1774
1775 LogicalBinary_i::~LogicalBinary_i()
1776 {
1777   if ( myPredicate1 )
1778     myPredicate1->UnRegister();
1779
1780   if ( myPredicate2 )
1781     myPredicate2->UnRegister();
1782 }
1783
1784 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
1785 {
1786   if ( myPredicate1 )
1787     myPredicate1->SetMesh( theMesh );
1788
1789   if ( myPredicate2 )
1790     myPredicate2->SetMesh( theMesh );
1791 }
1792
1793 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
1794 {
1795   if ( myPredicate1 )
1796     myPredicate1->UnRegister();
1797
1798   myPredicate1 = SMESH::GetPredicate(thePredicate);
1799
1800   if ( myPredicate1 ){
1801     myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
1802     myPredicate1->Register();
1803     TPythonDump()<<this<<".SetPredicate1("<<myPredicate1<<")";
1804   }
1805 }
1806
1807 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
1808 {
1809   if ( myPredicate2 )
1810     myPredicate2->UnRegister();
1811
1812   myPredicate2 = SMESH::GetPredicate(thePredicate);
1813
1814   if ( myPredicate2 ){
1815     myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
1816     myPredicate2->Register();
1817     TPythonDump()<<this<<".SetPredicate2("<<myPredicate2<<")";
1818   }
1819 }
1820
1821 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
1822 {
1823   return myLogicalBinaryPtr;
1824 }
1825
1826 Predicate_i* LogicalBinary_i::GetPredicate1_i()
1827 {
1828   return myPredicate1;
1829 }
1830 Predicate_i* LogicalBinary_i::GetPredicate2_i()
1831 {
1832   return myPredicate2;
1833 }
1834
1835
1836 /*
1837   Class       : LogicalAND_i
1838   Description : Logical AND
1839 */
1840 LogicalAND_i::LogicalAND_i()
1841 {
1842   myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
1843   myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1844 }
1845
1846 FunctorType LogicalAND_i::GetFunctorType()
1847 {
1848   return SMESH::FT_LogicalAND;
1849 }
1850
1851
1852 /*
1853   Class       : LogicalOR_i
1854   Description : Logical OR
1855 */
1856 LogicalOR_i::LogicalOR_i()
1857 {
1858   myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
1859   myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1860 }
1861
1862 FunctorType LogicalOR_i::GetFunctorType()
1863 {
1864   return SMESH::FT_LogicalOR;
1865 }
1866
1867
1868 /*
1869                             FILTER MANAGER
1870 */
1871
1872 FilterManager_i::FilterManager_i()
1873 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
1874 {
1875   //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
1876   //PortableServer::ObjectId_var anObjectId =
1877   //  SMESH_Gen_i::GetPOA()->activate_object( this );
1878 }
1879
1880
1881 FilterManager_i::~FilterManager_i()
1882 {
1883   //TPythonDump()<<this<<".UnRegister()";
1884 }
1885
1886
1887 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
1888 {
1889   SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
1890   SMESH::MinimumAngle_var anObj = aServant->_this();
1891   TPythonDump()<<aServant<<" = "<<this<<".CreateMinimumAngle()";
1892   return anObj._retn();
1893 }
1894
1895
1896 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
1897 {
1898   SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
1899   SMESH::AspectRatio_var anObj = aServant->_this();
1900   TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio()";
1901   return anObj._retn();
1902 }
1903
1904
1905 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
1906 {
1907   SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
1908   SMESH::AspectRatio3D_var anObj = aServant->_this();
1909   TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio3D()";
1910   return anObj._retn();
1911 }
1912
1913
1914 Warping_ptr FilterManager_i::CreateWarping()
1915 {
1916   SMESH::Warping_i* aServant = new SMESH::Warping_i();
1917   SMESH::Warping_var anObj = aServant->_this();
1918   TPythonDump()<<aServant<<" = "<<this<<".CreateWarping()";
1919   return anObj._retn();
1920 }
1921
1922
1923 Taper_ptr FilterManager_i::CreateTaper()
1924 {
1925   SMESH::Taper_i* aServant = new SMESH::Taper_i();
1926   SMESH::Taper_var anObj = aServant->_this();
1927   TPythonDump()<<aServant<<" = "<<this<<".CreateTaper()";
1928   return anObj._retn();
1929 }
1930
1931
1932 Skew_ptr FilterManager_i::CreateSkew()
1933 {
1934   SMESH::Skew_i* aServant = new SMESH::Skew_i();
1935   SMESH::Skew_var anObj = aServant->_this();
1936   TPythonDump()<<aServant<<" = "<<this<<".CreateSkew()";
1937   return anObj._retn();
1938 }
1939
1940
1941 Area_ptr FilterManager_i::CreateArea()
1942 {
1943   SMESH::Area_i* aServant = new SMESH::Area_i();
1944   SMESH::Area_var anObj = aServant->_this();
1945   TPythonDump()<<aServant<<" = "<<this<<".CreateArea()";
1946   return anObj._retn();
1947 }
1948
1949
1950 Volume3D_ptr FilterManager_i::CreateVolume3D()
1951 {
1952   SMESH::Volume3D_i* aServant = new SMESH::Volume3D_i();
1953   SMESH::Volume3D_var anObj = aServant->_this();
1954   TPythonDump()<<aServant<<" = "<<this<<".CreateVolume3D()";
1955   return anObj._retn();
1956 }
1957
1958
1959 MaxElementLength2D_ptr FilterManager_i::CreateMaxElementLength2D()
1960 {
1961   SMESH::MaxElementLength2D_i* aServant = new SMESH::MaxElementLength2D_i();
1962   SMESH::MaxElementLength2D_var anObj = aServant->_this();
1963   TPythonDump()<<aServant<<" = "<<this<<".CreateMaxElementLength2D()";
1964   return anObj._retn();
1965 }
1966
1967
1968 MaxElementLength3D_ptr FilterManager_i::CreateMaxElementLength3D()
1969 {
1970   SMESH::MaxElementLength3D_i* aServant = new SMESH::MaxElementLength3D_i();
1971   SMESH::MaxElementLength3D_var anObj = aServant->_this();
1972   TPythonDump()<<aServant<<" = "<<this<<".CreateMaxElementLength3D()";
1973   return anObj._retn();
1974 }
1975
1976
1977 Length_ptr FilterManager_i::CreateLength()
1978 {
1979   SMESH::Length_i* aServant = new SMESH::Length_i();
1980   SMESH::Length_var anObj = aServant->_this();
1981   TPythonDump()<<aServant<<" = "<<this<<".CreateLength()";
1982   return anObj._retn();
1983 }
1984
1985 Length2D_ptr FilterManager_i::CreateLength2D()
1986 {
1987   SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
1988   SMESH::Length2D_var anObj = aServant->_this();
1989   TPythonDump()<<aServant<<" = "<<this<<".CreateLength2D()";
1990   return anObj._retn();
1991 }
1992
1993 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
1994 {
1995   SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
1996   SMESH::MultiConnection_var anObj = aServant->_this();
1997   TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection()";
1998   return anObj._retn();
1999 }
2000
2001 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
2002 {
2003   SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
2004   SMESH::MultiConnection2D_var anObj = aServant->_this();
2005   TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection2D()";
2006   return anObj._retn();
2007 }
2008
2009 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
2010 {
2011   SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
2012   SMESH::BelongToGeom_var anObj = aServant->_this();
2013   TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGeom()";
2014   return anObj._retn();
2015 }
2016
2017 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
2018 {
2019   SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
2020   SMESH::BelongToPlane_var anObj = aServant->_this();
2021   TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToPlane()";
2022   return anObj._retn();
2023 }
2024
2025 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
2026 {
2027   SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
2028   SMESH::BelongToCylinder_var anObj = aServant->_this();
2029   TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToCylinder()";
2030   return anObj._retn();
2031 }
2032
2033 BelongToGenSurface_ptr FilterManager_i::CreateBelongToGenSurface()
2034 {
2035   SMESH::BelongToGenSurface_i* aServant = new SMESH::BelongToGenSurface_i();
2036   SMESH::BelongToGenSurface_var anObj = aServant->_this();
2037   TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGenSurface()";
2038   return anObj._retn();
2039 }
2040
2041 LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom()
2042 {
2043   SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i();
2044   SMESH::LyingOnGeom_var anObj = aServant->_this();
2045   TPythonDump()<<aServant<<" = "<<this<<".CreateLyingOnGeom()";
2046   return anObj._retn();
2047 }
2048
2049 CoplanarFaces_ptr FilterManager_i::CreateCoplanarFaces()
2050 {
2051   SMESH::CoplanarFaces_i* aServant = new SMESH::CoplanarFaces_i();
2052   SMESH::CoplanarFaces_var anObj = aServant->_this();
2053   TPythonDump()<<aServant<<" = "<<this<<".CreateCoplanarFaces()";
2054   return anObj._retn();
2055 }
2056
2057 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
2058 {
2059   SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
2060   SMESH::FreeBorders_var anObj = aServant->_this();
2061   TPythonDump()<<aServant<<" = "<<this<<".CreateFreeBorders()";
2062   return anObj._retn();
2063 }
2064
2065 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
2066 {
2067   SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
2068   SMESH::FreeEdges_var anObj = aServant->_this();
2069   TPythonDump()<<aServant<<" = "<<this<<".CreateFreeEdges()";
2070   return anObj._retn();
2071 }
2072
2073 FreeFaces_ptr FilterManager_i::CreateFreeFaces()
2074 {
2075   SMESH::FreeFaces_i* aServant = new SMESH::FreeFaces_i();
2076   SMESH::FreeFaces_var anObj = aServant->_this();
2077   TPythonDump()<<aServant<<" = "<<this<<".CreateFreeFaces()";
2078   return anObj._retn();
2079 }
2080
2081 FreeNodes_ptr FilterManager_i::CreateFreeNodes()
2082 {
2083   SMESH::FreeNodes_i* aServant = new SMESH::FreeNodes_i();
2084   SMESH::FreeNodes_var anObj = aServant->_this();
2085   TPythonDump()<<aServant<<" = "<<this<<".CreateFreeNodes()";
2086   return anObj._retn();
2087 }
2088
2089 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
2090 {
2091   SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
2092   SMESH::RangeOfIds_var anObj = aServant->_this();
2093   TPythonDump()<<aServant<<" = "<<this<<".CreateRangeOfIds()";
2094   return anObj._retn();
2095 }
2096
2097 BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
2098 {
2099   SMESH::BadOrientedVolume_i* aServant = new SMESH::BadOrientedVolume_i();
2100   SMESH::BadOrientedVolume_var anObj = aServant->_this();
2101   TPythonDump()<<aServant<<" = "<<this<<".CreateBadOrientedVolume()";
2102   return anObj._retn();
2103 }
2104
2105 BareBorderVolume_ptr FilterManager_i::CreateBareBorderVolume()
2106 {
2107   SMESH::BareBorderVolume_i* aServant = new SMESH::BareBorderVolume_i();
2108   SMESH::BareBorderVolume_var anObj = aServant->_this();
2109   TPythonDump()<<aServant<<" = "<<this<<".CreateBareBorderVolume()";
2110   return anObj._retn();
2111 }
2112
2113 BareBorderFace_ptr FilterManager_i::CreateBareBorderFace()
2114 {
2115   SMESH::BareBorderFace_i* aServant = new SMESH::BareBorderFace_i();
2116   SMESH::BareBorderFace_var anObj = aServant->_this();
2117   TPythonDump()<<aServant<<" = "<<this<<".CreateBareBorderFace()";
2118   return anObj._retn();
2119 }
2120
2121 OverConstrainedVolume_ptr FilterManager_i::CreateOverConstrainedVolume()
2122 {
2123   SMESH::OverConstrainedVolume_i* aServant = new SMESH::OverConstrainedVolume_i();
2124   SMESH::OverConstrainedVolume_var anObj = aServant->_this();
2125   TPythonDump()<<aServant<<" = "<<this<<".CreateOverConstrainedVolume()";
2126   return anObj._retn();
2127 }
2128
2129 OverConstrainedFace_ptr FilterManager_i::CreateOverConstrainedFace()
2130 {
2131   SMESH::OverConstrainedFace_i* aServant = new SMESH::OverConstrainedFace_i();
2132   SMESH::OverConstrainedFace_var anObj = aServant->_this();
2133   TPythonDump()<<aServant<<" = "<<this<<".CreateOverConstrainedFace()";
2134   return anObj._retn();
2135 }
2136
2137 LessThan_ptr FilterManager_i::CreateLessThan()
2138 {
2139   SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
2140   SMESH::LessThan_var anObj = aServant->_this();
2141   TPythonDump()<<aServant<<" = "<<this<<".CreateLessThan()";
2142   return anObj._retn();
2143 }
2144
2145 MoreThan_ptr FilterManager_i::CreateMoreThan()
2146 {
2147   SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
2148   SMESH::MoreThan_var anObj = aServant->_this();
2149   TPythonDump()<<aServant<<" = "<<this<<".CreateMoreThan()";
2150   return anObj._retn();
2151 }
2152
2153 EqualTo_ptr FilterManager_i::CreateEqualTo()
2154 {
2155   SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
2156   SMESH::EqualTo_var anObj = aServant->_this();
2157   TPythonDump()<<aServant<<" = "<<this<<".CreateEqualTo()";
2158   return anObj._retn();
2159 }
2160
2161 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
2162 {
2163   SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
2164   SMESH::LogicalNOT_var anObj = aServant->_this();
2165   TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalNOT()";
2166   return anObj._retn();
2167 }
2168
2169 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
2170 {
2171   SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
2172   SMESH::LogicalAND_var anObj = aServant->_this();
2173   TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalAND()";
2174   return anObj._retn();
2175 }
2176
2177 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
2178 {
2179   SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
2180   SMESH::LogicalOR_var anObj = aServant->_this();
2181   TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalOR()";
2182   return anObj._retn();
2183 }
2184
2185 LinearOrQuadratic_ptr FilterManager_i::CreateLinearOrQuadratic()
2186 {
2187   SMESH::LinearOrQuadratic_i* aServant = new SMESH::LinearOrQuadratic_i();
2188   SMESH::LinearOrQuadratic_var anObj = aServant->_this();
2189   TPythonDump()<<aServant<<" = "<<this<<".CreateLinearOrQuadratic()";
2190   return anObj._retn();
2191 }
2192
2193 GroupColor_ptr FilterManager_i::CreateGroupColor()
2194 {
2195   SMESH::GroupColor_i* aServant = new SMESH::GroupColor_i();
2196   SMESH::GroupColor_var anObj = aServant->_this();
2197   TPythonDump()<<aServant<<" = "<<this<<".CreateGroupColor()";
2198   return anObj._retn();
2199 }
2200
2201 ElemGeomType_ptr FilterManager_i::CreateElemGeomType()
2202 {
2203   SMESH::ElemGeomType_i* aServant = new SMESH::ElemGeomType_i();
2204   SMESH::ElemGeomType_var anObj = aServant->_this();
2205   TPythonDump()<<aServant<<" = "<<this<<".CreateElemGeomType()";
2206   return anObj._retn();
2207 }
2208
2209 Filter_ptr FilterManager_i::CreateFilter()
2210 {
2211   SMESH::Filter_i* aServant = new SMESH::Filter_i();
2212   SMESH::Filter_var anObj = aServant->_this();
2213   TPythonDump()<<aServant<<" = "<<this<<".CreateFilter()";
2214   return anObj._retn();
2215 }
2216
2217 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
2218 {
2219   SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
2220   SMESH::FilterLibrary_var anObj = aServant->_this();
2221   TPythonDump()<<aServant<<" = "<<this<<".LoadLibrary('"<<aFileName<<"')";
2222   return anObj._retn();
2223 }
2224
2225 FilterLibrary_ptr FilterManager_i::CreateLibrary()
2226 {
2227   SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
2228   SMESH::FilterLibrary_var anObj = aServant->_this();
2229   TPythonDump()<<aServant<<" = "<<this<<".CreateLibrary()";
2230   return anObj._retn();
2231 }
2232
2233 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
2234 {
2235   TPythonDump()<<this<<".DeleteLibrary("<<aFileName<<")";
2236   return remove( aFileName ) ? false : true;
2237 }
2238
2239 //=============================================================================
2240 /*!
2241  *  SMESH_Gen_i::CreateFilterManager
2242  *
2243  *  Create filter manager
2244  */
2245 //=============================================================================
2246
2247 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
2248 {
2249   SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2250   SMESH::FilterManager_var anObj = aFilter->_this();
2251   return anObj._retn();
2252 }
2253
2254
2255 /*
2256                               FILTER
2257 */
2258
2259 //=======================================================================
2260 // name    : Filter_i::Filter_i
2261 // Purpose : Constructor
2262 //=======================================================================
2263 Filter_i::Filter_i()
2264 : myPredicate( NULL )
2265 {}
2266
2267 //=======================================================================
2268 // name    : Filter_i::~Filter_i
2269 // Purpose : Destructor
2270 //=======================================================================
2271 Filter_i::~Filter_i()
2272 {
2273   if ( myPredicate )
2274     myPredicate->UnRegister();
2275
2276   if(!CORBA::is_nil(myMesh))
2277     myMesh->UnRegister();
2278
2279   //TPythonDump()<<this<<".UnRegister()";
2280 }
2281
2282 //=======================================================================
2283 // name    : Filter_i::SetPredicate
2284 // Purpose : Set predicate
2285 //=======================================================================
2286 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
2287 {
2288   if ( myPredicate )
2289     myPredicate->UnRegister();
2290
2291   myPredicate = SMESH::GetPredicate(thePredicate);
2292
2293   if ( myPredicate )
2294   {
2295     myFilter.SetPredicate( myPredicate->GetPredicate() );
2296     myPredicate->Register();
2297     if ( const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh))
2298       myPredicate->GetPredicate()->SetMesh( aMesh );
2299     TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
2300   }
2301   std::list<TPredicateChangeWaiter*>::iterator i = myWaiters.begin();
2302   for ( ; i != myWaiters.end(); ++i )
2303     (*i)->PredicateChanged();
2304 }
2305
2306 //=======================================================================
2307 // name    : Filter_i::GetElementType
2308 // Purpose : Get entity type
2309 //=======================================================================
2310 SMESH::ElementType Filter_i::GetElementType()
2311 {
2312   return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
2313 }
2314
2315 //=======================================================================
2316 // name    : Filter_i::SetMesh
2317 // Purpose : Set mesh
2318 //=======================================================================
2319 void
2320 Filter_i::
2321 SetMesh( SMESH_Mesh_ptr theMesh )
2322 {
2323   if(!CORBA::is_nil(theMesh))
2324     theMesh->Register();
2325
2326   if(!CORBA::is_nil(myMesh))
2327     myMesh->UnRegister();
2328
2329   myMesh = SMESH_Mesh::_duplicate( theMesh );
2330   TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
2331
2332   if ( myPredicate )
2333     if ( const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
2334       myPredicate->GetPredicate()->SetMesh( aMesh );
2335 }
2336
2337 SMESH::long_array*
2338 Filter_i::
2339 GetIDs()
2340 {
2341   return GetElementsId(myMesh);
2342 }
2343
2344 //=======================================================================
2345 // name    : Filter_i::GetElementsId
2346 // Purpose : Get ids of entities
2347 //=======================================================================
2348 void
2349 Filter_i::
2350 GetElementsId( Predicate_i* thePredicate,
2351                const SMDS_Mesh* theMesh,
2352                Controls::Filter::TIdSequence& theSequence )
2353 {
2354   if (thePredicate)
2355     Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence);
2356 }
2357
2358 void
2359 Filter_i::
2360 GetElementsId( Predicate_i* thePredicate,
2361                SMESH_Mesh_ptr theMesh,
2362                Controls::Filter::TIdSequence& theSequence )
2363 {
2364   if (thePredicate) 
2365     if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
2366       Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence);
2367 }
2368
2369 SMESH::long_array*
2370 Filter_i::
2371 GetElementsId( SMESH_Mesh_ptr theMesh )
2372 {
2373   SMESH::long_array_var anArray = new SMESH::long_array;
2374   if(!CORBA::is_nil(theMesh) && myPredicate){
2375     Controls::Filter::TIdSequence aSequence;
2376     GetElementsId(myPredicate,theMesh,aSequence);
2377     long i = 0, iEnd = aSequence.size();
2378     anArray->length( iEnd );
2379     for ( ; i < iEnd; i++ )
2380       anArray[ i ] = aSequence[i];
2381   }
2382   return anArray._retn();
2383 }
2384
2385 template<class TElement, class TIterator, class TPredicate>
2386 static void collectMeshInfo(const TIterator& theItr,
2387                             TPredicate& thePred,
2388                             SMESH::long_array& theRes)
2389 {         
2390   if (!theItr)
2391     return;
2392   while (theItr->more()) {
2393     const SMDS_MeshElement* anElem = theItr->next();
2394     if ( thePred->IsSatisfy( anElem->GetID() ) )
2395       theRes[ anElem->GetEntityType() ]++;
2396   }
2397 }
2398
2399 //=============================================================================
2400 /*!
2401  * \brief Returns statistic of mesh elements
2402  */
2403 //=============================================================================
2404 SMESH::long_array* ::Filter_i::GetMeshInfo()
2405 {
2406   SMESH::long_array_var aRes = new SMESH::long_array();
2407   aRes->length(SMESH::Entity_Last);
2408   for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
2409     aRes[i] = 0;
2410
2411   if(!CORBA::is_nil(myMesh) && myPredicate) {
2412     const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
2413     SMDS_ElemIteratorPtr it;
2414     switch( GetElementType() )
2415     {
2416     case SMDSAbs_Node:
2417       collectMeshInfo<const SMDS_MeshNode*>(aMesh->nodesIterator(),myPredicate,aRes);
2418       break;
2419     case SMDSAbs_Edge:
2420       collectMeshInfo<const SMDS_MeshElement*>(aMesh->edgesIterator(),myPredicate,aRes);
2421       break;
2422     case SMDSAbs_Face:
2423       collectMeshInfo<const SMDS_MeshElement*>(aMesh->facesIterator(),myPredicate,aRes);
2424       break;
2425     case SMDSAbs_Volume:
2426       collectMeshInfo<const SMDS_MeshElement*>(aMesh->volumesIterator(),myPredicate,aRes);
2427       break;
2428     case SMDSAbs_All:
2429     default:
2430       collectMeshInfo<const SMDS_MeshElement*>(aMesh->elementsIterator(),myPredicate,aRes);
2431       break;
2432     }
2433   }
2434
2435   return aRes._retn();  
2436 }
2437
2438 //================================================================================
2439 /*!
2440  * \brief Return GetElementType() within an array
2441  * Implement SMESH_IDSource interface
2442  */
2443 //================================================================================
2444
2445 SMESH::array_of_ElementType* Filter_i::GetTypes()
2446 {
2447   SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
2448
2449   // check if any element passes through the filter
2450   if ( !CORBA::is_nil(myMesh) && myPredicate )
2451   {
2452     const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
2453     SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() ));
2454     bool satisfies = false;
2455     while ( !satisfies && it->more() )
2456       satisfies = myPredicate->IsSatisfy( it->next()->GetID() );
2457     if ( satisfies ) {
2458       types->length( 1 );
2459       types[0] = GetElementType();
2460     }
2461   }
2462   return types._retn();
2463 }
2464
2465 //=======================================================================
2466 //function : GetMesh
2467 //purpose  : Returns mesh
2468 //=======================================================================
2469
2470 SMESH::SMESH_Mesh_ptr Filter_i::GetMesh()
2471 {
2472   return SMESH_Mesh::_duplicate( myMesh );
2473 }
2474
2475 //================================================================================
2476 /*!
2477  * \brief Stores an object to be notified on change of predicate
2478  */
2479 //================================================================================
2480
2481 void Filter_i::AddWaiter( TPredicateChangeWaiter* waiter )
2482 {
2483   if ( waiter )
2484     myWaiters.push_back( waiter );
2485 }
2486
2487 //================================================================================
2488 /*!
2489  * \brief Removes an object to be notified on change of predicate
2490  */
2491 //================================================================================
2492
2493 void Filter_i::RemoveWaiter( TPredicateChangeWaiter* waiter )
2494 {
2495   myWaiters.remove( waiter );
2496 }
2497
2498 //=======================================================================
2499 // name    : getCriteria
2500 // Purpose : Retrieve criterions from predicate
2501 //=======================================================================
2502 static inline bool getCriteria( Predicate_i*                thePred,
2503                                 SMESH::Filter::Criteria_out theCriteria )
2504 {
2505   int aFType = thePred->GetFunctorType();
2506
2507   switch ( aFType )
2508   {
2509   case FT_FreeBorders:
2510   case FT_FreeEdges:
2511   case FT_FreeFaces:
2512   case FT_LinearOrQuadratic:
2513   case FT_FreeNodes:
2514     {
2515       CORBA::ULong i = theCriteria->length();
2516       theCriteria->length( i + 1 );
2517
2518       theCriteria[ i ] = createCriterion();
2519
2520       theCriteria[ i ].Type = aFType;
2521       theCriteria[ i ].TypeOfElement = thePred->GetElementType();
2522       return true;
2523     }
2524   case FT_BelongToGeom:
2525     {
2526       BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
2527
2528       CORBA::ULong i = theCriteria->length();
2529       theCriteria->length( i + 1 );
2530
2531       theCriteria[ i ] = createCriterion();
2532
2533       theCriteria[ i ].Type          = FT_BelongToGeom;
2534       theCriteria[ i ].ThresholdStr  = aPred->GetShapeName();
2535       theCriteria[ i ].ThresholdID   = aPred->GetShapeID();
2536       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2537       theCriteria[ i ].Tolerance     = aPred->GetTolerance();
2538
2539       return true;
2540     }
2541   case FT_BelongToPlane:
2542   case FT_BelongToCylinder:
2543   case FT_BelongToGenSurface:
2544     {
2545       BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
2546
2547       CORBA::ULong i = theCriteria->length();
2548       theCriteria->length( i + 1 );
2549
2550       theCriteria[ i ] = createCriterion();
2551
2552       theCriteria[ i ].Type          = aFType;
2553       theCriteria[ i ].ThresholdStr  = aPred->GetShapeName();
2554       theCriteria[ i ].ThresholdID   = aPred->GetShapeID();
2555       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2556       theCriteria[ i ].Tolerance     = aPred->GetTolerance();
2557
2558       return true;
2559     }
2560    case FT_LyingOnGeom:
2561     {
2562       LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
2563
2564       CORBA::ULong i = theCriteria->length();
2565       theCriteria->length( i + 1 );
2566
2567       theCriteria[ i ] = createCriterion();
2568
2569       theCriteria[ i ].Type          = FT_LyingOnGeom;
2570       theCriteria[ i ].ThresholdStr  = aPred->GetShapeName();
2571       theCriteria[ i ].ThresholdID   = aPred->GetShapeID();
2572       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2573       theCriteria[ i ].Tolerance     = aPred->GetTolerance();
2574
2575       return true;
2576     }
2577    case FT_CoplanarFaces:
2578     {
2579       CoplanarFaces_i* aPred = dynamic_cast<CoplanarFaces_i*>( thePred );
2580
2581       CORBA::ULong i = theCriteria->length();
2582       theCriteria->length( i + 1 );
2583
2584       theCriteria[ i ] = createCriterion();
2585       CORBA::String_var faceId = aPred->GetFaceAsString();
2586
2587       theCriteria[ i ].Type          = FT_CoplanarFaces;
2588       theCriteria[ i ].ThresholdID   = faceId;
2589       theCriteria[ i ].Tolerance     = aPred->GetTolerance();
2590
2591       return true;
2592     }
2593   case FT_RangeOfIds:
2594     {
2595       RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
2596
2597       CORBA::ULong i = theCriteria->length();
2598       theCriteria->length( i + 1 );
2599
2600       theCriteria[ i ] = createCriterion();
2601
2602       theCriteria[ i ].Type          = FT_RangeOfIds;
2603       theCriteria[ i ].ThresholdStr  = aPred->GetRangeStr();
2604       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2605
2606       return true;
2607     }
2608   case FT_BadOrientedVolume:
2609     {
2610       BadOrientedVolume_i* aPred = dynamic_cast<BadOrientedVolume_i*>( thePred );
2611
2612       CORBA::ULong i = theCriteria->length();
2613       theCriteria->length( i + 1 );
2614
2615       theCriteria[ i ] = createCriterion();
2616
2617       theCriteria[ i ].Type          = FT_BadOrientedVolume;
2618       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2619
2620       return true;
2621     }
2622   case FT_BareBorderVolume:
2623     {
2624       BareBorderVolume_i* aPred = dynamic_cast<BareBorderVolume_i*>( thePred );
2625
2626       CORBA::ULong i = theCriteria->length();
2627       theCriteria->length( i + 1 );
2628
2629       theCriteria[ i ] = createCriterion();
2630
2631       theCriteria[ i ].Type          = FT_BareBorderVolume;
2632       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2633
2634       return true;
2635     }
2636   case FT_BareBorderFace:
2637     {
2638       BareBorderFace_i* aPred = dynamic_cast<BareBorderFace_i*>( thePred );
2639
2640       CORBA::ULong i = theCriteria->length();
2641       theCriteria->length( i + 1 );
2642
2643       theCriteria[ i ] = createCriterion();
2644
2645       theCriteria[ i ].Type          = FT_BareBorderFace;
2646       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2647
2648       return true;
2649     }
2650   case FT_OverConstrainedVolume:
2651     {
2652       OverConstrainedVolume_i* aPred = dynamic_cast<OverConstrainedVolume_i*>( thePred );
2653
2654       CORBA::ULong i = theCriteria->length();
2655       theCriteria->length( i + 1 );
2656
2657       theCriteria[ i ] = createCriterion();
2658
2659       theCriteria[ i ].Type          = FT_OverConstrainedVolume;
2660       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2661
2662       return true;
2663     }
2664   case FT_OverConstrainedFace:
2665     {
2666       OverConstrainedFace_i* aPred = dynamic_cast<OverConstrainedFace_i*>( thePred );
2667
2668       CORBA::ULong i = theCriteria->length();
2669       theCriteria->length( i + 1 );
2670
2671       theCriteria[ i ] = createCriterion();
2672
2673       theCriteria[ i ].Type          = FT_OverConstrainedFace;
2674       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2675
2676       return true;
2677     }
2678   case FT_LessThan:
2679   case FT_MoreThan:
2680   case FT_EqualTo:
2681     {
2682       Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
2683
2684       CORBA::ULong i = theCriteria->length();
2685       theCriteria->length( i + 1 );
2686
2687       theCriteria[ i ] = createCriterion();
2688
2689       theCriteria[ i ].Type      = aCompar->GetNumFunctor_i()->GetFunctorType();
2690       theCriteria[ i ].Compare   = aFType;
2691       theCriteria[ i ].Threshold = aCompar->GetMargin();
2692       theCriteria[ i ].TypeOfElement = aCompar->GetElementType();
2693
2694       if ( aFType == FT_EqualTo )
2695       {
2696         EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
2697         theCriteria[ i ].Tolerance = aCompar->GetTolerance();
2698       }
2699     }
2700     return true;
2701
2702   case FT_LogicalNOT:
2703     {
2704       Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
2705       getCriteria( aPred, theCriteria );
2706       theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
2707     }
2708     return true;
2709
2710   case FT_LogicalAND:
2711   case FT_LogicalOR:
2712     {
2713       Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
2714       Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
2715       if ( !getCriteria( aPred1, theCriteria ) )
2716         return false;
2717       theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
2718       return getCriteria( aPred2, theCriteria );
2719     }
2720   case FT_GroupColor:
2721     {
2722       CORBA::ULong i = theCriteria->length();
2723       theCriteria->length( i + 1 );
2724
2725       theCriteria[ i ] = createCriterion();
2726
2727       GroupColor_i* aPred = dynamic_cast<GroupColor_i*>( thePred );
2728       theCriteria[ i ].Type          = aFType;
2729       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2730       theCriteria[ i ].ThresholdStr  = aPred->GetColorStr();
2731
2732       return true;
2733     }
2734   case FT_ElemGeomType:
2735     {
2736       CORBA::ULong i = theCriteria->length();
2737       theCriteria->length( i + 1 );
2738
2739       theCriteria[ i ] = createCriterion();
2740
2741       ElemGeomType_i* aPred = dynamic_cast<ElemGeomType_i*>( thePred );
2742       theCriteria[ i ].Type          = aFType;
2743       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2744       theCriteria[ i ].Threshold     = (double)aPred->GetGeometryType();
2745       return true;
2746     }
2747
2748   case FT_Undefined:
2749     return false;
2750   default:
2751     return false;
2752   }
2753 }
2754
2755 //=======================================================================
2756 // name    : Filter_i::GetCriteria
2757 // Purpose : Retrieve criterions from predicate
2758 //=======================================================================
2759 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
2760 {
2761   theCriteria = new SMESH::Filter::Criteria;
2762   return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
2763 }
2764
2765 //=======================================================================
2766 // name    : Filter_i::SetCriteria
2767 // Purpose : Create new predicate and set criterions in it
2768 //=======================================================================
2769 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
2770 {
2771   if ( myPredicate != 0 )
2772     myPredicate->UnRegister();
2773
2774   SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2775   FilterManager_ptr aFilterMgr = aFilter->_this();
2776
2777   // CREATE two lists ( PREDICATES  and LOG OP )
2778
2779   // Criterion
2780   TPythonDump()<<"aCriteria = []";
2781   std::list<SMESH::Predicate_ptr> aPredicates;
2782   std::list<int>                  aBinaries;
2783   for ( int i = 0, n = theCriteria.length(); i < n; i++ )
2784   {
2785     int         aCriterion    = theCriteria[ i ].Type;
2786     int         aCompare      = theCriteria[ i ].Compare;
2787     double      aThreshold    = theCriteria[ i ].Threshold;
2788     const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
2789     const char* aThresholdID  = theCriteria[ i ].ThresholdID;
2790     int         aUnary        = theCriteria[ i ].UnaryOp;
2791     int         aBinary       = theCriteria[ i ].BinaryOp;
2792     double      aTolerance    = theCriteria[ i ].Tolerance;
2793     ElementType aTypeOfElem   = theCriteria[ i ].TypeOfElement;
2794     long        aPrecision    = theCriteria[ i ].Precision;
2795
2796     {
2797       TPythonDump pd;
2798       pd << "aCriterion = SMESH.Filter.Criterion("
2799          << aCriterion    << ", "
2800          << aCompare      << ", "
2801          << aThreshold    << ", '"
2802          << aThresholdStr << "', '";
2803       if (aThresholdID) pd << aThresholdID;
2804       pd                  << "', "
2805          << aUnary        << ", "
2806          << aBinary       << ", "
2807          << aTolerance    << ", "
2808          << aTypeOfElem   << ", "
2809          << aPrecision    << ")";
2810     }
2811     TPythonDump pd;
2812
2813     SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
2814     SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
2815
2816     switch ( aCriterion )
2817     {
2818       // Functors
2819
2820       case SMESH::FT_MultiConnection:
2821         aFunctor = aFilterMgr->CreateMultiConnection();
2822         break;
2823       case SMESH::FT_MultiConnection2D:
2824         aFunctor = aFilterMgr->CreateMultiConnection2D();
2825         break;
2826       case SMESH::FT_Length:
2827         aFunctor = aFilterMgr->CreateLength();
2828         break;
2829       case SMESH::FT_Length2D:
2830         aFunctor = aFilterMgr->CreateLength2D();
2831         break;
2832       case SMESH::FT_AspectRatio:
2833         aFunctor = aFilterMgr->CreateAspectRatio();
2834         break;
2835       case SMESH::FT_AspectRatio3D:
2836         aFunctor = aFilterMgr->CreateAspectRatio3D();
2837         break;
2838       case SMESH::FT_Warping:
2839         aFunctor = aFilterMgr->CreateWarping();
2840         break;
2841       case SMESH::FT_MinimumAngle:
2842         aFunctor = aFilterMgr->CreateMinimumAngle();
2843         break;
2844       case SMESH::FT_Taper:
2845         aFunctor = aFilterMgr->CreateTaper();
2846         break;
2847       case SMESH::FT_Skew:
2848         aFunctor = aFilterMgr->CreateSkew();
2849         break;
2850       case SMESH::FT_Area:
2851         aFunctor = aFilterMgr->CreateArea();
2852         break;
2853       case SMESH::FT_Volume3D:
2854         aFunctor = aFilterMgr->CreateVolume3D();
2855         break;
2856       case SMESH::FT_MaxElementLength2D:
2857         aFunctor = aFilterMgr->CreateMaxElementLength2D();
2858         break;
2859       case SMESH::FT_MaxElementLength3D:
2860         aFunctor = aFilterMgr->CreateMaxElementLength3D();
2861         break;
2862
2863       // Predicates
2864
2865       case SMESH::FT_FreeBorders:
2866         aPredicate = aFilterMgr->CreateFreeBorders();
2867         break;
2868       case SMESH::FT_FreeEdges:
2869         aPredicate = aFilterMgr->CreateFreeEdges();
2870         break;
2871       case SMESH::FT_FreeFaces:
2872         aPredicate = aFilterMgr->CreateFreeFaces();
2873         break;
2874       case SMESH::FT_FreeNodes:
2875         aPredicate = aFilterMgr->CreateFreeNodes();
2876         break;
2877       case SMESH::FT_BelongToGeom:
2878         {
2879           SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
2880           tmpPred->SetElementType( aTypeOfElem );
2881           tmpPred->SetShape( aThresholdID, aThresholdStr );
2882           tmpPred->SetTolerance( aTolerance );
2883           aPredicate = tmpPred;
2884         }
2885         break;
2886       case SMESH::FT_BelongToPlane:
2887       case SMESH::FT_BelongToCylinder:
2888       case SMESH::FT_BelongToGenSurface:
2889         {
2890           SMESH::BelongToSurface_ptr tmpPred;
2891           switch ( aCriterion ) {
2892           case SMESH::FT_BelongToPlane:
2893             tmpPred = aFilterMgr->CreateBelongToPlane(); break;
2894           case SMESH::FT_BelongToCylinder:
2895             tmpPred = aFilterMgr->CreateBelongToCylinder(); break;
2896           default:
2897             tmpPred = aFilterMgr->CreateBelongToGenSurface();
2898           }
2899           tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem );
2900           tmpPred->SetTolerance( aTolerance );
2901           aPredicate = tmpPred;
2902         }
2903         break;
2904       case SMESH::FT_LyingOnGeom:
2905         {
2906           SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
2907           tmpPred->SetElementType( aTypeOfElem );
2908           tmpPred->SetShape( aThresholdID, aThresholdStr );
2909           tmpPred->SetTolerance( aTolerance );
2910           aPredicate = tmpPred;
2911         }
2912         break;
2913       case SMESH::FT_RangeOfIds:
2914         {
2915           SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
2916           tmpPred->SetRangeStr( aThresholdStr );
2917           tmpPred->SetElementType( aTypeOfElem );
2918           aPredicate = tmpPred;
2919         }
2920         break;
2921       case SMESH::FT_BadOrientedVolume:
2922         {
2923           aPredicate = aFilterMgr->CreateBadOrientedVolume();
2924         }
2925         break;
2926       case SMESH::FT_BareBorderVolume:
2927         {
2928           aPredicate = aFilterMgr->CreateBareBorderVolume();
2929         }
2930         break;
2931       case SMESH::FT_BareBorderFace:
2932         {
2933           aPredicate = aFilterMgr->CreateBareBorderFace();
2934         }
2935         break;
2936       case SMESH::FT_OverConstrainedVolume:
2937         {
2938           aPredicate = aFilterMgr->CreateOverConstrainedVolume();
2939         }
2940         break;
2941       case SMESH::FT_OverConstrainedFace:
2942         {
2943           aPredicate = aFilterMgr->CreateOverConstrainedFace();
2944         }
2945         break;
2946       case SMESH::FT_LinearOrQuadratic:
2947         {
2948           SMESH::LinearOrQuadratic_ptr tmpPred = aFilterMgr->CreateLinearOrQuadratic();
2949           tmpPred->SetElementType( aTypeOfElem );
2950           aPredicate = tmpPred;
2951           break;
2952         }
2953       case SMESH::FT_GroupColor:
2954         {
2955           SMESH::GroupColor_ptr tmpPred = aFilterMgr->CreateGroupColor();
2956           tmpPred->SetElementType( aTypeOfElem );
2957           tmpPred->SetColorStr( aThresholdStr );
2958           aPredicate = tmpPred;
2959           break;
2960         }
2961       case SMESH::FT_ElemGeomType:
2962         {
2963           SMESH::ElemGeomType_ptr tmpPred = aFilterMgr->CreateElemGeomType();
2964           tmpPred->SetElementType( aTypeOfElem );
2965           tmpPred->SetGeometryType( (GeometryType)(int)(aThreshold + 0.5) );
2966           aPredicate = tmpPred;
2967           break;
2968         }
2969       case SMESH::FT_CoplanarFaces:
2970         {
2971           SMESH::CoplanarFaces_ptr tmpPred = aFilterMgr->CreateCoplanarFaces();
2972           tmpPred->SetFace( atol (aThresholdID ));
2973           tmpPred->SetTolerance( aTolerance );
2974           aPredicate = tmpPred;
2975           break;
2976         }
2977
2978       default:
2979         continue;
2980     }
2981
2982     // Comparator
2983     if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
2984     {
2985       SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
2986
2987       if ( aCompare == SMESH::FT_LessThan )
2988         aComparator = aFilterMgr->CreateLessThan();
2989       else if ( aCompare == SMESH::FT_MoreThan )
2990         aComparator = aFilterMgr->CreateMoreThan();
2991       else if ( aCompare == SMESH::FT_EqualTo )
2992         aComparator = aFilterMgr->CreateEqualTo();
2993       else
2994         continue;
2995
2996       aComparator->SetNumFunctor( aFunctor );
2997       aComparator->SetMargin( aThreshold );
2998
2999       if ( aCompare == FT_EqualTo )
3000       {
3001         SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
3002         anEqualTo->SetTolerance( aTolerance );
3003       }
3004
3005       aPredicate = aComparator;
3006
3007       aFunctor->SetPrecision( aPrecision );
3008     }
3009
3010     // Logical not
3011     if ( aUnary == FT_LogicalNOT )
3012     {
3013       SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
3014       aNotPred->SetPredicate( aPredicate );
3015       aPredicate = aNotPred;
3016     }
3017
3018     // logical op
3019     aPredicates.push_back( aPredicate );
3020     aBinaries.push_back( aBinary );
3021     pd <<"aCriteria.append(aCriterion)";
3022
3023   } // end of for
3024   TPythonDump pd; pd<<this<<".SetCriteria(aCriteria)";
3025
3026   // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
3027
3028   // combine all "AND" operations
3029
3030   std::list<SMESH::Predicate_ptr> aResList;
3031
3032   std::list<SMESH::Predicate_ptr>::iterator aPredIter;
3033   std::list<int>::iterator                  aBinaryIter;
3034
3035   SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
3036   int aPrevBinary = SMESH::FT_Undefined;
3037
3038   for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
3039         aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
3040         ++aPredIter, ++aBinaryIter )
3041   {
3042     int aCurrBinary = *aBinaryIter;
3043
3044     SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
3045
3046     if ( aPrevBinary == SMESH::FT_LogicalAND )
3047     {
3048
3049       SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
3050       aBinaryPred->SetPredicate1( aPrevPredicate );
3051       aBinaryPred->SetPredicate2( *aPredIter );
3052       aCurrPred = aBinaryPred;
3053     }
3054     else
3055       aCurrPred = *aPredIter;
3056
3057     if ( aCurrBinary != SMESH::FT_LogicalAND )
3058       aResList.push_back( aCurrPred );
3059
3060     aPrevPredicate = aCurrPred;
3061     aPrevBinary = aCurrBinary;
3062   }
3063
3064   // combine all "OR" operations
3065
3066   SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
3067
3068   if ( aResList.size() == 1 )
3069     aResPredicate = *aResList.begin();
3070   else if ( aResList.size() > 1 )
3071   {
3072     std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
3073     aResPredicate = *anIter;
3074     anIter++;
3075     for ( ; anIter != aResList.end(); ++anIter )
3076     {
3077       SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
3078       aBinaryPred->SetPredicate1( aResPredicate );
3079       aBinaryPred->SetPredicate2( *anIter );
3080       aResPredicate = aBinaryPred;
3081     }
3082   }
3083
3084   SetPredicate( aResPredicate );
3085
3086   return !aResPredicate->_is_nil();
3087 }
3088
3089 //=======================================================================
3090 // name    : Filter_i::GetPredicate_i
3091 // Purpose : Get implementation of predicate
3092 //=======================================================================
3093 Predicate_i* Filter_i::GetPredicate_i()
3094 {
3095   return myPredicate;
3096 }
3097
3098 //=======================================================================
3099 // name    : Filter_i::GetPredicate
3100 // Purpose : Get predicate
3101 //=======================================================================
3102 Predicate_ptr Filter_i::GetPredicate()
3103 {
3104   if ( myPredicate == 0 )
3105     return SMESH::Predicate::_nil();
3106   else
3107   {
3108     SMESH::Predicate_var anObj = myPredicate->_this();
3109     // if ( SMESH::Functor_i* fun = SMESH::DownCast<SMESH::Functor_i*>( anObj ))
3110     //   TPythonDump() << fun << " = " << this << ".GetPredicate()";
3111     return anObj._retn();
3112   }
3113 }
3114
3115 /*
3116                             FILTER LIBRARY
3117 */
3118
3119 #define ATTR_TYPE          "type"
3120 #define ATTR_COMPARE       "compare"
3121 #define ATTR_THRESHOLD     "threshold"
3122 #define ATTR_UNARY         "unary"
3123 #define ATTR_BINARY        "binary"
3124 #define ATTR_THRESHOLD_STR "threshold_str"
3125 #define ATTR_TOLERANCE     "tolerance"
3126 #define ATTR_ELEMENT_TYPE  "ElementType"
3127
3128 //=======================================================================
3129 // name    : toString
3130 // Purpose : Convert bool to LDOMString
3131 //=======================================================================
3132 static inline LDOMString toString( CORBA::Boolean val )
3133 {
3134   return val ? "logical not" : "";
3135 }
3136
3137 //=======================================================================
3138 // name    : toBool
3139 // Purpose : Convert LDOMString to bool
3140 //=======================================================================
3141 static inline bool toBool( const LDOMString& theStr )
3142 {
3143   return theStr.equals( "logical not" );
3144 }
3145
3146 //=======================================================================
3147 // name    : toString
3148 // Purpose : Convert double to LDOMString
3149 //=======================================================================
3150 static inline LDOMString toString( CORBA::Double val )
3151 {
3152   char a[ 255 ];
3153   sprintf( a, "%e", val );
3154   return LDOMString( a );
3155 }
3156
3157 //=======================================================================
3158 // name    : toDouble
3159 // Purpose : Convert LDOMString to double
3160 //=======================================================================
3161 static inline double toDouble( const LDOMString& theStr )
3162 {
3163   return atof( theStr.GetString() );
3164 }
3165
3166 //=======================================================================
3167 // name    : toString
3168 // Purpose : Convert functor type to LDOMString
3169 //=======================================================================
3170 static inline LDOMString toString( CORBA::Long theType )
3171 {
3172   switch ( theType )
3173   {
3174     case FT_AspectRatio     : return "Aspect ratio";
3175     case FT_Warping         : return "Warping";
3176     case FT_MinimumAngle    : return "Minimum angle";
3177     case FT_Taper           : return "Taper";
3178     case FT_Skew            : return "Skew";
3179     case FT_Area            : return "Area";
3180     case FT_Volume3D        : return "Volume3D";
3181     case FT_MaxElementLength2D: return "Max element length 2D";
3182     case FT_MaxElementLength3D: return "Max element length 3D";
3183     case FT_BelongToGeom    : return "Belong to Geom";
3184     case FT_BelongToPlane   : return "Belong to Plane";
3185     case FT_BelongToCylinder: return "Belong to Cylinder";
3186     case FT_BelongToGenSurface: return "Belong to Generic Surface";
3187     case FT_LyingOnGeom     : return "Lying on Geom";
3188     case FT_BadOrientedVolume:return "Bad Oriented Volume";
3189     case FT_BareBorderVolume: return "Volumes with bare border";
3190     case FT_BareBorderFace  : return "Faces with bare border";
3191     case FT_OverConstrainedVolume: return "Over-constrained Volumes";
3192     case FT_OverConstrainedFace  : return "Over-constrained Faces";
3193     case FT_RangeOfIds      : return "Range of IDs";
3194     case FT_FreeBorders     : return "Free borders";
3195     case FT_FreeEdges       : return "Free edges";
3196     case FT_FreeFaces       : return "Free faces";
3197     case FT_FreeNodes       : return "Free nodes";
3198     case FT_MultiConnection : return "Borders at multi-connections";
3199     case FT_MultiConnection2D: return "Borders at multi-connections 2D";
3200     case FT_Length          : return "Length";
3201     case FT_Length2D        : return "Length 2D";
3202     case FT_LessThan        : return "Less than";
3203     case FT_MoreThan        : return "More than";
3204     case FT_EqualTo         : return "Equal to";
3205     case FT_LogicalNOT      : return "Not";
3206     case FT_LogicalAND      : return "And";
3207     case FT_LogicalOR       : return "Or";
3208     case FT_GroupColor      : return "Color of Group";
3209     case FT_LinearOrQuadratic : return "Linear or Quadratic";
3210     case FT_ElemGeomType    : return "Element geomtry type";
3211     case FT_Undefined       : return "";
3212     default                 : return "";
3213   }
3214 }
3215
3216 //=======================================================================
3217 // name    : toFunctorType
3218 // Purpose : Convert LDOMString to functor type
3219 //=======================================================================
3220 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
3221 {
3222   if      ( theStr.equals( "Aspect ratio"                 ) ) return FT_AspectRatio;
3223   else if ( theStr.equals( "Warping"                      ) ) return FT_Warping;
3224   else if ( theStr.equals( "Minimum angle"                ) ) return FT_MinimumAngle;
3225   else if ( theStr.equals( "Taper"                        ) ) return FT_Taper;
3226   else if ( theStr.equals( "Skew"                         ) ) return FT_Skew;
3227   else if ( theStr.equals( "Area"                         ) ) return FT_Area;
3228   else if ( theStr.equals( "Volume3D"                     ) ) return FT_Volume3D;
3229   else if ( theStr.equals( "Max element length 2D"        ) ) return FT_MaxElementLength2D;
3230   else if ( theStr.equals( "Max element length 3D"        ) ) return FT_MaxElementLength3D;
3231   else if ( theStr.equals( "Belong to Geom"               ) ) return FT_BelongToGeom;
3232   else if ( theStr.equals( "Belong to Plane"              ) ) return FT_BelongToPlane;
3233   else if ( theStr.equals( "Belong to Cylinder"           ) ) return FT_BelongToCylinder;
3234   else if ( theStr.equals( "Belong to Generic Surface"    ) ) return FT_BelongToGenSurface;
3235   else if ( theStr.equals( "Lying on Geom"                ) ) return FT_LyingOnGeom;
3236   else if ( theStr.equals( "Free borders"                 ) ) return FT_FreeBorders;
3237   else if ( theStr.equals( "Free edges"                   ) ) return FT_FreeEdges;
3238   else if ( theStr.equals( "Free faces"                   ) ) return FT_FreeFaces;
3239   else if ( theStr.equals( "Free nodes"                   ) ) return FT_FreeNodes;
3240   else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
3241   //  else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
3242   else if ( theStr.equals( "Length"                       ) ) return FT_Length;
3243   //  else if ( theStr.equals( "Length2D"                     ) ) return FT_Length2D;
3244   else if ( theStr.equals( "Range of IDs"                 ) ) return FT_RangeOfIds;
3245   else if ( theStr.equals( "Bad Oriented Volume"          ) ) return FT_BadOrientedVolume;
3246   else if ( theStr.equals( "Volumes with bare border"     ) ) return FT_BareBorderVolume;
3247   else if ( theStr.equals( "Faces with bare border"       ) ) return FT_BareBorderFace;
3248   else if ( theStr.equals( "Over-constrained Volumes"     ) ) return FT_OverConstrainedVolume;
3249   else if ( theStr.equals( "Over-constrained Faces"       ) ) return FT_OverConstrainedFace;
3250   else if ( theStr.equals( "Less than"                    ) ) return FT_LessThan;
3251   else if ( theStr.equals( "More than"                    ) ) return FT_MoreThan;
3252   else if ( theStr.equals( "Equal to"                     ) ) return FT_EqualTo;
3253   else if ( theStr.equals( "Not"                          ) ) return FT_LogicalNOT;
3254   else if ( theStr.equals( "And"                          ) ) return FT_LogicalAND;
3255   else if ( theStr.equals( "Or"                           ) ) return FT_LogicalOR;
3256   else if ( theStr.equals( "Color of Group"               ) ) return FT_GroupColor;
3257   else if ( theStr.equals( "Linear or Quadratic"          ) ) return FT_LinearOrQuadratic;
3258   else if ( theStr.equals( "Element geomtry type"         ) ) return FT_ElemGeomType;
3259   else if ( theStr.equals( ""                             ) ) return FT_Undefined;
3260   else  return FT_Undefined;
3261 }
3262
3263 //=======================================================================
3264 // name    : toFunctorType
3265 // Purpose : Convert LDOMString to value of ElementType enumeration
3266 //=======================================================================
3267 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
3268 {
3269   if      ( theStr.equals( "NODE"   ) ) return SMESH::NODE;
3270   else if ( theStr.equals( "EDGE"   ) ) return SMESH::EDGE;
3271   else if ( theStr.equals( "FACE"   ) ) return SMESH::FACE;
3272   else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
3273   else                                  return SMESH::ALL;
3274 }
3275
3276 //=======================================================================
3277 // name    : toString
3278 // Purpose : Convert ElementType to string
3279 //=======================================================================
3280 static inline LDOMString toString( const SMESH::ElementType theType )
3281 {
3282   switch ( theType )
3283   {
3284     case SMESH::NODE   : return "NODE";
3285     case SMESH::EDGE   : return "EDGE";
3286     case SMESH::FACE   : return "FACE";
3287     case SMESH::VOLUME : return "VOLUME";
3288     case SMESH::ALL    : return "ALL";
3289     default            : return "";
3290   }
3291 }
3292
3293 //=======================================================================
3294 // name    : findFilter
3295 // Purpose : Find filter in document
3296 //=======================================================================
3297 static LDOM_Element findFilter( const char* theFilterName,
3298                                 const LDOM_Document& theDoc,
3299                                 LDOM_Node* theParent = 0 )
3300 {
3301   LDOM_Element aRootElement = theDoc.getDocumentElement();
3302   if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
3303     return LDOM_Element();
3304
3305   for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
3306         !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
3307   {
3308     for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
3309           !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
3310     {
3311       LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
3312       if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
3313            anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
3314       {
3315         if ( theParent != 0  )
3316           *theParent = aTypeNode;
3317         return (LDOM_Element&)aFilter;
3318       }
3319     }
3320   }
3321   return LDOM_Element();
3322 }
3323
3324 //=======================================================================
3325 // name    : getSectionName
3326 // Purpose : Get name of section of filters
3327 //=======================================================================
3328 static const char* getSectionName( const ElementType theType )
3329 {
3330   switch ( theType )
3331   {
3332     case SMESH::NODE   : return "Filters for nodes";
3333     case SMESH::EDGE   : return "Filters for edges";
3334     case SMESH::FACE   : return "Filters for faces";
3335     case SMESH::VOLUME : return "Filters for volumes";
3336     case SMESH::ALL    : return "Filters for elements";
3337     default            : return "";
3338   }
3339 }
3340
3341 //=======================================================================
3342 // name    : getSection
3343 // Purpose : Create section for filters corresponding to the entity type
3344 //=======================================================================
3345 static LDOM_Node getSection( const ElementType theType,
3346                              LDOM_Document&    theDoc,
3347                              const bool        toCreate = false )
3348 {
3349   LDOM_Element aRootElement = theDoc.getDocumentElement();
3350   if ( aRootElement.isNull() )
3351     return LDOM_Node();
3352
3353   // Find section
3354   bool anExist = false;
3355   const char* aSectionName = getSectionName( theType );
3356   if ( strcmp( aSectionName, "" ) == 0 )
3357     return LDOM_Node();
3358
3359   LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
3360   LDOM_Node aNode;
3361   for ( int i = 0, n = aSections.getLength(); i < n; i++ )
3362   {
3363     aNode = aSections.item( i );
3364     LDOM_Element& anItem = ( LDOM_Element& )aNode;
3365     if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
3366     {
3367       anExist = true;
3368       break;
3369     }
3370   }
3371
3372   // Create new section if necessary
3373   if ( !anExist )
3374   {
3375     if ( toCreate )
3376     {
3377       LDOM_Element aNewItem = theDoc.createElement( "section" );
3378       aNewItem.setAttribute( "name", aSectionName );
3379       aRootElement.appendChild( aNewItem );
3380       return aNewItem;
3381     }
3382     else
3383       return LDOM_Node();
3384   }
3385   return
3386     aNode;
3387 }
3388
3389 //=======================================================================
3390 // name    : createFilterItem
3391 // Purpose : Create filter item or LDOM document
3392 //=======================================================================
3393 static LDOM_Element createFilterItem( const char*       theName,
3394                                       SMESH::Filter_ptr theFilter,
3395                                       LDOM_Document&    theDoc )
3396 {
3397   // create new filter in document
3398   LDOM_Element aFilterItem = theDoc.createElement( "filter" );
3399   aFilterItem.setAttribute( "name", theName );
3400
3401   // save filter criterions
3402   SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
3403
3404   if ( !theFilter->GetCriteria( aCriteria ) )
3405     return LDOM_Element();
3406
3407   for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
3408   {
3409     LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
3410     
3411     aCriterionItem.setAttribute( ATTR_TYPE         , toString(  aCriteria[ i ].Type) );
3412     aCriterionItem.setAttribute( ATTR_COMPARE      , toString(  aCriteria[ i ].Compare ) );
3413     aCriterionItem.setAttribute( ATTR_THRESHOLD    , toString(  aCriteria[ i ].Threshold ) );
3414     aCriterionItem.setAttribute( ATTR_UNARY        , toString(  aCriteria[ i ].UnaryOp ) );
3415     aCriterionItem.setAttribute( ATTR_BINARY       , toString(  aCriteria[ i ].BinaryOp ) );
3416
3417     aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
3418     aCriterionItem.setAttribute( ATTR_TOLERANCE    , toString( aCriteria[ i ].Tolerance ) );
3419     aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
3420       toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
3421
3422     aFilterItem.appendChild( aCriterionItem );
3423   }
3424
3425   return aFilterItem;
3426 }
3427
3428 //=======================================================================
3429 // name    : FilterLibrary_i::FilterLibrary_i
3430 // Purpose : Constructor
3431 //=======================================================================
3432 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
3433 {
3434   myFileName = strdup( theFileName );
3435   SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
3436   myFilterMgr = aFilterMgr->_this();
3437
3438   LDOMParser aParser;
3439
3440   // Try to use existing library file
3441   bool anExists = false;
3442   if ( !aParser.parse( myFileName ) )
3443   {
3444     myDoc = aParser.getDocument();
3445     anExists = true;
3446   }
3447   // Create a new XML document if it doesn't exist
3448   else
3449     myDoc = LDOM_Document::createDocument( LDOMString() );
3450
3451   LDOM_Element aRootElement = myDoc.getDocumentElement();
3452   if ( aRootElement.isNull() )
3453   {
3454     // If the existing document is empty --> try to create a new one
3455     if ( anExists )
3456       myDoc = LDOM_Document::createDocument( LDOMString() );
3457   }
3458 }
3459
3460 //=======================================================================
3461 // name    : FilterLibrary_i::FilterLibrary_i
3462 // Purpose : Constructor
3463 //=======================================================================
3464 FilterLibrary_i::FilterLibrary_i()
3465 {
3466   myFileName = 0;
3467   SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
3468   myFilterMgr = aFilter->_this();
3469
3470   myDoc = LDOM_Document::createDocument( LDOMString() );
3471 }
3472
3473 FilterLibrary_i::~FilterLibrary_i()
3474 {
3475   delete myFileName;
3476   //TPythonDump()<<this<<".UnRegister()";
3477 }
3478
3479 //=======================================================================
3480 // name    : FilterLibrary_i::Copy
3481 // Purpose : Create filter and initialize it with values from library
3482 //=======================================================================
3483 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
3484 {
3485   Filter_ptr aRes = Filter::_nil();
3486   LDOM_Node aFilter = findFilter( theFilterName, myDoc );
3487
3488   if ( aFilter.isNull() )
3489     return aRes;
3490
3491   std::list<SMESH::Filter::Criterion> aCriteria;
3492
3493   for ( LDOM_Node aCritNode = aFilter.getFirstChild();
3494         !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
3495   {
3496     LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
3497
3498     const char* aTypeStr      = aCrit->getAttribute( ATTR_TYPE          ).GetString();
3499     const char* aCompareStr   = aCrit->getAttribute( ATTR_COMPARE       ).GetString();
3500     const char* aUnaryStr     = aCrit->getAttribute( ATTR_UNARY         ).GetString();
3501     const char* aBinaryStr    = aCrit->getAttribute( ATTR_BINARY        ).GetString();
3502     const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE  ).GetString();
3503
3504     SMESH::Filter::Criterion aCriterion = createCriterion();
3505
3506     aCriterion.Type          = toFunctorType( aTypeStr );
3507     aCriterion.Compare       = toFunctorType( aCompareStr );
3508     aCriterion.UnaryOp       = toFunctorType( aUnaryStr );
3509     aCriterion.BinaryOp      = toFunctorType( aBinaryStr );
3510
3511     aCriterion.TypeOfElement = toElementType( anElemTypeStr );
3512
3513     LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
3514     int val = 0;
3515     aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3516       ? val : atof( str.GetString() );
3517
3518     str = aCrit->getAttribute( ATTR_TOLERANCE );
3519     aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3520       ? val : atof( str.GetString() );
3521
3522     str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
3523     if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
3524     {
3525       char a[ 255 ];
3526       sprintf( a, "%d", val );
3527       aCriterion.ThresholdStr = strdup( a );
3528     }
3529     else
3530       aCriterion.ThresholdStr = str.GetString();
3531
3532     aCriteria.push_back( aCriterion );
3533   }
3534
3535   SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
3536   aCriteriaVar->length( aCriteria.size() );
3537
3538   CORBA::ULong i = 0;
3539   std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
3540
3541   for( ; anIter != aCriteria.end(); ++anIter )
3542     aCriteriaVar[ i++ ] = *anIter;
3543
3544   aRes = myFilterMgr->CreateFilter();
3545   aRes->SetCriteria( aCriteriaVar.inout() );
3546
3547   TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
3548
3549   return aRes;
3550 }
3551
3552 //=======================================================================
3553 // name    : FilterLibrary_i::SetFileName
3554 // Purpose : Set file name for library
3555 //=======================================================================
3556 void FilterLibrary_i::SetFileName( const char* theFileName )
3557 {
3558   delete myFileName;
3559   myFileName = strdup( theFileName );
3560   TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
3561 }
3562
3563 //=======================================================================
3564 // name    : FilterLibrary_i::GetFileName
3565 // Purpose : Get file name of library
3566 //=======================================================================
3567 char* FilterLibrary_i::GetFileName()
3568 {
3569   return CORBA::string_dup( myFileName );
3570 }
3571
3572 //=======================================================================
3573 // name    : FilterLibrary_i::Add
3574 // Purpose : Add new filter to library
3575 //=======================================================================
3576 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
3577 {
3578   // if filter already in library or entry filter is null do nothing
3579   LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3580   if ( !aFilterNode.isNull() || theFilter->_is_nil() )
3581     return false;
3582
3583   // get section corresponding to the filter type
3584   ElementType anEntType = theFilter->GetElementType();
3585
3586   LDOM_Node aSection = getSection( anEntType, myDoc, true );
3587   if ( aSection.isNull() )
3588     return false;
3589
3590   // create filter item
3591   LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
3592   if ( aFilterItem.isNull() )
3593     return false;
3594   else
3595   {
3596     aSection.appendChild( aFilterItem );
3597     if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3598       TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
3599     return true;
3600   }
3601 }
3602
3603 //=======================================================================
3604 // name    : FilterLibrary_i::Add
3605 // Purpose : Add new filter to library
3606 //=======================================================================
3607 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
3608 {
3609   // if filter already in library or entry filter is null do nothing
3610   LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3611   if ( !aFilterNode.isNull() )
3612     return false;
3613
3614   LDOM_Node aSection = getSection( theType, myDoc, true );
3615   if ( aSection.isNull() )
3616     return false;
3617
3618   // create filter item
3619   Filter_var aFilter = myFilterMgr->CreateFilter();
3620
3621   LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
3622   if ( aFilterItem.isNull() )
3623     return false;
3624   else
3625   {
3626     aSection.appendChild( aFilterItem );
3627     TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
3628     return true;
3629   }
3630 }
3631
3632 //=======================================================================
3633 // name    : FilterLibrary_i::Delete
3634 // Purpose : Delete filter from library
3635 //=======================================================================
3636 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
3637 {
3638   LDOM_Node aParentNode;
3639   LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
3640   if ( aFilterNode.isNull() || aParentNode.isNull() )
3641     return false;
3642
3643   aParentNode.removeChild( aFilterNode );
3644   TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
3645   return true;
3646 }
3647
3648 //=======================================================================
3649 // name      : FilterLibrary_i::Replace
3650 // Purpose   : Replace existing filter with entry filter.
3651 // IMPORTANT : If filter does not exist it is not created
3652 //=======================================================================
3653 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
3654                                          const char* theNewName,
3655                                          Filter_ptr  theFilter )
3656 {
3657   LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
3658   if ( aFilterItem.isNull() || theFilter->_is_nil() )
3659     return false;
3660
3661   LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
3662   if ( aNewItem.isNull() )
3663     return false;
3664   else
3665   {
3666     aFilterItem.ReplaceElement( aNewItem );
3667     if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3668       TPythonDump()<<this<<".Replace('"<<theFilterName<<"','"<<theNewName<<"',"<<aFilter<<")";
3669     return true;
3670   }
3671 }
3672
3673 //=======================================================================
3674 // name    : FilterLibrary_i::Save
3675 // Purpose : Save library on disk
3676 //=======================================================================
3677 CORBA::Boolean FilterLibrary_i::Save()
3678 {
3679   if ( myFileName == 0 || strlen( myFileName ) == 0 )
3680     return false;
3681
3682   FILE* aOutFile = fopen( myFileName, "wt" );
3683   if ( !aOutFile )
3684     return false;
3685
3686   LDOM_XmlWriter aWriter( aOutFile );
3687   aWriter.SetIndentation( 2 );
3688   aWriter << myDoc;
3689   fclose( aOutFile );
3690
3691   TPythonDump()<<this<<".Save()";
3692   return true;
3693 }
3694
3695 //=======================================================================
3696 // name    : FilterLibrary_i::SaveAs
3697 // Purpose : Save library on disk
3698 //=======================================================================
3699 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
3700 {
3701   myFileName = strdup ( aFileName );
3702   TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
3703   return Save();
3704 }
3705
3706 //=======================================================================
3707 // name    : FilterLibrary_i::IsPresent
3708 // Purpose : Verify whether filter is in library
3709 //=======================================================================
3710 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
3711 {
3712   return !findFilter( theFilterName, myDoc ).isNull();
3713 }
3714
3715 //=======================================================================
3716 // name    : FilterLibrary_i::NbFilters
3717 // Purpose : Return amount of filters in library
3718 //=======================================================================
3719 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
3720 {
3721   string_array_var aNames = GetNames( theType );
3722   return aNames->length();
3723 }
3724
3725 //=======================================================================
3726 // name    : FilterLibrary_i::GetNames
3727 // Purpose : Get names of filters from library
3728 //=======================================================================
3729 string_array* FilterLibrary_i::GetNames( ElementType theType )
3730 {
3731   string_array_var anArray = new string_array;
3732   TColStd_SequenceOfHAsciiString aSeq;
3733
3734   LDOM_Node aSection = getSection( theType, myDoc, false );
3735
3736   if ( !aSection.isNull() )
3737   {
3738     for ( LDOM_Node aFilter = aSection.getFirstChild();
3739           !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
3740     {
3741       LDOM_Element& anElem = ( LDOM_Element& )aFilter;
3742       aSeq.Append( new TCollection_HAsciiString(
3743          (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
3744     }
3745   }
3746
3747   anArray->length( aSeq.Length() );
3748   for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
3749     anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
3750
3751   return anArray._retn();
3752 }
3753
3754 //=======================================================================
3755 // name    : FilterLibrary_i::GetAllNames
3756 // Purpose : Get names of filters from library
3757 //=======================================================================
3758 string_array* FilterLibrary_i::GetAllNames()
3759 {
3760   string_array_var aResArray = new string_array;
3761   for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
3762   {
3763     SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
3764
3765     int aPrevLength = aResArray->length();
3766     aResArray->length( aPrevLength + aNames->length() );
3767     for ( int i = 0, n = aNames->length(); i < n; i++ )
3768       aResArray[ aPrevLength + i ] = aNames[ i ];
3769   }
3770
3771   return aResArray._retn();
3772 }
3773
3774 //================================================================================
3775 /*!
3776  * \brief Return an array of strings corresponding to items of enum FunctorType
3777  */
3778 //================================================================================
3779
3780 static const char** getFunctNames()
3781 {
3782   static const char* functName[ SMESH::FT_Undefined + 1 ] = {
3783     // If this line doesn't compile, this means that enum FunctorType has changed and
3784     // it's necessary to update this array accordingly (refer to SMESH_Filter.idl)
3785     // The order is IMPORTANT !!!
3786     "FT_AspectRatio", "FT_AspectRatio3D", "FT_Warping", "FT_MinimumAngle",
3787     "FT_Taper", "FT_Skew", "FT_Area", "FT_Volume3D", "FT_MaxElementLength2D",
3788     "FT_MaxElementLength3D", "FT_FreeBorders", "FT_FreeEdges", "FT_FreeNodes",
3789     "FT_FreeFaces", "FT_MultiConnection", "FT_MultiConnection2D", "FT_Length",
3790     "FT_Length2D", "FT_BelongToGeom", "FT_BelongToPlane", "FT_BelongToCylinder",
3791     "FT_BelongToGenSurface", "FT_LyingOnGeom", "FT_RangeOfIds", "FT_BadOrientedVolume",
3792     "FT_BareBorderVolume", "FT_BareBorderFace", "FT_OverConstrainedVolume",
3793     "FT_OverConstrainedFace", "FT_LinearOrQuadratic", "FT_GroupColor", "FT_ElemGeomType",
3794     "FT_CoplanarFaces", "FT_LessThan", "FT_MoreThan", "FT_EqualTo", "FT_LogicalNOT",
3795     "FT_LogicalAND", "FT_LogicalOR", "FT_Undefined" };
3796   return functName;
3797 }
3798
3799 //================================================================================
3800 /*!
3801  * \brief Return a string corresponding to an item of enum FunctorType
3802  */
3803 //================================================================================
3804
3805 const char* SMESH::FunctorTypeToString(SMESH::FunctorType ft)
3806 {
3807   if ( ft < 0 || ft > SMESH::FT_Undefined )
3808     return "FT_Undefined";
3809   return getFunctNames()[ ft ];
3810 }
3811
3812 //================================================================================
3813 /*!
3814  * \brief Converts a string to FunctorType. This is reverse of FunctorTypeToString()
3815  */
3816 //================================================================================
3817
3818 SMESH::FunctorType SMESH::StringToFunctorType(const char* str)
3819 {
3820   std::string name( str + 3 ); // skip "FT_"
3821   const char** functNames = getFunctNames();
3822   int ft = 0;
3823   for ( ; ft < SMESH::FT_Undefined; ++ft )
3824     if ( name == ( functNames[ft] + 3 ))
3825       break;
3826
3827   //ASSERT( strcmp( str, FunctorTypeToString( SMESH::FunctorType( ft ))) == 0 );
3828
3829   return SMESH::FunctorType( ft );
3830 }