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