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