Salome HOME
0020168: EDF SMESH 953: uncomplete selection with filter 'belong on geom'
[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       theCriteria[ i ].Tolerance     = aPred->GetTolerance();
2193
2194       return true;
2195     }
2196   case FT_BelongToPlane:
2197   case FT_BelongToCylinder:
2198   case FT_BelongToGenSurface:
2199     {
2200       BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
2201
2202       CORBA::ULong i = theCriteria->length();
2203       theCriteria->length( i + 1 );
2204
2205       theCriteria[ i ] = createCriterion();
2206
2207       theCriteria[ i ].Type          = aFType;
2208       theCriteria[ i ].ThresholdStr  = aPred->GetShapeName();
2209       theCriteria[ i ].ThresholdID   = aPred->GetShapeID();
2210       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2211       theCriteria[ i ].Tolerance     = aPred->GetTolerance();
2212
2213       return true;
2214     }
2215    case FT_LyingOnGeom:
2216     {
2217       LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
2218
2219       CORBA::ULong i = theCriteria->length();
2220       theCriteria->length( i + 1 );
2221
2222       theCriteria[ i ] = createCriterion();
2223
2224       theCriteria[ i ].Type          = FT_LyingOnGeom;
2225       theCriteria[ i ].ThresholdStr  = aPred->GetShapeName();
2226       theCriteria[ i ].ThresholdID   = aPred->GetShapeID();
2227       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2228       theCriteria[ i ].Tolerance     = aPred->GetTolerance();
2229
2230       return true;
2231     }
2232   case FT_RangeOfIds:
2233     {
2234       RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
2235
2236       CORBA::ULong i = theCriteria->length();
2237       theCriteria->length( i + 1 );
2238
2239       theCriteria[ i ] = createCriterion();
2240
2241       theCriteria[ i ].Type          = FT_RangeOfIds;
2242       theCriteria[ i ].ThresholdStr  = aPred->GetRangeStr();
2243       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2244
2245       return true;
2246     }
2247   case FT_BadOrientedVolume:
2248     {
2249       BadOrientedVolume_i* aPred = dynamic_cast<BadOrientedVolume_i*>( thePred );
2250
2251       CORBA::ULong i = theCriteria->length();
2252       theCriteria->length( i + 1 );
2253
2254       theCriteria[ i ] = createCriterion();
2255
2256       theCriteria[ i ].Type          = FT_BadOrientedVolume;
2257       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2258
2259       return true;
2260     }
2261   case FT_LessThan:
2262   case FT_MoreThan:
2263   case FT_EqualTo:
2264     {
2265       Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
2266
2267       CORBA::ULong i = theCriteria->length();
2268       theCriteria->length( i + 1 );
2269
2270       theCriteria[ i ] = createCriterion();
2271
2272       theCriteria[ i ].Type      = aCompar->GetNumFunctor_i()->GetFunctorType();
2273       theCriteria[ i ].Compare   = aFType;
2274       theCriteria[ i ].Threshold = aCompar->GetMargin();
2275       theCriteria[ i ].TypeOfElement = aCompar->GetElementType();
2276
2277       if ( aFType == FT_EqualTo )
2278       {
2279         EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
2280         theCriteria[ i ].Tolerance = aCompar->GetTolerance();
2281       }
2282     }
2283     return true;
2284
2285   case FT_LogicalNOT:
2286     {
2287       Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
2288       getCriteria( aPred, theCriteria );
2289       theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
2290     }
2291     return true;
2292
2293   case FT_LogicalAND:
2294   case FT_LogicalOR:
2295     {
2296       Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
2297       Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
2298       if ( !getCriteria( aPred1, theCriteria ) )
2299         return false;
2300       theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
2301       return getCriteria( aPred2, theCriteria );
2302     }
2303   case FT_GroupColor:
2304     {
2305       CORBA::ULong i = theCriteria->length();
2306       theCriteria->length( i + 1 );
2307
2308       theCriteria[ i ] = createCriterion();
2309
2310       GroupColor_i* aPred = dynamic_cast<GroupColor_i*>( thePred );
2311       theCriteria[ i ].Type          = aFType;
2312       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2313       theCriteria[ i ].ThresholdStr  = aPred->GetColorStr();
2314
2315       return true;
2316     }
2317   case FT_ElemGeomType:
2318     {
2319       CORBA::ULong i = theCriteria->length();
2320       theCriteria->length( i + 1 );
2321
2322       theCriteria[ i ] = createCriterion();
2323
2324       ElemGeomType_i* aPred = dynamic_cast<ElemGeomType_i*>( thePred );
2325       theCriteria[ i ].Type          = aFType;
2326       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2327       theCriteria[ i ].Threshold     = (double)aPred->GetGeometryType();
2328       return true;
2329     }
2330
2331   case FT_Undefined:
2332     return false;
2333   default:
2334     return false;
2335   }
2336 }
2337
2338 //=======================================================================
2339 // name    : Filter_i::GetCriteria
2340 // Purpose : Retrieve criterions from predicate
2341 //=======================================================================
2342 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
2343 {
2344   theCriteria = new SMESH::Filter::Criteria;
2345   return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
2346 }
2347
2348 //=======================================================================
2349 // name    : Filter_i::SetCriteria
2350 // Purpose : Create new predicate and set criterions in it
2351 //=======================================================================
2352 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
2353 {
2354   if ( myPredicate != 0 )
2355     myPredicate->Destroy();
2356
2357   SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2358   FilterManager_ptr aFilterMgr = aFilter->_this();
2359
2360   // CREATE two lists ( PREDICATES  and LOG OP )
2361
2362   // Criterion
2363   TPythonDump()<<"aCriteria = []";
2364   std::list<SMESH::Predicate_ptr> aPredicates;
2365   std::list<int>                  aBinaries;
2366   for ( int i = 0, n = theCriteria.length(); i < n; i++ )
2367   {
2368     int         aCriterion    = theCriteria[ i ].Type;
2369     int         aCompare      = theCriteria[ i ].Compare;
2370     double      aThreshold    = theCriteria[ i ].Threshold;
2371     const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
2372     const char* aThresholdID  = theCriteria[ i ].ThresholdID;
2373     int         aUnary        = theCriteria[ i ].UnaryOp;
2374     int         aBinary       = theCriteria[ i ].BinaryOp;
2375     double      aTolerance    = theCriteria[ i ].Tolerance;
2376     ElementType aTypeOfElem   = theCriteria[ i ].TypeOfElement;
2377     long        aPrecision    = theCriteria[ i ].Precision;
2378
2379     {
2380       TPythonDump pd;
2381       pd << "aCriterion = SMESH.Filter.Criterion(" << aCriterion << "," << aCompare
2382          << "," << aThreshold << ",'" << aThresholdStr;
2383       if (aThresholdID)
2384         pd << "',salome.ObjectToID(" << aThresholdID
2385            << ")," << aUnary << "," << aBinary << "," << aTolerance
2386            << "," << aTypeOfElem << "," << aPrecision << ")";
2387       else
2388         pd << "',''," << aUnary << "," << aBinary << "," << aTolerance
2389            << "," << aTypeOfElem << "," << aPrecision << ")";
2390     }
2391
2392     SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
2393     SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
2394
2395     switch ( aCriterion )
2396     {
2397       // Functors
2398
2399       case SMESH::FT_MultiConnection:
2400         aFunctor = aFilterMgr->CreateMultiConnection();
2401         break;
2402       case SMESH::FT_MultiConnection2D:
2403         aFunctor = aFilterMgr->CreateMultiConnection2D();
2404         break;
2405       case SMESH::FT_Length:
2406         aFunctor = aFilterMgr->CreateLength();
2407         break;
2408       case SMESH::FT_Length2D:
2409         aFunctor = aFilterMgr->CreateLength2D();
2410         break;
2411       case SMESH::FT_AspectRatio:
2412         aFunctor = aFilterMgr->CreateAspectRatio();
2413         break;
2414       case SMESH::FT_AspectRatio3D:
2415         aFunctor = aFilterMgr->CreateAspectRatio3D();
2416         break;
2417       case SMESH::FT_Warping:
2418         aFunctor = aFilterMgr->CreateWarping();
2419         break;
2420       case SMESH::FT_MinimumAngle:
2421         aFunctor = aFilterMgr->CreateMinimumAngle();
2422         break;
2423       case SMESH::FT_Taper:
2424         aFunctor = aFilterMgr->CreateTaper();
2425         break;
2426       case SMESH::FT_Skew:
2427         aFunctor = aFilterMgr->CreateSkew();
2428         break;
2429       case SMESH::FT_Area:
2430         aFunctor = aFilterMgr->CreateArea();
2431         break;
2432       case SMESH::FT_Volume3D:
2433         aFunctor = aFilterMgr->CreateVolume3D();
2434         break;
2435
2436       // Predicates
2437
2438       case SMESH::FT_FreeBorders:
2439         aPredicate = aFilterMgr->CreateFreeBorders();
2440         break;
2441       case SMESH::FT_FreeEdges:
2442         aPredicate = aFilterMgr->CreateFreeEdges();
2443         break;
2444       case SMESH::FT_FreeFaces:
2445         aPredicate = aFilterMgr->CreateFreeFaces();
2446         break;
2447       case SMESH::FT_FreeNodes:
2448         aPredicate = aFilterMgr->CreateFreeNodes();
2449         break;
2450       case SMESH::FT_BelongToGeom:
2451         {
2452           SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
2453           tmpPred->SetElementType( aTypeOfElem );
2454           tmpPred->SetShape( aThresholdID, aThresholdStr );
2455           tmpPred->SetTolerance( aTolerance );
2456           aPredicate = tmpPred;
2457         }
2458         break;
2459       case SMESH::FT_BelongToPlane:
2460       case SMESH::FT_BelongToCylinder:
2461       case SMESH::FT_BelongToGenSurface:
2462         {
2463           SMESH::BelongToSurface_ptr tmpPred;
2464           switch ( aCriterion ) {
2465           case SMESH::FT_BelongToPlane:
2466             tmpPred = aFilterMgr->CreateBelongToPlane(); break;
2467           case SMESH::FT_BelongToCylinder:
2468             tmpPred = aFilterMgr->CreateBelongToCylinder(); break;
2469           default:
2470             tmpPred = aFilterMgr->CreateBelongToGenSurface();
2471           }
2472           tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem );
2473           tmpPred->SetTolerance( aTolerance );
2474           aPredicate = tmpPred;
2475         }
2476         break;
2477       case SMESH::FT_LyingOnGeom:
2478         {
2479           SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
2480           tmpPred->SetElementType( aTypeOfElem );
2481           tmpPred->SetShape( aThresholdID, aThresholdStr );
2482           tmpPred->SetTolerance( aTolerance );
2483           aPredicate = tmpPred;
2484         }
2485         break;
2486       case SMESH::FT_RangeOfIds:
2487         {
2488           SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
2489           tmpPred->SetRangeStr( aThresholdStr );
2490           tmpPred->SetElementType( aTypeOfElem );
2491           aPredicate = tmpPred;
2492         }
2493         break;
2494       case SMESH::FT_BadOrientedVolume:
2495         {
2496           aPredicate = aFilterMgr->CreateBadOrientedVolume();
2497         }
2498         break;
2499       case SMESH::FT_LinearOrQuadratic:
2500         {
2501           SMESH::LinearOrQuadratic_ptr tmpPred = aFilterMgr->CreateLinearOrQuadratic();
2502           tmpPred->SetElementType( aTypeOfElem );
2503           aPredicate = tmpPred;
2504           break;
2505         }
2506       case SMESH::FT_GroupColor:
2507         {
2508           SMESH::GroupColor_ptr tmpPred = aFilterMgr->CreateGroupColor();
2509           tmpPred->SetElementType( aTypeOfElem );
2510           tmpPred->SetColorStr( aThresholdStr );
2511           aPredicate = tmpPred;
2512           break;
2513         }
2514       case SMESH::FT_ElemGeomType:
2515         {
2516           SMESH::ElemGeomType_ptr tmpPred = aFilterMgr->CreateElemGeomType();
2517           tmpPred->SetElementType( aTypeOfElem );
2518           tmpPred->SetGeometryType( (GeometryType)(aThreshold + 0.5) );
2519           aPredicate = tmpPred;
2520           break;
2521         }
2522
2523       default:
2524         continue;
2525     }
2526
2527     // Comparator
2528     if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
2529     {
2530       SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
2531
2532       if ( aCompare == SMESH::FT_LessThan )
2533         aComparator = aFilterMgr->CreateLessThan();
2534       else if ( aCompare == SMESH::FT_MoreThan )
2535         aComparator = aFilterMgr->CreateMoreThan();
2536       else if ( aCompare == SMESH::FT_EqualTo )
2537         aComparator = aFilterMgr->CreateEqualTo();
2538       else
2539         continue;
2540
2541       aComparator->SetNumFunctor( aFunctor );
2542       aComparator->SetMargin( aThreshold );
2543
2544       if ( aCompare == FT_EqualTo )
2545       {
2546         SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
2547         anEqualTo->SetTolerance( aTolerance );
2548       }
2549
2550       aPredicate = aComparator;
2551
2552       aFunctor->SetPrecision( aPrecision );
2553     }
2554
2555     // Logical not
2556     if ( aUnary == FT_LogicalNOT )
2557     {
2558       SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
2559       aNotPred->SetPredicate( aPredicate );
2560       aPredicate = aNotPred;
2561     }
2562
2563     // logical op
2564     aPredicates.push_back( aPredicate );
2565     aBinaries.push_back( aBinary );
2566     TPythonDump()<<"aCriteria.append(aCriterion)";
2567
2568   } // end of for
2569   TPythonDump()<<this<<".SetCriteria(aCriteria)";
2570
2571   // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
2572
2573   // combine all "AND" operations
2574
2575   std::list<SMESH::Predicate_ptr> aResList;
2576
2577   std::list<SMESH::Predicate_ptr>::iterator aPredIter;
2578   std::list<int>::iterator                  aBinaryIter;
2579
2580   SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
2581   int aPrevBinary = SMESH::FT_Undefined;
2582
2583   for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
2584         aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
2585         ++aPredIter, ++aBinaryIter )
2586   {
2587     int aCurrBinary = *aBinaryIter;
2588
2589     SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
2590
2591     if ( aPrevBinary == SMESH::FT_LogicalAND )
2592     {
2593
2594       SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
2595       aBinaryPred->SetPredicate1( aPrevPredicate );
2596       aBinaryPred->SetPredicate2( *aPredIter );
2597       aCurrPred = aBinaryPred;
2598     }
2599     else
2600       aCurrPred = *aPredIter;
2601
2602     if ( aCurrBinary != SMESH::FT_LogicalAND )
2603       aResList.push_back( aCurrPred );
2604
2605     aPrevPredicate = aCurrPred;
2606     aPrevBinary = aCurrBinary;
2607   }
2608
2609   // combine all "OR" operations
2610
2611   SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
2612
2613   if ( aResList.size() == 1 )
2614     aResPredicate = *aResList.begin();
2615   else if ( aResList.size() > 1 )
2616   {
2617     std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
2618     aResPredicate = *anIter;
2619     anIter++;
2620     for ( ; anIter != aResList.end(); ++anIter )
2621     {
2622       SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
2623       aBinaryPred->SetPredicate1( aResPredicate );
2624       aBinaryPred->SetPredicate2( *anIter );
2625       aResPredicate = aBinaryPred;
2626     }
2627   }
2628
2629   SetPredicate( aResPredicate );
2630
2631   return !aResPredicate->_is_nil();
2632 }
2633
2634 //=======================================================================
2635 // name    : Filter_i::GetPredicate_i
2636 // Purpose : Get implementation of predicate
2637 //=======================================================================
2638 Predicate_i* Filter_i::GetPredicate_i()
2639 {
2640   return myPredicate;
2641 }
2642
2643 //=======================================================================
2644 // name    : Filter_i::GetPredicate
2645 // Purpose : Get predicate
2646 //=======================================================================
2647 Predicate_ptr Filter_i::GetPredicate()
2648 {
2649   if ( myPredicate == 0 )
2650     return SMESH::Predicate::_nil();
2651   else
2652   {
2653     SMESH::Predicate_var anObj = myPredicate->_this();
2654     return anObj._retn();
2655   }
2656 }
2657
2658 /*
2659                             FILTER LIBRARY
2660 */
2661
2662 #define ATTR_TYPE          "type"
2663 #define ATTR_COMPARE       "compare"
2664 #define ATTR_THRESHOLD     "threshold"
2665 #define ATTR_UNARY         "unary"
2666 #define ATTR_BINARY        "binary"
2667 #define ATTR_THRESHOLD_STR "threshold_str"
2668 #define ATTR_TOLERANCE     "tolerance"
2669 #define ATTR_ELEMENT_TYPE  "ElementType"
2670
2671 //=======================================================================
2672 // name    : toString
2673 // Purpose : Convert bool to LDOMString
2674 //=======================================================================
2675 static inline LDOMString toString( CORBA::Boolean val )
2676 {
2677   return val ? "logical not" : "";
2678 }
2679
2680 //=======================================================================
2681 // name    : toBool
2682 // Purpose : Convert LDOMString to bool
2683 //=======================================================================
2684 static inline bool toBool( const LDOMString& theStr )
2685 {
2686   return theStr.equals( "logical not" );
2687 }
2688
2689 //=======================================================================
2690 // name    : toString
2691 // Purpose : Convert double to LDOMString
2692 //=======================================================================
2693 static inline LDOMString toString( CORBA::Double val )
2694 {
2695   char a[ 255 ];
2696   sprintf( a, "%e", val );
2697   return LDOMString( a );
2698 }
2699
2700 //=======================================================================
2701 // name    : toDouble
2702 // Purpose : Convert LDOMString to double
2703 //=======================================================================
2704 static inline double toDouble( const LDOMString& theStr )
2705 {
2706   return atof( theStr.GetString() );
2707 }
2708
2709 //=======================================================================
2710 // name    : toString
2711 // Purpose : Convert functor type to LDOMString
2712 //=======================================================================
2713 static inline LDOMString toString( CORBA::Long theType )
2714 {
2715   switch ( theType )
2716   {
2717     case FT_AspectRatio     : return "Aspect ratio";
2718     case FT_Warping         : return "Warping";
2719     case FT_MinimumAngle    : return "Minimum angle";
2720     case FT_Taper           : return "Taper";
2721     case FT_Skew            : return "Skew";
2722     case FT_Area            : return "Area";
2723     case FT_Volume3D        : return "Volume3D";
2724     case FT_BelongToGeom    : return "Belong to Geom";
2725     case FT_BelongToPlane   : return "Belong to Plane";
2726     case FT_BelongToCylinder: return "Belong to Cylinder";
2727     case FT_BelongToGenSurface: return "Belong to Generic Surface";
2728     case FT_LyingOnGeom     : return "Lying on Geom";
2729     case FT_BadOrientedVolume: return "Bad Oriented Volume";
2730     case FT_RangeOfIds      : return "Range of IDs";
2731     case FT_FreeBorders     : return "Free borders";
2732     case FT_FreeEdges       : return "Free edges";
2733     case FT_FreeFaces       : return "Free faces";
2734     case FT_FreeNodes       : return "Free nodes";
2735     case FT_MultiConnection : return "Borders at multi-connections";
2736     case FT_MultiConnection2D: return "Borders at multi-connections 2D";
2737     case FT_Length          : return "Length";
2738     case FT_Length2D        : return "Length 2D";
2739     case FT_LessThan        : return "Less than";
2740     case FT_MoreThan        : return "More than";
2741     case FT_EqualTo         : return "Equal to";
2742     case FT_LogicalNOT      : return "Not";
2743     case FT_LogicalAND      : return "And";
2744     case FT_LogicalOR       : return "Or";
2745     case FT_GroupColor      : return "Color of Group";
2746     case FT_LinearOrQuadratic : return "Linear or Quadratic";
2747     case FT_ElemGeomType    : return "Element geomtry type";
2748     case FT_Undefined       : return "";
2749     default                 : return "";
2750   }
2751 }
2752
2753 //=======================================================================
2754 // name    : toFunctorType
2755 // Purpose : Convert LDOMString to functor type
2756 //=======================================================================
2757 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
2758 {
2759   if      ( theStr.equals( "Aspect ratio"                 ) ) return FT_AspectRatio;
2760   else if ( theStr.equals( "Warping"                      ) ) return FT_Warping;
2761   else if ( theStr.equals( "Minimum angle"                ) ) return FT_MinimumAngle;
2762   else if ( theStr.equals( "Taper"                        ) ) return FT_Taper;
2763   else if ( theStr.equals( "Skew"                         ) ) return FT_Skew;
2764   else if ( theStr.equals( "Area"                         ) ) return FT_Area;
2765   else if ( theStr.equals( "Volume3D"                     ) ) return FT_Volume3D;
2766   else if ( theStr.equals( "Belong to Geom"               ) ) return FT_BelongToGeom;
2767   else if ( theStr.equals( "Belong to Plane"              ) ) return FT_BelongToPlane;
2768   else if ( theStr.equals( "Belong to Cylinder"           ) ) return FT_BelongToCylinder;
2769   else if ( theStr.equals( "Belong to Generic Surface"    ) ) return FT_BelongToGenSurface;
2770   else if ( theStr.equals( "Lying on Geom"                ) ) return FT_LyingOnGeom;
2771   else if ( theStr.equals( "Free borders"                 ) ) return FT_FreeBorders;
2772   else if ( theStr.equals( "Free edges"                   ) ) return FT_FreeEdges;
2773   else if ( theStr.equals( "Free faces"                   ) ) return FT_FreeFaces;
2774   else if ( theStr.equals( "Free nodes"                   ) ) return FT_FreeNodes;
2775   else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
2776   //  else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
2777   else if ( theStr.equals( "Length"                       ) ) return FT_Length;
2778   //  else if ( theStr.equals( "Length2D"                     ) ) return FT_Length2D;
2779   else if ( theStr.equals( "Range of IDs"                 ) ) return FT_RangeOfIds;
2780   else if ( theStr.equals( "Bad Oriented Volume"          ) ) return FT_BadOrientedVolume;
2781   else if ( theStr.equals( "Less than"                    ) ) return FT_LessThan;
2782   else if ( theStr.equals( "More than"                    ) ) return FT_MoreThan;
2783   else if ( theStr.equals( "Equal to"                     ) ) return FT_EqualTo;
2784   else if ( theStr.equals( "Not"                          ) ) return FT_LogicalNOT;
2785   else if ( theStr.equals( "And"                          ) ) return FT_LogicalAND;
2786   else if ( theStr.equals( "Or"                           ) ) return FT_LogicalOR;
2787   else if ( theStr.equals( "Color of Group"               ) ) return FT_GroupColor;
2788   else if ( theStr.equals( "Linear or Quadratic"          ) ) return FT_LinearOrQuadratic;
2789   else if ( theStr.equals( "Element geomtry type"         ) ) return FT_ElemGeomType;
2790   else if ( theStr.equals( ""                             ) ) return FT_Undefined;
2791   else  return FT_Undefined;
2792 }
2793
2794 //=======================================================================
2795 // name    : toFunctorType
2796 // Purpose : Convert LDOMString to value of ElementType enumeration
2797 //=======================================================================
2798 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
2799 {
2800   if      ( theStr.equals( "NODE"   ) ) return SMESH::NODE;
2801   else if ( theStr.equals( "EDGE"   ) ) return SMESH::EDGE;
2802   else if ( theStr.equals( "FACE"   ) ) return SMESH::FACE;
2803   else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
2804   else                                  return SMESH::ALL;
2805 }
2806
2807 //=======================================================================
2808 // name    : toString
2809 // Purpose : Convert ElementType to string
2810 //=======================================================================
2811 static inline LDOMString toString( const SMESH::ElementType theType )
2812 {
2813   switch ( theType )
2814   {
2815     case SMESH::NODE   : return "NODE";
2816     case SMESH::EDGE   : return "EDGE";
2817     case SMESH::FACE   : return "FACE";
2818     case SMESH::VOLUME : return "VOLUME";
2819     case SMESH::ALL    : return "ALL";
2820     default            : return "";
2821   }
2822 }
2823
2824 //=======================================================================
2825 // name    : findFilter
2826 // Purpose : Find filter in document
2827 //=======================================================================
2828 static LDOM_Element findFilter( const char* theFilterName,
2829                                 const LDOM_Document& theDoc,
2830                                 LDOM_Node* theParent = 0 )
2831 {
2832   LDOM_Element aRootElement = theDoc.getDocumentElement();
2833   if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
2834     return LDOM_Element();
2835
2836   for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
2837         !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
2838   {
2839     for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
2840           !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2841     {
2842       LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
2843       if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
2844            anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
2845       {
2846         if ( theParent != 0  )
2847           *theParent = aTypeNode;
2848         return (LDOM_Element&)aFilter;
2849       }
2850     }
2851   }
2852   return LDOM_Element();
2853 }
2854
2855 //=======================================================================
2856 // name    : getSectionName
2857 // Purpose : Get name of section of filters
2858 //=======================================================================
2859 static const char* getSectionName( const ElementType theType )
2860 {
2861   switch ( theType )
2862   {
2863     case SMESH::NODE   : return "Filters for nodes";
2864     case SMESH::EDGE   : return "Filters for edges";
2865     case SMESH::FACE   : return "Filters for faces";
2866     case SMESH::VOLUME : return "Filters for volumes";
2867     case SMESH::ALL    : return "Filters for elements";
2868     default            : return "";
2869   }
2870 }
2871
2872 //=======================================================================
2873 // name    : getSection
2874 // Purpose : Create section for filters corresponding to the entity type
2875 //=======================================================================
2876 static LDOM_Node getSection( const ElementType theType,
2877                              LDOM_Document&    theDoc,
2878                              const bool        toCreate = false )
2879 {
2880   LDOM_Element aRootElement = theDoc.getDocumentElement();
2881   if ( aRootElement.isNull() )
2882     return LDOM_Node();
2883
2884   // Find section
2885   bool anExist = false;
2886   const char* aSectionName = getSectionName( theType );
2887   if ( strcmp( aSectionName, "" ) == 0 )
2888     return LDOM_Node();
2889
2890   LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
2891   LDOM_Node aNode;
2892   for ( int i = 0, n = aSections.getLength(); i < n; i++ )
2893   {
2894     aNode = aSections.item( i );
2895     LDOM_Element& anItem = ( LDOM_Element& )aNode;
2896     if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
2897     {
2898       anExist = true;
2899       break;
2900     }
2901   }
2902
2903   // Create new section if necessary
2904   if ( !anExist )
2905   {
2906     if ( toCreate )
2907     {
2908       LDOM_Element aNewItem = theDoc.createElement( "section" );
2909       aNewItem.setAttribute( "name", aSectionName );
2910       aRootElement.appendChild( aNewItem );
2911       return aNewItem;
2912     }
2913     else
2914       return LDOM_Node();
2915   }
2916   return
2917     aNode;
2918 }
2919
2920 //=======================================================================
2921 // name    : createFilterItem
2922 // Purpose : Create filter item or LDOM document
2923 //=======================================================================
2924 static LDOM_Element createFilterItem( const char*       theName,
2925                                       SMESH::Filter_ptr theFilter,
2926                                       LDOM_Document&    theDoc )
2927 {
2928   // create new filter in document
2929   LDOM_Element aFilterItem = theDoc.createElement( "filter" );
2930   aFilterItem.setAttribute( "name", theName );
2931
2932   // save filter criterions
2933   SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2934
2935   if ( !theFilter->GetCriteria( aCriteria ) )
2936     return LDOM_Element();
2937
2938   for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
2939   {
2940     LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
2941     
2942     aCriterionItem.setAttribute( ATTR_TYPE         , toString(  aCriteria[ i ].Type) );
2943     aCriterionItem.setAttribute( ATTR_COMPARE      , toString(  aCriteria[ i ].Compare ) );
2944     aCriterionItem.setAttribute( ATTR_THRESHOLD    , toString(  aCriteria[ i ].Threshold ) );
2945     aCriterionItem.setAttribute( ATTR_UNARY        , toString(  aCriteria[ i ].UnaryOp ) );
2946     aCriterionItem.setAttribute( ATTR_BINARY       , toString(  aCriteria[ i ].BinaryOp ) );
2947
2948     aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
2949     aCriterionItem.setAttribute( ATTR_TOLERANCE    , toString( aCriteria[ i ].Tolerance ) );
2950     aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
2951       toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
2952
2953     aFilterItem.appendChild( aCriterionItem );
2954   }
2955
2956   return aFilterItem;
2957 }
2958
2959 //=======================================================================
2960 // name    : FilterLibrary_i::FilterLibrary_i
2961 // Purpose : Constructor
2962 //=======================================================================
2963 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
2964 {
2965   myFileName = strdup( theFileName );
2966   SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
2967   myFilterMgr = aFilterMgr->_this();
2968
2969   LDOMParser aParser;
2970
2971   // Try to use existing library file
2972   bool anExists = false;
2973   if ( !aParser.parse( myFileName ) )
2974   {
2975     myDoc = aParser.getDocument();
2976     anExists = true;
2977   }
2978   // Create a new XML document if it doesn't exist
2979   else
2980     myDoc = LDOM_Document::createDocument( LDOMString() );
2981
2982   LDOM_Element aRootElement = myDoc.getDocumentElement();
2983   if ( aRootElement.isNull() )
2984   {
2985     // If the existing document is empty --> try to create a new one
2986     if ( anExists )
2987       myDoc = LDOM_Document::createDocument( LDOMString() );
2988   }
2989 }
2990
2991 //=======================================================================
2992 // name    : FilterLibrary_i::FilterLibrary_i
2993 // Purpose : Constructor
2994 //=======================================================================
2995 FilterLibrary_i::FilterLibrary_i()
2996 {
2997   myFileName = 0;
2998   SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2999   myFilterMgr = aFilter->_this();
3000
3001   myDoc = LDOM_Document::createDocument( LDOMString() );
3002 }
3003
3004 FilterLibrary_i::~FilterLibrary_i()
3005 {
3006   delete myFileName;
3007   //TPythonDump()<<this<<".Destroy()";
3008 }
3009
3010 //=======================================================================
3011 // name    : FilterLibrary_i::Copy
3012 // Purpose : Create filter and initialize it with values from library
3013 //=======================================================================
3014 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
3015 {
3016   Filter_ptr aRes = Filter::_nil();
3017   LDOM_Node aFilter = findFilter( theFilterName, myDoc );
3018
3019   if ( aFilter.isNull() )
3020     return aRes;
3021
3022   std::list<SMESH::Filter::Criterion> aCriteria;
3023
3024   for ( LDOM_Node aCritNode = aFilter.getFirstChild();
3025         !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
3026   {
3027     LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
3028
3029     const char* aTypeStr      = aCrit->getAttribute( ATTR_TYPE          ).GetString();
3030     const char* aCompareStr   = aCrit->getAttribute( ATTR_COMPARE       ).GetString();
3031     const char* aUnaryStr     = aCrit->getAttribute( ATTR_UNARY         ).GetString();
3032     const char* aBinaryStr    = aCrit->getAttribute( ATTR_BINARY        ).GetString();
3033     const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE  ).GetString();
3034
3035     SMESH::Filter::Criterion aCriterion = createCriterion();
3036
3037     aCriterion.Type          = toFunctorType( aTypeStr );
3038     aCriterion.Compare       = toFunctorType( aCompareStr );
3039     aCriterion.UnaryOp       = toFunctorType( aUnaryStr );
3040     aCriterion.BinaryOp      = toFunctorType( aBinaryStr );
3041
3042     aCriterion.TypeOfElement = toElementType( anElemTypeStr );
3043
3044     LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
3045     int val = 0;
3046     aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3047       ? val : atof( str.GetString() );
3048
3049     str = aCrit->getAttribute( ATTR_TOLERANCE );
3050     aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3051       ? val : atof( str.GetString() );
3052
3053     str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
3054     if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
3055     {
3056       char a[ 255 ];
3057       sprintf( a, "%d", val );
3058       aCriterion.ThresholdStr = strdup( a );
3059     }
3060     else
3061       aCriterion.ThresholdStr = str.GetString();
3062
3063     aCriteria.push_back( aCriterion );
3064   }
3065
3066   SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
3067   aCriteriaVar->length( aCriteria.size() );
3068
3069   CORBA::ULong i = 0;
3070   std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
3071
3072   for( ; anIter != aCriteria.end(); ++anIter )
3073     aCriteriaVar[ i++ ] = *anIter;
3074
3075   aRes = myFilterMgr->CreateFilter();
3076   aRes->SetCriteria( aCriteriaVar.inout() );
3077
3078   TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
3079
3080   return aRes;
3081 }
3082
3083 //=======================================================================
3084 // name    : FilterLibrary_i::SetFileName
3085 // Purpose : Set file name for library
3086 //=======================================================================
3087 void FilterLibrary_i::SetFileName( const char* theFileName )
3088 {
3089   delete myFileName;
3090   myFileName = strdup( theFileName );
3091   TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
3092 }
3093
3094 //=======================================================================
3095 // name    : FilterLibrary_i::GetFileName
3096 // Purpose : Get file name of library
3097 //=======================================================================
3098 char* FilterLibrary_i::GetFileName()
3099 {
3100   return CORBA::string_dup( myFileName );
3101 }
3102
3103 //=======================================================================
3104 // name    : FilterLibrary_i::Add
3105 // Purpose : Add new filter to library
3106 //=======================================================================
3107 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
3108 {
3109   // if filter already in library or entry filter is null do nothing
3110   LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3111   if ( !aFilterNode.isNull() || theFilter->_is_nil() )
3112     return false;
3113
3114   // get section corresponding to the filter type
3115   ElementType anEntType = theFilter->GetElementType();
3116
3117   LDOM_Node aSection = getSection( anEntType, myDoc, true );
3118   if ( aSection.isNull() )
3119     return false;
3120
3121   // create filter item
3122   LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
3123   if ( aFilterItem.isNull() )
3124     return false;
3125   else
3126   {
3127     aSection.appendChild( aFilterItem );
3128     if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3129       TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
3130     return true;
3131   }
3132 }
3133
3134 //=======================================================================
3135 // name    : FilterLibrary_i::Add
3136 // Purpose : Add new filter to library
3137 //=======================================================================
3138 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
3139 {
3140   // if filter already in library or entry filter is null do nothing
3141   LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3142   if ( !aFilterNode.isNull() )
3143     return false;
3144
3145   LDOM_Node aSection = getSection( theType, myDoc, true );
3146   if ( aSection.isNull() )
3147     return false;
3148
3149   // create filter item
3150   Filter_var aFilter = myFilterMgr->CreateFilter();
3151
3152   LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
3153   if ( aFilterItem.isNull() )
3154     return false;
3155   else
3156   {
3157     aSection.appendChild( aFilterItem );
3158     TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
3159     return true;
3160   }
3161 }
3162
3163 //=======================================================================
3164 // name    : FilterLibrary_i::Delete
3165 // Purpose : Delete filter from library
3166 //=======================================================================
3167 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
3168 {
3169   LDOM_Node aParentNode;
3170   LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
3171   if ( aFilterNode.isNull() || aParentNode.isNull() )
3172     return false;
3173
3174   aParentNode.removeChild( aFilterNode );
3175   TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
3176   return true;
3177 }
3178
3179 //=======================================================================
3180 // name      : FilterLibrary_i::Replace
3181 // Purpose   : Replace existing filter with entry filter.
3182 // IMPORTANT : If filter does not exist it is not created
3183 //=======================================================================
3184 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
3185                                          const char* theNewName,
3186                                          Filter_ptr  theFilter )
3187 {
3188   LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
3189   if ( aFilterItem.isNull() || theFilter->_is_nil() )
3190     return false;
3191
3192   LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
3193   if ( aNewItem.isNull() )
3194     return false;
3195   else
3196   {
3197     aFilterItem.ReplaceElement( aNewItem );
3198     if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3199       TPythonDump()<<this<<".Replace('"<<theFilterName<<"',"<<theNewName<<"',"<<aFilter<<")";
3200     return true;
3201   }
3202 }
3203
3204 //=======================================================================
3205 // name    : FilterLibrary_i::Save
3206 // Purpose : Save library on disk
3207 //=======================================================================
3208 CORBA::Boolean FilterLibrary_i::Save()
3209 {
3210   if ( myFileName == 0 || strlen( myFileName ) == 0 )
3211     return false;
3212
3213   FILE* aOutFile = fopen( myFileName, "wt" );
3214   if ( !aOutFile )
3215     return false;
3216
3217   LDOM_XmlWriter aWriter( aOutFile );
3218   aWriter.SetIndentation( 2 );
3219   aWriter << myDoc;
3220   fclose( aOutFile );
3221
3222   TPythonDump()<<this<<".Save()";
3223   return true;
3224 }
3225
3226 //=======================================================================
3227 // name    : FilterLibrary_i::SaveAs
3228 // Purpose : Save library on disk
3229 //=======================================================================
3230 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
3231 {
3232   myFileName = strdup ( aFileName );
3233   TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
3234   return Save();
3235 }
3236
3237 //=======================================================================
3238 // name    : FilterLibrary_i::IsPresent
3239 // Purpose : Verify whether filter is in library
3240 //=======================================================================
3241 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
3242 {
3243   return !findFilter( theFilterName, myDoc ).isNull();
3244 }
3245
3246 //=======================================================================
3247 // name    : FilterLibrary_i::NbFilters
3248 // Purpose : Return amount of filters in library
3249 //=======================================================================
3250 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
3251 {
3252   string_array_var aNames = GetNames( theType );
3253   return aNames->length();
3254 }
3255
3256 //=======================================================================
3257 // name    : FilterLibrary_i::GetNames
3258 // Purpose : Get names of filters from library
3259 //=======================================================================
3260 string_array* FilterLibrary_i::GetNames( ElementType theType )
3261 {
3262   string_array_var anArray = new string_array;
3263   TColStd_SequenceOfHAsciiString aSeq;
3264
3265   LDOM_Node aSection = getSection( theType, myDoc, false );
3266
3267   if ( !aSection.isNull() )
3268   {
3269     for ( LDOM_Node aFilter = aSection.getFirstChild();
3270           !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
3271     {
3272       LDOM_Element& anElem = ( LDOM_Element& )aFilter;
3273       aSeq.Append( new TCollection_HAsciiString(
3274          (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
3275     }
3276   }
3277
3278   anArray->length( aSeq.Length() );
3279   for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
3280     anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
3281
3282   return anArray._retn();
3283 }
3284
3285 //=======================================================================
3286 // name    : FilterLibrary_i::GetAllNames
3287 // Purpose : Get names of filters from library
3288 //=======================================================================
3289 string_array* FilterLibrary_i::GetAllNames()
3290 {
3291   string_array_var aResArray = new string_array;
3292   for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
3293   {
3294     SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
3295
3296     int aPrevLength = aResArray->length();
3297     aResArray->length( aPrevLength + aNames->length() );
3298     for ( int i = 0, n = aNames->length(); i < n; i++ )
3299       aResArray[ aPrevLength + i ] = aNames[ i ];
3300   }
3301
3302   return aResArray._retn();
3303 }