Salome HOME
PythonDump for SMESH Controls / Filter
[modules/smesh.git] / src / SMESH_I / SMESH_Filter_i.cxx
1 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 //
24 //  File   : SMESH_Filter_i.cxx
25 //  Author : Alexey Petrov, OCC
26 //  Module : SMESH
27
28
29 #include "SMESH_Filter_i.hxx"
30
31 #include "SMESH_Gen_i.hxx"
32 #include "SMESH_PythonDump.hxx"
33
34 #include "SMDS_Mesh.hxx"
35 #include "SMDS_MeshNode.hxx"
36 #include "SMDS_MeshElement.hxx"
37
38 #include "SMESHDS_Mesh.hxx"
39
40 #include <LDOM_Document.hxx>
41 #include <LDOM_Element.hxx>
42 #include <LDOM_Node.hxx>
43 #include <LDOMString.hxx>
44 #include <LDOMParser.hxx>
45 #include <LDOM_XmlWriter.hxx>
46 #include <TCollection_HAsciiString.hxx>
47 #include <TColStd_ListIteratorOfListOfInteger.hxx>
48 #include <TColStd_ListOfInteger.hxx>
49 #include <TColStd_ListOfReal.hxx>
50 #include <TColStd_MapOfInteger.hxx>
51 #include <TColStd_SequenceOfHAsciiString.hxx>
52 #include <TColStd_ListIteratorOfListOfReal.hxx>
53 #include <Precision.hxx>
54 #include <BRep_Tool.hxx>
55 #include <TopoDS_Shape.hxx>
56 #include <TopoDS.hxx>
57 #include <TopoDS_Face.hxx>
58 #include <Geom_Plane.hxx>
59 #include <Geom_CylindricalSurface.hxx>
60 #include <TopExp_Explorer.hxx>
61 #include <OSD_Path.hxx>
62 #include <OSD_File.hxx>
63
64 using namespace SMESH;
65 using namespace SMESH::Controls;
66
67
68 namespace SMESH
69 {
70   Predicate_i* 
71   GetPredicate( Predicate_ptr thePredicate )
72   {
73     return DownCast<Predicate_i*>(thePredicate);
74   }
75 }
76
77
78 /*
79   Class       : BelongToGeom
80   Description : Predicate for verifying whether entiy belong to
81                 specified geometrical support
82 */
83
84 Controls::BelongToGeom::BelongToGeom()
85 : myMeshDS(NULL),
86   myType(SMDSAbs_All)
87 {}
88
89 void Controls::BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
90 {
91   myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
92 }
93
94 void Controls::BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
95 {
96   myShape = theShape;
97 }
98
99 static bool IsContains( const SMESHDS_Mesh*     theMeshDS,
100                         const TopoDS_Shape&     theShape,
101                         const SMDS_MeshElement* theElem,
102                         TopAbs_ShapeEnum        theFindShapeEnum,
103                         TopAbs_ShapeEnum        theAvoidShapeEnum = TopAbs_SHAPE )
104 {
105   TopExp_Explorer anExp( theShape,theFindShapeEnum,theAvoidShapeEnum );
106   
107   while( anExp.More() )
108   {
109     const TopoDS_Shape& aShape = anExp.Current();
110     if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
111       if( aSubMesh->Contains( theElem ) )
112         return true;
113     }
114     anExp.Next();
115   }
116   return false;
117 }
118
119 bool Controls::BelongToGeom::IsSatisfy( long theId )
120 {
121   if ( myMeshDS == 0 || myShape.IsNull() )
122     return false;
123
124   if( myType == SMDSAbs_Node )
125   {
126     if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
127     {
128       const SMDS_PositionPtr& aPosition = aNode->GetPosition();
129       SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
130       switch( aTypeOfPosition )
131       {
132       case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
133       case SMDS_TOP_EDGE   : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
134       case SMDS_TOP_FACE   : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
135       case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
136       }
137     }
138   }
139   else
140   {
141     if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
142     {
143       if( myType == SMDSAbs_All )
144       {
145         return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
146                IsContains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
147                IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
148                IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
149       }
150       else if( myType == anElem->GetType() )
151       {
152         switch( myType )
153         {
154         case SMDSAbs_Edge  : return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE );
155         case SMDSAbs_Face  : return IsContains( myMeshDS,myShape,anElem,TopAbs_FACE );
156         case SMDSAbs_Volume: return IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
157                                     IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
158         }
159       }
160     }
161   }
162     
163   return false;
164 }
165
166 void Controls::BelongToGeom::SetType( SMDSAbs_ElementType theType )
167 {
168   myType = theType;
169 }
170
171 SMDSAbs_ElementType Controls::BelongToGeom::GetType() const
172 {
173   return myType;
174 }
175
176 TopoDS_Shape Controls::BelongToGeom::GetShape()
177 {
178   return myShape;
179 }
180
181 const SMESHDS_Mesh* 
182 Controls::BelongToGeom::
183 GetMeshDS() const
184 {
185   return myMeshDS;
186 }
187
188 /*
189   Class       : LyingOnGeom
190   Description : Predicate for verifying whether entiy lying or partially lying on
191                 specified geometrical support
192 */
193
194 Controls::LyingOnGeom::LyingOnGeom()
195 : myMeshDS(NULL),
196   myType(SMDSAbs_All)
197 {}
198
199 void Controls::LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
200 {
201   myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
202 }
203
204 void Controls::LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
205 {
206   myShape = theShape;
207 }
208
209 bool Controls::LyingOnGeom::IsSatisfy( long theId )
210 {
211   if ( myMeshDS == 0 || myShape.IsNull() )
212     return false;
213
214   if( myType == SMDSAbs_Node )
215   {
216     if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
217     {
218       const SMDS_PositionPtr& aPosition = aNode->GetPosition();
219       SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
220       switch( aTypeOfPosition )
221       {
222       case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
223       case SMDS_TOP_EDGE   : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
224       case SMDS_TOP_FACE   : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
225       case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
226       }
227     }
228   }
229   else
230   {
231     if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
232     {
233       if( myType == SMDSAbs_All )
234       {
235         return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
236                Contains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
237                Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
238                Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
239       }
240       else if( myType == anElem->GetType() )
241       {
242         switch( myType )
243         {
244         case SMDSAbs_Edge  : return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE );
245         case SMDSAbs_Face  : return Contains( myMeshDS,myShape,anElem,TopAbs_FACE );
246         case SMDSAbs_Volume: return Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
247                                     Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
248         }
249       }
250     }
251   }
252     
253   return false;
254 }
255
256 void Controls::LyingOnGeom::SetType( SMDSAbs_ElementType theType )
257 {
258   myType = theType;
259 }
260
261 SMDSAbs_ElementType Controls::LyingOnGeom::GetType() const
262 {
263   return myType;
264 }
265
266 TopoDS_Shape Controls::LyingOnGeom::GetShape()
267 {
268   return myShape;
269 }
270
271 const SMESHDS_Mesh* 
272 Controls::LyingOnGeom::
273 GetMeshDS() const
274 {
275   return myMeshDS;
276 }
277
278 bool Controls::LyingOnGeom::Contains( const SMESHDS_Mesh*     theMeshDS,
279                                       const TopoDS_Shape&     theShape,
280                                       const SMDS_MeshElement* theElem,
281                                       TopAbs_ShapeEnum        theFindShapeEnum,
282                                       TopAbs_ShapeEnum        theAvoidShapeEnum )
283 {
284   if (IsContains(theMeshDS, theShape, theElem, theFindShapeEnum, theAvoidShapeEnum))
285     return true;
286   
287   TopTools_IndexedMapOfShape aSubShapes;
288   TopExp::MapShapes( theShape, aSubShapes );
289   
290   for (int i = 1; i <= aSubShapes.Extent(); i++)
291     {
292       const TopoDS_Shape& aShape = aSubShapes.FindKey(i);
293       
294       if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
295         if( aSubMesh->Contains( theElem ) )
296           return true;
297         
298         SMDS_NodeIteratorPtr aNodeIt = aSubMesh->GetNodes();
299         while ( aNodeIt->more() )
300           {
301             const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(aNodeIt->next());
302             SMDS_ElemIteratorPtr anElemIt = aNode->GetInverseElementIterator();
303             while ( anElemIt->more() )
304               {
305                 const SMDS_MeshElement* anElement = static_cast<const SMDS_MeshElement*>(anElemIt->next());
306                 if (anElement == theElem)
307                   return true;
308               }
309           }
310       }
311     }
312   return false;
313 }
314
315
316 /*
317                             AUXILIARY METHODS
318 */
319
320 inline 
321 const SMDS_Mesh* 
322 MeshPtr2SMDSMesh( SMESH_Mesh_ptr theMesh )
323 {
324   SMESH_Mesh_i* anImplPtr = DownCast<SMESH_Mesh_i*>(theMesh);
325   return anImplPtr ? anImplPtr->GetImpl().GetMeshDS() : 0;
326 }
327
328 inline 
329 SMESH::long_array* 
330 toArray( const TColStd_ListOfInteger& aList )
331 {
332   SMESH::long_array_var anArray = new SMESH::long_array;
333   anArray->length( aList.Extent() );
334   TColStd_ListIteratorOfListOfInteger anIter( aList );
335   int i = 0;
336   for( ; anIter.More(); anIter.Next() )
337     anArray[ i++ ] = anIter.Value();
338
339   return anArray._retn();
340 }
341
342 inline 
343 SMESH::double_array* 
344 toArray( const TColStd_ListOfReal& aList )
345 {
346   SMESH::double_array_var anArray = new SMESH::double_array;
347   anArray->length( aList.Extent() );
348   TColStd_ListIteratorOfListOfReal anIter( aList );
349   int i = 0;
350   for( ; anIter.More(); anIter.Next() )
351     anArray[ i++ ] = anIter.Value();
352
353   return anArray._retn();
354 }
355
356 static SMESH::Filter::Criterion createCriterion()
357 {
358   SMESH::Filter::Criterion aCriterion;
359
360   aCriterion.Type          = FT_Undefined;
361   aCriterion.Compare       = FT_Undefined;
362   aCriterion.Threshold     = 0;
363   aCriterion.UnaryOp       = FT_Undefined;
364   aCriterion.BinaryOp      = FT_Undefined;
365   aCriterion.ThresholdStr  = "";
366   aCriterion.Tolerance     = Precision::Confusion();
367   aCriterion.TypeOfElement = SMESH::ALL;
368   aCriterion.Precision     = -1;
369
370   return aCriterion;
371 }
372
373 static TopoDS_Shape getShapeByName( const char* theName )
374 {
375   if ( theName != 0 )
376   {
377     SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
378     SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
379     if ( aStudy != 0 )
380     {
381       SALOMEDS::Study::ListOfSObject_var aList =
382         aStudy->FindObjectByName( theName, "GEOM" );
383       if ( aList->length() > 0 )
384       {
385         GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aList[ 0 ]->GetObject() );
386         if ( !aGeomObj->_is_nil() )
387         {
388           GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
389           TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
390           return aLocShape;
391         }
392       }
393     }
394   }
395   return TopoDS_Shape();
396 }
397
398
399
400 /*
401                                 FUNCTORS
402 */
403
404 /*
405   Class       : Functor_i
406   Description : An abstact class for all functors 
407 */
408 Functor_i::Functor_i(): 
409   SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
410 {
411   SMESH_Gen_i::GetPOA()->activate_object( this );
412 }
413
414 void Functor_i::SetMesh( SMESH_Mesh_ptr theMesh )
415 {
416   myFunctorPtr->SetMesh( MeshPtr2SMDSMesh( theMesh ) );
417   TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
418 }
419
420 ElementType Functor_i::GetElementType()
421 {
422   return ( ElementType )myFunctorPtr->GetType();
423 }
424
425
426 /*
427   Class       : NumericalFunctor_i
428   Description : Base class for numerical functors
429 */
430 CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
431 {
432   return myNumericalFunctorPtr->GetValue( theId );
433 }
434
435 void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision )
436 {
437   myNumericalFunctorPtr->SetPrecision( thePrecision );
438   TPythonDump()<<this<<".SetPrecision("<<thePrecision<<")";
439 }
440
441 CORBA::Long NumericalFunctor_i::GetPrecision()
442 {
443  return myNumericalFunctorPtr->GetPrecision();
444 }
445
446 Controls::NumericalFunctorPtr NumericalFunctor_i::GetNumericalFunctor()
447 {
448   return myNumericalFunctorPtr;
449 }
450
451
452 /*
453   Class       : SMESH_MinimumAngle
454   Description : Functor for calculation of minimum angle
455 */
456 MinimumAngle_i::MinimumAngle_i()
457 {
458   myNumericalFunctorPtr.reset( new Controls::MinimumAngle() );
459   myFunctorPtr = myNumericalFunctorPtr;
460 }
461
462 FunctorType MinimumAngle_i::GetFunctorType()
463 {
464   return SMESH::FT_MinimumAngle;
465 }
466
467
468 /*
469   Class       : AspectRatio
470   Description : Functor for calculating aspect ratio
471 */
472 AspectRatio_i::AspectRatio_i()
473 {
474   myNumericalFunctorPtr.reset( new Controls::AspectRatio() );
475   myFunctorPtr = myNumericalFunctorPtr;
476 }
477
478 FunctorType AspectRatio_i::GetFunctorType()
479 {
480   return SMESH::FT_AspectRatio;
481 }
482
483
484 /*
485   Class       : AspectRatio3D
486   Description : Functor for calculating aspect ratio 3D
487 */
488 AspectRatio3D_i::AspectRatio3D_i()
489 {
490   myNumericalFunctorPtr.reset( new Controls::AspectRatio3D() );
491   myFunctorPtr = myNumericalFunctorPtr;
492 }
493
494 FunctorType AspectRatio3D_i::GetFunctorType()
495 {
496   return SMESH::FT_AspectRatio3D;
497 }
498
499
500 /*
501   Class       : Warping_i
502   Description : Functor for calculating warping
503 */
504 Warping_i::Warping_i()
505 {
506   myNumericalFunctorPtr.reset( new Controls::Warping() );
507   myFunctorPtr = myNumericalFunctorPtr;
508 }
509
510 FunctorType Warping_i::GetFunctorType()
511 {
512   return SMESH::FT_Warping;
513 }
514
515
516 /*
517   Class       : Taper_i
518   Description : Functor for calculating taper
519 */
520 Taper_i::Taper_i()
521 {
522   myNumericalFunctorPtr.reset( new Controls::Taper() );
523   myFunctorPtr = myNumericalFunctorPtr;
524 }
525
526 FunctorType Taper_i::GetFunctorType()
527 {
528   return SMESH::FT_Taper;
529 }
530
531
532 /*
533   Class       : Skew_i
534   Description : Functor for calculating skew in degrees
535 */
536 Skew_i::Skew_i()
537 {
538   myNumericalFunctorPtr.reset( new Controls::Skew() );
539   myFunctorPtr = myNumericalFunctorPtr;
540 }
541
542 FunctorType Skew_i::GetFunctorType()
543 {
544   return SMESH::FT_Skew;
545 }
546
547 /*
548   Class       : Area_i
549   Description : Functor for calculating area
550 */
551 Area_i::Area_i()
552 {
553   myNumericalFunctorPtr.reset( new Controls::Area() );
554   myFunctorPtr = myNumericalFunctorPtr;
555 }
556
557 FunctorType Area_i::GetFunctorType()
558 {
559   return SMESH::FT_Area;
560 }
561
562 /*
563   Class       : Length_i
564   Description : Functor for calculating length off edge
565 */
566 Length_i::Length_i()
567 {
568   myNumericalFunctorPtr.reset( new Controls::Length() );
569   myFunctorPtr = myNumericalFunctorPtr;
570 }
571
572 FunctorType Length_i::GetFunctorType()
573 {
574   return SMESH::FT_Length;
575 }
576
577 /*
578   Class       : Length2D_i
579   Description : Functor for calculating length of edge
580 */
581 Length2D_i::Length2D_i()
582 {
583   myNumericalFunctorPtr.reset( new Controls::Length2D() );
584   myFunctorPtr = myNumericalFunctorPtr;
585 }
586
587 FunctorType Length2D_i::GetFunctorType()
588 {
589   return SMESH::FT_Length2D;
590 }
591
592 SMESH::Length2D::Values* Length2D_i::GetValues()
593 {
594   INFOS("Length2D_i::GetValues");
595   SMESH::Controls::Length2D::TValues aValues;
596   myLength2DPtr->GetValues( aValues );
597   
598   long i = 0, iEnd = aValues.size();
599
600   SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd);
601
602   SMESH::Controls::Length2D::TValues::const_iterator anIter;
603   for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
604   {
605     const SMESH::Controls::Length2D::Value&  aVal = *anIter;
606     SMESH::Length2D::Value &aValue = aResult[ i ];
607     
608     aValue.myLength = aVal.myLength;
609     aValue.myPnt1 = aVal.myPntId[ 0 ];
610     aValue.myPnt2 = aVal.myPntId[ 1 ];
611    
612   }
613
614   INFOS("Length2D_i::GetValuess~");
615   return aResult._retn();
616 }
617
618 /*
619   Class       : MultiConnection_i
620   Description : Functor for calculating number of faces conneted to the edge
621 */
622 MultiConnection_i::MultiConnection_i()
623 {
624   myNumericalFunctorPtr.reset( new Controls::MultiConnection() );
625   myFunctorPtr = myNumericalFunctorPtr;
626 }
627
628 FunctorType MultiConnection_i::GetFunctorType()
629 {
630   return SMESH::FT_MultiConnection;
631 }
632
633 /*
634   Class       : MultiConnection2D_i
635   Description : Functor for calculating number of faces conneted to the edge
636 */
637 MultiConnection2D_i::MultiConnection2D_i()
638 {
639   myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() );
640   myFunctorPtr = myNumericalFunctorPtr;
641 }
642
643 FunctorType MultiConnection2D_i::GetFunctorType()
644 {
645   return SMESH::FT_MultiConnection2D;
646 }
647
648 SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
649 {
650   INFOS("MultiConnection2D_i::GetValues");
651   SMESH::Controls::MultiConnection2D::MValues aValues;
652   myMulticonnection2DPtr->GetValues( aValues );
653   
654   long i = 0, iEnd = aValues.size();
655
656   SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd);
657
658   SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter;
659   for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
660   {
661     const SMESH::Controls::MultiConnection2D::Value&  aVal = (*anIter).first;
662     SMESH::MultiConnection2D::Value &aValue = aResult[ i ];
663     
664     aValue.myPnt1 = aVal.myPntId[ 0 ];
665     aValue.myPnt2 = aVal.myPntId[ 1 ];
666     aValue.myNbConnects = (*anIter).second;
667    
668   }
669
670   INFOS("Multiconnection2D_i::GetValuess~");
671   return aResult._retn();
672 }
673
674 /*
675                             PREDICATES
676 */
677
678
679 /*
680   Class       : Predicate_i
681   Description : Base class for all predicates
682 */
683 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
684 {
685   return myPredicatePtr->IsSatisfy( theId );
686 }
687
688 Controls::PredicatePtr Predicate_i::GetPredicate()
689 {
690   return myPredicatePtr;
691 }
692
693 /*
694   Class       : BadOrientedVolume_i
695   Description : Verify whether a mesh volume is incorrectly oriented from
696                 the point of view of MED convention
697 */
698 BadOrientedVolume_i::BadOrientedVolume_i()
699 {
700   Controls::PredicatePtr control( new Controls::BadOrientedVolume() );
701   myFunctorPtr = myPredicatePtr = control;
702 };
703
704 FunctorType BadOrientedVolume_i::GetFunctorType()
705 {
706   return SMESH::FT_BadOrientedVolume;
707 }
708
709 /*
710   Class       : BelongToGeom_i
711   Description : Predicate for selection on geometrical support
712 */
713 BelongToGeom_i::BelongToGeom_i()
714 {
715   myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
716   myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
717   myShapeName = 0;
718 }
719
720 BelongToGeom_i::~BelongToGeom_i()
721 {
722   delete myShapeName;
723 }
724
725 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
726 {
727   if ( theGeom->_is_nil() )
728     return;
729   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
730   GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
731   TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
732   myBelongToGeomPtr->SetGeom( aLocShape );
733   TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
734 }
735
736 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
737 {
738   myBelongToGeomPtr->SetGeom( theShape );
739 }
740
741 void BelongToGeom_i::SetElementType(ElementType theType){
742   myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
743   TPythonDump()<<this<<".SetElementType("<<theType<<")";
744 }
745
746 FunctorType BelongToGeom_i::GetFunctorType()
747 {
748   return SMESH::FT_BelongToGeom;
749 }
750
751 void BelongToGeom_i::SetShapeName( const char* theName )
752 {
753   delete myShapeName;
754   myShapeName = strdup( theName );
755   myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
756   TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
757 }
758
759 char* BelongToGeom_i::GetShapeName()
760 {
761   return CORBA::string_dup( myShapeName );
762 }
763
764 /*
765   Class       : BelongToSurface_i
766   Description : Predicate for selection on geometrical support
767 */
768 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
769 {
770   myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
771   myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
772   myShapeName = 0;
773   mySurfaceType = theSurfaceType;
774 }
775
776 BelongToSurface_i::~BelongToSurface_i()
777 {
778   delete myShapeName;
779 }
780
781 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
782 {
783   if ( theGeom->_is_nil() )
784     return;
785   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
786   GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
787   TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
788
789   if ( aLocShape.ShapeType() == TopAbs_FACE )
790   {
791     Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
792     if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
793     {
794       myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
795       return;
796     }
797   }
798
799   myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
800   TPythonDump()<<this<<".SetSurface("<<theGeom<<",'"<<theType<<"')";
801 }
802
803 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
804 {
805   delete myShapeName;
806   myShapeName = strdup( theName );
807   myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
808   TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
809 }
810
811 char* BelongToSurface_i::GetShapeName()
812 {
813   return CORBA::string_dup( myShapeName );
814 }
815
816 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
817 {
818   myElementsOnSurfacePtr->SetTolerance( theToler );
819   TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
820 }
821
822 CORBA::Double BelongToSurface_i::GetTolerance()
823 {
824   return myElementsOnSurfacePtr->GetTolerance();
825 }
826
827 /*
828   Class       : BelongToPlane_i
829   Description : Verify whether mesh element lie in pointed Geom planar object
830 */
831
832 BelongToPlane_i::BelongToPlane_i()
833 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
834 {
835 }
836
837 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
838 {
839   BelongToSurface_i::SetSurface( theGeom, theType );
840   TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
841 }
842
843 FunctorType BelongToPlane_i::GetFunctorType()
844 {
845   return FT_BelongToPlane;
846 }
847
848 /*
849   Class       : BelongToCylinder_i
850   Description : Verify whether mesh element lie in pointed Geom planar object
851 */
852
853 BelongToCylinder_i::BelongToCylinder_i()
854 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
855 {
856 }
857
858 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
859 {
860   BelongToSurface_i::SetSurface( theGeom, theType );
861   TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
862 }
863
864 FunctorType BelongToCylinder_i::GetFunctorType()
865 {
866   return FT_BelongToCylinder;
867 }
868
869 /*
870   Class       : LyingOnGeom_i
871   Description : Predicate for selection on geometrical support
872 */
873 LyingOnGeom_i::LyingOnGeom_i()
874 {
875   myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
876   myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
877   myShapeName = 0;
878 }
879
880 LyingOnGeom_i::~LyingOnGeom_i()
881 {
882   delete myShapeName;
883 }
884
885 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
886 {
887   if ( theGeom->_is_nil() )
888     return;
889   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
890   GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
891   TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
892   myLyingOnGeomPtr->SetGeom( aLocShape );
893   TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
894 }
895
896 void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
897 {
898   myLyingOnGeomPtr->SetGeom( theShape );
899 }
900
901 void LyingOnGeom_i::SetElementType(ElementType theType){
902   myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
903   TPythonDump()<<this<<".SetElementType("<<theType<<")";
904 }
905
906 FunctorType LyingOnGeom_i::GetFunctorType()
907 {
908   return SMESH::FT_LyingOnGeom;
909 }
910
911 void LyingOnGeom_i::SetShapeName( const char* theName )
912 {
913   delete myShapeName;
914   myShapeName = strdup( theName );
915   myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
916   TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
917 }
918
919 char* LyingOnGeom_i::GetShapeName()
920 {
921   return CORBA::string_dup( myShapeName );
922 }
923
924 /*
925   Class       : FreeBorders_i
926   Description : Predicate for free borders
927 */
928 FreeBorders_i::FreeBorders_i()
929 {
930   myPredicatePtr.reset(new Controls::FreeBorders());
931   myFunctorPtr = myPredicatePtr;
932 }
933
934 FunctorType FreeBorders_i::GetFunctorType()
935 {
936   return SMESH::FT_FreeBorders;
937 }
938
939 /*
940   Class       : FreeEdges_i
941   Description : Predicate for free borders
942 */
943 FreeEdges_i::FreeEdges_i()
944 : myFreeEdgesPtr( new Controls::FreeEdges() )
945 {
946   myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
947 }
948
949 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
950 {
951   INFOS("FreeEdges_i::GetBorders");
952   SMESH::Controls::FreeEdges::TBorders aBorders;
953   myFreeEdgesPtr->GetBoreders( aBorders );
954   
955   long i = 0, iEnd = aBorders.size();
956
957   SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders(iEnd);
958
959   SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
960   for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
961   {
962     const SMESH::Controls::FreeEdges::Border&  aBord = *anIter;
963     SMESH::FreeEdges::Border &aBorder = aResult[ i ];
964     
965     aBorder.myElemId = aBord.myElemId;
966     aBorder.myPnt1 = aBord.myPntId[ 0 ];
967     aBorder.myPnt2 = aBord.myPntId[ 1 ];
968   }
969
970   INFOS("FreeEdges_i::GetBorders~");
971   return aResult._retn();
972 }
973
974 FunctorType FreeEdges_i::GetFunctorType()
975 {
976   return SMESH::FT_FreeEdges;
977 }
978
979 /*
980   Class       : RangeOfIds_i
981   Description : Predicate for Range of Ids.
982                 Range may be specified with two ways.
983                 1. Using AddToRange method
984                 2. With SetRangeStr method. Parameter of this method is a string
985                    like as "1,2,3,50-60,63,67,70-"
986 */
987
988 RangeOfIds_i::RangeOfIds_i()
989 {
990   myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
991   myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
992 }
993
994 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
995 {
996   CORBA::Long iEnd = theIds.length();
997   for ( CORBA::Long i = 0; i < iEnd; i++ )
998     myRangeOfIdsPtr->AddToRange( theIds[ i ] );
999   TPythonDump()<<this<<".SetRange("<<theIds<<")";
1000 }
1001
1002 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
1003 {
1004   TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
1005   return myRangeOfIdsPtr->SetRangeStr(
1006     TCollection_AsciiString( (Standard_CString)theRange ) );
1007 }
1008
1009 char* RangeOfIds_i::GetRangeStr()
1010 {
1011   TCollection_AsciiString aStr;
1012   myRangeOfIdsPtr->GetRangeStr( aStr );
1013   return CORBA::string_dup( aStr.ToCString() );
1014 }
1015
1016 void RangeOfIds_i::SetElementType( ElementType theType )
1017 {
1018   myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
1019   TPythonDump()<<this<<".SetElementType("<<theType<<")";
1020 }
1021
1022 FunctorType RangeOfIds_i::GetFunctorType()
1023 {
1024   return SMESH::FT_RangeOfIds;
1025 }
1026
1027 /*
1028   Class       : Comparator_i
1029   Description : Base class for comparators
1030 */
1031 Comparator_i::Comparator_i():
1032   myNumericalFunctor( NULL )
1033 {}
1034
1035 Comparator_i::~Comparator_i()
1036 {
1037   if ( myNumericalFunctor )
1038     myNumericalFunctor->Destroy();
1039 }
1040
1041 void Comparator_i::SetMargin( CORBA::Double theValue )
1042 {
1043   myComparatorPtr->SetMargin( theValue );
1044   TPythonDump()<<this<<".SetMargin("<<theValue<<")";
1045 }
1046
1047 CORBA::Double Comparator_i::GetMargin()
1048 {
1049   return myComparatorPtr->GetMargin();
1050 }
1051
1052 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
1053 {
1054   if ( myNumericalFunctor )
1055     myNumericalFunctor->Destroy();
1056
1057   myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
1058
1059   if ( myNumericalFunctor )
1060   {
1061     myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
1062     myNumericalFunctor->Register();
1063     TPythonDump()<<this<<".SetNumFunctor("<<myNumericalFunctor<<")";
1064   }
1065 }
1066
1067 Controls::ComparatorPtr Comparator_i::GetComparator()
1068 {
1069   return myComparatorPtr;
1070 }
1071
1072 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
1073 {
1074   return myNumericalFunctor;
1075 }
1076
1077
1078 /*
1079   Class       : LessThan_i
1080   Description : Comparator "<"
1081 */
1082 LessThan_i::LessThan_i()
1083 {
1084   myComparatorPtr.reset( new Controls::LessThan() );
1085   myFunctorPtr = myPredicatePtr = myComparatorPtr;
1086 }
1087
1088 FunctorType LessThan_i::GetFunctorType()
1089 {
1090   return SMESH::FT_LessThan;
1091 }
1092
1093
1094 /*
1095   Class       : MoreThan_i
1096   Description : Comparator ">"
1097 */
1098 MoreThan_i::MoreThan_i()
1099 {
1100   myComparatorPtr.reset( new Controls::MoreThan() );
1101   myFunctorPtr = myPredicatePtr = myComparatorPtr;
1102 }
1103
1104 FunctorType MoreThan_i::GetFunctorType()
1105 {
1106   return SMESH::FT_MoreThan;
1107 }
1108
1109
1110 /*
1111   Class       : EqualTo_i
1112   Description : Comparator "="
1113 */
1114 EqualTo_i::EqualTo_i()
1115 : myEqualToPtr( new Controls::EqualTo() )
1116 {
1117   myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
1118 }
1119
1120 void EqualTo_i::SetTolerance( CORBA::Double theToler )
1121 {
1122   myEqualToPtr->SetTolerance( theToler );
1123   TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1124 }
1125
1126 CORBA::Double EqualTo_i::GetTolerance()
1127 {
1128   return myEqualToPtr->GetTolerance();
1129 }
1130
1131 FunctorType EqualTo_i::GetFunctorType()
1132 {
1133   return SMESH::FT_EqualTo;
1134 }
1135
1136 /*
1137   Class       : LogicalNOT_i
1138   Description : Logical NOT predicate
1139 */
1140 LogicalNOT_i::LogicalNOT_i()
1141 : myPredicate( NULL ),
1142   myLogicalNOTPtr( new Controls::LogicalNOT() )
1143 {
1144   myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
1145 }
1146
1147 LogicalNOT_i::~LogicalNOT_i()
1148 {
1149   if ( myPredicate )
1150     myPredicate->Destroy();
1151 }
1152
1153 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
1154 {
1155   if ( myPredicate )
1156     myPredicate->Destroy();
1157
1158   myPredicate = SMESH::GetPredicate(thePredicate);
1159
1160   if ( myPredicate ){
1161     myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
1162     myPredicate->Register();
1163     TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1164   }
1165 }
1166
1167 FunctorType LogicalNOT_i::GetFunctorType()
1168 {
1169   return SMESH::FT_LogicalNOT;
1170 }
1171
1172 Predicate_i* LogicalNOT_i::GetPredicate_i()
1173 {
1174   return myPredicate;
1175 }
1176
1177
1178 /*
1179   Class       : LogicalBinary_i
1180   Description : Base class for binary logical predicate
1181 */
1182 LogicalBinary_i::LogicalBinary_i()
1183 : myPredicate1( NULL ),
1184   myPredicate2( NULL )
1185 {}
1186
1187 LogicalBinary_i::~LogicalBinary_i()
1188 {
1189   if ( myPredicate1 )
1190     myPredicate1->Destroy();
1191
1192   if ( myPredicate2 )
1193     myPredicate2->Destroy();
1194 }
1195
1196 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
1197 {
1198   if ( myPredicate1 )
1199     myPredicate1->SetMesh( theMesh );
1200
1201   if ( myPredicate2 )
1202     myPredicate2->SetMesh( theMesh );
1203 }
1204
1205 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
1206 {
1207   if ( myPredicate1 )
1208     myPredicate1->Destroy();
1209
1210   myPredicate1 = SMESH::GetPredicate(thePredicate);
1211
1212   if ( myPredicate1 ){
1213     myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
1214     myPredicate1->Register();
1215     TPythonDump()<<this<<".SetPredicate1("<<myPredicate1<<")";
1216   }
1217 }
1218
1219 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
1220 {
1221   if ( myPredicate2 )
1222     myPredicate2->Destroy();
1223
1224   myPredicate2 = SMESH::GetPredicate(thePredicate);
1225
1226   if ( myPredicate2 ){
1227     myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
1228     myPredicate2->Register();
1229     TPythonDump()<<this<<".SetPredicate2("<<myPredicate2<<")";
1230   }
1231 }
1232
1233 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
1234 {
1235   return myLogicalBinaryPtr;
1236 }
1237
1238 Predicate_i* LogicalBinary_i::GetPredicate1_i()
1239 {
1240   return myPredicate1;
1241 }
1242 Predicate_i* LogicalBinary_i::GetPredicate2_i()
1243 {
1244   return myPredicate2;
1245 }
1246
1247
1248 /*
1249   Class       : LogicalAND_i
1250   Description : Logical AND
1251 */
1252 LogicalAND_i::LogicalAND_i()
1253 {
1254   myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
1255   myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1256 }
1257
1258 FunctorType LogicalAND_i::GetFunctorType()
1259 {
1260   return SMESH::FT_LogicalAND;
1261 }
1262
1263
1264 /*
1265   Class       : LogicalOR_i
1266   Description : Logical OR
1267 */
1268 LogicalOR_i::LogicalOR_i()
1269 {
1270   myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
1271   myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1272 }
1273
1274 FunctorType LogicalOR_i::GetFunctorType()
1275 {
1276   return SMESH::FT_LogicalOR;
1277 }
1278
1279
1280 /*
1281                             FILTER MANAGER
1282 */
1283
1284 FilterManager_i::FilterManager_i()
1285 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
1286 {
1287   SMESH_Gen_i::GetPOA()->activate_object( this );
1288 }
1289
1290 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
1291 {
1292   SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
1293   SMESH::MinimumAngle_var anObj = aServant->_this();
1294   TPythonDump()<<aServant<<" = "<<this<<".CreateMinimumAngle()";
1295   return anObj._retn();
1296 }
1297
1298
1299 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
1300 {
1301   SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
1302   SMESH::AspectRatio_var anObj = aServant->_this();
1303   TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio()";
1304   return anObj._retn();
1305 }
1306
1307
1308 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
1309 {
1310   SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
1311   SMESH::AspectRatio3D_var anObj = aServant->_this();
1312   TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio3D()";
1313   return anObj._retn();
1314 }
1315
1316
1317 Warping_ptr FilterManager_i::CreateWarping()
1318 {
1319   SMESH::Warping_i* aServant = new SMESH::Warping_i();
1320   SMESH::Warping_var anObj = aServant->_this();
1321   TPythonDump()<<aServant<<" = "<<this<<".CreateWarping()";
1322   return anObj._retn();
1323 }
1324
1325
1326 Taper_ptr FilterManager_i::CreateTaper()
1327 {
1328   SMESH::Taper_i* aServant = new SMESH::Taper_i();
1329   SMESH::Taper_var anObj = aServant->_this();
1330   TPythonDump()<<aServant<<" = "<<this<<".CreateTaper()";
1331   return anObj._retn();
1332 }
1333
1334
1335 Skew_ptr FilterManager_i::CreateSkew()
1336 {
1337   SMESH::Skew_i* aServant = new SMESH::Skew_i();
1338   SMESH::Skew_var anObj = aServant->_this();
1339   TPythonDump()<<aServant<<" = "<<this<<".CreateSkew()";
1340   return anObj._retn();
1341 }
1342
1343
1344 Area_ptr FilterManager_i::CreateArea()
1345 {
1346   SMESH::Area_i* aServant = new SMESH::Area_i();
1347   SMESH::Area_var anObj = aServant->_this();
1348   TPythonDump()<<aServant<<" = "<<this<<".CreateArea()";
1349   return anObj._retn();
1350 }
1351
1352
1353 Length_ptr FilterManager_i::CreateLength()
1354 {
1355   SMESH::Length_i* aServant = new SMESH::Length_i();
1356   SMESH::Length_var anObj = aServant->_this();
1357   TPythonDump()<<aServant<<" = "<<this<<".CreateLength()";
1358   return anObj._retn();
1359 }
1360
1361 Length2D_ptr FilterManager_i::CreateLength2D()
1362 {
1363   SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
1364   SMESH::Length2D_var anObj = aServant->_this();
1365   TPythonDump()<<aServant<<" = "<<this<<".CreateLength2D()";
1366   return anObj._retn();
1367 }
1368
1369 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
1370 {
1371   SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
1372   SMESH::MultiConnection_var anObj = aServant->_this();
1373   TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection()";
1374   return anObj._retn();
1375 }
1376
1377 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
1378 {
1379   SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
1380   SMESH::MultiConnection2D_var anObj = aServant->_this();
1381   TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection2D()";
1382   return anObj._retn();
1383 }
1384
1385 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
1386 {
1387   SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
1388   SMESH::BelongToGeom_var anObj = aServant->_this();
1389   TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGeom()";
1390   return anObj._retn();
1391 }
1392
1393 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
1394 {
1395   SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
1396   SMESH::BelongToPlane_var anObj = aServant->_this();
1397   TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToPlane()";
1398   return anObj._retn();
1399 }
1400
1401 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
1402 {
1403   SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
1404   SMESH::BelongToCylinder_var anObj = aServant->_this();
1405   TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToCylinder()";
1406   return anObj._retn();
1407 }
1408
1409 LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom()
1410 {
1411   SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i();
1412   SMESH::LyingOnGeom_var anObj = aServant->_this();
1413   TPythonDump()<<aServant<<" = "<<this<<".CreateLyingOnGeom()";
1414   return anObj._retn();
1415 }
1416
1417 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
1418 {
1419   SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
1420   SMESH::FreeBorders_var anObj = aServant->_this();
1421   TPythonDump()<<aServant<<" = "<<this<<".CreateFreeBorders()";
1422   return anObj._retn();
1423 }
1424
1425 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
1426 {
1427   SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
1428   SMESH::FreeEdges_var anObj = aServant->_this();
1429   TPythonDump()<<aServant<<" = "<<this<<".CreateFreeEdges()";
1430   return anObj._retn();
1431 }
1432
1433 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
1434 {
1435   SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
1436   SMESH::RangeOfIds_var anObj = aServant->_this();
1437   TPythonDump()<<aServant<<" = "<<this<<".CreateRangeOfIds()";
1438   return anObj._retn();
1439 }
1440
1441 BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
1442 {
1443   SMESH::BadOrientedVolume_i* aServant = new SMESH::BadOrientedVolume_i();
1444   SMESH::BadOrientedVolume_var anObj = aServant->_this();
1445   TPythonDump()<<aServant<<" = "<<this<<".CreateBadOrientedVolume()";
1446   return anObj._retn();
1447 }
1448
1449 LessThan_ptr FilterManager_i::CreateLessThan()
1450 {
1451   SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
1452   SMESH::LessThan_var anObj = aServant->_this();
1453   TPythonDump()<<aServant<<" = "<<this<<".CreateLessThan()";
1454   return anObj._retn();
1455 }
1456
1457
1458 MoreThan_ptr FilterManager_i::CreateMoreThan()
1459 {
1460   SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
1461   SMESH::MoreThan_var anObj = aServant->_this();
1462   TPythonDump()<<aServant<<" = "<<this<<".CreateMoreThan()";
1463   return anObj._retn();
1464 }
1465
1466 EqualTo_ptr FilterManager_i::CreateEqualTo()
1467 {
1468   SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
1469   SMESH::EqualTo_var anObj = aServant->_this();
1470   TPythonDump()<<aServant<<" = "<<this<<".CreateEqualTo()";
1471   return anObj._retn();
1472 }
1473
1474
1475 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
1476 {
1477   SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
1478   SMESH::LogicalNOT_var anObj = aServant->_this();
1479   TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalNOT()";
1480   return anObj._retn();
1481 }
1482
1483
1484 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
1485 {
1486   SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
1487   SMESH::LogicalAND_var anObj = aServant->_this();
1488   TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalAND()";
1489   return anObj._retn();
1490 }
1491
1492
1493 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
1494 {
1495   SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
1496   SMESH::LogicalOR_var anObj = aServant->_this();
1497   TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalOR()";
1498   return anObj._retn();
1499 }
1500
1501 Filter_ptr FilterManager_i::CreateFilter()
1502 {
1503   SMESH::Filter_i* aServant = new SMESH::Filter_i();
1504   SMESH::Filter_var anObj = aServant->_this();
1505   TPythonDump()<<aServant<<" = "<<this<<".CreateFilter()";
1506   return anObj._retn();
1507 }
1508
1509 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
1510 {
1511   SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
1512   SMESH::FilterLibrary_var anObj = aServant->_this();
1513   TPythonDump()<<aServant<<" = "<<this<<".LoadLibrary("<<aFileName<<")";
1514   return anObj._retn();
1515 }
1516
1517 FilterLibrary_ptr FilterManager_i::CreateLibrary()
1518 {
1519   SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
1520   SMESH::FilterLibrary_var anObj = aServant->_this();
1521   TPythonDump()<<aServant<<" = "<<this<<".CreateLibrary()";
1522   return anObj._retn();
1523 }
1524
1525 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
1526 {
1527   TPythonDump()<<this<<".DeleteLibrary("<<aFileName<<")";
1528   return remove( aFileName ) ? false : true;
1529 }
1530
1531 //=============================================================================
1532 /*!
1533  *  SMESH_Gen_i::CreateFilterManager
1534  *
1535  *  Create filter manager
1536  */
1537 //=============================================================================
1538
1539 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
1540 {
1541   SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
1542   SMESH::FilterManager_var anObj = aFilter->_this();
1543   TPythonDump()<<aFilter<<" = smesh.CreateFilterManager()";
1544   return anObj._retn();
1545 }
1546
1547
1548 /*
1549                               FILTER
1550 */
1551
1552 //=======================================================================
1553 // name    : Filter_i::Filter_i
1554 // Purpose : Constructor
1555 //=======================================================================
1556 Filter_i::Filter_i()
1557 : myPredicate( NULL )
1558 {}
1559
1560 //=======================================================================
1561 // name    : Filter_i::~Filter_i
1562 // Purpose : Destructor
1563 //=======================================================================
1564 Filter_i::~Filter_i()
1565 {
1566   if ( myPredicate )
1567     myPredicate->Destroy();
1568 }
1569
1570 //=======================================================================
1571 // name    : Filter_i::SetPredicate
1572 // Purpose : Set predicate
1573 //=======================================================================
1574 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
1575 {
1576   if ( myPredicate )
1577     myPredicate->Destroy();
1578
1579   myPredicate = SMESH::GetPredicate(thePredicate);
1580
1581   if ( myPredicate )
1582   {
1583     myFilter.SetPredicate( myPredicate->GetPredicate() );
1584     myPredicate->Register();
1585     TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1586   }
1587 }
1588
1589 //=======================================================================
1590 // name    : Filter_i::GetElementType
1591 // Purpose : Get entity type
1592 //=======================================================================
1593 SMESH::ElementType Filter_i::GetElementType()
1594 {
1595   return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
1596 }
1597
1598 //=======================================================================
1599 // name    : Filter_i::SetMesh
1600 // Purpose : Set mesh
1601 //=======================================================================
1602 void Filter_i::SetMesh( SMESH_Mesh_ptr theMesh )
1603 {
1604   if(myPredicate){
1605     myPredicate->SetMesh( theMesh );
1606     TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
1607   }
1608 }
1609
1610 //=======================================================================
1611 // name    : Filter_i::GetElementsId
1612 // Purpose : Get ids of entities
1613 //=======================================================================
1614 void
1615 Filter_i::
1616 GetElementsId( Predicate_i* thePredicate,
1617                const SMDS_Mesh* theMesh,
1618                Controls::Filter::TIdSequence& theSequence )
1619 {
1620   Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence);
1621 }
1622
1623 void
1624 Filter_i::
1625 GetElementsId( Predicate_i* thePredicate,
1626                SMESH_Mesh_ptr theMesh,
1627                Controls::Filter::TIdSequence& theSequence )
1628 {
1629   if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
1630     Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence);
1631 }
1632
1633 SMESH::long_array* 
1634 Filter_i::
1635 GetElementsId( SMESH_Mesh_ptr theMesh )
1636 {
1637   Controls::Filter::TIdSequence aSequence;
1638   GetElementsId(myPredicate,theMesh,aSequence);
1639
1640   SMESH::long_array_var anArray = new SMESH::long_array;
1641   long i = 0, iEnd = aSequence.size();
1642
1643   anArray->length( iEnd );
1644   for ( ; i < iEnd; i++ )
1645     anArray[ i ] = aSequence[i];
1646
1647   return anArray._retn();
1648 }
1649
1650 //=======================================================================
1651 // name    : getCriteria
1652 // Purpose : Retrieve criterions from predicate
1653 //=======================================================================
1654 static inline bool getCriteria( Predicate_i*                thePred,
1655                                 SMESH::Filter::Criteria_out theCriteria )
1656 {
1657   int aFType = thePred->GetFunctorType();
1658
1659   switch ( aFType )
1660   {
1661   case FT_FreeBorders:
1662   case FT_FreeEdges:
1663     {
1664       CORBA::ULong i = theCriteria->length();
1665       theCriteria->length( i + 1 );
1666
1667       theCriteria[ i ] = createCriterion();
1668
1669       theCriteria[ i ].Type = aFType;
1670       theCriteria[ i ].TypeOfElement = thePred->GetElementType();
1671       return true;
1672     }
1673   case FT_BelongToGeom:
1674     {
1675       BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
1676
1677       CORBA::ULong i = theCriteria->length();
1678       theCriteria->length( i + 1 );
1679
1680       theCriteria[ i ] = createCriterion();
1681
1682       theCriteria[ i ].Type          = FT_BelongToGeom;
1683       theCriteria[ i ].ThresholdStr  = aPred->GetShapeName();
1684       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1685
1686       return true;
1687     }
1688   case FT_BelongToPlane:
1689   case FT_BelongToCylinder:
1690     {
1691       BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
1692
1693       CORBA::ULong i = theCriteria->length();
1694       theCriteria->length( i + 1 );
1695
1696       theCriteria[ i ] = createCriterion();
1697
1698       theCriteria[ i ].Type          = aFType;
1699       theCriteria[ i ].ThresholdStr  = aPred->GetShapeName();
1700       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1701       theCriteria[ i ].Tolerance     = aPred->GetTolerance();
1702
1703       return true;
1704     }
1705    case FT_LyingOnGeom:
1706     {
1707       LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
1708
1709       CORBA::ULong i = theCriteria->length();
1710       theCriteria->length( i + 1 );
1711
1712       theCriteria[ i ] = createCriterion();
1713
1714       theCriteria[ i ].Type          = FT_LyingOnGeom;
1715       theCriteria[ i ].ThresholdStr  = aPred->GetShapeName();
1716       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1717
1718       return true;
1719     }
1720   case FT_RangeOfIds:
1721     {
1722       RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
1723
1724       CORBA::ULong i = theCriteria->length();
1725       theCriteria->length( i + 1 );
1726
1727       theCriteria[ i ] = createCriterion();
1728
1729       theCriteria[ i ].Type          = FT_RangeOfIds;
1730       theCriteria[ i ].ThresholdStr  = aPred->GetRangeStr();
1731       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1732
1733       return true;
1734     }
1735   case FT_BadOrientedVolume:
1736     {
1737       BadOrientedVolume_i* aPred = dynamic_cast<BadOrientedVolume_i*>( thePred );
1738
1739       CORBA::ULong i = theCriteria->length();
1740       theCriteria->length( i + 1 );
1741
1742       theCriteria[ i ] = createCriterion();
1743
1744       theCriteria[ i ].Type          = FT_BadOrientedVolume;
1745       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1746
1747       return true;
1748     }
1749   case FT_LessThan:
1750   case FT_MoreThan:
1751   case FT_EqualTo:
1752     {
1753       Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
1754
1755       CORBA::ULong i = theCriteria->length();
1756       theCriteria->length( i + 1 );
1757
1758       theCriteria[ i ] = createCriterion();
1759
1760       theCriteria[ i ].Type      = aCompar->GetNumFunctor_i()->GetFunctorType();
1761       theCriteria[ i ].Compare   = aFType;
1762       theCriteria[ i ].Threshold = aCompar->GetMargin();
1763       theCriteria[ i ].TypeOfElement = aCompar->GetElementType();
1764
1765       if ( aFType == FT_EqualTo )
1766       {
1767         EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
1768         theCriteria[ i ].Tolerance = aCompar->GetTolerance();
1769       }
1770     }
1771     return true;
1772
1773   case FT_LogicalNOT:
1774     {
1775       Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
1776       getCriteria( aPred, theCriteria );
1777       theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
1778     }
1779     return true;
1780
1781   case FT_LogicalAND:
1782   case FT_LogicalOR:
1783     {
1784       Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
1785       Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
1786       if ( !getCriteria( aPred1, theCriteria ) )
1787         return false;
1788       theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
1789       return getCriteria( aPred2, theCriteria );
1790     }
1791
1792   case FT_Undefined:
1793     return false;
1794   default:
1795     return false;
1796   }
1797 }
1798
1799 //=======================================================================
1800 // name    : Filter_i::GetCriteria
1801 // Purpose : Retrieve criterions from predicate
1802 //=======================================================================
1803 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
1804 {
1805   theCriteria = new SMESH::Filter::Criteria;
1806   return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
1807 }
1808
1809 //=======================================================================
1810 // name    : Filter_i::SetCriteria
1811 // Purpose : Create new predicate and set criterions in it
1812 //=======================================================================
1813 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
1814 {
1815   if ( myPredicate != 0 )
1816     myPredicate->Destroy();
1817
1818     SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
1819     FilterManager_ptr aFilterMgr = aFilter->_this();
1820
1821   // CREATE two lists ( PREDICATES  and LOG OP )
1822
1823   // Criterion
1824   std::list<SMESH::Predicate_ptr> aPredicates;
1825   std::list<int>                  aBinaries;
1826   for ( int i = 0, n = theCriteria.length(); i < n; i++ )
1827   {
1828     int         aCriterion    = theCriteria[ i ].Type;
1829     int         aCompare      = theCriteria[ i ].Compare;
1830     double      aThreshold    = theCriteria[ i ].Threshold;
1831     int         aUnary        = theCriteria[ i ].UnaryOp;
1832     int         aBinary       = theCriteria[ i ].BinaryOp;
1833     double      aTolerance    = theCriteria[ i ].Tolerance;
1834     const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
1835     ElementType aTypeOfElem   = theCriteria[ i ].TypeOfElement;
1836     long        aPrecision    = theCriteria[ i ].Precision;
1837
1838     TPythonDump()<<this<<".SetCriteria(SMESH.Filter.Criteria("<<
1839       aCriterion<<","<<aCompare<<","<<aThreshold<<","<<aUnary<<","<<aBinary<<","<<
1840       aTolerance<<",'"<<aThresholdStr<<"',"<<aTypeOfElem<<","<<aPrecision<<")";
1841     
1842     SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
1843     SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
1844
1845     switch ( aCriterion )
1846     {
1847       // Functors
1848       
1849       case SMESH::FT_MultiConnection:
1850         aFunctor = aFilterMgr->CreateMultiConnection();
1851         break;
1852       case SMESH::FT_MultiConnection2D:
1853         aFunctor = aFilterMgr->CreateMultiConnection2D();
1854         break;
1855       case SMESH::FT_Length:
1856         aFunctor = aFilterMgr->CreateLength();
1857         break;
1858       case SMESH::FT_Length2D:
1859         aFunctor = aFilterMgr->CreateLength2D();
1860         break;
1861       case SMESH::FT_AspectRatio:
1862         aFunctor = aFilterMgr->CreateAspectRatio();
1863         break;
1864       case SMESH::FT_AspectRatio3D:
1865         aFunctor = aFilterMgr->CreateAspectRatio3D();
1866         break;
1867       case SMESH::FT_Warping:
1868         aFunctor = aFilterMgr->CreateWarping();
1869         break;
1870       case SMESH::FT_MinimumAngle:
1871         aFunctor = aFilterMgr->CreateMinimumAngle();
1872         break;
1873       case SMESH::FT_Taper:
1874         aFunctor = aFilterMgr->CreateTaper();
1875         break;
1876       case SMESH::FT_Skew:
1877         aFunctor = aFilterMgr->CreateSkew();
1878         break;
1879       case SMESH::FT_Area:
1880         aFunctor = aFilterMgr->CreateArea();
1881         break;
1882
1883       // Predicates
1884
1885       case SMESH::FT_FreeBorders:
1886         aPredicate = aFilterMgr->CreateFreeBorders();
1887         break;
1888       case SMESH::FT_FreeEdges:
1889         aPredicate = aFilterMgr->CreateFreeEdges();
1890         break;
1891       case SMESH::FT_BelongToGeom:
1892         {
1893           SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
1894           tmpPred->SetElementType( aTypeOfElem );
1895           tmpPred->SetShapeName( aThresholdStr );
1896           aPredicate = tmpPred;
1897         }
1898         break;
1899       case SMESH::FT_BelongToPlane:
1900       case SMESH::FT_BelongToCylinder:
1901         {
1902           SMESH::BelongToSurface_ptr tmpPred;
1903           if ( aCriterion == SMESH::FT_BelongToPlane )
1904             tmpPred = aFilterMgr->CreateBelongToPlane();
1905           else
1906             tmpPred = aFilterMgr->CreateBelongToCylinder();
1907           tmpPred->SetShapeName( aThresholdStr, aTypeOfElem );
1908           tmpPred->SetTolerance( aTolerance );
1909           aPredicate = tmpPred;
1910         }
1911         break;
1912       case SMESH::FT_LyingOnGeom:
1913         {
1914           SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
1915           tmpPred->SetElementType( aTypeOfElem );
1916           tmpPred->SetShapeName( aThresholdStr );
1917           aPredicate = tmpPred;
1918         }
1919         break; 
1920       case SMESH::FT_RangeOfIds:
1921         {
1922           SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
1923           tmpPred->SetRangeStr( aThresholdStr );
1924           tmpPred->SetElementType( aTypeOfElem );
1925           aPredicate = tmpPred;
1926         }
1927         break;
1928       case SMESH::FT_BadOrientedVolume:
1929         {
1930           aPredicate = aFilterMgr->CreateBadOrientedVolume();
1931         }
1932         break;
1933               
1934       default:
1935         continue;
1936     }
1937
1938     // Comparator
1939     if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
1940     {
1941       SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
1942
1943       if ( aCompare == SMESH::FT_LessThan )
1944         aComparator = aFilterMgr->CreateLessThan();
1945       else if ( aCompare == SMESH::FT_MoreThan )
1946         aComparator = aFilterMgr->CreateMoreThan();
1947       else if ( aCompare == SMESH::FT_EqualTo )
1948         aComparator = aFilterMgr->CreateEqualTo();
1949       else
1950         continue;
1951
1952       aComparator->SetNumFunctor( aFunctor );
1953       aComparator->SetMargin( aThreshold );
1954
1955       if ( aCompare == FT_EqualTo )
1956       {
1957         SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
1958         anEqualTo->SetTolerance( aTolerance );
1959       }
1960
1961       aPredicate = aComparator;
1962
1963       aFunctor->SetPrecision( aPrecision );
1964     }
1965
1966     // Logical not
1967     if ( aUnary == FT_LogicalNOT )
1968     {
1969       SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
1970       aNotPred->SetPredicate( aPredicate );
1971       aPredicate = aNotPred;
1972     }
1973
1974     // logical op
1975     aPredicates.push_back( aPredicate );
1976     aBinaries.push_back( aBinary );
1977
1978   } // end of for
1979
1980   // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
1981
1982   // combine all "AND" operations
1983
1984   std::list<SMESH::Predicate_ptr> aResList;
1985
1986   std::list<SMESH::Predicate_ptr>::iterator aPredIter;
1987   std::list<int>::iterator                  aBinaryIter;
1988
1989   SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
1990   int aPrevBinary = SMESH::FT_Undefined;
1991
1992   for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
1993         aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
1994         ++aPredIter, ++aBinaryIter )
1995   {
1996     int aCurrBinary = *aBinaryIter;
1997
1998     SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
1999
2000     if ( aPrevBinary == SMESH::FT_LogicalAND )
2001     {
2002
2003       SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
2004       aBinaryPred->SetPredicate1( aPrevPredicate );
2005       aBinaryPred->SetPredicate2( *aPredIter );
2006       aCurrPred = aBinaryPred;
2007     }
2008     else
2009       aCurrPred = *aPredIter;
2010
2011     if ( aCurrBinary != SMESH::FT_LogicalAND )
2012       aResList.push_back( aCurrPred );
2013
2014     aPrevPredicate = aCurrPred;
2015     aPrevBinary = aCurrBinary;
2016   }
2017
2018   // combine all "OR" operations
2019
2020   SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
2021
2022   if ( aResList.size() == 1 )
2023     aResPredicate = *aResList.begin();
2024   else if ( aResList.size() > 1 )
2025   {
2026     std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
2027     aResPredicate = *anIter;
2028     anIter++;
2029     for ( ; anIter != aResList.end(); ++anIter )
2030     {
2031       SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
2032       aBinaryPred->SetPredicate1( aResPredicate );
2033       aBinaryPred->SetPredicate2( *anIter );
2034       aResPredicate = aBinaryPred;
2035     }
2036   }
2037
2038   SetPredicate( aResPredicate );
2039
2040   return !aResPredicate->_is_nil();
2041 }
2042
2043 //=======================================================================
2044 // name    : Filter_i::GetPredicate_i
2045 // Purpose : Get implementation of predicate
2046 //=======================================================================
2047 Predicate_i* Filter_i::GetPredicate_i()
2048 {
2049   return myPredicate;
2050 }
2051
2052 //=======================================================================
2053 // name    : Filter_i::GetPredicate
2054 // Purpose : Get predicate
2055 //=======================================================================
2056 Predicate_ptr Filter_i::GetPredicate()
2057 {
2058   if ( myPredicate == 0 )
2059     return SMESH::Predicate::_nil();
2060   else
2061   {
2062     SMESH::Predicate_var anObj = myPredicate->_this();
2063     return anObj._retn();
2064   }
2065 }
2066
2067 /*
2068                             FILTER LIBRARY
2069 */
2070
2071 #define ATTR_TYPE          "type"
2072 #define ATTR_COMPARE       "compare"
2073 #define ATTR_THRESHOLD     "threshold"
2074 #define ATTR_UNARY         "unary"
2075 #define ATTR_BINARY        "binary"
2076 #define ATTR_THRESHOLD_STR "threshold_str"
2077 #define ATTR_TOLERANCE     "tolerance"
2078 #define ATTR_ELEMENT_TYPE  "ElementType"
2079
2080 //=======================================================================
2081 // name    : toString
2082 // Purpose : Convert bool to LDOMString
2083 //=======================================================================
2084 static inline LDOMString toString( const bool val )
2085 {
2086   return val ? "logical not" : "";
2087 }
2088
2089 //=======================================================================
2090 // name    : toBool
2091 // Purpose : Convert LDOMString to bool
2092 //=======================================================================
2093 static inline bool toBool( const LDOMString& theStr )
2094 {
2095   return theStr.equals( "logical not" );
2096 }
2097
2098 //=======================================================================
2099 // name    : toString
2100 // Purpose : Convert double to LDOMString
2101 //=======================================================================
2102 static inline LDOMString toString( const double val )
2103 {
2104   char a[ 255 ];
2105   sprintf( a, "%e", val );
2106   return LDOMString( a );
2107 }
2108
2109 //=======================================================================
2110 // name    : toDouble
2111 // Purpose : Convert LDOMString to double
2112 //=======================================================================
2113 static inline double toDouble( const LDOMString& theStr )
2114 {
2115   return atof( theStr.GetString() );
2116 }
2117
2118 //=======================================================================
2119 // name    : toString
2120 // Purpose : Convert functor type to LDOMString
2121 //=======================================================================
2122 static inline LDOMString toString( const long theType )
2123 {
2124   switch ( theType )
2125   {
2126     case FT_AspectRatio     : return "Aspect ratio";
2127     case FT_Warping         : return "Warping";
2128     case FT_MinimumAngle    : return "Minimum angle";
2129     case FT_Taper           : return "Taper";
2130     case FT_Skew            : return "Skew";
2131     case FT_Area            : return "Area";
2132     case FT_BelongToGeom    : return "Belong to Geom";
2133     case FT_BelongToPlane   : return "Belong to Plane";
2134     case FT_BelongToCylinder: return "Belong to Cylinder";
2135     case FT_LyingOnGeom     : return "Lying on Geom";
2136     case FT_BadOrientedVolume: return "Bad Oriented Volume";
2137     case FT_RangeOfIds      : return "Range of IDs";
2138     case FT_FreeBorders     : return "Free borders";
2139     case FT_FreeEdges       : return "Free edges";
2140     case FT_MultiConnection : return "Borders at multi-connections";
2141     case FT_MultiConnection2D: return "Borders at multi-connections 2D";
2142     case FT_Length          : return "Length";
2143     case FT_Length2D        : return "Length2D";
2144     case FT_LessThan        : return "Less than";
2145     case FT_MoreThan        : return "More than";
2146     case FT_EqualTo         : return "Equal to";
2147     case FT_LogicalNOT      : return "Not";
2148     case FT_LogicalAND      : return "And";
2149     case FT_LogicalOR       : return "Or";
2150     case FT_Undefined       : return "";
2151     default                 : return "";
2152   }
2153 }
2154
2155 //=======================================================================
2156 // name    : toFunctorType
2157 // Purpose : Convert LDOMString to functor type
2158 //=======================================================================
2159 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
2160 {
2161   if      ( theStr.equals( "Aspect ratio"                 ) ) return FT_AspectRatio;
2162   else if ( theStr.equals( "Warping"                      ) ) return FT_Warping;
2163   else if ( theStr.equals( "Minimum angle"                ) ) return FT_MinimumAngle;
2164   else if ( theStr.equals( "Taper"                        ) ) return FT_Taper;
2165   else if ( theStr.equals( "Skew"                         ) ) return FT_Skew;
2166   else if ( theStr.equals( "Area"                         ) ) return FT_Area;
2167   else if ( theStr.equals( "Belong to Geom"               ) ) return FT_BelongToGeom;
2168   else if ( theStr.equals( "Belong to Plane"              ) ) return FT_BelongToPlane;
2169   else if ( theStr.equals( "Belong to Cylinder"           ) ) return FT_BelongToCylinder;
2170   else if ( theStr.equals( "Lying on Geom"                ) ) return FT_LyingOnGeom;
2171   else if ( theStr.equals( "Free borders"                 ) ) return FT_FreeBorders;
2172   else if ( theStr.equals( "Free edges"                   ) ) return FT_FreeEdges;
2173   else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
2174   //  else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
2175   else if ( theStr.equals( "Length"                       ) ) return FT_Length;
2176   //  else if ( theStr.equals( "Length2D"                     ) ) return FT_Length2D;
2177   else if ( theStr.equals( "Range of IDs"                 ) ) return FT_RangeOfIds;
2178   else if ( theStr.equals( "Bad Oriented Volume"          ) ) return FT_BadOrientedVolume;
2179   else if ( theStr.equals( "Less than"                    ) ) return FT_LessThan;
2180   else if ( theStr.equals( "More than"                    ) ) return FT_MoreThan;
2181   else if ( theStr.equals( "Equal to"                     ) ) return FT_EqualTo;
2182   else if ( theStr.equals( "Not"                          ) ) return FT_LogicalNOT;
2183   else if ( theStr.equals( "And"                          ) ) return FT_LogicalAND;
2184   else if ( theStr.equals( "Or"                           ) ) return FT_LogicalOR;
2185   else if ( theStr.equals( ""                             ) ) return FT_Undefined;
2186   else  return FT_Undefined;
2187 }
2188
2189 //=======================================================================
2190 // name    : toFunctorType
2191 // Purpose : Convert LDOMString to value of ElementType enumeration
2192 //=======================================================================
2193 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
2194 {
2195   if      ( theStr.equals( "NODE"   ) ) return SMESH::NODE;
2196   else if ( theStr.equals( "EDGE"   ) ) return SMESH::EDGE;
2197   else if ( theStr.equals( "FACE"   ) ) return SMESH::FACE;
2198   else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
2199   else                                  return SMESH::ALL;
2200 }
2201
2202 //=======================================================================
2203 // name    : toString
2204 // Purpose : Convert ElementType to string
2205 //=======================================================================
2206 static inline LDOMString toString( const SMESH::ElementType theType )
2207 {
2208   switch ( theType )
2209   {
2210     case SMESH::NODE   : return "NODE";
2211     case SMESH::EDGE   : return "EDGE";
2212     case SMESH::FACE   : return "FACE";
2213     case SMESH::VOLUME : return "VOLUME";
2214     case SMESH::ALL    : return "ALL";
2215     default            : return "";
2216   }
2217 }
2218
2219 //=======================================================================
2220 // name    : findFilter
2221 // Purpose : Find filter in document
2222 //=======================================================================
2223 static LDOM_Element findFilter( const char* theFilterName,
2224                                 const LDOM_Document& theDoc,
2225                                 LDOM_Node* theParent = 0 )
2226 {
2227   LDOM_Element aRootElement = theDoc.getDocumentElement();
2228   if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
2229     return LDOM_Element();
2230
2231   for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
2232         !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
2233   {
2234     for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
2235           !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2236     {
2237       LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
2238       if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
2239            anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
2240       {
2241         if ( theParent != 0  )
2242           *theParent = aTypeNode;
2243         return (LDOM_Element&)aFilter;
2244       }
2245     }
2246   }
2247   return LDOM_Element();
2248 }
2249
2250 //=======================================================================
2251 // name    : getSectionName
2252 // Purpose : Get name of section of filters
2253 //=======================================================================
2254 static const char* getSectionName( const ElementType theType )
2255 {
2256   switch ( theType )
2257   {
2258     case SMESH::NODE   : return "Filters for nodes";
2259     case SMESH::EDGE   : return "Filters for edges";
2260     case SMESH::FACE   : return "Filters for faces";
2261     case SMESH::VOLUME : return "Filters for volumes";
2262     case SMESH::ALL    : return "Filters for elements";
2263     default            : return "";
2264   }
2265 }
2266
2267 //=======================================================================
2268 // name    : getSection
2269 // Purpose : Create section for filters corresponding to the entity type
2270 //=======================================================================
2271 static LDOM_Node getSection( const ElementType theType,
2272                              LDOM_Document&    theDoc,
2273                              const bool        toCreate = false )
2274 {
2275   LDOM_Element aRootElement = theDoc.getDocumentElement();
2276   if ( aRootElement.isNull() )
2277     return LDOM_Node();
2278
2279   // Find section
2280   bool anExist = false;
2281   const char* aSectionName = getSectionName( theType );
2282   if ( strcmp( aSectionName, "" ) == 0 )
2283     return LDOM_Node();
2284   
2285   LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
2286   LDOM_Node aNode;
2287   for ( int i = 0, n = aSections.getLength(); i < n; i++ )
2288   {
2289     aNode = aSections.item( i );
2290     LDOM_Element& anItem = ( LDOM_Element& )aNode;
2291     if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
2292     {
2293       anExist = true;
2294       break;
2295     }
2296   }
2297
2298   // Create new section if necessary
2299   if ( !anExist )
2300   {
2301     if ( toCreate )
2302     {
2303       LDOM_Element aNewItem = theDoc.createElement( "section" );
2304       aNewItem.setAttribute( "name", aSectionName );
2305       aRootElement.appendChild( aNewItem );
2306       return aNewItem;
2307     }
2308     else
2309       return LDOM_Node();
2310   }
2311   return
2312     aNode;
2313 }
2314
2315 //=======================================================================
2316 // name    : createFilterItem
2317 // Purpose : Create filter item or LDOM document
2318 //=======================================================================
2319 static LDOM_Element createFilterItem( const char*       theName,
2320                                       SMESH::Filter_ptr theFilter,
2321                                       LDOM_Document&    theDoc )
2322 {
2323   // create new filter in document
2324   LDOM_Element aFilterItem = theDoc.createElement( "filter" );
2325   aFilterItem.setAttribute( "name", theName );
2326
2327   // save filter criterions
2328   SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2329
2330   if ( !theFilter->GetCriteria( aCriteria ) )
2331     return LDOM_Element();
2332
2333   for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
2334   {
2335     LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
2336
2337     aCriterionItem.setAttribute( ATTR_TYPE         , toString( aCriteria[ i ].Type      ) );
2338     aCriterionItem.setAttribute( ATTR_COMPARE      , toString( aCriteria[ i ].Compare   ) );
2339     aCriterionItem.setAttribute( ATTR_THRESHOLD    , toString( aCriteria[ i ].Threshold ) );
2340     aCriterionItem.setAttribute( ATTR_UNARY        , toString( aCriteria[ i ].UnaryOp   ) );
2341     aCriterionItem.setAttribute( ATTR_BINARY       , toString( aCriteria[ i ].BinaryOp  ) );
2342     
2343     aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
2344     aCriterionItem.setAttribute( ATTR_TOLERANCE    , toString( aCriteria[ i ].Tolerance ) );
2345     aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
2346       toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
2347
2348     aFilterItem.appendChild( aCriterionItem );
2349   }
2350
2351   return aFilterItem;
2352 }
2353
2354 //=======================================================================
2355 // name    : FilterLibrary_i::FilterLibrary_i
2356 // Purpose : Constructor
2357 //=======================================================================
2358 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
2359 {
2360   myFileName = strdup( theFileName );
2361   SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
2362   myFilterMgr = aFilterMgr->_this();
2363
2364   LDOMParser aParser;
2365
2366   // Try to use existing library file
2367   bool anExists = false;
2368   if ( !aParser.parse( myFileName ) )
2369   {
2370     myDoc = aParser.getDocument();
2371     anExists = true;
2372   }
2373   // Create a new XML document if it doesn't exist
2374   else
2375     myDoc = LDOM_Document::createDocument( LDOMString() );
2376
2377   LDOM_Element aRootElement = myDoc.getDocumentElement();
2378   if ( aRootElement.isNull() )
2379   {
2380     // If the existing document is empty --> try to create a new one
2381     if ( anExists )
2382       myDoc = LDOM_Document::createDocument( LDOMString() );
2383   }
2384 }
2385
2386 //=======================================================================
2387 // name    : FilterLibrary_i::FilterLibrary_i
2388 // Purpose : Constructor
2389 //=======================================================================
2390 FilterLibrary_i::FilterLibrary_i()
2391 {
2392   myFileName = 0;
2393   SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2394   myFilterMgr = aFilter->_this();
2395
2396   myDoc = LDOM_Document::createDocument( LDOMString() );
2397 }
2398
2399 FilterLibrary_i::~FilterLibrary_i()
2400 {
2401   delete myFileName;
2402 }
2403
2404 //=======================================================================
2405 // name    : FilterLibrary_i::Copy
2406 // Purpose : Create filter and initialize it with values from library
2407 //=======================================================================
2408 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
2409 {
2410   Filter_ptr aRes;
2411   LDOM_Node aFilter = findFilter( theFilterName, myDoc );
2412
2413   if ( aFilter.isNull() )
2414     return aRes;
2415
2416   std::list<SMESH::Filter::Criterion> aCriteria;
2417     
2418   for ( LDOM_Node aCritNode = aFilter.getFirstChild();
2419         !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
2420   {
2421     LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
2422
2423     const char* aTypeStr      = aCrit->getAttribute( ATTR_TYPE          ).GetString();
2424     const char* aCompareStr   = aCrit->getAttribute( ATTR_COMPARE       ).GetString();
2425     const char* aUnaryStr     = aCrit->getAttribute( ATTR_UNARY         ).GetString();
2426     const char* aBinaryStr    = aCrit->getAttribute( ATTR_BINARY        ).GetString();
2427     const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE  ).GetString();
2428     
2429     SMESH::Filter::Criterion aCriterion = createCriterion();
2430
2431     aCriterion.Type          = toFunctorType( aTypeStr );
2432     aCriterion.Compare       = toFunctorType( aCompareStr );
2433     aCriterion.UnaryOp       = toFunctorType( aUnaryStr );
2434     aCriterion.BinaryOp      = toFunctorType( aBinaryStr );
2435     
2436     aCriterion.TypeOfElement = toElementType( anElemTypeStr );
2437
2438     LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
2439     int val = 0;
2440     aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
2441       ? val : atof( str.GetString() );
2442
2443     str = aCrit->getAttribute( ATTR_TOLERANCE );
2444     aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
2445       ? val : atof( str.GetString() );
2446
2447     str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
2448     if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
2449     {
2450       char a[ 255 ];
2451       sprintf( a, "%d", val );
2452       aCriterion.ThresholdStr = strdup( a );
2453     }
2454     else
2455       aCriterion.ThresholdStr = str.GetString();
2456
2457     aCriteria.push_back( aCriterion );
2458   }
2459
2460   SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
2461   aCriteriaVar->length( aCriteria.size() );
2462   
2463   CORBA::ULong i = 0;
2464   std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
2465   
2466   for( ; anIter != aCriteria.end(); ++anIter )
2467     aCriteriaVar[ i++ ] = *anIter;
2468
2469   aRes = myFilterMgr->CreateFilter();
2470   aRes->SetCriteria( aCriteriaVar.inout() );
2471   
2472   TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
2473   
2474   return aRes;
2475 }
2476
2477 //=======================================================================
2478 // name    : FilterLibrary_i::SetFileName
2479 // Purpose : Set file name for library
2480 //=======================================================================
2481 void FilterLibrary_i::SetFileName( const char* theFileName )
2482 {
2483   delete myFileName;
2484   myFileName = strdup( theFileName );
2485   TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
2486 }
2487
2488 //=======================================================================
2489 // name    : FilterLibrary_i::GetFileName
2490 // Purpose : Get file name of library
2491 //=======================================================================
2492 char* FilterLibrary_i::GetFileName()
2493 {
2494   return CORBA::string_dup( myFileName );
2495 }
2496
2497 //=======================================================================
2498 // name    : FilterLibrary_i::Add
2499 // Purpose : Add new filter to library
2500 //=======================================================================
2501 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
2502 {
2503   // if filter already in library or entry filter is null do nothing
2504   LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
2505   if ( !aFilterNode.isNull() || theFilter->_is_nil() )
2506     return false;
2507
2508   // get section corresponding to the filter type
2509   ElementType anEntType = theFilter->GetElementType();
2510
2511   LDOM_Node aSection = getSection( anEntType, myDoc, true );
2512   if ( aSection.isNull() )
2513     return false;
2514
2515   // create filter item
2516   LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
2517   if ( aFilterItem.isNull() )
2518     return false;
2519   else
2520   {
2521     aSection.appendChild( aFilterItem );
2522     if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
2523       TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
2524     return true;
2525   }
2526 }
2527
2528 //=======================================================================
2529 // name    : FilterLibrary_i::Add
2530 // Purpose : Add new filter to library
2531 //=======================================================================
2532 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
2533 {
2534   // if filter already in library or entry filter is null do nothing
2535   LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
2536   if ( !aFilterNode.isNull() )
2537     return false;
2538
2539   LDOM_Node aSection = getSection( theType, myDoc, true );
2540   if ( aSection.isNull() )
2541     return false;
2542
2543   // create filter item
2544   Filter_var aFilter = myFilterMgr->CreateFilter();
2545   
2546   LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
2547   if ( aFilterItem.isNull() )
2548     return false;
2549   else
2550   {
2551     aSection.appendChild( aFilterItem );
2552     TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
2553     return true;
2554   }
2555 }
2556
2557 //=======================================================================
2558 // name    : FilterLibrary_i::Delete
2559 // Purpose : Delete filter from library
2560 //=======================================================================
2561 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
2562 {
2563   LDOM_Node aParentNode;
2564   LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
2565   if ( aFilterNode.isNull() || aParentNode.isNull() )
2566     return false;
2567
2568   aParentNode.removeChild( aFilterNode );
2569   TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
2570   return true;
2571 }
2572
2573 //=======================================================================
2574 // name      : FilterLibrary_i::Replace 
2575 // Purpose   : Replace existing filter with entry filter.
2576 // IMPORTANT : If filter does not exist it is not created
2577 //=======================================================================
2578 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
2579                                          const char* theNewName,                 
2580                                          Filter_ptr  theFilter )
2581 {
2582   LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
2583   if ( aFilterItem.isNull() || theFilter->_is_nil() )
2584     return false;
2585
2586   LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
2587   if ( aNewItem.isNull() )
2588     return false;
2589   else                                                                                          
2590   {
2591     aFilterItem.ReplaceElement( aNewItem );
2592     if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
2593       TPythonDump()<<this<<".Replace('"<<theFilterName<<"',"<<theNewName<<"',"<<aFilter<<")";
2594     return true;
2595   }
2596 }
2597
2598 //=======================================================================
2599 // name    : FilterLibrary_i::Save
2600 // Purpose : Save library on disk
2601 //=======================================================================
2602 CORBA::Boolean FilterLibrary_i::Save()
2603 {
2604   if ( myFileName == 0 || strlen( myFileName ) == 0 )
2605     return false;
2606           
2607   FILE* aOutFile = fopen( myFileName, "wt" );
2608   if ( !aOutFile )
2609     return false;
2610
2611   LDOM_XmlWriter aWriter( aOutFile );
2612   aWriter.SetIndentation( 2 );
2613   aWriter << myDoc;
2614   fclose( aOutFile );
2615
2616   TPythonDump()<<this<<".Save()";
2617   return true;
2618 }
2619
2620 //=======================================================================
2621 // name    : FilterLibrary_i::SaveAs
2622 // Purpose : Save library on disk
2623 //=======================================================================
2624 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
2625 {
2626   myFileName = strdup ( aFileName );
2627   TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
2628   return Save();
2629 }
2630
2631 //=======================================================================
2632 // name    : FilterLibrary_i::IsPresent
2633 // Purpose : Verify whether filter is in library
2634 //=======================================================================
2635 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
2636 {
2637   return !findFilter( theFilterName, myDoc ).isNull();
2638 }
2639
2640 //=======================================================================
2641 // name    : FilterLibrary_i::NbFilters
2642 // Purpose : Return amount of filters in library
2643 //=======================================================================
2644 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
2645 {
2646   string_array_var aNames = GetNames( theType );
2647   return aNames->length();
2648 }
2649
2650 //=======================================================================
2651 // name    : FilterLibrary_i::GetNames
2652 // Purpose : Get names of filters from library
2653 //=======================================================================
2654 string_array* FilterLibrary_i::GetNames( ElementType theType )
2655 {
2656   string_array_var anArray = new string_array;
2657   TColStd_SequenceOfHAsciiString aSeq;
2658
2659   LDOM_Node aSection = getSection( theType, myDoc, false );
2660
2661   if ( !aSection.isNull() )
2662   {
2663     for ( LDOM_Node aFilter = aSection.getFirstChild();
2664           !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2665     {
2666       LDOM_Element& anElem = ( LDOM_Element& )aFilter;
2667       aSeq.Append( new TCollection_HAsciiString(
2668          (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
2669     }
2670   }
2671
2672   anArray->length( aSeq.Length() );
2673   for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
2674     anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
2675
2676   return anArray._retn();
2677 }
2678
2679 //=======================================================================
2680 // name    : FilterLibrary_i::GetAllNames
2681 // Purpose : Get names of filters from library
2682 //=======================================================================
2683 string_array* FilterLibrary_i::GetAllNames()
2684 {
2685   string_array_var aResArray = new string_array;
2686   for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
2687   {
2688     SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
2689
2690     int aPrevLength = aResArray->length();
2691     aResArray->length( aPrevLength + aNames->length() );
2692     for ( int i = 0, n = aNames->length(); i < n; i++ )
2693       aResArray[ aPrevLength + i ] = aNames[ i ];
2694   }
2695
2696   return aResArray._retn();
2697 }