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