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