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