Salome HOME
Update copyrights
[modules/smesh.git] / src / SMESH_I / SMESH_Filter_i.cxx
1 // Copyright (C) 2007-2019  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   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
907   GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
908   TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
909   myBelongToGeomPtr->SetGeom( aLocShape );
910   TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
911 }
912
913 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
914 {
915   myBelongToGeomPtr->SetGeom( theShape );
916 }
917
918 void BelongToGeom_i::SetElementType(ElementType theType)
919 {
920   myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
921   TPythonDump()<<this<<".SetElementType("<<theType<<")";
922 }
923
924 FunctorType BelongToGeom_i::GetFunctorType()
925 {
926   return SMESH::FT_BelongToGeom;
927 }
928
929 void BelongToGeom_i::SetShapeName( const char* theName )
930 {
931   CORBA::string_free( myShapeName );
932   myShapeName = CORBA::string_dup( theName );
933   myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
934   TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
935 }
936
937 void BelongToGeom_i::SetShape( const char* theID, const char* theName )
938 {
939   CORBA::string_free( myShapeName );
940   CORBA::string_free( myShapeID );
941   myShapeName = CORBA::string_dup( theName );
942   myShapeID   = CORBA::string_dup( theID );
943   bool hasName = ( theName && theName[0] );
944   bool hasID   = ( theID   && theID[0] );
945
946   TopoDS_Shape S;
947   if ( hasName && hasID )
948   {
949     S = getShapeByID( myShapeID );
950     if ( S.IsNull() )
951       S = getShapeByName( myShapeName );
952   }
953   else
954   {
955     S = hasID ? getShapeByID( myShapeID ) : getShapeByName( myShapeName );
956   }
957   myBelongToGeomPtr->SetGeom( S );
958 }
959
960 char* BelongToGeom_i::GetShapeName()
961 {
962   return CORBA::string_dup( myShapeName );
963 }
964
965 char* BelongToGeom_i::GetShapeID()
966 {
967   return CORBA::string_dup( myShapeID );
968 }
969
970 void BelongToGeom_i::SetTolerance( CORBA::Double theToler )
971 {
972   myBelongToGeomPtr->SetTolerance( theToler );
973   TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
974 }
975
976 CORBA::Double BelongToGeom_i::GetTolerance()
977 {
978   return myBelongToGeomPtr->GetTolerance();
979 }
980
981 /*
982   Class       : BelongToSurface_i
983   Description : Predicate for selection on geometrical support
984 */
985 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
986 {
987   myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
988   myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
989   myShapeName = 0;
990   myShapeID   = 0;
991   mySurfaceType = theSurfaceType;
992 }
993
994 BelongToSurface_i::~BelongToSurface_i()
995 {
996   CORBA::string_free( myShapeName );
997   CORBA::string_free( myShapeID );
998 }
999
1000 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1001 {
1002   if ( theGeom->_is_nil() )
1003     return;
1004   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1005   GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1006   TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1007
1008   if ( aLocShape.ShapeType() == TopAbs_FACE )
1009   {
1010     Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
1011     if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
1012     {
1013       myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1014       return;
1015     }
1016   }
1017
1018   myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
1019 }
1020
1021 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
1022 {
1023   CORBA::string_free( myShapeName );
1024   myShapeName = CORBA::string_dup( theName );
1025   myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
1026   TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
1027 }
1028
1029 void BelongToSurface_i::SetShape( const char* theID,  const char* theName, ElementType theType )
1030 {
1031   CORBA::string_free( myShapeName );
1032   CORBA::string_free( myShapeID );
1033   myShapeName = CORBA::string_dup( theName );
1034   myShapeID   = CORBA::string_dup( theID );
1035   bool hasName = ( theName && theName[0] );
1036   bool hasID   = ( theID   && theID[0] );
1037
1038   TopoDS_Shape S;
1039   if ( hasName && hasID )
1040   {
1041     S = getShapeByID( myShapeID );
1042     if ( S.IsNull() )
1043       S = getShapeByName( myShapeName );
1044   }
1045   else
1046   {
1047     S = hasID ? getShapeByID( myShapeID ) : getShapeByName( myShapeName );
1048   }
1049   myElementsOnSurfacePtr->SetSurface( S, (SMDSAbs_ElementType)theType );
1050 }
1051
1052 char* BelongToSurface_i::GetShapeName()
1053 {
1054   return CORBA::string_dup( myShapeName );
1055 }
1056
1057 char* BelongToSurface_i::GetShapeID()
1058 {
1059   return CORBA::string_dup( myShapeID );
1060 }
1061
1062 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
1063 {
1064   myElementsOnSurfacePtr->SetTolerance( theToler );
1065   TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1066 }
1067
1068 CORBA::Double BelongToSurface_i::GetTolerance()
1069 {
1070   return myElementsOnSurfacePtr->GetTolerance();
1071 }
1072
1073 void BelongToSurface_i::SetUseBoundaries( CORBA::Boolean theUseBndRestrictions )
1074 {
1075   myElementsOnSurfacePtr->SetUseBoundaries( theUseBndRestrictions );
1076   TPythonDump()<<this<<".SetUseBoundaries( " << theUseBndRestrictions << " )";
1077 }
1078
1079 CORBA::Boolean BelongToSurface_i::GetUseBoundaries()
1080 {
1081   return myElementsOnSurfacePtr->GetUseBoundaries();
1082 }
1083
1084
1085 /*
1086   Class       : BelongToPlane_i
1087   Description : Verify whether mesh element lie in pointed Geom planar object
1088 */
1089
1090 BelongToPlane_i::BelongToPlane_i()
1091 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
1092 {
1093 }
1094
1095 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1096 {
1097   BelongToSurface_i::SetSurface( theGeom, theType );
1098   TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
1099 }
1100
1101 FunctorType BelongToPlane_i::GetFunctorType()
1102 {
1103   return FT_BelongToPlane;
1104 }
1105
1106 /*
1107   Class       : BelongToCylinder_i
1108   Description : Verify whether mesh element lie in pointed Geom planar object
1109 */
1110
1111 BelongToCylinder_i::BelongToCylinder_i()
1112 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1113 {
1114 }
1115
1116 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1117 {
1118   BelongToSurface_i::SetSurface( theGeom, theType );
1119   TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
1120 }
1121
1122 FunctorType BelongToCylinder_i::GetFunctorType()
1123 {
1124   return FT_BelongToCylinder;
1125 }
1126
1127 /*
1128   Class       : BelongToGenSurface_i
1129   Description : Verify whether mesh element lie in pointed Geom planar object
1130 */
1131
1132 BelongToGenSurface_i::BelongToGenSurface_i()
1133 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1134 {
1135 }
1136
1137 void BelongToGenSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1138 {
1139   if ( theGeom->_is_nil() )
1140     return;
1141   TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
1142   if ( !aLocShape.IsNull() && aLocShape.ShapeType() != TopAbs_FACE )
1143     aLocShape.Nullify();
1144   
1145   BelongToSurface_i::myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1146   TPythonDump()<<this<<".SetGenSurface("<<theGeom<<","<<theType<<")";
1147 }
1148
1149 FunctorType BelongToGenSurface_i::GetFunctorType()
1150 {
1151   return FT_BelongToGenSurface;
1152 }
1153
1154 /*
1155   Class       : LyingOnGeom_i
1156   Description : Predicate for selection on geometrical support
1157 */
1158 LyingOnGeom_i::LyingOnGeom_i()
1159 {
1160   myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
1161   myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
1162   myShapeName = 0;
1163   myShapeID = 0;
1164 }
1165
1166 LyingOnGeom_i::~LyingOnGeom_i()
1167 {
1168   CORBA::string_free( myShapeName );
1169   CORBA::string_free( myShapeID );
1170 }
1171
1172 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
1173 {
1174   if ( theGeom->_is_nil() )
1175     return;
1176   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1177   GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1178   TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1179   myLyingOnGeomPtr->SetGeom( aLocShape );
1180   TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
1181 }
1182
1183 void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
1184 {
1185   myLyingOnGeomPtr->SetGeom( theShape );
1186 }
1187
1188 void LyingOnGeom_i::SetElementType(ElementType theType){
1189   myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
1190   TPythonDump()<<this<<".SetElementType("<<theType<<")";
1191 }
1192
1193 FunctorType LyingOnGeom_i::GetFunctorType()
1194 {
1195   return SMESH::FT_LyingOnGeom;
1196 }
1197
1198 void LyingOnGeom_i::SetShapeName( const char* theName )
1199 {
1200   CORBA::string_free( myShapeName );
1201   myShapeName = CORBA::string_dup( theName );
1202   myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1203   TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
1204 }
1205
1206 void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
1207 {
1208   CORBA::string_free( myShapeName );
1209   CORBA::string_free( myShapeID   );
1210   myShapeName = CORBA::string_dup( theName );
1211   myShapeID   = CORBA::string_dup( theID   );
1212   bool hasName = ( theName && theName[0] );
1213   bool hasID   = ( theID   && theID[0]   );
1214
1215   TopoDS_Shape S;
1216   if ( hasName && hasID )
1217   {
1218     S = getShapeByID( myShapeID );
1219     if ( S.IsNull() )
1220       S = getShapeByName( myShapeName );
1221   }
1222   else
1223   {
1224     S = hasID ? getShapeByID( myShapeID ) : getShapeByName( myShapeName );
1225   }
1226   myLyingOnGeomPtr->SetGeom( S );
1227 }
1228
1229 char* LyingOnGeom_i::GetShapeName()
1230 {
1231   return CORBA::string_dup( myShapeName );
1232 }
1233
1234 char* LyingOnGeom_i::GetShapeID()
1235 {
1236   return CORBA::string_dup( myShapeID );
1237 }
1238
1239 void LyingOnGeom_i::SetTolerance( CORBA::Double theToler )
1240 {
1241   myLyingOnGeomPtr->SetTolerance( theToler );
1242   TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1243 }
1244
1245 CORBA::Double LyingOnGeom_i::GetTolerance()
1246 {
1247   return myLyingOnGeomPtr->GetTolerance();
1248 }
1249
1250 /*
1251   Class       : FreeBorders_i
1252   Description : Predicate for free borders
1253 */
1254 FreeBorders_i::FreeBorders_i()
1255 {
1256   myPredicatePtr.reset(new Controls::FreeBorders());
1257   myFunctorPtr = myPredicatePtr;
1258 }
1259
1260 FunctorType FreeBorders_i::GetFunctorType()
1261 {
1262   return SMESH::FT_FreeBorders;
1263 }
1264
1265 /*
1266   Class       : FreeEdges_i
1267   Description : Predicate for free borders
1268 */
1269 FreeEdges_i::FreeEdges_i()
1270 : myFreeEdgesPtr( new Controls::FreeEdges() )
1271 {
1272   myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
1273 }
1274
1275 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
1276 {
1277   SMESH::Controls::FreeEdges::TBorders aBorders;
1278   myFreeEdgesPtr->GetBoreders( aBorders );
1279
1280   long i = 0, iEnd = aBorders.size();
1281
1282   SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders;
1283   aResult->length(iEnd);
1284
1285   SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
1286   for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
1287   {
1288     const SMESH::Controls::FreeEdges::Border&  aBord = *anIter;
1289     SMESH::FreeEdges::Border &aBorder = aResult[ i ];
1290
1291     aBorder.myElemId = aBord.myElemId;
1292     aBorder.myPnt1 = aBord.myPntId[ 0 ];
1293     aBorder.myPnt2 = aBord.myPntId[ 1 ];
1294   }
1295   return aResult._retn();
1296 }
1297
1298 FunctorType FreeEdges_i::GetFunctorType()
1299 {
1300   return SMESH::FT_FreeEdges;
1301 }
1302
1303 /*
1304   Class       : FreeFaces_i
1305   Description : Predicate for free faces
1306 */
1307 FreeFaces_i::FreeFaces_i()
1308 {
1309   myPredicatePtr.reset(new Controls::FreeFaces());
1310   myFunctorPtr = myPredicatePtr;
1311 }
1312
1313 FunctorType FreeFaces_i::GetFunctorType()
1314 {
1315   return SMESH::FT_FreeFaces;
1316 }
1317
1318 /*
1319   Class       : FreeNodes_i
1320   Description : Predicate for free nodes
1321 */
1322 FreeNodes_i::FreeNodes_i()
1323 {
1324   myPredicatePtr.reset(new Controls::FreeNodes());
1325   myFunctorPtr = myPredicatePtr;
1326 }
1327
1328 FunctorType FreeNodes_i::GetFunctorType()
1329 {
1330   return SMESH::FT_FreeNodes;
1331 }
1332
1333 /*
1334   Class       : EqualNodes_i
1335   Description : Predicate for Equal nodes
1336 */
1337 EqualNodes_i::EqualNodes_i()
1338 {
1339   myCoincidentNodesPtr.reset(new Controls::CoincidentNodes());
1340   myFunctorPtr = myPredicatePtr = myCoincidentNodesPtr;
1341 }
1342
1343 FunctorType EqualNodes_i::GetFunctorType()
1344 {
1345   return SMESH::FT_EqualNodes;
1346 }
1347
1348 void EqualNodes_i::SetTolerance( double tol )
1349 {
1350   myCoincidentNodesPtr->SetTolerance( tol );
1351 }
1352
1353 double EqualNodes_i::GetTolerance()
1354 {
1355   return myCoincidentNodesPtr->GetTolerance();
1356 }
1357
1358 /*
1359   Class       : EqualEdges_i
1360   Description : Predicate for Equal Edges
1361 */
1362 EqualEdges_i::EqualEdges_i()
1363 {
1364   myPredicatePtr.reset(new Controls::CoincidentElements1D());
1365   myFunctorPtr = myPredicatePtr;
1366 }
1367
1368 FunctorType EqualEdges_i::GetFunctorType()
1369 {
1370   return SMESH::FT_EqualEdges;
1371 }
1372
1373 /*
1374   Class       : EqualFaces_i
1375   Description : Predicate for Equal Faces
1376 */
1377 EqualFaces_i::EqualFaces_i()
1378 {
1379   myPredicatePtr.reset(new Controls::CoincidentElements2D());
1380   myFunctorPtr = myPredicatePtr;
1381 }
1382
1383 FunctorType EqualFaces_i::GetFunctorType()
1384 {
1385   return SMESH::FT_EqualFaces;
1386 }
1387
1388 /*
1389   Class       : EqualVolumes_i
1390   Description : Predicate for Equal Volumes
1391 */
1392 EqualVolumes_i::EqualVolumes_i()
1393 {
1394   myPredicatePtr.reset(new Controls::CoincidentElements3D());
1395   myFunctorPtr = myPredicatePtr;
1396 }
1397
1398 FunctorType EqualVolumes_i::GetFunctorType()
1399 {
1400   return SMESH::FT_EqualVolumes;
1401 }
1402
1403
1404 /*
1405   Class       : RangeOfIds_i
1406   Description : Predicate for Range of Ids.
1407                 Range may be specified with two ways.
1408                 1. Using AddToRange method
1409                 2. With SetRangeStr method. Parameter of this method is a string
1410                    like as "1,2,3,50-60,63,67,70-"
1411 */
1412
1413 RangeOfIds_i::RangeOfIds_i()
1414 {
1415   myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
1416   myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
1417 }
1418
1419 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
1420 {
1421   CORBA::Long iEnd = theIds.length();
1422   for ( CORBA::Long i = 0; i < iEnd; i++ )
1423     myRangeOfIdsPtr->AddToRange( theIds[ i ] );
1424   TPythonDump()<<this<<".SetRange("<<theIds<<")";
1425 }
1426
1427 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
1428 {
1429   TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
1430   return myRangeOfIdsPtr->SetRangeStr(
1431     TCollection_AsciiString( (Standard_CString)theRange ) );
1432 }
1433
1434 char* RangeOfIds_i::GetRangeStr()
1435 {
1436   TCollection_AsciiString aStr;
1437   myRangeOfIdsPtr->GetRangeStr( aStr );
1438   return CORBA::string_dup( aStr.ToCString() );
1439 }
1440
1441 void RangeOfIds_i::SetElementType( ElementType theType )
1442 {
1443   myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
1444   TPythonDump()<<this<<".SetElementType("<<theType<<")";
1445 }
1446
1447 FunctorType RangeOfIds_i::GetFunctorType()
1448 {
1449   return SMESH::FT_RangeOfIds;
1450 }
1451
1452 /*
1453   Class       : LinearOrQuadratic_i
1454   Description : Predicate to verify whether a mesh element is linear
1455 */
1456 LinearOrQuadratic_i::LinearOrQuadratic_i()
1457 {
1458   myLinearOrQuadraticPtr.reset(new Controls::LinearOrQuadratic());
1459   myFunctorPtr = myPredicatePtr = myLinearOrQuadraticPtr;
1460 }
1461
1462 void LinearOrQuadratic_i::SetElementType(ElementType theType)
1463 {
1464   myLinearOrQuadraticPtr->SetType(SMDSAbs_ElementType(theType));
1465   TPythonDump()<<this<<".SetElementType("<<theType<<")";
1466 }
1467
1468 FunctorType LinearOrQuadratic_i::GetFunctorType()
1469 {
1470   return SMESH::FT_LinearOrQuadratic;
1471 }
1472
1473 /*
1474   Class       : GroupColor_i
1475   Description : Functor for check color of group to which mesh element belongs to
1476 */
1477 GroupColor_i::GroupColor_i()
1478 {
1479   myGroupColorPtr.reset(new Controls::GroupColor());
1480   myFunctorPtr = myPredicatePtr = myGroupColorPtr;
1481 }
1482
1483 FunctorType GroupColor_i::GetFunctorType()
1484 {
1485   return SMESH::FT_GroupColor;
1486 }
1487
1488 void GroupColor_i::SetColorStr( const char* theColor )
1489 {
1490   myGroupColorPtr->SetColorStr(
1491     TCollection_AsciiString( (Standard_CString)theColor ) );
1492   TPythonDump()<<this<<".SetColorStr('"<<theColor<<"')";
1493 }
1494
1495 char* GroupColor_i::GetColorStr()
1496 {
1497   TCollection_AsciiString aStr;
1498   myGroupColorPtr->GetColorStr( aStr );
1499   return CORBA::string_dup( aStr.ToCString() );
1500 }
1501
1502 void GroupColor_i::SetElementType(ElementType theType)
1503 {
1504   myGroupColorPtr->SetType(SMDSAbs_ElementType(theType));
1505   TPythonDump()<<this<<".SetElementType("<<theType<<")";
1506 }
1507
1508 /*
1509   Class       : ElemGeomType_i
1510   Description : Predicate check is element has indicated geometry type
1511 */
1512 ElemGeomType_i::ElemGeomType_i()
1513 {
1514   myElemGeomTypePtr.reset(new Controls::ElemGeomType());
1515   myFunctorPtr = myPredicatePtr = myElemGeomTypePtr;
1516 }
1517
1518 void ElemGeomType_i::SetElementType(ElementType theType)
1519 {
1520   myElemGeomTypePtr->SetType(SMDSAbs_ElementType(theType));
1521   TPythonDump()<<this<<".SetElementType("<<theType<<")";
1522 }
1523
1524 void ElemGeomType_i::SetGeometryType(GeometryType theType)
1525 {
1526   myElemGeomTypePtr->SetGeomType(SMDSAbs_GeometryType(theType));
1527   TPythonDump()<<this<<".SetGeometryType("<<theType<<")";
1528 }
1529
1530 GeometryType ElemGeomType_i::GetGeometryType() const
1531 {
1532   return (GeometryType)myElemGeomTypePtr->GetGeomType();
1533 }
1534
1535 FunctorType ElemGeomType_i::GetFunctorType()
1536 {
1537   return SMESH::FT_ElemGeomType;
1538 }
1539
1540 /*
1541   Class       : ElemEntityType_i
1542   Description : Predicate check is element has indicated entity type
1543 */
1544 ElemEntityType_i::ElemEntityType_i()
1545 {
1546   myElemEntityTypePtr.reset(new Controls::ElemEntityType());
1547   myFunctorPtr = myPredicatePtr = myElemEntityTypePtr;
1548 }
1549
1550 void ElemEntityType_i::SetElementType(ElementType theType)
1551 {
1552   myElemEntityTypePtr->SetType(SMDSAbs_ElementType(theType));
1553   TPythonDump()<<this<<".SetElementType("<<theType<<")";
1554 }
1555
1556 void ElemEntityType_i::SetEntityType(EntityType theEntityType)
1557 {
1558   myElemEntityTypePtr->SetElemEntityType(SMDSAbs_EntityType (theEntityType));
1559   TPythonDump()<<this<<".SetEntityType("<<theEntityType<<")";
1560 }
1561 EntityType ElemEntityType_i::GetEntityType() const
1562 {
1563  return (EntityType) myElemEntityTypePtr->GetElemEntityType();
1564 }
1565
1566 FunctorType ElemEntityType_i::GetFunctorType()
1567 {
1568   return SMESH::FT_EntityType;
1569 }
1570
1571 /*
1572   Class       : CoplanarFaces_i
1573   Description : Returns true if a mesh face is a coplanar neighbour to a given one
1574 */
1575 CoplanarFaces_i::CoplanarFaces_i()
1576 {
1577   myCoplanarFacesPtr.reset(new Controls::CoplanarFaces());
1578   myFunctorPtr = myPredicatePtr = myCoplanarFacesPtr;
1579 }
1580
1581 void CoplanarFaces_i::SetFace ( CORBA::Long theFaceID )
1582 {
1583   myCoplanarFacesPtr->SetFace(theFaceID);
1584   TPythonDump()<<this<<".SetFace("<<theFaceID<<")";
1585 }
1586
1587 void CoplanarFaces_i::SetTolerance( CORBA::Double theToler )
1588 {
1589   myCoplanarFacesPtr->SetTolerance(theToler);
1590   TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1591 }
1592
1593 CORBA::Long CoplanarFaces_i::GetFace () const
1594 {
1595   return myCoplanarFacesPtr->GetFace();
1596 }
1597
1598 char* CoplanarFaces_i::GetFaceAsString () const
1599 {
1600   TCollection_AsciiString str(Standard_Integer(myCoplanarFacesPtr->GetFace()));
1601   return CORBA::string_dup( str.ToCString() );
1602 }
1603
1604 CORBA::Double CoplanarFaces_i::GetTolerance() const
1605 {
1606   return myCoplanarFacesPtr->GetTolerance();
1607 }
1608
1609 FunctorType CoplanarFaces_i::GetFunctorType()
1610 {
1611   return SMESH::FT_CoplanarFaces;
1612 }
1613
1614 /*
1615  * Class       : ConnectedElements_i
1616  * Description : Returns true if an element is connected via other elements to the element
1617  *               located at a given point.
1618  */
1619 ConnectedElements_i::ConnectedElements_i()
1620 {
1621   myConnectedElementsPtr.reset(new Controls::ConnectedElements());
1622   myFunctorPtr = myPredicatePtr = myConnectedElementsPtr;
1623 }
1624
1625 FunctorType ConnectedElements_i::GetFunctorType()
1626 {
1627   return FT_ConnectedElements;
1628 }
1629
1630 void ConnectedElements_i::SetElementType( ElementType theType )
1631 {
1632   myConnectedElementsPtr->SetType( SMDSAbs_ElementType( theType ));
1633   TPythonDump() << this << ".SetElementType( " << theType << " )";
1634 }
1635
1636 void ConnectedElements_i::SetPoint( CORBA::Double x, CORBA::Double y, CORBA::Double z )
1637 {
1638   myConnectedElementsPtr->SetPoint( x,y,z );
1639   myVertexID.clear();
1640   TPythonDump() << this << ".SetPoint( " << x << ", " << y << ", " << z << " )";
1641 }
1642
1643 void ConnectedElements_i::SetVertex( GEOM::GEOM_Object_ptr vertex )
1644   throw (SALOME::SALOME_Exception)
1645 {
1646   TopoDS_Shape shape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( vertex );
1647   if ( shape.IsNull() )
1648     THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetVertex(): NULL Vertex",
1649                                   SALOME::BAD_PARAM );
1650
1651   TopExp_Explorer v( shape, TopAbs_VERTEX );
1652   if ( !v.More() )
1653     THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetVertex(): empty vertex",
1654                                   SALOME::BAD_PARAM );
1655
1656   gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( v.Current() ));
1657   myConnectedElementsPtr->SetPoint( p.X(), p.Y(), p.Z() );
1658   //
1659   CORBA::String_var id = vertex->GetStudyEntry();
1660   myVertexID = id.in();
1661
1662   TPythonDump() << this << ".SetVertex( " << vertex << " )";
1663 }
1664
1665 void ConnectedElements_i::SetNode ( CORBA::Long nodeID )
1666   throw (SALOME::SALOME_Exception)
1667 {
1668   if ( nodeID < 1 )
1669     THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetNode(): nodeID must be > 0",
1670                                   SALOME::BAD_PARAM );
1671
1672   myConnectedElementsPtr->SetNode( nodeID );
1673   myVertexID.clear();
1674   TPythonDump() << this << ".SetNode( " << nodeID << " )";
1675 }
1676
1677 /*!
1678  * \brief This is a comfort method for Filter dialog
1679  */
1680 void ConnectedElements_i::SetThreshold ( const char*                             threshold,
1681                                          SMESH::ConnectedElements::ThresholdType type )
1682   throw (SALOME::SALOME_Exception)
1683 {
1684   if ( !threshold )
1685     THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetThreshold(): NULL threshold",
1686                                   SALOME::BAD_PARAM );
1687   switch ( type )
1688   {
1689   case SMESH::ConnectedElements::POINT: // read 3 node coordinates ///////////////////
1690     {
1691       std::vector< double > xyz;
1692       char* endptr;
1693       do
1694       {
1695         // skip a separator
1696         while ( *threshold &&
1697                 *threshold != '+' &&
1698                 *threshold != '-' &&
1699                 !isdigit( *threshold ))
1700           ++threshold;
1701         if ( !*threshold )
1702           break;
1703         // read a coordinate
1704         xyz.push_back( strtod( threshold, &endptr ));
1705         if ( threshold == endptr )
1706         {
1707           xyz.resize( xyz.size() - 1 );
1708           break;
1709         }
1710         threshold = endptr;
1711       }
1712       while ( xyz.size() < 3 );
1713
1714       if ( xyz.size() < 3 )
1715         THROW_SALOME_CORBA_EXCEPTION
1716           ( "ConnectedElements_i::SetThreshold(): invalid point coordinates", SALOME::BAD_PARAM );
1717
1718       SetPoint( xyz[0], xyz[1], xyz[2] );
1719       break;
1720     }
1721   case SMESH::ConnectedElements::VERTEX: // get a VERTEX by its entry /////////////////
1722     {
1723       SALOMEDS::SObject_wrap sobj = SMESH_Gen_i::getStudyServant()->FindObjectID( threshold );
1724       if ( sobj->_is_nil() )
1725         THROW_SALOME_CORBA_EXCEPTION
1726           ( "ConnectedElements_i::SetThreshold(): invalid vertex study entry", SALOME::BAD_PARAM );
1727       CORBA::Object_var        obj = sobj->GetObject();
1728       GEOM::GEOM_Object_var vertex = GEOM::GEOM_Object::_narrow( obj );
1729       if ( vertex->_is_nil() )
1730         THROW_SALOME_CORBA_EXCEPTION
1731           ( "ConnectedElements_i::SetThreshold(): no GEOM_Object in SObject", SALOME::BAD_PARAM );
1732       SetVertex( vertex );
1733       break;
1734     }
1735   case SMESH::ConnectedElements::NODE: // read a node ID ////////////////////////////
1736     {
1737       char* endptr;
1738       int id = strtol( threshold, &endptr, 10 );
1739       if ( threshold == endptr )
1740         THROW_SALOME_CORBA_EXCEPTION
1741           ( "ConnectedElements_i::SetThreshold(): invalid node ID", SALOME::BAD_PARAM );
1742       SetNode( id );
1743       break;
1744     }
1745   default:
1746     THROW_SALOME_CORBA_EXCEPTION
1747       ( "ConnectedElements_i::SetThreshold(): invalid ThresholdType", SALOME::BAD_PARAM );
1748   }
1749 }
1750
1751 char* ConnectedElements_i::GetThreshold ( SMESH::ConnectedElements::ThresholdType& type )
1752 {
1753   std::string threshold;
1754   if ( !myVertexID.empty() )
1755   {
1756     threshold = myVertexID;
1757     type      = SMESH::ConnectedElements::VERTEX;
1758   }
1759   else
1760   {
1761     std::vector<double> xyz = myConnectedElementsPtr->GetPoint();
1762     if ( xyz.size() == 3 )
1763     {
1764       threshold = SMESH_Comment( xyz[0] ) << "; " << xyz[1] << "; " << xyz[2];
1765       type      = SMESH::ConnectedElements::POINT;
1766     }
1767     else
1768     {
1769       threshold = SMESH_Comment( myConnectedElementsPtr->GetNode() );
1770       type      = SMESH::ConnectedElements::NODE;
1771     }
1772   }
1773   return CORBA::string_dup( threshold.c_str() );
1774 }
1775
1776 /*
1777   Class       : Comparator_i
1778   Description : Base class for comparators
1779 */
1780 Comparator_i::Comparator_i():
1781   myNumericalFunctor( NULL )
1782 {}
1783
1784 Comparator_i::~Comparator_i()
1785 {
1786   if ( myNumericalFunctor )
1787     myNumericalFunctor->UnRegister();
1788 }
1789
1790 void Comparator_i::SetMargin( CORBA::Double theValue )
1791 {
1792   myComparatorPtr->SetMargin( theValue );
1793   TPythonDump()<<this<<".SetMargin("<<theValue<<")";
1794 }
1795
1796 CORBA::Double Comparator_i::GetMargin()
1797 {
1798   return myComparatorPtr->GetMargin();
1799 }
1800
1801 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
1802 {
1803   if ( myNumericalFunctor )
1804     myNumericalFunctor->UnRegister();
1805
1806   myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
1807
1808   if ( myNumericalFunctor )
1809   {
1810     myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
1811     myNumericalFunctor->Register();
1812     TPythonDump()<<this<<".SetNumFunctor("<<myNumericalFunctor<<")";
1813   }
1814 }
1815
1816 Controls::ComparatorPtr Comparator_i::GetComparator()
1817 {
1818   return myComparatorPtr;
1819 }
1820
1821 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
1822 {
1823   return myNumericalFunctor;
1824 }
1825
1826
1827 /*
1828   Class       : LessThan_i
1829   Description : Comparator "<"
1830 */
1831 LessThan_i::LessThan_i()
1832 {
1833   myComparatorPtr.reset( new Controls::LessThan() );
1834   myFunctorPtr = myPredicatePtr = myComparatorPtr;
1835 }
1836
1837 FunctorType LessThan_i::GetFunctorType()
1838 {
1839   return SMESH::FT_LessThan;
1840 }
1841
1842
1843 /*
1844   Class       : MoreThan_i
1845   Description : Comparator ">"
1846 */
1847 MoreThan_i::MoreThan_i()
1848 {
1849   myComparatorPtr.reset( new Controls::MoreThan() );
1850   myFunctorPtr = myPredicatePtr = myComparatorPtr;
1851 }
1852
1853 FunctorType MoreThan_i::GetFunctorType()
1854 {
1855   return SMESH::FT_MoreThan;
1856 }
1857
1858
1859 /*
1860   Class       : EqualTo_i
1861   Description : Comparator "="
1862 */
1863 EqualTo_i::EqualTo_i()
1864 : myEqualToPtr( new Controls::EqualTo() )
1865 {
1866   myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
1867 }
1868
1869 void EqualTo_i::SetTolerance( CORBA::Double theToler )
1870 {
1871   myEqualToPtr->SetTolerance( theToler );
1872   TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1873 }
1874
1875 CORBA::Double EqualTo_i::GetTolerance()
1876 {
1877   return myEqualToPtr->GetTolerance();
1878 }
1879
1880 FunctorType EqualTo_i::GetFunctorType()
1881 {
1882   return SMESH::FT_EqualTo;
1883 }
1884
1885 /*
1886   Class       : LogicalNOT_i
1887   Description : Logical NOT predicate
1888 */
1889 LogicalNOT_i::LogicalNOT_i():
1890   myLogicalNOTPtr( new Controls::LogicalNOT() ),
1891   myPredicate( NULL )
1892 {
1893   myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
1894 }
1895
1896 LogicalNOT_i::~LogicalNOT_i()
1897 {
1898   if ( myPredicate )
1899     myPredicate->UnRegister();
1900 }
1901
1902 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
1903 {
1904   if ( myPredicate )
1905     myPredicate->UnRegister();
1906
1907   myPredicate = SMESH::GetPredicate(thePredicate);
1908
1909   if ( myPredicate ){
1910     myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
1911     myPredicate->Register();
1912     TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1913   }
1914 }
1915
1916 FunctorType LogicalNOT_i::GetFunctorType()
1917 {
1918   return SMESH::FT_LogicalNOT;
1919 }
1920
1921 Predicate_i* LogicalNOT_i::GetPredicate_i()
1922 {
1923   return myPredicate;
1924 }
1925
1926
1927
1928 /*
1929   Class       : LogicalBinary_i
1930   Description : Base class for binary logical predicate
1931 */
1932 LogicalBinary_i::LogicalBinary_i()
1933 : myPredicate1( NULL ),
1934   myPredicate2( NULL )
1935 {}
1936
1937 LogicalBinary_i::~LogicalBinary_i()
1938 {
1939   if ( myPredicate1 )
1940     myPredicate1->UnRegister();
1941
1942   if ( myPredicate2 )
1943     myPredicate2->UnRegister();
1944 }
1945
1946 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
1947 {
1948   if ( myPredicate1 )
1949     myPredicate1->SetMesh( theMesh );
1950
1951   if ( myPredicate2 )
1952     myPredicate2->SetMesh( theMesh );
1953 }
1954
1955 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
1956 {
1957   if ( myPredicate1 )
1958     myPredicate1->UnRegister();
1959
1960   myPredicate1 = SMESH::GetPredicate(thePredicate);
1961
1962   if ( myPredicate1 ){
1963     myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
1964     myPredicate1->Register();
1965     TPythonDump()<<this<<".SetPredicate1("<<myPredicate1<<")";
1966   }
1967 }
1968
1969 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
1970 {
1971   if ( myPredicate2 )
1972     myPredicate2->UnRegister();
1973
1974   myPredicate2 = SMESH::GetPredicate(thePredicate);
1975
1976   if ( myPredicate2 ){
1977     myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
1978     myPredicate2->Register();
1979     TPythonDump()<<this<<".SetPredicate2("<<myPredicate2<<")";
1980   }
1981 }
1982
1983 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
1984 {
1985   return myLogicalBinaryPtr;
1986 }
1987
1988 Predicate_i* LogicalBinary_i::GetPredicate1_i()
1989 {
1990   return myPredicate1;
1991 }
1992 Predicate_i* LogicalBinary_i::GetPredicate2_i()
1993 {
1994   return myPredicate2;
1995 }
1996
1997
1998 /*
1999   Class       : LogicalAND_i
2000   Description : Logical AND
2001 */
2002 LogicalAND_i::LogicalAND_i()
2003 {
2004   myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
2005   myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
2006 }
2007
2008 FunctorType LogicalAND_i::GetFunctorType()
2009 {
2010   return SMESH::FT_LogicalAND;
2011 }
2012
2013
2014 /*
2015   Class       : LogicalOR_i
2016   Description : Logical OR
2017 */
2018 LogicalOR_i::LogicalOR_i()
2019 {
2020   myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
2021   myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
2022 }
2023
2024 FunctorType LogicalOR_i::GetFunctorType()
2025 {
2026   return SMESH::FT_LogicalOR;
2027 }
2028
2029
2030 /*
2031                             FILTER MANAGER
2032 */
2033
2034 FilterManager_i::FilterManager_i()
2035 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
2036 {
2037   //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
2038   //PortableServer::ObjectId_var anObjectId =
2039   //  SMESH_Gen_i::GetPOA()->activate_object( this );
2040 }
2041
2042
2043 FilterManager_i::~FilterManager_i()
2044 {
2045   //TPythonDump()<<this<<".UnRegister()";
2046 }
2047
2048
2049 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
2050 {
2051   SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
2052   SMESH::MinimumAngle_var anObj = aServant->_this();
2053   TPythonDump()<<aServant<<" = "<<this<<".CreateMinimumAngle()";
2054   return anObj._retn();
2055 }
2056
2057
2058 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
2059 {
2060   SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
2061   SMESH::AspectRatio_var anObj = aServant->_this();
2062   TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio()";
2063   return anObj._retn();
2064 }
2065
2066
2067 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
2068 {
2069   SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
2070   SMESH::AspectRatio3D_var anObj = aServant->_this();
2071   TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio3D()";
2072   return anObj._retn();
2073 }
2074
2075
2076 Warping_ptr FilterManager_i::CreateWarping()
2077 {
2078   SMESH::Warping_i* aServant = new SMESH::Warping_i();
2079   SMESH::Warping_var anObj = aServant->_this();
2080   TPythonDump()<<aServant<<" = "<<this<<".CreateWarping()";
2081   return anObj._retn();
2082 }
2083
2084
2085 Taper_ptr FilterManager_i::CreateTaper()
2086 {
2087   SMESH::Taper_i* aServant = new SMESH::Taper_i();
2088   SMESH::Taper_var anObj = aServant->_this();
2089   TPythonDump()<<aServant<<" = "<<this<<".CreateTaper()";
2090   return anObj._retn();
2091 }
2092
2093
2094 Skew_ptr FilterManager_i::CreateSkew()
2095 {
2096   SMESH::Skew_i* aServant = new SMESH::Skew_i();
2097   SMESH::Skew_var anObj = aServant->_this();
2098   TPythonDump()<<aServant<<" = "<<this<<".CreateSkew()";
2099   return anObj._retn();
2100 }
2101
2102
2103 Area_ptr FilterManager_i::CreateArea()
2104 {
2105   SMESH::Area_i* aServant = new SMESH::Area_i();
2106   SMESH::Area_var anObj = aServant->_this();
2107   TPythonDump()<<aServant<<" = "<<this<<".CreateArea()";
2108   return anObj._retn();
2109 }
2110
2111
2112 Volume3D_ptr FilterManager_i::CreateVolume3D()
2113 {
2114   SMESH::Volume3D_i* aServant = new SMESH::Volume3D_i();
2115   SMESH::Volume3D_var anObj = aServant->_this();
2116   TPythonDump()<<aServant<<" = "<<this<<".CreateVolume3D()";
2117   return anObj._retn();
2118 }
2119
2120
2121 MaxElementLength2D_ptr FilterManager_i::CreateMaxElementLength2D()
2122 {
2123   SMESH::MaxElementLength2D_i* aServant = new SMESH::MaxElementLength2D_i();
2124   SMESH::MaxElementLength2D_var anObj = aServant->_this();
2125   TPythonDump()<<aServant<<" = "<<this<<".CreateMaxElementLength2D()";
2126   return anObj._retn();
2127 }
2128
2129
2130 MaxElementLength3D_ptr FilterManager_i::CreateMaxElementLength3D()
2131 {
2132   SMESH::MaxElementLength3D_i* aServant = new SMESH::MaxElementLength3D_i();
2133   SMESH::MaxElementLength3D_var anObj = aServant->_this();
2134   TPythonDump()<<aServant<<" = "<<this<<".CreateMaxElementLength3D()";
2135   return anObj._retn();
2136 }
2137
2138
2139 Length_ptr FilterManager_i::CreateLength()
2140 {
2141   SMESH::Length_i* aServant = new SMESH::Length_i();
2142   SMESH::Length_var anObj = aServant->_this();
2143   TPythonDump()<<aServant<<" = "<<this<<".CreateLength()";
2144   return anObj._retn();
2145 }
2146
2147 Length2D_ptr FilterManager_i::CreateLength2D()
2148 {
2149   SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
2150   SMESH::Length2D_var anObj = aServant->_this();
2151   TPythonDump()<<aServant<<" = "<<this<<".CreateLength2D()";
2152   return anObj._retn();
2153 }
2154
2155 Length3D_ptr FilterManager_i::CreateLength3D()
2156 {
2157   SMESH::Length3D_i* aServant = new SMESH::Length3D_i();
2158   SMESH::Length3D_var anObj = aServant->_this();
2159   TPythonDump()<<aServant<<" = "<<this<<".CreateLength3D()";
2160   return anObj._retn();
2161 }
2162
2163 Deflection2D_ptr FilterManager_i::CreateDeflection2D()
2164 {
2165   SMESH::Deflection2D_i* aServant = new SMESH::Deflection2D_i();
2166   SMESH::Deflection2D_var   anObj = aServant->_this();
2167   TPythonDump()<<aServant<<" = "<<this<<".CreateDeflection2D()";
2168   return anObj._retn();
2169 }
2170
2171 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
2172 {
2173   SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
2174   SMESH::MultiConnection_var anObj = aServant->_this();
2175   TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection()";
2176   return anObj._retn();
2177 }
2178
2179 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
2180 {
2181   SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
2182   SMESH::MultiConnection2D_var anObj = aServant->_this();
2183   TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection2D()";
2184   return anObj._retn();
2185 }
2186
2187 BallDiameter_ptr FilterManager_i::CreateBallDiameter()
2188 {
2189   SMESH::BallDiameter_i* aServant = new SMESH::BallDiameter_i();
2190   SMESH::BallDiameter_var anObj = aServant->_this();
2191   TPythonDump()<<aServant<<" = "<<this<<".CreateBallDiameter()";
2192   return anObj._retn();
2193 }
2194
2195 NodeConnectivityNumber_ptr FilterManager_i::CreateNodeConnectivityNumber()
2196 {
2197   SMESH::NodeConnectivityNumber_i* aServant = new SMESH::NodeConnectivityNumber_i();
2198   SMESH::NodeConnectivityNumber_var anObj = aServant->_this();
2199   TPythonDump()<<aServant<<" = "<<this<<".CreateNodeConnectivityNumber()";
2200   return anObj._retn();
2201 }
2202
2203 BelongToMeshGroup_ptr FilterManager_i::CreateBelongToMeshGroup()
2204 {
2205   SMESH::BelongToMeshGroup_i* aServant = new SMESH::BelongToMeshGroup_i();
2206   SMESH::BelongToMeshGroup_var anObj = aServant->_this();
2207   TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToMeshGroup()";
2208   return anObj._retn();
2209 }
2210
2211 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
2212 {
2213   SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
2214   SMESH::BelongToGeom_var anObj = aServant->_this();
2215   TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGeom()";
2216   return anObj._retn();
2217 }
2218
2219 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
2220 {
2221   SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
2222   SMESH::BelongToPlane_var anObj = aServant->_this();
2223   TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToPlane()";
2224   return anObj._retn();
2225 }
2226
2227 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
2228 {
2229   SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
2230   SMESH::BelongToCylinder_var anObj = aServant->_this();
2231   TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToCylinder()";
2232   return anObj._retn();
2233 }
2234
2235 BelongToGenSurface_ptr FilterManager_i::CreateBelongToGenSurface()
2236 {
2237   SMESH::BelongToGenSurface_i* aServant = new SMESH::BelongToGenSurface_i();
2238   SMESH::BelongToGenSurface_var anObj = aServant->_this();
2239   TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGenSurface()";
2240   return anObj._retn();
2241 }
2242
2243 LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom()
2244 {
2245   SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i();
2246   SMESH::LyingOnGeom_var anObj = aServant->_this();
2247   TPythonDump()<<aServant<<" = "<<this<<".CreateLyingOnGeom()";
2248   return anObj._retn();
2249 }
2250
2251 CoplanarFaces_ptr FilterManager_i::CreateCoplanarFaces()
2252 {
2253   SMESH::CoplanarFaces_i* aServant = new SMESH::CoplanarFaces_i();
2254   SMESH::CoplanarFaces_var anObj = aServant->_this();
2255   TPythonDump()<<aServant<<" = "<<this<<".CreateCoplanarFaces()";
2256   return anObj._retn();
2257 }
2258
2259 ConnectedElements_ptr FilterManager_i::CreateConnectedElements()
2260 {
2261   SMESH::ConnectedElements_i* aServant = new SMESH::ConnectedElements_i();
2262   SMESH::ConnectedElements_var anObj = aServant->_this();
2263   TPythonDump()<<aServant<<" = "<<this<<".CreateConnectedElements()";
2264   return anObj._retn();
2265 }
2266
2267 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
2268 {
2269   SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
2270   SMESH::FreeBorders_var anObj = aServant->_this();
2271   TPythonDump()<<aServant<<" = "<<this<<".CreateFreeBorders()";
2272   return anObj._retn();
2273 }
2274
2275 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
2276 {
2277   SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
2278   SMESH::FreeEdges_var anObj = aServant->_this();
2279   TPythonDump()<<aServant<<" = "<<this<<".CreateFreeEdges()";
2280   return anObj._retn();
2281 }
2282
2283 FreeFaces_ptr FilterManager_i::CreateFreeFaces()
2284 {
2285   SMESH::FreeFaces_i* aServant = new SMESH::FreeFaces_i();
2286   SMESH::FreeFaces_var anObj = aServant->_this();
2287   TPythonDump()<<aServant<<" = "<<this<<".CreateFreeFaces()";
2288   return anObj._retn();
2289 }
2290
2291 FreeNodes_ptr FilterManager_i::CreateFreeNodes()
2292 {
2293   SMESH::FreeNodes_i* aServant = new SMESH::FreeNodes_i();
2294   SMESH::FreeNodes_var anObj = aServant->_this();
2295   TPythonDump()<<aServant<<" = "<<this<<".CreateFreeNodes()";
2296   return anObj._retn();
2297 }
2298
2299 EqualNodes_ptr FilterManager_i::CreateEqualNodes()
2300 {
2301   SMESH::EqualNodes_i* aServant = new SMESH::EqualNodes_i();
2302   SMESH::EqualNodes_var anObj = aServant->_this();
2303   TPythonDump()<<aServant<<" = "<<this<<".CreateEqualNodes()";
2304   return anObj._retn();
2305 }
2306
2307 EqualEdges_ptr FilterManager_i::CreateEqualEdges()
2308 {
2309   SMESH::EqualEdges_i* aServant = new SMESH::EqualEdges_i();
2310   SMESH::EqualEdges_var anObj = aServant->_this();
2311   TPythonDump()<<aServant<<" = "<<this<<".CreateEqualEdges()";
2312   return anObj._retn();
2313 }
2314 EqualFaces_ptr FilterManager_i::CreateEqualFaces()
2315 {
2316   SMESH::EqualFaces_i* aServant = new SMESH::EqualFaces_i();
2317   SMESH::EqualFaces_var anObj = aServant->_this();
2318   TPythonDump()<<aServant<<" = "<<this<<".CreateEqualFaces()";
2319   return anObj._retn();
2320 }
2321 EqualVolumes_ptr FilterManager_i::CreateEqualVolumes()
2322 {
2323   SMESH::EqualVolumes_i* aServant = new SMESH::EqualVolumes_i();
2324   SMESH::EqualVolumes_var anObj = aServant->_this();
2325   TPythonDump()<<aServant<<" = "<<this<<".CreateEqualVolumes()";
2326   return anObj._retn();
2327 }
2328
2329 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
2330 {
2331   SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
2332   SMESH::RangeOfIds_var anObj = aServant->_this();
2333   TPythonDump()<<aServant<<" = "<<this<<".CreateRangeOfIds()";
2334   return anObj._retn();
2335 }
2336
2337 BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
2338 {
2339   SMESH::BadOrientedVolume_i* aServant = new SMESH::BadOrientedVolume_i();
2340   SMESH::BadOrientedVolume_var anObj = aServant->_this();
2341   TPythonDump()<<aServant<<" = "<<this<<".CreateBadOrientedVolume()";
2342   return anObj._retn();
2343 }
2344
2345 BareBorderVolume_ptr FilterManager_i::CreateBareBorderVolume()
2346 {
2347   SMESH::BareBorderVolume_i* aServant = new SMESH::BareBorderVolume_i();
2348   SMESH::BareBorderVolume_var anObj = aServant->_this();
2349   TPythonDump()<<aServant<<" = "<<this<<".CreateBareBorderVolume()";
2350   return anObj._retn();
2351 }
2352
2353 BareBorderFace_ptr FilterManager_i::CreateBareBorderFace()
2354 {
2355   SMESH::BareBorderFace_i* aServant = new SMESH::BareBorderFace_i();
2356   SMESH::BareBorderFace_var anObj = aServant->_this();
2357   TPythonDump()<<aServant<<" = "<<this<<".CreateBareBorderFace()";
2358   return anObj._retn();
2359 }
2360
2361 OverConstrainedVolume_ptr FilterManager_i::CreateOverConstrainedVolume()
2362 {
2363   SMESH::OverConstrainedVolume_i* aServant = new SMESH::OverConstrainedVolume_i();
2364   SMESH::OverConstrainedVolume_var anObj = aServant->_this();
2365   TPythonDump()<<aServant<<" = "<<this<<".CreateOverConstrainedVolume()";
2366   return anObj._retn();
2367 }
2368
2369 OverConstrainedFace_ptr FilterManager_i::CreateOverConstrainedFace()
2370 {
2371   SMESH::OverConstrainedFace_i* aServant = new SMESH::OverConstrainedFace_i();
2372   SMESH::OverConstrainedFace_var anObj = aServant->_this();
2373   TPythonDump()<<aServant<<" = "<<this<<".CreateOverConstrainedFace()";
2374   return anObj._retn();
2375 }
2376
2377 LessThan_ptr FilterManager_i::CreateLessThan()
2378 {
2379   SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
2380   SMESH::LessThan_var anObj = aServant->_this();
2381   TPythonDump()<<aServant<<" = "<<this<<".CreateLessThan()";
2382   return anObj._retn();
2383 }
2384
2385 MoreThan_ptr FilterManager_i::CreateMoreThan()
2386 {
2387   SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
2388   SMESH::MoreThan_var anObj = aServant->_this();
2389   TPythonDump()<<aServant<<" = "<<this<<".CreateMoreThan()";
2390   return anObj._retn();
2391 }
2392
2393 EqualTo_ptr FilterManager_i::CreateEqualTo()
2394 {
2395   SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
2396   SMESH::EqualTo_var anObj = aServant->_this();
2397   TPythonDump()<<aServant<<" = "<<this<<".CreateEqualTo()";
2398   return anObj._retn();
2399 }
2400
2401 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
2402 {
2403   SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
2404   SMESH::LogicalNOT_var anObj = aServant->_this();
2405   TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalNOT()";
2406   return anObj._retn();
2407 }
2408
2409 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
2410 {
2411   SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
2412   SMESH::LogicalAND_var anObj = aServant->_this();
2413   TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalAND()";
2414   return anObj._retn();
2415 }
2416
2417 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
2418 {
2419   SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
2420   SMESH::LogicalOR_var anObj = aServant->_this();
2421   TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalOR()";
2422   return anObj._retn();
2423 }
2424
2425 LinearOrQuadratic_ptr FilterManager_i::CreateLinearOrQuadratic()
2426 {
2427   SMESH::LinearOrQuadratic_i* aServant = new SMESH::LinearOrQuadratic_i();
2428   SMESH::LinearOrQuadratic_var anObj = aServant->_this();
2429   TPythonDump()<<aServant<<" = "<<this<<".CreateLinearOrQuadratic()";
2430   return anObj._retn();
2431 }
2432
2433 GroupColor_ptr FilterManager_i::CreateGroupColor()
2434 {
2435   SMESH::GroupColor_i* aServant = new SMESH::GroupColor_i();
2436   SMESH::GroupColor_var anObj = aServant->_this();
2437   TPythonDump()<<aServant<<" = "<<this<<".CreateGroupColor()";
2438   return anObj._retn();
2439 }
2440
2441 ElemGeomType_ptr FilterManager_i::CreateElemGeomType()
2442 {
2443   SMESH::ElemGeomType_i* aServant = new SMESH::ElemGeomType_i();
2444   SMESH::ElemGeomType_var anObj = aServant->_this();
2445   TPythonDump()<<aServant<<" = "<<this<<".CreateElemGeomType()";
2446   return anObj._retn();
2447 }
2448
2449 ElemEntityType_ptr FilterManager_i::CreateElemEntityType()
2450 {
2451   SMESH::ElemEntityType_i* aServant = new SMESH::ElemEntityType_i();
2452   SMESH::ElemEntityType_var anObj = aServant->_this();
2453   TPythonDump()<<aServant<<" = "<<this<<".CreateElemEntityType()";
2454   return anObj._retn();
2455 }
2456
2457 Filter_ptr FilterManager_i::CreateFilter()
2458 {
2459   SMESH::Filter_i* aServant = new SMESH::Filter_i();
2460   SMESH::Filter_var anObj = aServant->_this();
2461   TPythonDump()<<aServant<<" = "<<this<<".CreateFilter()";
2462   return anObj._retn();
2463 }
2464
2465 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
2466 {
2467   SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
2468   SMESH::FilterLibrary_var anObj = aServant->_this();
2469   TPythonDump()<<aServant<<" = "<<this<<".LoadLibrary('"<<aFileName<<"')";
2470   return anObj._retn();
2471 }
2472
2473 FilterLibrary_ptr FilterManager_i::CreateLibrary()
2474 {
2475   SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
2476   SMESH::FilterLibrary_var anObj = aServant->_this();
2477   TPythonDump()<<aServant<<" = "<<this<<".CreateLibrary()";
2478   return anObj._retn();
2479 }
2480
2481 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
2482 {
2483   TPythonDump()<<this<<".DeleteLibrary("<<aFileName<<")";
2484   return remove( aFileName ) ? false : true;
2485 }
2486
2487 //=============================================================================
2488 /*!
2489  *  SMESH_Gen_i::CreateFilterManager
2490  *
2491  *  Create filter manager
2492  */
2493 //=============================================================================
2494
2495 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
2496 {
2497   SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2498   SMESH::FilterManager_var anObj = aFilter->_this();
2499   return anObj._retn();
2500 }
2501
2502
2503 /*
2504                               FILTER
2505 */
2506
2507 //=======================================================================
2508 // name    : Filter_i::Filter_i
2509 // Purpose : Constructor
2510 //=======================================================================
2511 Filter_i::Filter_i()
2512 : myPredicate( NULL )
2513 {}
2514
2515 //=======================================================================
2516 // name    : Filter_i::~Filter_i
2517 // Purpose : Destructor
2518 //=======================================================================
2519 Filter_i::~Filter_i()
2520 {
2521   if ( myPredicate )
2522     myPredicate->UnRegister();
2523
2524   if(!CORBA::is_nil(myMesh))
2525     myMesh->UnRegister();
2526
2527   myPredicate = 0;
2528   FindBaseObjects();
2529 }
2530
2531 //=======================================================================
2532 // name    : Filter_i::SetPredicate
2533 // Purpose : Set predicate
2534 //=======================================================================
2535 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
2536 {
2537   if ( myPredicate )
2538     myPredicate->UnRegister();
2539
2540   myPredicate = SMESH::GetPredicate(thePredicate);
2541
2542   if ( myPredicate )
2543   {
2544     myFilter.SetPredicate( myPredicate->GetPredicate() );
2545     myPredicate->Register();
2546     if ( const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh))
2547       myPredicate->GetPredicate()->SetMesh( aMesh );
2548     TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
2549   }
2550   NotifyerAndWaiter::Modified();
2551 }
2552
2553 //=======================================================================
2554 // name    : Filter_i::GetElementType
2555 // Purpose : Get entity type
2556 //=======================================================================
2557 SMESH::ElementType Filter_i::GetElementType()
2558 {
2559   return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
2560 }
2561
2562 //=======================================================================
2563 // name    : Filter_i::SetMesh
2564 // Purpose : Set mesh
2565 //=======================================================================
2566 void
2567 Filter_i::
2568 SetMesh( SMESH_Mesh_ptr theMesh )
2569 {
2570   if(!CORBA::is_nil(theMesh))
2571     theMesh->Register();
2572
2573   if(!CORBA::is_nil(myMesh))
2574     myMesh->UnRegister();
2575
2576   myMesh = SMESH_Mesh::_duplicate( theMesh );
2577   TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
2578
2579   if ( myPredicate )
2580     if ( const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
2581       myPredicate->GetPredicate()->SetMesh( aMesh );
2582 }
2583
2584 SMESH::long_array*
2585 Filter_i::
2586 GetIDs()
2587 {
2588   return GetElementsId(myMesh);
2589 }
2590
2591 //=======================================================================
2592 // name    : Filter_i::GetElementsId
2593 // Purpose : Get ids of entities
2594 //=======================================================================
2595 void
2596 Filter_i::
2597 GetElementsId( Predicate_i* thePredicate,
2598                const SMDS_Mesh* theMesh,
2599                Controls::Filter::TIdSequence& theSequence )
2600 {
2601   if (thePredicate)
2602     Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence);
2603 }
2604
2605 void
2606 Filter_i::
2607 GetElementsId( Predicate_i* thePredicate,
2608                SMESH_Mesh_ptr theMesh,
2609                Controls::Filter::TIdSequence& theSequence )
2610 {
2611   if (thePredicate) 
2612     if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
2613       Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence);
2614 }
2615
2616 SMESH::long_array*
2617 Filter_i::
2618 GetElementsId( SMESH_Mesh_ptr theMesh )
2619 {
2620   SMESH::long_array_var anArray = new SMESH::long_array;
2621   if(!CORBA::is_nil(theMesh) && myPredicate){
2622     theMesh->Load();
2623     Controls::Filter::TIdSequence aSequence;
2624     GetElementsId(myPredicate,theMesh,aSequence);
2625     long i = 0, iEnd = aSequence.size();
2626     anArray->length( iEnd );
2627     for ( ; i < iEnd; i++ )
2628       anArray[ i ] = aSequence[i];
2629   }
2630   return anArray._retn();
2631 }
2632
2633 SMESH::long_array*
2634 Filter_i::
2635 GetElementsIdFromParts( const ListOfIDSources& theParts )
2636 {
2637   SMESH::long_array_var array = new SMESH::long_array;
2638   if ( theParts.length() > 0 && myPredicate )
2639   {
2640     SMESH_Mesh_ptr mesh = theParts[0]->GetMesh();
2641     mesh->Load();
2642     const SMDS_Mesh* meshDS = MeshPtr2SMDSMesh( mesh );
2643     Controls::Filter::TIdSequence totalSequence;
2644     for ( CORBA::ULong i = 0; i < theParts.length(); ++i )
2645     {
2646       if ( SMESH::Filter_i* filter = SMESH::DownCast<SMESH::Filter_i*>( theParts[i] ))
2647         filter->SetMesh( mesh );
2648       SMDS_ElemIteratorPtr iter = SMESH_Mesh_i::GetElements( theParts[i], GetElementType() );
2649       if ( iter && meshDS )
2650       {
2651         Controls::Filter::TIdSequence sequence;
2652         Controls::Filter::GetElementsId( meshDS, myPredicate->GetPredicate(), sequence, iter );
2653         totalSequence.insert( totalSequence.end(), sequence.begin(), sequence.end() );
2654       }
2655     }
2656     array->length( totalSequence.size() );
2657     for ( size_t i = 0; i < totalSequence.size(); ++i )
2658       array[ i ] = totalSequence[ i ];
2659   }
2660   return array._retn();
2661 }
2662
2663 //=============================================================================
2664 /*!
2665  * \brief Returns number of mesh elements per each \a EntityType
2666  */
2667 //=============================================================================
2668
2669 SMESH::long_array* ::Filter_i::GetMeshInfo()
2670 {
2671   SMESH::long_array_var aRes = new SMESH::long_array();
2672   aRes->length(SMESH::Entity_Last);
2673   for (int i = 0; i < SMESH::Entity_Last; i++)
2674     aRes[i] = 0;
2675
2676   if ( !CORBA::is_nil(myMesh) && myPredicate )
2677   {
2678     const SMDS_Mesh*  aMesh = MeshPtr2SMDSMesh(myMesh);
2679     SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() ));
2680     while ( it->more() )
2681     {
2682       const SMDS_MeshElement* anElem = it->next();
2683       if ( myPredicate->IsSatisfy( anElem->GetID() ) )
2684         aRes[ anElem->GetEntityType() ]++;
2685     }
2686   }
2687
2688   return aRes._retn();  
2689 }
2690
2691 //=============================================================================
2692 /*!
2693  * \brief Returns number of mesh elements of each \a ElementType
2694  */
2695 //=============================================================================
2696
2697 SMESH::long_array* ::Filter_i::GetNbElementsByType()
2698 {
2699   SMESH::long_array_var aRes = new SMESH::long_array();
2700   aRes->length(SMESH::NB_ELEMENT_TYPES);
2701   for (int i = 0; i < SMESH::NB_ELEMENT_TYPES; i++)
2702     aRes[i] = 0;
2703
2704   if ( !CORBA::is_nil(myMesh) && myPredicate ) {
2705     const SMDS_Mesh*  aMesh = MeshPtr2SMDSMesh(myMesh);
2706     SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() ));
2707     CORBA::Long& nbElems = aRes[ GetElementType() ];
2708     while ( it->more() )
2709     {
2710       const SMDS_MeshElement* anElem = it->next();
2711       if ( myPredicate->IsSatisfy( anElem->GetID() ) )
2712         nbElems++;
2713     }
2714   }
2715
2716   return aRes._retn();  
2717 }
2718
2719
2720 //================================================================================
2721 /*!
2722  * \brief Return GetElementType() within an array
2723  * Implement SMESH_IDSource interface
2724  */
2725 //================================================================================
2726
2727 SMESH::array_of_ElementType* Filter_i::GetTypes()
2728 {
2729   SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
2730
2731   // check if any element passes through the filter
2732   if ( !CORBA::is_nil(myMesh) && myPredicate )
2733   {
2734     const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
2735     SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() ));
2736     bool satisfies = false;
2737     while ( !satisfies && it->more() )
2738       satisfies = myPredicate->IsSatisfy( it->next()->GetID() );
2739     if ( satisfies ) {
2740       types->length( 1 );
2741       types[0] = GetElementType();
2742     }
2743   }
2744   return types._retn();
2745 }
2746
2747 //=======================================================================
2748 //function : GetMesh
2749 //purpose  : Returns mesh
2750 //=======================================================================
2751
2752 SMESH::SMESH_Mesh_ptr Filter_i::GetMesh()
2753 {
2754   return SMESH_Mesh::_duplicate( myMesh );
2755 }
2756
2757 //=======================================================================
2758 //function : GetVtkUgStream
2759 //purpose  : Return data vtk unstructured grid (not implemented)
2760 //=======================================================================
2761
2762 SALOMEDS::TMPFile* Filter_i::GetVtkUgStream()
2763 {
2764   SALOMEDS::TMPFile_var SeqFile;
2765   return SeqFile._retn();
2766 }
2767 //=======================================================================
2768 // name    : getCriteria
2769 // Purpose : Retrieve criterions from predicate
2770 //=======================================================================
2771 static inline void getPrediacates( Predicate_i*                thePred,
2772                                    std::vector<Predicate_i*> & thePredVec )
2773 {
2774   const int aFType = thePred->GetFunctorType();
2775
2776   switch ( aFType )
2777   {
2778   case FT_LogicalNOT:
2779   {
2780     Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
2781     getPrediacates( aPred, thePredVec );
2782     break;
2783   }
2784   case FT_LogicalAND:
2785   case FT_LogicalOR:
2786   {
2787     Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
2788     Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
2789     getPrediacates( aPred1, thePredVec );
2790     getPrediacates( aPred2, thePredVec );
2791     break;
2792    }
2793   default:;
2794   }
2795   thePredVec.push_back( thePred );
2796 }
2797
2798 //=======================================================================
2799 // name    : getCriteria
2800 // Purpose : Retrieve criterions from predicate
2801 //=======================================================================
2802 static inline bool getCriteria( Predicate_i*                thePred,
2803                                 SMESH::Filter::Criteria_out theCriteria )
2804 {
2805   const int aFType = thePred->GetFunctorType();
2806
2807   switch ( aFType )
2808   {
2809   case FT_LogicalNOT:
2810     {
2811       Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
2812       getCriteria( aPred, theCriteria );
2813       theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
2814     }
2815     return true;
2816
2817   case FT_LogicalAND:
2818   case FT_LogicalOR:
2819     {
2820       Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
2821       Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
2822       if ( !getCriteria( aPred1, theCriteria ) )
2823         return false;
2824       theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
2825       return getCriteria( aPred2, theCriteria );
2826     }
2827   case FT_Undefined:
2828     return false;
2829   }
2830
2831   // resize theCriteria
2832   CORBA::ULong i = theCriteria->length();
2833   theCriteria->length( i + 1 );
2834   theCriteria[ i ] = createCriterion();
2835
2836   // set members of the added Criterion
2837
2838   theCriteria[ i ].Type = aFType;
2839   theCriteria[ i ].TypeOfElement = thePred->GetElementType();
2840
2841   switch ( aFType )
2842   {
2843   case FT_FreeBorders:
2844   case FT_FreeEdges:
2845   case FT_FreeFaces:
2846   case FT_LinearOrQuadratic:
2847   case FT_FreeNodes:
2848   case FT_EqualEdges:
2849   case FT_EqualFaces:
2850   case FT_EqualVolumes:
2851   case FT_BadOrientedVolume:
2852   case FT_BareBorderVolume:
2853   case FT_BareBorderFace:
2854   case FT_OverConstrainedVolume:
2855   case FT_OverConstrainedFace:
2856     {
2857       return true;
2858     }
2859   case FT_BelongToMeshGroup:
2860     {
2861       BelongToMeshGroup_i* aPred = dynamic_cast<BelongToMeshGroup_i*>( thePred );
2862       SMESH::SMESH_GroupBase_var grp = aPred->GetGroup();
2863       if ( !grp->_is_nil() )
2864       {
2865         theCriteria[ i ].ThresholdStr = grp->GetName();
2866         theCriteria[ i ].ThresholdID  = aPred->GetGroupID().c_str();
2867       }
2868       return true;
2869     }
2870   case FT_BelongToGeom:
2871     {
2872       BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
2873       theCriteria[ i ].ThresholdStr  = aPred->GetShapeName();
2874       theCriteria[ i ].ThresholdID   = aPred->GetShapeID();
2875       theCriteria[ i ].Tolerance     = aPred->GetTolerance();
2876       return true;
2877     }
2878   case FT_BelongToPlane:
2879   case FT_BelongToCylinder:
2880   case FT_BelongToGenSurface:
2881     {
2882       BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
2883       theCriteria[ i ].ThresholdStr  = aPred->GetShapeName();
2884       theCriteria[ i ].ThresholdID   = aPred->GetShapeID();
2885       theCriteria[ i ].Tolerance     = aPred->GetTolerance();
2886       return true;
2887     }
2888   case FT_LyingOnGeom:
2889     {
2890       LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
2891       theCriteria[ i ].ThresholdStr  = aPred->GetShapeName();
2892       theCriteria[ i ].ThresholdID   = aPred->GetShapeID();
2893       theCriteria[ i ].Tolerance     = aPred->GetTolerance();
2894       return true;
2895     }
2896   case FT_CoplanarFaces:
2897     {
2898       CoplanarFaces_i* aPred = dynamic_cast<CoplanarFaces_i*>( thePred );
2899       theCriteria[ i ].ThresholdID   = aPred->GetFaceAsString();
2900       theCriteria[ i ].Tolerance     = aPred->GetTolerance();
2901       return true;
2902     }
2903   case FT_ConnectedElements:
2904     {
2905       ConnectedElements_i* aPred = dynamic_cast<ConnectedElements_i*>( thePred );
2906       SMESH::ConnectedElements::ThresholdType type;
2907       CORBA::String_var threshold = aPred->GetThreshold( type );
2908       switch ( type ) {
2909       case SMESH::ConnectedElements::POINT:
2910         theCriteria[ i ].ThresholdStr = threshold; break;
2911       case SMESH::ConnectedElements::VERTEX:
2912         theCriteria[ i ].ThresholdID = threshold; break;
2913       case SMESH::ConnectedElements::NODE:
2914         theCriteria[ i ].Threshold = atof( threshold.in() ); break;
2915       default:;
2916       }
2917       return true;
2918     }
2919   case FT_EqualNodes:
2920     {
2921       EqualNodes_i* aPred = dynamic_cast<EqualNodes_i*>( thePred );
2922       theCriteria[ i ].Tolerance  = aPred->GetTolerance();
2923       return true;
2924     }
2925   case FT_RangeOfIds:
2926     {
2927       RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
2928       theCriteria[ i ].ThresholdStr  = aPred->GetRangeStr();
2929       return true;
2930     }
2931   case FT_LessThan:
2932   case FT_MoreThan:
2933   case FT_EqualTo:
2934     {
2935       Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
2936       theCriteria[ i ].Type      = aCompar->GetNumFunctor_i()->GetFunctorType();
2937       theCriteria[ i ].Compare   = aFType;
2938       theCriteria[ i ].Threshold = aCompar->GetMargin();
2939       if ( aFType == FT_EqualTo )
2940       {
2941         EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
2942         theCriteria[ i ].Tolerance = aCompar->GetTolerance();
2943       }
2944       return true;
2945     }
2946   case FT_GroupColor:
2947     {
2948       GroupColor_i* aPred = dynamic_cast<GroupColor_i*>( thePred );
2949       theCriteria[ i ].ThresholdStr = aPred->GetColorStr();
2950       return true;
2951     }
2952   case FT_ElemGeomType:
2953     {
2954       ElemGeomType_i* aPred = dynamic_cast<ElemGeomType_i*>( thePred );
2955       theCriteria[ i ].Threshold = (double)aPred->GetGeometryType();
2956       return true;
2957     }
2958   case FT_EntityType:
2959     {
2960       ElemEntityType_i* aPred = dynamic_cast<ElemEntityType_i*>( thePred );
2961       theCriteria[ i ].Threshold = (double)aPred->GetEntityType();
2962       return true;
2963     }
2964   default:
2965     return false;
2966   }
2967 }
2968
2969 //=======================================================================
2970 // name    : Filter_i::GetCriteria
2971 // Purpose : Retrieve criterions from predicate
2972 //=======================================================================
2973 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
2974 {
2975   theCriteria = new SMESH::Filter::Criteria;
2976   return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
2977 }
2978
2979 //=======================================================================
2980 // name    : Filter_i::SetCriteria
2981 // Purpose : Create new predicate and set criterions in it
2982 //=======================================================================
2983 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
2984 {
2985   SetPredicate( SMESH::Predicate::_nil() );
2986
2987   SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2988   FilterManager_ptr aFilterMgr = aFilter->_this();
2989
2990   // CREATE two lists ( PREDICATES  and LOG OP )
2991
2992   // Criterion
2993   TPythonDump()<<"aCriteria = []";
2994   std::list<SMESH::Predicate_ptr> aPredicates;
2995   std::list<int>                  aBinaries;
2996   for ( int i = 0, n = theCriteria.length(); i < n; i++ )
2997   {
2998     int         aCriterion    = theCriteria[ i ].Type;
2999     int         aCompare      = theCriteria[ i ].Compare;
3000     double      aThreshold    = theCriteria[ i ].Threshold;
3001     const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
3002     const char* aThresholdID  = theCriteria[ i ].ThresholdID;
3003     int         aUnary        = theCriteria[ i ].UnaryOp;
3004     int         aBinary       = theCriteria[ i ].BinaryOp;
3005     double      aTolerance    = theCriteria[ i ].Tolerance;
3006     ElementType aTypeOfElem   = theCriteria[ i ].TypeOfElement;
3007     long        aPrecision    = theCriteria[ i ].Precision;
3008
3009     {
3010       TPythonDump pd;
3011       pd << "aCriterion = SMESH.Filter.Criterion("
3012          << aCriterion    << ", "
3013          << aCompare      << ", "
3014          << aThreshold    << ", '"
3015          << aThresholdStr << "', '"
3016          << aThresholdID  << "', "
3017          << aUnary        << ", "
3018          << aBinary       << ", "
3019          << aTolerance    << ", "
3020          << aTypeOfElem   << ", "
3021          << aPrecision    << ")";
3022     }
3023     TPythonDump pd;
3024
3025     SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
3026     SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
3027
3028     switch ( aCriterion )
3029     {
3030       // Functors
3031
3032       case SMESH::FT_MultiConnection:
3033         aFunctor = aFilterMgr->CreateMultiConnection();
3034         break;
3035       case SMESH::FT_MultiConnection2D:
3036         aFunctor = aFilterMgr->CreateMultiConnection2D();
3037         break;
3038       case SMESH::FT_Length:
3039         aFunctor = aFilterMgr->CreateLength();
3040         break;
3041       case SMESH::FT_Length2D:
3042         aFunctor = aFilterMgr->CreateLength2D();
3043         break;
3044       case SMESH::FT_Length3D:
3045         aFunctor = aFilterMgr->CreateLength3D();
3046         break;
3047       case SMESH::FT_Deflection2D:
3048         aFunctor = aFilterMgr->CreateDeflection2D();
3049         break;
3050       case SMESH::FT_AspectRatio:
3051         aFunctor = aFilterMgr->CreateAspectRatio();
3052         break;
3053       case SMESH::FT_AspectRatio3D:
3054         aFunctor = aFilterMgr->CreateAspectRatio3D();
3055         break;
3056       case SMESH::FT_Warping:
3057         aFunctor = aFilterMgr->CreateWarping();
3058         break;
3059       case SMESH::FT_MinimumAngle:
3060         aFunctor = aFilterMgr->CreateMinimumAngle();
3061         break;
3062       case SMESH::FT_Taper:
3063         aFunctor = aFilterMgr->CreateTaper();
3064         break;
3065       case SMESH::FT_Skew:
3066         aFunctor = aFilterMgr->CreateSkew();
3067         break;
3068       case SMESH::FT_Area:
3069         aFunctor = aFilterMgr->CreateArea();
3070         break;
3071       case SMESH::FT_Volume3D:
3072         aFunctor = aFilterMgr->CreateVolume3D();
3073         break;
3074       case SMESH::FT_MaxElementLength2D:
3075         aFunctor = aFilterMgr->CreateMaxElementLength2D();
3076         break;
3077       case SMESH::FT_MaxElementLength3D:
3078         aFunctor = aFilterMgr->CreateMaxElementLength3D();
3079         break;
3080       case SMESH::FT_BallDiameter:
3081         aFunctor = aFilterMgr->CreateBallDiameter();
3082         break;
3083       case SMESH::FT_NodeConnectivityNumber:
3084         aFunctor = aFilterMgr->CreateNodeConnectivityNumber();
3085         break;
3086
3087       // Predicates
3088
3089       case SMESH::FT_FreeBorders:
3090         aPredicate = aFilterMgr->CreateFreeBorders();
3091         break;
3092       case SMESH::FT_FreeEdges:
3093         aPredicate = aFilterMgr->CreateFreeEdges();
3094         break;
3095       case SMESH::FT_FreeFaces:
3096         aPredicate = aFilterMgr->CreateFreeFaces();
3097         break;
3098       case SMESH::FT_FreeNodes:
3099         aPredicate = aFilterMgr->CreateFreeNodes();
3100         break;
3101       case SMESH::FT_EqualNodes:
3102         {
3103           SMESH::EqualNodes_ptr pred = aFilterMgr->CreateEqualNodes();
3104           pred->SetTolerance( aTolerance );
3105           aPredicate = pred;
3106           break;
3107         }
3108       case SMESH::FT_EqualEdges:
3109         aPredicate = aFilterMgr->CreateEqualEdges();
3110         break;
3111       case SMESH::FT_EqualFaces:
3112         aPredicate = aFilterMgr->CreateEqualFaces();
3113         break;
3114       case SMESH::FT_EqualVolumes:
3115         aPredicate = aFilterMgr->CreateEqualVolumes();
3116         break;
3117       case SMESH::FT_BelongToMeshGroup:
3118         {
3119           SMESH::BelongToMeshGroup_ptr tmpPred = aFilterMgr->CreateBelongToMeshGroup();
3120           tmpPred->SetGroupID( aThresholdID );
3121           aPredicate = tmpPred;
3122         }
3123         break;
3124       case SMESH::FT_BelongToGeom:
3125         {
3126           SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
3127           tmpPred->SetElementType( aTypeOfElem );
3128           tmpPred->SetShape( aThresholdID, aThresholdStr );
3129           tmpPred->SetTolerance( aTolerance );
3130           aPredicate = tmpPred;
3131         }
3132         break;
3133       case SMESH::FT_BelongToPlane:
3134       case SMESH::FT_BelongToCylinder:
3135       case SMESH::FT_BelongToGenSurface:
3136         {
3137           SMESH::BelongToSurface_ptr tmpPred;
3138           switch ( aCriterion ) {
3139           case SMESH::FT_BelongToPlane:
3140             tmpPred = aFilterMgr->CreateBelongToPlane(); break;
3141           case SMESH::FT_BelongToCylinder:
3142             tmpPred = aFilterMgr->CreateBelongToCylinder(); break;
3143           default:
3144             tmpPred = aFilterMgr->CreateBelongToGenSurface();
3145           }
3146           tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem );
3147           tmpPred->SetTolerance( aTolerance );
3148           aPredicate = tmpPred;
3149         }
3150         break;
3151       case SMESH::FT_LyingOnGeom:
3152         {
3153           SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
3154           tmpPred->SetElementType( aTypeOfElem );
3155           tmpPred->SetShape( aThresholdID, aThresholdStr );
3156           tmpPred->SetTolerance( aTolerance );
3157           aPredicate = tmpPred;
3158         }
3159         break;
3160       case SMESH::FT_RangeOfIds:
3161         {
3162           SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
3163           tmpPred->SetRangeStr( aThresholdStr );
3164           tmpPred->SetElementType( aTypeOfElem );
3165           aPredicate = tmpPred;
3166         }
3167         break;
3168       case SMESH::FT_BadOrientedVolume:
3169         {
3170           aPredicate = aFilterMgr->CreateBadOrientedVolume();
3171         }
3172         break;
3173       case SMESH::FT_BareBorderVolume:
3174         {
3175           aPredicate = aFilterMgr->CreateBareBorderVolume();
3176         }
3177         break;
3178       case SMESH::FT_BareBorderFace:
3179         {
3180           aPredicate = aFilterMgr->CreateBareBorderFace();
3181         }
3182         break;
3183       case SMESH::FT_OverConstrainedVolume:
3184         {
3185           aPredicate = aFilterMgr->CreateOverConstrainedVolume();
3186         }
3187         break;
3188       case SMESH::FT_OverConstrainedFace:
3189         {
3190           aPredicate = aFilterMgr->CreateOverConstrainedFace();
3191         }
3192         break;
3193       case SMESH::FT_LinearOrQuadratic:
3194         {
3195           SMESH::LinearOrQuadratic_ptr tmpPred = aFilterMgr->CreateLinearOrQuadratic();
3196           tmpPred->SetElementType( aTypeOfElem );
3197           aPredicate = tmpPred;
3198           break;
3199         }
3200       case SMESH::FT_GroupColor:
3201         {
3202           SMESH::GroupColor_ptr tmpPred = aFilterMgr->CreateGroupColor();
3203           tmpPred->SetElementType( aTypeOfElem );
3204           tmpPred->SetColorStr( aThresholdStr );
3205           aPredicate = tmpPred;
3206           break;
3207         }
3208       case SMESH::FT_ElemGeomType:
3209         {
3210           SMESH::ElemGeomType_ptr tmpPred = aFilterMgr->CreateElemGeomType();
3211           tmpPred->SetElementType( aTypeOfElem );
3212           tmpPred->SetGeometryType( (GeometryType)(int)(aThreshold + 0.5) );
3213           aPredicate = tmpPred;
3214           break;
3215         }
3216       case SMESH::FT_EntityType:
3217         {
3218           SMESH::ElemEntityType_ptr tmpPred = aFilterMgr->CreateElemEntityType();
3219           tmpPred->SetElementType( aTypeOfElem );
3220           tmpPred->SetEntityType( EntityType( (int (aThreshold + 0.5))));
3221           aPredicate = tmpPred;
3222           break;
3223         }
3224       case SMESH::FT_CoplanarFaces:
3225         {
3226           SMESH::CoplanarFaces_ptr tmpPred = aFilterMgr->CreateCoplanarFaces();
3227           tmpPred->SetFace( atol (aThresholdID ));
3228           tmpPred->SetTolerance( aTolerance );
3229           aPredicate = tmpPred;
3230           break;
3231         }
3232       case SMESH::FT_ConnectedElements:
3233         {
3234           SMESH::ConnectedElements_ptr tmpPred = aFilterMgr->CreateConnectedElements();
3235           if ( strlen( aThresholdID ) > 0 ) // shape ID
3236             tmpPred->SetThreshold( aThresholdID, SMESH::ConnectedElements::VERTEX );
3237           else if ( strlen( aThresholdStr ) > 0 ) // point coords
3238             tmpPred->SetThreshold( aThresholdStr, SMESH::ConnectedElements::POINT );
3239           else if ( aThreshold >= 1 )
3240             tmpPred->SetNode( (CORBA::Long) aThreshold ); // node ID
3241           tmpPred->SetElementType( aTypeOfElem );
3242           aPredicate = tmpPred;
3243           break;
3244         }
3245
3246       default:
3247         continue;
3248     }
3249
3250     // Comparator
3251     if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
3252     {
3253       SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
3254
3255       if ( aCompare == SMESH::FT_LessThan )
3256         aComparator = aFilterMgr->CreateLessThan();
3257       else if ( aCompare == SMESH::FT_MoreThan )
3258         aComparator = aFilterMgr->CreateMoreThan();
3259       else if ( aCompare == SMESH::FT_EqualTo )
3260         aComparator = aFilterMgr->CreateEqualTo();
3261       else
3262         continue;
3263
3264       aComparator->SetNumFunctor( aFunctor );
3265       aComparator->SetMargin( aThreshold );
3266
3267       if ( aCompare == FT_EqualTo )
3268       {
3269         SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
3270         anEqualTo->SetTolerance( aTolerance );
3271       }
3272
3273       aPredicate = aComparator;
3274
3275       aFunctor->SetPrecision( aPrecision );
3276     }
3277
3278     // Logical not
3279     if ( aUnary == FT_LogicalNOT )
3280     {
3281       SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
3282       aNotPred->SetPredicate( aPredicate );
3283       aPredicate = aNotPred;
3284     }
3285
3286     // logical op
3287     aPredicates.push_back( aPredicate );
3288     aBinaries.push_back( aBinary );
3289     pd <<"aCriteria.append(aCriterion)";
3290
3291   } // end of for
3292   TPythonDump pd; pd<<this<<".SetCriteria(aCriteria)";
3293
3294   // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
3295
3296   // combine all "AND" operations
3297
3298   std::list<SMESH::Predicate_ptr> aResList;
3299
3300   std::list<SMESH::Predicate_ptr>::iterator aPredIter;
3301   std::list<int>::iterator                  aBinaryIter;
3302
3303   SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
3304   int aPrevBinary = SMESH::FT_Undefined;
3305   if ( !aBinaries.empty() )
3306     aBinaries.back() = SMESH::FT_Undefined;
3307
3308   for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
3309         aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
3310         ++aPredIter, ++aBinaryIter )
3311   {
3312     int aCurrBinary = *aBinaryIter;
3313
3314     SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
3315
3316     if ( aPrevBinary == SMESH::FT_LogicalAND )
3317     {
3318
3319       SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
3320       aBinaryPred->SetPredicate1( aPrevPredicate );
3321       aBinaryPred->SetPredicate2( *aPredIter );
3322       aCurrPred = aBinaryPred;
3323     }
3324     else
3325       aCurrPred = *aPredIter;
3326
3327     if ( aCurrBinary != SMESH::FT_LogicalAND )
3328       aResList.push_back( aCurrPred );
3329
3330     aPrevPredicate = aCurrPred;
3331     aPrevBinary = aCurrBinary;
3332   }
3333
3334   // combine all "OR" operations
3335
3336   SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
3337
3338   if ( aResList.size() == 1 )
3339     aResPredicate = *aResList.begin();
3340   else if ( aResList.size() > 1 )
3341   {
3342     std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
3343     aResPredicate = *anIter;
3344     anIter++;
3345     for ( ; anIter != aResList.end(); ++anIter )
3346     {
3347       SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
3348       aBinaryPred->SetPredicate1( aResPredicate );
3349       aBinaryPred->SetPredicate2( *anIter );
3350       aResPredicate = aBinaryPred;
3351     }
3352   }
3353
3354   SetPredicate( aResPredicate );
3355   if ( !aResPredicate->_is_nil() )
3356     aResPredicate->UnRegister();
3357
3358   return !aResPredicate->_is_nil();
3359 }
3360
3361 //=======================================================================
3362 // name    : Filter_i::GetPredicate_i
3363 // Purpose : Get implementation of predicate
3364 //=======================================================================
3365 Predicate_i* Filter_i::GetPredicate_i()
3366 {
3367   return myPredicate;
3368 }
3369
3370 //=======================================================================
3371 // name    : Filter_i::GetPredicate
3372 // Purpose : Get predicate
3373 //=======================================================================
3374 Predicate_ptr Filter_i::GetPredicate()
3375 {
3376   if ( myPredicate == 0 )
3377     return SMESH::Predicate::_nil();
3378   else
3379   {
3380     SMESH::Predicate_var anObj = myPredicate->_this();
3381     // if ( SMESH::Functor_i* fun = SMESH::DownCast<SMESH::Functor_i*>( anObj ))
3382     //   TPythonDump() << fun << " = " << this << ".GetPredicate()";
3383     return anObj._retn();
3384   }
3385 }
3386
3387 //================================================================================
3388 /*!
3389  * \brief Find groups it depends on
3390  */
3391 //================================================================================
3392
3393 void Filter_i::FindBaseObjects()
3394 {
3395   // release current groups
3396   for ( size_t i = 0; i < myBaseGroups.size(); ++i )
3397     if ( myBaseGroups[i] )
3398     {
3399       myBaseGroups[i]->RemoveModifWaiter( this );
3400       myBaseGroups[i]->UnRegister();
3401     }
3402
3403   // remember new groups
3404   myBaseGroups.clear();
3405   if ( myPredicate )
3406   {
3407     std::vector<Predicate_i*> predicates;
3408     getPrediacates( myPredicate, predicates );
3409     for ( size_t i = 0; i < predicates.size(); ++i )
3410       if ( BelongToMeshGroup_i* bmg = dynamic_cast< BelongToMeshGroup_i* >( predicates[i] ))
3411       {
3412         SMESH::SMESH_GroupBase_var g = bmg->GetGroup();
3413         SMESH_GroupBase_i* g_i = SMESH::DownCast< SMESH_GroupBase_i*>( g );
3414         if ( g_i )
3415         {
3416           g_i->AddModifWaiter( this );
3417           g_i->Register();
3418           myBaseGroups.push_back( g_i );
3419         }
3420       }
3421   }
3422 }
3423
3424 //================================================================================
3425 /*!
3426  * \brief When notified on removal of myBaseGroups[i], remove a reference to a
3427  *        group from a predicate
3428  */
3429 //================================================================================
3430
3431 void Filter_i::OnBaseObjModified(NotifyerAndWaiter* group, bool removed)
3432 {
3433   if ( !removed )
3434     return; // a GroupOnFilter holding this filter is notified automatically
3435
3436   if ( myPredicate )
3437   {
3438     std::vector<Predicate_i*> predicates;
3439     getPrediacates( myPredicate, predicates );
3440     for ( size_t i = 0; i < predicates.size(); ++i )
3441       if ( BelongToMeshGroup_i* bmg = dynamic_cast< BelongToMeshGroup_i* >( predicates[i] ))
3442       {
3443         SMESH::SMESH_GroupBase_var g = bmg->GetGroup();
3444         SMESH_GroupBase_i* g_i = SMESH::DownCast< SMESH_GroupBase_i*>( g );
3445         if ( g_i == group )
3446         {
3447           bmg->SetGroup( SMESH::SMESH_GroupBase::_nil() );
3448           bmg->SetGroupID( "" );
3449         }
3450       }
3451   }
3452
3453   FindBaseObjects(); // release and update myBaseGroups;
3454 }
3455
3456 /*
3457                             FILTER LIBRARY
3458 */
3459
3460 #define ATTR_TYPE          "type"
3461 #define ATTR_COMPARE       "compare"
3462 #define ATTR_THRESHOLD     "threshold"
3463 #define ATTR_UNARY         "unary"
3464 #define ATTR_BINARY        "binary"
3465 #define ATTR_THRESHOLD_STR "threshold_str"
3466 #define ATTR_TOLERANCE     "tolerance"
3467 #define ATTR_ELEMENT_TYPE  "ElementType"
3468
3469 //=======================================================================
3470 // name    : toString
3471 // Purpose : Convert bool to LDOMString
3472 //=======================================================================
3473 static inline LDOMString toString( CORBA::Boolean val )
3474 {
3475   return val ? "logical not" : "";
3476 }
3477
3478 //=======================================================================
3479 // name    : toBool
3480 // Purpose : Convert LDOMString to bool
3481 //=======================================================================
3482 static inline bool toBool( const LDOMString& theStr )
3483 {
3484   return theStr.equals( "logical not" );
3485 }
3486
3487 //=======================================================================
3488 // name    : toString
3489 // Purpose : Convert double to LDOMString
3490 //=======================================================================
3491 static inline LDOMString toString( CORBA::Double val )
3492 {
3493   char a[ 255 ];
3494   sprintf( a, "%e", val );
3495   return LDOMString( a );
3496 }
3497
3498 //=======================================================================
3499 // name    : toDouble
3500 // Purpose : Convert LDOMString to double
3501 //=======================================================================
3502 static inline double toDouble( const LDOMString& theStr )
3503 {
3504   return atof( theStr.GetString() );
3505 }
3506
3507 //=======================================================================
3508 // name    : toString
3509 // Purpose : Convert functor type to LDOMString
3510 //=======================================================================
3511 static inline LDOMString toString( CORBA::Long theType )
3512 {
3513   switch ( theType )
3514   {
3515     case FT_AspectRatio           : return "Aspect ratio";
3516     case FT_Warping               : return "Warping";
3517     case FT_MinimumAngle          : return "Minimum angle";
3518     case FT_Taper                 : return "Taper";
3519     case FT_Skew                  : return "Skew";
3520     case FT_Area                  : return "Area";
3521     case FT_Volume3D              : return "Volume3D";
3522     case FT_MaxElementLength2D    : return "Max element length 2D";
3523     case FT_MaxElementLength3D    : return "Max element length 3D";
3524     case FT_BelongToMeshGroup     : return "Belong to Mesh Group";
3525     case FT_BelongToGeom          : return "Belong to Geom";
3526     case FT_BelongToPlane         : return "Belong to Plane";
3527     case FT_BelongToCylinder      : return "Belong to Cylinder";
3528     case FT_BelongToGenSurface    : return "Belong to Generic Surface";
3529     case FT_LyingOnGeom           : return "Lying on Geom";
3530     case FT_BadOrientedVolume     : return "Bad Oriented Volume";
3531     case FT_BareBorderVolume      : return "Volumes with bare border";
3532     case FT_BareBorderFace        : return "Faces with bare border";
3533     case FT_OverConstrainedVolume : return "Over-constrained Volumes";
3534     case FT_OverConstrainedFace   : return "Over-constrained Faces";
3535     case FT_RangeOfIds            : return "Range of IDs";
3536     case FT_FreeBorders           : return "Free borders";
3537     case FT_FreeEdges             : return "Free edges";
3538     case FT_FreeFaces             : return "Free faces";
3539     case FT_FreeNodes             : return "Free nodes";
3540     case FT_EqualNodes            : return "Equal nodes";
3541     case FT_EqualEdges            : return "Equal edges";
3542     case FT_EqualFaces            : return "Equal faces";
3543     case FT_EqualVolumes          : return "Equal volumes";
3544     case FT_MultiConnection       : return "Borders at multi-connections";
3545     case FT_MultiConnection2D     : return "Borders at multi-connections 2D";
3546     case FT_Length                : return "Length";
3547     case FT_Length2D              : return "Length 2D";
3548     case FT_Length3D              : return "Length 3D";
3549     case FT_Deflection2D          : return "Deflection 2D";
3550     case FT_LessThan              : return "Less than";
3551     case FT_MoreThan              : return "More than";
3552     case FT_EqualTo               : return "Equal to";
3553     case FT_LogicalNOT            : return "Not";
3554     case FT_LogicalAND            : return "And";
3555     case FT_LogicalOR             : return "Or";
3556     case FT_GroupColor            : return "Color of Group";
3557     case FT_LinearOrQuadratic     : return "Linear or Quadratic";
3558     case FT_ElemGeomType          : return "Element geometry type";
3559     case FT_EntityType            : return "Entity type";
3560     case FT_Undefined             : return "";
3561     default                       : return "";
3562   }
3563 }
3564
3565 //=======================================================================
3566 // name    : toFunctorType
3567 // Purpose : Convert LDOMString to functor type
3568 //=======================================================================
3569 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
3570 {
3571   if      ( theStr.equals( "Aspect ratio"                 ) ) return FT_AspectRatio;
3572   else if ( theStr.equals( "Warping"                      ) ) return FT_Warping;
3573   else if ( theStr.equals( "Minimum angle"                ) ) return FT_MinimumAngle;
3574   else if ( theStr.equals( "Taper"                        ) ) return FT_Taper;
3575   else if ( theStr.equals( "Skew"                         ) ) return FT_Skew;
3576   else if ( theStr.equals( "Area"                         ) ) return FT_Area;
3577   else if ( theStr.equals( "Volume3D"                     ) ) return FT_Volume3D;
3578   else if ( theStr.equals( "Max element length 2D"        ) ) return FT_MaxElementLength2D;
3579   else if ( theStr.equals( "Max element length 3D"        ) ) return FT_MaxElementLength3D;
3580   else if ( theStr.equals( "Belong to Mesh Group"         ) ) return FT_BelongToMeshGroup;
3581   else if ( theStr.equals( "Belong to Geom"               ) ) return FT_BelongToGeom;
3582   else if ( theStr.equals( "Belong to Plane"              ) ) return FT_BelongToPlane;
3583   else if ( theStr.equals( "Belong to Cylinder"           ) ) return FT_BelongToCylinder;
3584   else if ( theStr.equals( "Belong to Generic Surface"    ) ) return FT_BelongToGenSurface;
3585   else if ( theStr.equals( "Lying on Geom"                ) ) return FT_LyingOnGeom;
3586   else if ( theStr.equals( "Free borders"                 ) ) return FT_FreeBorders;
3587   else if ( theStr.equals( "Free edges"                   ) ) return FT_FreeEdges;
3588   else if ( theStr.equals( "Free faces"                   ) ) return FT_FreeFaces;
3589   else if ( theStr.equals( "Free nodes"                   ) ) return FT_FreeNodes;
3590   else if ( theStr.equals( "Equal nodes"                  ) ) return FT_EqualNodes;
3591   else if ( theStr.equals( "Equal edges"                  ) ) return FT_EqualEdges;
3592   else if ( theStr.equals( "Equal faces"                  ) ) return FT_EqualFaces;
3593   else if ( theStr.equals( "Equal volumes"                ) ) return FT_EqualVolumes;
3594   else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
3595   //  else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
3596   else if ( theStr.equals( "Length"                       ) ) return FT_Length;
3597   //  else if ( theStr.equals( "Length2D"                     ) ) return FT_Length2D;
3598   //  else if ( theStr.equals( "Length3D"                     ) ) return FT_Length3D;
3599   else if ( theStr.equals( "Deflection"                   ) ) return FT_Deflection2D;
3600   else if ( theStr.equals( "Range of IDs"                 ) ) return FT_RangeOfIds;
3601   else if ( theStr.equals( "Bad Oriented Volume"          ) ) return FT_BadOrientedVolume;
3602   else if ( theStr.equals( "Volumes with bare border"     ) ) return FT_BareBorderVolume;
3603   else if ( theStr.equals( "Faces with bare border"       ) ) return FT_BareBorderFace;
3604   else if ( theStr.equals( "Over-constrained Volumes"     ) ) return FT_OverConstrainedVolume;
3605   else if ( theStr.equals( "Over-constrained Faces"       ) ) return FT_OverConstrainedFace;
3606   else if ( theStr.equals( "Less than"                    ) ) return FT_LessThan;
3607   else if ( theStr.equals( "More than"                    ) ) return FT_MoreThan;
3608   else if ( theStr.equals( "Equal to"                     ) ) return FT_EqualTo;
3609   else if ( theStr.equals( "Not"                          ) ) return FT_LogicalNOT;
3610   else if ( theStr.equals( "And"                          ) ) return FT_LogicalAND;
3611   else if ( theStr.equals( "Or"                           ) ) return FT_LogicalOR;
3612   else if ( theStr.equals( "Color of Group"               ) ) return FT_GroupColor;
3613   else if ( theStr.equals( "Linear or Quadratic"          ) ) return FT_LinearOrQuadratic;
3614   else if ( theStr.equals( "Element geometry type"        ) ) return FT_ElemGeomType;
3615   else if ( theStr.equals( "Entity type"                  ) ) return FT_EntityType;
3616   else if ( theStr.equals( ""                             ) ) return FT_Undefined;
3617   else  return FT_Undefined;
3618 }
3619
3620 //=======================================================================
3621 // name    : toFunctorType
3622 // Purpose : Convert LDOMString to value of ElementType enumeration
3623 //=======================================================================
3624 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
3625 {
3626   if      ( theStr.equals( "NODE"   ) ) return SMESH::NODE;
3627   else if ( theStr.equals( "EDGE"   ) ) return SMESH::EDGE;
3628   else if ( theStr.equals( "FACE"   ) ) return SMESH::FACE;
3629   else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
3630   else                                  return SMESH::ALL;
3631 }
3632
3633 //=======================================================================
3634 // name    : toString
3635 // Purpose : Convert ElementType to string
3636 //=======================================================================
3637 static inline LDOMString toString( const SMESH::ElementType theType )
3638 {
3639   switch ( theType )
3640   {
3641     case SMESH::NODE   : return "NODE";
3642     case SMESH::EDGE   : return "EDGE";
3643     case SMESH::FACE   : return "FACE";
3644     case SMESH::VOLUME : return "VOLUME";
3645     case SMESH::ALL    : return "ALL";
3646     default            : return "";
3647   }
3648 }
3649
3650 //=======================================================================
3651 // name    : findFilter
3652 // Purpose : Find filter in document
3653 //=======================================================================
3654 static LDOM_Element findFilter( const char* theFilterName,
3655                                 const LDOM_Document& theDoc,
3656                                 LDOM_Node* theParent = 0 )
3657 {
3658   LDOM_Element aRootElement = theDoc.getDocumentElement();
3659   if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
3660     return LDOM_Element();
3661
3662   for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
3663         !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
3664   {
3665     for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
3666           !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
3667     {
3668       LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
3669       if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
3670            anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
3671       {
3672         if ( theParent != 0  )
3673           *theParent = aTypeNode;
3674         return (LDOM_Element&)aFilter;
3675       }
3676     }
3677   }
3678   return LDOM_Element();
3679 }
3680
3681 //=======================================================================
3682 // name    : getSectionName
3683 // Purpose : Get name of section of filters
3684 //=======================================================================
3685 static const char* getSectionName( const ElementType theType )
3686 {
3687   switch ( theType )
3688   {
3689     case SMESH::NODE   : return "Filters for nodes";
3690     case SMESH::EDGE   : return "Filters for edges";
3691     case SMESH::FACE   : return "Filters for faces";
3692     case SMESH::VOLUME : return "Filters for volumes";
3693     case SMESH::ALL    : return "Filters for elements";
3694     default            : return "";
3695   }
3696 }
3697
3698 //=======================================================================
3699 // name    : getSection
3700 // Purpose : Create section for filters corresponding to the entity type
3701 //=======================================================================
3702 static LDOM_Node getSection( const ElementType theType,
3703                              LDOM_Document&    theDoc,
3704                              const bool        toCreate = false )
3705 {
3706   LDOM_Element aRootElement = theDoc.getDocumentElement();
3707   if ( aRootElement.isNull() )
3708     return LDOM_Node();
3709
3710   // Find section
3711   bool anExist = false;
3712   const char* aSectionName = getSectionName( theType );
3713   if ( strcmp( aSectionName, "" ) == 0 )
3714     return LDOM_Node();
3715
3716   LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
3717   LDOM_Node aNode;
3718   for ( int i = 0, n = aSections.getLength(); i < n; i++ )
3719   {
3720     aNode = aSections.item( i );
3721     LDOM_Element& anItem = ( LDOM_Element& )aNode;
3722     if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
3723     {
3724       anExist = true;
3725       break;
3726     }
3727   }
3728
3729   // Create new section if necessary
3730   if ( !anExist )
3731   {
3732     if ( toCreate )
3733     {
3734       LDOM_Element aNewItem = theDoc.createElement( "section" );
3735       aNewItem.setAttribute( "name", aSectionName );
3736       aRootElement.appendChild( aNewItem );
3737       return aNewItem;
3738     }
3739     else
3740       return LDOM_Node();
3741   }
3742   return
3743     aNode;
3744 }
3745
3746 //=======================================================================
3747 // name    : createFilterItem
3748 // Purpose : Create filter item or LDOM document
3749 //=======================================================================
3750 static LDOM_Element createFilterItem( const char*       theName,
3751                                       SMESH::Filter_ptr theFilter,
3752                                       LDOM_Document&    theDoc )
3753 {
3754   // create new filter in document
3755   LDOM_Element aFilterItem = theDoc.createElement( "filter" );
3756   aFilterItem.setAttribute( "name", theName );
3757
3758   // save filter criterions
3759   SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
3760
3761   if ( !theFilter->GetCriteria( aCriteria ) )
3762     return LDOM_Element();
3763
3764   for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
3765   {
3766     LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
3767     
3768     aCriterionItem.setAttribute( ATTR_TYPE         , toString(  aCriteria[ i ].Type) );
3769     aCriterionItem.setAttribute( ATTR_COMPARE      , toString(  aCriteria[ i ].Compare ) );
3770     aCriterionItem.setAttribute( ATTR_THRESHOLD    , toString(  aCriteria[ i ].Threshold ) );
3771     aCriterionItem.setAttribute( ATTR_UNARY        , toString(  aCriteria[ i ].UnaryOp ) );
3772     aCriterionItem.setAttribute( ATTR_BINARY       , toString(  aCriteria[ i ].BinaryOp ) );
3773
3774     aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
3775     aCriterionItem.setAttribute( ATTR_TOLERANCE    , toString( aCriteria[ i ].Tolerance ) );
3776     aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
3777       toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
3778
3779     aFilterItem.appendChild( aCriterionItem );
3780   }
3781
3782   return aFilterItem;
3783 }
3784
3785 //=======================================================================
3786 // name    : FilterLibrary_i::FilterLibrary_i
3787 // Purpose : Constructor
3788 //=======================================================================
3789 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
3790 {
3791   myFileName = CORBA::string_dup( theFileName );
3792   SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
3793   myFilterMgr = aFilterMgr->_this();
3794
3795   LDOMParser aParser;
3796
3797   // Try to use existing library file
3798   bool anExists = false;
3799   if ( !aParser.parse( myFileName ) )
3800   {
3801     myDoc = aParser.getDocument();
3802     anExists = true;
3803   }
3804   // Create a new XML document if it doesn't exist
3805   else
3806     myDoc = LDOM_Document::createDocument( LDOMString() );
3807
3808   LDOM_Element aRootElement = myDoc.getDocumentElement();
3809   if ( aRootElement.isNull() )
3810   {
3811     // If the existing document is empty --> try to create a new one
3812     if ( anExists )
3813       myDoc = LDOM_Document::createDocument( LDOMString() );
3814   }
3815 }
3816
3817 //=======================================================================
3818 // name    : FilterLibrary_i::FilterLibrary_i
3819 // Purpose : Constructor
3820 //=======================================================================
3821 FilterLibrary_i::FilterLibrary_i()
3822 {
3823   myFileName = 0;
3824   SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
3825   myFilterMgr = aFilter->_this();
3826
3827   myDoc = LDOM_Document::createDocument( LDOMString() );
3828 }
3829
3830 FilterLibrary_i::~FilterLibrary_i()
3831 {
3832   CORBA::string_free( myFileName );
3833   //TPythonDump()<<this<<".UnRegister()";
3834 }
3835
3836 //=======================================================================
3837 // name    : FilterLibrary_i::Copy
3838 // Purpose : Create filter and initialize it with values from library
3839 //=======================================================================
3840 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
3841 {
3842   Filter_ptr aRes = Filter::_nil();
3843   LDOM_Node aFilter = findFilter( theFilterName, myDoc );
3844
3845   if ( aFilter.isNull() )
3846     return aRes;
3847
3848   std::list<SMESH::Filter::Criterion> aCriteria;
3849
3850   for ( LDOM_Node aCritNode = aFilter.getFirstChild();
3851         !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
3852   {
3853     LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
3854
3855     const char* aTypeStr      = aCrit->getAttribute( ATTR_TYPE          ).GetString();
3856     const char* aCompareStr   = aCrit->getAttribute( ATTR_COMPARE       ).GetString();
3857     const char* aUnaryStr     = aCrit->getAttribute( ATTR_UNARY         ).GetString();
3858     const char* aBinaryStr    = aCrit->getAttribute( ATTR_BINARY        ).GetString();
3859     const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE  ).GetString();
3860
3861     SMESH::Filter::Criterion aCriterion = createCriterion();
3862
3863     aCriterion.Type          = toFunctorType( aTypeStr );
3864     aCriterion.Compare       = toFunctorType( aCompareStr );
3865     aCriterion.UnaryOp       = toFunctorType( aUnaryStr );
3866     aCriterion.BinaryOp      = toFunctorType( aBinaryStr );
3867
3868     aCriterion.TypeOfElement = toElementType( anElemTypeStr );
3869
3870     LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
3871     int val = 0;
3872     aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3873       ? val : atof( str.GetString() );
3874
3875     str = aCrit->getAttribute( ATTR_TOLERANCE );
3876     aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3877       ? val : atof( str.GetString() );
3878
3879     str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
3880     if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
3881     {
3882       char a[ 255 ];
3883       sprintf( a, "%d", val );
3884       aCriterion.ThresholdStr = CORBA::string_dup( a );
3885     }
3886     else
3887       aCriterion.ThresholdStr = str.GetString();
3888
3889     aCriteria.push_back( aCriterion );
3890   }
3891
3892   SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
3893   aCriteriaVar->length( aCriteria.size() );
3894
3895   CORBA::ULong i = 0;
3896   std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
3897
3898   for( ; anIter != aCriteria.end(); ++anIter )
3899     aCriteriaVar[ i++ ] = *anIter;
3900
3901   aRes = myFilterMgr->CreateFilter();
3902   aRes->SetCriteria( aCriteriaVar.inout() );
3903
3904   TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
3905
3906   return aRes;
3907 }
3908
3909 //=======================================================================
3910 // name    : FilterLibrary_i::SetFileName
3911 // Purpose : Set file name for library
3912 //=======================================================================
3913 void FilterLibrary_i::SetFileName( const char* theFileName )
3914 {
3915   CORBA::string_free( myFileName );
3916   myFileName = CORBA::string_dup( theFileName );
3917   TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
3918 }
3919
3920 //=======================================================================
3921 // name    : FilterLibrary_i::GetFileName
3922 // Purpose : Get file name of library
3923 //=======================================================================
3924 char* FilterLibrary_i::GetFileName()
3925 {
3926   return CORBA::string_dup( myFileName );
3927 }
3928
3929 //=======================================================================
3930 // name    : FilterLibrary_i::Add
3931 // Purpose : Add new filter to library
3932 //=======================================================================
3933 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
3934 {
3935   // if filter already in library or entry filter is null do nothing
3936   LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3937   if ( !aFilterNode.isNull() || theFilter->_is_nil() )
3938     return false;
3939
3940   // get section corresponding to the filter type
3941   ElementType anEntType = theFilter->GetElementType();
3942
3943   LDOM_Node aSection = getSection( anEntType, myDoc, true );
3944   if ( aSection.isNull() )
3945     return false;
3946
3947   // create filter item
3948   LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
3949   if ( aFilterItem.isNull() )
3950     return false;
3951   else
3952   {
3953     aSection.appendChild( aFilterItem );
3954     if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3955       TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
3956     return true;
3957   }
3958 }
3959
3960 //=======================================================================
3961 // name    : FilterLibrary_i::Add
3962 // Purpose : Add new filter to library
3963 //=======================================================================
3964 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
3965 {
3966   // if filter already in library or entry filter is null do nothing
3967   LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3968   if ( !aFilterNode.isNull() )
3969     return false;
3970
3971   LDOM_Node aSection = getSection( theType, myDoc, true );
3972   if ( aSection.isNull() )
3973     return false;
3974
3975   // create filter item
3976   Filter_var aFilter = myFilterMgr->CreateFilter();
3977
3978   LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
3979   if ( aFilterItem.isNull() )
3980     return false;
3981   else
3982   {
3983     aSection.appendChild( aFilterItem );
3984     TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
3985     return true;
3986   }
3987 }
3988
3989 //=======================================================================
3990 // name    : FilterLibrary_i::Delete
3991 // Purpose : Delete filter from library
3992 //=======================================================================
3993 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
3994 {
3995   LDOM_Node aParentNode;
3996   LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
3997   if ( aFilterNode.isNull() || aParentNode.isNull() )
3998     return false;
3999
4000   aParentNode.removeChild( aFilterNode );
4001   TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
4002   return true;
4003 }
4004
4005 //=======================================================================
4006 // name      : FilterLibrary_i::Replace
4007 // Purpose   : Replace existing filter with entry filter.
4008 // IMPORTANT : If filter does not exist it is not created
4009 //=======================================================================
4010 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
4011                                          const char* theNewName,
4012                                          Filter_ptr  theFilter )
4013 {
4014   LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
4015   if ( aFilterItem.isNull() || theFilter->_is_nil() )
4016     return false;
4017
4018   LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
4019   if ( aNewItem.isNull() )
4020     return false;
4021   else
4022   {
4023     aFilterItem.ReplaceElement( aNewItem );
4024     if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
4025       TPythonDump()<<this<<".Replace('"<<theFilterName<<"','"<<theNewName<<"',"<<aFilter<<")";
4026     return true;
4027   }
4028 }
4029
4030 //=======================================================================
4031 // name    : FilterLibrary_i::Save
4032 // Purpose : Save library on disk
4033 //=======================================================================
4034 CORBA::Boolean FilterLibrary_i::Save()
4035 {
4036   if ( myFileName == 0 || strlen( myFileName ) == 0 )
4037     return false;
4038
4039   std::filebuf fb;
4040   fb.open( myFileName, std::ios::out );
4041
4042   Standard_OStream os( &fb );
4043
4044   LDOM_XmlWriter aWriter;
4045   aWriter.SetIndentation( 2 );
4046   aWriter.Write( os, myDoc );
4047   fb.close();
4048
4049   TPythonDump()<<this<<".Save()";
4050   return true;
4051 }
4052
4053 //=======================================================================
4054 // name    : FilterLibrary_i::SaveAs
4055 // Purpose : Save library on disk
4056 //=======================================================================
4057 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
4058 {
4059   myFileName = strdup ( aFileName );
4060   TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
4061   return Save();
4062 }
4063
4064 //=======================================================================
4065 // name    : FilterLibrary_i::IsPresent
4066 // Purpose : Verify whether filter is in library
4067 //=======================================================================
4068 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
4069 {
4070   return !findFilter( theFilterName, myDoc ).isNull();
4071 }
4072
4073 //=======================================================================
4074 // name    : FilterLibrary_i::NbFilters
4075 // Purpose : Return amount of filters in library
4076 //=======================================================================
4077 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
4078 {
4079   string_array_var aNames = GetNames( theType );
4080   return aNames->length();
4081 }
4082
4083 //=======================================================================
4084 // name    : FilterLibrary_i::GetNames
4085 // Purpose : Get names of filters from library
4086 //=======================================================================
4087 string_array* FilterLibrary_i::GetNames( ElementType theType )
4088 {
4089   string_array_var anArray = new string_array;
4090   TColStd_SequenceOfHAsciiString aSeq;
4091
4092   LDOM_Node aSection = getSection( theType, myDoc, false );
4093
4094   if ( !aSection.isNull() )
4095   {
4096     for ( LDOM_Node aFilter = aSection.getFirstChild();
4097           !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
4098     {
4099       LDOM_Element& anElem = ( LDOM_Element& )aFilter;
4100       aSeq.Append( new TCollection_HAsciiString(
4101          (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
4102     }
4103   }
4104
4105   anArray->length( aSeq.Length() );
4106   for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
4107     anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
4108
4109   return anArray._retn();
4110 }
4111
4112 //=======================================================================
4113 // name    : FilterLibrary_i::GetAllNames
4114 // Purpose : Get names of filters from library
4115 //=======================================================================
4116 string_array* FilterLibrary_i::GetAllNames()
4117 {
4118   string_array_var aResArray = new string_array;
4119   for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
4120   {
4121     SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
4122
4123     int aPrevLength = aResArray->length();
4124     aResArray->length( aPrevLength + aNames->length() );
4125     for ( int i = 0, n = aNames->length(); i < n; i++ )
4126       aResArray[ aPrevLength + i ] = aNames[ i ];
4127   }
4128
4129   return aResArray._retn();
4130 }
4131
4132 //================================================================================
4133 /*!
4134  * \brief Return an array of strings corresponding to items of enum FunctorType
4135  */
4136 //================================================================================
4137
4138 static const char** getFunctNames()
4139 {
4140   static const char* functName[] = {
4141     // IT's necessary to update this array according to enum FunctorType (SMESH_Filter.idl)
4142     // The order is IMPORTANT !!!
4143     "FT_AspectRatio",
4144     "FT_AspectRatio3D",
4145     "FT_Warping",
4146     "FT_MinimumAngle",
4147     "FT_Taper",
4148     "FT_Skew",
4149     "FT_Area",
4150     "FT_Volume3D",
4151     "FT_MaxElementLength2D",
4152     "FT_MaxElementLength3D",
4153     "FT_FreeBorders",
4154     "FT_FreeEdges",
4155     "FT_FreeNodes",
4156     "FT_FreeFaces",
4157     "FT_EqualNodes",
4158     "FT_EqualEdges",
4159     "FT_EqualFaces",
4160     "FT_EqualVolumes",
4161     "FT_MultiConnection",
4162     "FT_MultiConnection2D",
4163     "FT_Length",
4164     "FT_Length2D",
4165     "FT_Length3D",
4166     "FT_Deflection2D",
4167     "FT_NodeConnectivityNumber",
4168     "FT_BelongToMeshGroup",
4169     "FT_BelongToGeom",
4170     "FT_BelongToPlane",
4171     "FT_BelongToCylinder",
4172     "FT_BelongToGenSurface",
4173     "FT_LyingOnGeom",
4174     "FT_RangeOfIds",
4175     "FT_BadOrientedVolume",
4176     "FT_BareBorderVolume",
4177     "FT_BareBorderFace",
4178     "FT_OverConstrainedVolume",
4179     "FT_OverConstrainedFace",
4180     "FT_LinearOrQuadratic",
4181     "FT_GroupColor",
4182     "FT_ElemGeomType",
4183     "FT_EntityType",
4184     "FT_CoplanarFaces",
4185     "FT_BallDiameter",
4186     "FT_ConnectedElements",
4187     "FT_LessThan",
4188     "FT_MoreThan",
4189     "FT_EqualTo",
4190     "FT_LogicalNOT",
4191     "FT_LogicalAND",
4192     "FT_LogicalOR",
4193     "FT_Undefined"};
4194
4195 #ifdef _DEBUG_
4196   // check if functName is complete, compilation failure means that enum FunctorType changed
4197   const int nbFunctors = sizeof(functName) / sizeof(const char*);
4198   int _assert[( nbFunctors == SMESH::FT_Undefined + 1 ) ? 2 : -1 ]; _assert[0]=_assert[1]=0;
4199 #endif
4200
4201   return functName;
4202 }
4203
4204 //================================================================================
4205 /*!
4206  * \brief Return a string corresponding to an item of enum FunctorType
4207  */
4208 //================================================================================
4209
4210 const char* SMESH::FunctorTypeToString(SMESH::FunctorType ft)
4211 {
4212   if ( ft < 0 || ft > SMESH::FT_Undefined )
4213     return "FT_Undefined";
4214   return getFunctNames()[ ft ];
4215 }
4216
4217 //================================================================================
4218 /*!
4219  * \brief Converts a string to FunctorType. This is reverse of FunctorTypeToString()
4220  */
4221 //================================================================================
4222
4223 SMESH::FunctorType SMESH::StringToFunctorType(const char* str)
4224 {
4225   std::string name( str + 3 ); // skip "FT_"
4226   const char** functNames = getFunctNames();
4227   int ft = 0;
4228   for ( ; ft < SMESH::FT_Undefined; ++ft )
4229     if ( name == ( functNames[ft] + 3 ))
4230       break;
4231
4232   //ASSERT( strcmp( str, FunctorTypeToString( SMESH::FunctorType( ft ))) == 0 );
4233
4234   return SMESH::FunctorType( ft );
4235 }
4236
4237 //================================================================================
4238 /*!
4239  * \brief calls OnBaseObjModified(), if who != this, and myWaiters[i]->Modified(who)
4240  */
4241 //================================================================================
4242
4243 void NotifyerAndWaiter::Modified( bool removed, NotifyerAndWaiter* who )
4244 {
4245   if ( who != 0 && who != this )
4246     OnBaseObjModified( who, removed );
4247   else
4248     who = this;
4249
4250   std::list<NotifyerAndWaiter*> waiters = myWaiters; // myWaiters can be changed by Modified()
4251   std::list<NotifyerAndWaiter*>::iterator i = waiters.begin();
4252   for ( ; i != waiters.end(); ++i )
4253     (*i)->Modified( removed, who );
4254 }
4255
4256 //================================================================================
4257 /*!
4258  * \brief Stores an object to be notified on change of predicate
4259  */
4260 //================================================================================
4261
4262 void NotifyerAndWaiter::AddModifWaiter( NotifyerAndWaiter* waiter )
4263 {
4264   if ( waiter )
4265     myWaiters.push_back( waiter );
4266 }
4267
4268 //================================================================================
4269 /*!
4270  * \brief Removes an object to be notified on change of predicate
4271  */
4272 //================================================================================
4273
4274 void NotifyerAndWaiter::RemoveModifWaiter( NotifyerAndWaiter* waiter )
4275 {
4276   myWaiters.remove( waiter );
4277 }
4278
4279 //================================================================================
4280 /*!
4281  * \brief Checks if a waiter is among myWaiters, maybe nested
4282  */
4283 //================================================================================
4284
4285 bool NotifyerAndWaiter::ContainModifWaiter( NotifyerAndWaiter* waiter )
4286 {
4287   bool is = ( waiter == this );
4288
4289   std::list<NotifyerAndWaiter*>::iterator w = myWaiters.begin();
4290   for ( ; !is && w != myWaiters.end(); ++w )
4291     is = (*w)->ContainModifWaiter( waiter );
4292
4293   return is;
4294 }