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